diff options
author | Darshan Sen <darshan.sen@postman.com> | 2021-07-31 09:23:45 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-08-06 22:43:49 +0300 |
commit | 0a7f850123f1b85010e0e91ce6ea1af69a20a010 (patch) | |
tree | a8724da2936d037062683ce32d4b2c1117004884 /src/api | |
parent | 26632c96a637e11759e6393ff68aeec1428468d7 (diff) |
src: return Maybe from a couple of functions
Functions affected:
* InitializeContext()
* InitializeContextForSnapshot()
* InitializePrimordials()
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
PR-URL: https://github.com/nodejs/node/pull/39603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
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 | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index bd9de560d08..2b9eab2bc0b 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -20,8 +20,11 @@ using v8::Function; using v8::FunctionCallbackInfo; using v8::HandleScope; using v8::Isolate; +using v8::Just; using v8::Local; +using v8::Maybe; using v8::MaybeLocal; +using v8::Nothing; using v8::Null; using v8::Object; using v8::ObjectTemplate; @@ -501,7 +504,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).IsNothing()) return MaybeLocal<Object>(); return handle_scope.Escape(exports); } @@ -514,7 +517,7 @@ Local<Context> NewContext(Isolate* isolate, auto context = Context::New(isolate, nullptr, object_template); if (context.IsEmpty()) return context; - if (!InitializeContext(context)) { + if (InitializeContext(context).IsNothing()) { return Local<Context>(); } @@ -581,16 +584,17 @@ void InitializeContextRuntime(Local<Context> context) { } } -bool InitializeContextForSnapshot(Local<Context> context) { +Maybe<bool> InitializeContextForSnapshot(Local<Context> context) { Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration, True(isolate)); + return InitializePrimordials(context); } -bool InitializePrimordials(Local<Context> context) { +Maybe<bool> InitializePrimordials(Local<Context> context) { // Run per-context JS files. Isolate* isolate = context->GetIsolate(); Context::Scope context_scope(context); @@ -603,10 +607,10 @@ bool InitializePrimordials(Local<Context> context) { // Create primordials first and make it available to per-context scripts. Local<Object> primordials = Object::New(isolate); - if (!primordials->SetPrototype(context, Null(isolate)).FromJust() || + if (primordials->SetPrototype(context, Null(isolate)).IsNothing() || !GetPerContextExports(context).ToLocal(&exports) || - !exports->Set(context, primordials_string, primordials).FromJust()) { - return false; + exports->Set(context, primordials_string, primordials).IsNothing()) { + return Nothing<bool>(); } static const char* context_files[] = {"internal/per_context/primordials", @@ -623,27 +627,27 @@ bool InitializePrimordials(Local<Context> context) { context, *module, ¶meters, nullptr); Local<Function> fn; if (!maybe_fn.ToLocal(&fn)) { - return false; + return Nothing<bool>(); } 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 Nothing<bool>(); } } - return true; + return Just(true); } -bool InitializeContext(Local<Context> context) { - if (!InitializeContextForSnapshot(context)) { - return false; +Maybe<bool> InitializeContext(Local<Context> context) { + if (InitializeContextForSnapshot(context).IsNothing()) { + return Nothing<bool>(); } InitializeContextRuntime(context); - return true; + + return Just(true); } uv_loop_t* GetCurrentEventLoop(Isolate* isolate) { |