summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/api/environment.cc17
-rw-r--r--src/node.h4
2 files changed, 17 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, &parameters, 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) {
diff --git a/src/node.h b/src/node.h
index f79a518b0f..d5c3c2a667 100644
--- a/src/node.h
+++ b/src/node.h
@@ -305,6 +305,10 @@ NODE_EXTERN v8::Local<v8::Context> NewContext(
v8::Local<v8::ObjectTemplate> object_template =
v8::Local<v8::ObjectTemplate>());
+// Runs Node.js-specific tweaks on an already constructed context
+// Return value indicates success of operation
+NODE_EXTERN bool InitializeContext(v8::Local<v8::Context> context);
+
// If `platform` is passed, it will be used to register new Worker instances.
// It can be `nullptr`, in which case creating new Workers inside of
// Environments that use this `IsolateData` will not work.