-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootstrap: clean up inspector console methods during serialization
Some console methods are created by the V8 inspector after an inspector client is created, reset them to undefined during sereialization to avoid holding on to invalid references in the snapshot. V8 will take care of the re-initialization when another inspector client is created during deserialization. PR-URL: #44279 Fixes: nodejs/node-v8#237 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
1 parent
1e137c2
commit 143abcb
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { | ||
setDeserializeMainFunction, | ||
} = require('v8').startupSnapshot; | ||
|
||
console.log(JSON.stringify(Object.keys(console), null, 2)); | ||
|
||
setDeserializeMainFunction(() => { | ||
console.log(JSON.stringify(Object.keys(console), null, 2)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
// TODO(joyeecheung): remove the flag when it is turned on by default in V8. | ||
// Flags: --experimental-async-stack-tagging-api | ||
// This tests the console works in the deserialized snapshot. | ||
|
||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fixtures = require('../common/fixtures'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
tmpdir.refresh(); | ||
const blobPath = path.join(tmpdir.path, 'snapshot.blob'); | ||
const entry = fixtures.path('snapshot', 'console.js'); | ||
|
||
{ | ||
const child = spawnSync(process.execPath, [ | ||
'--experimental-async-stack-tagging-api', | ||
'--snapshot-blob', | ||
blobPath, | ||
'--build-snapshot', | ||
entry, | ||
], { | ||
cwd: tmpdir.path | ||
}); | ||
const stdout = child.stdout.toString(); | ||
if (child.status !== 0) { | ||
console.log(stdout); | ||
console.log(child.stderr.toString()); | ||
assert.strictEqual(child.status, 0); | ||
} | ||
assert.deepStrictEqual(Object.keys(console), JSON.parse(stdout)); | ||
const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); | ||
assert(stats.isFile()); | ||
} | ||
|
||
{ | ||
const child = spawnSync(process.execPath, [ | ||
'--experimental-async-stack-tagging-api', | ||
'--snapshot-blob', | ||
blobPath, | ||
], { | ||
cwd: tmpdir.path, | ||
env: { | ||
...process.env, | ||
} | ||
}); | ||
|
||
const stdout = child.stdout.toString(); | ||
if (child.status !== 0) { | ||
console.log(stdout); | ||
console.log(child.stderr.toString()); | ||
assert.strictEqual(child.status, 0); | ||
} | ||
assert.deepStrictEqual(Object.keys(console), JSON.parse(stdout)); | ||
assert.strictEqual(child.status, 0); | ||
} |