src,lib: allow running multiple per-context files · nodejs/node@e044563 (original) (raw)
`@@ -259,25 +259,33 @@ Local NewContext(Isolate* isolate,
`
259
259
`True(isolate));
`
260
260
``
261
261
` {
`
262
``
`-
// Run lib/internal/bootstrap/context.js
`
``
262
`+
// Run per-context JS files.
`
263
263
` Context::Scope context_scope(context);
`
264
264
``
265
``
`-
std::vector<Local> parameters = {
`
266
``
`-
FIXED_ONE_BYTE_STRING(isolate, "global")};
`
267
``
`-
Local arguments[] = {context->Global()};
`
268
``
`-
MaybeLocal maybe_fn =
`
269
``
`-
per_process::native_module_loader.LookupAndCompile(
`
270
``
`-
context, "internal/bootstrap/context", ¶meters, nullptr);
`
271
``
`-
if (maybe_fn.IsEmpty()) {
`
272
``
`-
return Local();
`
273
``
`-
}
`
274
``
`-
Local fn = maybe_fn.ToLocalChecked();
`
275
``
`-
MaybeLocal result =
`
276
``
`-
fn->Call(context, Undefined(isolate), arraysize(arguments), arguments);
`
277
``
`-
// Execution failed during context creation.
`
278
``
`-
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
`
279
``
`-
if (result.IsEmpty()) {
`
280
``
`-
return Local();
`
``
265
`+
static const char* context_files[] = {
`
``
266
`+
"internal/per_context/setup",
`
``
267
`+
nullptr
`
``
268
`+
};
`
``
269
+
``
270
`+
for (const char** module = context_files; *module != nullptr; module++) {
`
``
271
`+
std::vector<Local> parameters = {
`
``
272
`+
FIXED_ONE_BYTE_STRING(isolate, "global")};
`
``
273
`+
Local arguments[] = {context->Global()};
`
``
274
`+
MaybeLocal maybe_fn =
`
``
275
`+
per_process::native_module_loader.LookupAndCompile(
`
``
276
`+
context, *module, ¶meters, nullptr);
`
``
277
`+
if (maybe_fn.IsEmpty()) {
`
``
278
`+
return Local();
`
``
279
`+
}
`
``
280
`+
Local fn = maybe_fn.ToLocalChecked();
`
``
281
`+
MaybeLocal result =
`
``
282
`+
fn->Call(context, Undefined(isolate),
`
``
283
`+
arraysize(arguments), arguments);
`
``
284
`+
// Execution failed during context creation.
`
``
285
`+
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
`
``
286
`+
if (result.IsEmpty()) {
`
``
287
`+
return Local();
`
``
288
`+
}
`
281
289
` }
`
282
290
` }
`
283
291
``