| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0b9853 commit 0165a76
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,7 +90,8 @@ function setDeserializeMainFunction(callback, data) { | |||
| 90 | 90 | ||
| 91 | 91 | // This should be in sync with run_main_module.js until we make that | |
| 92 | 92 | // a built-in main function. | |
| 93 | - prepareMainThreadExecution(true); | ||
| 93 | + // TODO(joyeecheung): make a copy of argv[0] and insert it as argv[1]. | ||
| 94 | + prepareMainThreadExecution(false); | ||
| 94 | 95 | markBootstrapComplete(); | |
| 95 | 96 | callback(data); | |
| 96 | 97 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,58 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests snapshot JS API using the example in the docs. | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { spawnSync } = require('child_process'); | ||
| 8 | + const tmpdir = require('../common/tmpdir'); | ||
| 9 | + const path = require('path'); | ||
| 10 | + const fs = require('fs'); | ||
| 11 | + | ||
| 12 | + tmpdir.refresh(); | ||
| 13 | + const blobPath = path.join(tmpdir.path, 'snapshot.blob'); | ||
| 14 | + const code = ` | ||
| 15 | + require('v8').startupSnapshot.setDeserializeMainFunction(() => { | ||
| 16 | + console.log(JSON.stringify(process.argv)); | ||
| 17 | + }); | ||
| 18 | + `; | ||
| 19 | + { | ||
| 20 | + fs.writeFileSync(path.join(tmpdir.path, 'entry.js'), code, 'utf8'); | ||
| 21 | + const child = spawnSync(process.execPath, [ | ||
| 22 | + '--snapshot-blob', | ||
| 23 | + blobPath, | ||
| 24 | + '--build-snapshot', | ||
| 25 | + 'entry.js', | ||
| 26 | + ], { | ||
| 27 | + cwd: tmpdir.path | ||
| 28 | + }); | ||
| 29 | + if (child.status !== 0) { | ||
| 30 | + console.log(child.stderr.toString()); | ||
| 31 | + console.log(child.stdout.toString()); | ||
| 32 | + assert.strictEqual(child.status, 0); | ||
| 33 | + } | ||
| 34 | + const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); | ||
| 35 | + assert(stats.isFile()); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + { | ||
| 39 | + const child = spawnSync(process.execPath, [ | ||
| 40 | + '--snapshot-blob', | ||
| 41 | + blobPath, | ||
| 42 | + 'argv1', | ||
| 43 | + 'argv2', | ||
| 44 | + ], { | ||
| 45 | + cwd: tmpdir.path, | ||
| 46 | + env: { | ||
| 47 | + ...process.env, | ||
| 48 | + } | ||
| 49 | + }); | ||
| 50 | + | ||
| 51 | + const stdout = JSON.parse(child.stdout.toString().trim()); | ||
| 52 | + assert.deepStrictEqual(stdout, [ | ||
| 53 | + process.execPath, | ||
| 54 | + 'argv1', | ||
| 55 | + 'argv2', | ||
| 56 | + ]); | ||
| 57 | + assert.strictEqual(child.status, 0); | ||
| 58 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments