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

Side by Side Diff: test/mjsunit/compiler/function-apply.js

Issue 2950773002: [turbofan] Introduce new JSCallWithArrayLike operator. (Closed)
Patch Set: REBASE Created 3 years, 6 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/compiler/verifier.cc ('k') | test/mjsunit/compiler/reflect-apply.js » ('j') | 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 2017 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 // Flags: --allow-natives-syntax
6
7 // Test Function.prototype.apply with null/undefined argumentsList
8 (function() {
9 "use strict";
10 function bar() { return this; }
11 function foo() { return bar.apply(this, null); }
12
13 assertEquals(42, foo.call(42));
14 assertEquals(42, foo.call(42));
15 %OptimizeFunctionOnNextCall(foo);
16 assertEquals(42, foo.call(42));
17 })();
18 (function() {
19 "use strict";
20 function bar() { return this; }
21 function foo() { return bar.apply(this, undefined); }
22
23 assertEquals(42, foo.call(42));
24 assertEquals(42, foo.call(42));
25 %OptimizeFunctionOnNextCall(foo);
26 assertEquals(42, foo.call(42));
27 })();
28
29 // Test Function.prototype.apply within try/catch.
30 (function() {
31 "use strict";
32 function foo(bar) {
33 try {
34 return Function.prototype.apply.call(bar, bar, arguments);
35 } catch (e) {
36 return 1;
37 }
38 }
39
40 assertEquals(1, foo());
41 assertEquals(1, foo());
42 %OptimizeFunctionOnNextCall(foo);
43 assertEquals(1, foo());
44 })();
45 (function() {
46 "use strict";
47 function foo(bar) {
48 try {
49 return Function.prototype.apply.call(bar, bar, bar);
50 } catch (e) {
51 return 1;
52 }
53 }
54
55 assertEquals(1, foo());
56 assertEquals(1, foo());
57 %OptimizeFunctionOnNextCall(foo);
58 assertEquals(1, foo());
59 })();
60
61 // Test Function.prototype.apply with wrong number of arguments.
62 (function() {
63 "use strict";
64 function bar() { return this; }
65 function foo() { return bar.apply(); }
66
67 assertEquals(undefined, foo());
68 assertEquals(undefined, foo());
69 %OptimizeFunctionOnNextCall(foo);
70 assertEquals(undefined, foo());
71 })();
72 (function() {
73 "use strict";
74 function bar() { return this; }
75 function foo() { return bar.apply(this); }
76
77 assertEquals(42, foo.call(42));
78 assertEquals(42, foo.call(42));
79 %OptimizeFunctionOnNextCall(foo);
80 assertEquals(42, foo.call(42));
81 })();
82 (function() {
83 "use strict";
84 function bar() { return this; }
85 function foo() { return bar.apply(this, arguments, this); }
86
87 assertEquals(42, foo.call(42));
88 assertEquals(42, foo.call(42));
89 %OptimizeFunctionOnNextCall(foo);
90 assertEquals(42, foo.call(42));
91 })();
92
93 // Test proper order of callable check and array-like iteration
94 // in Function.prototype.apply.
95 (function() {
96 var dummy_length_counter = 0;
97 var dummy = { get length() { ++dummy_length_counter; return 0; } };
98
99 function foo() {
100 return Function.prototype.apply.call(undefined, this, dummy);
101 }
102
103 assertThrows(foo, TypeError);
104 assertThrows(foo, TypeError);
105 %OptimizeFunctionOnNextCall(foo);
106 assertThrows(foo, TypeError);
107 assertEquals(0, dummy_length_counter);
108 })();
109 (function() {
110 var dummy_length_counter = 0;
111 var dummy = { get length() { ++dummy_length_counter; return 0; } };
112
113 function foo() {
114 return Function.prototype.apply.call(null, this, dummy);
115 }
116
117 assertThrows(foo, TypeError);
118 assertThrows(foo, TypeError);
119 %OptimizeFunctionOnNextCall(foo);
120 assertThrows(foo, TypeError);
121 assertEquals(0, dummy_length_counter);
122 })();
123 (function() {
124 var dummy_length_counter = 0;
125 var dummy = { get length() { ++dummy_length_counter; return 0; } };
126
127 function foo() {
128 return Function.prototype.apply.call(null, this, dummy);
129 }
130
131 assertThrows(foo, TypeError);
132 assertThrows(foo, TypeError);
133 %OptimizeFunctionOnNextCall(foo);
134 assertThrows(foo, TypeError);
135 assertEquals(0, dummy_length_counter);
136 })();
OLDNEW
« no previous file with comments | « src/compiler/verifier.cc ('k') | test/mjsunit/compiler/reflect-apply.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698