mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 12:34:41 +02:00
Reuse %TypedArray%.from and .of tests on each TypedArray constructor
This commit is contained in:
parent
048073a29a
commit
76080eac08
@ -11,16 +11,51 @@ info: >
|
||||
a. If IsCallable(mapfn) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol.iterator]
|
||||
features: [Symbol, Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var getIterator = 0;
|
||||
var arrayLike = {};
|
||||
Object.defineProperty(arrayLike, Symbol.iterator, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
getIterator++;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, null);
|
||||
}, "mapfn is null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, 42);
|
||||
});
|
||||
}, "mapfn is a number");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, "");
|
||||
}, "mapfn is a string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, {});
|
||||
}, "mapfn is an ordinary object");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, []);
|
||||
}, "mapfn is an array");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, true);
|
||||
}, "mapfn is a boolean");
|
||||
|
||||
var s = Symbol("1")
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, s);
|
||||
}, "mapfn is a symbol");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TypedArray.from(arrayLike, Int8Array);
|
||||
}, "mapfn is a TypedArray constructor (not callable)");
|
||||
|
||||
assert.sameValue(
|
||||
getIterator, 0,
|
||||
"IsCallable(mapfn) check occurs before getting source[@@iterator]"
|
||||
);
|
27
test/built-ins/TypedArrays/from/arylk-get-length-error.js
Normal file
27
test/built-ins/TypedArrays/from/arylk-get-length-error.js
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.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Returns error produced by accessing array-like's length
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
7. Let len be ? ToLength(? Get(arrayLike, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var arrayLike = {};
|
||||
|
||||
Object.defineProperty(arrayLike, "length", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(arrayLike);
|
||||
});
|
||||
});
|
27
test/built-ins/TypedArrays/from/arylk-to-length-error.js
Normal file
27
test/built-ins/TypedArrays/from/arylk-to-length-error.js
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.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Returns error produced by interpreting length property as a length
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
7. Let len be ? ToLength(? Get(arrayLike, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var arrayLike = { length: {} };
|
||||
|
||||
arrayLike.length = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(arrayLike);
|
||||
});
|
||||
});
|
@ -13,5 +13,12 @@ includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.sameValue(TA.from, TypedArray.from);
|
||||
assert.sameValue(
|
||||
TA.from, TypedArray.from,
|
||||
"method is inherited %TypedArray%.from"
|
||||
);
|
||||
assert.sameValue(
|
||||
TA.hasOwnProperty("from"), false,
|
||||
"constructor does not define an own property named 'from'"
|
||||
);
|
||||
});
|
||||
|
22
test/built-ins/TypedArrays/from/invoked-as-func.js
Normal file
22
test/built-ins/TypedArrays/from/invoked-as-func.js
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: >
|
||||
"from" cannot be invoked as a function
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
1. Let C be the this value.
|
||||
2. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var from = TA.from;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
from([]);
|
||||
});
|
||||
});
|
32
test/built-ins/TypedArrays/from/iter-access-error.js
Normal file
32
test/built-ins/TypedArrays/from/iter-access-error.js
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.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Returns error produced by accessing @@iterator
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
6. Let arrayLike be ? IterableToArrayLike(source).
|
||||
...
|
||||
|
||||
22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items )
|
||||
|
||||
1. Let usingIterator be ? GetMethod(items, @@iterator).
|
||||
...
|
||||
features: [Symbol.iterator]
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var iter = {};
|
||||
Object.defineProperty(iter, Symbol.iterator, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(iter);
|
||||
});
|
||||
});
|
32
test/built-ins/TypedArrays/from/iter-invoke-error.js
Normal file
32
test/built-ins/TypedArrays/from/iter-invoke-error.js
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.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Returns error produced by invoking @@iterator
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
6. Let arrayLike be ? IterableToArrayLike(source).
|
||||
...
|
||||
|
||||
22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items )
|
||||
|
||||
1. Let usingIterator be ? GetMethod(items, @@iterator).
|
||||
2. If usingIterator is not undefined, then
|
||||
a. Let iterator be ? GetIterator(items, usingIterator).
|
||||
...
|
||||
features: [Symbol.iterator]
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(iter);
|
||||
});
|
||||
});
|
31
test/built-ins/TypedArrays/from/iter-next-error.js
Normal file
31
test/built-ins/TypedArrays/from/iter-next-error.js
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Returns error produced by advancing the iterator
|
||||
info: >
|
||||
22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items )
|
||||
|
||||
2. If usingIterator is not undefined, then
|
||||
...
|
||||
d. Repeat, while next is not false
|
||||
i. Let next be ? IteratorStep(iterator).
|
||||
...
|
||||
features: [Symbol.iterator]
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(iter);
|
||||
});
|
||||
});
|
40
test/built-ins/TypedArrays/from/iter-next-value-error.js
Normal file
40
test/built-ins/TypedArrays/from/iter-next-value-error.js
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.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Returns error produced by accessing iterated value
|
||||
info: >
|
||||
22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items )
|
||||
|
||||
2. If usingIterator is not undefined, then
|
||||
...
|
||||
d. Repeat, while next is not false
|
||||
...
|
||||
ii. If next is not false, then
|
||||
1. Let nextValue be ? IteratorValue(next).
|
||||
...
|
||||
features: [Symbol.iterator]
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var iter = {};
|
||||
iter[Symbol.iterator] = function() {
|
||||
return {
|
||||
next: function() {
|
||||
var result = {};
|
||||
Object.defineProperty(result, 'value', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(Test262Error, function() {
|
||||
TA.from(iter);
|
||||
});
|
||||
});
|
63
test/built-ins/TypedArrays/from/mapfn-is-not-callable.js
Normal file
63
test/built-ins/TypedArrays/from/mapfn-is-not-callable.js
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: Throw a TypeError exception is mapfn is not callable
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
...
|
||||
3. If mapfn was supplied and mapfn is not undefined, then
|
||||
a. If IsCallable(mapfn) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol, Symbol.iterator]
|
||||
---*/
|
||||
|
||||
var getIterator = 0;
|
||||
var arrayLike = {};
|
||||
Object.defineProperty(arrayLike, Symbol.iterator, {
|
||||
get: function() {
|
||||
getIterator++;
|
||||
}
|
||||
});
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, null);
|
||||
}, "mapfn is null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, 42);
|
||||
}, "mapfn is a number");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, "");
|
||||
}, "mapfn is a string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, {});
|
||||
}, "mapfn is an ordinary object");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, []);
|
||||
}, "mapfn is an array");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, true);
|
||||
}, "mapfn is a boolean");
|
||||
|
||||
var s = Symbol("1")
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, s);
|
||||
}, "mapfn is a symbol");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from(arrayLike, TA);
|
||||
}, "mapfn is a TypedArray constructor (not callable)");
|
||||
|
||||
assert.sameValue(
|
||||
getIterator, 0,
|
||||
"IsCallable(mapfn) check occurs before getting source[@@iterator]"
|
||||
);
|
||||
});
|
22
test/built-ins/TypedArrays/from/this-is-not-constructor.js
Normal file
22
test/built-ins/TypedArrays/from/this-is-not-constructor.js
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
id: sec-%typedarray%.from
|
||||
description: >
|
||||
Throws a TypeError exception if this is not a constructor
|
||||
info: >
|
||||
22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
|
||||
|
||||
1. Let C be the this value.
|
||||
2. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var m = { m() {} }.m;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(TypeError, function() {
|
||||
TA.from.call(m, []);
|
||||
});
|
||||
});
|
@ -13,5 +13,12 @@ includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.sameValue(TA.of, TypedArray.of);
|
||||
});
|
||||
assert.sameValue(
|
||||
TA.of, TypedArray.of,
|
||||
"method is inherited %TypedArray%.of"
|
||||
);
|
||||
assert.sameValue(
|
||||
TA.hasOwnProperty("of"), false,
|
||||
"constructor does not define an own property named 'of'"
|
||||
);
|
||||
});
|
23
test/built-ins/TypedArrays/of/invoked-as-func.js
Normal file
23
test/built-ins/TypedArrays/of/invoked-as-func.js
Normal file
@ -0,0 +1,23 @@
|
||||
// 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
|
||||
description: >
|
||||
"of" cannot be invoked as a function
|
||||
info: >
|
||||
22.2.2.2 %TypedArray%.of ( ...items )
|
||||
|
||||
...
|
||||
3. Let C be the this value.
|
||||
4. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var of = TA.of;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
of();
|
||||
});
|
||||
});
|
23
test/built-ins/TypedArrays/of/this-is-not-constructor.js
Normal file
23
test/built-ins/TypedArrays/of/this-is-not-constructor.js
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
id: sec-%typedarray%.of
|
||||
description: >
|
||||
Throws a TypeError exception if this is not a constructor
|
||||
info: >
|
||||
22.2.2.2 %TypedArray%.of ( ...items )
|
||||
|
||||
...
|
||||
3. Let C be the this value.
|
||||
4. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var m = { m() {} }.m;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
assert.throws(TypeError, function() {
|
||||
TA.of.call(m, []);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user