Skip to content

Commit

Permalink
src: update MaybeInitializeContext to return MaybeLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jul 22, 2019
1 parent 98b6cf5 commit 2dcfc04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,13 @@ Local<Context> NewContext(Isolate* isolate,
auto context = Context::New(isolate, nullptr, object_template);
if (context.IsEmpty()) return context;

return MaybeInitializeContext(context, object_template);
if (!InitializeContext(context)) {
return Local<Context>();
}
return context;
}

Local<Context> MaybeInitializeContext(Local<Context> context,
Local<ObjectTemplate> object_template) {
bool InitializeContext(Local<Context> context) {
Isolate* isolate = context->GetIsolate();
HandleScope handle_scope(isolate);

Expand All @@ -389,7 +391,7 @@ Local<Context> MaybeInitializeContext(Local<Context> context,
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",
Expand All @@ -405,7 +407,7 @@ Local<Context> MaybeInitializeContext(Local<Context> context,
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 =
Expand All @@ -414,12 +416,12 @@ Local<Context> MaybeInitializeContext(Local<Context> context,
// 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) {
Expand Down
6 changes: 2 additions & 4 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ NODE_EXTERN v8::Local<v8::Context> NewContext(
v8::Local<v8::ObjectTemplate>());

// Runs Node.js-specific tweaks on an already constructed context
NODE_EXTERN v8::Local<v8::Context> MaybeInitializeContext(
v8::Local<v8::Context> context,
v8::Local<v8::ObjectTemplate> object_template =
v8::Local<v8::ObjectTemplate>());
// 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
Expand Down

0 comments on commit 2dcfc04

Please sign in to comment.