Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var obj = {
}
};

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(1);
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(1));
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
sample.copyWithin(obj, obj);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ features: [BigInt, Symbol, TypedArray]

var s = Symbol(1);

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.copyWithin(0, 0, s);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ includes: [testTypedArray.js]
features: [BigInt, TypedArray]
---*/

testWithBigIntTypedArrayConstructors(function(TA) {
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var o1 = {
valueOf: function() {
throw new Test262Error();
}
};
var sample = new TA();
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.copyWithin(0, 0, o1);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ features: [BigInt, Symbol, TypedArray]

var s = Symbol(1);

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.copyWithin(0, s);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ var err = {
}
};

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.copyWithin(0, o, err);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ features: [BigInt, Symbol, TypedArray]

var s = Symbol(1);

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.copyWithin(s, 0);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var o = {
}
};

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.copyWithin(o);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ includes: [nans.js, compareArray.js, testTypedArray.js]
features: [TypedArray]
---*/

testWithTypedArrayConstructors(function body(FloatArray) {
var subject = new FloatArray(NaNs.length * 2);
testWithTypedArrayConstructors(function body(FloatArray, makeCtorArg) {
var subject = new FloatArray(makeCtorArg(NaNs.length * 2));

NaNs.forEach(function(v, i) {
subject[i] = v;
Expand All @@ -39,4 +39,4 @@ testWithTypedArrayConstructors(function body(FloatArray) {
);

assert(compareArray(originalBytes, copiedBytes));
}, floatArrayConstructors);
}, floatArrayConstructors, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray]
---*/

testWithTypedArrayConstructors(function(TA) {
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var ta;
var array = [];

Expand All @@ -33,8 +33,8 @@ testWithTypedArrayConstructors(function(TA) {

array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed
array.fill(7, 0);
ta = new TA(array);
ta = new TA(makeCtorArg(array));
assert.throws(TypeError, function(){
ta.copyWithin(0, 100, {valueOf : detachAndReturnIndex});
}, "should throw TypeError as array is detached");
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray]
---*/

testWithTypedArrayConstructors(function(TA) {
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var ta;
function detachAndReturnIndex(){
$DETACHBUFFER(ta.buffer);
Expand All @@ -31,8 +31,8 @@ testWithTypedArrayConstructors(function(TA) {
var array = [];
array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed
array.fill(7, 0);
ta = new TA(array);
ta = new TA(makeCtorArg(array));
assert.throws(TypeError, function(){
ta.copyWithin(0, 100, {valueOf : detachAndReturnIndex});
}, "should throw TypeError as array is detached");
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ includes: [testTypedArray.js, detachArrayBuffer.js]
features: [TypedArray]
---*/

testWithTypedArrayConstructors(function(TA) {
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var ta;
function detachAndReturnIndex(){
$DETACHBUFFER(ta.buffer);
Expand All @@ -31,8 +31,8 @@ testWithTypedArrayConstructors(function(TA) {
var array = [];
array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed
array.fill(7, 0);
ta = new TA(array);
ta = new TA(makeCtorArg(array));
assert.throws(TypeError, function(){
ta.copyWithin(0, {valueOf : detachAndReturnIndex}, 1000);
}, "should throw TypeError as array is detached");
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var obj = {
}
};

testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(1));
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
sample.copyWithin(obj, obj);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2025 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-%typedarray%.prototype.copywithin
description: Throws a TypeError exception when the backing buffer is immutable
info: |
%TypedArray%.prototype.copyWithin ( target, start [ , end ] )
1. Let O be the this value.
2. Let taRecord be ? ValidateTypedArray(O, ~seq-cst~, ~write~).
3. Let len be TypedArrayLength(taRecord).
4. Let relativeTarget be ? ToIntegerOrInfinity(target).
5. If relativeTarget = -∞, let targetIndex be 0.
6. Else if relativeTarget < 0, let targetIndex be max(len + relativeTarget, 0).
7. Else, let targetIndex be min(relativeTarget, len).
8. Let relativeStart be ? ToIntegerOrInfinity(start).
9. If relativeStart = -∞, let startIndex be 0.
10. Else if relativeStart < 0, let startIndex be max(len + relativeStart, 0).
11. Else, let startIndex be min(relativeStart, len).
12. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).

ValidateTypedArray ( O, order [ , accessMode ] )
1. If accessMode is not present, set accessMode to read.
2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
4. If accessMode is ~write~ and IsImmutableBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
features: [TypedArray, immutable-arraybuffer]
includes: [testTypedArray.js, compareArray.js]
---*/

testWithAllTypedArrayConstructors((TA, makeCtorArg) => {
var calls = [];

var ta = new TA(makeCtorArg(["1", "2", "3", "4"]));
var target = {
valueOf() {
calls.push("target.valueOf");
return 1;
}
};
var start = {
valueOf() {
calls.push("start.valueOf");
return 2;
}
};
var end = {
valueOf() {
calls.push("end.valueOf");
return 2;
}
};

assert.throws(TypeError, function() {
ta.copyWithin(target, start, end);
});
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
assert.compareArray(ta, new TA(["1", "2", "3", "4"]), "Must not mutate contents.");
}, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ features: [Symbol, TypedArray]

var s = Symbol(1);

testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.copyWithin(0, 0, s);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ includes: [testTypedArray.js]
features: [TypedArray]
---*/

testWithTypedArrayConstructors(function(TA) {
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var o1 = {
valueOf: function() {
throw new Test262Error();
}
};
var sample = new TA();
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.copyWithin(0, 0, o1);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ features: [Symbol, TypedArray]

var s = Symbol(1);

testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.copyWithin(0, s);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ var err = {
}
};

testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.copyWithin(0, o, err);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ features: [Symbol, TypedArray]

var s = Symbol(1);

testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.copyWithin(s, 0);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var o = {
}
};

testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.copyWithin(o);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var obj = {
}
};

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA(1);
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(1));
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
sample.fill(obj);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ features: [BigInt, Symbol, TypedArray]

var end = Symbol(1);

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.fill(1n, 0, end);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ var end = {
}
};

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.fill(1n, 0, end);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ features: [BigInt, Symbol, TypedArray]

var start = Symbol(1);

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(TypeError, function() {
sample.fill(1n, start);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var start = {
}
};

testWithBigIntTypedArrayConstructors(function(TA) {
var sample = new TA();
testWithBigIntTypedArrayConstructors(function(TA, makeCtorArg) {
var sample = new TA(makeCtorArg(0));
assert.throws(Test262Error, function() {
sample.fill(1n, start);
});
}, null, ["passthrough"]);
}, null, null, ["immutable"]);
Loading
Loading