lib: remove use of Debug.MakeMirror()
This paves the way for removing `vm.runInDebugContext()`. Inspection of Map and Set iterators is now done through V8 instrinsics. Fixes: https://github.com/nodejs/node/issues/11875 PR-URL: https://github.com/nodejs/node/pull/13295 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This commit is contained in:
parent
0028241fb4
commit
05948d8e4e
@ -1,3 +1,4 @@
|
|||||||
|
lib/internal/v8.js
|
||||||
lib/internal/v8_prof_polyfill.js
|
lib/internal/v8_prof_polyfill.js
|
||||||
lib/punycode.js
|
lib/punycode.js
|
||||||
test/addons/??_*
|
test/addons/??_*
|
||||||
|
15
lib/internal/bootstrap_node.js
vendored
15
lib/internal/bootstrap_node.js
vendored
@ -27,6 +27,7 @@
|
|||||||
// do this good and early, since it handles errors.
|
// do this good and early, since it handles errors.
|
||||||
setupProcessFatal();
|
setupProcessFatal();
|
||||||
|
|
||||||
|
setupV8();
|
||||||
setupProcessICUVersions();
|
setupProcessICUVersions();
|
||||||
|
|
||||||
setupGlobalVariables();
|
setupGlobalVariables();
|
||||||
@ -414,6 +415,20 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupV8() {
|
||||||
|
// Warm up the map and set iterator preview functions. V8 compiles
|
||||||
|
// functions lazily (unless --nolazy is set) so we need to do this
|
||||||
|
// before we turn off --allow_natives_syntax again.
|
||||||
|
const v8 = NativeModule.require('internal/v8');
|
||||||
|
v8.previewMapIterator(new Map().entries(), 1);
|
||||||
|
v8.previewSetIterator(new Set().entries(), 1);
|
||||||
|
// Disable --allow_natives_syntax again unless it was explicitly
|
||||||
|
// specified on the command line.
|
||||||
|
const re = /^--allow[-_]natives[-_]syntax$/;
|
||||||
|
if (!process.execArgv.some((s) => re.test(s)))
|
||||||
|
process.binding('v8').setFlagsFromString('--noallow_natives_syntax');
|
||||||
|
}
|
||||||
|
|
||||||
function setupProcessICUVersions() {
|
function setupProcessICUVersions() {
|
||||||
const icu = process.binding('config').hasIntl ?
|
const icu = process.binding('config').hasIntl ?
|
||||||
process.binding('icu') : undefined;
|
process.binding('icu') : undefined;
|
||||||
|
21
lib/internal/v8.js
Normal file
21
lib/internal/v8.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
function take(it, n) {
|
||||||
|
const result = [];
|
||||||
|
for (const e of it) {
|
||||||
|
if (--n < 0)
|
||||||
|
break;
|
||||||
|
result.push(e);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function previewMapIterator(it, n) {
|
||||||
|
return take(%MapIteratorClone(it), n);
|
||||||
|
}
|
||||||
|
|
||||||
|
function previewSetIterator(it, n) {
|
||||||
|
return take(%SetIteratorClone(it), n);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { previewMapIterator, previewSetIterator };
|
39
lib/util.js
39
lib/util.js
@ -26,6 +26,7 @@ const { TextDecoder, TextEncoder } = require('internal/encoding');
|
|||||||
const { isBuffer } = require('buffer').Buffer;
|
const { isBuffer } = require('buffer').Buffer;
|
||||||
|
|
||||||
const { errname } = process.binding('uv');
|
const { errname } = process.binding('uv');
|
||||||
|
const { previewMapIterator, previewSetIterator } = require('internal/v8');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getPromiseDetails,
|
getPromiseDetails,
|
||||||
@ -77,7 +78,6 @@ const dateToISOString = Date.prototype.toISOString;
|
|||||||
const errorToString = Error.prototype.toString;
|
const errorToString = Error.prototype.toString;
|
||||||
|
|
||||||
var CIRCULAR_ERROR_MESSAGE;
|
var CIRCULAR_ERROR_MESSAGE;
|
||||||
var Debug;
|
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/;
|
const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/;
|
||||||
@ -356,17 +356,6 @@ function stylizeNoColor(str, styleType) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureDebugIsInitialized() {
|
|
||||||
if (Debug === undefined) {
|
|
||||||
const runInDebugContext = require('vm').runInDebugContext;
|
|
||||||
// a workaround till this entire method is removed
|
|
||||||
const originalValue = process.noDeprecation;
|
|
||||||
process.noDeprecation = true;
|
|
||||||
Debug = runInDebugContext('Debug');
|
|
||||||
process.noDeprecation = originalValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatValue(ctx, value, recurseTimes, ln) {
|
function formatValue(ctx, value, recurseTimes, ln) {
|
||||||
// Primitive types cannot have properties
|
// Primitive types cannot have properties
|
||||||
if (typeof value !== 'object' && typeof value !== 'function') {
|
if (typeof value !== 'object' && typeof value !== 'function') {
|
||||||
@ -474,10 +463,10 @@ function formatValue(ctx, value, recurseTimes, ln) {
|
|||||||
formatter = formatTypedArray;
|
formatter = formatTypedArray;
|
||||||
} else if (isMapIterator(value)) {
|
} else if (isMapIterator(value)) {
|
||||||
braces = ['MapIterator {', '}'];
|
braces = ['MapIterator {', '}'];
|
||||||
formatter = formatCollectionIterator;
|
formatter = formatMapIterator;
|
||||||
} else if (isSetIterator(value)) {
|
} else if (isSetIterator(value)) {
|
||||||
braces = ['SetIterator {', '}'];
|
braces = ['SetIterator {', '}'];
|
||||||
formatter = formatCollectionIterator;
|
formatter = formatSetIterator;
|
||||||
} else {
|
} else {
|
||||||
// Check for boxed strings with valueOf()
|
// Check for boxed strings with valueOf()
|
||||||
// The .valueOf() call can fail for a multitude of reasons
|
// The .valueOf() call can fail for a multitude of reasons
|
||||||
@ -782,17 +771,27 @@ function formatMap(ctx, value, recurseTimes, keys) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCollectionIterator(ctx, value, recurseTimes, keys) {
|
function formatCollectionIterator(preview, ctx, value, recurseTimes,
|
||||||
ensureDebugIsInitialized();
|
visibleKeys, keys) {
|
||||||
const mirror = Debug.MakeMirror(value, true);
|
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
|
||||||
const vals = mirror.preview();
|
var vals = preview(value, 100);
|
||||||
const output = [];
|
var output = [];
|
||||||
for (const o of vals) {
|
for (const o of vals) {
|
||||||
output.push(formatValue(ctx, o, recurseTimes));
|
output.push(formatValue(ctx, o, nextRecurseTimes));
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatMapIterator(ctx, value, recurseTimes, visibleKeys, keys) {
|
||||||
|
return formatCollectionIterator(previewMapIterator, ctx, value, recurseTimes,
|
||||||
|
visibleKeys, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSetIterator(ctx, value, recurseTimes, visibleKeys, keys) {
|
||||||
|
return formatCollectionIterator(previewSetIterator, ctx, value, recurseTimes,
|
||||||
|
visibleKeys, keys);
|
||||||
|
}
|
||||||
|
|
||||||
function formatPromise(ctx, value, recurseTimes, keys) {
|
function formatPromise(ctx, value, recurseTimes, keys) {
|
||||||
var output;
|
var output;
|
||||||
const [state, result] = getPromiseDetails(value);
|
const [state, result] = getPromiseDetails(value);
|
||||||
|
1
node.gyp
1
node.gyp
@ -132,6 +132,7 @@
|
|||||||
'lib/internal/http2/core.js',
|
'lib/internal/http2/core.js',
|
||||||
'lib/internal/http2/compat.js',
|
'lib/internal/http2/compat.js',
|
||||||
'lib/internal/http2/util.js',
|
'lib/internal/http2/util.js',
|
||||||
|
'lib/internal/v8.js',
|
||||||
'lib/internal/v8_prof_polyfill.js',
|
'lib/internal/v8_prof_polyfill.js',
|
||||||
'lib/internal/v8_prof_processor.js',
|
'lib/internal/v8_prof_processor.js',
|
||||||
'lib/internal/streams/lazy_transform.js',
|
'lib/internal/streams/lazy_transform.js',
|
||||||
|
@ -4288,6 +4288,12 @@ void Init(int* argc,
|
|||||||
const char no_typed_array_heap[] = "--typed_array_max_size_in_heap=0";
|
const char no_typed_array_heap[] = "--typed_array_max_size_in_heap=0";
|
||||||
V8::SetFlagsFromString(no_typed_array_heap, sizeof(no_typed_array_heap) - 1);
|
V8::SetFlagsFromString(no_typed_array_heap, sizeof(no_typed_array_heap) - 1);
|
||||||
|
|
||||||
|
// Needed for access to V8 intrinsics. Disabled again during bootstrapping,
|
||||||
|
// see lib/internal/bootstrap_node.js.
|
||||||
|
const char allow_natives_syntax[] = "--allow_natives_syntax";
|
||||||
|
V8::SetFlagsFromString(allow_natives_syntax,
|
||||||
|
sizeof(allow_natives_syntax) - 1);
|
||||||
|
|
||||||
// We should set node_is_initialized here instead of in node::Start,
|
// We should set node_is_initialized here instead of in node::Start,
|
||||||
// otherwise embedders using node::Init to initialize everything will not be
|
// otherwise embedders using node::Init to initialize everything will not be
|
||||||
// able to set it and native modules will not load for them.
|
// able to set it and native modules will not load for them.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user