Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: test/mjsunit/es6/typedarray-set-length.js

Issue 1237583005: Only evaluate length once in %TypedArray%.prototype.set (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add more cases to the test Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/typedarray.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // 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
5 var typedArrayConstructors = [
6 Uint8Array,
7 Int8Array,
8 Uint16Array,
9 Int16Array,
10 Uint32Array,
11 Int32Array,
12 Uint8ClampedArray,
13 Float32Array,
14 Float64Array
15 ];
16
17 var lengthCalled = false;
18 function lengthValue() {
19 assertFalse(lengthCalled);
20 lengthCalled = true;
21 return 5;
22 }
23
24 // ToLength should convert these to usable lengths.
25 var 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.
37 function badNonIntegerLength() {
38 return Symbol("5");
39 }
40
41 for (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 }
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698