lib: remove simd support from util.format()
Upstream V8 is removing SIMD support. Be proactive and follow suit. Refs: https://bugs.chromium.org/p/v8/issues/detail?id=4124 PR-URL: https://github.com/nodejs/node/pull/11346 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
c5d1851ac4
commit
2ba4eeadbb
41
lib/util.js
41
lib/util.js
@ -18,41 +18,6 @@ const inspectDefaultOptions = Object.seal({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var Debug;
|
var Debug;
|
||||||
var simdFormatters;
|
|
||||||
|
|
||||||
// SIMD is only available when --harmony_simd is specified on the command line
|
|
||||||
// and the set of available types differs between v5 and v6, that's why we use
|
|
||||||
// a map to look up and store the formatters. It also provides a modicum of
|
|
||||||
// protection against users monkey-patching the SIMD object.
|
|
||||||
if (typeof global.SIMD === 'object' && global.SIMD !== null) {
|
|
||||||
simdFormatters = new Map();
|
|
||||||
|
|
||||||
const make =
|
|
||||||
(extractLane, count) => (ctx, value, recurseTimes, visibleKeys, keys) => {
|
|
||||||
const output = new Array(count);
|
|
||||||
for (var i = 0; i < count; i += 1)
|
|
||||||
output[i] = formatPrimitive(ctx, extractLane(value, i));
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
|
|
||||||
const countPerType = {
|
|
||||||
Bool16x8: 8,
|
|
||||||
Bool32x4: 4,
|
|
||||||
Bool8x16: 16,
|
|
||||||
Float32x4: 4,
|
|
||||||
Int16x8: 8,
|
|
||||||
Int32x4: 4,
|
|
||||||
Int8x16: 16,
|
|
||||||
Uint16x8: 8,
|
|
||||||
Uint32x4: 4,
|
|
||||||
Uint8x16: 16
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const key in countPerType) {
|
|
||||||
const type = global.SIMD[key];
|
|
||||||
simdFormatters.set(type, make(type.extractLane, countPerType[key]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function tryStringify(arg) {
|
function tryStringify(arg) {
|
||||||
try {
|
try {
|
||||||
@ -508,7 +473,6 @@ function formatValue(ctx, value, recurseTimes) {
|
|||||||
braces = ['{', '}'];
|
braces = ['{', '}'];
|
||||||
formatter = formatPromise;
|
formatter = formatPromise;
|
||||||
} else {
|
} else {
|
||||||
let maybeSimdFormatter;
|
|
||||||
if (binding.isMapIterator(value)) {
|
if (binding.isMapIterator(value)) {
|
||||||
constructor = { name: 'MapIterator' };
|
constructor = { name: 'MapIterator' };
|
||||||
braces = ['{', '}'];
|
braces = ['{', '}'];
|
||||||
@ -519,11 +483,6 @@ function formatValue(ctx, value, recurseTimes) {
|
|||||||
braces = ['{', '}'];
|
braces = ['{', '}'];
|
||||||
empty = false;
|
empty = false;
|
||||||
formatter = formatCollectionIterator;
|
formatter = formatCollectionIterator;
|
||||||
} else if (simdFormatters &&
|
|
||||||
typeof constructor === 'function' &&
|
|
||||||
(maybeSimdFormatter = simdFormatters.get(constructor))) {
|
|
||||||
braces = ['[', ']'];
|
|
||||||
formatter = maybeSimdFormatter;
|
|
||||||
} else {
|
} else {
|
||||||
// Unset the constructor to prevent "Object {...}" for ordinary objects.
|
// Unset the constructor to prevent "Object {...}" for ordinary objects.
|
||||||
if (constructor && constructor.name === 'Object')
|
if (constructor && constructor.name === 'Object')
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
// Flags: --harmony_simd
|
|
||||||
/* global SIMD */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
require('../common');
|
|
||||||
const assert = require('assert');
|
|
||||||
const inspect = require('util').inspect;
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Bool16x8()),
|
|
||||||
'Bool16x8 [ false, false, false, false, false, false, false, false ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Bool32x4()),
|
|
||||||
'Bool32x4 [ false, false, false, false ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Bool8x16()),
|
|
||||||
'Bool8x16 [\n false,\n false,\n false,\n false,\n false,\n' +
|
|
||||||
' false,\n false,\n false,\n false,\n false,\n false,\n' +
|
|
||||||
' false,\n false,\n false,\n false,\n false ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Bool32x4()),
|
|
||||||
'Bool32x4 [ false, false, false, false ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Float32x4()),
|
|
||||||
'Float32x4 [ NaN, NaN, NaN, NaN ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Int16x8()),
|
|
||||||
'Int16x8 [ 0, 0, 0, 0, 0, 0, 0, 0 ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Int32x4()),
|
|
||||||
'Int32x4 [ 0, 0, 0, 0 ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Int8x16()),
|
|
||||||
'Int8x16 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Uint16x8()),
|
|
||||||
'Uint16x8 [ 0, 0, 0, 0, 0, 0, 0, 0 ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Uint32x4()),
|
|
||||||
'Uint32x4 [ 0, 0, 0, 0 ]');
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
inspect(SIMD.Uint8x16()),
|
|
||||||
'Uint8x16 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]');
|
|
||||||
|
|
||||||
// Tests from test-inspect.js that should not fail with --harmony_simd.
|
|
||||||
assert.strictEqual(inspect([]), '[]');
|
|
||||||
assert.strictEqual(inspect([0]), '[ 0 ]');
|
|
||||||
assert.strictEqual(inspect({}), '{}');
|
|
||||||
assert.strictEqual(inspect({foo: 42}), '{ foo: 42 }');
|
|
||||||
assert.strictEqual(inspect(null), 'null');
|
|
||||||
assert.strictEqual(inspect(true), 'true');
|
|
||||||
assert.strictEqual(inspect(false), 'false');
|
|
Loading…
x
Reference in New Issue
Block a user