mirror of https://github.com/tc39/test262.git
Update Symbol.species tests for TypedArray constructor
This updates tests in line with https://github.com/tc39/ecma262/pull/2719
This commit is contained in:
parent
da507a703e
commit
51822ff2d8
|
@ -1,61 +0,0 @@
|
|||
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-typedarray
|
||||
description: >
|
||||
When a TypedArray is created from another TypedArray with a different element-type
|
||||
and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still
|
||||
executed.
|
||||
info: |
|
||||
22.2.4.3 TypedArray ( typedArray )
|
||||
|
||||
...
|
||||
16. If IsSharedArrayBuffer(srcData) is false, then
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
18. If SameValue(elementType, srcType) is true, then
|
||||
...
|
||||
19. Else,
|
||||
a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%",
|
||||
« [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
|
||||
...
|
||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||
features: [BigInt, TypedArray, Symbol.species]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var speciesCallCount = 0;
|
||||
var bufferConstructor = Object.defineProperty({}, Symbol.species, {
|
||||
get: function() {
|
||||
speciesCallCount += 1;
|
||||
$DETACHBUFFER(ta.buffer);
|
||||
return speciesConstructor;
|
||||
}
|
||||
});
|
||||
|
||||
var prototypeCallCount = 0;
|
||||
var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", {
|
||||
get: function() {
|
||||
prototypeCallCount += 1;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
var ta = new TA(0);
|
||||
ta.buffer.constructor = bufferConstructor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var targetType = TA !== BigInt64Array ? BigInt64Array : BigUint64Array;
|
||||
new targetType(ta);
|
||||
}, "TypeError thrown for detached source buffer");
|
||||
|
||||
assert.sameValue(speciesCallCount, 1, "@@species getter called once");
|
||||
assert.sameValue(prototypeCallCount, 1, "prototype getter called once");
|
||||
});
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-typedarray
|
||||
description: >
|
||||
When a TypedArray is created from another TypedArray with the same element-type
|
||||
and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still
|
||||
executed.
|
||||
info: |
|
||||
22.2.4.3 TypedArray ( typedArray )
|
||||
|
||||
...
|
||||
16. If IsSharedArrayBuffer(srcData) is false, then
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
18. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset, srcLength, cloneConstructor )
|
||||
|
||||
...
|
||||
3. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
|
||||
4. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%",
|
||||
« [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
|
||||
...
|
||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||
features: [BigInt, TypedArray, Symbol.species]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var speciesCallCount = 0;
|
||||
var bufferConstructor = Object.defineProperty({}, Symbol.species, {
|
||||
get: function() {
|
||||
speciesCallCount += 1;
|
||||
$DETACHBUFFER(ta.buffer);
|
||||
return speciesConstructor;
|
||||
}
|
||||
});
|
||||
|
||||
var prototypeCallCount = 0;
|
||||
var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", {
|
||||
get: function() {
|
||||
prototypeCallCount += 1;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
var ta = new TA(0);
|
||||
ta.buffer.constructor = bufferConstructor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(ta);
|
||||
}, "TypeError thrown for detached source buffer");
|
||||
|
||||
assert.sameValue(speciesCallCount, 1, "@@species getter called once");
|
||||
assert.sameValue(prototypeCallCount, 1, "prototype getter called once");
|
||||
});
|
|
@ -1,41 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from getting typedArray argument's buffer.constructor
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var OtherCtor = TA === BigInt64Array ? BigUint64Array : BigInt64Array;
|
||||
var sample = new OtherCtor();
|
||||
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,58 +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-typedarray
|
||||
description: >
|
||||
Derive the ArrayBuffer prototype from the realm of the species constructor
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
9.1.14 GetPrototypeFromConstructor
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, cross-realm, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new BigInt64Array();
|
||||
var sample2 = new BigUint64Array();
|
||||
var other = $262.createRealm().global;
|
||||
var C = new other.Function();
|
||||
C.prototype = null;
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === BigInt64Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = C;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype
|
||||
);
|
||||
});
|
|
@ -1,52 +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-typedarray
|
||||
description: >
|
||||
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new BigInt64Array();
|
||||
var sample2 = new BigUint64Array();
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === BigInt64Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
var called = 0;
|
||||
var custom = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function() {
|
||||
called++;
|
||||
};
|
||||
|
||||
ctor[Symbol.species].prototype = custom;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
|
||||
assert.sameValue(called, 0);
|
||||
});
|
|
@ -1,61 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from typedArray argument's buffer.constructor's value
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
4. If Type(C) is not Object, throw a TypeError exception.
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new BigInt64Array();
|
||||
var sample2 = new BigUint64Array();
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === BigInt64Array ? sample2 : sample1;
|
||||
|
||||
sample.buffer.constructor = 1;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = true;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = "";
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = null;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
var s = Symbol("1");
|
||||
sample.buffer.constructor = s;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,45 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from getting typedArray argument's buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new BigInt64Array();
|
||||
var sample2 = new BigUint64Array();
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === BigInt64Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
Object.defineProperty(ctor, Symbol.species, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,47 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
8. Throw a TypeError exception.
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new BigInt64Array();
|
||||
var sample2 = new BigUint64Array();
|
||||
|
||||
var ctor = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
var m = { m() {} }.m;
|
||||
ctor[Symbol.species] = m;
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === BigInt64Array ? sample2 : sample1;
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,59 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
...
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor,
|
||||
"%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » )
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new BigInt64Array();
|
||||
var sample2 = new BigUint64Array();
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === BigInt64Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
var called = 0;
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function() {called++;}.bind(null);
|
||||
Object.defineProperty(ctor[Symbol.species], "prototype", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
assert.sameValue(called, 0);
|
||||
});
|
|
@ -1,46 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from getting typedArray argument's buffer.constructor
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,68 +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-typedarray
|
||||
description: >
|
||||
Derive the ArrayBuffer prototype from the realm of the species constructor
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
|
||||
...
|
||||
|
||||
9.1.14 GetPrototypeFromConstructor
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, cross-realm, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var C = new other.Function();
|
||||
C.prototype = null;
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = C;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype
|
||||
);
|
||||
});
|
|
@ -1,60 +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-typedarray
|
||||
description: >
|
||||
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
var called = 0;
|
||||
var custom = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function() {
|
||||
called++;
|
||||
};
|
||||
|
||||
ctor[Symbol.species].prototype = custom;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
|
||||
assert.sameValue(called, 0);
|
||||
});
|
|
@ -1,49 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
8. Throw a TypeError exception.
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
var m = { m() {} };
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = m;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,62 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
...
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor,
|
||||
"%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » )
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function(){}.bind(null);
|
||||
Object.defineProperty(ctor[Symbol.species], "prototype", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,49 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from getting typedArray argument's buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
Object.defineProperty(ctor, Symbol.species, {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,65 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from typedArray argument's buffer.constructor's value
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
4. If Type(C) is not Object, throw a TypeError exception.
|
||||
...
|
||||
includes: [testBigIntTypedArray.js]
|
||||
features: [BigInt, Symbol, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
|
||||
sample.buffer.constructor = 1;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = true;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = '';
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = null;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
var s = Symbol('1');
|
||||
sample.buffer.constructor = s;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2022 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Creating TypedArray from other TypedArrays doesn't look up Symbol.species.
|
||||
features: [Symbol.species]
|
||||
---*/
|
||||
|
||||
let throwOnGrossBufferConstruction = false;
|
||||
|
||||
class GrossBuffer extends ArrayBuffer {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
if (throwOnGrossBufferConstruction) {
|
||||
throw new Test262Error("unreachable");
|
||||
}
|
||||
}
|
||||
static get [Symbol.species]() {
|
||||
throw new Test262Error("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
let grossBuf = new GrossBuffer(1024);
|
||||
throwOnGrossBufferConstruction = true;
|
||||
let grossTA = new Uint8Array(grossBuf);
|
||||
let mysteryTA = new Int8Array(grossTA);
|
||||
|
||||
assert.sameValue(mysteryTA.buffer.__proto__, ArrayBuffer.prototype);
|
||||
assert.sameValue(mysteryTA.buffer.constructor, ArrayBuffer);
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-typedarray
|
||||
description: >
|
||||
When a TypedArray is created from another TypedArray with a different element-type
|
||||
and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still
|
||||
executed.
|
||||
info: |
|
||||
22.2.4.3 TypedArray ( typedArray )
|
||||
|
||||
...
|
||||
16. If IsSharedArrayBuffer(srcData) is false, then
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
18. If SameValue(elementType, srcType) is true, then
|
||||
...
|
||||
19. Else,
|
||||
a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%",
|
||||
« [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
|
||||
...
|
||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||
features: [TypedArray, Symbol.species]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var speciesCallCount = 0;
|
||||
var bufferConstructor = Object.defineProperty({}, Symbol.species, {
|
||||
get: function() {
|
||||
speciesCallCount += 1;
|
||||
$DETACHBUFFER(ta.buffer);
|
||||
return speciesConstructor;
|
||||
}
|
||||
});
|
||||
|
||||
var prototypeCallCount = 0;
|
||||
var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", {
|
||||
get: function() {
|
||||
prototypeCallCount += 1;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
var ta = new TA(0);
|
||||
ta.buffer.constructor = bufferConstructor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var targetType = TA !== Int32Array ? Int32Array : Uint32Array;
|
||||
new targetType(ta);
|
||||
}, "TypeError thrown for detached source buffer");
|
||||
|
||||
assert.sameValue(speciesCallCount, 1, "@@species getter called once");
|
||||
assert.sameValue(prototypeCallCount, 1, "prototype getter called once");
|
||||
});
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-typedarray
|
||||
description: >
|
||||
When a TypedArray is created from another TypedArray with the same element-type
|
||||
and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still
|
||||
executed.
|
||||
info: |
|
||||
22.2.4.3 TypedArray ( typedArray )
|
||||
|
||||
...
|
||||
16. If IsSharedArrayBuffer(srcData) is false, then
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
18. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset, srcLength, cloneConstructor )
|
||||
|
||||
...
|
||||
3. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
|
||||
4. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%",
|
||||
« [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
|
||||
...
|
||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||
features: [TypedArray, Symbol.species]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var speciesCallCount = 0;
|
||||
var bufferConstructor = Object.defineProperty({}, Symbol.species, {
|
||||
get: function() {
|
||||
speciesCallCount += 1;
|
||||
$DETACHBUFFER(ta.buffer);
|
||||
return speciesConstructor;
|
||||
}
|
||||
});
|
||||
|
||||
var prototypeCallCount = 0;
|
||||
var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", {
|
||||
get: function() {
|
||||
prototypeCallCount += 1;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
var ta = new TA(0);
|
||||
ta.buffer.constructor = bufferConstructor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(ta);
|
||||
}, "TypeError thrown for detached source buffer");
|
||||
|
||||
assert.sameValue(speciesCallCount, 1, "@@species getter called once");
|
||||
assert.sameValue(prototypeCallCount, 1, "prototype getter called once");
|
||||
});
|
|
@ -1,41 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from getting typedArray argument's buffer.constructor
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var OtherCtor = TA === Int8Array ? Int16Array : Int8Array;
|
||||
var sample = new OtherCtor();
|
||||
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,59 +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-typedarray
|
||||
description: >
|
||||
Derive the ArrayBuffer prototype from the realm of the species constructor
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
9.1.14 GetPrototypeFromConstructor
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [cross-realm, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
var other = $262.createRealm().global;
|
||||
var C = new other.Function();
|
||||
C.prototype = null;
|
||||
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = C;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype
|
||||
);
|
||||
});
|
|
@ -1,52 +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-typedarray
|
||||
description: >
|
||||
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
var called = 0;
|
||||
var custom = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function() {
|
||||
called++;
|
||||
};
|
||||
|
||||
ctor[Symbol.species].prototype = custom;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
|
||||
assert.sameValue(called, 0);
|
||||
});
|
|
@ -1,61 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from typedArray argument's buffer.constructor's value
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
4. If Type(C) is not Object, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
|
||||
sample.buffer.constructor = 1;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = true;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = "";
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = null;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
var s = Symbol("1");
|
||||
sample.buffer.constructor = s;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,45 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from getting typedArray argument's buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
Object.defineProperty(ctor, Symbol.species, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,47 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
8. Throw a TypeError exception.
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
|
||||
var ctor = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
var m = { m() {} }.m;
|
||||
ctor[Symbol.species] = m;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,44 +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-typedarray
|
||||
description: >
|
||||
Use default ArrayBuffer constructor on null buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var OtherCtor = TA === Int8Array ? Int16Array : Int8Array;
|
||||
var sample = new OtherCtor();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = null;
|
||||
var typedArray = new TA(sample);
|
||||
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(typedArray.buffer),
|
||||
ArrayBuffer.prototype,
|
||||
"buffer ctor is not called when species is null"
|
||||
);
|
||||
});
|
|
@ -1,59 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
...
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor,
|
||||
"%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » )
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
var called = 0;
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function() {called++;}.bind(null);
|
||||
Object.defineProperty(ctor[Symbol.species], "prototype", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
assert.sameValue(called, 0);
|
||||
});
|
|
@ -1,43 +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-typedarray
|
||||
description: >
|
||||
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
18. Else,
|
||||
a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var OtherCtor = TA === Int8Array ? Int16Array : Int8Array;
|
||||
var sample = new OtherCtor();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = undefined;
|
||||
var a = new TA(sample);
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(a.buffer),
|
||||
ArrayBuffer.prototype,
|
||||
"buffer ctor is not called when species is undefined"
|
||||
);
|
||||
});
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright (C) 2021 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: >
|
||||
Error when a TypedArray is created from another TypedArray with a different
|
||||
element-type and SpeciesConstructor causes the "source" array to go
|
||||
out-of-bounds.
|
||||
includes: [testTypedArray.js, compareArray.js]
|
||||
features: [TypedArray, Symbol.species, resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
// If the host chooses to throw as allowed by the specification, the observed
|
||||
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
|
||||
// has not been implemented. The following assertion prevents this test from
|
||||
// passing in runtimes which have not implemented the method.
|
||||
assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var BPE = TA.BYTES_PER_ELEMENT;
|
||||
var TargetCtor = TA !== Int32Array ? Int32Array : Uint32Array;
|
||||
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||
var speciesConstructor = Object.defineProperty(function(){}.bind(), 'prototype', {
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
var onGetSpecies;
|
||||
ab.constructor = Object.defineProperty({}, Symbol.species, {
|
||||
get: function() {
|
||||
onGetSpecies();
|
||||
return speciesConstructor;
|
||||
}
|
||||
});
|
||||
var source = new TA(ab, BPE);
|
||||
var expected = [10, 20, 30];
|
||||
|
||||
source[0] = 10;
|
||||
source[1] = 20;
|
||||
source[2] = 30;
|
||||
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(BPE * 5);
|
||||
expected = [10, 20, 30, 0];
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
assert(compareArray(new TargetCtor(source), expected), 'following grow');
|
||||
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(BPE * 3);
|
||||
expected = [10, 20];
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
assert(compareArray(new TargetCtor(source), expected), 'following shrink (within bounds)');
|
||||
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(BPE);
|
||||
expected = [];
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
assert(compareArray(new TargetCtor(source), expected), 'following shrink (on boundary)');
|
||||
|
||||
// `assert.throws` cannot be used in this case because the expected error
|
||||
// is derived only after the constructor is invoked.
|
||||
var expectedError;
|
||||
var actualError;
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(0);
|
||||
expectedError = TypeError;
|
||||
} catch (_) {
|
||||
expectedError = Test262Error;
|
||||
}
|
||||
};
|
||||
try {
|
||||
new TargetCtor(source);
|
||||
throw new Test262Error('the operation completed successfully');
|
||||
} catch (caught) {
|
||||
actualError = caught;
|
||||
}
|
||||
|
||||
assert.sameValue(actualError.constructor, expectedError);
|
||||
});
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright (C) 2021 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: >
|
||||
Error when a TypedArray is created from another TypedArray with the same
|
||||
element-type and SpeciesConstructor causes the "source" array to go
|
||||
out-of-bounds.
|
||||
includes: [testTypedArray.js, compareArray.js]
|
||||
features: [TypedArray, Symbol.species, resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
// If the host chooses to throw as allowed by the specification, the observed
|
||||
// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
|
||||
// has not been implemented. The following assertion prevents this test from
|
||||
// passing in runtimes which have not implemented the method.
|
||||
assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var BPE = TA.BYTES_PER_ELEMENT;
|
||||
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||
var speciesConstructor = Object.defineProperty(function(){}.bind(), 'prototype', {
|
||||
get: function() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
var onGetSpecies;
|
||||
ab.constructor = Object.defineProperty({}, Symbol.species, {
|
||||
get: function() {
|
||||
onGetSpecies();
|
||||
return speciesConstructor;
|
||||
}
|
||||
});
|
||||
var source = new TA(ab, BPE);
|
||||
var expected = [10, 20, 30];
|
||||
|
||||
source[0] = 10;
|
||||
source[1] = 20;
|
||||
source[2] = 30;
|
||||
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(BPE * 5);
|
||||
expected = [10, 20, 30, 0];
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
assert.sameValue((new TA(source)).join(','), expected.join(','));
|
||||
assert(compareArray(new TA(source), expected), 'following grow');
|
||||
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(BPE * 3);
|
||||
expected = [10, 20];
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
assert(compareArray(new TA(source), expected), 'following shrink (within bounds)');
|
||||
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(BPE);
|
||||
expected = [];
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
assert(compareArray(new TA(source), expected), 'following shrink (on boundary)');
|
||||
|
||||
// `assert.throws` cannot be used in this case because the expected error
|
||||
// is derived only after the constructor is invoked.
|
||||
var expectedError;
|
||||
var actualError;
|
||||
onGetSpecies = function() {
|
||||
try {
|
||||
ab.resize(0);
|
||||
expectedError = TypeError;
|
||||
} catch (_) {
|
||||
expectedError = Test262Error;
|
||||
}
|
||||
};
|
||||
try {
|
||||
new TA(source);
|
||||
throw new Test262Error('the operation completed successfully');
|
||||
} catch (caught) {
|
||||
actualError = caught;
|
||||
}
|
||||
|
||||
assert.sameValue(actualError.constructor, expectedError);
|
||||
});
|
|
@ -1,46 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from getting typedArray argument's buffer.constructor
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,68 +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-typedarray
|
||||
description: >
|
||||
Derive the ArrayBuffer prototype from the realm of the species constructor
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
|
||||
...
|
||||
|
||||
9.1.14 GetPrototypeFromConstructor
|
||||
|
||||
...
|
||||
3. Let proto be ? Get(constructor, "prototype").
|
||||
4. If Type(proto) is not Object, then
|
||||
a. Let realm be ? GetFunctionRealm(constructor).
|
||||
b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [cross-realm, Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var C = new other.Function();
|
||||
C.prototype = null;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = C;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype
|
||||
);
|
||||
});
|
|
@ -1,60 +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-typedarray
|
||||
description: >
|
||||
Use default ArrayBuffer constructor on undefined buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
var called = 0;
|
||||
var custom = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function() {
|
||||
called++;
|
||||
};
|
||||
|
||||
ctor[Symbol.species].prototype = custom;
|
||||
|
||||
var typedArray = new TA(sample);
|
||||
assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
|
||||
assert.sameValue(called, 0);
|
||||
});
|
|
@ -1,49 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
8. Throw a TypeError exception.
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
var m = { m() {} };
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = m;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,62 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from buffer.constructor.@@species.prototype
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
6. If S is either undefined or null, return defaultConstructor.
|
||||
7. If IsConstructor(S) is true, return S.
|
||||
...
|
||||
|
||||
24.1.1.1 AllocateArrayBuffer ( constructor, byteLength )
|
||||
|
||||
...
|
||||
1. Let obj be ? OrdinaryCreateFromConstructor(constructor,
|
||||
"%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » )
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = function(){}.bind(null);
|
||||
Object.defineProperty(ctor[Symbol.species], "prototype", {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,49 +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-typedarray
|
||||
description: >
|
||||
Return abrupt from getting typedArray argument's buffer.constructor.@@species
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
5. Let S be ? Get(C, @@species).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.species, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
var ctor = {};
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
Object.defineProperty(ctor, Symbol.species, {
|
||||
get() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
|
@ -1,65 +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-typedarray
|
||||
description: >
|
||||
Return abrupt completion from typedArray argument's buffer.constructor's value
|
||||
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.
|
||||
|
||||
...
|
||||
17. If SameValue(elementType, srcType) is true, then
|
||||
a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset).
|
||||
...
|
||||
|
||||
24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] )
|
||||
|
||||
...
|
||||
2. If cloneConstructor is not present, then
|
||||
a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
...
|
||||
|
||||
7.3.20 SpeciesConstructor ( O, defaultConstructor )
|
||||
|
||||
...
|
||||
2. Let C be ? Get(O, "constructor").
|
||||
...
|
||||
4. If Type(C) is not Object, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol, TypedArray]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
|
||||
sample.buffer.constructor = 1;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = true;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = '';
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
sample.buffer.constructor = null;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
var s = Symbol('1');
|
||||
sample.buffer.constructor = s;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue