Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArray / from / mapfn-is-not-callable.js
blobece0766bee0b04b239b8bd2132446c30f44b50c2
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-%typedarray%.from
5 description: Throw a TypeError exception is mapfn is not callable
6 info: |
7   22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
9   ...
10   3. If mapfn was supplied and mapfn is not undefined, then
11     a. If IsCallable(mapfn) is false, throw a TypeError exception.
12   ...
13 includes: [testTypedArray.js]
14 features: [Symbol, Symbol.iterator, TypedArray]
15 ---*/
17 var getIterator = 0;
18 var arrayLike = {};
19 Object.defineProperty(arrayLike, Symbol.iterator, {
20   get: function() {
21     getIterator++;
22   }
23 });
25 assert.throws(TypeError, function() {
26   TypedArray.from(arrayLike, null);
27 }, "mapfn is null");
29 assert.throws(TypeError, function() {
30   TypedArray.from(arrayLike, 42);
31 }, "mapfn is a number");
33 assert.throws(TypeError, function() {
34   TypedArray.from(arrayLike, "");
35 }, "mapfn is a string");
37 assert.throws(TypeError, function() {
38   TypedArray.from(arrayLike, {});
39 }, "mapfn is an ordinary object");
41 assert.throws(TypeError, function() {
42   TypedArray.from(arrayLike, []);
43 }, "mapfn is an array");
45 assert.throws(TypeError, function() {
46   TypedArray.from(arrayLike, true);
47 }, "mapfn is a boolean");
49 var s = Symbol("1");
50 assert.throws(TypeError, function() {
51   TypedArray.from(arrayLike, s);
52 }, "mapfn is a symbol");
54 assert.sameValue(
55   getIterator, 0,
56   "IsCallable(mapfn) check occurs before getting source[@@iterator]"
59 reportCompare(0, 0);