GeezerVison is showing github.com — src: replace ARRAY_SIZE with typesafe arraysize · nodejs/node@2fd8be2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/async-wrap-inl.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,7 +54,7 @@ inline AsyncWrap::AsyncWrap(Environment* env, | 54 | 54 | v8::TryCatch try_catch(env->isolate()); | 55 | 55 |
| 56 | 56 | v8::MaybeLocal<v8::Value> ret = | 57 | | - init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv); | | 57 | + init_fn->Call(env->context(), object, arraysize(argv), argv); | 58 | 58 |
| 59 | 59 | if (ret.IsEmpty()) { | 60 | 60 | ClearFatalExceptionHandlers(env); | |
Collapse file Copy file name to clipboardExpand all lines: src/async-wrap.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -242,7 +242,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb, | 242 | 242 | Local<Value> vals[] = { uid, did_throw }; | 243 | 243 | TryCatch try_catch(env()->isolate()); | 244 | 244 | MaybeLocal<Value> ar = | 245 | | - post_fn->Call(env()->context(), context, ARRAY_SIZE(vals), vals); | | 245 | + post_fn->Call(env()->context(), context, arraysize(vals), vals); | 246 | 246 | if (ar.IsEmpty()) { | 247 | 247 | ClearFatalExceptionHandlers(env()); | 248 | 248 | FatalException(env()->isolate(), try_catch); | |
Collapse file Copy file name to clipboardExpand all lines: src/cares_wrap.cc +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -310,7 +310,7 @@ class QueryWrap : public AsyncWrap { | 310 | 310 | Integer::New(env()->isolate(), 0), | 311 | 311 | answer | 312 | 312 | }; | 313 | | - MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv); | | 313 | + MakeCallback(env()->oncomplete_string(), arraysize(argv), argv); | 314 | 314 | } | 315 | 315 |
| 316 | 316 | void CallOnComplete(Local<Value> answer, Local<Value> family) { | @@ -321,7 +321,7 @@ class QueryWrap : public AsyncWrap { | 321 | 321 | answer, | 322 | 322 | family | 323 | 323 | }; | 324 | | - MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv); | | 324 | + MakeCallback(env()->oncomplete_string(), arraysize(argv), argv); | 325 | 325 | } | 326 | 326 |
| 327 | 327 | void ParseError(int status) { | @@ -994,7 +994,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { | 994 | 994 | uv_freeaddrinfo(res); | 995 | 995 |
| 996 | 996 | // Make the callback into JavaScript | 997 | | - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); | | 997 | + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); | 998 | 998 |
| 999 | 999 | delete req_wrap; | 1000 | 1000 | } | @@ -1025,7 +1025,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req, | 1025 | 1025 | } | 1026 | 1026 |
| 1027 | 1027 | // Make the callback into JavaScript | 1028 | | - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); | | 1028 | + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); | 1029 | 1029 |
| 1030 | 1030 | delete req_wrap; | 1031 | 1031 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/debug-agent.cc +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | #include "debug-agent.h" | 23 | 23 |
| 24 | 24 | #include "node.h" | 25 | | -#include "node_internals.h" // ARRAY_SIZE | | 25 | +#include "node_internals.h" // arraysize | 26 | 26 | #include "env.h" | 27 | 27 | #include "env-inl.h" | 28 | 28 | #include "v8.h" | @@ -175,9 +175,9 @@ void Agent::WorkerRun() { | 175 | 175 | isolate, | 176 | 176 | &child_loop_, | 177 | 177 | context, | 178 | | - ARRAY_SIZE(argv), | | 178 | + arraysize(argv), | 179 | 179 | argv, | 180 | | - ARRAY_SIZE(argv), | | 180 | + arraysize(argv), | 181 | 181 | argv); | 182 | 182 |
| 183 | 183 | child_env_ = env; | @@ -301,7 +301,7 @@ void Agent::ChildSignalCb(uv_async_t* signal) { | 301 | 301 | MakeCallback(isolate, | 302 | 302 | api, | 303 | 303 | "onmessage", | 304 | | - ARRAY_SIZE(argv), | | 304 | + arraysize(argv), | 305 | 305 | argv); | 306 | 306 | delete msg; | 307 | 307 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/fs_event_wrap.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -159,7 +159,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, | 159 | 159 | argv[2] = OneByteString(env->isolate(), filename); | 160 | 160 | } | 161 | 161 |
| 162 | | - wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv); | | 162 | + wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv); | 163 | 163 | } | 164 | 164 |
| 165 | 165 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/js_stream.cc +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,7 +75,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) { | 75 | 75 |
| 76 | 76 | req_wrap->Dispatched(); | 77 | 77 | Local<Value> res = | 78 | | - MakeCallback(env()->onshutdown_string(), ARRAY_SIZE(argv), argv); | | 78 | + MakeCallback(env()->onshutdown_string(), arraysize(argv), argv); | 79 | 79 |
| 80 | 80 | return res->Int32Value(); | 81 | 81 | } | @@ -103,7 +103,7 @@ int JSStream::DoWrite(WriteWrap* w, | 103 | 103 |
| 104 | 104 | w->Dispatched(); | 105 | 105 | Local<Value> res = | 106 | | - MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv); | | 106 | + MakeCallback(env()->onwrite_string(), arraysize(argv), argv); | 107 | 107 |
| 108 | 108 | return res->Int32Value(); | 109 | 109 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +13-13Lines changed: 13 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1113,7 +1113,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) { | 1113 | 1113 | Local<Value> args[] = { event, promise, value }; | 1114 | 1114 | Local<Object> process = env->process_object(); | 1115 | 1115 |
| 1116 | | - callback->Call(process, ARRAY_SIZE(args), args); | | 1116 | + callback->Call(process, arraysize(args), args); | 1117 | 1117 | } | 1118 | 1118 |
| 1119 | 1119 | void SetupPromises(const FunctionCallbackInfo<Value>& args) { | @@ -1196,7 +1196,7 @@ Local<Value> MakeCallback(Environment* env, | 1196 | 1196 | { Undefined(env->isolate()).As<Value>(), did_throw }; | 1197 | 1197 | TryCatch try_catch(env->isolate()); | 1198 | 1198 | MaybeLocal<Value> ar = | 1199 | | - post_fn->Call(env->context(), object, ARRAY_SIZE(vals), vals); | | 1199 | + post_fn->Call(env->context(), object, arraysize(vals), vals); | 1200 | 1200 | if (ar.IsEmpty()) { | 1201 | 1201 | ClearFatalExceptionHandlers(env); | 1202 | 1202 | FatalException(env->isolate(), try_catch); | @@ -1651,7 +1651,7 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { | 1651 | 1651 | if (w->persistent().IsEmpty()) | 1652 | 1652 | continue; | 1653 | 1653 | argv[idx] = w->object(); | 1654 | | - if (++idx >= ARRAY_SIZE(argv)) { | | 1654 | + if (++idx >= arraysize(argv)) { | 1655 | 1655 | fn->Call(ctx, ary, idx, argv).ToLocalChecked(); | 1656 | 1656 | idx = 0; | 1657 | 1657 | } | @@ -1686,7 +1686,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { | 1686 | 1686 | if (owner->IsUndefined()) | 1687 | 1687 | owner = object; | 1688 | 1688 | argv[idx] = owner; | 1689 | | - if (++idx >= ARRAY_SIZE(argv)) { | | 1689 | + if (++idx >= arraysize(argv)) { | 1690 | 1690 | fn->Call(ctx, ary, idx, argv).ToLocalChecked(); | 1691 | 1691 | idx = 0; | 1692 | 1692 | } | @@ -2520,12 +2520,12 @@ static void EnvGetter(Local<String> property, | 2520 | 2520 | WCHAR buffer[32767]; // The maximum size allowed for environment variables. | 2521 | 2521 | DWORD result = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(*key), | 2522 | 2522 | buffer, | 2523 | | - ARRAY_SIZE(buffer)); | | 2523 | + arraysize(buffer)); | 2524 | 2524 | // If result >= sizeof buffer the buffer was too small. That should never | 2525 | 2525 | // happen. If result == 0 and result != ERROR_SUCCESS the variable was not | 2526 | 2526 | // not found. | 2527 | 2527 | if ((result > 0 || GetLastError() == ERROR_SUCCESS) && | 2528 | | - result < ARRAY_SIZE(buffer)) { | | 2528 | + result < arraysize(buffer)) { | 2529 | 2529 | const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer); | 2530 | 2530 | Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer); | 2531 | 2531 | return info.GetReturnValue().Set(rc); | @@ -2626,7 +2626,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { | 2626 | 2626 | var, | 2627 | 2627 | String::kNormalString, | 2628 | 2628 | length); | 2629 | | - if (++idx >= ARRAY_SIZE(argv)) { | | 2629 | + if (++idx >= arraysize(argv)) { | 2630 | 2630 | fn->Call(ctx, envarr, idx, argv).ToLocalChecked(); | 2631 | 2631 | idx = 0; | 2632 | 2632 | } | @@ -2658,7 +2658,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { | 2658 | 2658 | two_byte_buffer, | 2659 | 2659 | String::kNormalString, | 2660 | 2660 | two_byte_buffer_len); | 2661 | | - if (++idx >= ARRAY_SIZE(argv)) { | | 2661 | + if (++idx >= arraysize(argv)) { | 2662 | 2662 | fn->Call(ctx, envarr, idx, argv).ToLocalChecked(); | 2663 | 2663 | idx = 0; | 2664 | 2664 | } | @@ -3556,7 +3556,7 @@ static void EnableDebug(Environment* env) { | 3556 | 3556 | FIXED_ONE_BYTE_STRING(env->isolate(), "internalMessage"), | 3557 | 3557 | message | 3558 | 3558 | }; | 3559 | | - MakeCallback(env, env->process_object(), "emit", ARRAY_SIZE(argv), argv); | | 3559 | + MakeCallback(env, env->process_object(), "emit", arraysize(argv), argv); | 3560 | 3560 |
| 3561 | 3561 | // Enabled debugger, possibly making it wait on a semaphore | 3562 | 3562 | env->debugger_agent()->Enable(); | @@ -3677,7 +3677,7 @@ static int RegisterDebugSignalHandler() { | 3677 | 3677 |
| 3678 | 3678 | if (GetDebugSignalHandlerMappingName(pid, | 3679 | 3679 | mapping_name, | 3680 | | - ARRAY_SIZE(mapping_name)) < 0) { | | 3680 | + arraysize(mapping_name)) < 0) { | 3681 | 3681 | return -1; | 3682 | 3682 | } | 3683 | 3683 |
| @@ -3740,7 +3740,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { | 3740 | 3740 |
| 3741 | 3741 | if (GetDebugSignalHandlerMappingName(pid, | 3742 | 3742 | mapping_name, | 3743 | | - ARRAY_SIZE(mapping_name)) < 0) { | | 3743 | + arraysize(mapping_name)) < 0) { | 3744 | 3744 | env->ThrowErrnoException(errno, "sprintf"); | 3745 | 3745 | goto out; | 3746 | 3746 | } | @@ -4017,7 +4017,7 @@ void EmitBeforeExit(Environment* env) { | 4017 | 4017 | FIXED_ONE_BYTE_STRING(env->isolate(), "beforeExit"), | 4018 | 4018 | process_object->Get(exit_code)->ToInteger(env->isolate()) | 4019 | 4019 | }; | 4020 | | - MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); | | 4020 | + MakeCallback(env, process_object, "emit", arraysize(args), args); | 4021 | 4021 | } | 4022 | 4022 |
| 4023 | 4023 |
| @@ -4036,7 +4036,7 @@ int EmitExit(Environment* env) { | 4036 | 4036 | Integer::New(env->isolate(), code) | 4037 | 4037 | }; | 4038 | 4038 |
| 4039 | | - MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); | | 4039 | + MakeCallback(env, process_object, "emit", arraysize(args), args); | 4040 | 4040 |
| 4041 | 4041 | // Reload exit code, it may be changed by `emit('exit')` | 4042 | 4042 | return process_object->Get(exitCode)->Int32Value(); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_contextify.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -163,7 +163,7 @@ class ContextifyContext { | 163 | 163 | CHECK(clone_property_method->IsFunction()); | 164 | 164 | } | 165 | 165 | Local<Value> args[] = { global, key, sandbox_obj }; | 166 | | - clone_property_method->Call(global, ARRAY_SIZE(args), args); | | 166 | + clone_property_method->Call(global, arraysize(args), args); | 167 | 167 | } | 168 | 168 | } | 169 | 169 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_counters.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,7 +98,7 @@ void InitPerfCounters(Environment* env, Local<Object> target) { | 98 | 98 | #undef NODE_PROBE | 99 | 99 | }; | 100 | 100 |
| 101 | | - for (int i = 0; i < ARRAY_SIZE(tab); i++) { | | 101 | + for (size_t i = 0; i < arraysize(tab); i++) { | 102 | 102 | Local<String> key = OneByteString(env->isolate(), tab[i].name); | 103 | 103 | Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); | 104 | 104 | target->Set(key, val); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_crypto.cc +11-11Lines changed: 11 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -752,7 +752,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { | 752 | 752 | if (!root_cert_store) { | 753 | 753 | root_cert_store = X509_STORE_new(); | 754 | 754 |
| 755 | | - for (size_t i = 0; i < ARRAY_SIZE(root_certs); i++) { | | 755 | + for (size_t i = 0; i < arraysize(root_certs); i++) { | 756 | 756 | BIO* bp = NodeBIO::NewFixed(root_certs[i], strlen(root_certs[i])); | 757 | 757 | if (bp == nullptr) { | 758 | 758 | return; | @@ -1084,7 +1084,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl, | 1084 | 1084 | Local<Value> ret = node::MakeCallback(env, | 1085 | 1085 | sc->object(), | 1086 | 1086 | env->ticketkeycallback_string(), | 1087 | | - ARRAY_SIZE(argv), | | 1087 | + arraysize(argv), | 1088 | 1088 | argv); | 1089 | 1089 | Local<Array> arr = ret.As<Array>(); | 1090 | 1090 |
| @@ -1281,7 +1281,7 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) { | 1281 | 1281 | sess->session_id_length).ToLocalChecked(); | 1282 | 1282 | Local<Value> argv[] = { session, buff }; | 1283 | 1283 | w->new_session_wait_ = true; | 1284 | | - w->MakeCallback(env->onnewsession_string(), ARRAY_SIZE(argv), argv); | | 1284 | + w->MakeCallback(env->onnewsession_string(), arraysize(argv), argv); | 1285 | 1285 |
| 1286 | 1286 | return 0; | 1287 | 1287 | } | @@ -1315,7 +1315,7 @@ void SSLWrap<Base>::OnClientHello(void* arg, | 1315 | 1315 | Boolean::New(env->isolate(), hello.ocsp_request())); | 1316 | 1316 |
| 1317 | 1317 | Local<Value> argv[] = { hello_obj }; | 1318 | | - w->MakeCallback(env->onclienthello_string(), ARRAY_SIZE(argv), argv); | | 1318 | + w->MakeCallback(env->onclienthello_string(), arraysize(argv), argv); | 1319 | 1319 | } | 1320 | 1320 |
| 1321 | 1321 |
| @@ -1390,8 +1390,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { | 1390 | 1390 | int nids[] = { NID_subject_alt_name, NID_info_access }; | 1391 | 1391 | Local<String> keys[] = { env->subjectaltname_string(), | 1392 | 1392 | env->infoaccess_string() }; | 1393 | | - CHECK_EQ(ARRAY_SIZE(nids), ARRAY_SIZE(keys)); | 1394 | | - for (unsigned int i = 0; i < ARRAY_SIZE(nids); i++) { | | 1393 | + CHECK_EQ(arraysize(nids), arraysize(keys)); | | 1394 | + for (size_t i = 0; i < arraysize(nids); i++) { | 1395 | 1395 | int index = X509_get_ext_by_NID(cert, nids[i], -1); | 1396 | 1396 | if (index < 0) | 1397 | 1397 | continue; | @@ -2282,7 +2282,7 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) { | 2282 | 2282 | info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp)); | 2283 | 2283 |
| 2284 | 2284 | Local<Value> argv[] = { info }; | 2285 | | - w->MakeCallback(env->oncertcb_string(), ARRAY_SIZE(argv), argv); | | 2285 | + w->MakeCallback(env->oncertcb_string(), arraysize(argv), argv); | 2286 | 2286 |
| 2287 | 2287 | if (!w->cert_cb_running_) | 2288 | 2288 | return 1; | @@ -2645,7 +2645,7 @@ inline CheckResult CheckWhitelistedServerCert(X509_STORE_CTX* ctx) { | 2645 | 2645 | CHECK(ret); | 2646 | 2646 |
| 2647 | 2647 | void* result = bsearch(hash, WhitelistedCNNICHashes, | 2648 | | - ARRAY_SIZE(WhitelistedCNNICHashes), | | 2648 | + arraysize(WhitelistedCNNICHashes), | 2649 | 2649 | CNNIC_WHITELIST_HASH_LEN, compar); | 2650 | 2650 | if (result == nullptr) { | 2651 | 2651 | sk_X509_pop_free(chain, X509_free); | @@ -4383,7 +4383,7 @@ void DiffieHellman::DiffieHellmanGroup( | 4383 | 4383 | bool initialized = false; | 4384 | 4384 |
| 4385 | 4385 | const node::Utf8Value group_name(env->isolate(), args[0]); | 4386 | | - for (unsigned int i = 0; i < ARRAY_SIZE(modp_groups); ++i) { | | 4386 | + for (size_t i = 0; i < arraysize(modp_groups); ++i) { | 4387 | 4387 | const modp_group* it = modp_groups + i; | 4388 | 4388 |
| 4389 | 4389 | if (strcasecmp(*group_name, it->name) != 0) | @@ -5086,7 +5086,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) { | 5086 | 5086 | Context::Scope context_scope(env->context()); | 5087 | 5087 | Local<Value> argv[2]; | 5088 | 5088 | EIO_PBKDF2After(req, argv); | 5089 | | - req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv); | | 5089 | + req->MakeCallback(env->ondone_string(), arraysize(argv), argv); | 5090 | 5090 | delete req; | 5091 | 5091 | } | 5092 | 5092 |
| @@ -5327,7 +5327,7 @@ void RandomBytesAfter(uv_work_t* work_req, int status) { | 5327 | 5327 | Context::Scope context_scope(env->context()); | 5328 | 5328 | Local<Value> argv[2]; | 5329 | 5329 | RandomBytesCheck(req, argv); | 5330 | | - req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv); | | 5330 | + req->MakeCallback(env->ondone_string(), arraysize(argv), argv); | 5331 | 5331 | delete req; | 5332 | 5332 | } | 5333 | 5333 |
| |
|