blob: 6dd5bf76e0a91397bd2f1c0e7b5e5cf49e16cbdc [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5var typedArrayConstructors = [
6 Uint8Array,
7 Int8Array,
8 Uint16Array,
9 Int16Array,
10 Uint32Array,
11 Int32Array,
12 Uint8ClampedArray,
13 Float32Array,
14 Float64Array
15];
16
17var lengthCalled = false;
18function lengthValue() {
19 assertFalse(lengthCalled);
20 lengthCalled = true;
21 return 5;
22}
23
24// ToLength should convert these to usable lengths.
25var goodNonIntegerLengths = [
26 function() { return 4.6; },
27 function() { return -5; },
28 function() { return NaN; },
29 function() { return "5"; },
30 function() { return "abc"; },
31 function() { return true; },
32 function() { return null; },
33 function() { return undefined; }
34];
35
36// This will fail if you use ToLength on it.
37function badNonIntegerLength() {
38 return Symbol("5");
39}
40
41for (var constructor of typedArrayConstructors) {
42 lengthCalled = false;
43 var a = new constructor(10);
44 a.set({length: {valueOf: lengthValue}});
45 assertTrue(lengthCalled);
46
47 for (var lengthFun of goodNonIntegerLengths) {
48 a.set({length: {valueOf: lengthFun}});
49 }
50
51 assertThrows(function() {
52 a.set({length: {valueOf: badNonIntegerLength}});
53 }, TypeError);
54}