| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 853b48d commit be40c82
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,15 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const { | |
| 3 | 3 | prepareMainThreadExecution, | |
| 4 | - markBootstrapComplete, | ||
| 5 | 4 | } = require('internal/process/pre_execution'); | |
| 6 | 5 | const { isExperimentalSeaWarningNeeded } = internalBinding('sea'); | |
| 7 | 6 | const { emitExperimentalWarning } = require('internal/util'); | |
| 8 | 7 | const { embedderRequire, embedderRunCjs } = require('internal/util/embedding'); | |
| 9 | - const { runEmbedderEntryPoint } = internalBinding('mksnapshot'); | ||
| 10 | 8 | ||
| 11 | 9 | prepareMainThreadExecution(false, true); | |
| 12 | - markBootstrapComplete(); | ||
| 13 | 10 | ||
| 14 | 11 | if (isExperimentalSeaWarningNeeded()) { | |
| 15 | 12 | emitExperimentalWarning('Single executable application'); | |
| 16 | 13 | } | |
| 17 | 14 | ||
| 18 | - return runEmbedderEntryPoint(process, embedderRequire, embedderRunCjs); | ||
| 15 | + return [process, embedderRequire, embedderRunCjs]; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,6 @@ const { | |||
| 11 | 11 | ||
| 12 | 12 | const { BuiltinModule: { normalizeRequirableId } } = require('internal/bootstrap/realm'); | |
| 13 | 13 | const { | |
| 14 | - runEmbedderEntryPoint, | ||
| 15 | 14 | compileSerializeMain, | |
| 16 | 15 | anonymousMainPath, | |
| 17 | 16 | } = internalBinding('mksnapshot'); | |
@@ -20,9 +19,6 @@ const { isExperimentalSeaWarningNeeded } = internalBinding('sea'); | |||
| 20 | 19 | ||
| 21 | 20 | const { emitExperimentalWarning } = require('internal/util'); | |
| 22 | 21 | const { emitWarningSync } = require('internal/process/warning'); | |
| 23 | - const { | ||
| 24 | - getOptionValue, | ||
| 25 | - } = require('internal/options'); | ||
| 26 | 22 | ||
| 27 | 23 | const { | |
| 28 | 24 | initializeCallbacks, | |
@@ -179,18 +175,11 @@ function main() { | |||
| 179 | 175 | return fn(requireForUserSnapshot, filename, dirname); | |
| 180 | 176 | } | |
| 181 | 177 | ||
| 182 | - const serializeMainArgs = [process, requireForUserSnapshot, minimalRunCjs]; | ||
| 183 | - | ||
| 184 | 178 | if (isExperimentalSeaWarningNeeded()) { | |
| 185 | 179 | emitExperimentalWarning('Single executable application'); | |
| 186 | 180 | } | |
| 187 | 181 | ||
| 188 | - if (getOptionValue('--inspect-brk')) { | ||
| 189 | - internalBinding('inspector').callAndPauseOnStart( | ||
| 190 | - runEmbedderEntryPoint, undefined, ...serializeMainArgs); | ||
| 191 | - } else { | ||
| 192 | - runEmbedderEntryPoint(...serializeMainArgs); | ||
| 193 | - } | ||
| 182 | + return [process, requireForUserSnapshot, minimalRunCjs]; | ||
| 194 | 183 | } | |
| 195 | 184 | ||
| 196 | - main(); | ||
| 185 | + return main(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -430,14 +430,6 @@ inline builtins::BuiltinLoader* Environment::builtin_loader() { | |||
| 430 | 430 | return &builtin_loader_; | |
| 431 | 431 | } | |
| 432 | 432 | ||
| 433 | - inline const StartExecutionCallback& Environment::embedder_entry_point() const { | ||
| 434 | - return embedder_entry_point_; | ||
| 435 | - } | ||
| 436 | - | ||
| 437 | - inline void Environment::set_embedder_entry_point(StartExecutionCallback&& fn) { | ||
| 438 | - embedder_entry_point_ = std::move(fn); | ||
| 439 | - } | ||
| 440 | - | ||
| 441 | 433 | inline double Environment::new_async_id() { | |
| 442 | 434 | async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1; | |
| 443 | 435 | return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -999,9 +999,6 @@ class Environment : public MemoryRetainer { | |||
| 999 | 999 | ||
| 1000 | 1000 | #endif // HAVE_INSPECTOR | |
| 1001 | 1001 | ||
| 1002 | - inline const StartExecutionCallback& embedder_entry_point() const; | ||
| 1003 | - inline void set_embedder_entry_point(StartExecutionCallback&& fn); | ||
| 1004 | - | ||
| 1005 | 1002 | inline void set_process_exit_handler( | |
| 1006 | 1003 | std::function<void(Environment*, ExitCode)>&& handler); | |
| 1007 | 1004 | ||
@@ -1212,7 +1209,6 @@ class Environment : public MemoryRetainer { | |||
| 1212 | 1209 | std::unique_ptr<PrincipalRealm> principal_realm_ = nullptr; | |
| 1213 | 1210 | ||
| 1214 | 1211 | builtins::BuiltinLoader builtin_loader_; | |
| 1215 | - StartExecutionCallback embedder_entry_point_; | ||
| 1216 | 1212 | ||
| 1217 | 1213 | // Used by allocate_managed_buffer() and release_managed_buffer() to keep | |
| 1218 | 1214 | // track of the BackingStore for a given pointer. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,7 +131,10 @@ | |||
| 131 | 131 | ||
| 132 | 132 | namespace node { | |
| 133 | 133 | ||
| 134 | + using v8::Array; | ||
| 135 | + using v8::Context; | ||
| 134 | 136 | using v8::EscapableHandleScope; | |
| 137 | + using v8::Function; | ||
| 135 | 138 | using v8::Isolate; | |
| 136 | 139 | using v8::Local; | |
| 137 | 140 | using v8::MaybeLocal; | |
@@ -278,26 +281,65 @@ MaybeLocal<Value> StartExecution(Environment* env, const char* main_script_id) { | |||
| 278 | 281 | return scope.EscapeMaybe(realm->ExecuteBootstrapper(main_script_id)); | |
| 279 | 282 | } | |
| 280 | 283 | ||
| 284 | + // Convert the result returned by an intermediate main script into | ||
| 285 | + // StartExecutionCallbackInfo. Currently the result is an array containing | ||
| 286 | + // [process, requireFunction, cjsRunner] | ||
| 287 | + std::optional<StartExecutionCallbackInfo> CallbackInfoFromArray( | ||
| 288 | + Local<Context> context, Local<Value> result) { | ||
| 289 | + CHECK(result->IsArray()); | ||
| 290 | + Local<Array> args = result.As<Array>(); | ||
| 291 | + CHECK_EQ(args->Length(), 3); | ||
| 292 | + Local<Value> process_obj, require_fn, runcjs_fn; | ||
| 293 | + if (!args->Get(context, 0).ToLocal(&process_obj) || | ||
| 294 | + !args->Get(context, 1).ToLocal(&require_fn) || | ||
| 295 | + !args->Get(context, 2).ToLocal(&runcjs_fn)) { | ||
| 296 | + return std::nullopt; | ||
| 297 | + } | ||
| 298 | + CHECK(process_obj->IsObject()); | ||
| 299 | + CHECK(require_fn->IsFunction()); | ||
| 300 | + CHECK(runcjs_fn->IsFunction()); | ||
| 301 | + node::StartExecutionCallbackInfo info{process_obj.As<Object>(), | ||
| 302 | + require_fn.As<Function>(), | ||
| 303 | + runcjs_fn.As<Function>()}; | ||
| 304 | + return info; | ||
| 305 | + } | ||
| 306 | + | ||
| 281 | 307 | MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) { | |
| 282 | 308 | InternalCallbackScope callback_scope( | |
| 283 | 309 | env, | |
| 284 | 310 | Object::New(env->isolate()), | |
| 285 | 311 | { 1, 0 }, | |
| 286 | 312 | InternalCallbackScope::kSkipAsyncHooks); | |
| 287 | 313 | ||
| 314 | + // Only snapshot builder or embedder applications set the | ||
| 315 | + // callback. | ||
| 288 | 316 | if (cb != nullptr) { | |
| 289 | 317 | EscapableHandleScope scope(env->isolate()); | |
| 290 | - // TODO(addaleax): pass the callback to the main script more directly, | ||
| 291 | - // e.g. by making StartExecution(env, builtin) parametrizable | ||
| 292 | - env->set_embedder_entry_point(std::move(cb)); | ||
| 293 | - auto reset_entry_point = | ||
| 294 | - OnScopeLeave([&]() { env->set_embedder_entry_point({}); }); | ||
| 295 | 318 | ||
| 296 | - const char* entry = env->isolate_data()->is_building_snapshot() | ||
| 297 | - ? "internal/main/mksnapshot" | ||
| 298 | - : "internal/main/embedding"; | ||
| 319 | + Local<Value> result; | ||
| 320 | + if (env->isolate_data()->is_building_snapshot()) { | ||
| 321 | + if (!StartExecution(env, "internal/main/mksnapshot").ToLocal(&result)) { | ||
| 322 | + return MaybeLocal<Value>(); | ||
| 323 | + } | ||
| 324 | + } else { | ||
| 325 | + if (!StartExecution(env, "internal/main/embedding").ToLocal(&result)) { | ||
| 326 | + return MaybeLocal<Value>(); | ||
| 327 | + } | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + auto info = CallbackInfoFromArray(env->context(), result); | ||
| 331 | + if (!info.has_value()) { | ||
| 332 | + MaybeLocal<Value>(); | ||
| 333 | + } | ||
| 334 | + #if HAVE_INSPECTOR | ||
| 335 | + if (env->options()->debug_options().break_first_line) { | ||
| 336 | + env->inspector_agent()->PauseOnNextJavascriptStatement("Break on start"); | ||
| 337 | + } | ||
| 338 | + #endif | ||
| 299 | 339 | ||
| 300 | - return scope.EscapeMaybe(StartExecution(env, entry)); | ||
| 340 | + env->performance_state()->Mark( | ||
| 341 | + performance::NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE); | ||
| 342 | + return scope.EscapeMaybe(cb(info.value())); | ||
| 301 | 343 | } | |
| 302 | 344 | ||
| 303 | 345 | CHECK(!env->isolate_data()->is_building_snapshot()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,6 @@ using v8::FunctionCallbackInfo; | |||
| 40 | 40 | using v8::HandleScope; | |
| 41 | 41 | using v8::Isolate; | |
| 42 | 42 | using v8::Local; | |
| 43 | - using v8::MaybeLocal; | ||
| 44 | 43 | using v8::Object; | |
| 45 | 44 | using v8::ObjectTemplate; | |
| 46 | 45 | using v8::ScriptCompiler; | |
@@ -1410,25 +1409,6 @@ void SerializeSnapshotableObjects(Realm* realm, | |||
| 1410 | 1409 | }); | |
| 1411 | 1410 | } | |
| 1412 | 1411 | ||
| 1413 | - static void RunEmbedderEntryPoint(const FunctionCallbackInfo<Value>& args) { | ||
| 1414 | - Environment* env = Environment::GetCurrent(args); | ||
| 1415 | - Local<Value> process_obj = args[0]; | ||
| 1416 | - Local<Value> require_fn = args[1]; | ||
| 1417 | - Local<Value> runcjs_fn = args[2]; | ||
| 1418 | - CHECK(process_obj->IsObject()); | ||
| 1419 | - CHECK(require_fn->IsFunction()); | ||
| 1420 | - CHECK(runcjs_fn->IsFunction()); | ||
| 1421 | - | ||
| 1422 | - const node::StartExecutionCallback& callback = env->embedder_entry_point(); | ||
| 1423 | - node::StartExecutionCallbackInfo info{process_obj.As<Object>(), | ||
| 1424 | - require_fn.As<Function>(), | ||
| 1425 | - runcjs_fn.As<Function>()}; | ||
| 1426 | - MaybeLocal<Value> retval = callback(info); | ||
| 1427 | - if (!retval.IsEmpty()) { | ||
| 1428 | - args.GetReturnValue().Set(retval.ToLocalChecked()); | ||
| 1429 | - } | ||
| 1430 | - } | ||
| 1431 | - | ||
| 1432 | 1412 | void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) { | |
| 1433 | 1413 | CHECK(args[0]->IsString()); | |
| 1434 | 1414 | Local<String> filename = args[0].As<String>(); | |
@@ -1552,7 +1532,6 @@ void CreatePerContextProperties(Local<Object> target, | |||
| 1552 | 1532 | void CreatePerIsolateProperties(IsolateData* isolate_data, | |
| 1553 | 1533 | Local<ObjectTemplate> target) { | |
| 1554 | 1534 | Isolate* isolate = isolate_data->isolate(); | |
| 1555 | - SetMethod(isolate, target, "runEmbedderEntryPoint", RunEmbedderEntryPoint); | ||
| 1556 | 1535 | SetMethod(isolate, target, "compileSerializeMain", CompileSerializeMain); | |
| 1557 | 1536 | SetMethod(isolate, target, "setSerializeCallback", SetSerializeCallback); | |
| 1558 | 1537 | SetMethod(isolate, target, "setDeserializeCallback", SetDeserializeCallback); | |
@@ -1565,7 +1544,6 @@ void CreatePerIsolateProperties(IsolateData* isolate_data, | |||
| 1565 | 1544 | } | |
| 1566 | 1545 | ||
| 1567 | 1546 | void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |
| 1568 | - registry->Register(RunEmbedderEntryPoint); | ||
| 1569 | 1547 | registry->Register(CompileSerializeMain); | |
| 1570 | 1548 | registry->Register(SetSerializeCallback); | |
| 1571 | 1549 | registry->Register(SetDeserializeCallback); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments