diff --git a/benchmark/util/type-check.js b/benchmark/util/type-check.js index 269c2a4e9c1374..0815dd70061c14 100644 --- a/benchmark/util/type-check.js +++ b/benchmark/util/type-check.js @@ -23,6 +23,11 @@ const args = { 'false-primitive': true, 'false-object': int32Array, }, + DataView: { + 'true': dataView, + 'false-primitive': true, + 'false-object': uint8Array, + }, }; const bench = common.createBenchmark(main, { diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 393608331aa1f5..81efeb6699aedc 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -6,6 +6,10 @@ const { TypedArrayPrototypeGetSymbolToStringTag, } = primordials; +function isDataView(value) { + return ArrayBufferIsView(value) && TypedArrayPrototypeGetSymbolToStringTag(value) === undefined; +} + function isTypedArray(value) { return TypedArrayPrototypeGetSymbolToStringTag(value) !== undefined; } @@ -61,6 +65,7 @@ function isBigUint64Array(value) { module.exports = { ...internalBinding('types'), isArrayBufferView: ArrayBufferIsView, + isDataView, isTypedArray, isUint8Array, isUint8ClampedArray, diff --git a/src/node_types.cc b/src/node_types.cc index c49d736b0a3a1f..f83559e82f6e69 100644 --- a/src/node_types.cc +++ b/src/node_types.cc @@ -19,7 +19,6 @@ namespace { V(AsyncFunction) \ V(BigIntObject) \ V(BooleanObject) \ - V(DataView) \ V(Date) \ V(External) \ V(GeneratorFunction) \ diff --git a/test/parallel/test-util-types.js b/test/parallel/test-util-types.js index b839447ad3bc22..cd698621fcee58 100644 --- a/test/parallel/test-util-types.js +++ b/test/parallel/test-util-types.js @@ -650,23 +650,6 @@ for (const [ value, _method ] of [ } } -{ - function testIsDataView(input) { - return types.isDataView(input); - } - - eval('%PrepareFunctionForOptimization(testIsDataView)'); - testIsDataView(new DataView(new ArrayBuffer())); - eval('%OptimizeFunctionOnNextCall(testIsDataView)'); - assert.strictEqual(testIsDataView(new DataView(new ArrayBuffer())), true); - assert.strictEqual(testIsDataView(Math.random()), false); - - if (common.isDebug) { - const { getV8FastApiCallCount } = internalBinding('debug'); - assert.strictEqual(getV8FastApiCallCount('types.isDataView'), 2); - } -} - { function testIsSharedArrayBuffer(input) { return types.isSharedArrayBuffer(input);