Run Test262 tests that include testTypedArray.js (#2031)

This commit is contained in:
Chris Tate
2026-10-23 14:59:25 -05:00
committed by GitHub
14 changed files with 1032 additions and 7 deletions
+20
View File
@@ -101,6 +101,26 @@ test("the property helper only admits direct inline descriptor checks", () => {
}
});
test("the typed array helper is admitted without the %TypedArray% intrinsic", () => {
const text = source(
"includes: [testTypedArray.js]",
"testWithTypedArrayConstructors(function(TA) { assert.sameValue(new TA(1).length, 1); });",
);
expect(exclusion(text, metadata(text), "strict")).toBeUndefined();
const prepared = prepare(text, false, undefined, "strict", ["testTypedArray.js"]);
expect(prepared).toContain("function testWithTypedArrayConstructors(");
expect(prepared).not.toContain("Object.getPrototypeOf(Int8Array)");
for (const body of [
"assert.sameValue(typeof TypedArray, 'function');",
"testWithTypedArrayConstructors(function(TA) { assert.sameValue(Object.getPrototypeOf(TA), TypedArray); });",
]) {
const named = source("includes: [testTypedArray.js]", body);
expect(exclusion(named, metadata(named), "strict")).toBe("harness:TypedArray-intrinsic");
}
const other = source("includes: [testTypedArray.js, detachArrayBuffer.js]");
expect(exclusion(other, metadata(other), "strict")).toBe("harness-includes:detachArrayBuffer.js");
});
test("receiver-bound this is admitted without adapting script-level this", () => {
for (const [body, expected] of [
["class C { read() { return this.value; } }", undefined],
+69
View File
@@ -19,6 +19,10 @@ const upstreamHarness = ["assert.js", "sta.js"]
.map((name) => readFileSync(join(vendorRoot, "harness", name), "utf8"))
.join("\n");
const upstreamPropertyHelper = readFileSync(join(vendorRoot, "harness/propertyHelper.js"), "utf8");
const upstreamTypedArrayHelper = readFileSync(
join(vendorRoot, "harness/testTypedArray.js"),
"utf8",
);
function runUpstream(
source: string,
@@ -29,6 +33,8 @@ function runUpstream(
runInContext(upstreamHarness, context, { timeout: 5000 });
if (includes.includes("propertyHelper.js"))
runInContext(upstreamPropertyHelper, context, { timeout: 5000 });
if (includes.includes("testTypedArray.js"))
runInContext(upstreamTypedArrayHelper, context, { timeout: 5000 });
runInContext(variant === "strict" ? `"use strict";\n${source}` : source, context, {
timeout: 5000,
});
@@ -52,6 +58,8 @@ async function runUpstreamAsync(
runInContext(upstreamHarness, context, { timeout: 5000 });
if (includes.includes("propertyHelper.js"))
runInContext(upstreamPropertyHelper, context, { timeout: 5000 });
if (includes.includes("testTypedArray.js"))
runInContext(upstreamTypedArrayHelper, context, { timeout: 5000 });
runInContext(variant === "strict" ? `"use strict";\n${source}` : source, context, {
timeout: 5000,
});
@@ -375,6 +383,67 @@ if (propertyControls.length > 0)
}
});
const typedArrayControls = shardSelect(
[
{
name: "every constructor with array, array-like and buffer arguments",
status: "pass",
source:
"testWithTypedArrayConstructors(function(TA, makeCtorArg) { var sample = new TA(makeCtorArg([40, 41, 42])); assert.sameValue(sample.length, 3); assert.sameValue(sample[2], 42); }, null, ['passthrough', 'arraylike', 'arraybuffer']);",
},
{
name: "failing element assertion",
status: "fail",
source:
"testWithTypedArrayConstructors(function(TA, makeCtorArg) { var sample = new TA(makeCtorArg([40, 41, 42])); assert.sameValue(sample[2], 43); });",
},
{
name: "failure in one constructor",
status: "fail",
source:
"testWithTypedArrayConstructors(function(TA) { assert(TA !== Int16Array, 'Int16Array'); });",
},
{
name: "passthrough factories visit each constructor once",
status: "pass",
source:
"var count = 0; testWithTypedArrayConstructors(function(TA, makeCtorArg) { assert.sameValue(new TA(makeCtorArg(4)).length, 4); count++; }, null, ['passthrough']); assert.sameValue(count, typedArrayConstructors.length);",
},
{
name: "explicit constructor list",
status: "pass",
source:
"var names = []; testWithTypedArrayConstructors(function(TA) { names.push(TA.name); }, [Uint8Array, Float64Array], ['passthrough']); assert.compareArray(names, ['Uint8Array', 'Float64Array']);",
},
{
name: "float constructor classification",
status: "pass",
source:
"assert(isFloatTypedArrayConstructor(Float32Array)); assert(!isFloatTypedArrayConstructor(Int8Array)); assert.sameValue(floatTypedArrayConstructorPrecision(Float64Array), 'double');",
},
{
name: "unknown argument factory feature",
status: "fail",
source: "testWithTypedArrayConstructors(function() {}, null, ['unknown']);",
},
],
(item) => `typed-array:${item.name}`,
);
if (typedArrayControls.length > 0)
describe(`Test262 typed array helper contract${shardSuffix()}`, () => {
for (const control of typedArrayControls) {
test(control.name, async () => {
const includes = ["compareArray.js", "testTypedArray.js"];
if (control.status === "fail")
expect(() => runUpstream(control.source, "strict", includes)).toThrow();
else expect(() => runUpstream(control.source, "strict", includes)).not.toThrow();
const result = await runSource(control.source, { sanitize, includes });
expect(result, JSON.stringify(result, null, 2)).toMatchObject({ status: control.status });
});
}
});
const asyncControls = shardSelect(
[
{
+2 -2
View File
@@ -28,11 +28,11 @@ Pass the resulting directory as `--root` and use `--filter` to survey an API fam
## Execution profile and limits
The current profile is `static-adapted-v5`. It adapts strict scripts to standalone modules and sloppy scripts to CommonJS entries. Preparation supplies host assertions and a completion marker while leaving the upstream test body unchanged. Each program executes in a fresh native process. Conservative syntax checks reject known global-script dependencies, but cannot establish that every adaptation preserves the original script's semantics. Reports are local investigation artifacts, not published compatibility assessments.
The current profile is `static-adapted-v6`. It adapts strict scripts to standalone modules and sloppy scripts to CommonJS entries. Preparation supplies host assertions and a completion marker while leaving the upstream test body unchanged. Each program executes in a fresh native process. Conservative syntax checks reject known global-script dependencies, but cannot establish that every adaptation preserves the original script's semantics. Reports are local investigation artifacts, not published compatibility assessments.
The unmodified upstream assertion helper currently reaches scriptc's JavaScript function-expando refusal. Test262 explicitly permits host implementations of harness functions in its [interpretation rules](https://github.com/tc39/test262/blob/7ab7fafa0003f73fc85c1b95d88094d33f7eb8bd/INTERPRETING.md#host-defined-functions). `harness.ts` supplies `assert`, `assert.sameValue`, `assert.notSameValue`, `assert.compareArray`, `assert.throws` for selected Error constructors, `$DONE`, and `Test262Error`. Scalar SameValue and scalar array-element comparisons use the statically compiled `node:assert/strict` implementation. Contract tests compare successful and failing assertions with the original Test262 helpers under Node, including NaN, signed zero, null/undefined, differing primitive types, and premature termination.
Reference-equality assertions terminate with a distinct harness-refusal result: conversion at a native function boundary can copy references, so this adapter cannot faithfully compare every object, array, or function identity. Tests cannot catch this refusal and accidentally pass. Sparse array comparisons are not yet handled faithfully across that boundary. The adapted `propertyHelper.js` admits direct `verifyProperty` calls with an inline descriptor literal or `undefined`; reference-valued comparisons still refuse, while other property helpers and descriptor expressions remain excluded. Assertion aliases, mutation, reflection, additional assertion methods, and other `includes` helpers remain excluded.
Reference-equality assertions terminate with a distinct harness-refusal result: conversion at a native function boundary can copy references, so this adapter cannot faithfully compare every object, array, or function identity. Tests cannot catch this refusal and accidentally pass. Sparse array comparisons are not yet handled faithfully across that boundary. The adapted `propertyHelper.js` admits direct `verifyProperty` calls with an inline descriptor literal or `undefined`; reference-valued comparisons still refuse, while other property helpers and descriptor expressions remain excluded. The adapted `testTypedArray.js` keeps the upstream constructor lists, argument factories and `testWith*` helpers. It omits the `TypedArray` (%TypedArray%) binding, so tests that name it are excluded. Its resizable and immutable buffer factories run only where `ArrayBuffer.prototype` provides `resize` and `transferToImmutable`, as the upstream feature checks intend. Contract tests compare its successful and failing uses with the upstream helper under Node. Assertion aliases, mutation, reflection, additional assertion methods, and other `includes` helpers remain excluded.
Raw tests, module variants, agents, resolution negatives, and runtime negatives remain excluded. Parse negatives pass only when a source-matched syntax or vetted JavaScript early-error diagnostic appears; TypeScript type errors and harness-only failures never satisfy a negative expectation. `$262`, dynamic evaluation, observable script-global state, and other unsupported host requirements are excluded as well. The runtime and compiler continue to enforce their existing refusal boundaries for admitted source.
+3 -3
View File
@@ -4,7 +4,7 @@ import { parseArgs } from "node:util";
import { shardSelect } from "../harness/shard.js";
import { runSource, type Outcome } from "./execute.js";
import {
assertThrowsSource, directory, exclusion, harnessSource, propertyHelperSource, matchesExpectation, matchesParseNegative, metadata, pin, sha256, snapshotDigest, summarize,
assertThrowsSource, directory, exclusion, harnessSource, propertyHelperSource, typedArrayHelperSource, matchesExpectation, matchesParseNegative, metadata, pin, sha256, snapshotDigest, summarize,
testPaths, variants, vendorRoot, verifyVendor,
} from "./support.mjs";
@@ -104,8 +104,8 @@ Other variants remain visible as exclusions.`);
const report = {
schema: "scriptc.test262.v1",
revision: pin.commit, snapshotSha256: pin.snapshotSha256,
profile: "static-adapted-v5",
harnessSha256: sha256(harnessSource + assertThrowsSource + propertyHelperSource),
profile: "static-adapted-v6",
harnessSha256: sha256(harnessSource + assertThrowsSource + propertyHelperSource + typedArrayHelperSource),
requestedBackend: backend, sanitize: process.env.SCRIPTC_SAN === "1",
host: `${process.platform}-${process.arch}`, node: process.version,
compilerVersion: JSON.parse(readFileSync(join(directory, "../../packages/compiler/package.json"), "utf8")).version,
+10 -2
View File
@@ -12,6 +12,8 @@ export const completion = "__scriptc_test262_complete__";
export const harnessSource = readFileSync(join(directory, "harness.ts"), "utf8");
export const assertThrowsSource = readFileSync(join(directory, "assert-throws.js"), "utf8");
export const propertyHelperSource = readFileSync(join(directory, "property-helper.js"), "utf8");
export const typedArrayHelperSource = readFileSync(join(directory, "test-typed-array.js"), "utf8");
const adaptedIncludes = new Set(["compareArray.js", "propertyHelper.js", "testTypedArray.js"]);
export const expectations = JSON.parse(readFileSync(join(directory, "expectations.json"), "utf8"));
export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
@@ -131,11 +133,12 @@ export function exclusion(source, meta, variant) {
}
if (variant !== "strict" && variant !== "sloppy") return `execution:${variant}`;
if (meta.flags.some((flag) => flag.startsWith("CanBlock"))) return "host:agents";
const unsupportedIncludes = meta.includes.filter((name) => name !== "compareArray.js" && name !== "propertyHelper.js");
const unsupportedIncludes = meta.includes.filter((name) => !adaptedIncludes.has(name));
if (unsupportedIncludes.length) return `harness-includes:${unsupportedIncludes.join(",")}`;
const sf = ts.createSourceFile("test.js", source, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
let reason;
const propertyHelper = meta.includes.includes("propertyHelper.js");
const typedArrayHelper = meta.includes.includes("testTypedArray.js");
const forbidden = new Set(["$262", "$DONE", "$DONOTEVALUATE", "globalThis", "eval", "Function", "print", "process", "require"]);
if (variant === "sloppy") for (const name of ["module", "exports", "__dirname", "__filename"]) forbidden.add(name);
if (meta.flags.includes("async")) forbidden.delete("$DONE");
@@ -170,6 +173,9 @@ export function exclusion(source, meta, variant) {
reason = "harness:compareArray-surface";
} else if (ts.isIdentifier(node) && node.text === "Test262Error") {
if (!ts.isNewExpression(node.parent) || node.parent.expression !== node) reason = "harness:Test262Error-surface";
} else if (typedArrayHelper && ts.isIdentifier(node) && node.text === "TypedArray") {
// The adapted testTypedArray.js leaves out %TypedArray%.
reason = "harness:TypedArray-intrinsic";
} else if (propertyHelper && ts.isIdentifier(node)) {
if (unsupportedPropertyHelpers.has(node.text)) reason = "harness:propertyHelper-surface";
else if (node.text === "verifyProperty") {
@@ -188,7 +194,9 @@ export function exclusion(source, meta, variant) {
export function prepare(source, asyncTest = false, marker = completion, variant = "strict", includes = []) {
const names = asyncTest ? "assert, Test262Error, $DONE" : "assert, Test262Error";
const end = asyncTest ? "" : `;console.log(${JSON.stringify(marker)});\n`;
const helpers = includes.includes("propertyHelper.js") ? `${propertyHelperSource}\n` : "";
const helpers =
(includes.includes("propertyHelper.js") ? `${propertyHelperSource}\n` : "") +
(includes.includes("testTypedArray.js") ? `${typedArrayHelperSource}\n` : "");
if (variant === "sloppy") return `const { ${names} } = require("./harness.ts");\n${helpers}${source}\n${end}`;
return `"use strict";\nimport { ${names} } from "./harness.ts";\n${helpers}${source}\n${end}`;
}
+313
View File
@@ -0,0 +1,313 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This adaptation of Test262's testTypedArray.js is governed by the BSD license in vendor/LICENSE.
// It keeps the upstream constructor lists and argument factories. The host
// assert.js is replaced by harness.ts, so isPrimitive is defined here, and
// Test262Error is a class that needs `new`. Factories bind through a
// closure, and feature checks use typeof (and tolerate an ArrayBuffer
// without a reachable prototype, which then has no resizable or immutable
// factories). %TypedArray% (`TypedArray`) is left out: tests that name it
// are excluded.
function isPrimitive(value) {
return !value || (typeof value !== "object" && typeof value !== "function");
}
var floatArrayConstructors = [
Float64Array,
Float32Array
];
var nonClampedIntArrayConstructors = [
Int32Array,
Int16Array,
Int8Array,
Uint32Array,
Uint16Array,
Uint8Array
];
var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]);
// Float16Array is a newer feature
// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it
if (typeof Float16Array !== "undefined") {
floatArrayConstructors.push(Float16Array);
}
var bigIntArrayConstructors = [];
if (typeof BigInt64Array !== "undefined") {
bigIntArrayConstructors.push(BigInt64Array);
}
if (typeof BigUint64Array !== "undefined") {
bigIntArrayConstructors.push(BigUint64Array);
}
var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
var allTypedArrayConstructors = typedArrayConstructors.concat(bigIntArrayConstructors);
function makePassthrough(TA, primitiveOrIterable) {
return primitiveOrIterable;
}
function makeArray(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable);
// Only values between 0 and 2**53 - 1 inclusive can get mapped into TA contents.
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return Array.from({ length: n }, function() { return "0"; });
}
return Array.from(primitiveOrIterable);
}
function makeArrayLike(TA, primitiveOrIterable) {
var arr = makeArray(TA, primitiveOrIterable);
if (isPrimitive(arr)) return arr;
var obj = { length: arr.length };
for (var i = 0; i < obj.length; i++) obj[i] = arr[i];
return obj;
}
var makeIterable;
if (typeof Symbol !== "undefined") {
makeIterable = function makeIterable(TA, primitiveOrIterable) {
var src = makeArray(TA, primitiveOrIterable);
if (isPrimitive(src)) return src;
var obj = {};
obj[Symbol.iterator] = function() { return src[Symbol.iterator](); };
return obj;
};
}
function makeArrayBuffer(TA, primitiveOrIterable) {
var arr = makeArray(TA, primitiveOrIterable);
if (isPrimitive(arr)) return arr;
return new TA(arr).buffer;
}
var makeResizableArrayBuffer, makeGrownArrayBuffer, makeShrunkArrayBuffer, makeImmutableArrayBuffer;
if (typeof ArrayBuffer.prototype === "object" && typeof ArrayBuffer.prototype.resize === "function") {
var copyIntoArrayBuffer = function(destBuffer, srcBuffer) {
var destView = new Uint8Array(destBuffer);
var srcView = new Uint8Array(srcBuffer);
for (var i = 0; i < srcView.length; i++) destView[i] = srcView[i];
return destBuffer;
};
makeResizableArrayBuffer = function makeResizableArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return new ArrayBuffer(n, { maxByteLength: n * 2 });
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var resizable = new ArrayBuffer(byteLength, { maxByteLength: byteLength * 2 });
return copyIntoArrayBuffer(resizable, fixed);
};
makeGrownArrayBuffer = function makeGrownArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
var grown = new ArrayBuffer(Math.floor(n / 2), { maxByteLength: n });
grown.resize(n);
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var grown = new ArrayBuffer(Math.floor(byteLength / 2), { maxByteLength: byteLength });
grown.resize(byteLength);
return copyIntoArrayBuffer(grown, fixed);
};
makeShrunkArrayBuffer = function makeShrunkArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
var shrunk = new ArrayBuffer(n * 2, { maxByteLength: n * 2 });
shrunk.resize(n);
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var shrunk = new ArrayBuffer(byteLength * 2, { maxByteLength: byteLength * 2 });
copyIntoArrayBuffer(shrunk, fixed);
shrunk.resize(byteLength);
return shrunk;
};
}
if (typeof ArrayBuffer.prototype === "object" && typeof ArrayBuffer.prototype.transferToImmutable === "function") {
makeImmutableArrayBuffer = function makeImmutableArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return (new ArrayBuffer(n)).transferToImmutable();
}
var mutable = makeArrayBuffer(TA, primitiveOrIterable);
return mutable.transferToImmutable();
};
}
var typedArrayCtorArgFactories = [makePassthrough, makeArray, makeArrayLike];
if (makeIterable) typedArrayCtorArgFactories.push(makeIterable);
typedArrayCtorArgFactories.push(makeArrayBuffer);
if (makeResizableArrayBuffer) typedArrayCtorArgFactories.push(makeResizableArrayBuffer);
if (makeGrownArrayBuffer) typedArrayCtorArgFactories.push(makeGrownArrayBuffer);
if (makeShrunkArrayBuffer) typedArrayCtorArgFactories.push(makeShrunkArrayBuffer);
if (makeImmutableArrayBuffer) typedArrayCtorArgFactories.push(makeImmutableArrayBuffer);
function ctorArgFactoryMatchesSome(argFactory, features) {
for (var i = 0; i < features.length; ++i) {
switch (features[i]) {
case "passthrough":
if (argFactory === makePassthrough) return true;
break;
case "arraylike":
if (argFactory === makeArray || argFactory === makeArrayLike) return true;
break;
case "iterable":
if (argFactory === makeIterable) return true;
break;
case "arraybuffer":
if (
argFactory === makeArrayBuffer ||
argFactory === makeResizableArrayBuffer ||
argFactory === makeGrownArrayBuffer ||
argFactory === makeShrunkArrayBuffer ||
argFactory === makeImmutableArrayBuffer
) {
return true;
}
break;
case "resizable":
if (
argFactory === makeResizableArrayBuffer ||
argFactory === makeGrownArrayBuffer ||
argFactory === makeShrunkArrayBuffer
) {
return true;
}
break;
case "immutable":
if (argFactory === makeImmutableArrayBuffer) return true;
break;
default:
throw new Test262Error("unknown feature: " + features[i]);
}
}
return false;
}
function bindArgFactory(argFactory, constructor) {
return function(primitiveOrIterable) {
return argFactory(constructor, primitiveOrIterable);
};
}
function testWithAllTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || allTypedArrayConstructors;
var ctorArgFactories = typedArrayCtorArgFactories;
if (includeArgFactories) {
ctorArgFactories = [];
for (var i = 0; i < typedArrayCtorArgFactories.length; ++i) {
if (ctorArgFactoryMatchesSome(typedArrayCtorArgFactories[i], includeArgFactories)) {
ctorArgFactories.push(typedArrayCtorArgFactories[i]);
}
}
}
if (excludeArgFactories) {
ctorArgFactories = ctorArgFactories.slice();
for (var i = ctorArgFactories.length - 1; i >= 0; --i) {
if (ctorArgFactoryMatchesSome(ctorArgFactories[i], excludeArgFactories)) {
ctorArgFactories.splice(i, 1);
}
}
}
if (ctorArgFactories.length === 0) {
throw new Test262Error("no arg factories match include " + includeArgFactories + " and exclude " + excludeArgFactories);
}
for (var k = 0; k < ctorArgFactories.length; ++k) {
var argFactory = ctorArgFactories[k];
for (var i = 0; i < ctors.length; ++i) {
var constructor = ctors[i];
var boundArgFactory = bindArgFactory(argFactory, constructor);
try {
f(constructor, boundArgFactory);
} catch (e) {
e.message += " (Testing with " + constructor.name + " and " + argFactory.name + ".)";
throw e;
}
}
}
}
function testWithTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || typedArrayConstructors;
testWithAllTypedArrayConstructors(f, ctors, includeArgFactories, excludeArgFactories);
}
function testWithBigIntTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || [BigInt64Array, BigUint64Array];
testWithAllTypedArrayConstructors(f, ctors, includeArgFactories, excludeArgFactories);
}
var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]);
function testWithNonAtomicsFriendlyTypedArrayConstructors(f, includeArgFactories, excludeArgFactories) {
testWithAllTypedArrayConstructors(
f,
nonAtomicsFriendlyTypedArrayConstructors,
includeArgFactories,
excludeArgFactories
);
}
function testWithAtomicsFriendlyTypedArrayConstructors(f, includeArgFactories, excludeArgFactories) {
testWithAllTypedArrayConstructors(
f,
[
Int32Array,
Int16Array,
Int8Array,
Uint32Array,
Uint16Array,
Uint8Array,
],
includeArgFactories,
excludeArgFactories
);
}
function testTypedArrayConversions(byteConversionValues, fn) {
var values = byteConversionValues.values;
var expected = byteConversionValues.expected;
testWithTypedArrayConstructors(function(TA) {
var name = TA.name.slice(0, -5);
return values.forEach(function(value, index) {
var exp = expected[name][index];
var initial = 0;
if (exp === 0) {
initial = 1;
}
fn(TA, value, exp, initial);
});
}, null, ["passthrough"]);
}
function isFloatTypedArrayConstructor(arg) {
return floatArrayConstructors.indexOf(arg) !== -1;
}
function floatTypedArrayConstructorPrecision(FA) {
if (typeof Float16Array !== "undefined" && FA === Float16Array) {
return "half";
} else if (FA === Float32Array) {
return "single";
} else if (FA === Float64Array) {
return "double";
} else {
throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray");
}
}
+13
View File
@@ -169,6 +169,12 @@
"test/built-ins/String/prototype/trim/15.5.4.20-2-47.js",
"test/built-ins/String/prototype/trim/15.5.4.20-2-50.js",
"test/built-ins/String/prototype/trim/15.5.4.20-2-6.js",
"test/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js",
"test/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js",
"test/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero-sab.js",
"test/built-ins/TypedArrayConstructors/ctors/length-arg/is-infinity-throws-rangeerror.js",
"test/built-ins/TypedArrayConstructors/ctors/typedarray-arg/undefined-newtarget-throws.js",
"test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js",
"test/language/arguments-object/func-decl-args-trailing-comma-null.js",
"test/language/arguments-object/func-expr-args-trailing-comma-undefined.js",
"test/language/expressions/addition/S11.6.1_A4_T1.js",
@@ -214,6 +220,7 @@
"harness/assert.js": "206e274ca325eb8a652e3911c3fbd090e2480d11ed7579dc17a5d17a2360ed48",
"harness/propertyHelper.js": "08bc29114d804c4f24f906bac950ee4dc9c93c659d93258e7b44a54283ba9bb8",
"harness/sta.js": "1930c54af79455c484799f43e9a28e2b2f15c40d0917c9941ca54e26db243f35",
"harness/testTypedArray.js": "51eb50e53e6215f31f14d64d249bea2d08ad943c77835f63ba52ec694de2189a",
"test/annexB/language/function-code/function-redeclaration-block.js": "8d4a3f259dabceeee101959aac117a19f5bfe9e374e1178b45f45a1142195d9e",
"test/annexB/language/function-code/if-decl-else-decl-b-func-existing-fn-no-init.js": "ccd95922fd6c784012f7299445f0859db04812232a2266dd90070b026244bbf5",
"test/built-ins/Array/prototype/at/returns-item-relative-index.js": "71f53cf86f1387101b19b6ae9939d47ced34497d3cee12f954eef454f912ba88",
@@ -377,6 +384,12 @@
"test/built-ins/String/prototype/trim/15.5.4.20-2-47.js": "3e1a745af465177a96a29601e56299afc044060dbc2ac3061a59032be451cfde",
"test/built-ins/String/prototype/trim/15.5.4.20-2-50.js": "38b84997faa99e422408917eeac7f3575bd6064b429ea390a9d041fd77fce532",
"test/built-ins/String/prototype/trim/15.5.4.20-2-6.js": "3d5857f24117f65f07a70edd0d254dfa07f593c76effed94500847ccf8564c06",
"test/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js": "04cd6e31c8223319bbc6f5e5630ee476708a3897ead70e9cec34d40fb3ebd062",
"test/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js": "51fd475317d19c863a85c26f1ffa2070b10abf123b49a3243bb3829218b0b7a9",
"test/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero-sab.js": "96741e885f333125077884cb59c23c297fad61a4834941a5ac38720227094d7d",
"test/built-ins/TypedArrayConstructors/ctors/length-arg/is-infinity-throws-rangeerror.js": "ea340740e8fb3227b19fff023508c38d3bd6b2ff45f7a623d1e4460fad9b32c1",
"test/built-ins/TypedArrayConstructors/ctors/typedarray-arg/undefined-newtarget-throws.js": "19d2ebe0d3db51eb9f978b9b2462bb38ff5cf4702f32e3163d8be46e851d0f8f",
"test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js": "711cf2873e49c9d48b3246f8dd067380ac902d286907b620735f5f4dbd36c943",
"test/language/arguments-object/func-decl-args-trailing-comma-null.js": "80aecea8edd0d7bac1ddcfcd6cb97dc9a513b25a9283bb9cedd21fd77dd64d50",
"test/language/arguments-object/func-expr-args-trailing-comma-undefined.js": "cf39515a9031db4c81db231a157516bdc97617c392e4ef28890b2ae74777a99e",
"test/language/expressions/addition/S11.6.1_A4_T1.js": "12928eb319dcf0cc785e399580effb0b7495709296dce9c0a58e8408616a959f",
+431
View File
@@ -0,0 +1,431 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
Collection of functions used to assert the correctness of TypedArray objects.
defines:
- floatArrayConstructors
- nonClampedIntArrayConstructors
- intArrayConstructors
- typedArrayConstructors
- TypedArray
- testWithAllTypedArrayConstructors
- testWithTypedArrayConstructors
- testWithBigIntTypedArrayConstructors
- nonAtomicsFriendlyTypedArrayConstructors
- testWithAtomicsFriendlyTypedArrayConstructors
- testWithNonAtomicsFriendlyTypedArrayConstructors
- testTypedArrayConversions
---*/
var floatArrayConstructors = [
Float64Array,
Float32Array
];
var nonClampedIntArrayConstructors = [
Int32Array,
Int16Array,
Int8Array,
Uint32Array,
Uint16Array,
Uint8Array
];
var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]);
// Float16Array is a newer feature
// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it
if (typeof Float16Array !== "undefined") {
floatArrayConstructors.push(Float16Array);
}
var bigIntArrayConstructors = [];
if (typeof BigInt64Array !== "undefined") {
bigIntArrayConstructors.push(BigInt64Array);
}
if (typeof BigUint64Array !== "undefined") {
bigIntArrayConstructors.push(BigUint64Array);
}
/**
* Array containing every non-bigint typed array constructor.
*/
var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
/**
* Array containing every typed array constructor, including those with bigint values.
*/
var allTypedArrayConstructors = typedArrayConstructors.concat(bigIntArrayConstructors);
/**
* The %TypedArray% intrinsic constructor function.
*/
var TypedArray = Object.getPrototypeOf(Int8Array);
function makePassthrough(TA, primitiveOrIterable) {
return primitiveOrIterable;
}
function makeArray(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable);
// Only values between 0 and 2**53 - 1 inclusive can get mapped into TA contents.
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return Array.from({ length: n }, function() { return "0"; });
}
return Array.from(primitiveOrIterable);
}
function makeArrayLike(TA, primitiveOrIterable) {
var arr = makeArray(TA, primitiveOrIterable);
if (isPrimitive(arr)) return arr;
var obj = { length: arr.length };
for (var i = 0; i < obj.length; i++) obj[i] = arr[i];
return obj;
}
var makeIterable;
if (typeof Symbol !== "undefined" && Symbol.iterator) {
makeIterable = function makeIterable(TA, primitiveOrIterable) {
var src = makeArray(TA, primitiveOrIterable);
if (isPrimitive(src)) return src;
var obj = {};
obj[Symbol.iterator] = function() { return src[Symbol.iterator](); };
return obj;
};
}
function makeArrayBuffer(TA, primitiveOrIterable) {
var arr = makeArray(TA, primitiveOrIterable);
if (isPrimitive(arr)) return arr;
return new TA(arr).buffer;
}
var makeResizableArrayBuffer, makeGrownArrayBuffer, makeShrunkArrayBuffer, makeImmutableArrayBuffer;
if (ArrayBuffer.prototype.resize) {
var copyIntoArrayBuffer = function(destBuffer, srcBuffer) {
var destView = new Uint8Array(destBuffer);
var srcView = new Uint8Array(srcBuffer);
for (var i = 0; i < srcView.length; i++) destView[i] = srcView[i];
return destBuffer;
};
makeResizableArrayBuffer = function makeResizableArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return new ArrayBuffer(n, { maxByteLength: n * 2 });
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var resizable = new ArrayBuffer(byteLength, { maxByteLength: byteLength * 2 });
return copyIntoArrayBuffer(resizable, fixed);
};
makeGrownArrayBuffer = function makeGrownArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
var grown = new ArrayBuffer(Math.floor(n / 2), { maxByteLength: n });
grown.resize(n);
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var grown = new ArrayBuffer(Math.floor(byteLength / 2), { maxByteLength: byteLength });
grown.resize(byteLength);
return copyIntoArrayBuffer(grown, fixed);
};
makeShrunkArrayBuffer = function makeShrunkArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
var shrunk = new ArrayBuffer(n * 2, { maxByteLength: n * 2 });
shrunk.resize(n);
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var shrunk = new ArrayBuffer(byteLength * 2, { maxByteLength: byteLength * 2 });
copyIntoArrayBuffer(shrunk, fixed);
shrunk.resize(byteLength);
return shrunk;
};
}
if (ArrayBuffer.prototype.transferToImmutable) {
makeImmutableArrayBuffer = function makeImmutableArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return (new ArrayBuffer(n)).transferToImmutable();
}
var mutable = makeArrayBuffer(TA, primitiveOrIterable);
return mutable.transferToImmutable();
};
}
var typedArrayCtorArgFactories = [makePassthrough, makeArray, makeArrayLike];
if (makeIterable) typedArrayCtorArgFactories.push(makeIterable);
typedArrayCtorArgFactories.push(makeArrayBuffer);
if (makeResizableArrayBuffer) typedArrayCtorArgFactories.push(makeResizableArrayBuffer);
if (makeGrownArrayBuffer) typedArrayCtorArgFactories.push(makeGrownArrayBuffer);
if (makeShrunkArrayBuffer) typedArrayCtorArgFactories.push(makeShrunkArrayBuffer);
if (makeImmutableArrayBuffer) typedArrayCtorArgFactories.push(makeImmutableArrayBuffer);
/**
* @typedef {"passthrough" | "arraylike" | "iterable" | "arraybuffer" | "resizable" | "immutable"} typedArrayArgFactoryFeature
*/
/**
* A predicate for testing whether a TypedArray argument factory from this file
* matches any of the provided features.
*
* @param {Function} argFactory
* @param {typedArrayArgFactoryFeature[]} features
* @returns {boolean}
*/
function ctorArgFactoryMatchesSome(argFactory, features) {
for (var i = 0; i < features.length; ++i) {
switch (features[i]) {
case "passthrough":
if (argFactory === makePassthrough) return true;
break;
case "arraylike":
if (argFactory === makeArray || argFactory === makeArrayLike) return true;
break;
case "iterable":
if (argFactory === makeIterable) return true;
break;
case "arraybuffer":
if (
argFactory === makeArrayBuffer ||
argFactory === makeResizableArrayBuffer ||
argFactory === makeGrownArrayBuffer ||
argFactory === makeShrunkArrayBuffer ||
argFactory === makeImmutableArrayBuffer
) {
return true;
}
break;
case "resizable":
if (
argFactory === makeResizableArrayBuffer ||
argFactory === makeGrownArrayBuffer ||
argFactory === makeShrunkArrayBuffer
) {
return true;
}
break;
case "immutable":
if (argFactory === makeImmutableArrayBuffer) return true;
break;
default:
throw Test262Error("unknown feature: " + features[i]);
}
}
return false;
}
/**
* Callback for testing a typed array constructor.
*
* @callback typedArrayConstructorCallback
* @param {Function} TypedArrayConstructor the constructor object to test with
* @param {Function} [TypedArrayConstructorArgFactory] a function for making
* a TypedArrayConstructor argument from a primitive (usually a number) or
* iterable (usually an array)
*/
/**
* Calls the provided function with (typedArrayCtor, typedArrayCtorArgFactory)
* pairs, where typedArrayCtor is Uint8Array/Int8Array/BigInt64Array/etc. and
* typedArrayCtorArgFactory is a function for mapping a primitive (usually a
* number) or iterable (usually an array) into a value suitable as the first
* argument of typedArrayCtor (an Array, arraylike, iterable, or ArrayBuffer).
*
* @param {typedArrayConstructorCallback} f - the function to call
* @param {Array} [constructors] - an explicit list of TypedArray constructors
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithAllTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || allTypedArrayConstructors;
var ctorArgFactories = typedArrayCtorArgFactories;
if (includeArgFactories) {
ctorArgFactories = [];
for (var i = 0; i < typedArrayCtorArgFactories.length; ++i) {
if (ctorArgFactoryMatchesSome(typedArrayCtorArgFactories[i], includeArgFactories)) {
ctorArgFactories.push(typedArrayCtorArgFactories[i]);
}
}
}
if (excludeArgFactories) {
ctorArgFactories = ctorArgFactories.slice();
for (var i = ctorArgFactories.length - 1; i >= 0; --i) {
if (ctorArgFactoryMatchesSome(ctorArgFactories[i], excludeArgFactories)) {
ctorArgFactories.splice(i, 1);
}
}
}
if (ctorArgFactories.length === 0) {
throw Test262Error("no arg factories match include " + includeArgFactories + " and exclude " + excludeArgFactories);
}
for (var k = 0; k < ctorArgFactories.length; ++k) {
var argFactory = ctorArgFactories[k];
for (var i = 0; i < ctors.length; ++i) {
var constructor = ctors[i];
var boundArgFactory = argFactory.bind(undefined, constructor);
try {
f(constructor, boundArgFactory);
} catch (e) {
e.message += " (Testing with " + constructor.name + " and " + argFactory.name + ".)";
throw e;
}
}
}
}
/**
* Calls the provided function with (typedArrayCtor, typedArrayCtorArgFactory)
* pairs, where typedArrayCtor is Uint8Array/Int8Array/BigInt64Array/etc. and
* typedArrayCtorArgFactory is a function for mapping a primitive (usually a
* number) or iterable (usually an array) into a value suitable as the first
* argument of typedArrayCtor (an Array, arraylike, iterable, or ArrayBuffer).
*
* typedArrayCtor will not be BigInt64Array or BigUint64Array unless one or both
* of those are explicitly provided.
*
* @param {typedArrayConstructorCallback} f - the function to call
* @param {Array} [constructors] - an explicit list of TypedArray constructors
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || typedArrayConstructors;
testWithAllTypedArrayConstructors(f, ctors, includeArgFactories, excludeArgFactories);
}
/**
* Calls the provided function for every BigInt typed array constructor.
*
* @param {typedArrayConstructorCallback} f - the function to call
* @param {Array} [constructors] - an explicit list of TypedArray constructors
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithBigIntTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || [BigInt64Array, BigUint64Array];
testWithAllTypedArrayConstructors(f, ctors, includeArgFactories, excludeArgFactories);
}
var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]);
/**
* Calls the provided function for every non-"Atomics Friendly" typed array constructor.
*
* @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
* @param {Array} selected - An optional Array with filtered typed arrays
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithNonAtomicsFriendlyTypedArrayConstructors(f, includeArgFactories, excludeArgFactories) {
testWithAllTypedArrayConstructors(
f,
nonAtomicsFriendlyTypedArrayConstructors,
includeArgFactories,
excludeArgFactories
);
}
/**
* Calls the provided function for every "Atomics Friendly" typed array constructor.
*
* @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
* @param {Array} selected - An optional Array with filtered typed arrays
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithAtomicsFriendlyTypedArrayConstructors(f, includeArgFactories, excludeArgFactories) {
testWithAllTypedArrayConstructors(
f,
[
Int32Array,
Int16Array,
Int8Array,
Uint32Array,
Uint16Array,
Uint8Array,
],
includeArgFactories,
excludeArgFactories
);
}
/**
* Helper for conversion operations on TypedArrays, the expected values
* properties are indexed in order to match the respective value for each
* TypedArray constructor
* @param {Function} fn - the function to call for each constructor and value.
* will be called with the constructor, value, expected
* value, and a initial value that can be used to avoid
* a false positive with an equivalent expected value.
*/
function testTypedArrayConversions(byteConversionValues, fn) {
var values = byteConversionValues.values;
var expected = byteConversionValues.expected;
testWithTypedArrayConstructors(function(TA) {
var name = TA.name.slice(0, -5);
return values.forEach(function(value, index) {
var exp = expected[name][index];
var initial = 0;
if (exp === 0) {
initial = 1;
}
fn(TA, value, exp, initial);
});
}, null, ["passthrough"]);
}
/**
* Checks if the given argument is one of the float-based TypedArray constructors.
*
* @param {constructor} ctor - the value to check
* @returns {boolean}
*/
function isFloatTypedArrayConstructor(arg) {
return floatArrayConstructors.indexOf(arg) !== -1;
}
/**
* Determines the precision of the given float-based TypedArray constructor.
*
* @param {constructor} ctor - the value to check
* @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively.
*/
function floatTypedArrayConstructorPrecision(FA) {
if (typeof Float16Array !== "undefined" && FA === Float16Array) {
return "half";
} else if (FA === Float32Array) {
return "single";
} else if (FA === Float64Array) {
return "double";
} else {
throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray");
}
}
@@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-%typedarray%.prototype.byteoffset
description: >
Return value from [[ByteOffset]] internal slot
info: |
22.2.3.3 get %TypedArray%.prototype.byteOffset
...
6. Let offset be the value of O's [[ByteOffset]] internal slot.
7. Return size.
includes: [testTypedArray.js]
features: [TypedArray]
---*/
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var ta1 = new TA();
assert.sameValue(ta1.byteOffset, 0, "Regular typedArray");
var offset = 4 * TA.BYTES_PER_ELEMENT;
var buffer1 = makeCtorArg(8);
var ta2 = new TA(buffer1, offset);
assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)");
var buffer2 = makeCtorArg(8);
var sample = new TA(buffer2, offset);
var ta3 = new TA(sample);
assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)");
}, null, ["arraybuffer"]);
@@ -0,0 +1,24 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.subarray
description: Return abrupt from ToInteger(begin), begin is symbol
info: |
22.2.3.27 %TypedArray%.prototype.subarray( begin , end )
...
7. Let relativeBegin be ? ToInteger(begin).
...
includes: [testTypedArray.js]
features: [Symbol, TypedArray]
---*/
var s = Symbol("1");
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.subarray(s);
});
});
@@ -0,0 +1,23 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
description: >
TypedArray's [[ByteOffset]] internal slot is always a positive number, test with negative zero.
info: |
%TypedArray% ( buffer [ , byteOffset [ , length ] ] )
...
6. Let offset be ? ToInteger(byteOffset).
7. If offset < 0, throw a RangeError exception.
8. If offset is -0, let offset be +0.
...
includes: [testTypedArray.js]
features: [SharedArrayBuffer, TypedArray]
---*/
testWithTypedArrayConstructors(function(TAConstructor) {
var typedArray = new TAConstructor(new SharedArrayBuffer(8), -0);
assert.sameValue(typedArray.byteOffset, +0);
}, null, ["passthrough"]);
@@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-typedarray-length
description: >
Throws a RangeError if length is a Infinity value
info: |
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
5. Let elementLength be ToLength(numberLength).
6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError
exception.
...
includes: [testTypedArray.js]
features: [TypedArray]
---*/
testWithTypedArrayConstructors(function(TA) {
assert.throws(RangeError, function() {
new TA(Infinity);
});
}, null, ["passthrough"]);
@@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-typedarray-typedarray
description: >
Throws a TypeError if NewTarget is undefined.
info: |
22.2.4.3 TypedArray ( typedArray )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is Object and that
object has a [[TypedArrayName]] internal slot.
...
2. If NewTarget is undefined, throw a TypeError exception.
...
includes: [testTypedArray.js]
features: [TypedArray]
---*/
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var typedArray = new TA(makeCtorArg(4));
assert.throws(TypeError, function() {
TA(typedArray);
});
});
@@ -0,0 +1,39 @@
// Copyright (C) 2021 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Throws TypeError for valid index & non-configurable descriptor.
info: |
[[DefineOwnProperty]] ( P, Desc )
[...]
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
[...]
ii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false.
includes: [testTypedArray.js]
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
---*/
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg([0]));
assert.throws(TypeError, function() {
Object.defineProperty(sample, "0", {
configurable: false,
});
}, "partial descriptor");
assert.throws(TypeError, function() {
Object.defineProperty(sample, "0", {
value: 42,
writable: true,
enumerable: true,
configurable: false,
});
}, "complete descriptor");
assert.sameValue(sample[0], 0, "side effect check");
}, null, ["passthrough"]);