Skip to content

Commit

Permalink
src: return MaybeLocal from InitializePrimordials
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
  • Loading branch information
RaisinTen committed Jul 31, 2021
1 parent 8be3b91 commit a77d745
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {

Local<Object> exports = Object::New(isolate);
if (context->Global()->SetPrivate(context, key, exports).IsNothing() ||
!InitializePrimordials(context))
InitializePrimordials(context).IsEmpty())
return MaybeLocal<Object>();
return handle_scope.Escape(exports);
}
Expand Down Expand Up @@ -587,10 +587,10 @@ bool InitializeContextForSnapshot(Local<Context> context) {

context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration,
True(isolate));
return InitializePrimordials(context);
return !InitializePrimordials(context).IsEmpty();
}

bool InitializePrimordials(Local<Context> context) {
MaybeLocal<Object> InitializePrimordials(Local<Context> context) {
// Run per-context JS files.
Isolate* isolate = context->GetIsolate();
Context::Scope context_scope(context);
Expand All @@ -606,7 +606,7 @@ bool InitializePrimordials(Local<Context> context) {
if (!primordials->SetPrototype(context, Null(isolate)).FromJust() ||
!GetPerContextExports(context).ToLocal(&exports) ||
!exports->Set(context, primordials_string, primordials).FromJust()) {
return false;
return MaybeLocal<Object>();
}

static const char* context_files[] = {"internal/per_context/primordials",
Expand All @@ -623,18 +623,17 @@ bool InitializePrimordials(Local<Context> context) {
context, *module, &parameters, nullptr);
Local<Function> fn;
if (!maybe_fn.ToLocal(&fn)) {
return false;
return MaybeLocal<Object>();
}
MaybeLocal<Value> result =
fn->Call(context, Undefined(isolate), arraysize(arguments), arguments);
// Execution failed during context creation.
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
if (result.IsEmpty()) {
return false;
return MaybeLocal<Object>();
}
}

return true;
return primordials;
}

bool InitializeContext(Local<Context> context) {
Expand Down
5 changes: 3 additions & 2 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ void SignalExit(int signal, siginfo_t* info, void* ucontext);
std::string GetProcessTitle(const char* default_title);
std::string GetHumanReadableProcessName();

void InitializeContextRuntime(v8::Local<v8::Context>);
bool InitializePrimordials(v8::Local<v8::Context> context);
void InitializeContextRuntime(v8::Local<v8::Context> context);
v8::MaybeLocal<v8::Object> InitializePrimordials(
v8::Local<v8::Context> context);

class NodeArrayBufferAllocator : public ArrayBufferAllocator {
public:
Expand Down

0 comments on commit a77d745

Please sign in to comment.