mirror of https://github.com/tc39/test262.git
Add tests for custom ctor returns on TypedArrays from and of
This commit is contained in:
parent
6fcbfaf0f0
commit
021d44822c
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
es6id: 22.2.2.1
|
||||||
|
esid: sec-%typedarray%.from
|
||||||
|
description: >
|
||||||
|
Custom constructor can return any TypedArray instance with higher or same
|
||||||
|
length
|
||||||
|
info: |
|
||||||
|
%TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. If usingIterator is not undefined, then
|
||||||
|
a. Let values be ? IterableToList(source, usingIterator).
|
||||||
|
b. Let len be the number of elements in values.
|
||||||
|
c. Let targetObj be ? TypedArrayCreate(C, «len»).
|
||||||
|
...
|
||||||
|
10. Let len be ? ToLength(? Get(arrayLike, "length")).
|
||||||
|
11. Let targetObj be ? TypedArrayCreate(C, « len »).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var sourceItor = [1, 2];
|
||||||
|
var sourceObj = {
|
||||||
|
length: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var result;
|
||||||
|
var custom = new TA(2);
|
||||||
|
var ctor = function() {
|
||||||
|
return custom;
|
||||||
|
};
|
||||||
|
|
||||||
|
result = TypedArray.from.call(ctor, sourceItor);
|
||||||
|
assert.sameValue(result, custom, "using iterator, same length");
|
||||||
|
|
||||||
|
result = TypedArray.from.call(ctor, sourceObj);
|
||||||
|
assert.sameValue(result, custom, "not using iterator, same length");
|
||||||
|
|
||||||
|
custom = new TA(3);
|
||||||
|
|
||||||
|
result = TypedArray.from.call(ctor, sourceItor);
|
||||||
|
assert.sameValue(result, custom, "using iterator, higher length");
|
||||||
|
|
||||||
|
result = TypedArray.from.call(ctor, sourceObj);
|
||||||
|
assert.sameValue(result, custom, "not using iterator, higher length");
|
||||||
|
});
|
|
@ -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.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
es6id: 22.2.2.1
|
||||||
|
esid: sec-%typedarray%.from
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if a custom `this` returns a smaller instance
|
||||||
|
info: |
|
||||||
|
%TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. If usingIterator is not undefined, then
|
||||||
|
a. Let values be ? IterableToList(source, usingIterator).
|
||||||
|
b. Let len be the number of elements in values.
|
||||||
|
c. Let targetObj be ? TypedArrayCreate(C, «len»).
|
||||||
|
...
|
||||||
|
10. Let len be ? ToLength(? Get(arrayLike, "length")).
|
||||||
|
11. Let targetObj be ? TypedArrayCreate(C, « len »).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var sourceItor = [1, 2];
|
||||||
|
var sourceObj = {
|
||||||
|
length: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var ctor = function() {
|
||||||
|
return new TA(1);
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
TA.from.call(ctor, sourceItor);
|
||||||
|
}, "source is using iterator");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
TA.from.call(ctor, sourceObj);
|
||||||
|
}, "source is not using iterator");
|
||||||
|
});
|
|
@ -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.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
es6id: 22.2.2.2
|
||||||
|
esid: sec-%typedarray%.of
|
||||||
|
description: >
|
||||||
|
Custom constructor can return any TypedArray instance with higher or same
|
||||||
|
length
|
||||||
|
info: |
|
||||||
|
%TypedArray%.of ( ...items )
|
||||||
|
|
||||||
|
1. Let len be the actual number of arguments passed to this function.
|
||||||
|
...
|
||||||
|
5. Let newObj be ? TypedArrayCreate(C, « len »).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var result;
|
||||||
|
var custom = new TA(3);
|
||||||
|
var ctor = function() {
|
||||||
|
return custom;
|
||||||
|
};
|
||||||
|
|
||||||
|
result = TypedArray.of.call(ctor, 1, 2, 3);
|
||||||
|
assert.sameValue(result, custom, "using iterator, same length");
|
||||||
|
|
||||||
|
result = TypedArray.of.call(ctor, 1, 2);
|
||||||
|
assert.sameValue(result, custom, "using iterator, higher length");
|
||||||
|
});
|
|
@ -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.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
es6id: 22.2.2.2
|
||||||
|
esid: sec-%typedarray%.of
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if a custom `this` returns a smaller instance
|
||||||
|
info: |
|
||||||
|
%TypedArray%.of ( ...items )
|
||||||
|
|
||||||
|
1. Let len be the actual number of arguments passed to this function.
|
||||||
|
...
|
||||||
|
5. Let newObj be ? TypedArrayCreate(C, « len »).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var ctor = function() {
|
||||||
|
return new TA(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
TypedArray.of.call(ctor, 1, 2);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue