diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-07 15:12:52 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-15 16:54:19 +0100 |
commit | 7e2088f773d97e00e29cacdc20e1a36b80528be0 (patch) | |
tree | 5c99263864c7cf624c4fc3093e0df5429c95fda1 /src/api/environment.cc | |
parent | 0752a18b88452fd0cbf554856dc5305076cb9da5 (diff) | |
download | android-node-v8-7e2088f773d97e00e29cacdc20e1a36b80528be0.tar.gz android-node-v8-7e2088f773d97e00e29cacdc20e1a36b80528be0.tar.bz2 android-node-v8-7e2088f773d97e00e29cacdc20e1a36b80528be0.zip |
src,lib: allow running multiple per-context files
Create an `lib/internal/per_context/` directory that can
host multiple files which we execute for each context.
PR-URL: https://github.com/nodejs/node/pull/26497
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/api/environment.cc')
-rw-r--r-- | src/api/environment.cc | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index 9b8e468685..c4a8120d1c 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -289,25 +289,33 @@ Local<Context> NewContext(Isolate* isolate, True(isolate)); { - // Run lib/internal/bootstrap/context.js + // Run per-context JS files. Context::Scope context_scope(context); - std::vector<Local<String>> parameters = { - FIXED_ONE_BYTE_STRING(isolate, "global")}; - Local<Value> arguments[] = {context->Global()}; - MaybeLocal<Function> maybe_fn = - per_process::native_module_loader.LookupAndCompile( - context, "internal/bootstrap/context", ¶meters, nullptr); - if (maybe_fn.IsEmpty()) { - return Local<Context>(); - } - Local<Function> fn = maybe_fn.ToLocalChecked(); - 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 Local<Context>(); + static const char* context_files[] = { + "internal/per_context/setup", + nullptr + }; + + for (const char** module = context_files; *module != nullptr; module++) { + std::vector<Local<String>> parameters = { + FIXED_ONE_BYTE_STRING(isolate, "global")}; + Local<Value> arguments[] = {context->Global()}; + MaybeLocal<Function> maybe_fn = + per_process::native_module_loader.LookupAndCompile( + context, *module, ¶meters, nullptr); + if (maybe_fn.IsEmpty()) { + return Local<Context>(); + } + Local<Function> fn = maybe_fn.ToLocalChecked(); + 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 Local<Context>(); + } } } |