diff options
author | Samuel Attard <sattard@slack-corp.com> | 2019-07-04 15:57:09 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-26 18:24:10 -0700 |
commit | 33ae95c58da835086e6f9581715208c2d6ecfd70 (patch) | |
tree | 0dad8c23cfae53f23343f427469509ab59a9b901 /src/api | |
parent | d770b8a931bd5a407e75d094829a42833d96f004 (diff) | |
download | android-node-v8-33ae95c58da835086e6f9581715208c2d6ecfd70.tar.gz android-node-v8-33ae95c58da835086e6f9581715208c2d6ecfd70.tar.bz2 android-node-v8-33ae95c58da835086e6f9581715208c2d6ecfd70.zip |
src: expose MaybeInitializeContext to allow existing contexts
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a Node.js Environment now that primordials are
initialized and required so early.
Update MaybeInitializeContext to return MaybeLocal,
PR-URL: https://github.com/nodejs/node/pull/28544
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/environment.cc | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index ac1e513967..7fd219d6e8 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -353,6 +353,15 @@ Local<Context> NewContext(Isolate* isolate, Local<ObjectTemplate> object_template) { auto context = Context::New(isolate, nullptr, object_template); if (context.IsEmpty()) return context; + + if (!InitializeContext(context)) { + return Local<Context>(); + } + return context; +} + +bool InitializeContext(Local<Context> context) { + Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration, @@ -373,7 +382,7 @@ Local<Context> NewContext(Isolate* isolate, if (!primordials->SetPrototype(context, Null(isolate)).FromJust() || !GetPerContextExports(context).ToLocal(&exports) || !exports->Set(context, primordials_string, primordials).FromJust()) { - return Local<Context>(); + return false; } static const char* context_files[] = {"internal/per_context/primordials", @@ -389,7 +398,7 @@ Local<Context> NewContext(Isolate* isolate, native_module::NativeModuleEnv::LookupAndCompile( context, *module, ¶meters, nullptr); if (maybe_fn.IsEmpty()) { - return Local<Context>(); + return false; } Local<Function> fn = maybe_fn.ToLocalChecked(); MaybeLocal<Value> result = @@ -398,12 +407,12 @@ Local<Context> NewContext(Isolate* isolate, // Execution failed during context creation. // TODO(joyeecheung): deprecate this signature and return a MaybeLocal. if (result.IsEmpty()) { - return Local<Context>(); + return false; } } } - return context; + return true; } uv_loop_t* GetCurrentEventLoop(Isolate* isolate) { |