mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
Add tests for TypedArrays set
This commit is contained in:
parent
b17ffc0298
commit
2c7c989439
34
test/built-ins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js
vendored
Normal file
34
test/built-ins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Throw a RangeError exception if targetOffset < 0
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
7. If targetOffset < 0, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(4);
|
||||||
|
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set([1], -1);
|
||||||
|
}, "-1");
|
||||||
|
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set([1], -1.00001);
|
||||||
|
}, "-1.00001");
|
||||||
|
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set([1], -Infinity);
|
||||||
|
}, "-Infinity");
|
||||||
|
});
|
94
test/built-ins/TypedArray/prototype/set/array-arg-offset-tointeger.js
vendored
Normal file
94
test/built-ins/TypedArray/prototype/set/array-arg-offset-tointeger.js
vendored
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
ToInteger(offset) operations
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
7. If targetOffset < 0, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample;
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], "");
|
||||||
|
assert(compareArray(sample, [42, 2]), "the empty string");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], "0");
|
||||||
|
assert(compareArray(sample, [42, 2]), "'0'");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], false);
|
||||||
|
assert(compareArray(sample, [42, 2]), "false");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], 0.1);
|
||||||
|
assert(compareArray(sample, [42, 2]), "0.1");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], 0.9);
|
||||||
|
assert(compareArray(sample, [42, 2]), "0.9");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], -0.5);
|
||||||
|
assert(compareArray(sample, [42, 2]), "-0.5");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], 1.1);
|
||||||
|
assert(compareArray(sample, [1, 42]), "1.1");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], NaN);
|
||||||
|
assert(compareArray(sample, [42, 2]), "NaN");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], null);
|
||||||
|
assert(compareArray(sample, [42, 2]), "null");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], undefined);
|
||||||
|
assert(compareArray(sample, [42, 2]), "undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], {});
|
||||||
|
assert(compareArray(sample, [42, 2]), "{}");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], []);
|
||||||
|
assert(compareArray(sample, [42, 2]), "[]");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], [0]);
|
||||||
|
assert(compareArray(sample, [42, 2]), "[0]");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], true);
|
||||||
|
assert(compareArray(sample, [1, 42]), "true");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], "1");
|
||||||
|
assert(compareArray(sample, [1, 42]), "'1'");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], [1]);
|
||||||
|
assert(compareArray(sample, [1, 42]), "[1]");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], { valueOf: function() {return 1;} });
|
||||||
|
assert(compareArray(sample, [1, 42]), "valueOf");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set([42], { toString: function() {return 1;} });
|
||||||
|
assert(compareArray(sample, [1, 42]), "toString");
|
||||||
|
});
|
32
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js
vendored
Normal file
32
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt getting src "length"
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
16. Let srcLength be ? ToLength(? Get(src, "length")).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {};
|
||||||
|
Object.defineProperty(obj, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3]);
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
});
|
||||||
|
});
|
47
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js
vendored
Normal file
47
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from getting src property value
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
length: 4,
|
||||||
|
"0": 42,
|
||||||
|
"1": 43,
|
||||||
|
"3": 44
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj, "2", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3, 4]);
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(sample, [42, 43, 3, 4]),
|
||||||
|
"values are set until exception"
|
||||||
|
);
|
||||||
|
});
|
30
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js
vendored
Normal file
30
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt getting src "length" as symbol
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
16. Let srcLength be ? ToLength(? Get(src, "length")).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
length: Symbol("1")
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3]);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
});
|
||||||
|
});
|
45
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js
vendored
Normal file
45
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToLength(src "length")
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
16. Let srcLength be ? ToLength(? Get(src, "length")).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj1 = {
|
||||||
|
length: {
|
||||||
|
valueOf: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var obj2 = {
|
||||||
|
length: {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3]);
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(obj1);
|
||||||
|
}, "valueOf");
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(obj2);
|
||||||
|
}, "toString");
|
||||||
|
});
|
@ -0,0 +1,44 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToNumber(src property symbol value)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
length: 4,
|
||||||
|
"0": 42,
|
||||||
|
"1": 43,
|
||||||
|
"2": Symbol("1"),
|
||||||
|
"3": 44
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3, 4]);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(sample, [42, 43, 3, 4]),
|
||||||
|
"values are set until exception"
|
||||||
|
);
|
||||||
|
});
|
47
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js
vendored
Normal file
47
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToNumber(src property value)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
length: 4,
|
||||||
|
"0": 42,
|
||||||
|
"1": 43,
|
||||||
|
"2": {
|
||||||
|
valueOf: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"3": 44
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3, 4]);
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(sample, [42, 43, 3, 4]),
|
||||||
|
"values are set until exception"
|
||||||
|
);
|
||||||
|
});
|
27
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js
vendored
Normal file
27
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js
vendored
Normal file
@ -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%.prototype.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToInteger(Symbol offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var s = Symbol("1");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set([1], s);
|
||||||
|
});
|
||||||
|
});
|
40
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToInteger(offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj1 = {
|
||||||
|
valueOf: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var obj2 = {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set([], obj1);
|
||||||
|
}, "abrupt from valueOf");
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set([], obj2);
|
||||||
|
}, "abrupt from toString");
|
||||||
|
});
|
29
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js
vendored
Normal file
29
test/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToObject(array)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
15. Let src be ? ToObject(array).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3]);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(undefined);
|
||||||
|
}, "undefined");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(null);
|
||||||
|
}, "null");
|
||||||
|
});
|
71
test/built-ins/TypedArray/prototype/set/array-arg-set-values-in-order.js
vendored
Normal file
71
test/built-ins/TypedArray/prototype/set/array-arg-set-values-in-order.js
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Get and set each value in order
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(5);
|
||||||
|
var calls = [];
|
||||||
|
var obj = {
|
||||||
|
length: 3
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj, 0, {
|
||||||
|
get: function() {
|
||||||
|
calls.push(0);
|
||||||
|
calls.push(sample.join());
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(obj, 1, {
|
||||||
|
get: function() {
|
||||||
|
calls.push(1);
|
||||||
|
calls.push(sample.join());
|
||||||
|
return 43;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(obj, 2, {
|
||||||
|
get: function() {
|
||||||
|
calls.push(2);
|
||||||
|
calls.push(sample.join());
|
||||||
|
return 44;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(obj, 3, {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error("Should not call obj[3]");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sample.set(obj, 1);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(sample, [0, 42, 43, 44, 0]),
|
||||||
|
"values are set for src length"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(calls, [0, "0,0,0,0,0", 1, "0,42,0,0,0", 2, "0,42,43,0,0"]),
|
||||||
|
"values are set in order"
|
||||||
|
);
|
||||||
|
});
|
62
test/built-ins/TypedArray/prototype/set/array-arg-set-values.js
vendored
Normal file
62
test/built-ins/TypedArray/prototype/set/array-arg-set-values.js
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Set values to target and return undefined
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
Let Pk be ! ToString(k).
|
||||||
|
Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber).
|
||||||
|
...
|
||||||
|
22. Return undefined.
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var src = [42, 43];
|
||||||
|
var srcObj = {
|
||||||
|
length: 2,
|
||||||
|
'0': 7,
|
||||||
|
'1': 17
|
||||||
|
};
|
||||||
|
var sample, result;
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 0);
|
||||||
|
assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 1);
|
||||||
|
assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 2);
|
||||||
|
assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(srcObj, 0);
|
||||||
|
assert(compareArray(sample, [7, 17, 3, 4]), "offset: 0, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(srcObj, 1);
|
||||||
|
assert(compareArray(sample, [1, 7, 17, 4]), "offset: 1, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(srcObj, 2);
|
||||||
|
assert(compareArray(sample, [1, 2, 7, 17]), "offset: 2, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
});
|
30
test/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js
vendored
Normal file
30
test/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Values conversions on ToNumber(src property value)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testTypedArrayConversions(function(TA, value, expected, initial) {
|
||||||
|
var sample = new TA([initial]);
|
||||||
|
|
||||||
|
sample.set([value]);
|
||||||
|
|
||||||
|
assert.sameValue(sample[0], expected, "["+value+"] => ["+expected +"]");
|
||||||
|
});
|
49
test/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js
vendored
Normal file
49
test/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Type conversions on ToNumber(src property value)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj1 = {
|
||||||
|
valueOf: function() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var obj2 = {
|
||||||
|
toString: function() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// undefined and NaN covered on typedArrayConversions
|
||||||
|
var arr = ["1", "", false, true, null, obj1, obj2, [], [1]];
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(arr.length);
|
||||||
|
var expected = new TA([1, 0, 0, 1, 0, 42, 42, 0, 1]);
|
||||||
|
|
||||||
|
sample.set(arr);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
compareArray(sample, expected),
|
||||||
|
"sample: [" + sample + "], expected: [" + expected + "]"
|
||||||
|
);
|
||||||
|
});
|
46
test/built-ins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js
vendored
Normal file
46
test/built-ins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Values from src array are not cached
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(5);
|
||||||
|
var obj = {
|
||||||
|
length: 5,
|
||||||
|
'1': 7,
|
||||||
|
'2': 7,
|
||||||
|
'3': 7,
|
||||||
|
'4': 7
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj, 0, {
|
||||||
|
get: function() {
|
||||||
|
obj[1] = 43;
|
||||||
|
obj[2] = 44;
|
||||||
|
obj[3] = 45;
|
||||||
|
obj[4] = 46;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sample.set(obj);
|
||||||
|
|
||||||
|
assert(compareArray(sample, [42, 43, 44, 45, 46]));
|
||||||
|
});
|
40
test/built-ins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Uses target's internal [[ArrayLength]]
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
10. Let targetLength be the value of target's [[ArrayLength]] internal slot.
|
||||||
|
...
|
||||||
|
17. If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var getCalls = 0;
|
||||||
|
var desc = {
|
||||||
|
get: function() {
|
||||||
|
getCalls++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
|
||||||
|
Object.defineProperty(TA.prototype, "length", desc);
|
||||||
|
Object.defineProperty(sample, "length", desc);
|
||||||
|
|
||||||
|
sample.set([42, 43]);
|
||||||
|
|
||||||
|
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||||
|
});
|
@ -0,0 +1,44 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Throws an error if buffer is detached before setting a value
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
21. Repeat, while targetByteIndex < limit
|
||||||
|
a. Let Pk be ! ToString(k).
|
||||||
|
b. Let kNumber be ? ToNumber(? Get(src, Pk)).
|
||||||
|
c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
kNumber).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([1, 2, 3]);
|
||||||
|
var obj = {
|
||||||
|
length: 3,
|
||||||
|
"0": 42
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj, 1, {
|
||||||
|
get: function() {
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.defineProperty(obj, 2, {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error("Should not get other values");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,38 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if targetBuffer is detached on ToInteger(offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
...
|
||||||
|
8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal
|
||||||
|
slot.
|
||||||
|
9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
var calledOffset = 0;
|
||||||
|
var obj = {
|
||||||
|
valueOf: function() {
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
calledOffset += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set([1], obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(calledOffset, 1);
|
||||||
|
});
|
42
test/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js
vendored
Normal file
42
test/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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.set-array-offset
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if targetBuffer is detached
|
||||||
|
info: >
|
||||||
|
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: array is any ECMAScript language value other than an Object with a
|
||||||
|
[[TypedArrayName]] internal slot. If it is such an Object, the definition in
|
||||||
|
22.2.3.23.2 applies.
|
||||||
|
...
|
||||||
|
8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal
|
||||||
|
slot.
|
||||||
|
9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
15. Let src be ? ToObject(array).
|
||||||
|
16. Let srcLength be ? ToLength(? Get(src, "length")).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {};
|
||||||
|
Object.defineProperty(obj, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set([1]);
|
||||||
|
}, "regular check");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(obj);
|
||||||
|
}, "IsDetachedBuffer happens before Get(src.length)");
|
||||||
|
});
|
@ -1,33 +0,0 @@
|
|||||||
// 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.set
|
|
||||||
description: Throws a TypeError if this has a detached buffer
|
|
||||||
info: >
|
|
||||||
22.2.3.23 %TypedArray%.prototype.set ( overloaded [ , offset ])
|
|
||||||
|
|
||||||
22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )
|
|
||||||
|
|
||||||
...
|
|
||||||
9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
|
||||||
...
|
|
||||||
|
|
||||||
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
|
||||||
|
|
||||||
...
|
|
||||||
9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
|
||||||
...
|
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
|
||||||
var sample = new TA();
|
|
||||||
$DETACHBUFFER(sample.buffer);
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
sample.set([]);
|
|
||||||
}, "argument is an array");
|
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
|
||||||
sample.set(sample);
|
|
||||||
}, "argument is a TypedArray object");
|
|
||||||
});
|
|
32
test/built-ins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js
vendored
Normal file
32
test/built-ins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Throw a RangeError exception if targetOffset < 0
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
7. If targetOffset < 0, throw a RangeError exception.
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(sample, -1);
|
||||||
|
}, "-1");
|
||||||
|
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(sample, -1.00001);
|
||||||
|
}, "-1.00001");
|
||||||
|
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(sample, -Infinity);
|
||||||
|
}, "-Infinity");
|
||||||
|
});
|
92
test/built-ins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js
vendored
Normal file
92
test/built-ins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js
vendored
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
ToInteger(offset) operations
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample;
|
||||||
|
var src = new TA([42]);
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, "");
|
||||||
|
assert(compareArray(sample, [42, 2]), "the empty string");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, "0");
|
||||||
|
assert(compareArray(sample, [42, 2]), "'0'");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, false);
|
||||||
|
assert(compareArray(sample, [42, 2]), "false");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, 0.1);
|
||||||
|
assert(compareArray(sample, [42, 2]), "0.1");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, 0.9);
|
||||||
|
assert(compareArray(sample, [42, 2]), "0.9");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, -0.5);
|
||||||
|
assert(compareArray(sample, [42, 2]), "-0.5");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, 1.1);
|
||||||
|
assert(compareArray(sample, [1, 42]), "1.1");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, NaN);
|
||||||
|
assert(compareArray(sample, [42, 2]), "NaN");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, null);
|
||||||
|
assert(compareArray(sample, [42, 2]), "null");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, undefined);
|
||||||
|
assert(compareArray(sample, [42, 2]), "undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, {});
|
||||||
|
assert(compareArray(sample, [42, 2]), "{}");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, []);
|
||||||
|
assert(compareArray(sample, [42, 2]), "[]");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, [0]);
|
||||||
|
assert(compareArray(sample, [42, 2]), "[0]");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, true);
|
||||||
|
assert(compareArray(sample, [1, 42]), "true");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, "1");
|
||||||
|
assert(compareArray(sample, [1, 42]), "'1'");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, [1]);
|
||||||
|
assert(compareArray(sample, [1, 42]), "[1]");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, { valueOf: function() {return 1;} });
|
||||||
|
assert(compareArray(sample, [1, 42]), "valueOf");
|
||||||
|
|
||||||
|
sample = new TA([1, 2]);
|
||||||
|
sample.set(src, { toString: function() {return 1;} });
|
||||||
|
assert(compareArray(sample, [1, 42]), "toString");
|
||||||
|
});
|
@ -0,0 +1,26 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToInteger(Symbol offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var s = Symbol("1");
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(sample, s);
|
||||||
|
});
|
||||||
|
});
|
39
test/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js
vendored
Normal file
39
test/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToInteger(offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj1 = {
|
||||||
|
valueOf: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var obj2 = {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(sample, obj1);
|
||||||
|
}, "abrupt from valueOf");
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.set(sample, obj2);
|
||||||
|
}, "abrupt from toString");
|
||||||
|
});
|
@ -0,0 +1,37 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Set converted values from different buffer and different type instances
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
23. If SameValue(srcBuffer, targetBuffer) is true, then
|
||||||
|
...
|
||||||
|
24. Else, let srcByteIndex be srcByteOffset.
|
||||||
|
...
|
||||||
|
27. If SameValue(srcType, targetType) is true, then,
|
||||||
|
...
|
||||||
|
28. Else,
|
||||||
|
a. Repeat, while targetByteIndex < limit
|
||||||
|
i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType).
|
||||||
|
ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
value).
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testTypedArrayConversions(function(TA, value, expected, initial) {
|
||||||
|
if (TA === Float64Array) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var src = new Float64Array([value]);
|
||||||
|
var target = new TA([initial]);
|
||||||
|
|
||||||
|
target.set(src);
|
||||||
|
|
||||||
|
assert.sameValue(target[0], expected);
|
||||||
|
});
|
47
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js
vendored
Normal file
47
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Set values from different instances using the different buffer and different
|
||||||
|
type.
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
23. If SameValue(srcBuffer, targetBuffer) is true, then
|
||||||
|
...
|
||||||
|
24. Else, let srcByteIndex be srcByteOffset.
|
||||||
|
...
|
||||||
|
27. If SameValue(srcType, targetType) is true, then,
|
||||||
|
...
|
||||||
|
28. Else,
|
||||||
|
a. Repeat, while targetByteIndex < limit
|
||||||
|
i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType).
|
||||||
|
ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
value).
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var other = TA === Float32Array ? Float64Array : Float32Array;
|
||||||
|
var src = new other([42, 43]);
|
||||||
|
var sample, result;
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 0);
|
||||||
|
assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 1);
|
||||||
|
assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 2);
|
||||||
|
assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
});
|
49
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js
vendored
Normal file
49
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Set values from different instances using the different buffer and same
|
||||||
|
constructor. srcBuffer values are cached.
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
23. If SameValue(srcBuffer, targetBuffer) is true, then
|
||||||
|
...
|
||||||
|
24. Else, let srcByteIndex be srcByteOffset.
|
||||||
|
...
|
||||||
|
27. If SameValue(srcType, targetType) is true, then,
|
||||||
|
a. NOTE: If srcType and targetType are the same, the transfer must be
|
||||||
|
performed in a manner that preserves the bit-level encoding of the source
|
||||||
|
data.
|
||||||
|
b. Repeat, while targetByteIndex < limit
|
||||||
|
i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8").
|
||||||
|
ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8",
|
||||||
|
value).
|
||||||
|
...
|
||||||
|
29. Return undefined.
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample, result;
|
||||||
|
var src = new TA([42, 43]);
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 1);
|
||||||
|
assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 0);
|
||||||
|
assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
result = sample.set(src, 2);
|
||||||
|
assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
});
|
58
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js
vendored
Normal file
58
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js
vendored
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Set values from different instances using the same buffer and different
|
||||||
|
constructor.
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
23. If SameValue(srcBuffer, targetBuffer) is true, then
|
||||||
|
a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength,
|
||||||
|
%ArrayBuffer%).
|
||||||
|
b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not
|
||||||
|
have any observable side-effects.
|
||||||
|
...
|
||||||
|
...
|
||||||
|
27. If SameValue(srcType, targetType) is true, then,
|
||||||
|
...
|
||||||
|
28. Else,
|
||||||
|
a. Repeat, while targetByteIndex < limit
|
||||||
|
i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType).
|
||||||
|
ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
|
||||||
|
value).
|
||||||
|
...
|
||||||
|
29. Return undefined.
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var expected = {
|
||||||
|
Float64Array: [1.0000002464512363, 42, 1.875, 4, 5, 6, 7, 8],
|
||||||
|
Float32Array: [0, 42, 512.0001220703125, 4, 5, 6, 7, 8],
|
||||||
|
Int32Array: [1109917696, 42, 0, 4, 5, 6, 7, 8],
|
||||||
|
Int16Array: [0, 42, 0, 4, 5, 6, 7, 8],
|
||||||
|
Int8Array: [0, 42, 0, 66, 5, 6, 7, 8],
|
||||||
|
Uint32Array: [1109917696, 42, 0, 4, 5, 6, 7, 8],
|
||||||
|
Uint16Array: [0, 42, 0, 4, 5, 6, 7, 8],
|
||||||
|
Uint8Array: [0, 42, 0, 66, 5, 6, 7, 8],
|
||||||
|
Uint8ClampedArray: [0, 42, 0, 66, 5, 6, 7, 8]
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var other = TA === Float32Array ? Float64Array : Float32Array;
|
||||||
|
|
||||||
|
var sample = new TA([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||||
|
var src = new other(sample.buffer, 0, 2);
|
||||||
|
|
||||||
|
// Reflect changes on sample object
|
||||||
|
src[0] = 42;
|
||||||
|
|
||||||
|
var result = sample.set(src, 1);
|
||||||
|
|
||||||
|
assert(compareArray(sample, expected[TA.name]), sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
});
|
52
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js
vendored
Normal file
52
test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Set values from different instances using the same buffer and same
|
||||||
|
constructor. srcBuffer values are cached.
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
23. If SameValue(srcBuffer, targetBuffer) is true, then
|
||||||
|
a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength,
|
||||||
|
%ArrayBuffer%).
|
||||||
|
b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not
|
||||||
|
have any observable side-effects.
|
||||||
|
...
|
||||||
|
...
|
||||||
|
27. If SameValue(srcType, targetType) is true, then,
|
||||||
|
a. NOTE: If srcType and targetType are the same, the transfer must be
|
||||||
|
performed in a manner that preserves the bit-level encoding of the source
|
||||||
|
data.
|
||||||
|
b. Repeat, while targetByteIndex < limit
|
||||||
|
i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8").
|
||||||
|
ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8",
|
||||||
|
value).
|
||||||
|
includes: [testTypedArray.js, compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample, src, result;
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
src = new TA(sample.buffer, 0, 2);
|
||||||
|
result = sample.set(src, 0);
|
||||||
|
assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
src = new TA(sample.buffer, 0, 2);
|
||||||
|
result = sample.set(src, 1);
|
||||||
|
assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
|
||||||
|
sample = new TA([1, 2, 3, 4]);
|
||||||
|
src = new TA(sample.buffer, 0, 2);
|
||||||
|
result = sample.set(src, 2);
|
||||||
|
assert(compareArray(sample, [1, 2, 1, 2]), "offset: 2, result: " + sample);
|
||||||
|
assert.sameValue(result, undefined, "returns undefined");
|
||||||
|
});
|
40
test/built-ins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Uses typedArray's internal [[ArrayLength]]
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot.
|
||||||
|
...
|
||||||
|
22. If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var getCalls = 0;
|
||||||
|
var desc = {
|
||||||
|
get: function getLen() {
|
||||||
|
getCalls++;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
var src = new TA([42, 43]);
|
||||||
|
|
||||||
|
Object.defineProperty(TA.prototype, "length", desc);
|
||||||
|
Object.defineProperty(src, "length", desc);
|
||||||
|
|
||||||
|
sample.set(src);
|
||||||
|
|
||||||
|
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||||
|
});
|
@ -0,0 +1,50 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
...
|
||||||
|
10. Let targetLength be the value of target's [[ArrayLength]] internal slot.
|
||||||
|
...
|
||||||
|
20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot.
|
||||||
|
...
|
||||||
|
22. If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample, src;
|
||||||
|
|
||||||
|
sample = new TA(2);
|
||||||
|
src = new TA(2);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(src, 1);
|
||||||
|
}, "2 + 1 > 2");
|
||||||
|
|
||||||
|
sample = new TA(1);
|
||||||
|
src = new TA(2);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(src, 0);
|
||||||
|
}, "2 + 0 > 1");
|
||||||
|
|
||||||
|
sample = new TA(1);
|
||||||
|
src = new TA(0);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(src, 2);
|
||||||
|
}, "0 + 2 > 1");
|
||||||
|
|
||||||
|
sample = new TA(2);
|
||||||
|
src = new TA(2);
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
sample.set(src, Infinity);
|
||||||
|
}, "2 + Infinity > 2");
|
||||||
|
});
|
@ -0,0 +1,38 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if srcBuffer is detached on ToInteger(offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
...
|
||||||
|
11. Let srcBuffer be the value of typedArray's [[ViewedArrayBuffer]] internal
|
||||||
|
slot.
|
||||||
|
12. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
var target = new TA();
|
||||||
|
var calledOffset = 0;
|
||||||
|
var obj = {
|
||||||
|
valueOf: function() {
|
||||||
|
$DETACHBUFFER(target.buffer);
|
||||||
|
calledOffset += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(target, obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(calledOffset, 1);
|
||||||
|
});
|
41
test/built-ins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Uses target's internal [[ArrayLength]]
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
2. Let target be the this value.
|
||||||
|
...
|
||||||
|
10. Let targetLength be the value of target's [[ArrayLength]] internal slot.
|
||||||
|
...
|
||||||
|
22. If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var getCalls = 0;
|
||||||
|
var desc = {
|
||||||
|
get: function() {
|
||||||
|
getCalls++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
var src = new TA([42, 43]);
|
||||||
|
|
||||||
|
Object.defineProperty(TA.prototype, "length", desc);
|
||||||
|
Object.defineProperty(sample, "length", desc);
|
||||||
|
|
||||||
|
sample.set(src);
|
||||||
|
|
||||||
|
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||||
|
});
|
@ -0,0 +1,38 @@
|
|||||||
|
// 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.set-typedarray-offset
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if targetBuffer is detached on ToInteger(offset)
|
||||||
|
info: >
|
||||||
|
22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )
|
||||||
|
|
||||||
|
1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
|
||||||
|
the definition in 22.2.3.23.1 applies.
|
||||||
|
...
|
||||||
|
6. Let targetOffset be ? ToInteger(offset).
|
||||||
|
...
|
||||||
|
8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal
|
||||||
|
slot.
|
||||||
|
9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
var src = new TA(1);
|
||||||
|
var calledOffset = 0;
|
||||||
|
var obj = {
|
||||||
|
valueOf: function() {
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
calledOffset += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.set(src, obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(calledOffset, 1);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user