summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2017-11-24 00:13:44 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2017-11-24 00:13:44 +0100
commit05948d8e4e3fefb757ea8b8aa5160cacd07e0cf4 (patch)
tree85a924240378ed30b4e6e9db15fce44a76db4801
parent0028241fb4c19d04066b006bca4f3e0b3b403d90 (diff)
downloadandroid-node-v8-05948d8e4e3fefb757ea8b8aa5160cacd07e0cf4.tar.gz
android-node-v8-05948d8e4e3fefb757ea8b8aa5160cacd07e0cf4.tar.bz2
android-node-v8-05948d8e4e3fefb757ea8b8aa5160cacd07e0cf4.zip
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>
-rw-r--r--.eslintignore1
-rw-r--r--lib/internal/bootstrap_node.js15
-rw-r--r--lib/internal/v8.js21
-rw-r--r--lib/util.js39
-rw-r--r--node.gyp1
-rw-r--r--src/node.cc6
6 files changed, 63 insertions, 20 deletions
diff --git a/.eslintignore b/.eslintignore
index 4b6e6b5e0f..9b1d8b3f35 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,3 +1,4 @@
+lib/internal/v8.js
lib/internal/v8_prof_polyfill.js
lib/punycode.js
test/addons/??_*
diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js
index fb8bc76228..a565916193 100644
--- a/lib/internal/bootstrap_node.js
+++ b/lib/internal/bootstrap_node.js
@@ -27,6 +27,7 @@
// do this good and early, since it handles errors.
setupProcessFatal();
+ setupV8();
setupProcessICUVersions();
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() {
const icu = process.binding('config').hasIntl ?
process.binding('icu') : undefined;
diff --git a/lib/internal/v8.js b/lib/internal/v8.js
new file mode 100644
index 0000000000..b80e3de33d
--- /dev/null
+++ b/lib/internal/v8.js
@@ -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 };
diff --git a/lib/util.js b/lib/util.js
index 3ea3fa0dc8..058b5ed6bd 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -26,6 +26,7 @@ const { TextDecoder, TextEncoder } = require('internal/encoding');
const { isBuffer } = require('buffer').Buffer;
const { errname } = process.binding('uv');
+const { previewMapIterator, previewSetIterator } = require('internal/v8');
const {
getPromiseDetails,
@@ -77,7 +78,6 @@ const dateToISOString = Date.prototype.toISOString;
const errorToString = Error.prototype.toString;
var CIRCULAR_ERROR_MESSAGE;
-var Debug;
/* eslint-disable */
const strEscapeSequencesRegExp = /[\x00-\x1f\x27\x5c]/;
@@ -356,17 +356,6 @@ function stylizeNoColor(str, styleType) {
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) {
// Primitive types cannot have properties
if (typeof value !== 'object' && typeof value !== 'function') {
@@ -474,10 +463,10 @@ function formatValue(ctx, value, recurseTimes, ln) {
formatter = formatTypedArray;
} else if (isMapIterator(value)) {
braces = ['MapIterator {', '}'];
- formatter = formatCollectionIterator;
+ formatter = formatMapIterator;
} else if (isSetIterator(value)) {
braces = ['SetIterator {', '}'];
- formatter = formatCollectionIterator;
+ formatter = formatSetIterator;
} else {
// Check for boxed strings with valueOf()
// The .valueOf() call can fail for a multitude of reasons
@@ -782,17 +771,27 @@ function formatMap(ctx, value, recurseTimes, keys) {
return output;
}
-function formatCollectionIterator(ctx, value, recurseTimes, keys) {
- ensureDebugIsInitialized();
- const mirror = Debug.MakeMirror(value, true);
- const vals = mirror.preview();
- const output = [];
+function formatCollectionIterator(preview, ctx, value, recurseTimes,
+ visibleKeys, keys) {
+ var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
+ var vals = preview(value, 100);
+ var output = [];
for (const o of vals) {
- output.push(formatValue(ctx, o, recurseTimes));
+ output.push(formatValue(ctx, o, nextRecurseTimes));
}
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) {
var output;
const [state, result] = getPromiseDetails(value);
diff --git a/node.gyp b/node.gyp
index c32adc3720..ed28b4a6ce 100644
--- a/node.gyp
+++ b/node.gyp
@@ -132,6 +132,7 @@
'lib/internal/http2/core.js',
'lib/internal/http2/compat.js',
'lib/internal/http2/util.js',
+ 'lib/internal/v8.js',
'lib/internal/v8_prof_polyfill.js',
'lib/internal/v8_prof_processor.js',
'lib/internal/streams/lazy_transform.js',
diff --git a/src/node.cc b/src/node.cc
index 111f3b80f2..57c1a4cc8a 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -4288,6 +4288,12 @@ void Init(int* argc,
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);
+ // 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,
// otherwise embedders using node::Init to initialize everything will not be
// able to set it and native modules will not load for them.