| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c2fb38c commit a6f0cfa
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,7 +320,8 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) { | |||
| 320 | 320 | CHECK(!env->isolate_data()->is_building_snapshot()); | |
| 321 | 321 | ||
| 322 | 322 | #ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION | |
| 323 | - if (sea::IsSingleExecutable()) { | ||
| 323 | + // Snapshot in SEA is only loaded for the main thread. | ||
| 324 | + if (sea::IsSingleExecutable() && env->is_main_thread()) { | ||
| 324 | 325 | sea::SeaResource sea = sea::FindSingleExecutableResource(); | |
| 325 | 326 | // The SEA preparation blob building process should already enforce this, | |
| 326 | 327 | // this check is just here to guard against the unlikely case where | |
@@ -342,6 +343,9 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) { | |||
| 342 | 343 | // move the pre-execution part into a different file that can be | |
| 343 | 344 | // reused when dealing with user-defined main functions. | |
| 344 | 345 | if (!env->snapshot_deserialize_main().IsEmpty()) { | |
| 346 | + // Custom worker snapshot is not supported yet, | ||
| 347 | + // so workers can't have deserialize main functions. | ||
| 348 | + CHECK(env->is_main_thread()); | ||
| 345 | 349 | return env->RunSnapshotDeserializeMain(); | |
| 346 | 350 | } | |
| 347 | 351 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,80 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const { | ||
| 6 | + generateSEA, | ||
| 7 | + skipIfSingleExecutableIsNotSupported, | ||
| 8 | + } = require('../common/sea'); | ||
| 9 | + | ||
| 10 | + skipIfSingleExecutableIsNotSupported(); | ||
| 11 | + | ||
| 12 | + // This tests the snapshot support in single executable applications. | ||
| 13 | + | ||
| 14 | + const tmpdir = require('../common/tmpdir'); | ||
| 15 | + const { writeFileSync, existsSync } = require('fs'); | ||
| 16 | + const { | ||
| 17 | + spawnSyncAndAssert, spawnSyncAndExitWithoutError, | ||
| 18 | + } = require('../common/child_process'); | ||
| 19 | + const assert = require('assert'); | ||
| 20 | + | ||
| 21 | + const configFile = tmpdir.resolve('sea-config.json'); | ||
| 22 | + const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); | ||
| 23 | + const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); | ||
| 24 | + | ||
| 25 | + { | ||
| 26 | + tmpdir.refresh(); | ||
| 27 | + | ||
| 28 | + // FIXME(joyeecheung): currently `worker_threads` cannot be loaded during the | ||
| 29 | + // snapshot building process because internal/worker.js is accessing isMainThread at | ||
| 30 | + // the top level (and there are maybe more code that access these at the top-level), | ||
| 31 | + // and have to be loaded in the deserialized snapshot main function. | ||
| 32 | + // Change these states to be accessed on-demand. | ||
| 33 | + const code = ` | ||
| 34 | + const { | ||
| 35 | + setDeserializeMainFunction, | ||
| 36 | + } = require('v8').startupSnapshot; | ||
| 37 | + setDeserializeMainFunction(() => { | ||
| 38 | + const { Worker } = require('worker_threads'); | ||
| 39 | + new Worker("console.log('Hello from Worker')", { eval: true }); | ||
| 40 | + }); | ||
| 41 | + `; | ||
| 42 | + | ||
| 43 | + writeFileSync(tmpdir.resolve('snapshot.js'), code, 'utf-8'); | ||
| 44 | + writeFileSync(configFile, ` | ||
| 45 | + { | ||
| 46 | + "main": "snapshot.js", | ||
| 47 | + "output": "sea-prep.blob", | ||
| 48 | + "useSnapshot": true | ||
| 49 | + } | ||
| 50 | + `); | ||
| 51 | + | ||
| 52 | + spawnSyncAndExitWithoutError( | ||
| 53 | + process.execPath, | ||
| 54 | + ['--experimental-sea-config', 'sea-config.json'], | ||
| 55 | + { | ||
| 56 | + cwd: tmpdir.path, | ||
| 57 | + env: { | ||
| 58 | + NODE_DEBUG_NATIVE: 'SEA', | ||
| 59 | + ...process.env, | ||
| 60 | + }, | ||
| 61 | + }); | ||
| 62 | + | ||
| 63 | + assert(existsSync(seaPrepBlob)); | ||
| 64 | + | ||
| 65 | + generateSEA(outputFile, process.execPath, seaPrepBlob); | ||
| 66 | + | ||
| 67 | + spawnSyncAndAssert( | ||
| 68 | + outputFile, | ||
| 69 | + { | ||
| 70 | + env: { | ||
| 71 | + NODE_DEBUG_NATIVE: 'SEA', | ||
| 72 | + ...process.env, | ||
| 73 | + } | ||
| 74 | + }, | ||
| 75 | + { | ||
| 76 | + trim: true, | ||
| 77 | + stdout: 'Hello from Worker' | ||
| 78 | + } | ||
| 79 | + ); | ||
| 80 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments