diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/console.js | 6 | ||||
-rw-r--r-- | lib/internal/bootstrap/node.js | 17 | ||||
-rw-r--r-- | lib/internal/v8.js | 39 | ||||
-rw-r--r-- | lib/util.js | 32 |
4 files changed, 14 insertions, 80 deletions
diff --git a/lib/console.js b/lib/console.js index de2d11afe1..e8b89536b9 100644 --- a/lib/console.js +++ b/lib/console.js @@ -29,7 +29,7 @@ const { ERR_INVALID_ARG_VALUE, }, } = require('internal/errors'); -const { previewMapIterator, previewSetIterator } = require('internal/v8'); +const { previewEntries } = process.binding('util'); const { Buffer: { isBuffer } } = require('buffer'); const util = require('util'); const { @@ -345,7 +345,7 @@ Console.prototype.table = function(tabularData, properties) { const mapIter = isMapIterator(tabularData); if (mapIter) - tabularData = previewMapIterator(tabularData); + tabularData = previewEntries(tabularData); if (mapIter || isMap(tabularData)) { const keys = []; @@ -367,7 +367,7 @@ Console.prototype.table = function(tabularData, properties) { const setIter = isSetIterator(tabularData); if (setIter) - tabularData = previewSetIterator(tabularData); + tabularData = previewEntries(tabularData); const setlike = setIter || isSet(tabularData); if (setlike) { diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index e23ec858f3..a8485f5d1c 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -29,7 +29,6 @@ // Do this good and early, since it handles errors. setupProcessFatal(); - setupV8(); setupProcessICUVersions(); setupGlobalVariables(); @@ -479,22 +478,6 @@ }; } - 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()); - v8.previewSetIterator(new Set().entries()); - v8.previewWeakMap(new WeakMap(), 1); - v8.previewWeakSet(new WeakSet(), 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 deleted file mode 100644 index 3102b45a2d..0000000000 --- a/lib/internal/v8.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -// This file provides access to some of V8's native runtime functions. See -// https://github.com/v8/v8/wiki/Built-in-functions for further information -// about their implementation. -// They have to be loaded before anything else to make sure we deactivate them -// before executing any other code. Gaining access is achieved by using a -// specific flag that is used internally in the startup phase. - -// Clone the provided Map Iterator. -function previewMapIterator(it) { - return %MapIteratorClone(it); -} - -// Clone the provided Set Iterator. -function previewSetIterator(it) { - return %SetIteratorClone(it); -} - -// Retrieve all WeakMap instance key / value pairs up to `max`. `max` limits the -// number of key / value pairs returned. Make sure it is a positive number, -// otherwise V8 aborts. Passing through `0` returns all elements. -function previewWeakMap(weakMap, max) { - return %GetWeakMapEntries(weakMap, max); -} - -// Retrieve all WeakSet instance values up to `max`. `max` limits the -// number of key / value pairs returned. Make sure it is a positive number, -// otherwise V8 aborts. Passing through `0` returns all elements. -function previewWeakSet(weakSet, max) { - return %GetWeakSetValues(weakSet, max); -} - -module.exports = { - previewMapIterator, - previewSetIterator, - previewWeakMap, - previewWeakSet -}; diff --git a/lib/util.js b/lib/util.js index bd7a98694b..f358adefdb 100644 --- a/lib/util.js +++ b/lib/util.js @@ -31,17 +31,11 @@ const { TextDecoder, TextEncoder } = require('internal/encoding'); const { isBuffer } = require('buffer').Buffer; const { - previewMapIterator, - previewSetIterator, - previewWeakMap, - previewWeakSet -} = require('internal/v8'); - -const { getPromiseDetails, getProxyDetails, kPending, kRejected, + previewEntries } = process.binding('util'); const { internalBinding } = require('internal/bootstrap/loaders'); @@ -912,7 +906,7 @@ function formatMap(ctx, value, recurseTimes, keys) { function formatWeakSet(ctx, value, recurseTimes, keys) { const maxArrayLength = Math.max(ctx.maxArrayLength, 0); - const entries = previewWeakSet(value, maxArrayLength + 1); + const entries = previewEntries(value).slice(0, maxArrayLength + 1); const maxLength = Math.min(maxArrayLength, entries.length); let output = new Array(maxLength); for (var i = 0; i < maxLength; ++i) @@ -929,16 +923,14 @@ function formatWeakSet(ctx, value, recurseTimes, keys) { function formatWeakMap(ctx, value, recurseTimes, keys) { const maxArrayLength = Math.max(ctx.maxArrayLength, 0); - const entries = previewWeakMap(value, maxArrayLength + 1); - // Entries exist as [key1, val1, key2, val2, ...] - const remainder = entries.length / 2 > maxArrayLength; - const len = entries.length / 2 - (remainder ? 1 : 0); + const entries = previewEntries(value).slice(0, maxArrayLength + 1); + const remainder = entries.length > maxArrayLength; + const len = entries.length - (remainder ? 1 : 0); const maxLength = Math.min(maxArrayLength, len); let output = new Array(maxLength); for (var i = 0; i < len; i++) { - const pos = i * 2; - output[i] = `${formatValue(ctx, entries[pos], recurseTimes)} => ` + - formatValue(ctx, entries[pos + 1], recurseTimes); + output[i] = `${formatValue(ctx, entries[i][0], recurseTimes)} => ` + + formatValue(ctx, entries[i][1], recurseTimes); } // Sort all entries to have a halfway reliable output (if more entries than // retrieved ones exist, we can not reliably return the same output). @@ -950,9 +942,9 @@ function formatWeakMap(ctx, value, recurseTimes, keys) { return output; } -function formatCollectionIterator(preview, ctx, value, recurseTimes, keys) { +function formatCollectionIterator(ctx, value, recurseTimes, keys) { const output = []; - for (const entry of preview(value)) { + for (const entry of previewEntries(value)) { if (ctx.maxArrayLength === output.length) { output.push('... more items'); break; @@ -966,13 +958,11 @@ function formatCollectionIterator(preview, ctx, value, recurseTimes, keys) { } function formatMapIterator(ctx, value, recurseTimes, keys) { - return formatCollectionIterator(previewMapIterator, ctx, value, recurseTimes, - keys); + return formatCollectionIterator(ctx, value, recurseTimes, keys); } function formatSetIterator(ctx, value, recurseTimes, keys) { - return formatCollectionIterator(previewSetIterator, ctx, value, recurseTimes, - keys); + return formatCollectionIterator(ctx, value, recurseTimes, keys); } function formatPromise(ctx, value, recurseTimes, keys) { |