Bug 1903767 - Run browser_genai_init with experimental preferences enabled r=tarek
[gecko.git] / js / src / tests / test262 / built-ins / TypedArray / from / mapfn-is-not-callable.js
blob42fa25ef618ecf7b36987912e72b5064b7b27e1c
1 // |reftest| shell-option(--enable-float16array)
2 // Copyright (C) 2016 the V8 project authors. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-%typedarray%.from
6 description: Throw a TypeError exception is mapfn is not callable
7 info: |
8   22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] )
10   ...
11   3. If mapfn was supplied and mapfn is not undefined, then
12     a. If IsCallable(mapfn) is false, throw a TypeError exception.
13   ...
14 includes: [testTypedArray.js]
15 features: [Symbol, Symbol.iterator, TypedArray]
16 ---*/
18 var getIterator = 0;
19 var arrayLike = {};
20 Object.defineProperty(arrayLike, Symbol.iterator, {
21   get: function() {
22     getIterator++;
23   }
24 });
26 assert.throws(TypeError, function() {
27   TypedArray.from(arrayLike, null);
28 }, "mapfn is null");
30 assert.throws(TypeError, function() {
31   TypedArray.from(arrayLike, 42);
32 }, "mapfn is a number");
34 assert.throws(TypeError, function() {
35   TypedArray.from(arrayLike, "");
36 }, "mapfn is a string");
38 assert.throws(TypeError, function() {
39   TypedArray.from(arrayLike, {});
40 }, "mapfn is an ordinary object");
42 assert.throws(TypeError, function() {
43   TypedArray.from(arrayLike, []);
44 }, "mapfn is an array");
46 assert.throws(TypeError, function() {
47   TypedArray.from(arrayLike, true);
48 }, "mapfn is a boolean");
50 var s = Symbol("1");
51 assert.throws(TypeError, function() {
52   TypedArray.from(arrayLike, s);
53 }, "mapfn is a symbol");
55 assert.sameValue(
56   getIterator, 0,
57   "IsCallable(mapfn) check occurs before getting source[@@iterator]"
60 reportCompare(0, 0);