| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5c5d881 commit 5d5c3fa
15 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -681,12 +681,16 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb, | |||
| 681 | 681 | ||
| 682 | 682 | ||
| 683 | 683 | async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) { | |
| 684 | - return Environment::GetCurrent(isolate)->execution_async_id(); | ||
| 684 | + Environment* env = Environment::GetCurrent(isolate); | ||
| 685 | + if (env == nullptr) return -1; | ||
| 686 | + return env->execution_async_id(); | ||
| 685 | 687 | } | |
| 686 | 688 | ||
| 687 | 689 | ||
| 688 | 690 | async_id AsyncHooksGetTriggerAsyncId(Isolate* isolate) { | |
| 689 | - return Environment::GetCurrent(isolate)->trigger_async_id(); | ||
| 691 | + Environment* env = Environment::GetCurrent(isolate); | ||
| 692 | + if (env == nullptr) return -1; | ||
| 693 | + return env->trigger_async_id(); | ||
| 690 | 694 | } | |
| 691 | 695 | ||
| 692 | 696 | ||
@@ -705,6 +709,7 @@ async_context EmitAsyncInit(Isolate* isolate, | |||
| 705 | 709 | v8::Local<v8::String> name, | |
| 706 | 710 | async_id trigger_async_id) { | |
| 707 | 711 | Environment* env = Environment::GetCurrent(isolate); | |
| 712 | + CHECK_NOT_NULL(env); | ||
| 708 | 713 | ||
| 709 | 714 | // Initialize async context struct | |
| 710 | 715 | if (trigger_async_id == -1) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,6 +61,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) { | |||
| 61 | 61 | PromiseRejectEvent event = message.GetEvent(); | |
| 62 | 62 | ||
| 63 | 63 | Environment* env = Environment::GetCurrent(isolate); | |
| 64 | + if (env == nullptr) return; | ||
| 64 | 65 | Local<Function> callback; | |
| 65 | 66 | Local<Value> value; | |
| 66 | 67 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, | |||
| 43 | 43 | object_(object), | |
| 44 | 44 | callback_scope_(env) { | |
| 45 | 45 | CHECK_IMPLIES(expect == kRequireResource, !object.IsEmpty()); | |
| 46 | + CHECK_NOT_NULL(env); | ||
| 46 | 47 | ||
| 47 | 48 | if (!env->can_call_into_js()) { | |
| 48 | 49 | failed_ = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -302,6 +302,15 @@ inline Environment* Environment::GetCurrent(v8::Isolate* isolate) { | |||
| 302 | 302 | } | |
| 303 | 303 | ||
| 304 | 304 | inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) { | |
| 305 | + if (UNLIKELY(context.IsEmpty() || | ||
| 306 | + context->GetNumberOfEmbedderDataFields() < | ||
| 307 | + ContextEmbedderIndex::kContextTag || | ||
| 308 | + context->GetAlignedPointerFromEmbedderData( | ||
| 309 | + ContextEmbedderIndex::kContextTag) != | ||
| 310 | + Environment::kNodeContextTagPtr)) { | ||
| 311 | + return nullptr; | ||
| 312 | + } | ||
| 313 | + | ||
| 305 | 314 | return static_cast<Environment*>( | |
| 306 | 315 | context->GetAlignedPointerFromEmbedderData( | |
| 307 | 316 | ContextEmbedderIndex::kEnvironment)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -449,18 +449,9 @@ void Environment::EnvPromiseHook(v8::PromiseHookType type, | |||
| 449 | 449 | v8::Local<v8::Value> parent) { | |
| 450 | 450 | Local<v8::Context> context = promise->CreationContext(); | |
| 451 | 451 | ||
| 452 | - // Grow the embedder data if necessary to make sure we are not out of bounds | ||
| 453 | - // when reading the magic number. | ||
| 454 | - context->SetAlignedPointerInEmbedderData( | ||
| 455 | - ContextEmbedderIndex::kContextTagBoundary, nullptr); | ||
| 456 | - int* magicNumberPtr = reinterpret_cast<int*>( | ||
| 457 | - context->GetAlignedPointerFromEmbedderData( | ||
| 458 | - ContextEmbedderIndex::kContextTag)); | ||
| 459 | - if (magicNumberPtr != Environment::kNodeContextTagPtr) { | ||
| 460 | - return; | ||
| 461 | - } | ||
| 462 | - | ||
| 463 | 452 | Environment* env = Environment::GetCurrent(context); | |
| 453 | + if (env == nullptr) return; | ||
| 454 | + | ||
| 464 | 455 | for (const PromiseHookCallback& hook : env->promise_hooks_) { | |
| 465 | 456 | hook.cb_(type, promise, parent, hook.arg_); | |
| 466 | 457 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,12 +149,11 @@ void CallAndPauseOnStart(const FunctionCallbackInfo<v8::Value>& args) { | |||
| 149 | 149 | } | |
| 150 | 150 | ||
| 151 | 151 | void InspectorConsoleCall(const FunctionCallbackInfo<Value>& info) { | |
| 152 | - Isolate* isolate = info.GetIsolate(); | ||
| 153 | - HandleScope handle_scope(isolate); | ||
| 152 | + Environment* env = Environment::GetCurrent(info); | ||
| 153 | + Isolate* isolate = env->isolate(); | ||
| 154 | 154 | Local<Context> context = isolate->GetCurrentContext(); | |
| 155 | 155 | CHECK_LT(2, info.Length()); | |
| 156 | 156 | SlicedArguments call_args(info, /* start */ 3); | |
| 157 | - Environment* env = Environment::GetCurrent(isolate); | ||
| 158 | 157 | if (InspectorEnabled(env)) { | |
| 159 | 158 | Local<Value> inspector_method = info[0]; | |
| 160 | 159 | CHECK(inspector_method->IsFunction()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -362,6 +362,7 @@ MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context, | |||
| 362 | 362 | Local<String> specifier, | |
| 363 | 363 | Local<Module> referrer) { | |
| 364 | 364 | Environment* env = Environment::GetCurrent(context); | |
| 365 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 365 | 366 | Isolate* isolate = env->isolate(); | |
| 366 | 367 | if (env->module_map.count(referrer->GetIdentityHash()) == 0) { | |
| 367 | 368 | env->ThrowError("linking error, unknown module"); | |
@@ -700,6 +701,7 @@ static MaybeLocal<Promise> ImportModuleDynamically( | |||
| 700 | 701 | Local<String> specifier) { | |
| 701 | 702 | Isolate* iso = context->GetIsolate(); | |
| 702 | 703 | Environment* env = Environment::GetCurrent(context); | |
| 704 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 703 | 705 | v8::EscapableHandleScope handle_scope(iso); | |
| 704 | 706 | ||
| 705 | 707 | if (env->context() != context) { | |
@@ -750,8 +752,8 @@ void ModuleWrap::SetImportModuleDynamicallyCallback( | |||
| 750 | 752 | ||
| 751 | 753 | void ModuleWrap::HostInitializeImportMetaObjectCallback( | |
| 752 | 754 | Local<Context> context, Local<Module> module, Local<Object> meta) { | |
| 753 | - Isolate* isolate = context->GetIsolate(); | ||
| 754 | 755 | Environment* env = Environment::GetCurrent(context); | |
| 756 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 755 | 757 | ModuleWrap* module_wrap = GetFromModule(env, module); | |
| 756 | 758 | ||
| 757 | 759 | if (module_wrap == nullptr) { | |
@@ -762,7 +764,7 @@ void ModuleWrap::HostInitializeImportMetaObjectCallback( | |||
| 762 | 764 | Local<Function> callback = | |
| 763 | 765 | env->host_initialize_import_meta_object_callback(); | |
| 764 | 766 | Local<Value> args[] = { wrap, meta }; | |
| 765 | - callback->Call(context, Undefined(isolate), arraysize(args), args) | ||
| 767 | + callback->Call(context, Undefined(env->isolate()), arraysize(args), args) | ||
| 766 | 768 | .ToLocalChecked(); | |
| 767 | 769 | } | |
| 768 | 770 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -630,7 +630,8 @@ namespace { | |||
| 630 | 630 | bool ShouldAbortOnUncaughtException(Isolate* isolate) { | |
| 631 | 631 | HandleScope scope(isolate); | |
| 632 | 632 | Environment* env = Environment::GetCurrent(isolate); | |
| 633 | - return env->should_abort_on_uncaught_toggle()[0] && | ||
| 633 | + return env != nullptr && | ||
| 634 | + env->should_abort_on_uncaught_toggle()[0] && | ||
| 634 | 635 | !env->inside_should_not_abort_on_uncaught_scope(); | |
| 635 | 636 | } | |
| 636 | 637 | ||
@@ -639,13 +640,15 @@ bool ShouldAbortOnUncaughtException(Isolate* isolate) { | |||
| 639 | 640 | ||
| 640 | 641 | void AddPromiseHook(Isolate* isolate, promise_hook_func fn, void* arg) { | |
| 641 | 642 | Environment* env = Environment::GetCurrent(isolate); | |
| 643 | + CHECK_NOT_NULL(env); | ||
| 642 | 644 | env->AddPromiseHook(fn, arg); | |
| 643 | 645 | } | |
| 644 | 646 | ||
| 645 | 647 | void AddEnvironmentCleanupHook(Isolate* isolate, | |
| 646 | 648 | void (*fun)(void* arg), | |
| 647 | 649 | void* arg) { | |
| 648 | 650 | Environment* env = Environment::GetCurrent(isolate); | |
| 651 | + CHECK_NOT_NULL(env); | ||
| 649 | 652 | env->AddCleanupHook(fun, arg); | |
| 650 | 653 | } | |
| 651 | 654 | ||
@@ -654,6 +657,7 @@ void RemoveEnvironmentCleanupHook(Isolate* isolate, | |||
| 654 | 657 | void (*fun)(void* arg), | |
| 655 | 658 | void* arg) { | |
| 656 | 659 | Environment* env = Environment::GetCurrent(isolate); | |
| 660 | + CHECK_NOT_NULL(env); | ||
| 657 | 661 | env->RemoveCleanupHook(fun, arg); | |
| 658 | 662 | } | |
| 659 | 663 | ||
@@ -738,6 +742,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate, | |||
| 738 | 742 | // Because of the AssignToContext() call in src/node_contextify.cc, | |
| 739 | 743 | // the two contexts need not be the same. | |
| 740 | 744 | Environment* env = Environment::GetCurrent(callback->CreationContext()); | |
| 745 | + CHECK_NOT_NULL(env); | ||
| 741 | 746 | Context::Scope context_scope(env->context()); | |
| 742 | 747 | MaybeLocal<Value> ret = InternalMakeCallback(env, recv, callback, | |
| 743 | 748 | argc, argv, asyncContext); | |
@@ -1376,6 +1381,7 @@ void FatalException(Isolate* isolate, | |||
| 1376 | 1381 | HandleScope scope(isolate); | |
| 1377 | 1382 | ||
| 1378 | 1383 | Environment* env = Environment::GetCurrent(isolate); | |
| 1384 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 1379 | 1385 | Local<Object> process_object = env->process_object(); | |
| 1380 | 1386 | Local<String> fatal_exception_string = env->fatal_exception_string(); | |
| 1381 | 1387 | Local<Value> fatal_exception_function = | |
@@ -1601,7 +1607,7 @@ static void GetInternalBinding(const FunctionCallbackInfo<Value>& args) { | |||
| 1601 | 1607 | } | |
| 1602 | 1608 | ||
| 1603 | 1609 | static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) { | |
| 1604 | - Environment* env = Environment::GetCurrent(args.GetIsolate()); | ||
| 1610 | + Environment* env = Environment::GetCurrent(args); | ||
| 1605 | 1611 | ||
| 1606 | 1612 | CHECK(args[0]->IsString()); | |
| 1607 | 1613 | ||
@@ -2705,10 +2711,13 @@ void RunAtExit(Environment* env) { | |||
| 2705 | 2711 | ||
| 2706 | 2712 | uv_loop_t* GetCurrentEventLoop(Isolate* isolate) { | |
| 2707 | 2713 | HandleScope handle_scope(isolate); | |
| 2708 | - auto context = isolate->GetCurrentContext(); | ||
| 2714 | + Local<Context> context = isolate->GetCurrentContext(); | ||
| 2709 | 2715 | if (context.IsEmpty()) | |
| 2710 | 2716 | return nullptr; | |
| 2711 | - return Environment::GetCurrent(context)->event_loop(); | ||
| 2717 | + Environment* env = Environment::GetCurrent(context); | ||
| 2718 | + if (env == nullptr) | ||
| 2719 | + return nullptr; | ||
| 2720 | + return env->event_loop(); | ||
| 2712 | 2721 | } | |
| 2713 | 2722 | ||
| 2714 | 2723 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -946,7 +946,7 @@ class ThreadSafeFunction : public node::AsyncResource { | |||
| 946 | 946 | return napi_ok; | |
| 947 | 947 | } | |
| 948 | 948 | ||
| 949 | - node::Environment::GetCurrent(env->isolate)->CloseHandle( | ||
| 949 | + NodeEnv()->CloseHandle( | ||
| 950 | 950 | reinterpret_cast<uv_handle_t*>(&async), | |
| 951 | 951 | [](uv_handle_t* handle) -> void { | |
| 952 | 952 | ThreadSafeFunction* ts_fn = | |
@@ -1036,9 +1036,12 @@ class ThreadSafeFunction : public node::AsyncResource { | |||
| 1036 | 1036 | } | |
| 1037 | 1037 | ||
| 1038 | 1038 | node::Environment* NodeEnv() { | |
| 1039 | - // For some reason grabbing the Node.js environment requires a handle scope. | ||
| 1039 | + // Grabbing the Node.js environment requires a handle scope because it | ||
| 1040 | + // looks up fields on the current context. | ||
| 1040 | 1041 | v8::HandleScope scope(env->isolate); | |
| 1041 | - return node::Environment::GetCurrent(env->isolate); | ||
| 1042 | + node::Environment* node_env = node::Environment::GetCurrent(env->isolate); | ||
| 1043 | + CHECK_NOT_NULL(node_env); | ||
| 1044 | + return node_env; | ||
| 1042 | 1045 | } | |
| 1043 | 1046 | ||
| 1044 | 1047 | void MaybeStartIdle() { | |
@@ -1234,7 +1237,9 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports, | |||
| 1234 | 1237 | v8::Local<v8::Context> context, | |
| 1235 | 1238 | napi_addon_register_func init) { | |
| 1236 | 1239 | if (init == nullptr) { | |
| 1237 | - node::Environment::GetCurrent(context)->ThrowError( | ||
| 1240 | + node::Environment* node_env = node::Environment::GetCurrent(context); | ||
| 1241 | + CHECK_NOT_NULL(node_env); | ||
| 1242 | + node_env->ThrowError( | ||
| 1238 | 1243 | "Module has no declared entry point."); | |
| 1239 | 1244 | return; | |
| 1240 | 1245 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -274,7 +274,9 @@ MaybeLocal<Object> New(Isolate* isolate, | |||
| 274 | 274 | MaybeLocal<Object> New(Isolate* isolate, size_t length) { | |
| 275 | 275 | EscapableHandleScope handle_scope(isolate); | |
| 276 | 276 | Local<Object> obj; | |
| 277 | - if (Buffer::New(Environment::GetCurrent(isolate), length).ToLocal(&obj)) | ||
| 277 | + Environment* env = Environment::GetCurrent(isolate); | ||
| 278 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 279 | + if (Buffer::New(env, length).ToLocal(&obj)) | ||
| 278 | 280 | return handle_scope.Escape(obj); | |
| 279 | 281 | return Local<Object>(); | |
| 280 | 282 | } | |
@@ -316,6 +318,7 @@ MaybeLocal<Object> New(Environment* env, size_t length) { | |||
| 316 | 318 | MaybeLocal<Object> Copy(Isolate* isolate, const char* data, size_t length) { | |
| 317 | 319 | EscapableHandleScope handle_scope(isolate); | |
| 318 | 320 | Environment* env = Environment::GetCurrent(isolate); | |
| 321 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 319 | 322 | Local<Object> obj; | |
| 320 | 323 | if (Buffer::Copy(env, data, length).ToLocal(&obj)) | |
| 321 | 324 | return handle_scope.Escape(obj); | |
@@ -365,6 +368,7 @@ MaybeLocal<Object> New(Isolate* isolate, | |||
| 365 | 368 | void* hint) { | |
| 366 | 369 | EscapableHandleScope handle_scope(isolate); | |
| 367 | 370 | Environment* env = Environment::GetCurrent(isolate); | |
| 371 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 368 | 372 | Local<Object> obj; | |
| 369 | 373 | if (Buffer::New(env, data, length, callback, hint).ToLocal(&obj)) | |
| 370 | 374 | return handle_scope.Escape(obj); | |
@@ -403,6 +407,7 @@ MaybeLocal<Object> New(Environment* env, | |||
| 403 | 407 | MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) { | |
| 404 | 408 | EscapableHandleScope handle_scope(isolate); | |
| 405 | 409 | Environment* env = Environment::GetCurrent(isolate); | |
| 410 | + CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | ||
| 406 | 411 | Local<Object> obj; | |
| 407 | 412 | if (Buffer::New(env, data, length).ToLocal(&obj)) | |
| 408 | 413 | return handle_scope.Escape(obj); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments