OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/bytecode-array-iterator.h" | 10 #include "src/interpreter/bytecode-array-iterator.h" |
11 #include "src/interpreter/bytecode-label.h" | 11 #include "src/interpreter/bytecode-label.h" |
12 #include "src/interpreter/interpreter.h" | 12 #include "src/interpreter/interpreter.h" |
13 #include "test/cctest/cctest.h" | 13 #include "test/cctest/cctest.h" |
14 #include "test/cctest/interpreter/interpreter-tester.h" | 14 #include "test/cctest/interpreter/interpreter-tester.h" |
15 #include "test/cctest/test-feedback-vector.h" | 15 #include "test/cctest/test-feedback-vector.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 namespace interpreter { | 19 namespace interpreter { |
20 | 20 |
21 | 21 |
22 TEST(InterpreterReturn) { | 22 TEST(InterpreterReturn) { |
23 HandleAndZoneScope handles; | 23 HandleAndZoneScope handles; |
24 Handle<Object> undefined_value = | 24 Isolate* isolate = handles.main_isolate(); |
25 handles.main_isolate()->factory()->undefined_value(); | 25 Handle<Object> undefined_value = isolate->factory()->undefined_value(); |
26 | 26 |
27 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 27 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
28 0, 0); | |
29 builder.Return(); | 28 builder.Return(); |
30 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 29 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
31 | 30 |
32 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 31 InterpreterTester tester(isolate, bytecode_array); |
33 auto callable = tester.GetCallable<>(); | 32 auto callable = tester.GetCallable<>(); |
34 Handle<Object> return_val = callable().ToHandleChecked(); | 33 Handle<Object> return_val = callable().ToHandleChecked(); |
35 CHECK(return_val.is_identical_to(undefined_value)); | 34 CHECK(return_val.is_identical_to(undefined_value)); |
36 } | 35 } |
37 | 36 |
38 | 37 |
39 TEST(InterpreterLoadUndefined) { | 38 TEST(InterpreterLoadUndefined) { |
40 HandleAndZoneScope handles; | 39 HandleAndZoneScope handles; |
41 Handle<Object> undefined_value = | 40 Isolate* isolate = handles.main_isolate(); |
42 handles.main_isolate()->factory()->undefined_value(); | 41 Handle<Object> undefined_value = isolate->factory()->undefined_value(); |
43 | 42 |
44 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 43 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
45 0, 0); | |
46 builder.LoadUndefined().Return(); | 44 builder.LoadUndefined().Return(); |
47 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 45 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
48 | 46 |
49 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 47 InterpreterTester tester(isolate, bytecode_array); |
50 auto callable = tester.GetCallable<>(); | 48 auto callable = tester.GetCallable<>(); |
51 Handle<Object> return_val = callable().ToHandleChecked(); | 49 Handle<Object> return_val = callable().ToHandleChecked(); |
52 CHECK(return_val.is_identical_to(undefined_value)); | 50 CHECK(return_val.is_identical_to(undefined_value)); |
53 } | 51 } |
54 | 52 |
55 | 53 |
56 TEST(InterpreterLoadNull) { | 54 TEST(InterpreterLoadNull) { |
57 HandleAndZoneScope handles; | 55 HandleAndZoneScope handles; |
58 Handle<Object> null_value = handles.main_isolate()->factory()->null_value(); | 56 Isolate* isolate = handles.main_isolate(); |
| 57 Handle<Object> null_value = isolate->factory()->null_value(); |
59 | 58 |
60 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 59 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
61 0, 0); | |
62 builder.LoadNull().Return(); | 60 builder.LoadNull().Return(); |
63 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 61 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
64 | 62 |
65 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 63 InterpreterTester tester(isolate, bytecode_array); |
66 auto callable = tester.GetCallable<>(); | 64 auto callable = tester.GetCallable<>(); |
67 Handle<Object> return_val = callable().ToHandleChecked(); | 65 Handle<Object> return_val = callable().ToHandleChecked(); |
68 CHECK(return_val.is_identical_to(null_value)); | 66 CHECK(return_val.is_identical_to(null_value)); |
69 } | 67 } |
70 | 68 |
71 | 69 |
72 TEST(InterpreterLoadTheHole) { | 70 TEST(InterpreterLoadTheHole) { |
73 HandleAndZoneScope handles; | 71 HandleAndZoneScope handles; |
74 Handle<Object> the_hole_value = | 72 Isolate* isolate = handles.main_isolate(); |
75 handles.main_isolate()->factory()->the_hole_value(); | 73 Handle<Object> the_hole_value = isolate->factory()->the_hole_value(); |
76 | 74 |
77 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 75 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
78 0, 0); | |
79 builder.LoadTheHole().Return(); | 76 builder.LoadTheHole().Return(); |
80 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 77 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
81 | 78 |
82 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 79 InterpreterTester tester(isolate, bytecode_array); |
83 auto callable = tester.GetCallable<>(); | 80 auto callable = tester.GetCallable<>(); |
84 Handle<Object> return_val = callable().ToHandleChecked(); | 81 Handle<Object> return_val = callable().ToHandleChecked(); |
85 CHECK(return_val.is_identical_to(the_hole_value)); | 82 CHECK(return_val.is_identical_to(the_hole_value)); |
86 } | 83 } |
87 | 84 |
88 | 85 |
89 TEST(InterpreterLoadTrue) { | 86 TEST(InterpreterLoadTrue) { |
90 HandleAndZoneScope handles; | 87 HandleAndZoneScope handles; |
91 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 88 Isolate* isolate = handles.main_isolate(); |
| 89 Handle<Object> true_value = isolate->factory()->true_value(); |
92 | 90 |
93 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 91 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
94 0, 0); | |
95 builder.LoadTrue().Return(); | 92 builder.LoadTrue().Return(); |
96 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 93 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
97 | 94 |
98 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 95 InterpreterTester tester(isolate, bytecode_array); |
99 auto callable = tester.GetCallable<>(); | 96 auto callable = tester.GetCallable<>(); |
100 Handle<Object> return_val = callable().ToHandleChecked(); | 97 Handle<Object> return_val = callable().ToHandleChecked(); |
101 CHECK(return_val.is_identical_to(true_value)); | 98 CHECK(return_val.is_identical_to(true_value)); |
102 } | 99 } |
103 | 100 |
104 | 101 |
105 TEST(InterpreterLoadFalse) { | 102 TEST(InterpreterLoadFalse) { |
106 HandleAndZoneScope handles; | 103 HandleAndZoneScope handles; |
107 Handle<Object> false_value = handles.main_isolate()->factory()->false_value(); | 104 Isolate* isolate = handles.main_isolate(); |
| 105 Handle<Object> false_value = isolate->factory()->false_value(); |
108 | 106 |
109 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 107 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
110 0, 0); | |
111 builder.LoadFalse().Return(); | 108 builder.LoadFalse().Return(); |
112 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 109 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
113 | 110 |
114 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 111 InterpreterTester tester(isolate, bytecode_array); |
115 auto callable = tester.GetCallable<>(); | 112 auto callable = tester.GetCallable<>(); |
116 Handle<Object> return_val = callable().ToHandleChecked(); | 113 Handle<Object> return_val = callable().ToHandleChecked(); |
117 CHECK(return_val.is_identical_to(false_value)); | 114 CHECK(return_val.is_identical_to(false_value)); |
118 } | 115 } |
119 | 116 |
120 | 117 |
121 TEST(InterpreterLoadLiteral) { | 118 TEST(InterpreterLoadLiteral) { |
122 HandleAndZoneScope handles; | 119 HandleAndZoneScope handles; |
123 i::Factory* factory = handles.main_isolate()->factory(); | 120 Isolate* isolate = handles.main_isolate(); |
| 121 Factory* factory = isolate->factory(); |
124 | 122 |
125 // Small Smis. | 123 // Small Smis. |
126 for (int i = -128; i < 128; i++) { | 124 for (int i = -128; i < 128; i++) { |
127 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 125 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
128 0, 0); | |
129 builder.LoadLiteral(Smi::FromInt(i)).Return(); | 126 builder.LoadLiteral(Smi::FromInt(i)).Return(); |
130 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 127 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
131 | 128 |
132 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 129 InterpreterTester tester(isolate, bytecode_array); |
133 auto callable = tester.GetCallable<>(); | 130 auto callable = tester.GetCallable<>(); |
134 Handle<Object> return_val = callable().ToHandleChecked(); | 131 Handle<Object> return_val = callable().ToHandleChecked(); |
135 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(i)); | 132 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(i)); |
136 } | 133 } |
137 | 134 |
138 // Large Smis. | 135 // Large Smis. |
139 { | 136 { |
140 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 137 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
141 0, 0); | |
142 | 138 |
143 builder.LoadLiteral(Smi::FromInt(0x12345678)).Return(); | 139 builder.LoadLiteral(Smi::FromInt(0x12345678)).Return(); |
144 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 140 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
145 | 141 |
146 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 142 InterpreterTester tester(isolate, bytecode_array); |
147 auto callable = tester.GetCallable<>(); | 143 auto callable = tester.GetCallable<>(); |
148 Handle<Object> return_val = callable().ToHandleChecked(); | 144 Handle<Object> return_val = callable().ToHandleChecked(); |
149 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x12345678)); | 145 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x12345678)); |
150 } | 146 } |
151 | 147 |
152 // Heap numbers. | 148 // Heap numbers. |
153 { | 149 { |
154 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 150 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
155 0, 0); | |
156 | 151 |
157 builder.LoadLiteral(factory->NewHeapNumber(-2.1e19)).Return(); | 152 builder.LoadLiteral(factory->NewHeapNumber(-2.1e19)).Return(); |
158 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 153 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
159 | 154 |
160 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 155 InterpreterTester tester(isolate, bytecode_array); |
161 auto callable = tester.GetCallable<>(); | 156 auto callable = tester.GetCallable<>(); |
162 Handle<Object> return_val = callable().ToHandleChecked(); | 157 Handle<Object> return_val = callable().ToHandleChecked(); |
163 CHECK_EQ(i::HeapNumber::cast(*return_val)->value(), -2.1e19); | 158 CHECK_EQ(i::HeapNumber::cast(*return_val)->value(), -2.1e19); |
164 } | 159 } |
165 | 160 |
166 // Strings. | 161 // Strings. |
167 { | 162 { |
168 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 163 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
169 0, 0); | |
170 | 164 |
171 Handle<i::String> string = factory->NewStringFromAsciiChecked("String"); | 165 Handle<i::String> string = factory->NewStringFromAsciiChecked("String"); |
172 builder.LoadLiteral(string).Return(); | 166 builder.LoadLiteral(string).Return(); |
173 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 167 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
174 | 168 |
175 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 169 InterpreterTester tester(isolate, bytecode_array); |
176 auto callable = tester.GetCallable<>(); | 170 auto callable = tester.GetCallable<>(); |
177 Handle<Object> return_val = callable().ToHandleChecked(); | 171 Handle<Object> return_val = callable().ToHandleChecked(); |
178 CHECK(i::String::cast(*return_val)->Equals(*string)); | 172 CHECK(i::String::cast(*return_val)->Equals(*string)); |
179 } | 173 } |
180 } | 174 } |
181 | 175 |
182 | 176 |
183 TEST(InterpreterLoadStoreRegisters) { | 177 TEST(InterpreterLoadStoreRegisters) { |
184 HandleAndZoneScope handles; | 178 HandleAndZoneScope handles; |
185 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 179 Isolate* isolate = handles.main_isolate(); |
| 180 Handle<Object> true_value = isolate->factory()->true_value(); |
186 for (int i = 0; i <= kMaxInt8; i++) { | 181 for (int i = 0; i <= kMaxInt8; i++) { |
187 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 182 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, i + 1); |
188 0, i + 1); | |
189 | 183 |
190 Register reg(i); | 184 Register reg(i); |
191 builder.LoadTrue() | 185 builder.LoadTrue() |
192 .StoreAccumulatorInRegister(reg) | 186 .StoreAccumulatorInRegister(reg) |
193 .LoadFalse() | 187 .LoadFalse() |
194 .LoadAccumulatorWithRegister(reg) | 188 .LoadAccumulatorWithRegister(reg) |
195 .Return(); | 189 .Return(); |
196 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 190 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
197 | 191 |
198 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 192 InterpreterTester tester(isolate, bytecode_array); |
199 auto callable = tester.GetCallable<>(); | 193 auto callable = tester.GetCallable<>(); |
200 Handle<Object> return_val = callable().ToHandleChecked(); | 194 Handle<Object> return_val = callable().ToHandleChecked(); |
201 CHECK(return_val.is_identical_to(true_value)); | 195 CHECK(return_val.is_identical_to(true_value)); |
202 } | 196 } |
203 } | 197 } |
204 | 198 |
205 | 199 |
206 static const Token::Value kShiftOperators[] = { | 200 static const Token::Value kShiftOperators[] = { |
207 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR}; | 201 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR}; |
208 | 202 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 254 } |
261 | 255 |
262 | 256 |
263 TEST(InterpreterShiftOpsSmi) { | 257 TEST(InterpreterShiftOpsSmi) { |
264 int lhs_inputs[] = {0, -17, -182, 1073741823, -1}; | 258 int lhs_inputs[] = {0, -17, -182, 1073741823, -1}; |
265 int rhs_inputs[] = {5, 2, 1, -1, -2, 0, 31, 32, -32, 64, 37}; | 259 int rhs_inputs[] = {5, 2, 1, -1, -2, 0, 31, 32, -32, 64, 37}; |
266 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { | 260 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
267 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { | 261 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
268 for (size_t o = 0; o < arraysize(kShiftOperators); o++) { | 262 for (size_t o = 0; o < arraysize(kShiftOperators); o++) { |
269 HandleAndZoneScope handles; | 263 HandleAndZoneScope handles; |
270 i::Isolate* isolate = handles.main_isolate(); | 264 Isolate* isolate = handles.main_isolate(); |
271 i::Factory* factory = isolate->factory(); | 265 Factory* factory = isolate->factory(); |
272 i::Zone zone(isolate->allocator()); | 266 Zone zone(isolate->allocator()); |
273 BytecodeArrayBuilder builder(handles.main_isolate(), | 267 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
274 handles.main_zone(), 1, 0, 1); | |
275 | 268 |
276 i::FeedbackVectorSpec feedback_spec(&zone); | 269 FeedbackVectorSpec feedback_spec(&zone); |
277 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 270 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
278 Handle<i::TypeFeedbackVector> vector = | 271 Handle<i::TypeFeedbackVector> vector = |
279 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 272 NewTypeFeedbackVector(isolate, &feedback_spec); |
280 | 273 |
281 Register reg(0); | 274 Register reg(0); |
282 int lhs = lhs_inputs[l]; | 275 int lhs = lhs_inputs[l]; |
283 int rhs = rhs_inputs[r]; | 276 int rhs = rhs_inputs[r]; |
284 builder.LoadLiteral(Smi::FromInt(lhs)) | 277 builder.LoadLiteral(Smi::FromInt(lhs)) |
285 .StoreAccumulatorInRegister(reg) | 278 .StoreAccumulatorInRegister(reg) |
286 .LoadLiteral(Smi::FromInt(rhs)) | 279 .LoadLiteral(Smi::FromInt(rhs)) |
287 .BinaryOperation(kShiftOperators[o], reg, vector->GetIndex(slot)) | 280 .BinaryOperation(kShiftOperators[o], reg, vector->GetIndex(slot)) |
288 .Return(); | 281 .Return(); |
289 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 282 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
290 | 283 |
291 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 284 InterpreterTester tester(isolate, bytecode_array); |
292 auto callable = tester.GetCallable<>(); | 285 auto callable = tester.GetCallable<>(); |
293 Handle<Object> return_value = callable().ToHandleChecked(); | 286 Handle<Object> return_value = callable().ToHandleChecked(); |
294 Handle<Object> expected_value = | 287 Handle<Object> expected_value = |
295 factory->NewNumber(BinaryOpC(kShiftOperators[o], lhs, rhs)); | 288 factory->NewNumber(BinaryOpC(kShiftOperators[o], lhs, rhs)); |
296 CHECK(return_value->SameValue(*expected_value)); | 289 CHECK(return_value->SameValue(*expected_value)); |
297 } | 290 } |
298 } | 291 } |
299 } | 292 } |
300 } | 293 } |
301 | 294 |
302 | 295 |
303 TEST(InterpreterBinaryOpsSmi) { | 296 TEST(InterpreterBinaryOpsSmi) { |
304 int lhs_inputs[] = {3266, 1024, 0, -17, -18000}; | 297 int lhs_inputs[] = {3266, 1024, 0, -17, -18000}; |
305 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2}; | 298 int rhs_inputs[] = {3266, 5, 4, 3, 2, 1, -1, -2}; |
306 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { | 299 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
307 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { | 300 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
308 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { | 301 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { |
309 HandleAndZoneScope handles; | 302 HandleAndZoneScope handles; |
310 i::Isolate* isolate = handles.main_isolate(); | 303 Isolate* isolate = handles.main_isolate(); |
311 i::Factory* factory = isolate->factory(); | 304 Factory* factory = isolate->factory(); |
312 i::Zone zone(isolate->allocator()); | 305 Zone zone(isolate->allocator()); |
313 BytecodeArrayBuilder builder(handles.main_isolate(), | 306 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
314 handles.main_zone(), 1, 0, 1); | |
315 | 307 |
316 i::FeedbackVectorSpec feedback_spec(&zone); | 308 FeedbackVectorSpec feedback_spec(&zone); |
317 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 309 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
318 Handle<i::TypeFeedbackVector> vector = | 310 Handle<i::TypeFeedbackVector> vector = |
319 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 311 NewTypeFeedbackVector(isolate, &feedback_spec); |
320 | 312 |
321 Register reg(0); | 313 Register reg(0); |
322 int lhs = lhs_inputs[l]; | 314 int lhs = lhs_inputs[l]; |
323 int rhs = rhs_inputs[r]; | 315 int rhs = rhs_inputs[r]; |
324 builder.LoadLiteral(Smi::FromInt(lhs)) | 316 builder.LoadLiteral(Smi::FromInt(lhs)) |
325 .StoreAccumulatorInRegister(reg) | 317 .StoreAccumulatorInRegister(reg) |
326 .LoadLiteral(Smi::FromInt(rhs)) | 318 .LoadLiteral(Smi::FromInt(rhs)) |
327 .BinaryOperation(kArithmeticOperators[o], reg, | 319 .BinaryOperation(kArithmeticOperators[o], reg, |
328 vector->GetIndex(slot)) | 320 vector->GetIndex(slot)) |
329 .Return(); | 321 .Return(); |
330 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 322 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
331 | 323 |
332 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 324 InterpreterTester tester(isolate, bytecode_array); |
333 auto callable = tester.GetCallable<>(); | 325 auto callable = tester.GetCallable<>(); |
334 Handle<Object> return_value = callable().ToHandleChecked(); | 326 Handle<Object> return_value = callable().ToHandleChecked(); |
335 Handle<Object> expected_value = | 327 Handle<Object> expected_value = |
336 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); | 328 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); |
337 CHECK(return_value->SameValue(*expected_value)); | 329 CHECK(return_value->SameValue(*expected_value)); |
338 } | 330 } |
339 } | 331 } |
340 } | 332 } |
341 } | 333 } |
342 | 334 |
343 | 335 |
344 TEST(InterpreterBinaryOpsHeapNumber) { | 336 TEST(InterpreterBinaryOpsHeapNumber) { |
345 double lhs_inputs[] = {3266.101, 1024.12, 0.01, -17.99, -18000.833, 9.1e17}; | 337 double lhs_inputs[] = {3266.101, 1024.12, 0.01, -17.99, -18000.833, 9.1e17}; |
346 double rhs_inputs[] = {3266.101, 5.999, 4.778, 3.331, 2.643, | 338 double rhs_inputs[] = {3266.101, 5.999, 4.778, 3.331, 2.643, |
347 1.1, -1.8, -2.9, 8.3e-27}; | 339 1.1, -1.8, -2.9, 8.3e-27}; |
348 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { | 340 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
349 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { | 341 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
350 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { | 342 for (size_t o = 0; o < arraysize(kArithmeticOperators); o++) { |
351 HandleAndZoneScope handles; | 343 HandleAndZoneScope handles; |
352 i::Isolate* isolate = handles.main_isolate(); | 344 Isolate* isolate = handles.main_isolate(); |
353 i::Factory* factory = isolate->factory(); | 345 Factory* factory = isolate->factory(); |
354 i::Zone zone(isolate->allocator()); | 346 Zone zone(isolate->allocator()); |
355 BytecodeArrayBuilder builder(handles.main_isolate(), | 347 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
356 handles.main_zone(), 1, 0, 1); | |
357 | 348 |
358 i::FeedbackVectorSpec feedback_spec(&zone); | 349 FeedbackVectorSpec feedback_spec(&zone); |
359 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 350 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
360 Handle<i::TypeFeedbackVector> vector = | 351 Handle<i::TypeFeedbackVector> vector = |
361 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 352 NewTypeFeedbackVector(isolate, &feedback_spec); |
362 | 353 |
363 Register reg(0); | 354 Register reg(0); |
364 double lhs = lhs_inputs[l]; | 355 double lhs = lhs_inputs[l]; |
365 double rhs = rhs_inputs[r]; | 356 double rhs = rhs_inputs[r]; |
366 builder.LoadLiteral(factory->NewNumber(lhs)) | 357 builder.LoadLiteral(factory->NewNumber(lhs)) |
367 .StoreAccumulatorInRegister(reg) | 358 .StoreAccumulatorInRegister(reg) |
368 .LoadLiteral(factory->NewNumber(rhs)) | 359 .LoadLiteral(factory->NewNumber(rhs)) |
369 .BinaryOperation(kArithmeticOperators[o], reg, | 360 .BinaryOperation(kArithmeticOperators[o], reg, |
370 vector->GetIndex(slot)) | 361 vector->GetIndex(slot)) |
371 .Return(); | 362 .Return(); |
372 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 363 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
373 | 364 |
374 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 365 InterpreterTester tester(isolate, bytecode_array); |
375 auto callable = tester.GetCallable<>(); | 366 auto callable = tester.GetCallable<>(); |
376 Handle<Object> return_value = callable().ToHandleChecked(); | 367 Handle<Object> return_value = callable().ToHandleChecked(); |
377 Handle<Object> expected_value = | 368 Handle<Object> expected_value = |
378 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); | 369 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); |
379 CHECK(return_value->SameValue(*expected_value)); | 370 CHECK(return_value->SameValue(*expected_value)); |
380 } | 371 } |
381 } | 372 } |
382 } | 373 } |
383 } | 374 } |
384 | 375 |
385 | 376 |
386 TEST(InterpreterStringAdd) { | 377 TEST(InterpreterStringAdd) { |
387 HandleAndZoneScope handles; | 378 HandleAndZoneScope handles; |
388 i::Isolate* isolate = handles.main_isolate(); | 379 Isolate* isolate = handles.main_isolate(); |
389 i::Factory* factory = isolate->factory(); | 380 Factory* factory = isolate->factory(); |
390 i::Zone zone(isolate->allocator()); | 381 Zone zone(isolate->allocator()); |
391 | 382 |
392 struct TestCase { | 383 struct TestCase { |
393 Handle<Object> lhs; | 384 Handle<Object> lhs; |
394 Handle<Object> rhs; | 385 Handle<Object> rhs; |
395 Handle<Object> expected_value; | 386 Handle<Object> expected_value; |
396 } test_cases[] = { | 387 } test_cases[] = { |
397 {factory->NewStringFromStaticChars("a"), | 388 {factory->NewStringFromStaticChars("a"), |
398 factory->NewStringFromStaticChars("b"), | 389 factory->NewStringFromStaticChars("b"), |
399 factory->NewStringFromStaticChars("ab")}, | 390 factory->NewStringFromStaticChars("ab")}, |
400 {factory->NewStringFromStaticChars("aaaaaa"), | 391 {factory->NewStringFromStaticChars("aaaaaa"), |
(...skipping 10 matching lines...) Expand all Loading... |
411 factory->NewStringFromStaticChars("a")}, | 402 factory->NewStringFromStaticChars("a")}, |
412 {factory->NewStringFromStaticChars("1.11"), factory->NewHeapNumber(2.5), | 403 {factory->NewStringFromStaticChars("1.11"), factory->NewHeapNumber(2.5), |
413 factory->NewStringFromStaticChars("1.112.5")}, | 404 factory->NewStringFromStaticChars("1.112.5")}, |
414 {factory->NewStringFromStaticChars("-1.11"), factory->NewHeapNumber(2.56), | 405 {factory->NewStringFromStaticChars("-1.11"), factory->NewHeapNumber(2.56), |
415 factory->NewStringFromStaticChars("-1.112.56")}, | 406 factory->NewStringFromStaticChars("-1.112.56")}, |
416 {factory->NewStringFromStaticChars(""), factory->NewHeapNumber(2.5), | 407 {factory->NewStringFromStaticChars(""), factory->NewHeapNumber(2.5), |
417 factory->NewStringFromStaticChars("2.5")}, | 408 factory->NewStringFromStaticChars("2.5")}, |
418 }; | 409 }; |
419 | 410 |
420 for (size_t i = 0; i < arraysize(test_cases); i++) { | 411 for (size_t i = 0; i < arraysize(test_cases); i++) { |
421 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 412 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
422 0, 1); | 413 FeedbackVectorSpec feedback_spec(&zone); |
423 i::FeedbackVectorSpec feedback_spec(&zone); | 414 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
424 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | |
425 Handle<i::TypeFeedbackVector> vector = | 415 Handle<i::TypeFeedbackVector> vector = |
426 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 416 NewTypeFeedbackVector(isolate, &feedback_spec); |
427 | 417 |
428 Register reg(0); | 418 Register reg(0); |
429 builder.LoadLiteral(test_cases[i].lhs) | 419 builder.LoadLiteral(test_cases[i].lhs) |
430 .StoreAccumulatorInRegister(reg) | 420 .StoreAccumulatorInRegister(reg) |
431 .LoadLiteral(test_cases[i].rhs) | 421 .LoadLiteral(test_cases[i].rhs) |
432 .BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)) | 422 .BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)) |
433 .Return(); | 423 .Return(); |
434 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 424 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
435 | 425 |
436 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 426 InterpreterTester tester(isolate, bytecode_array); |
437 auto callable = tester.GetCallable<>(); | 427 auto callable = tester.GetCallable<>(); |
438 Handle<Object> return_value = callable().ToHandleChecked(); | 428 Handle<Object> return_value = callable().ToHandleChecked(); |
439 CHECK(return_value->SameValue(*test_cases[i].expected_value)); | 429 CHECK(return_value->SameValue(*test_cases[i].expected_value)); |
440 } | 430 } |
441 } | 431 } |
442 | 432 |
443 | 433 |
444 TEST(InterpreterParameter1) { | 434 TEST(InterpreterParameter1) { |
445 HandleAndZoneScope handles; | 435 HandleAndZoneScope handles; |
446 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 436 Isolate* isolate = handles.main_isolate(); |
447 0, 0); | 437 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
448 | 438 |
449 builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return(); | 439 builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return(); |
450 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 440 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
451 | 441 |
452 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 442 InterpreterTester tester(isolate, bytecode_array); |
453 auto callable = tester.GetCallable<Handle<Object>>(); | 443 auto callable = tester.GetCallable<Handle<Object>>(); |
454 | 444 |
455 // Check for heap objects. | 445 // Check for heap objects. |
456 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 446 Handle<Object> true_value = isolate->factory()->true_value(); |
457 Handle<Object> return_val = callable(true_value).ToHandleChecked(); | 447 Handle<Object> return_val = callable(true_value).ToHandleChecked(); |
458 CHECK(return_val.is_identical_to(true_value)); | 448 CHECK(return_val.is_identical_to(true_value)); |
459 | 449 |
460 // Check for Smis. | 450 // Check for Smis. |
461 return_val = callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) | 451 return_val = callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) |
462 .ToHandleChecked(); | 452 .ToHandleChecked(); |
463 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 453 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
464 } | 454 } |
465 | 455 |
466 | 456 |
467 TEST(InterpreterParameter8) { | 457 TEST(InterpreterParameter8) { |
468 HandleAndZoneScope handles; | 458 HandleAndZoneScope handles; |
469 i::Isolate* isolate = handles.main_isolate(); | 459 Isolate* isolate = handles.main_isolate(); |
470 i::Zone zone(isolate->allocator()); | 460 Zone zone(isolate->allocator()); |
471 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 8, | 461 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 8, 0, 0); |
472 0, 0); | |
473 | 462 |
474 i::FeedbackVectorSpec feedback_spec(&zone); | 463 FeedbackVectorSpec feedback_spec(&zone); |
475 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 464 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
476 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 465 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
477 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 466 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
478 i::FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); | 467 FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); |
479 i::FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); | 468 FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); |
480 i::FeedbackVectorSlot slot5 = feedback_spec.AddGeneralSlot(); | 469 FeedbackVectorSlot slot5 = feedback_spec.AddGeneralSlot(); |
481 i::FeedbackVectorSlot slot6 = feedback_spec.AddGeneralSlot(); | 470 FeedbackVectorSlot slot6 = feedback_spec.AddGeneralSlot(); |
482 | 471 |
483 Handle<i::TypeFeedbackVector> vector = | 472 Handle<i::TypeFeedbackVector> vector = |
484 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 473 NewTypeFeedbackVector(isolate, &feedback_spec); |
485 | 474 |
486 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) | 475 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) |
487 .BinaryOperation(Token::Value::ADD, builder.Parameter(1), | 476 .BinaryOperation(Token::Value::ADD, builder.Parameter(1), |
488 vector->GetIndex(slot)) | 477 vector->GetIndex(slot)) |
489 .BinaryOperation(Token::Value::ADD, builder.Parameter(2), | 478 .BinaryOperation(Token::Value::ADD, builder.Parameter(2), |
490 vector->GetIndex(slot1)) | 479 vector->GetIndex(slot1)) |
491 .BinaryOperation(Token::Value::ADD, builder.Parameter(3), | 480 .BinaryOperation(Token::Value::ADD, builder.Parameter(3), |
492 vector->GetIndex(slot2)) | 481 vector->GetIndex(slot2)) |
493 .BinaryOperation(Token::Value::ADD, builder.Parameter(4), | 482 .BinaryOperation(Token::Value::ADD, builder.Parameter(4), |
494 vector->GetIndex(slot3)) | 483 vector->GetIndex(slot3)) |
495 .BinaryOperation(Token::Value::ADD, builder.Parameter(5), | 484 .BinaryOperation(Token::Value::ADD, builder.Parameter(5), |
496 vector->GetIndex(slot4)) | 485 vector->GetIndex(slot4)) |
497 .BinaryOperation(Token::Value::ADD, builder.Parameter(6), | 486 .BinaryOperation(Token::Value::ADD, builder.Parameter(6), |
498 vector->GetIndex(slot5)) | 487 vector->GetIndex(slot5)) |
499 .BinaryOperation(Token::Value::ADD, builder.Parameter(7), | 488 .BinaryOperation(Token::Value::ADD, builder.Parameter(7), |
500 vector->GetIndex(slot6)) | 489 vector->GetIndex(slot6)) |
501 .Return(); | 490 .Return(); |
502 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 491 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
503 | 492 |
504 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 493 InterpreterTester tester(isolate, bytecode_array, vector); |
505 typedef Handle<Object> H; | 494 typedef Handle<Object> H; |
506 auto callable = tester.GetCallable<H, H, H, H, H, H, H, H>(); | 495 auto callable = tester.GetCallable<H, H, H, H, H, H, H, H>(); |
507 | 496 |
508 Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(1), handles.main_isolate()); | 497 Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(1), handles.main_isolate()); |
509 Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), handles.main_isolate()); | 498 Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), handles.main_isolate()); |
510 Handle<Smi> arg3 = Handle<Smi>(Smi::FromInt(3), handles.main_isolate()); | 499 Handle<Smi> arg3 = Handle<Smi>(Smi::FromInt(3), handles.main_isolate()); |
511 Handle<Smi> arg4 = Handle<Smi>(Smi::FromInt(4), handles.main_isolate()); | 500 Handle<Smi> arg4 = Handle<Smi>(Smi::FromInt(4), handles.main_isolate()); |
512 Handle<Smi> arg5 = Handle<Smi>(Smi::FromInt(5), handles.main_isolate()); | 501 Handle<Smi> arg5 = Handle<Smi>(Smi::FromInt(5), handles.main_isolate()); |
513 Handle<Smi> arg6 = Handle<Smi>(Smi::FromInt(6), handles.main_isolate()); | 502 Handle<Smi> arg6 = Handle<Smi>(Smi::FromInt(6), handles.main_isolate()); |
514 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); | 503 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); |
515 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); | 504 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); |
516 // Check for Smis. | 505 // Check for Smis. |
517 Handle<Object> return_val = | 506 Handle<Object> return_val = |
518 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) | 507 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
519 .ToHandleChecked(); | 508 .ToHandleChecked(); |
520 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); | 509 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); |
521 } | 510 } |
522 | 511 |
523 | 512 |
524 TEST(InterpreterParameter1Assign) { | 513 TEST(InterpreterParameter1Assign) { |
525 HandleAndZoneScope handles; | 514 HandleAndZoneScope handles; |
526 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 515 Isolate* isolate = handles.main_isolate(); |
527 0, 0); | 516 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
528 | 517 |
529 builder.LoadLiteral(Smi::FromInt(5)) | 518 builder.LoadLiteral(Smi::FromInt(5)) |
530 .StoreAccumulatorInRegister(builder.Parameter(0)) | 519 .StoreAccumulatorInRegister(builder.Parameter(0)) |
531 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 520 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
532 .Return(); | 521 .Return(); |
533 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 522 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
534 | 523 |
535 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 524 InterpreterTester tester(isolate, bytecode_array); |
536 auto callable = tester.GetCallable<Handle<Object>>(); | 525 auto callable = tester.GetCallable<Handle<Object>>(); |
537 | 526 |
538 Handle<Object> return_val = | 527 Handle<Object> return_val = |
539 callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) | 528 callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) |
540 .ToHandleChecked(); | 529 .ToHandleChecked(); |
541 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); | 530 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
542 } | 531 } |
543 | 532 |
544 | 533 |
545 TEST(InterpreterLoadGlobal) { | 534 TEST(InterpreterLoadGlobal) { |
546 HandleAndZoneScope handles; | 535 HandleAndZoneScope handles; |
| 536 Isolate* isolate = handles.main_isolate(); |
547 | 537 |
548 // Test loading a global. | 538 // Test loading a global. |
549 std::string source( | 539 std::string source( |
550 "var global = 321;\n" | 540 "var global = 321;\n" |
551 "function " + InterpreterTester::function_name() + "() {\n" | 541 "function " + InterpreterTester::function_name() + "() {\n" |
552 " return global;\n" | 542 " return global;\n" |
553 "}"); | 543 "}"); |
554 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 544 InterpreterTester tester(isolate, source.c_str()); |
555 auto callable = tester.GetCallable<>(); | 545 auto callable = tester.GetCallable<>(); |
556 | 546 |
557 Handle<Object> return_val = callable().ToHandleChecked(); | 547 Handle<Object> return_val = callable().ToHandleChecked(); |
558 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); | 548 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); |
559 } | 549 } |
560 | 550 |
561 | 551 |
562 TEST(InterpreterStoreGlobal) { | 552 TEST(InterpreterStoreGlobal) { |
563 HandleAndZoneScope handles; | 553 HandleAndZoneScope handles; |
564 i::Isolate* isolate = handles.main_isolate(); | 554 Isolate* isolate = handles.main_isolate(); |
565 i::Factory* factory = isolate->factory(); | 555 Factory* factory = isolate->factory(); |
566 | 556 |
567 // Test storing to a global. | 557 // Test storing to a global. |
568 std::string source( | 558 std::string source( |
569 "var global = 321;\n" | 559 "var global = 321;\n" |
570 "function " + InterpreterTester::function_name() + "() {\n" | 560 "function " + InterpreterTester::function_name() + "() {\n" |
571 " global = 999;\n" | 561 " global = 999;\n" |
572 "}"); | 562 "}"); |
573 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 563 InterpreterTester tester(isolate, source.c_str()); |
574 auto callable = tester.GetCallable<>(); | 564 auto callable = tester.GetCallable<>(); |
575 | 565 |
576 callable().ToHandleChecked(); | 566 callable().ToHandleChecked(); |
577 Handle<i::String> name = factory->InternalizeUtf8String("global"); | 567 Handle<i::String> name = factory->InternalizeUtf8String("global"); |
578 Handle<i::Object> global_obj = | 568 Handle<i::Object> global_obj = |
579 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); | 569 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); |
580 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); | 570 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); |
581 } | 571 } |
582 | 572 |
583 | 573 |
584 TEST(InterpreterCallGlobal) { | 574 TEST(InterpreterCallGlobal) { |
585 HandleAndZoneScope handles; | 575 HandleAndZoneScope handles; |
| 576 Isolate* isolate = handles.main_isolate(); |
586 | 577 |
587 // Test calling a global function. | 578 // Test calling a global function. |
588 std::string source( | 579 std::string source( |
589 "function g_add(a, b) { return a + b; }\n" | 580 "function g_add(a, b) { return a + b; }\n" |
590 "function " + InterpreterTester::function_name() + "() {\n" | 581 "function " + InterpreterTester::function_name() + "() {\n" |
591 " return g_add(5, 10);\n" | 582 " return g_add(5, 10);\n" |
592 "}"); | 583 "}"); |
593 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 584 InterpreterTester tester(isolate, source.c_str()); |
594 auto callable = tester.GetCallable<>(); | 585 auto callable = tester.GetCallable<>(); |
595 | 586 |
596 Handle<Object> return_val = callable().ToHandleChecked(); | 587 Handle<Object> return_val = callable().ToHandleChecked(); |
597 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); | 588 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
598 } | 589 } |
599 | 590 |
600 | 591 |
601 TEST(InterpreterLoadUnallocated) { | 592 TEST(InterpreterLoadUnallocated) { |
602 HandleAndZoneScope handles; | 593 HandleAndZoneScope handles; |
| 594 Isolate* isolate = handles.main_isolate(); |
603 | 595 |
604 // Test loading an unallocated global. | 596 // Test loading an unallocated global. |
605 std::string source( | 597 std::string source( |
606 "unallocated = 123;\n" | 598 "unallocated = 123;\n" |
607 "function " + InterpreterTester::function_name() + "() {\n" | 599 "function " + InterpreterTester::function_name() + "() {\n" |
608 " return unallocated;\n" | 600 " return unallocated;\n" |
609 "}"); | 601 "}"); |
610 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 602 InterpreterTester tester(isolate, source.c_str()); |
611 auto callable = tester.GetCallable<>(); | 603 auto callable = tester.GetCallable<>(); |
612 | 604 |
613 Handle<Object> return_val = callable().ToHandleChecked(); | 605 Handle<Object> return_val = callable().ToHandleChecked(); |
614 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 606 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
615 } | 607 } |
616 | 608 |
617 | 609 |
618 TEST(InterpreterStoreUnallocated) { | 610 TEST(InterpreterStoreUnallocated) { |
619 HandleAndZoneScope handles; | 611 HandleAndZoneScope handles; |
620 i::Isolate* isolate = handles.main_isolate(); | 612 Isolate* isolate = handles.main_isolate(); |
621 i::Factory* factory = isolate->factory(); | 613 Factory* factory = isolate->factory(); |
622 | 614 |
623 // Test storing to an unallocated global. | 615 // Test storing to an unallocated global. |
624 std::string source( | 616 std::string source( |
625 "unallocated = 321;\n" | 617 "unallocated = 321;\n" |
626 "function " + InterpreterTester::function_name() + "() {\n" | 618 "function " + InterpreterTester::function_name() + "() {\n" |
627 " unallocated = 999;\n" | 619 " unallocated = 999;\n" |
628 "}"); | 620 "}"); |
629 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 621 InterpreterTester tester(isolate, source.c_str()); |
630 auto callable = tester.GetCallable<>(); | 622 auto callable = tester.GetCallable<>(); |
631 | 623 |
632 callable().ToHandleChecked(); | 624 callable().ToHandleChecked(); |
633 Handle<i::String> name = factory->InternalizeUtf8String("unallocated"); | 625 Handle<i::String> name = factory->InternalizeUtf8String("unallocated"); |
634 Handle<i::Object> global_obj = | 626 Handle<i::Object> global_obj = |
635 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); | 627 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); |
636 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); | 628 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); |
637 } | 629 } |
638 | 630 |
639 | 631 |
640 TEST(InterpreterLoadNamedProperty) { | 632 TEST(InterpreterLoadNamedProperty) { |
641 HandleAndZoneScope handles; | 633 HandleAndZoneScope handles; |
642 i::Isolate* isolate = handles.main_isolate(); | 634 Isolate* isolate = handles.main_isolate(); |
643 i::Factory* factory = isolate->factory(); | 635 Factory* factory = isolate->factory(); |
644 i::Zone zone(isolate->allocator()); | 636 Zone zone(isolate->allocator()); |
645 | 637 |
646 i::FeedbackVectorSpec feedback_spec(&zone); | 638 FeedbackVectorSpec feedback_spec(&zone); |
647 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 639 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
648 | 640 |
649 Handle<i::TypeFeedbackVector> vector = | 641 Handle<i::TypeFeedbackVector> vector = |
650 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 642 NewTypeFeedbackVector(isolate, &feedback_spec); |
651 | 643 |
652 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 644 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
653 name = factory->string_table()->LookupString(isolate, name); | 645 name = factory->string_table()->LookupString(isolate, name); |
654 | 646 |
655 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 647 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
656 0, 0); | |
657 | 648 |
658 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot)) | 649 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot)) |
659 .Return(); | 650 .Return(); |
660 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 651 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
661 | 652 |
662 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 653 InterpreterTester tester(isolate, bytecode_array, vector); |
663 auto callable = tester.GetCallable<Handle<Object>>(); | 654 auto callable = tester.GetCallable<Handle<Object>>(); |
664 | 655 |
665 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 656 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
666 // Test IC miss. | 657 // Test IC miss. |
667 Handle<Object> return_val = callable(object).ToHandleChecked(); | 658 Handle<Object> return_val = callable(object).ToHandleChecked(); |
668 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 659 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
669 | 660 |
670 // Test transition to monomorphic IC. | 661 // Test transition to monomorphic IC. |
671 return_val = callable(object).ToHandleChecked(); | 662 return_val = callable(object).ToHandleChecked(); |
672 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 663 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
(...skipping 13 matching lines...) Expand all Loading... |
686 callable(object4).ToHandleChecked(); | 677 callable(object4).ToHandleChecked(); |
687 Handle<Object> object5 = | 678 Handle<Object> object5 = |
688 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); | 679 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
689 return_val = callable(object5).ToHandleChecked(); | 680 return_val = callable(object5).ToHandleChecked(); |
690 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 681 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
691 } | 682 } |
692 | 683 |
693 | 684 |
694 TEST(InterpreterLoadKeyedProperty) { | 685 TEST(InterpreterLoadKeyedProperty) { |
695 HandleAndZoneScope handles; | 686 HandleAndZoneScope handles; |
696 i::Isolate* isolate = handles.main_isolate(); | 687 Isolate* isolate = handles.main_isolate(); |
697 i::Factory* factory = isolate->factory(); | 688 Factory* factory = isolate->factory(); |
698 i::Zone zone(isolate->allocator()); | 689 Zone zone(isolate->allocator()); |
699 | 690 |
700 i::FeedbackVectorSpec feedback_spec(&zone); | 691 FeedbackVectorSpec feedback_spec(&zone); |
701 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); | 692 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
702 | 693 |
703 Handle<i::TypeFeedbackVector> vector = | 694 Handle<i::TypeFeedbackVector> vector = |
704 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 695 NewTypeFeedbackVector(isolate, &feedback_spec); |
705 | 696 |
706 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); | 697 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); |
707 key = factory->string_table()->LookupString(isolate, key); | 698 key = factory->string_table()->LookupString(isolate, key); |
708 | 699 |
709 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 700 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
710 0, 1); | |
711 | 701 |
712 builder.LoadLiteral(key) | 702 builder.LoadLiteral(key) |
713 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot)) | 703 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot)) |
714 .Return(); | 704 .Return(); |
715 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 705 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
716 | 706 |
717 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 707 InterpreterTester tester(isolate, bytecode_array, vector); |
718 auto callable = tester.GetCallable<Handle<Object>>(); | 708 auto callable = tester.GetCallable<Handle<Object>>(); |
719 | 709 |
720 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); | 710 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); |
721 // Test IC miss. | 711 // Test IC miss. |
722 Handle<Object> return_val = callable(object).ToHandleChecked(); | 712 Handle<Object> return_val = callable(object).ToHandleChecked(); |
723 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 713 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
724 | 714 |
725 // Test transition to monomorphic IC. | 715 // Test transition to monomorphic IC. |
726 return_val = callable(object).ToHandleChecked(); | 716 return_val = callable(object).ToHandleChecked(); |
727 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 717 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
728 | 718 |
729 // Test transition to megamorphic IC. | 719 // Test transition to megamorphic IC. |
730 Handle<Object> object3 = | 720 Handle<Object> object3 = |
731 InterpreterTester::NewObject("({ key : 789, val2 : 123 })"); | 721 InterpreterTester::NewObject("({ key : 789, val2 : 123 })"); |
732 return_val = callable(object3).ToHandleChecked(); | 722 return_val = callable(object3).ToHandleChecked(); |
733 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 723 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
734 } | 724 } |
735 | 725 |
736 | 726 |
737 TEST(InterpreterStoreNamedProperty) { | 727 TEST(InterpreterStoreNamedProperty) { |
738 HandleAndZoneScope handles; | 728 HandleAndZoneScope handles; |
739 i::Isolate* isolate = handles.main_isolate(); | 729 Isolate* isolate = handles.main_isolate(); |
740 i::Factory* factory = isolate->factory(); | 730 Factory* factory = isolate->factory(); |
741 i::Zone zone(isolate->allocator()); | 731 Zone zone(isolate->allocator()); |
742 | 732 |
743 i::FeedbackVectorSpec feedback_spec(&zone); | 733 FeedbackVectorSpec feedback_spec(&zone); |
744 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); | 734 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); |
745 | 735 |
746 Handle<i::TypeFeedbackVector> vector = | 736 Handle<i::TypeFeedbackVector> vector = |
747 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 737 NewTypeFeedbackVector(isolate, &feedback_spec); |
748 | 738 |
749 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 739 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
750 name = factory->string_table()->LookupString(isolate, name); | 740 name = factory->string_table()->LookupString(isolate, name); |
751 | 741 |
752 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 742 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
753 0, 0); | |
754 | 743 |
755 builder.LoadLiteral(Smi::FromInt(999)) | 744 builder.LoadLiteral(Smi::FromInt(999)) |
756 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot), | 745 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot), |
757 i::STRICT) | 746 STRICT) |
758 .Return(); | 747 .Return(); |
759 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 748 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
760 | 749 |
761 InterpreterTester tester(isolate, bytecode_array, vector); | 750 InterpreterTester tester(isolate, bytecode_array, vector); |
762 auto callable = tester.GetCallable<Handle<Object>>(); | 751 auto callable = tester.GetCallable<Handle<Object>>(); |
763 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 752 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
764 // Test IC miss. | 753 // Test IC miss. |
765 Handle<Object> result; | 754 Handle<Object> result; |
766 callable(object).ToHandleChecked(); | 755 callable(object).ToHandleChecked(); |
767 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 756 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
768 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 757 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
769 | 758 |
(...skipping 19 matching lines...) Expand all Loading... |
789 Handle<Object> object5 = | 778 Handle<Object> object5 = |
790 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); | 779 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
791 callable(object5).ToHandleChecked(); | 780 callable(object5).ToHandleChecked(); |
792 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); | 781 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); |
793 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 782 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
794 } | 783 } |
795 | 784 |
796 | 785 |
797 TEST(InterpreterStoreKeyedProperty) { | 786 TEST(InterpreterStoreKeyedProperty) { |
798 HandleAndZoneScope handles; | 787 HandleAndZoneScope handles; |
799 i::Isolate* isolate = handles.main_isolate(); | 788 Isolate* isolate = handles.main_isolate(); |
800 i::Factory* factory = isolate->factory(); | 789 Factory* factory = isolate->factory(); |
801 i::Zone zone(isolate->allocator()); | 790 Zone zone(isolate->allocator()); |
802 | 791 |
803 i::FeedbackVectorSpec feedback_spec(&zone); | 792 FeedbackVectorSpec feedback_spec(&zone); |
804 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); | 793 FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); |
805 | 794 |
806 Handle<i::TypeFeedbackVector> vector = | 795 Handle<i::TypeFeedbackVector> vector = |
807 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 796 NewTypeFeedbackVector(isolate, &feedback_spec); |
808 | 797 |
809 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 798 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
810 name = factory->string_table()->LookupString(isolate, name); | 799 name = factory->string_table()->LookupString(isolate, name); |
811 | 800 |
812 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 801 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
813 0, 1); | |
814 | 802 |
815 builder.LoadLiteral(name) | 803 builder.LoadLiteral(name) |
816 .StoreAccumulatorInRegister(Register(0)) | 804 .StoreAccumulatorInRegister(Register(0)) |
817 .LoadLiteral(Smi::FromInt(999)) | 805 .LoadLiteral(Smi::FromInt(999)) |
818 .StoreKeyedProperty(builder.Parameter(0), Register(0), | 806 .StoreKeyedProperty(builder.Parameter(0), Register(0), |
819 vector->GetIndex(slot), i::SLOPPY) | 807 vector->GetIndex(slot), i::SLOPPY) |
820 .Return(); | 808 .Return(); |
821 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 809 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
822 | 810 |
823 InterpreterTester tester(isolate, bytecode_array, vector); | 811 InterpreterTester tester(isolate, bytecode_array, vector); |
824 auto callable = tester.GetCallable<Handle<Object>>(); | 812 auto callable = tester.GetCallable<Handle<Object>>(); |
825 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 813 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
826 // Test IC miss. | 814 // Test IC miss. |
827 Handle<Object> result; | 815 Handle<Object> result; |
828 callable(object).ToHandleChecked(); | 816 callable(object).ToHandleChecked(); |
829 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 817 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
830 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 818 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
831 | 819 |
832 // Test transition to monomorphic IC. | 820 // Test transition to monomorphic IC. |
833 callable(object).ToHandleChecked(); | 821 callable(object).ToHandleChecked(); |
834 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 822 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
835 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 823 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
836 | 824 |
837 // Test transition to megamorphic IC. | 825 // Test transition to megamorphic IC. |
838 Handle<Object> object2 = | 826 Handle<Object> object2 = |
839 InterpreterTester::NewObject("({ val : 456, other : 123 })"); | 827 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
840 callable(object2).ToHandleChecked(); | 828 callable(object2).ToHandleChecked(); |
841 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); | 829 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); |
842 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 830 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
843 } | 831 } |
844 | 832 |
845 static void TestInterpreterCall(TailCallMode tail_call_mode) { | 833 static void TestInterpreterCall(TailCallMode tail_call_mode) { |
846 HandleAndZoneScope handles; | 834 HandleAndZoneScope handles; |
847 i::Isolate* isolate = handles.main_isolate(); | 835 Isolate* isolate = handles.main_isolate(); |
848 i::Factory* factory = isolate->factory(); | 836 Factory* factory = isolate->factory(); |
849 i::Zone zone(isolate->allocator()); | 837 Zone zone(isolate->allocator()); |
850 | 838 |
851 i::FeedbackVectorSpec feedback_spec(&zone); | 839 FeedbackVectorSpec feedback_spec(&zone); |
852 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 840 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
853 i::FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot(); | 841 FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot(); |
854 | 842 |
855 Handle<i::TypeFeedbackVector> vector = | 843 Handle<i::TypeFeedbackVector> vector = |
856 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 844 NewTypeFeedbackVector(isolate, &feedback_spec); |
857 int slot_index = vector->GetIndex(slot); | 845 int slot_index = vector->GetIndex(slot); |
858 int call_slot_index = -1; | 846 int call_slot_index = -1; |
859 call_slot_index = vector->GetIndex(call_slot); | 847 call_slot_index = vector->GetIndex(call_slot); |
860 | 848 |
861 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); | 849 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); |
862 name = factory->string_table()->LookupString(isolate, name); | 850 name = factory->string_table()->LookupString(isolate, name); |
863 | 851 |
864 // Check with no args. | 852 // Check with no args. |
865 { | 853 { |
866 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 854 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
867 0, 1); | |
868 | 855 |
869 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 856 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
870 .StoreAccumulatorInRegister(Register(0)); | 857 .StoreAccumulatorInRegister(Register(0)); |
871 | 858 |
872 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, | 859 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, |
873 tail_call_mode); | 860 tail_call_mode); |
874 | 861 |
875 builder.Return(); | 862 builder.Return(); |
876 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 863 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
877 | 864 |
878 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 865 InterpreterTester tester(isolate, bytecode_array, vector); |
879 auto callable = tester.GetCallable<Handle<Object>>(); | 866 auto callable = tester.GetCallable<Handle<Object>>(); |
880 | 867 |
881 Handle<Object> object = InterpreterTester::NewObject( | 868 Handle<Object> object = InterpreterTester::NewObject( |
882 "new (function Obj() { this.func = function() { return 0x265; }})()"); | 869 "new (function Obj() { this.func = function() { return 0x265; }})()"); |
883 Handle<Object> return_val = callable(object).ToHandleChecked(); | 870 Handle<Object> return_val = callable(object).ToHandleChecked(); |
884 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); | 871 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); |
885 } | 872 } |
886 | 873 |
887 // Check that receiver is passed properly. | 874 // Check that receiver is passed properly. |
888 { | 875 { |
889 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 876 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
890 0, 1); | |
891 | 877 |
892 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 878 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
893 .StoreAccumulatorInRegister(Register(0)); | 879 .StoreAccumulatorInRegister(Register(0)); |
894 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, | 880 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, |
895 tail_call_mode); | 881 tail_call_mode); |
896 builder.Return(); | 882 builder.Return(); |
897 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 883 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
898 | 884 |
899 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 885 InterpreterTester tester(isolate, bytecode_array, vector); |
900 auto callable = tester.GetCallable<Handle<Object>>(); | 886 auto callable = tester.GetCallable<Handle<Object>>(); |
901 | 887 |
902 Handle<Object> object = InterpreterTester::NewObject( | 888 Handle<Object> object = InterpreterTester::NewObject( |
903 "new (function Obj() {" | 889 "new (function Obj() {" |
904 " this.val = 1234;" | 890 " this.val = 1234;" |
905 " this.func = function() { return this.val; };" | 891 " this.func = function() { return this.val; };" |
906 "})()"); | 892 "})()"); |
907 Handle<Object> return_val = callable(object).ToHandleChecked(); | 893 Handle<Object> return_val = callable(object).ToHandleChecked(); |
908 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); | 894 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); |
909 } | 895 } |
910 | 896 |
911 // Check with two parameters (+ receiver). | 897 // Check with two parameters (+ receiver). |
912 { | 898 { |
913 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 899 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 4); |
914 0, 4); | |
915 | 900 |
916 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 901 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
917 .StoreAccumulatorInRegister(Register(0)) | 902 .StoreAccumulatorInRegister(Register(0)) |
918 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 903 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
919 .StoreAccumulatorInRegister(Register(1)) | 904 .StoreAccumulatorInRegister(Register(1)) |
920 .LoadLiteral(Smi::FromInt(51)) | 905 .LoadLiteral(Smi::FromInt(51)) |
921 .StoreAccumulatorInRegister(Register(2)) | 906 .StoreAccumulatorInRegister(Register(2)) |
922 .LoadLiteral(Smi::FromInt(11)) | 907 .LoadLiteral(Smi::FromInt(11)) |
923 .StoreAccumulatorInRegister(Register(3)); | 908 .StoreAccumulatorInRegister(Register(3)); |
924 | 909 |
925 builder.Call(Register(0), Register(1), 3, call_slot_index, tail_call_mode); | 910 builder.Call(Register(0), Register(1), 3, call_slot_index, tail_call_mode); |
926 | 911 |
927 builder.Return(); | 912 builder.Return(); |
928 | 913 |
929 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 914 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
930 | 915 |
931 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 916 InterpreterTester tester(isolate, bytecode_array, vector); |
932 auto callable = tester.GetCallable<Handle<Object>>(); | 917 auto callable = tester.GetCallable<Handle<Object>>(); |
933 | 918 |
934 Handle<Object> object = InterpreterTester::NewObject( | 919 Handle<Object> object = InterpreterTester::NewObject( |
935 "new (function Obj() { " | 920 "new (function Obj() { " |
936 " this.func = function(a, b) { return a - b; }" | 921 " this.func = function(a, b) { return a - b; }" |
937 "})()"); | 922 "})()"); |
938 Handle<Object> return_val = callable(object).ToHandleChecked(); | 923 Handle<Object> return_val = callable(object).ToHandleChecked(); |
939 CHECK(return_val->SameValue(Smi::FromInt(40))); | 924 CHECK(return_val->SameValue(Smi::FromInt(40))); |
940 } | 925 } |
941 | 926 |
942 // Check with 10 parameters (+ receiver). | 927 // Check with 10 parameters (+ receiver). |
943 { | 928 { |
944 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 929 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 12); |
945 0, 12); | |
946 | 930 |
947 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 931 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
948 .StoreAccumulatorInRegister(Register(0)) | 932 .StoreAccumulatorInRegister(Register(0)) |
949 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 933 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
950 .StoreAccumulatorInRegister(Register(1)) | 934 .StoreAccumulatorInRegister(Register(1)) |
951 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) | 935 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) |
952 .StoreAccumulatorInRegister(Register(2)) | 936 .StoreAccumulatorInRegister(Register(2)) |
953 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) | 937 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) |
954 .StoreAccumulatorInRegister(Register(3)) | 938 .StoreAccumulatorInRegister(Register(3)) |
955 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) | 939 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) |
(...skipping 10 matching lines...) Expand all Loading... |
966 .StoreAccumulatorInRegister(Register(9)) | 950 .StoreAccumulatorInRegister(Register(9)) |
967 .LoadLiteral(factory->NewStringFromAsciiChecked("i")) | 951 .LoadLiteral(factory->NewStringFromAsciiChecked("i")) |
968 .StoreAccumulatorInRegister(Register(10)) | 952 .StoreAccumulatorInRegister(Register(10)) |
969 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) | 953 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) |
970 .StoreAccumulatorInRegister(Register(11)); | 954 .StoreAccumulatorInRegister(Register(11)); |
971 | 955 |
972 builder.Call(Register(0), Register(1), 11, call_slot_index, tail_call_mode); | 956 builder.Call(Register(0), Register(1), 11, call_slot_index, tail_call_mode); |
973 | 957 |
974 builder.Return(); | 958 builder.Return(); |
975 | 959 |
976 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 960 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
977 | 961 |
978 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 962 InterpreterTester tester(isolate, bytecode_array, vector); |
979 auto callable = tester.GetCallable<Handle<Object>>(); | 963 auto callable = tester.GetCallable<Handle<Object>>(); |
980 | 964 |
981 Handle<Object> object = InterpreterTester::NewObject( | 965 Handle<Object> object = InterpreterTester::NewObject( |
982 "new (function Obj() { " | 966 "new (function Obj() { " |
983 " this.prefix = \"prefix_\";" | 967 " this.prefix = \"prefix_\";" |
984 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" | 968 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" |
985 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" | 969 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" |
986 " }" | 970 " }" |
987 "})()"); | 971 "})()"); |
988 Handle<Object> return_val = callable(object).ToHandleChecked(); | 972 Handle<Object> return_val = callable(object).ToHandleChecked(); |
(...skipping 23 matching lines...) Expand all Loading... |
1012 return builder.StoreAccumulatorInRegister(scratch) | 996 return builder.StoreAccumulatorInRegister(scratch) |
1013 .LoadLiteral(Smi::FromInt(value)) | 997 .LoadLiteral(Smi::FromInt(value)) |
1014 .BinaryOperation(Token::Value::ADD, reg, slot_index) | 998 .BinaryOperation(Token::Value::ADD, reg, slot_index) |
1015 .StoreAccumulatorInRegister(reg) | 999 .StoreAccumulatorInRegister(reg) |
1016 .LoadAccumulatorWithRegister(scratch); | 1000 .LoadAccumulatorWithRegister(scratch); |
1017 } | 1001 } |
1018 | 1002 |
1019 | 1003 |
1020 TEST(InterpreterJumps) { | 1004 TEST(InterpreterJumps) { |
1021 HandleAndZoneScope handles; | 1005 HandleAndZoneScope handles; |
1022 i::Isolate* isolate = handles.main_isolate(); | 1006 Isolate* isolate = handles.main_isolate(); |
1023 i::Zone zone(isolate->allocator()); | 1007 Zone zone(isolate->allocator()); |
1024 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1008 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 2); |
1025 0, 2); | |
1026 | 1009 |
1027 i::FeedbackVectorSpec feedback_spec(&zone); | 1010 FeedbackVectorSpec feedback_spec(&zone); |
1028 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1011 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1029 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 1012 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
1030 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 1013 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
1031 | 1014 |
1032 Handle<i::TypeFeedbackVector> vector = | 1015 Handle<i::TypeFeedbackVector> vector = |
1033 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1016 NewTypeFeedbackVector(isolate, &feedback_spec); |
1034 | 1017 |
1035 Register reg(0), scratch(1); | 1018 Register reg(0), scratch(1); |
1036 BytecodeLabel label[3]; | 1019 BytecodeLabel label[3]; |
1037 | 1020 |
1038 builder.LoadLiteral(Smi::FromInt(0)) | 1021 builder.LoadLiteral(Smi::FromInt(0)) |
1039 .StoreAccumulatorInRegister(reg) | 1022 .StoreAccumulatorInRegister(reg) |
1040 .Jump(&label[1]); | 1023 .Jump(&label[1]); |
1041 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); | 1024 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); |
1042 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot)) | 1025 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot)) |
1043 .Jump(&label[2]); | 1026 .Jump(&label[2]); |
1044 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); | 1027 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); |
1045 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1)) | 1028 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1)) |
1046 .Jump(&label[0]); | 1029 .Jump(&label[0]); |
1047 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); | 1030 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); |
1048 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2)) | 1031 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2)) |
1049 .LoadAccumulatorWithRegister(reg) | 1032 .LoadAccumulatorWithRegister(reg) |
1050 .Return(); | 1033 .Return(); |
1051 | 1034 |
1052 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1035 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1053 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1036 InterpreterTester tester(isolate, bytecode_array); |
1054 auto callable = tester.GetCallable<>(); | 1037 auto callable = tester.GetCallable<>(); |
1055 Handle<Object> return_value = callable().ToHandleChecked(); | 1038 Handle<Object> return_value = callable().ToHandleChecked(); |
1056 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1039 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
1057 } | 1040 } |
1058 | 1041 |
1059 | 1042 |
1060 TEST(InterpreterConditionalJumps) { | 1043 TEST(InterpreterConditionalJumps) { |
1061 HandleAndZoneScope handles; | 1044 HandleAndZoneScope handles; |
1062 i::Isolate* isolate = handles.main_isolate(); | 1045 Isolate* isolate = handles.main_isolate(); |
1063 i::Zone zone(isolate->allocator()); | 1046 Zone zone(isolate->allocator()); |
1064 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1047 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 2); |
1065 0, 2); | |
1066 | 1048 |
1067 i::FeedbackVectorSpec feedback_spec(&zone); | 1049 FeedbackVectorSpec feedback_spec(&zone); |
1068 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1050 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1069 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 1051 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
1070 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 1052 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
1071 i::FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); | 1053 FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); |
1072 i::FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); | 1054 FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); |
1073 | 1055 |
1074 Handle<i::TypeFeedbackVector> vector = | 1056 Handle<i::TypeFeedbackVector> vector = |
1075 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1057 NewTypeFeedbackVector(isolate, &feedback_spec); |
1076 | 1058 |
1077 Register reg(0), scratch(1); | 1059 Register reg(0), scratch(1); |
1078 BytecodeLabel label[2]; | 1060 BytecodeLabel label[2]; |
1079 BytecodeLabel done, done1; | 1061 BytecodeLabel done, done1; |
1080 | 1062 |
1081 builder.LoadLiteral(Smi::FromInt(0)) | 1063 builder.LoadLiteral(Smi::FromInt(0)) |
1082 .StoreAccumulatorInRegister(reg) | 1064 .StoreAccumulatorInRegister(reg) |
1083 .LoadFalse() | 1065 .LoadFalse() |
1084 .JumpIfFalse(&label[0]); | 1066 .JumpIfFalse(&label[0]); |
1085 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) | 1067 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) |
1086 .Bind(&label[0]) | 1068 .Bind(&label[0]) |
1087 .LoadTrue() | 1069 .LoadTrue() |
1088 .JumpIfFalse(&done); | 1070 .JumpIfFalse(&done); |
1089 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) | 1071 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) |
1090 .LoadTrue() | 1072 .LoadTrue() |
1091 .JumpIfTrue(&label[1]); | 1073 .JumpIfTrue(&label[1]); |
1092 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) | 1074 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) |
1093 .Bind(&label[1]); | 1075 .Bind(&label[1]); |
1094 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) | 1076 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) |
1095 .LoadFalse() | 1077 .LoadFalse() |
1096 .JumpIfTrue(&done1); | 1078 .JumpIfTrue(&done1); |
1097 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) | 1079 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) |
1098 .LoadAccumulatorWithRegister(reg) | 1080 .LoadAccumulatorWithRegister(reg) |
1099 .Bind(&done) | 1081 .Bind(&done) |
1100 .Bind(&done1) | 1082 .Bind(&done1) |
1101 .Return(); | 1083 .Return(); |
1102 | 1084 |
1103 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1085 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1104 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1086 InterpreterTester tester(isolate, bytecode_array); |
1105 auto callable = tester.GetCallable<>(); | 1087 auto callable = tester.GetCallable<>(); |
1106 Handle<Object> return_value = callable().ToHandleChecked(); | 1088 Handle<Object> return_value = callable().ToHandleChecked(); |
1107 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1089 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
1108 } | 1090 } |
1109 | 1091 |
1110 TEST(InterpreterConditionalJumps2) { | 1092 TEST(InterpreterConditionalJumps2) { |
1111 // TODO(oth): Add tests for all conditional jumps near and far. | 1093 // TODO(oth): Add tests for all conditional jumps near and far. |
1112 HandleAndZoneScope handles; | 1094 HandleAndZoneScope handles; |
1113 i::Isolate* isolate = handles.main_isolate(); | 1095 Isolate* isolate = handles.main_isolate(); |
1114 i::Zone zone(isolate->allocator()); | 1096 Zone zone(isolate->allocator()); |
1115 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1097 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 2); |
1116 0, 2); | |
1117 | 1098 |
1118 i::FeedbackVectorSpec feedback_spec(&zone); | 1099 FeedbackVectorSpec feedback_spec(&zone); |
1119 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1100 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1120 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 1101 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
1121 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 1102 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
1122 i::FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); | 1103 FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); |
1123 i::FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); | 1104 FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); |
1124 | 1105 |
1125 Handle<i::TypeFeedbackVector> vector = | 1106 Handle<i::TypeFeedbackVector> vector = |
1126 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1107 NewTypeFeedbackVector(isolate, &feedback_spec); |
1127 | 1108 |
1128 Register reg(0), scratch(1); | 1109 Register reg(0), scratch(1); |
1129 BytecodeLabel label[2]; | 1110 BytecodeLabel label[2]; |
1130 BytecodeLabel done, done1; | 1111 BytecodeLabel done, done1; |
1131 | 1112 |
1132 builder.LoadLiteral(Smi::FromInt(0)) | 1113 builder.LoadLiteral(Smi::FromInt(0)) |
1133 .StoreAccumulatorInRegister(reg) | 1114 .StoreAccumulatorInRegister(reg) |
1134 .LoadFalse() | 1115 .LoadFalse() |
1135 .JumpIfFalse(&label[0]); | 1116 .JumpIfFalse(&label[0]); |
1136 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) | 1117 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) |
1137 .Bind(&label[0]) | 1118 .Bind(&label[0]) |
1138 .LoadTrue() | 1119 .LoadTrue() |
1139 .JumpIfFalse(&done); | 1120 .JumpIfFalse(&done); |
1140 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) | 1121 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) |
1141 .LoadTrue() | 1122 .LoadTrue() |
1142 .JumpIfTrue(&label[1]); | 1123 .JumpIfTrue(&label[1]); |
1143 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) | 1124 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) |
1144 .Bind(&label[1]); | 1125 .Bind(&label[1]); |
1145 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) | 1126 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) |
1146 .LoadFalse() | 1127 .LoadFalse() |
1147 .JumpIfTrue(&done1); | 1128 .JumpIfTrue(&done1); |
1148 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) | 1129 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) |
1149 .LoadAccumulatorWithRegister(reg) | 1130 .LoadAccumulatorWithRegister(reg) |
1150 .Bind(&done) | 1131 .Bind(&done) |
1151 .Bind(&done1) | 1132 .Bind(&done1) |
1152 .Return(); | 1133 .Return(); |
1153 | 1134 |
1154 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1135 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1155 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1136 InterpreterTester tester(isolate, bytecode_array); |
1156 auto callable = tester.GetCallable<>(); | 1137 auto callable = tester.GetCallable<>(); |
1157 Handle<Object> return_value = callable().ToHandleChecked(); | 1138 Handle<Object> return_value = callable().ToHandleChecked(); |
1158 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1139 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
1159 } | 1140 } |
1160 | 1141 |
1161 TEST(InterpreterJumpConstantWith16BitOperand) { | 1142 TEST(InterpreterJumpConstantWith16BitOperand) { |
1162 HandleAndZoneScope handles; | 1143 HandleAndZoneScope handles; |
1163 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1144 Isolate* isolate = handles.main_isolate(); |
1164 0, 257); | 1145 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 257); |
1165 | 1146 |
1166 i::Isolate* isolate = handles.main_isolate(); | 1147 Zone zone(isolate->allocator()); |
1167 i::Zone zone(isolate->allocator()); | |
1168 | 1148 |
1169 i::FeedbackVectorSpec feedback_spec(&zone); | 1149 FeedbackVectorSpec feedback_spec(&zone); |
1170 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1150 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1171 Handle<i::TypeFeedbackVector> vector = | 1151 Handle<i::TypeFeedbackVector> vector = |
1172 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1152 NewTypeFeedbackVector(isolate, &feedback_spec); |
1173 | 1153 |
1174 Register reg(0), scratch(256); | 1154 Register reg(0), scratch(256); |
1175 BytecodeLabel done, fake; | 1155 BytecodeLabel done, fake; |
1176 | 1156 |
1177 builder.LoadLiteral(Smi::FromInt(0)); | 1157 builder.LoadLiteral(Smi::FromInt(0)); |
1178 builder.StoreAccumulatorInRegister(reg); | 1158 builder.StoreAccumulatorInRegister(reg); |
1179 // Consume all 8-bit operands | 1159 // Consume all 8-bit operands |
1180 for (int i = 1; i <= 256; i++) { | 1160 for (int i = 1; i <= 256; i++) { |
1181 builder.LoadLiteral(handles.main_isolate()->factory()->NewNumber(i)); | 1161 builder.LoadLiteral(isolate->factory()->NewNumber(i)); |
1182 builder.BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)); | 1162 builder.BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)); |
1183 builder.StoreAccumulatorInRegister(reg); | 1163 builder.StoreAccumulatorInRegister(reg); |
1184 } | 1164 } |
1185 builder.Jump(&done); | 1165 builder.Jump(&done); |
1186 | 1166 |
1187 // Emit more than 16-bit immediate operands worth of code to jump over. | 1167 // Emit more than 16-bit immediate operands worth of code to jump over. |
1188 builder.Bind(&fake); | 1168 builder.Bind(&fake); |
1189 for (int i = 0; i < 6600; i++) { | 1169 for (int i = 0; i < 6600; i++) { |
1190 builder.LoadLiteral(Smi::FromInt(0)); // 1-byte | 1170 builder.LoadLiteral(Smi::FromInt(0)); // 1-byte |
1191 builder.BinaryOperation(Token::Value::ADD, scratch, | 1171 builder.BinaryOperation(Token::Value::ADD, scratch, |
1192 vector->GetIndex(slot)); // 6-bytes | 1172 vector->GetIndex(slot)); // 6-bytes |
1193 builder.StoreAccumulatorInRegister(scratch); // 4-bytes | 1173 builder.StoreAccumulatorInRegister(scratch); // 4-bytes |
1194 builder.MoveRegister(scratch, reg); // 6-bytes | 1174 builder.MoveRegister(scratch, reg); // 6-bytes |
1195 } | 1175 } |
1196 builder.Bind(&done); | 1176 builder.Bind(&done); |
1197 builder.LoadAccumulatorWithRegister(reg); | 1177 builder.LoadAccumulatorWithRegister(reg); |
1198 builder.Return(); | 1178 builder.Return(); |
1199 | 1179 |
1200 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1180 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1201 BytecodeArrayIterator iterator(bytecode_array); | 1181 BytecodeArrayIterator iterator(bytecode_array); |
1202 | 1182 |
1203 bool found_16bit_constant_jump = false; | 1183 bool found_16bit_constant_jump = false; |
1204 while (!iterator.done()) { | 1184 while (!iterator.done()) { |
1205 if (iterator.current_bytecode() == Bytecode::kJumpConstant && | 1185 if (iterator.current_bytecode() == Bytecode::kJumpConstant && |
1206 iterator.current_operand_scale() == OperandScale::kDouble) { | 1186 iterator.current_operand_scale() == OperandScale::kDouble) { |
1207 found_16bit_constant_jump = true; | 1187 found_16bit_constant_jump = true; |
1208 break; | 1188 break; |
1209 } | 1189 } |
1210 iterator.Advance(); | 1190 iterator.Advance(); |
1211 } | 1191 } |
1212 CHECK(found_16bit_constant_jump); | 1192 CHECK(found_16bit_constant_jump); |
1213 | 1193 |
1214 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1194 InterpreterTester tester(isolate, bytecode_array); |
1215 auto callable = tester.GetCallable<>(); | 1195 auto callable = tester.GetCallable<>(); |
1216 Handle<Object> return_value = callable().ToHandleChecked(); | 1196 Handle<Object> return_value = callable().ToHandleChecked(); |
1217 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256)); | 1197 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256)); |
1218 } | 1198 } |
1219 | 1199 |
1220 TEST(InterpreterJumpWith32BitOperand) { | 1200 TEST(InterpreterJumpWith32BitOperand) { |
1221 HandleAndZoneScope handles; | 1201 HandleAndZoneScope handles; |
1222 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1202 Isolate* isolate = handles.main_isolate(); |
1223 0, 1); | 1203 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
1224 Register reg(0); | 1204 Register reg(0); |
1225 BytecodeLabel done; | 1205 BytecodeLabel done; |
1226 | 1206 |
1227 builder.LoadLiteral(Smi::FromInt(0)); | 1207 builder.LoadLiteral(Smi::FromInt(0)); |
1228 builder.StoreAccumulatorInRegister(reg); | 1208 builder.StoreAccumulatorInRegister(reg); |
1229 // Consume all 16-bit constant pool entries | 1209 // Consume all 16-bit constant pool entries |
1230 for (int i = 1; i <= 65536; i++) { | 1210 for (int i = 1; i <= 65536; i++) { |
1231 builder.LoadLiteral(handles.main_isolate()->factory()->NewNumber(i)); | 1211 builder.LoadLiteral(isolate->factory()->NewNumber(i)); |
1232 } | 1212 } |
1233 builder.Jump(&done); | 1213 builder.Jump(&done); |
1234 builder.LoadLiteral(Smi::FromInt(0)); | 1214 builder.LoadLiteral(Smi::FromInt(0)); |
1235 builder.Bind(&done); | 1215 builder.Bind(&done); |
1236 builder.Return(); | 1216 builder.Return(); |
1237 | 1217 |
1238 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1218 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1239 BytecodeArrayIterator iterator(bytecode_array); | 1219 BytecodeArrayIterator iterator(bytecode_array); |
1240 | 1220 |
1241 bool found_32bit_jump = false; | 1221 bool found_32bit_jump = false; |
1242 while (!iterator.done()) { | 1222 while (!iterator.done()) { |
1243 if (iterator.current_bytecode() == Bytecode::kJump && | 1223 if (iterator.current_bytecode() == Bytecode::kJump && |
1244 iterator.current_operand_scale() == OperandScale::kQuadruple) { | 1224 iterator.current_operand_scale() == OperandScale::kQuadruple) { |
1245 found_32bit_jump = true; | 1225 found_32bit_jump = true; |
1246 break; | 1226 break; |
1247 } | 1227 } |
1248 iterator.Advance(); | 1228 iterator.Advance(); |
1249 } | 1229 } |
1250 CHECK(found_32bit_jump); | 1230 CHECK(found_32bit_jump); |
1251 | 1231 |
1252 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1232 InterpreterTester tester(isolate, bytecode_array); |
1253 auto callable = tester.GetCallable<>(); | 1233 auto callable = tester.GetCallable<>(); |
1254 Handle<Object> return_value = callable().ToHandleChecked(); | 1234 Handle<Object> return_value = callable().ToHandleChecked(); |
1255 CHECK_EQ(Smi::cast(*return_value)->value(), 65536.0); | 1235 CHECK_EQ(Smi::cast(*return_value)->value(), 65536.0); |
1256 } | 1236 } |
1257 | 1237 |
1258 static const Token::Value kComparisonTypes[] = { | 1238 static const Token::Value kComparisonTypes[] = { |
1259 Token::Value::EQ, Token::Value::NE, Token::Value::EQ_STRICT, | 1239 Token::Value::EQ, Token::Value::NE, Token::Value::EQ_STRICT, |
1260 Token::Value::LT, Token::Value::LTE, Token::Value::GT, | 1240 Token::Value::LT, Token::Value::LTE, Token::Value::GT, |
1261 Token::Value::GTE}; | 1241 Token::Value::GTE}; |
1262 | 1242 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 42, | 1281 42, |
1302 12345678, | 1282 12345678, |
1303 v8::internal::kMaxInt / 4, | 1283 v8::internal::kMaxInt / 4, |
1304 v8::internal::kMaxInt / 2}; | 1284 v8::internal::kMaxInt / 2}; |
1305 | 1285 |
1306 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1286 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1307 Token::Value comparison = kComparisonTypes[c]; | 1287 Token::Value comparison = kComparisonTypes[c]; |
1308 for (size_t i = 0; i < arraysize(inputs); i++) { | 1288 for (size_t i = 0; i < arraysize(inputs); i++) { |
1309 for (size_t j = 0; j < arraysize(inputs); j++) { | 1289 for (size_t j = 0; j < arraysize(inputs); j++) { |
1310 HandleAndZoneScope handles; | 1290 HandleAndZoneScope handles; |
1311 BytecodeArrayBuilder builder(handles.main_isolate(), | 1291 Isolate* isolate = handles.main_isolate(); |
1312 handles.main_zone(), 0, 0, 1); | 1292 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1313 | 1293 |
1314 Register r0(0); | 1294 Register r0(0); |
1315 builder.LoadLiteral(Smi::FromInt(inputs[i])) | 1295 builder.LoadLiteral(Smi::FromInt(inputs[i])) |
1316 .StoreAccumulatorInRegister(r0) | 1296 .StoreAccumulatorInRegister(r0) |
1317 .LoadLiteral(Smi::FromInt(inputs[j])) | 1297 .LoadLiteral(Smi::FromInt(inputs[j])) |
1318 .CompareOperation(comparison, r0) | 1298 .CompareOperation(comparison, r0) |
1319 .Return(); | 1299 .Return(); |
1320 | 1300 |
1321 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1301 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1322 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1302 InterpreterTester tester(isolate, bytecode_array); |
1323 auto callable = tester.GetCallable<>(); | 1303 auto callable = tester.GetCallable<>(); |
1324 Handle<Object> return_value = callable().ToHandleChecked(); | 1304 Handle<Object> return_value = callable().ToHandleChecked(); |
1325 CHECK(return_value->IsBoolean()); | 1305 CHECK(return_value->IsBoolean()); |
1326 CHECK_EQ(return_value->BooleanValue(), | 1306 CHECK_EQ(return_value->BooleanValue(), |
1327 CompareC(comparison, inputs[i], inputs[j])); | 1307 CompareC(comparison, inputs[i], inputs[j])); |
1328 } | 1308 } |
1329 } | 1309 } |
1330 } | 1310 } |
1331 } | 1311 } |
1332 | 1312 |
1333 | 1313 |
1334 TEST(InterpreterHeapNumberComparisons) { | 1314 TEST(InterpreterHeapNumberComparisons) { |
1335 double inputs[] = {std::numeric_limits<double>::min(), | 1315 double inputs[] = {std::numeric_limits<double>::min(), |
1336 std::numeric_limits<double>::max(), | 1316 std::numeric_limits<double>::max(), |
1337 -0.001, | 1317 -0.001, |
1338 0.01, | 1318 0.01, |
1339 0.1000001, | 1319 0.1000001, |
1340 1e99, | 1320 1e99, |
1341 -1e-99}; | 1321 -1e-99}; |
1342 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1322 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1343 Token::Value comparison = kComparisonTypes[c]; | 1323 Token::Value comparison = kComparisonTypes[c]; |
1344 for (size_t i = 0; i < arraysize(inputs); i++) { | 1324 for (size_t i = 0; i < arraysize(inputs); i++) { |
1345 for (size_t j = 0; j < arraysize(inputs); j++) { | 1325 for (size_t j = 0; j < arraysize(inputs); j++) { |
1346 HandleAndZoneScope handles; | 1326 HandleAndZoneScope handles; |
1347 i::Factory* factory = handles.main_isolate()->factory(); | 1327 Isolate* isolate = handles.main_isolate(); |
1348 BytecodeArrayBuilder builder(handles.main_isolate(), | 1328 Factory* factory = isolate->factory(); |
1349 handles.main_zone(), 0, 0, 1); | 1329 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1350 | 1330 |
1351 Register r0(0); | 1331 Register r0(0); |
1352 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) | 1332 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) |
1353 .StoreAccumulatorInRegister(r0) | 1333 .StoreAccumulatorInRegister(r0) |
1354 .LoadLiteral(factory->NewHeapNumber(inputs[j])) | 1334 .LoadLiteral(factory->NewHeapNumber(inputs[j])) |
1355 .CompareOperation(comparison, r0) | 1335 .CompareOperation(comparison, r0) |
1356 .Return(); | 1336 .Return(); |
1357 | 1337 |
1358 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1338 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1359 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1339 InterpreterTester tester(isolate, bytecode_array); |
1360 auto callable = tester.GetCallable<>(); | 1340 auto callable = tester.GetCallable<>(); |
1361 Handle<Object> return_value = callable().ToHandleChecked(); | 1341 Handle<Object> return_value = callable().ToHandleChecked(); |
1362 CHECK(return_value->IsBoolean()); | 1342 CHECK(return_value->IsBoolean()); |
1363 CHECK_EQ(return_value->BooleanValue(), | 1343 CHECK_EQ(return_value->BooleanValue(), |
1364 CompareC(comparison, inputs[i], inputs[j])); | 1344 CompareC(comparison, inputs[i], inputs[j])); |
1365 } | 1345 } |
1366 } | 1346 } |
1367 } | 1347 } |
1368 } | 1348 } |
1369 | 1349 |
1370 | 1350 |
1371 TEST(InterpreterStringComparisons) { | 1351 TEST(InterpreterStringComparisons) { |
1372 HandleAndZoneScope handles; | 1352 HandleAndZoneScope handles; |
1373 i::Isolate* isolate = handles.main_isolate(); | 1353 Isolate* isolate = handles.main_isolate(); |
1374 i::Factory* factory = isolate->factory(); | 1354 Factory* factory = isolate->factory(); |
1375 | 1355 |
1376 std::string inputs[] = {"A", "abc", "z", "", "Foo!", "Foo"}; | 1356 std::string inputs[] = {"A", "abc", "z", "", "Foo!", "Foo"}; |
1377 | 1357 |
1378 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1358 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1379 Token::Value comparison = kComparisonTypes[c]; | 1359 Token::Value comparison = kComparisonTypes[c]; |
1380 for (size_t i = 0; i < arraysize(inputs); i++) { | 1360 for (size_t i = 0; i < arraysize(inputs); i++) { |
1381 for (size_t j = 0; j < arraysize(inputs); j++) { | 1361 for (size_t j = 0; j < arraysize(inputs); j++) { |
1382 CanonicalHandleScope canonical(isolate); | 1362 CanonicalHandleScope canonical(isolate); |
1383 const char* lhs = inputs[i].c_str(); | 1363 const char* lhs = inputs[i].c_str(); |
1384 const char* rhs = inputs[j].c_str(); | 1364 const char* rhs = inputs[j].c_str(); |
1385 BytecodeArrayBuilder builder(handles.main_isolate(), | 1365 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1386 handles.main_zone(), 0, 0, 1); | |
1387 Register r0(0); | 1366 Register r0(0); |
1388 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) | 1367 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) |
1389 .StoreAccumulatorInRegister(r0) | 1368 .StoreAccumulatorInRegister(r0) |
1390 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) | 1369 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) |
1391 .CompareOperation(comparison, r0) | 1370 .CompareOperation(comparison, r0) |
1392 .Return(); | 1371 .Return(); |
1393 | 1372 |
1394 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1373 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1395 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1374 InterpreterTester tester(isolate, bytecode_array); |
1396 auto callable = tester.GetCallable<>(); | 1375 auto callable = tester.GetCallable<>(); |
1397 Handle<Object> return_value = callable().ToHandleChecked(); | 1376 Handle<Object> return_value = callable().ToHandleChecked(); |
1398 CHECK(return_value->IsBoolean()); | 1377 CHECK(return_value->IsBoolean()); |
1399 CHECK_EQ(return_value->BooleanValue(), | 1378 CHECK_EQ(return_value->BooleanValue(), |
1400 CompareC(comparison, inputs[i], inputs[j])); | 1379 CompareC(comparison, inputs[i], inputs[j])); |
1401 } | 1380 } |
1402 } | 1381 } |
1403 } | 1382 } |
1404 } | 1383 } |
1405 | 1384 |
1406 | 1385 |
1407 TEST(InterpreterMixedComparisons) { | 1386 TEST(InterpreterMixedComparisons) { |
1408 // This test compares a HeapNumber with a String. The latter is | 1387 // This test compares a HeapNumber with a String. The latter is |
1409 // convertible to a HeapNumber so comparison will be between numeric | 1388 // convertible to a HeapNumber so comparison will be between numeric |
1410 // values except for the strict comparisons where no conversion is | 1389 // values except for the strict comparisons where no conversion is |
1411 // performed. | 1390 // performed. |
1412 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; | 1391 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; |
1413 | 1392 |
1414 i::UnicodeCache unicode_cache; | 1393 UnicodeCache unicode_cache; |
1415 | 1394 |
1416 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1395 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1417 Token::Value comparison = kComparisonTypes[c]; | 1396 Token::Value comparison = kComparisonTypes[c]; |
1418 for (size_t i = 0; i < arraysize(inputs); i++) { | 1397 for (size_t i = 0; i < arraysize(inputs); i++) { |
1419 for (size_t j = 0; j < arraysize(inputs); j++) { | 1398 for (size_t j = 0; j < arraysize(inputs); j++) { |
1420 for (int pass = 0; pass < 2; pass++) { | 1399 for (int pass = 0; pass < 2; pass++) { |
1421 const char* lhs_cstr = inputs[i]; | 1400 const char* lhs_cstr = inputs[i]; |
1422 const char* rhs_cstr = inputs[j]; | 1401 const char* rhs_cstr = inputs[j]; |
1423 double lhs = StringToDouble(&unicode_cache, lhs_cstr, | 1402 double lhs = StringToDouble(&unicode_cache, lhs_cstr, |
1424 i::ConversionFlags::NO_FLAGS); | 1403 ConversionFlags::NO_FLAGS); |
1425 double rhs = StringToDouble(&unicode_cache, rhs_cstr, | 1404 double rhs = StringToDouble(&unicode_cache, rhs_cstr, |
1426 i::ConversionFlags::NO_FLAGS); | 1405 ConversionFlags::NO_FLAGS); |
1427 HandleAndZoneScope handles; | 1406 HandleAndZoneScope handles; |
1428 i::Factory* factory = handles.main_isolate()->factory(); | 1407 Isolate* isolate = handles.main_isolate(); |
1429 BytecodeArrayBuilder builder(handles.main_isolate(), | 1408 Factory* factory = isolate->factory(); |
1430 handles.main_zone(), 0, 0, 1); | 1409 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1431 | 1410 |
1432 Register r0(0); | 1411 Register r0(0); |
1433 if (pass == 0) { | 1412 if (pass == 0) { |
1434 // Comparison with HeapNumber on the lhs and String on the rhs | 1413 // Comparison with HeapNumber on the lhs and String on the rhs |
1435 builder.LoadLiteral(factory->NewNumber(lhs)) | 1414 builder.LoadLiteral(factory->NewNumber(lhs)) |
1436 .StoreAccumulatorInRegister(r0) | 1415 .StoreAccumulatorInRegister(r0) |
1437 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) | 1416 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) |
1438 .CompareOperation(comparison, r0) | 1417 .CompareOperation(comparison, r0) |
1439 .Return(); | 1418 .Return(); |
1440 } else { | 1419 } else { |
1441 // Comparison with HeapNumber on the rhs and String on the lhs | 1420 // Comparison with HeapNumber on the rhs and String on the lhs |
1442 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs_cstr)) | 1421 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs_cstr)) |
1443 .StoreAccumulatorInRegister(r0) | 1422 .StoreAccumulatorInRegister(r0) |
1444 .LoadLiteral(factory->NewNumber(rhs)) | 1423 .LoadLiteral(factory->NewNumber(rhs)) |
1445 .CompareOperation(comparison, r0) | 1424 .CompareOperation(comparison, r0) |
1446 .Return(); | 1425 .Return(); |
1447 } | 1426 } |
1448 | 1427 |
1449 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1428 Handle<BytecodeArray> bytecode_array = |
1450 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1429 builder.ToBytecodeArray(isolate); |
| 1430 InterpreterTester tester(isolate, bytecode_array); |
1451 auto callable = tester.GetCallable<>(); | 1431 auto callable = tester.GetCallable<>(); |
1452 Handle<Object> return_value = callable().ToHandleChecked(); | 1432 Handle<Object> return_value = callable().ToHandleChecked(); |
1453 CHECK(return_value->IsBoolean()); | 1433 CHECK(return_value->IsBoolean()); |
1454 CHECK_EQ(return_value->BooleanValue(), | 1434 CHECK_EQ(return_value->BooleanValue(), |
1455 CompareC(comparison, lhs, rhs, true)); | 1435 CompareC(comparison, lhs, rhs, true)); |
1456 } | 1436 } |
1457 } | 1437 } |
1458 } | 1438 } |
1459 } | 1439 } |
1460 } | 1440 } |
1461 | 1441 |
1462 TEST(InterpreterStrictNotEqual) { | 1442 TEST(InterpreterStrictNotEqual) { |
1463 HandleAndZoneScope handles; | 1443 HandleAndZoneScope handles; |
1464 i::Factory* factory = handles.main_isolate()->factory(); | 1444 Isolate* isolate = handles.main_isolate(); |
| 1445 Factory* factory = isolate->factory(); |
1465 const char* code_snippet = | 1446 const char* code_snippet = |
1466 "function f(lhs, rhs) {\n" | 1447 "function f(lhs, rhs) {\n" |
1467 " return lhs !== rhs;\n" | 1448 " return lhs !== rhs;\n" |
1468 "}\n" | 1449 "}\n" |
1469 "f(0, 0);\n"; | 1450 "f(0, 0);\n"; |
1470 InterpreterTester tester(handles.main_isolate(), code_snippet); | 1451 InterpreterTester tester(isolate, code_snippet); |
1471 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 1452 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
1472 | 1453 |
1473 // Test passing different types. | 1454 // Test passing different types. |
1474 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; | 1455 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; |
1475 i::UnicodeCache unicode_cache; | 1456 UnicodeCache unicode_cache; |
1476 for (size_t i = 0; i < arraysize(inputs); i++) { | 1457 for (size_t i = 0; i < arraysize(inputs); i++) { |
1477 for (size_t j = 0; j < arraysize(inputs); j++) { | 1458 for (size_t j = 0; j < arraysize(inputs); j++) { |
1478 double lhs = StringToDouble(&unicode_cache, inputs[i], | 1459 double lhs = |
1479 i::ConversionFlags::NO_FLAGS); | 1460 StringToDouble(&unicode_cache, inputs[i], ConversionFlags::NO_FLAGS); |
1480 double rhs = StringToDouble(&unicode_cache, inputs[j], | 1461 double rhs = |
1481 i::ConversionFlags::NO_FLAGS); | 1462 StringToDouble(&unicode_cache, inputs[j], ConversionFlags::NO_FLAGS); |
1482 Handle<Object> lhs_obj = factory->NewNumber(lhs); | 1463 Handle<Object> lhs_obj = factory->NewNumber(lhs); |
1483 Handle<Object> rhs_obj = factory->NewStringFromAsciiChecked(inputs[j]); | 1464 Handle<Object> rhs_obj = factory->NewStringFromAsciiChecked(inputs[j]); |
1484 | 1465 |
1485 Handle<Object> return_value = | 1466 Handle<Object> return_value = |
1486 callable(lhs_obj, rhs_obj).ToHandleChecked(); | 1467 callable(lhs_obj, rhs_obj).ToHandleChecked(); |
1487 CHECK(return_value->IsBoolean()); | 1468 CHECK(return_value->IsBoolean()); |
1488 CHECK_EQ(return_value->BooleanValue(), | 1469 CHECK_EQ(return_value->BooleanValue(), |
1489 CompareC(Token::Value::NE_STRICT, lhs, rhs, true)); | 1470 CompareC(Token::Value::NE_STRICT, lhs, rhs, true)); |
1490 } | 1471 } |
1491 } | 1472 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 CHECK(return_value->IsBoolean()); | 1506 CHECK(return_value->IsBoolean()); |
1526 CHECK_EQ(return_value->BooleanValue(), | 1507 CHECK_EQ(return_value->BooleanValue(), |
1527 CompareC(Token::Value::NE_STRICT, inputs_number[i], | 1508 CompareC(Token::Value::NE_STRICT, inputs_number[i], |
1528 inputs_number[j])); | 1509 inputs_number[j])); |
1529 } | 1510 } |
1530 } | 1511 } |
1531 } | 1512 } |
1532 | 1513 |
1533 TEST(InterpreterInstanceOf) { | 1514 TEST(InterpreterInstanceOf) { |
1534 HandleAndZoneScope handles; | 1515 HandleAndZoneScope handles; |
1535 i::Factory* factory = handles.main_isolate()->factory(); | 1516 Isolate* isolate = handles.main_isolate(); |
| 1517 Factory* factory = isolate->factory(); |
1536 Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); | 1518 Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); |
1537 Handle<i::JSFunction> func = factory->NewFunction(name); | 1519 Handle<i::JSFunction> func = factory->NewFunction(name); |
1538 Handle<i::JSObject> instance = factory->NewJSObject(func); | 1520 Handle<i::JSObject> instance = factory->NewJSObject(func); |
1539 Handle<i::Object> other = factory->NewNumber(3.3333); | 1521 Handle<i::Object> other = factory->NewNumber(3.3333); |
1540 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; | 1522 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; |
1541 for (size_t i = 0; i < arraysize(cases); i++) { | 1523 for (size_t i = 0; i < arraysize(cases); i++) { |
1542 bool expected_value = (i == 0); | 1524 bool expected_value = (i == 0); |
1543 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1525 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1544 0, 1); | |
1545 | 1526 |
1546 Register r0(0); | 1527 Register r0(0); |
1547 builder.LoadLiteral(cases[i]); | 1528 builder.LoadLiteral(cases[i]); |
1548 builder.StoreAccumulatorInRegister(r0) | 1529 builder.StoreAccumulatorInRegister(r0) |
1549 .LoadLiteral(func) | 1530 .LoadLiteral(func) |
1550 .CompareOperation(Token::Value::INSTANCEOF, r0) | 1531 .CompareOperation(Token::Value::INSTANCEOF, r0) |
1551 .Return(); | 1532 .Return(); |
1552 | 1533 |
1553 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1534 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1554 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1535 InterpreterTester tester(isolate, bytecode_array); |
1555 auto callable = tester.GetCallable<>(); | 1536 auto callable = tester.GetCallable<>(); |
1556 Handle<Object> return_value = callable().ToHandleChecked(); | 1537 Handle<Object> return_value = callable().ToHandleChecked(); |
1557 CHECK(return_value->IsBoolean()); | 1538 CHECK(return_value->IsBoolean()); |
1558 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1539 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1559 } | 1540 } |
1560 } | 1541 } |
1561 | 1542 |
1562 | 1543 |
1563 TEST(InterpreterTestIn) { | 1544 TEST(InterpreterTestIn) { |
1564 HandleAndZoneScope handles; | 1545 HandleAndZoneScope handles; |
1565 i::Factory* factory = handles.main_isolate()->factory(); | 1546 Isolate* isolate = handles.main_isolate(); |
| 1547 Factory* factory = isolate->factory(); |
1566 // Allocate an array | 1548 // Allocate an array |
1567 Handle<i::JSArray> array = | 1549 Handle<i::JSArray> array = |
1568 factory->NewJSArray(0, i::ElementsKind::FAST_SMI_ELEMENTS); | 1550 factory->NewJSArray(0, i::ElementsKind::FAST_SMI_ELEMENTS); |
1569 // Check for these properties on the array object | 1551 // Check for these properties on the array object |
1570 const char* properties[] = {"length", "fuzzle", "x", "0"}; | 1552 const char* properties[] = {"length", "fuzzle", "x", "0"}; |
1571 for (size_t i = 0; i < arraysize(properties); i++) { | 1553 for (size_t i = 0; i < arraysize(properties); i++) { |
1572 bool expected_value = (i == 0); | 1554 bool expected_value = (i == 0); |
1573 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1555 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1574 0, 1); | |
1575 | 1556 |
1576 Register r0(0); | 1557 Register r0(0); |
1577 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) | 1558 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) |
1578 .StoreAccumulatorInRegister(r0) | 1559 .StoreAccumulatorInRegister(r0) |
1579 .LoadLiteral(Handle<Object>::cast(array)) | 1560 .LoadLiteral(Handle<Object>::cast(array)) |
1580 .CompareOperation(Token::Value::IN, r0) | 1561 .CompareOperation(Token::Value::IN, r0) |
1581 .Return(); | 1562 .Return(); |
1582 | 1563 |
1583 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1564 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1584 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1565 InterpreterTester tester(isolate, bytecode_array); |
1585 auto callable = tester.GetCallable<>(); | 1566 auto callable = tester.GetCallable<>(); |
1586 Handle<Object> return_value = callable().ToHandleChecked(); | 1567 Handle<Object> return_value = callable().ToHandleChecked(); |
1587 CHECK(return_value->IsBoolean()); | 1568 CHECK(return_value->IsBoolean()); |
1588 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1569 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1589 } | 1570 } |
1590 } | 1571 } |
1591 | 1572 |
1592 | 1573 |
1593 TEST(InterpreterUnaryNot) { | 1574 TEST(InterpreterUnaryNot) { |
1594 HandleAndZoneScope handles; | 1575 HandleAndZoneScope handles; |
| 1576 Isolate* isolate = handles.main_isolate(); |
1595 for (size_t i = 1; i < 10; i++) { | 1577 for (size_t i = 1; i < 10; i++) { |
1596 bool expected_value = ((i & 1) == 1); | 1578 bool expected_value = ((i & 1) == 1); |
1597 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1579 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 0); |
1598 0, 0); | |
1599 | 1580 |
1600 Register r0(0); | 1581 Register r0(0); |
1601 builder.LoadFalse(); | 1582 builder.LoadFalse(); |
1602 for (size_t j = 0; j < i; j++) { | 1583 for (size_t j = 0; j < i; j++) { |
1603 builder.LogicalNot(); | 1584 builder.LogicalNot(); |
1604 } | 1585 } |
1605 builder.Return(); | 1586 builder.Return(); |
1606 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1587 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1607 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1588 InterpreterTester tester(isolate, bytecode_array); |
1608 auto callable = tester.GetCallable<>(); | 1589 auto callable = tester.GetCallable<>(); |
1609 Handle<Object> return_value = callable().ToHandleChecked(); | 1590 Handle<Object> return_value = callable().ToHandleChecked(); |
1610 CHECK(return_value->IsBoolean()); | 1591 CHECK(return_value->IsBoolean()); |
1611 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1592 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1612 } | 1593 } |
1613 } | 1594 } |
1614 | 1595 |
1615 | 1596 |
1616 static void LoadAny(BytecodeArrayBuilder* builder, | 1597 static void LoadAny(BytecodeArrayBuilder* builder, |
1617 v8::internal::Factory* factory, Handle<Object> obj) { | 1598 v8::internal::Factory* factory, Handle<Object> obj) { |
(...skipping 14 matching lines...) Expand all Loading... |
1632 } else if (obj->IsSmi()) { | 1613 } else if (obj->IsSmi()) { |
1633 builder->LoadLiteral(*Handle<Smi>::cast(obj)); | 1614 builder->LoadLiteral(*Handle<Smi>::cast(obj)); |
1634 } else { | 1615 } else { |
1635 builder->LoadLiteral(obj); | 1616 builder->LoadLiteral(obj); |
1636 } | 1617 } |
1637 } | 1618 } |
1638 | 1619 |
1639 | 1620 |
1640 TEST(InterpreterUnaryNotNonBoolean) { | 1621 TEST(InterpreterUnaryNotNonBoolean) { |
1641 HandleAndZoneScope handles; | 1622 HandleAndZoneScope handles; |
1642 i::Factory* factory = handles.main_isolate()->factory(); | 1623 Isolate* isolate = handles.main_isolate(); |
| 1624 Factory* factory = isolate->factory(); |
1643 | 1625 |
1644 std::pair<Handle<Object>, bool> object_type_tuples[] = { | 1626 std::pair<Handle<Object>, bool> object_type_tuples[] = { |
1645 std::make_pair(factory->undefined_value(), true), | 1627 std::make_pair(factory->undefined_value(), true), |
1646 std::make_pair(factory->null_value(), true), | 1628 std::make_pair(factory->null_value(), true), |
1647 std::make_pair(factory->false_value(), true), | 1629 std::make_pair(factory->false_value(), true), |
1648 std::make_pair(factory->true_value(), false), | 1630 std::make_pair(factory->true_value(), false), |
1649 std::make_pair(factory->NewNumber(9.1), false), | 1631 std::make_pair(factory->NewNumber(9.1), false), |
1650 std::make_pair(factory->NewNumberFromInt(0), true), | 1632 std::make_pair(factory->NewNumberFromInt(0), true), |
1651 std::make_pair( | 1633 std::make_pair( |
1652 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), | 1634 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), |
1653 false), | 1635 false), |
1654 std::make_pair( | 1636 std::make_pair( |
1655 Handle<Object>::cast(factory->NewStringFromStaticChars("")), true), | 1637 Handle<Object>::cast(factory->NewStringFromStaticChars("")), true), |
1656 }; | 1638 }; |
1657 | 1639 |
1658 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { | 1640 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { |
1659 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1641 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 0); |
1660 0, 0); | |
1661 | 1642 |
1662 Register r0(0); | 1643 Register r0(0); |
1663 LoadAny(&builder, factory, object_type_tuples[i].first); | 1644 LoadAny(&builder, factory, object_type_tuples[i].first); |
1664 builder.LogicalNot(); | 1645 builder.LogicalNot(); |
1665 builder.Return(); | 1646 builder.Return(); |
1666 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1647 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1667 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1648 InterpreterTester tester(isolate, bytecode_array); |
1668 auto callable = tester.GetCallable<>(); | 1649 auto callable = tester.GetCallable<>(); |
1669 Handle<Object> return_value = callable().ToHandleChecked(); | 1650 Handle<Object> return_value = callable().ToHandleChecked(); |
1670 CHECK(return_value->IsBoolean()); | 1651 CHECK(return_value->IsBoolean()); |
1671 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); | 1652 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); |
1672 } | 1653 } |
1673 } | 1654 } |
1674 | 1655 |
1675 | 1656 |
1676 TEST(InterpreterTypeof) { | 1657 TEST(InterpreterTypeof) { |
1677 HandleAndZoneScope handles; | 1658 HandleAndZoneScope handles; |
| 1659 Isolate* isolate = handles.main_isolate(); |
1678 | 1660 |
1679 std::pair<const char*, const char*> typeof_vals[] = { | 1661 std::pair<const char*, const char*> typeof_vals[] = { |
1680 std::make_pair("return typeof undefined;", "undefined"), | 1662 std::make_pair("return typeof undefined;", "undefined"), |
1681 std::make_pair("return typeof null;", "object"), | 1663 std::make_pair("return typeof null;", "object"), |
1682 std::make_pair("return typeof true;", "boolean"), | 1664 std::make_pair("return typeof true;", "boolean"), |
1683 std::make_pair("return typeof false;", "boolean"), | 1665 std::make_pair("return typeof false;", "boolean"), |
1684 std::make_pair("return typeof 9.1;", "number"), | 1666 std::make_pair("return typeof 9.1;", "number"), |
1685 std::make_pair("return typeof 7771;", "number"), | 1667 std::make_pair("return typeof 7771;", "number"), |
1686 std::make_pair("return typeof 'hello';", "string"), | 1668 std::make_pair("return typeof 'hello';", "string"), |
1687 std::make_pair("return typeof global_unallocated;", "undefined"), | 1669 std::make_pair("return typeof global_unallocated;", "undefined"), |
1688 }; | 1670 }; |
1689 | 1671 |
1690 for (size_t i = 0; i < arraysize(typeof_vals); i++) { | 1672 for (size_t i = 0; i < arraysize(typeof_vals); i++) { |
1691 std::string source(InterpreterTester::SourceForBody(typeof_vals[i].first)); | 1673 std::string source(InterpreterTester::SourceForBody(typeof_vals[i].first)); |
1692 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1674 InterpreterTester tester(isolate, source.c_str()); |
1693 | 1675 |
1694 auto callable = tester.GetCallable<>(); | 1676 auto callable = tester.GetCallable<>(); |
1695 Handle<v8::internal::String> return_value = | 1677 Handle<v8::internal::String> return_value = |
1696 Handle<v8::internal::String>::cast(callable().ToHandleChecked()); | 1678 Handle<v8::internal::String>::cast(callable().ToHandleChecked()); |
1697 auto actual = return_value->ToCString(); | 1679 auto actual = return_value->ToCString(); |
1698 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0); | 1680 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0); |
1699 } | 1681 } |
1700 } | 1682 } |
1701 | 1683 |
1702 | 1684 |
1703 TEST(InterpreterCallRuntime) { | 1685 TEST(InterpreterCallRuntime) { |
1704 HandleAndZoneScope handles; | 1686 HandleAndZoneScope handles; |
| 1687 Isolate* isolate = handles.main_isolate(); |
1705 | 1688 |
1706 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1689 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 2); |
1707 0, 2); | |
1708 | 1690 |
1709 builder.LoadLiteral(Smi::FromInt(15)) | 1691 builder.LoadLiteral(Smi::FromInt(15)) |
1710 .StoreAccumulatorInRegister(Register(0)) | 1692 .StoreAccumulatorInRegister(Register(0)) |
1711 .LoadLiteral(Smi::FromInt(40)) | 1693 .LoadLiteral(Smi::FromInt(40)) |
1712 .StoreAccumulatorInRegister(Register(1)) | 1694 .StoreAccumulatorInRegister(Register(1)) |
1713 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1695 .CallRuntime(Runtime::kAdd, Register(0), 2) |
1714 .Return(); | 1696 .Return(); |
1715 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1697 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1716 | 1698 |
1717 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1699 InterpreterTester tester(isolate, bytecode_array); |
1718 auto callable = tester.GetCallable<>(); | 1700 auto callable = tester.GetCallable<>(); |
1719 | 1701 |
1720 Handle<Object> return_val = callable().ToHandleChecked(); | 1702 Handle<Object> return_val = callable().ToHandleChecked(); |
1721 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1703 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
1722 } | 1704 } |
1723 | 1705 |
1724 TEST(InterpreterInvokeIntrinsic) { | 1706 TEST(InterpreterInvokeIntrinsic) { |
1725 HandleAndZoneScope handles; | 1707 HandleAndZoneScope handles; |
| 1708 Isolate* isolate = handles.main_isolate(); |
1726 | 1709 |
1727 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1710 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 2); |
1728 0, 2); | |
1729 | 1711 |
1730 builder.LoadLiteral(Smi::FromInt(15)) | 1712 builder.LoadLiteral(Smi::FromInt(15)) |
1731 .StoreAccumulatorInRegister(Register(0)) | 1713 .StoreAccumulatorInRegister(Register(0)) |
1732 .CallRuntime(Runtime::kInlineIsArray, Register(0), 1) | 1714 .CallRuntime(Runtime::kInlineIsArray, Register(0), 1) |
1733 .Return(); | 1715 .Return(); |
1734 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1716 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1735 | 1717 |
1736 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1718 InterpreterTester tester(isolate, bytecode_array); |
1737 auto callable = tester.GetCallable<>(); | 1719 auto callable = tester.GetCallable<>(); |
1738 | 1720 |
1739 Handle<Object> return_val = callable().ToHandleChecked(); | 1721 Handle<Object> return_val = callable().ToHandleChecked(); |
1740 CHECK(return_val->IsBoolean()); | 1722 CHECK(return_val->IsBoolean()); |
1741 CHECK_EQ(return_val->BooleanValue(), false); | 1723 CHECK_EQ(return_val->BooleanValue(), false); |
1742 } | 1724 } |
1743 | 1725 |
1744 TEST(InterpreterFunctionLiteral) { | 1726 TEST(InterpreterFunctionLiteral) { |
1745 HandleAndZoneScope handles; | 1727 HandleAndZoneScope handles; |
| 1728 Isolate* isolate = handles.main_isolate(); |
1746 | 1729 |
1747 // Test calling a function literal. | 1730 // Test calling a function literal. |
1748 std::string source( | 1731 std::string source( |
1749 "function " + InterpreterTester::function_name() + "(a) {\n" | 1732 "function " + InterpreterTester::function_name() + "(a) {\n" |
1750 " return (function(x){ return x + 2; })(a);\n" | 1733 " return (function(x){ return x + 2; })(a);\n" |
1751 "}"); | 1734 "}"); |
1752 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1735 InterpreterTester tester(isolate, source.c_str()); |
1753 auto callable = tester.GetCallable<Handle<Object>>(); | 1736 auto callable = tester.GetCallable<Handle<Object>>(); |
1754 | 1737 |
1755 Handle<i::Object> return_val = callable( | 1738 Handle<i::Object> return_val = callable( |
1756 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); | 1739 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); |
1757 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); | 1740 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
1758 } | 1741 } |
1759 | 1742 |
1760 | 1743 |
1761 TEST(InterpreterRegExpLiterals) { | 1744 TEST(InterpreterRegExpLiterals) { |
1762 HandleAndZoneScope handles; | 1745 HandleAndZoneScope handles; |
1763 i::Isolate* isolate = handles.main_isolate(); | 1746 Isolate* isolate = handles.main_isolate(); |
1764 i::Factory* factory = isolate->factory(); | 1747 Factory* factory = isolate->factory(); |
1765 | 1748 |
1766 std::pair<const char*, Handle<Object>> literals[] = { | 1749 std::pair<const char*, Handle<Object>> literals[] = { |
1767 std::make_pair("return /abd/.exec('cccabbdd');\n", | 1750 std::make_pair("return /abd/.exec('cccabbdd');\n", |
1768 factory->null_value()), | 1751 factory->null_value()), |
1769 std::make_pair("return /ab+d/.exec('cccabbdd')[0];\n", | 1752 std::make_pair("return /ab+d/.exec('cccabbdd')[0];\n", |
1770 factory->NewStringFromStaticChars("abbd")), | 1753 factory->NewStringFromStaticChars("abbd")), |
1771 std::make_pair("return /AbC/i.exec('ssaBC')[0];\n", | 1754 std::make_pair("return /AbC/i.exec('ssaBC')[0];\n", |
1772 factory->NewStringFromStaticChars("aBC")), | 1755 factory->NewStringFromStaticChars("aBC")), |
1773 std::make_pair("return 'ssaBC'.match(/AbC/i)[0];\n", | 1756 std::make_pair("return 'ssaBC'.match(/AbC/i)[0];\n", |
1774 factory->NewStringFromStaticChars("aBC")), | 1757 factory->NewStringFromStaticChars("aBC")), |
1775 std::make_pair("return 'ssaBCtAbC'.match(/(AbC)/gi)[1];\n", | 1758 std::make_pair("return 'ssaBCtAbC'.match(/(AbC)/gi)[1];\n", |
1776 factory->NewStringFromStaticChars("AbC")), | 1759 factory->NewStringFromStaticChars("AbC")), |
1777 }; | 1760 }; |
1778 | 1761 |
1779 for (size_t i = 0; i < arraysize(literals); i++) { | 1762 for (size_t i = 0; i < arraysize(literals); i++) { |
1780 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1763 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1781 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1764 InterpreterTester tester(isolate, source.c_str()); |
1782 auto callable = tester.GetCallable<>(); | 1765 auto callable = tester.GetCallable<>(); |
1783 | 1766 |
1784 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1767 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1785 CHECK(return_value->SameValue(*literals[i].second)); | 1768 CHECK(return_value->SameValue(*literals[i].second)); |
1786 } | 1769 } |
1787 } | 1770 } |
1788 | 1771 |
1789 | 1772 |
1790 TEST(InterpreterArrayLiterals) { | 1773 TEST(InterpreterArrayLiterals) { |
1791 HandleAndZoneScope handles; | 1774 HandleAndZoneScope handles; |
1792 i::Isolate* isolate = handles.main_isolate(); | 1775 Isolate* isolate = handles.main_isolate(); |
1793 i::Factory* factory = isolate->factory(); | 1776 Factory* factory = isolate->factory(); |
1794 | 1777 |
1795 std::pair<const char*, Handle<Object>> literals[] = { | 1778 std::pair<const char*, Handle<Object>> literals[] = { |
1796 std::make_pair("return [][0];\n", | 1779 std::make_pair("return [][0];\n", |
1797 factory->undefined_value()), | 1780 factory->undefined_value()), |
1798 std::make_pair("return [1, 3, 2][1];\n", | 1781 std::make_pair("return [1, 3, 2][1];\n", |
1799 handle(Smi::FromInt(3), isolate)), | 1782 handle(Smi::FromInt(3), isolate)), |
1800 std::make_pair("return ['a', 'b', 'c'][2];\n", | 1783 std::make_pair("return ['a', 'b', 'c'][2];\n", |
1801 factory->NewStringFromStaticChars("c")), | 1784 factory->NewStringFromStaticChars("c")), |
1802 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n", | 1785 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n", |
1803 handle(Smi::FromInt(102), isolate)), | 1786 handle(Smi::FromInt(102), isolate)), |
1804 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n", | 1787 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n", |
1805 factory->NewStringFromStaticChars("a")), | 1788 factory->NewStringFromStaticChars("a")), |
1806 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n", | 1789 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n", |
1807 factory->NewStringFromStaticChars("test")) | 1790 factory->NewStringFromStaticChars("test")) |
1808 }; | 1791 }; |
1809 | 1792 |
1810 for (size_t i = 0; i < arraysize(literals); i++) { | 1793 for (size_t i = 0; i < arraysize(literals); i++) { |
1811 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1794 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1812 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1795 InterpreterTester tester(isolate, source.c_str()); |
1813 auto callable = tester.GetCallable<>(); | 1796 auto callable = tester.GetCallable<>(); |
1814 | 1797 |
1815 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1798 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1816 CHECK(return_value->SameValue(*literals[i].second)); | 1799 CHECK(return_value->SameValue(*literals[i].second)); |
1817 } | 1800 } |
1818 } | 1801 } |
1819 | 1802 |
1820 | 1803 |
1821 TEST(InterpreterObjectLiterals) { | 1804 TEST(InterpreterObjectLiterals) { |
1822 HandleAndZoneScope handles; | 1805 HandleAndZoneScope handles; |
1823 i::Isolate* isolate = handles.main_isolate(); | 1806 Isolate* isolate = handles.main_isolate(); |
1824 i::Factory* factory = isolate->factory(); | 1807 Factory* factory = isolate->factory(); |
1825 | 1808 |
1826 std::pair<const char*, Handle<Object>> literals[] = { | 1809 std::pair<const char*, Handle<Object>> literals[] = { |
1827 std::make_pair("return { }.name;", | 1810 std::make_pair("return { }.name;", |
1828 factory->undefined_value()), | 1811 factory->undefined_value()), |
1829 std::make_pair("return { name: 'string', val: 9.2 }.name;", | 1812 std::make_pair("return { name: 'string', val: 9.2 }.name;", |
1830 factory->NewStringFromStaticChars("string")), | 1813 factory->NewStringFromStaticChars("string")), |
1831 std::make_pair("var a = 15; return { name: 'string', val: a }.val;", | 1814 std::make_pair("var a = 15; return { name: 'string', val: a }.val;", |
1832 handle(Smi::FromInt(15), isolate)), | 1815 handle(Smi::FromInt(15), isolate)), |
1833 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;", | 1816 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;", |
1834 handle(Smi::FromInt(6), isolate)), | 1817 handle(Smi::FromInt(6), isolate)), |
(...skipping 20 matching lines...) Expand all Loading... |
1855 "var b = { [a]: 1, __proto__: { var : a } };\n" | 1838 "var b = { [a]: 1, __proto__: { var : a } };\n" |
1856 "return Object.getPrototypeOf(b).var", | 1839 "return Object.getPrototypeOf(b).var", |
1857 factory->NewStringFromStaticChars("proto_str")), | 1840 factory->NewStringFromStaticChars("proto_str")), |
1858 std::make_pair("var n = 'name';\n" | 1841 std::make_pair("var n = 'name';\n" |
1859 "return { [n]: 'val', get a() { return 987 } }['a'];", | 1842 "return { [n]: 'val', get a() { return 987 } }['a'];", |
1860 handle(Smi::FromInt(987), isolate)), | 1843 handle(Smi::FromInt(987), isolate)), |
1861 }; | 1844 }; |
1862 | 1845 |
1863 for (size_t i = 0; i < arraysize(literals); i++) { | 1846 for (size_t i = 0; i < arraysize(literals); i++) { |
1864 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1847 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1865 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1848 InterpreterTester tester(isolate, source.c_str()); |
1866 auto callable = tester.GetCallable<>(); | 1849 auto callable = tester.GetCallable<>(); |
1867 | 1850 |
1868 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1851 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1869 CHECK(return_value->SameValue(*literals[i].second)); | 1852 CHECK(return_value->SameValue(*literals[i].second)); |
1870 } | 1853 } |
1871 } | 1854 } |
1872 | 1855 |
1873 | 1856 |
1874 TEST(InterpreterConstruct) { | 1857 TEST(InterpreterConstruct) { |
1875 HandleAndZoneScope handles; | 1858 HandleAndZoneScope handles; |
| 1859 Isolate* isolate = handles.main_isolate(); |
1876 | 1860 |
1877 std::string source( | 1861 std::string source( |
1878 "function counter() { this.count = 0; }\n" | 1862 "function counter() { this.count = 0; }\n" |
1879 "function " + | 1863 "function " + |
1880 InterpreterTester::function_name() + | 1864 InterpreterTester::function_name() + |
1881 "() {\n" | 1865 "() {\n" |
1882 " var c = new counter();\n" | 1866 " var c = new counter();\n" |
1883 " return c.count;\n" | 1867 " return c.count;\n" |
1884 "}"); | 1868 "}"); |
1885 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1869 InterpreterTester tester(isolate, source.c_str()); |
1886 auto callable = tester.GetCallable<>(); | 1870 auto callable = tester.GetCallable<>(); |
1887 | 1871 |
1888 Handle<Object> return_val = callable().ToHandleChecked(); | 1872 Handle<Object> return_val = callable().ToHandleChecked(); |
1889 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); | 1873 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); |
1890 } | 1874 } |
1891 | 1875 |
1892 | 1876 |
1893 TEST(InterpreterConstructWithArgument) { | 1877 TEST(InterpreterConstructWithArgument) { |
1894 HandleAndZoneScope handles; | 1878 HandleAndZoneScope handles; |
| 1879 Isolate* isolate = handles.main_isolate(); |
1895 | 1880 |
1896 std::string source( | 1881 std::string source( |
1897 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" | 1882 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
1898 "function " + | 1883 "function " + |
1899 InterpreterTester::function_name() + | 1884 InterpreterTester::function_name() + |
1900 "() {\n" | 1885 "() {\n" |
1901 " var c = new counter(3);\n" | 1886 " var c = new counter(3);\n" |
1902 " return c.x;\n" | 1887 " return c.x;\n" |
1903 "}"); | 1888 "}"); |
1904 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1889 InterpreterTester tester(isolate, source.c_str()); |
1905 auto callable = tester.GetCallable<>(); | 1890 auto callable = tester.GetCallable<>(); |
1906 | 1891 |
1907 Handle<Object> return_val = callable().ToHandleChecked(); | 1892 Handle<Object> return_val = callable().ToHandleChecked(); |
1908 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 1893 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
1909 } | 1894 } |
1910 | 1895 |
1911 | 1896 |
1912 TEST(InterpreterConstructWithArguments) { | 1897 TEST(InterpreterConstructWithArguments) { |
1913 HandleAndZoneScope handles; | 1898 HandleAndZoneScope handles; |
| 1899 Isolate* isolate = handles.main_isolate(); |
1914 | 1900 |
1915 std::string source( | 1901 std::string source( |
1916 "function counter(arg0, arg1) {\n" | 1902 "function counter(arg0, arg1) {\n" |
1917 " this.count = 7; this.x = arg0; this.y = arg1;\n" | 1903 " this.count = 7; this.x = arg0; this.y = arg1;\n" |
1918 "}\n" | 1904 "}\n" |
1919 "function " + | 1905 "function " + |
1920 InterpreterTester::function_name() + | 1906 InterpreterTester::function_name() + |
1921 "() {\n" | 1907 "() {\n" |
1922 " var c = new counter(3, 5);\n" | 1908 " var c = new counter(3, 5);\n" |
1923 " return c.count + c.x + c.y;\n" | 1909 " return c.count + c.x + c.y;\n" |
1924 "}"); | 1910 "}"); |
1925 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1911 InterpreterTester tester(isolate, source.c_str()); |
1926 auto callable = tester.GetCallable<>(); | 1912 auto callable = tester.GetCallable<>(); |
1927 | 1913 |
1928 Handle<Object> return_val = callable().ToHandleChecked(); | 1914 Handle<Object> return_val = callable().ToHandleChecked(); |
1929 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); | 1915 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
1930 } | 1916 } |
1931 | 1917 |
1932 | 1918 |
1933 TEST(InterpreterContextVariables) { | 1919 TEST(InterpreterContextVariables) { |
1934 HandleAndZoneScope handles; | 1920 HandleAndZoneScope handles; |
1935 i::Isolate* isolate = handles.main_isolate(); | 1921 Isolate* isolate = handles.main_isolate(); |
1936 | 1922 |
1937 std::ostringstream unique_vars; | 1923 std::ostringstream unique_vars; |
1938 for (int i = 0; i < 250; i++) { | 1924 for (int i = 0; i < 250; i++) { |
1939 unique_vars << "var a" << i << " = 0;"; | 1925 unique_vars << "var a" << i << " = 0;"; |
1940 } | 1926 } |
1941 std::pair<std::string, Handle<Object>> context_vars[] = { | 1927 std::pair<std::string, Handle<Object>> context_vars[] = { |
1942 std::make_pair("var a; (function() { a = 1; })(); return a;", | 1928 std::make_pair("var a; (function() { a = 1; })(); return a;", |
1943 handle(Smi::FromInt(1), isolate)), | 1929 handle(Smi::FromInt(1), isolate)), |
1944 std::make_pair("var a = 10; (function() { a; })(); return a;", | 1930 std::make_pair("var a = 10; (function() { a; })(); return a;", |
1945 handle(Smi::FromInt(10), isolate)), | 1931 handle(Smi::FromInt(10), isolate)), |
1946 std::make_pair("var a = 20; var b = 30;\n" | 1932 std::make_pair("var a = 20; var b = 30;\n" |
1947 "return (function() { return a + b; })();", | 1933 "return (function() { return a + b; })();", |
1948 handle(Smi::FromInt(50), isolate)), | 1934 handle(Smi::FromInt(50), isolate)), |
1949 std::make_pair("'use strict'; let a = 1;\n" | 1935 std::make_pair("'use strict'; let a = 1;\n" |
1950 "{ let b = 2; return (function() { return a + b; })(); }", | 1936 "{ let b = 2; return (function() { return a + b; })(); }", |
1951 handle(Smi::FromInt(3), isolate)), | 1937 handle(Smi::FromInt(3), isolate)), |
1952 std::make_pair("'use strict'; let a = 10;\n" | 1938 std::make_pair("'use strict'; let a = 10;\n" |
1953 "{ let b = 20; var c = function() { [a, b] };\n" | 1939 "{ let b = 20; var c = function() { [a, b] };\n" |
1954 " return a + b; }", | 1940 " return a + b; }", |
1955 handle(Smi::FromInt(30), isolate)), | 1941 handle(Smi::FromInt(30), isolate)), |
1956 std::make_pair("'use strict';" + unique_vars.str() + | 1942 std::make_pair("'use strict';" + unique_vars.str() + |
1957 "eval(); var b = 100; return b;", | 1943 "eval(); var b = 100; return b;", |
1958 handle(Smi::FromInt(100), isolate)), | 1944 handle(Smi::FromInt(100), isolate)), |
1959 }; | 1945 }; |
1960 | 1946 |
1961 for (size_t i = 0; i < arraysize(context_vars); i++) { | 1947 for (size_t i = 0; i < arraysize(context_vars); i++) { |
1962 std::string source( | 1948 std::string source( |
1963 InterpreterTester::SourceForBody(context_vars[i].first.c_str())); | 1949 InterpreterTester::SourceForBody(context_vars[i].first.c_str())); |
1964 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1950 InterpreterTester tester(isolate, source.c_str()); |
1965 auto callable = tester.GetCallable<>(); | 1951 auto callable = tester.GetCallable<>(); |
1966 | 1952 |
1967 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1953 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1968 CHECK(return_value->SameValue(*context_vars[i].second)); | 1954 CHECK(return_value->SameValue(*context_vars[i].second)); |
1969 } | 1955 } |
1970 } | 1956 } |
1971 | 1957 |
1972 | 1958 |
1973 TEST(InterpreterContextParameters) { | 1959 TEST(InterpreterContextParameters) { |
1974 HandleAndZoneScope handles; | 1960 HandleAndZoneScope handles; |
1975 i::Isolate* isolate = handles.main_isolate(); | 1961 Isolate* isolate = handles.main_isolate(); |
1976 | 1962 |
1977 std::pair<const char*, Handle<Object>> context_params[] = { | 1963 std::pair<const char*, Handle<Object>> context_params[] = { |
1978 std::make_pair("return (function() { return arg1; })();", | 1964 std::make_pair("return (function() { return arg1; })();", |
1979 handle(Smi::FromInt(1), isolate)), | 1965 handle(Smi::FromInt(1), isolate)), |
1980 std::make_pair("(function() { arg1 = 4; })(); return arg1;", | 1966 std::make_pair("(function() { arg1 = 4; })(); return arg1;", |
1981 handle(Smi::FromInt(4), isolate)), | 1967 handle(Smi::FromInt(4), isolate)), |
1982 std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;", | 1968 std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;", |
1983 handle(Smi::FromInt(1), isolate)), | 1969 handle(Smi::FromInt(1), isolate)), |
1984 }; | 1970 }; |
1985 | 1971 |
1986 for (size_t i = 0; i < arraysize(context_params); i++) { | 1972 for (size_t i = 0; i < arraysize(context_params); i++) { |
1987 std::string source = "function " + InterpreterTester::function_name() + | 1973 std::string source = "function " + InterpreterTester::function_name() + |
1988 "(arg1, arg2, arg3) {" + context_params[i].first + "}"; | 1974 "(arg1, arg2, arg3) {" + context_params[i].first + "}"; |
1989 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1975 InterpreterTester tester(isolate, source.c_str()); |
1990 auto callable = | 1976 auto callable = |
1991 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 1977 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
1992 | 1978 |
1993 Handle<Object> a1 = handle(Smi::FromInt(1), isolate); | 1979 Handle<Object> a1 = handle(Smi::FromInt(1), isolate); |
1994 Handle<Object> a2 = handle(Smi::FromInt(2), isolate); | 1980 Handle<Object> a2 = handle(Smi::FromInt(2), isolate); |
1995 Handle<Object> a3 = handle(Smi::FromInt(3), isolate); | 1981 Handle<Object> a3 = handle(Smi::FromInt(3), isolate); |
1996 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); | 1982 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); |
1997 CHECK(return_value->SameValue(*context_params[i].second)); | 1983 CHECK(return_value->SameValue(*context_params[i].second)); |
1998 } | 1984 } |
1999 } | 1985 } |
2000 | 1986 |
2001 | 1987 |
2002 TEST(InterpreterOuterContextVariables) { | 1988 TEST(InterpreterOuterContextVariables) { |
2003 HandleAndZoneScope handles; | 1989 HandleAndZoneScope handles; |
2004 i::Isolate* isolate = handles.main_isolate(); | 1990 Isolate* isolate = handles.main_isolate(); |
2005 | 1991 |
2006 std::pair<const char*, Handle<Object>> context_vars[] = { | 1992 std::pair<const char*, Handle<Object>> context_vars[] = { |
2007 std::make_pair("return outerVar * innerArg;", | 1993 std::make_pair("return outerVar * innerArg;", |
2008 handle(Smi::FromInt(200), isolate)), | 1994 handle(Smi::FromInt(200), isolate)), |
2009 std::make_pair("outerVar = innerArg; return outerVar", | 1995 std::make_pair("outerVar = innerArg; return outerVar", |
2010 handle(Smi::FromInt(20), isolate)), | 1996 handle(Smi::FromInt(20), isolate)), |
2011 }; | 1997 }; |
2012 | 1998 |
2013 std::string header( | 1999 std::string header( |
2014 "function Outer() {" | 2000 "function Outer() {" |
2015 " var outerVar = 10;" | 2001 " var outerVar = 10;" |
2016 " function Inner(innerArg) {" | 2002 " function Inner(innerArg) {" |
2017 " this.innerFunc = function() { "); | 2003 " this.innerFunc = function() { "); |
2018 std::string footer( | 2004 std::string footer( |
2019 " }}" | 2005 " }}" |
2020 " this.getInnerFunc = function() { return new Inner(20).innerFunc; }" | 2006 " this.getInnerFunc = function() { return new Inner(20).innerFunc; }" |
2021 "}" | 2007 "}" |
2022 "var f = new Outer().getInnerFunc();"); | 2008 "var f = new Outer().getInnerFunc();"); |
2023 | 2009 |
2024 for (size_t i = 0; i < arraysize(context_vars); i++) { | 2010 for (size_t i = 0; i < arraysize(context_vars); i++) { |
2025 std::string source = header + context_vars[i].first + footer; | 2011 std::string source = header + context_vars[i].first + footer; |
2026 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 2012 InterpreterTester tester(isolate, source.c_str(), "*"); |
2027 auto callable = tester.GetCallable<>(); | 2013 auto callable = tester.GetCallable<>(); |
2028 | 2014 |
2029 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2015 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2030 CHECK(return_value->SameValue(*context_vars[i].second)); | 2016 CHECK(return_value->SameValue(*context_vars[i].second)); |
2031 } | 2017 } |
2032 } | 2018 } |
2033 | 2019 |
2034 | 2020 |
2035 TEST(InterpreterComma) { | 2021 TEST(InterpreterComma) { |
2036 HandleAndZoneScope handles; | 2022 HandleAndZoneScope handles; |
2037 i::Isolate* isolate = handles.main_isolate(); | 2023 Isolate* isolate = handles.main_isolate(); |
2038 i::Factory* factory = isolate->factory(); | 2024 Factory* factory = isolate->factory(); |
2039 | 2025 |
2040 std::pair<const char*, Handle<Object>> literals[] = { | 2026 std::pair<const char*, Handle<Object>> literals[] = { |
2041 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), | 2027 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), |
2042 std::make_pair("return 'a', 2.2, 3;\n", | 2028 std::make_pair("return 'a', 2.2, 3;\n", |
2043 handle(Smi::FromInt(3), isolate)), | 2029 handle(Smi::FromInt(3), isolate)), |
2044 std::make_pair("return 'a', 'b', 'c';\n", | 2030 std::make_pair("return 'a', 'b', 'c';\n", |
2045 factory->NewStringFromStaticChars("c")), | 2031 factory->NewStringFromStaticChars("c")), |
2046 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)), | 2032 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)), |
2047 std::make_pair("var a = 10; return b = a, b = b+1;\n", | 2033 std::make_pair("var a = 10; return b = a, b = b+1;\n", |
2048 handle(Smi::FromInt(11), isolate)), | 2034 handle(Smi::FromInt(11), isolate)), |
2049 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n", | 2035 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n", |
2050 handle(Smi::FromInt(21), isolate))}; | 2036 handle(Smi::FromInt(21), isolate))}; |
2051 | 2037 |
2052 for (size_t i = 0; i < arraysize(literals); i++) { | 2038 for (size_t i = 0; i < arraysize(literals); i++) { |
2053 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 2039 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
2054 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2040 InterpreterTester tester(isolate, source.c_str()); |
2055 auto callable = tester.GetCallable<>(); | 2041 auto callable = tester.GetCallable<>(); |
2056 | 2042 |
2057 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2043 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2058 CHECK(return_value->SameValue(*literals[i].second)); | 2044 CHECK(return_value->SameValue(*literals[i].second)); |
2059 } | 2045 } |
2060 } | 2046 } |
2061 | 2047 |
2062 | 2048 |
2063 TEST(InterpreterLogicalOr) { | 2049 TEST(InterpreterLogicalOr) { |
2064 HandleAndZoneScope handles; | 2050 HandleAndZoneScope handles; |
2065 i::Isolate* isolate = handles.main_isolate(); | 2051 Isolate* isolate = handles.main_isolate(); |
2066 i::Factory* factory = isolate->factory(); | 2052 Factory* factory = isolate->factory(); |
2067 | 2053 |
2068 std::pair<const char*, Handle<Object>> literals[] = { | 2054 std::pair<const char*, Handle<Object>> literals[] = { |
2069 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), | 2055 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), |
2070 std::make_pair("var a, b = 10; return a || b;\n", | 2056 std::make_pair("var a, b = 10; return a || b;\n", |
2071 handle(Smi::FromInt(10), isolate)), | 2057 handle(Smi::FromInt(10), isolate)), |
2072 std::make_pair("var a = '0', b = 10; return a || b;\n", | 2058 std::make_pair("var a = '0', b = 10; return a || b;\n", |
2073 factory->NewStringFromStaticChars("0")), | 2059 factory->NewStringFromStaticChars("0")), |
2074 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), | 2060 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), |
2075 std::make_pair("return 'a' || 0;\n", | 2061 std::make_pair("return 'a' || 0;\n", |
2076 factory->NewStringFromStaticChars("a")), | 2062 factory->NewStringFromStaticChars("a")), |
2077 std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n", | 2063 std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n", |
2078 factory->true_value())}; | 2064 factory->true_value())}; |
2079 | 2065 |
2080 for (size_t i = 0; i < arraysize(literals); i++) { | 2066 for (size_t i = 0; i < arraysize(literals); i++) { |
2081 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 2067 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
2082 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2068 InterpreterTester tester(isolate, source.c_str()); |
2083 auto callable = tester.GetCallable<>(); | 2069 auto callable = tester.GetCallable<>(); |
2084 | 2070 |
2085 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2071 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2086 CHECK(return_value->SameValue(*literals[i].second)); | 2072 CHECK(return_value->SameValue(*literals[i].second)); |
2087 } | 2073 } |
2088 } | 2074 } |
2089 | 2075 |
2090 | 2076 |
2091 TEST(InterpreterLogicalAnd) { | 2077 TEST(InterpreterLogicalAnd) { |
2092 HandleAndZoneScope handles; | 2078 HandleAndZoneScope handles; |
2093 i::Isolate* isolate = handles.main_isolate(); | 2079 Isolate* isolate = handles.main_isolate(); |
2094 i::Factory* factory = isolate->factory(); | 2080 Factory* factory = isolate->factory(); |
2095 | 2081 |
2096 std::pair<const char*, Handle<Object>> literals[] = { | 2082 std::pair<const char*, Handle<Object>> literals[] = { |
2097 std::make_pair("var a, b = 10; return a && b;\n", | 2083 std::make_pair("var a, b = 10; return a && b;\n", |
2098 factory->undefined_value()), | 2084 factory->undefined_value()), |
2099 std::make_pair("var a = 0, b = 10; return a && b / a;\n", | 2085 std::make_pair("var a = 0, b = 10; return a && b / a;\n", |
2100 handle(Smi::FromInt(0), isolate)), | 2086 handle(Smi::FromInt(0), isolate)), |
2101 std::make_pair("var a = '0', b = 10; return a && b;\n", | 2087 std::make_pair("var a = '0', b = 10; return a && b;\n", |
2102 handle(Smi::FromInt(10), isolate)), | 2088 handle(Smi::FromInt(10), isolate)), |
2103 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)), | 2089 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)), |
2104 std::make_pair("return 'a' && 'b';\n", | 2090 std::make_pair("return 'a' && 'b';\n", |
2105 factory->NewStringFromStaticChars("b")), | 2091 factory->NewStringFromStaticChars("b")), |
2106 std::make_pair("return 'a' && 0 || 'b', 'c';\n", | 2092 std::make_pair("return 'a' && 0 || 'b', 'c';\n", |
2107 factory->NewStringFromStaticChars("c")), | 2093 factory->NewStringFromStaticChars("c")), |
2108 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", | 2094 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", |
2109 handle(Smi::FromInt(1), isolate)), | 2095 handle(Smi::FromInt(1), isolate)), |
2110 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n", | 2096 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n", |
2111 factory->true_value())}; | 2097 factory->true_value())}; |
2112 | 2098 |
2113 for (size_t i = 0; i < arraysize(literals); i++) { | 2099 for (size_t i = 0; i < arraysize(literals); i++) { |
2114 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 2100 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
2115 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2101 InterpreterTester tester(isolate, source.c_str()); |
2116 auto callable = tester.GetCallable<>(); | 2102 auto callable = tester.GetCallable<>(); |
2117 | 2103 |
2118 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2104 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2119 CHECK(return_value->SameValue(*literals[i].second)); | 2105 CHECK(return_value->SameValue(*literals[i].second)); |
2120 } | 2106 } |
2121 } | 2107 } |
2122 | 2108 |
2123 | 2109 |
2124 TEST(InterpreterTryCatch) { | 2110 TEST(InterpreterTryCatch) { |
2125 HandleAndZoneScope handles; | 2111 HandleAndZoneScope handles; |
2126 i::Isolate* isolate = handles.main_isolate(); | 2112 Isolate* isolate = handles.main_isolate(); |
2127 | 2113 |
2128 std::pair<const char*, Handle<Object>> catches[] = { | 2114 std::pair<const char*, Handle<Object>> catches[] = { |
2129 std::make_pair("var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", | 2115 std::make_pair("var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", |
2130 handle(Smi::FromInt(2), isolate)), | 2116 handle(Smi::FromInt(2), isolate)), |
2131 std::make_pair("var a; try { undef.x } catch(e) { a = 2 }; return a;", | 2117 std::make_pair("var a; try { undef.x } catch(e) { a = 2 }; return a;", |
2132 handle(Smi::FromInt(2), isolate)), | 2118 handle(Smi::FromInt(2), isolate)), |
2133 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", | 2119 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", |
2134 handle(Smi::FromInt(3), isolate)), | 2120 handle(Smi::FromInt(3), isolate)), |
2135 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 };" | 2121 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 };" |
2136 " try { throw a } catch(e) { a = e + 3 }; return a;", | 2122 " try { throw a } catch(e) { a = e + 3 }; return a;", |
2137 handle(Smi::FromInt(6), isolate)), | 2123 handle(Smi::FromInt(6), isolate)), |
2138 }; | 2124 }; |
2139 | 2125 |
2140 for (size_t i = 0; i < arraysize(catches); i++) { | 2126 for (size_t i = 0; i < arraysize(catches); i++) { |
2141 std::string source(InterpreterTester::SourceForBody(catches[i].first)); | 2127 std::string source(InterpreterTester::SourceForBody(catches[i].first)); |
2142 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2128 InterpreterTester tester(isolate, source.c_str()); |
2143 auto callable = tester.GetCallable<>(); | 2129 auto callable = tester.GetCallable<>(); |
2144 | 2130 |
2145 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2131 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2146 CHECK(return_value->SameValue(*catches[i].second)); | 2132 CHECK(return_value->SameValue(*catches[i].second)); |
2147 } | 2133 } |
2148 } | 2134 } |
2149 | 2135 |
2150 | 2136 |
2151 TEST(InterpreterTryFinally) { | 2137 TEST(InterpreterTryFinally) { |
2152 HandleAndZoneScope handles; | 2138 HandleAndZoneScope handles; |
2153 i::Isolate* isolate = handles.main_isolate(); | 2139 Isolate* isolate = handles.main_isolate(); |
2154 i::Factory* factory = isolate->factory(); | 2140 Factory* factory = isolate->factory(); |
2155 | 2141 |
2156 std::pair<const char*, Handle<Object>> finallies[] = { | 2142 std::pair<const char*, Handle<Object>> finallies[] = { |
2157 std::make_pair( | 2143 std::make_pair( |
2158 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", | 2144 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", |
2159 factory->NewStringFromStaticChars("R4")), | 2145 factory->NewStringFromStaticChars("R4")), |
2160 std::make_pair( | 2146 std::make_pair( |
2161 "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", | 2147 "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", |
2162 factory->NewStringFromStaticChars("R23")), | 2148 factory->NewStringFromStaticChars("R23")), |
2163 std::make_pair( | 2149 std::make_pair( |
2164 "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", | 2150 "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", |
(...skipping 25 matching lines...) Expand all Loading... |
2190 "tcf2();" | 2176 "tcf2();" |
2191 "return func_name;", | 2177 "return func_name;", |
2192 factory->NewStringFromStaticChars("Rtcf2")), | 2178 factory->NewStringFromStaticChars("Rtcf2")), |
2193 }; | 2179 }; |
2194 | 2180 |
2195 const char* try_wrapper = | 2181 const char* try_wrapper = |
2196 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()"; | 2182 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()"; |
2197 | 2183 |
2198 for (size_t i = 0; i < arraysize(finallies); i++) { | 2184 for (size_t i = 0; i < arraysize(finallies); i++) { |
2199 std::string source(InterpreterTester::SourceForBody(finallies[i].first)); | 2185 std::string source(InterpreterTester::SourceForBody(finallies[i].first)); |
2200 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2186 InterpreterTester tester(isolate, source.c_str()); |
2201 tester.GetCallable<>(); | 2187 tester.GetCallable<>(); |
2202 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | 2188 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); |
2203 CHECK(wrapped->SameValue(*finallies[i].second)); | 2189 CHECK(wrapped->SameValue(*finallies[i].second)); |
2204 } | 2190 } |
2205 } | 2191 } |
2206 | 2192 |
2207 | 2193 |
2208 TEST(InterpreterThrow) { | 2194 TEST(InterpreterThrow) { |
2209 HandleAndZoneScope handles; | 2195 HandleAndZoneScope handles; |
2210 i::Isolate* isolate = handles.main_isolate(); | 2196 Isolate* isolate = handles.main_isolate(); |
2211 i::Factory* factory = isolate->factory(); | 2197 Factory* factory = isolate->factory(); |
2212 | 2198 |
2213 std::pair<const char*, Handle<Object>> throws[] = { | 2199 std::pair<const char*, Handle<Object>> throws[] = { |
2214 std::make_pair("throw undefined;\n", | 2200 std::make_pair("throw undefined;\n", |
2215 factory->undefined_value()), | 2201 factory->undefined_value()), |
2216 std::make_pair("throw 1;\n", | 2202 std::make_pair("throw 1;\n", |
2217 handle(Smi::FromInt(1), isolate)), | 2203 handle(Smi::FromInt(1), isolate)), |
2218 std::make_pair("throw 'Error';\n", | 2204 std::make_pair("throw 'Error';\n", |
2219 factory->NewStringFromStaticChars("Error")), | 2205 factory->NewStringFromStaticChars("Error")), |
2220 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", | 2206 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", |
2221 factory->NewStringFromStaticChars("Error")), | 2207 factory->NewStringFromStaticChars("Error")), |
2222 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", | 2208 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", |
2223 factory->undefined_value()), | 2209 factory->undefined_value()), |
2224 std::make_pair("throw 'Error1'; throw 'Error2'\n", | 2210 std::make_pair("throw 'Error1'; throw 'Error2'\n", |
2225 factory->NewStringFromStaticChars("Error1")), | 2211 factory->NewStringFromStaticChars("Error1")), |
2226 }; | 2212 }; |
2227 | 2213 |
2228 const char* try_wrapper = | 2214 const char* try_wrapper = |
2229 "(function() { try { f(); } catch(e) { return e; }})()"; | 2215 "(function() { try { f(); } catch(e) { return e; }})()"; |
2230 | 2216 |
2231 for (size_t i = 0; i < arraysize(throws); i++) { | 2217 for (size_t i = 0; i < arraysize(throws); i++) { |
2232 std::string source(InterpreterTester::SourceForBody(throws[i].first)); | 2218 std::string source(InterpreterTester::SourceForBody(throws[i].first)); |
2233 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2219 InterpreterTester tester(isolate, source.c_str()); |
2234 tester.GetCallable<>(); | 2220 tester.GetCallable<>(); |
2235 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | 2221 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); |
2236 CHECK(thrown_obj->SameValue(*throws[i].second)); | 2222 CHECK(thrown_obj->SameValue(*throws[i].second)); |
2237 } | 2223 } |
2238 } | 2224 } |
2239 | 2225 |
2240 | 2226 |
2241 TEST(InterpreterCountOperators) { | 2227 TEST(InterpreterCountOperators) { |
2242 HandleAndZoneScope handles; | 2228 HandleAndZoneScope handles; |
2243 i::Isolate* isolate = handles.main_isolate(); | 2229 Isolate* isolate = handles.main_isolate(); |
2244 i::Factory* factory = isolate->factory(); | 2230 Factory* factory = isolate->factory(); |
2245 | 2231 |
2246 std::pair<const char*, Handle<Object>> count_ops[] = { | 2232 std::pair<const char*, Handle<Object>> count_ops[] = { |
2247 std::make_pair("var a = 1; return ++a;", | 2233 std::make_pair("var a = 1; return ++a;", |
2248 handle(Smi::FromInt(2), isolate)), | 2234 handle(Smi::FromInt(2), isolate)), |
2249 std::make_pair("var a = 1; return a++;", | 2235 std::make_pair("var a = 1; return a++;", |
2250 handle(Smi::FromInt(1), isolate)), | 2236 handle(Smi::FromInt(1), isolate)), |
2251 std::make_pair("var a = 5; return --a;", | 2237 std::make_pair("var a = 5; return --a;", |
2252 handle(Smi::FromInt(4), isolate)), | 2238 handle(Smi::FromInt(4), isolate)), |
2253 std::make_pair("var a = 5; return a--;", | 2239 std::make_pair("var a = 5; return a--;", |
2254 handle(Smi::FromInt(5), isolate)), | 2240 handle(Smi::FromInt(5), isolate)), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2286 handle(Smi::FromInt(1), isolate)), | 2272 handle(Smi::FromInt(1), isolate)), |
2287 std::make_pair("var i = 20; switch(i++) {\n" | 2273 std::make_pair("var i = 20; switch(i++) {\n" |
2288 " case 20: return 1;\n" | 2274 " case 20: return 1;\n" |
2289 " default: return 2;\n" | 2275 " default: return 2;\n" |
2290 "}", | 2276 "}", |
2291 handle(Smi::FromInt(1), isolate)), | 2277 handle(Smi::FromInt(1), isolate)), |
2292 }; | 2278 }; |
2293 | 2279 |
2294 for (size_t i = 0; i < arraysize(count_ops); i++) { | 2280 for (size_t i = 0; i < arraysize(count_ops); i++) { |
2295 std::string source(InterpreterTester::SourceForBody(count_ops[i].first)); | 2281 std::string source(InterpreterTester::SourceForBody(count_ops[i].first)); |
2296 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2282 InterpreterTester tester(isolate, source.c_str()); |
2297 auto callable = tester.GetCallable<>(); | 2283 auto callable = tester.GetCallable<>(); |
2298 | 2284 |
2299 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2285 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2300 CHECK(return_value->SameValue(*count_ops[i].second)); | 2286 CHECK(return_value->SameValue(*count_ops[i].second)); |
2301 } | 2287 } |
2302 } | 2288 } |
2303 | 2289 |
2304 | 2290 |
2305 TEST(InterpreterGlobalCountOperators) { | 2291 TEST(InterpreterGlobalCountOperators) { |
2306 HandleAndZoneScope handles; | 2292 HandleAndZoneScope handles; |
2307 i::Isolate* isolate = handles.main_isolate(); | 2293 Isolate* isolate = handles.main_isolate(); |
2308 | 2294 |
2309 std::pair<const char*, Handle<Object>> count_ops[] = { | 2295 std::pair<const char*, Handle<Object>> count_ops[] = { |
2310 std::make_pair("var global = 100;function f(){ return ++global; }", | 2296 std::make_pair("var global = 100;function f(){ return ++global; }", |
2311 handle(Smi::FromInt(101), isolate)), | 2297 handle(Smi::FromInt(101), isolate)), |
2312 std::make_pair("var global = 100; function f(){ return --global; }", | 2298 std::make_pair("var global = 100; function f(){ return --global; }", |
2313 handle(Smi::FromInt(99), isolate)), | 2299 handle(Smi::FromInt(99), isolate)), |
2314 std::make_pair("var global = 100; function f(){ return global++; }", | 2300 std::make_pair("var global = 100; function f(){ return global++; }", |
2315 handle(Smi::FromInt(100), isolate)), | 2301 handle(Smi::FromInt(100), isolate)), |
2316 std::make_pair("unallocated = 200; function f(){ return ++unallocated; }", | 2302 std::make_pair("unallocated = 200; function f(){ return ++unallocated; }", |
2317 handle(Smi::FromInt(201), isolate)), | 2303 handle(Smi::FromInt(201), isolate)), |
2318 std::make_pair("unallocated = 200; function f(){ return --unallocated; }", | 2304 std::make_pair("unallocated = 200; function f(){ return --unallocated; }", |
2319 handle(Smi::FromInt(199), isolate)), | 2305 handle(Smi::FromInt(199), isolate)), |
2320 std::make_pair("unallocated = 200; function f(){ return unallocated++; }", | 2306 std::make_pair("unallocated = 200; function f(){ return unallocated++; }", |
2321 handle(Smi::FromInt(200), isolate)), | 2307 handle(Smi::FromInt(200), isolate)), |
2322 }; | 2308 }; |
2323 | 2309 |
2324 for (size_t i = 0; i < arraysize(count_ops); i++) { | 2310 for (size_t i = 0; i < arraysize(count_ops); i++) { |
2325 InterpreterTester tester(handles.main_isolate(), count_ops[i].first); | 2311 InterpreterTester tester(isolate, count_ops[i].first); |
2326 auto callable = tester.GetCallable<>(); | 2312 auto callable = tester.GetCallable<>(); |
2327 | 2313 |
2328 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2314 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2329 CHECK(return_value->SameValue(*count_ops[i].second)); | 2315 CHECK(return_value->SameValue(*count_ops[i].second)); |
2330 } | 2316 } |
2331 } | 2317 } |
2332 | 2318 |
2333 | 2319 |
2334 TEST(InterpreterCompoundExpressions) { | 2320 TEST(InterpreterCompoundExpressions) { |
2335 HandleAndZoneScope handles; | 2321 HandleAndZoneScope handles; |
2336 i::Isolate* isolate = handles.main_isolate(); | 2322 Isolate* isolate = handles.main_isolate(); |
2337 i::Factory* factory = isolate->factory(); | 2323 Factory* factory = isolate->factory(); |
2338 | 2324 |
2339 std::pair<const char*, Handle<Object>> compound_expr[] = { | 2325 std::pair<const char*, Handle<Object>> compound_expr[] = { |
2340 std::make_pair("var a = 1; a += 2; return a;", | 2326 std::make_pair("var a = 1; a += 2; return a;", |
2341 Handle<Object>(Smi::FromInt(3), isolate)), | 2327 Handle<Object>(Smi::FromInt(3), isolate)), |
2342 std::make_pair("var a = 10; a /= 2; return a;", | 2328 std::make_pair("var a = 10; a /= 2; return a;", |
2343 Handle<Object>(Smi::FromInt(5), isolate)), | 2329 Handle<Object>(Smi::FromInt(5), isolate)), |
2344 std::make_pair("var a = 'test'; a += 'ing'; return a;", | 2330 std::make_pair("var a = 'test'; a += 'ing'; return a;", |
2345 factory->NewStringFromStaticChars("testing")), | 2331 factory->NewStringFromStaticChars("testing")), |
2346 std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;", | 2332 std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;", |
2347 Handle<Object>(Smi::FromInt(4), isolate)), | 2333 Handle<Object>(Smi::FromInt(4), isolate)), |
2348 std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;" | 2334 std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;" |
2349 "return a;", | 2335 "return a;", |
2350 Handle<Object>(Smi::FromInt(26), isolate)), | 2336 Handle<Object>(Smi::FromInt(26), isolate)), |
2351 }; | 2337 }; |
2352 | 2338 |
2353 for (size_t i = 0; i < arraysize(compound_expr); i++) { | 2339 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
2354 std::string source( | 2340 std::string source( |
2355 InterpreterTester::SourceForBody(compound_expr[i].first)); | 2341 InterpreterTester::SourceForBody(compound_expr[i].first)); |
2356 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2342 InterpreterTester tester(isolate, source.c_str()); |
2357 auto callable = tester.GetCallable<>(); | 2343 auto callable = tester.GetCallable<>(); |
2358 | 2344 |
2359 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2345 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2360 CHECK(return_value->SameValue(*compound_expr[i].second)); | 2346 CHECK(return_value->SameValue(*compound_expr[i].second)); |
2361 } | 2347 } |
2362 } | 2348 } |
2363 | 2349 |
2364 | 2350 |
2365 TEST(InterpreterGlobalCompoundExpressions) { | 2351 TEST(InterpreterGlobalCompoundExpressions) { |
2366 HandleAndZoneScope handles; | 2352 HandleAndZoneScope handles; |
2367 i::Isolate* isolate = handles.main_isolate(); | 2353 Isolate* isolate = handles.main_isolate(); |
2368 | 2354 |
2369 std::pair<const char*, Handle<Object>> compound_expr[2] = { | 2355 std::pair<const char*, Handle<Object>> compound_expr[2] = { |
2370 std::make_pair("var global = 100;" | 2356 std::make_pair("var global = 100;" |
2371 "function f() { global += 20; return global; }", | 2357 "function f() { global += 20; return global; }", |
2372 Handle<Object>(Smi::FromInt(120), isolate)), | 2358 Handle<Object>(Smi::FromInt(120), isolate)), |
2373 std::make_pair("unallocated = 100;" | 2359 std::make_pair("unallocated = 100;" |
2374 "function f() { unallocated -= 20; return unallocated; }", | 2360 "function f() { unallocated -= 20; return unallocated; }", |
2375 Handle<Object>(Smi::FromInt(80), isolate)), | 2361 Handle<Object>(Smi::FromInt(80), isolate)), |
2376 }; | 2362 }; |
2377 | 2363 |
2378 for (size_t i = 0; i < arraysize(compound_expr); i++) { | 2364 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
2379 InterpreterTester tester(handles.main_isolate(), compound_expr[i].first); | 2365 InterpreterTester tester(isolate, compound_expr[i].first); |
2380 auto callable = tester.GetCallable<>(); | 2366 auto callable = tester.GetCallable<>(); |
2381 | 2367 |
2382 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2368 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2383 CHECK(return_value->SameValue(*compound_expr[i].second)); | 2369 CHECK(return_value->SameValue(*compound_expr[i].second)); |
2384 } | 2370 } |
2385 } | 2371 } |
2386 | 2372 |
2387 | 2373 |
2388 TEST(InterpreterCreateArguments) { | 2374 TEST(InterpreterCreateArguments) { |
2389 HandleAndZoneScope handles; | 2375 HandleAndZoneScope handles; |
2390 i::Isolate* isolate = handles.main_isolate(); | 2376 Isolate* isolate = handles.main_isolate(); |
2391 i::Factory* factory = isolate->factory(); | 2377 Factory* factory = isolate->factory(); |
2392 | 2378 |
2393 std::pair<const char*, int> create_args[] = { | 2379 std::pair<const char*, int> create_args[] = { |
2394 std::make_pair("function f() { return arguments[0]; }", 0), | 2380 std::make_pair("function f() { return arguments[0]; }", 0), |
2395 std::make_pair("function f(a) { return arguments[0]; }", 0), | 2381 std::make_pair("function f(a) { return arguments[0]; }", 0), |
2396 std::make_pair("function f() { return arguments[2]; }", 2), | 2382 std::make_pair("function f() { return arguments[2]; }", 2), |
2397 std::make_pair("function f(a) { return arguments[2]; }", 2), | 2383 std::make_pair("function f(a) { return arguments[2]; }", 2), |
2398 std::make_pair("function f(a, b, c, d) { return arguments[2]; }", 2), | 2384 std::make_pair("function f(a, b, c, d) { return arguments[2]; }", 2), |
2399 std::make_pair("function f(a) {" | 2385 std::make_pair("function f(a) {" |
2400 "'use strict'; return arguments[0]; }", | 2386 "'use strict'; return arguments[0]; }", |
2401 0), | 2387 0), |
(...skipping 15 matching lines...) Expand all Loading... |
2417 std::make_pair("function f(a, ...restArray) { return arguments[0]; }", 0), | 2403 std::make_pair("function f(a, ...restArray) { return arguments[0]; }", 0), |
2418 std::make_pair("function f(a, ...restArray) { return arguments[1]; }", 1), | 2404 std::make_pair("function f(a, ...restArray) { return arguments[1]; }", 1), |
2419 std::make_pair("function f(a, ...restArray) { return restArray[1]; }", 2), | 2405 std::make_pair("function f(a, ...restArray) { return restArray[1]; }", 2), |
2420 std::make_pair("function f(a, ...arguments) { return arguments[0]; }", 1), | 2406 std::make_pair("function f(a, ...arguments) { return arguments[0]; }", 1), |
2421 std::make_pair("function f(a, b, ...restArray) { return restArray[0]; }", | 2407 std::make_pair("function f(a, b, ...restArray) { return restArray[0]; }", |
2422 2), | 2408 2), |
2423 }; | 2409 }; |
2424 | 2410 |
2425 // Test passing no arguments. | 2411 // Test passing no arguments. |
2426 for (size_t i = 0; i < arraysize(create_args); i++) { | 2412 for (size_t i = 0; i < arraysize(create_args); i++) { |
2427 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2413 InterpreterTester tester(isolate, create_args[i].first); |
2428 auto callable = tester.GetCallable<>(); | 2414 auto callable = tester.GetCallable<>(); |
2429 Handle<Object> return_val = callable().ToHandleChecked(); | 2415 Handle<Object> return_val = callable().ToHandleChecked(); |
2430 CHECK(return_val.is_identical_to(factory->undefined_value())); | 2416 CHECK(return_val.is_identical_to(factory->undefined_value())); |
2431 } | 2417 } |
2432 | 2418 |
2433 // Test passing one argument. | 2419 // Test passing one argument. |
2434 for (size_t i = 0; i < arraysize(create_args); i++) { | 2420 for (size_t i = 0; i < arraysize(create_args); i++) { |
2435 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2421 InterpreterTester tester(isolate, create_args[i].first); |
2436 auto callable = tester.GetCallable<Handle<Object>>(); | 2422 auto callable = tester.GetCallable<Handle<Object>>(); |
2437 Handle<Object> return_val = | 2423 Handle<Object> return_val = |
2438 callable(handle(Smi::FromInt(40), isolate)).ToHandleChecked(); | 2424 callable(handle(Smi::FromInt(40), isolate)).ToHandleChecked(); |
2439 if (create_args[i].second == 0) { | 2425 if (create_args[i].second == 0) { |
2440 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(40)); | 2426 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(40)); |
2441 } else { | 2427 } else { |
2442 CHECK(return_val.is_identical_to(factory->undefined_value())); | 2428 CHECK(return_val.is_identical_to(factory->undefined_value())); |
2443 } | 2429 } |
2444 } | 2430 } |
2445 | 2431 |
2446 // Test passing three argument. | 2432 // Test passing three argument. |
2447 for (size_t i = 0; i < arraysize(create_args); i++) { | 2433 for (size_t i = 0; i < arraysize(create_args); i++) { |
2448 Handle<Object> args[3] = { | 2434 Handle<Object> args[3] = { |
2449 handle(Smi::FromInt(40), isolate), | 2435 handle(Smi::FromInt(40), isolate), |
2450 handle(Smi::FromInt(60), isolate), | 2436 handle(Smi::FromInt(60), isolate), |
2451 handle(Smi::FromInt(80), isolate), | 2437 handle(Smi::FromInt(80), isolate), |
2452 }; | 2438 }; |
2453 | 2439 |
2454 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2440 InterpreterTester tester(isolate, create_args[i].first); |
2455 auto callable = | 2441 auto callable = |
2456 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 2442 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
2457 Handle<Object> return_val = | 2443 Handle<Object> return_val = |
2458 callable(args[0], args[1], args[2]).ToHandleChecked(); | 2444 callable(args[0], args[1], args[2]).ToHandleChecked(); |
2459 CHECK(return_val->SameValue(*args[create_args[i].second])); | 2445 CHECK(return_val->SameValue(*args[create_args[i].second])); |
2460 } | 2446 } |
2461 } | 2447 } |
2462 | 2448 |
2463 | 2449 |
2464 TEST(InterpreterConditional) { | 2450 TEST(InterpreterConditional) { |
2465 HandleAndZoneScope handles; | 2451 HandleAndZoneScope handles; |
2466 i::Isolate* isolate = handles.main_isolate(); | 2452 Isolate* isolate = handles.main_isolate(); |
2467 | 2453 |
2468 std::pair<const char*, Handle<Object>> conditional[] = { | 2454 std::pair<const char*, Handle<Object>> conditional[] = { |
2469 std::make_pair("return true ? 2 : 3;", | 2455 std::make_pair("return true ? 2 : 3;", |
2470 handle(Smi::FromInt(2), isolate)), | 2456 handle(Smi::FromInt(2), isolate)), |
2471 std::make_pair("return false ? 2 : 3;", | 2457 std::make_pair("return false ? 2 : 3;", |
2472 handle(Smi::FromInt(3), isolate)), | 2458 handle(Smi::FromInt(3), isolate)), |
2473 std::make_pair("var a = 1; return a ? 20 : 30;", | 2459 std::make_pair("var a = 1; return a ? 20 : 30;", |
2474 handle(Smi::FromInt(20), isolate)), | 2460 handle(Smi::FromInt(20), isolate)), |
2475 std::make_pair("var a = 1; return a ? 20 : 30;", | 2461 std::make_pair("var a = 1; return a ? 20 : 30;", |
2476 handle(Smi::FromInt(20), isolate)), | 2462 handle(Smi::FromInt(20), isolate)), |
2477 std::make_pair("var a = 'string'; return a ? 20 : 30;", | 2463 std::make_pair("var a = 'string'; return a ? 20 : 30;", |
2478 handle(Smi::FromInt(20), isolate)), | 2464 handle(Smi::FromInt(20), isolate)), |
2479 std::make_pair("var a = undefined; return a ? 20 : 30;", | 2465 std::make_pair("var a = undefined; return a ? 20 : 30;", |
2480 handle(Smi::FromInt(30), isolate)), | 2466 handle(Smi::FromInt(30), isolate)), |
2481 std::make_pair("return 1 ? 2 ? 3 : 4 : 5;", | 2467 std::make_pair("return 1 ? 2 ? 3 : 4 : 5;", |
2482 handle(Smi::FromInt(3), isolate)), | 2468 handle(Smi::FromInt(3), isolate)), |
2483 std::make_pair("return 0 ? 2 ? 3 : 4 : 5;", | 2469 std::make_pair("return 0 ? 2 ? 3 : 4 : 5;", |
2484 handle(Smi::FromInt(5), isolate)), | 2470 handle(Smi::FromInt(5), isolate)), |
2485 }; | 2471 }; |
2486 | 2472 |
2487 for (size_t i = 0; i < arraysize(conditional); i++) { | 2473 for (size_t i = 0; i < arraysize(conditional); i++) { |
2488 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); | 2474 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); |
2489 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2475 InterpreterTester tester(isolate, source.c_str()); |
2490 auto callable = tester.GetCallable<>(); | 2476 auto callable = tester.GetCallable<>(); |
2491 | 2477 |
2492 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2478 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2493 CHECK(return_value->SameValue(*conditional[i].second)); | 2479 CHECK(return_value->SameValue(*conditional[i].second)); |
2494 } | 2480 } |
2495 } | 2481 } |
2496 | 2482 |
2497 | 2483 |
2498 TEST(InterpreterDelete) { | 2484 TEST(InterpreterDelete) { |
2499 HandleAndZoneScope handles; | 2485 HandleAndZoneScope handles; |
2500 i::Isolate* isolate = handles.main_isolate(); | 2486 Isolate* isolate = handles.main_isolate(); |
2501 i::Factory* factory = isolate->factory(); | 2487 Factory* factory = isolate->factory(); |
2502 | 2488 |
2503 // Tests for delete for local variables that work both in strict | 2489 // Tests for delete for local variables that work both in strict |
2504 // and sloppy modes | 2490 // and sloppy modes |
2505 std::pair<const char*, Handle<Object>> test_delete[] = { | 2491 std::pair<const char*, Handle<Object>> test_delete[] = { |
2506 std::make_pair( | 2492 std::make_pair( |
2507 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n", | 2493 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n", |
2508 factory->undefined_value()), | 2494 factory->undefined_value()), |
2509 std::make_pair( | 2495 std::make_pair( |
2510 "var b = { x:10, y:'abc', z:30.2}; delete b.x; return b.y;\n", | 2496 "var b = { x:10, y:'abc', z:30.2}; delete b.x; return b.y;\n", |
2511 factory->NewStringFromStaticChars("abc")), | 2497 factory->NewStringFromStaticChars("abc")), |
(...skipping 11 matching lines...) Expand all Loading... |
2523 std::make_pair("var a = {1:10};\n" | 2509 std::make_pair("var a = {1:10};\n" |
2524 "(function f1() {return a;});" | 2510 "(function f1() {return a;});" |
2525 "return delete a[1];", | 2511 "return delete a[1];", |
2526 factory->ToBoolean(true)), | 2512 factory->ToBoolean(true)), |
2527 std::make_pair("return delete this;", factory->ToBoolean(true)), | 2513 std::make_pair("return delete this;", factory->ToBoolean(true)), |
2528 std::make_pair("return delete 'test';", factory->ToBoolean(true))}; | 2514 std::make_pair("return delete 'test';", factory->ToBoolean(true))}; |
2529 | 2515 |
2530 // Test delete in sloppy mode | 2516 // Test delete in sloppy mode |
2531 for (size_t i = 0; i < arraysize(test_delete); i++) { | 2517 for (size_t i = 0; i < arraysize(test_delete); i++) { |
2532 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); | 2518 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); |
2533 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2519 InterpreterTester tester(isolate, source.c_str()); |
2534 auto callable = tester.GetCallable<>(); | 2520 auto callable = tester.GetCallable<>(); |
2535 | 2521 |
2536 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2522 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2537 CHECK(return_value->SameValue(*test_delete[i].second)); | 2523 CHECK(return_value->SameValue(*test_delete[i].second)); |
2538 } | 2524 } |
2539 | 2525 |
2540 // Test delete in strict mode | 2526 // Test delete in strict mode |
2541 for (size_t i = 0; i < arraysize(test_delete); i++) { | 2527 for (size_t i = 0; i < arraysize(test_delete); i++) { |
2542 std::string strict_test = | 2528 std::string strict_test = |
2543 "'use strict'; " + std::string(test_delete[i].first); | 2529 "'use strict'; " + std::string(test_delete[i].first); |
2544 std::string source(InterpreterTester::SourceForBody(strict_test.c_str())); | 2530 std::string source(InterpreterTester::SourceForBody(strict_test.c_str())); |
2545 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2531 InterpreterTester tester(isolate, source.c_str()); |
2546 auto callable = tester.GetCallable<>(); | 2532 auto callable = tester.GetCallable<>(); |
2547 | 2533 |
2548 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2534 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2549 CHECK(return_value->SameValue(*test_delete[i].second)); | 2535 CHECK(return_value->SameValue(*test_delete[i].second)); |
2550 } | 2536 } |
2551 } | 2537 } |
2552 | 2538 |
2553 | 2539 |
2554 TEST(InterpreterDeleteSloppyUnqualifiedIdentifier) { | 2540 TEST(InterpreterDeleteSloppyUnqualifiedIdentifier) { |
2555 HandleAndZoneScope handles; | 2541 HandleAndZoneScope handles; |
2556 i::Isolate* isolate = handles.main_isolate(); | 2542 Isolate* isolate = handles.main_isolate(); |
2557 i::Factory* factory = isolate->factory(); | 2543 Factory* factory = isolate->factory(); |
2558 | 2544 |
2559 // These tests generate a syntax error for strict mode. We don't | 2545 // These tests generate a syntax error for strict mode. We don't |
2560 // test for it here. | 2546 // test for it here. |
2561 std::pair<const char*, Handle<Object>> test_delete[] = { | 2547 std::pair<const char*, Handle<Object>> test_delete[] = { |
2562 std::make_pair("var sloppy_a = { x:10, y:'abc'};\n" | 2548 std::make_pair("var sloppy_a = { x:10, y:'abc'};\n" |
2563 "var sloppy_b = delete sloppy_a;\n" | 2549 "var sloppy_b = delete sloppy_a;\n" |
2564 "if (delete sloppy_a) {\n" | 2550 "if (delete sloppy_a) {\n" |
2565 " return undefined;\n" | 2551 " return undefined;\n" |
2566 "} else {\n" | 2552 "} else {\n" |
2567 " return sloppy_a.x;\n" | 2553 " return sloppy_a.x;\n" |
2568 "}\n", | 2554 "}\n", |
2569 Handle<Object>(Smi::FromInt(10), isolate)), | 2555 Handle<Object>(Smi::FromInt(10), isolate)), |
2570 // TODO(mythria) When try-catch is implemented change the tests to check | 2556 // TODO(mythria) When try-catch is implemented change the tests to check |
2571 // if delete actually deletes | 2557 // if delete actually deletes |
2572 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" | 2558 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" |
2573 "var sloppy_b = delete sloppy_a;\n" | 2559 "var sloppy_b = delete sloppy_a;\n" |
2574 // "try{return a.x;} catch(e) {return b;}\n" | 2560 // "try{return a.x;} catch(e) {return b;}\n" |
2575 "return sloppy_b;", | 2561 "return sloppy_b;", |
2576 factory->ToBoolean(true)), | 2562 factory->ToBoolean(true)), |
2577 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" | 2563 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" |
2578 "var sloppy_b = delete sloppy_c;\n" | 2564 "var sloppy_b = delete sloppy_c;\n" |
2579 "return sloppy_b;", | 2565 "return sloppy_b;", |
2580 factory->ToBoolean(true))}; | 2566 factory->ToBoolean(true))}; |
2581 | 2567 |
2582 for (size_t i = 0; i < arraysize(test_delete); i++) { | 2568 for (size_t i = 0; i < arraysize(test_delete); i++) { |
2583 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); | 2569 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); |
2584 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2570 InterpreterTester tester(isolate, source.c_str()); |
2585 auto callable = tester.GetCallable<>(); | 2571 auto callable = tester.GetCallable<>(); |
2586 | 2572 |
2587 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2573 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2588 CHECK(return_value->SameValue(*test_delete[i].second)); | 2574 CHECK(return_value->SameValue(*test_delete[i].second)); |
2589 } | 2575 } |
2590 } | 2576 } |
2591 | 2577 |
2592 | 2578 |
2593 TEST(InterpreterGlobalDelete) { | 2579 TEST(InterpreterGlobalDelete) { |
2594 HandleAndZoneScope handles; | 2580 HandleAndZoneScope handles; |
2595 i::Isolate* isolate = handles.main_isolate(); | 2581 Isolate* isolate = handles.main_isolate(); |
2596 i::Factory* factory = isolate->factory(); | 2582 Factory* factory = isolate->factory(); |
2597 | 2583 |
2598 std::pair<const char*, Handle<Object>> test_global_delete[] = { | 2584 std::pair<const char*, Handle<Object>> test_global_delete[] = { |
2599 std::make_pair("var a = { x:10, y:'abc', z:30.2 };\n" | 2585 std::make_pair("var a = { x:10, y:'abc', z:30.2 };\n" |
2600 "function f() {\n" | 2586 "function f() {\n" |
2601 " delete a.x;\n" | 2587 " delete a.x;\n" |
2602 " return a.x;\n" | 2588 " return a.x;\n" |
2603 "}\n" | 2589 "}\n" |
2604 "f();\n", | 2590 "f();\n", |
2605 factory->undefined_value()), | 2591 factory->undefined_value()), |
2606 std::make_pair("var b = {1:10, 2:'abc', 3:30.2 };\n" | 2592 std::make_pair("var b = {1:10, 2:'abc', 3:30.2 };\n" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 " var obj = {h:10,\n" | 2626 " var obj = {h:10,\n" |
2641 " f1() {\n" | 2627 " f1() {\n" |
2642 " 'use strict';\n" | 2628 " 'use strict';\n" |
2643 " return delete this.h;}};\n" | 2629 " return delete this.h;}};\n" |
2644 " return obj.f1();\n" | 2630 " return obj.f1();\n" |
2645 "}\n" | 2631 "}\n" |
2646 "f();", | 2632 "f();", |
2647 factory->ToBoolean(true))}; | 2633 factory->ToBoolean(true))}; |
2648 | 2634 |
2649 for (size_t i = 0; i < arraysize(test_global_delete); i++) { | 2635 for (size_t i = 0; i < arraysize(test_global_delete); i++) { |
2650 InterpreterTester tester(handles.main_isolate(), | 2636 InterpreterTester tester(isolate, test_global_delete[i].first); |
2651 test_global_delete[i].first); | |
2652 auto callable = tester.GetCallable<>(); | 2637 auto callable = tester.GetCallable<>(); |
2653 | 2638 |
2654 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2639 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2655 CHECK(return_value->SameValue(*test_global_delete[i].second)); | 2640 CHECK(return_value->SameValue(*test_global_delete[i].second)); |
2656 } | 2641 } |
2657 } | 2642 } |
2658 | 2643 |
2659 | 2644 |
2660 TEST(InterpreterBasicLoops) { | 2645 TEST(InterpreterBasicLoops) { |
2661 HandleAndZoneScope handles; | 2646 HandleAndZoneScope handles; |
2662 i::Isolate* isolate = handles.main_isolate(); | 2647 Isolate* isolate = handles.main_isolate(); |
2663 i::Factory* factory = isolate->factory(); | 2648 Factory* factory = isolate->factory(); |
2664 | 2649 |
2665 std::pair<const char*, Handle<Object>> loops[] = { | 2650 std::pair<const char*, Handle<Object>> loops[] = { |
2666 std::make_pair("var a = 10; var b = 1;\n" | 2651 std::make_pair("var a = 10; var b = 1;\n" |
2667 "while (a) {\n" | 2652 "while (a) {\n" |
2668 " b = b * 2;\n" | 2653 " b = b * 2;\n" |
2669 " a = a - 1;\n" | 2654 " a = a - 1;\n" |
2670 "};\n" | 2655 "};\n" |
2671 "return b;\n", | 2656 "return b;\n", |
2672 factory->NewHeapNumber(1024)), | 2657 factory->NewHeapNumber(1024)), |
2673 std::make_pair("var a = 1; var b = 1;\n" | 2658 std::make_pair("var a = 1; var b = 1;\n" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2737 Handle<Object>(Smi::FromInt(2), isolate)), | 2722 Handle<Object>(Smi::FromInt(2), isolate)), |
2738 std::make_pair("var a = 10; var b = 1;\n" | 2723 std::make_pair("var a = 10; var b = 1;\n" |
2739 "for ( a = 1, b = 30; false; ) {\n" | 2724 "for ( a = 1, b = 30; false; ) {\n" |
2740 " b = b * 2;\n" | 2725 " b = b * 2;\n" |
2741 "}\n" | 2726 "}\n" |
2742 "return b;\n", | 2727 "return b;\n", |
2743 Handle<Object>(Smi::FromInt(30), isolate))}; | 2728 Handle<Object>(Smi::FromInt(30), isolate))}; |
2744 | 2729 |
2745 for (size_t i = 0; i < arraysize(loops); i++) { | 2730 for (size_t i = 0; i < arraysize(loops); i++) { |
2746 std::string source(InterpreterTester::SourceForBody(loops[i].first)); | 2731 std::string source(InterpreterTester::SourceForBody(loops[i].first)); |
2747 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2732 InterpreterTester tester(isolate, source.c_str()); |
2748 auto callable = tester.GetCallable<>(); | 2733 auto callable = tester.GetCallable<>(); |
2749 | 2734 |
2750 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2735 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2751 CHECK(return_value->SameValue(*loops[i].second)); | 2736 CHECK(return_value->SameValue(*loops[i].second)); |
2752 } | 2737 } |
2753 } | 2738 } |
2754 | 2739 |
2755 | 2740 |
2756 TEST(InterpreterForIn) { | 2741 TEST(InterpreterForIn) { |
2757 std::pair<const char*, int> for_in_samples[] = { | 2742 std::pair<const char*, int> for_in_samples[] = { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2914 "for (o[i++] in data)\n" // This is to test if value is loaded | 2899 "for (o[i++] in data)\n" // This is to test if value is loaded |
2915 " result += data[o[i-1]];\n" // back from accumulator before | 2900 " result += data[o[i-1]];\n" // back from accumulator before |
2916 "return result;\n", // storing keyed properties. | 2901 "return result;\n", // storing keyed properties. |
2917 57}}; | 2902 57}}; |
2918 | 2903 |
2919 // Two passes are made for this test. On the first, 8-bit register | 2904 // Two passes are made for this test. On the first, 8-bit register |
2920 // operands are employed, and on the 16-bit register operands are | 2905 // operands are employed, and on the 16-bit register operands are |
2921 // used. | 2906 // used. |
2922 for (int pass = 0; pass < 2; pass++) { | 2907 for (int pass = 0; pass < 2; pass++) { |
2923 HandleAndZoneScope handles; | 2908 HandleAndZoneScope handles; |
| 2909 Isolate* isolate = handles.main_isolate(); |
2924 std::ostringstream wide_os; | 2910 std::ostringstream wide_os; |
2925 if (pass == 1) { | 2911 if (pass == 1) { |
2926 for (int i = 0; i < 200; i++) { | 2912 for (int i = 0; i < 200; i++) { |
2927 wide_os << "var local" << i << " = 0;\n"; | 2913 wide_os << "var local" << i << " = 0;\n"; |
2928 } | 2914 } |
2929 } | 2915 } |
2930 | 2916 |
2931 for (size_t i = 0; i < arraysize(for_in_samples); i++) { | 2917 for (size_t i = 0; i < arraysize(for_in_samples); i++) { |
2932 std::ostringstream body_os; | 2918 std::ostringstream body_os; |
2933 body_os << wide_os.str() << for_in_samples[i].first; | 2919 body_os << wide_os.str() << for_in_samples[i].first; |
2934 std::string body(body_os.str()); | 2920 std::string body(body_os.str()); |
2935 std::string function = InterpreterTester::SourceForBody(body.c_str()); | 2921 std::string function = InterpreterTester::SourceForBody(body.c_str()); |
2936 InterpreterTester tester(handles.main_isolate(), function.c_str()); | 2922 InterpreterTester tester(isolate, function.c_str()); |
2937 auto callable = tester.GetCallable<>(); | 2923 auto callable = tester.GetCallable<>(); |
2938 Handle<Object> return_val = callable().ToHandleChecked(); | 2924 Handle<Object> return_val = callable().ToHandleChecked(); |
2939 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), | 2925 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), |
2940 for_in_samples[i].second); | 2926 for_in_samples[i].second); |
2941 } | 2927 } |
2942 } | 2928 } |
2943 } | 2929 } |
2944 | 2930 |
2945 | 2931 |
2946 TEST(InterpreterForOf) { | 2932 TEST(InterpreterForOf) { |
2947 HandleAndZoneScope handles; | 2933 HandleAndZoneScope handles; |
2948 i::Isolate* isolate = handles.main_isolate(); | 2934 Isolate* isolate = handles.main_isolate(); |
2949 i::Factory* factory = isolate->factory(); | 2935 Factory* factory = isolate->factory(); |
2950 | 2936 |
2951 std::pair<const char*, Handle<Object>> for_of[] = { | 2937 std::pair<const char*, Handle<Object>> for_of[] = { |
2952 {"function f() {\n" | 2938 {"function f() {\n" |
2953 " var r = 0;\n" | 2939 " var r = 0;\n" |
2954 " for (var a of [0,6,7,9]) { r += a; }\n" | 2940 " for (var a of [0,6,7,9]) { r += a; }\n" |
2955 " return r;\n" | 2941 " return r;\n" |
2956 "}", | 2942 "}", |
2957 handle(Smi::FromInt(22), isolate)}, | 2943 handle(Smi::FromInt(22), isolate)}, |
2958 {"function f() {\n" | 2944 {"function f() {\n" |
2959 " var r = '';\n" | 2945 " var r = '';\n" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3038 " }\n" | 3024 " }\n" |
3039 " }\n" | 3025 " }\n" |
3040 " }}\n" | 3026 " }}\n" |
3041 " for (a of obj) { r += a }\n" | 3027 " for (a of obj) { r += a }\n" |
3042 " return r;\n" | 3028 " return r;\n" |
3043 "}", | 3029 "}", |
3044 factory->NewStringFromStaticChars("dcba")}, | 3030 factory->NewStringFromStaticChars("dcba")}, |
3045 }; | 3031 }; |
3046 | 3032 |
3047 for (size_t i = 0; i < arraysize(for_of); i++) { | 3033 for (size_t i = 0; i < arraysize(for_of); i++) { |
3048 InterpreterTester tester(handles.main_isolate(), for_of[i].first); | 3034 InterpreterTester tester(isolate, for_of[i].first); |
3049 auto callable = tester.GetCallable<>(); | 3035 auto callable = tester.GetCallable<>(); |
3050 Handle<Object> return_val = callable().ToHandleChecked(); | 3036 Handle<Object> return_val = callable().ToHandleChecked(); |
3051 CHECK(return_val->SameValue(*for_of[i].second)); | 3037 CHECK(return_val->SameValue(*for_of[i].second)); |
3052 } | 3038 } |
3053 } | 3039 } |
3054 | 3040 |
3055 | 3041 |
3056 TEST(InterpreterSwitch) { | 3042 TEST(InterpreterSwitch) { |
3057 HandleAndZoneScope handles; | 3043 HandleAndZoneScope handles; |
3058 i::Isolate* isolate = handles.main_isolate(); | 3044 Isolate* isolate = handles.main_isolate(); |
3059 i::Factory* factory = isolate->factory(); | 3045 Factory* factory = isolate->factory(); |
3060 | 3046 |
3061 std::pair<const char*, Handle<Object>> switch_ops[] = { | 3047 std::pair<const char*, Handle<Object>> switch_ops[] = { |
3062 std::make_pair("var a = 1;\n" | 3048 std::make_pair("var a = 1;\n" |
3063 "switch(a) {\n" | 3049 "switch(a) {\n" |
3064 " case 1: return 2;\n" | 3050 " case 1: return 2;\n" |
3065 " case 2: return 3;\n" | 3051 " case 2: return 3;\n" |
3066 "}\n", | 3052 "}\n", |
3067 handle(Smi::FromInt(2), isolate)), | 3053 handle(Smi::FromInt(2), isolate)), |
3068 std::make_pair("var a = 1;\n" | 3054 std::make_pair("var a = 1;\n" |
3069 "switch(a) {\n" | 3055 "switch(a) {\n" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3117 " default : a += 2; break;\n" | 3103 " default : a += 2; break;\n" |
3118 " } // fall-through\n" | 3104 " } // fall-through\n" |
3119 " case 2: a += 3;\n" | 3105 " case 2: a += 3;\n" |
3120 "}\n" | 3106 "}\n" |
3121 "return a;", | 3107 "return a;", |
3122 handle(Smi::FromInt(5), isolate)), | 3108 handle(Smi::FromInt(5), isolate)), |
3123 }; | 3109 }; |
3124 | 3110 |
3125 for (size_t i = 0; i < arraysize(switch_ops); i++) { | 3111 for (size_t i = 0; i < arraysize(switch_ops); i++) { |
3126 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first)); | 3112 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first)); |
3127 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3113 InterpreterTester tester(isolate, source.c_str()); |
3128 auto callable = tester.GetCallable<>(); | 3114 auto callable = tester.GetCallable<>(); |
3129 | 3115 |
3130 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3116 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3131 CHECK(return_value->SameValue(*switch_ops[i].second)); | 3117 CHECK(return_value->SameValue(*switch_ops[i].second)); |
3132 } | 3118 } |
3133 } | 3119 } |
3134 | 3120 |
3135 | 3121 |
3136 TEST(InterpreterSloppyThis) { | 3122 TEST(InterpreterSloppyThis) { |
3137 HandleAndZoneScope handles; | 3123 HandleAndZoneScope handles; |
3138 i::Isolate* isolate = handles.main_isolate(); | 3124 Isolate* isolate = handles.main_isolate(); |
3139 i::Factory* factory = isolate->factory(); | 3125 Factory* factory = isolate->factory(); |
3140 | 3126 |
3141 std::pair<const char*, Handle<Object>> sloppy_this[] = { | 3127 std::pair<const char*, Handle<Object>> sloppy_this[] = { |
3142 std::make_pair("var global_val = 100;\n" | 3128 std::make_pair("var global_val = 100;\n" |
3143 "function f() { return this.global_val; }\n", | 3129 "function f() { return this.global_val; }\n", |
3144 handle(Smi::FromInt(100), isolate)), | 3130 handle(Smi::FromInt(100), isolate)), |
3145 std::make_pair("var global_val = 110;\n" | 3131 std::make_pair("var global_val = 110;\n" |
3146 "function g() { return this.global_val; };" | 3132 "function g() { return this.global_val; };" |
3147 "function f() { return g(); }\n", | 3133 "function f() { return g(); }\n", |
3148 handle(Smi::FromInt(110), isolate)), | 3134 handle(Smi::FromInt(110), isolate)), |
3149 std::make_pair("var global_val = 110;\n" | 3135 std::make_pair("var global_val = 110;\n" |
3150 "function g() { return this.global_val };" | 3136 "function g() { return this.global_val };" |
3151 "function f() { 'use strict'; return g(); }\n", | 3137 "function f() { 'use strict'; return g(); }\n", |
3152 handle(Smi::FromInt(110), isolate)), | 3138 handle(Smi::FromInt(110), isolate)), |
3153 std::make_pair("function f() { 'use strict'; return this; }\n", | 3139 std::make_pair("function f() { 'use strict'; return this; }\n", |
3154 factory->undefined_value()), | 3140 factory->undefined_value()), |
3155 std::make_pair("function g() { 'use strict'; return this; };" | 3141 std::make_pair("function g() { 'use strict'; return this; };" |
3156 "function f() { return g(); }\n", | 3142 "function f() { return g(); }\n", |
3157 factory->undefined_value()), | 3143 factory->undefined_value()), |
3158 }; | 3144 }; |
3159 | 3145 |
3160 for (size_t i = 0; i < arraysize(sloppy_this); i++) { | 3146 for (size_t i = 0; i < arraysize(sloppy_this); i++) { |
3161 InterpreterTester tester(handles.main_isolate(), sloppy_this[i].first); | 3147 InterpreterTester tester(isolate, sloppy_this[i].first); |
3162 auto callable = tester.GetCallable<>(); | 3148 auto callable = tester.GetCallable<>(); |
3163 | 3149 |
3164 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3150 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3165 CHECK(return_value->SameValue(*sloppy_this[i].second)); | 3151 CHECK(return_value->SameValue(*sloppy_this[i].second)); |
3166 } | 3152 } |
3167 } | 3153 } |
3168 | 3154 |
3169 | 3155 |
3170 TEST(InterpreterThisFunction) { | 3156 TEST(InterpreterThisFunction) { |
3171 HandleAndZoneScope handles; | 3157 HandleAndZoneScope handles; |
3172 i::Isolate* isolate = handles.main_isolate(); | 3158 Isolate* isolate = handles.main_isolate(); |
3173 i::Factory* factory = isolate->factory(); | 3159 Factory* factory = isolate->factory(); |
3174 | 3160 |
3175 InterpreterTester tester(handles.main_isolate(), | 3161 InterpreterTester tester(isolate, |
3176 "var f;\n f = function f() { return f.name; }"); | 3162 "var f;\n f = function f() { return f.name; }"); |
3177 auto callable = tester.GetCallable<>(); | 3163 auto callable = tester.GetCallable<>(); |
3178 | 3164 |
3179 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3165 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3180 CHECK(return_value->SameValue(*factory->NewStringFromStaticChars("f"))); | 3166 CHECK(return_value->SameValue(*factory->NewStringFromStaticChars("f"))); |
3181 } | 3167 } |
3182 | 3168 |
3183 | 3169 |
3184 TEST(InterpreterNewTarget) { | 3170 TEST(InterpreterNewTarget) { |
3185 HandleAndZoneScope handles; | 3171 HandleAndZoneScope handles; |
3186 i::Isolate* isolate = handles.main_isolate(); | 3172 Isolate* isolate = handles.main_isolate(); |
3187 i::Factory* factory = isolate->factory(); | 3173 Factory* factory = isolate->factory(); |
3188 | 3174 |
3189 // TODO(rmcilroy): Add tests that we get the original constructor for | 3175 // TODO(rmcilroy): Add tests that we get the original constructor for |
3190 // superclass constructors once we have class support. | 3176 // superclass constructors once we have class support. |
3191 InterpreterTester tester(handles.main_isolate(), | 3177 InterpreterTester tester(isolate, "function f() { this.a = new.target; }"); |
3192 "function f() { this.a = new.target; }"); | |
3193 auto callable = tester.GetCallable<>(); | 3178 auto callable = tester.GetCallable<>(); |
3194 callable().ToHandleChecked(); | 3179 callable().ToHandleChecked(); |
3195 | 3180 |
3196 Handle<Object> new_target_name = v8::Utils::OpenHandle( | 3181 Handle<Object> new_target_name = v8::Utils::OpenHandle( |
3197 *CompileRun("(function() { return (new f()).a.name; })();")); | 3182 *CompileRun("(function() { return (new f()).a.name; })();")); |
3198 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f"))); | 3183 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f"))); |
3199 } | 3184 } |
3200 | 3185 |
3201 | 3186 |
3202 TEST(InterpreterAssignmentInExpressions) { | 3187 TEST(InterpreterAssignmentInExpressions) { |
3203 HandleAndZoneScope handles; | 3188 HandleAndZoneScope handles; |
| 3189 Isolate* isolate = handles.main_isolate(); |
3204 | 3190 |
3205 std::pair<const char*, int> samples[] = { | 3191 std::pair<const char*, int> samples[] = { |
3206 {"function f() {\n" | 3192 {"function f() {\n" |
3207 " var x = 7;\n" | 3193 " var x = 7;\n" |
3208 " var y = x + (x = 1) + (x = 2);\n" | 3194 " var y = x + (x = 1) + (x = 2);\n" |
3209 " return y;\n" | 3195 " return y;\n" |
3210 "}", | 3196 "}", |
3211 10}, | 3197 10}, |
3212 {"function f() {\n" | 3198 {"function f() {\n" |
3213 " var x = 7;\n" | 3199 " var x = 7;\n" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3323 "}", | 3309 "}", |
3324 60}, | 3310 60}, |
3325 {"function f(a) {\n" | 3311 {"function f(a) {\n" |
3326 " return a + (arguments[0] = 10) + arguments[0];\n" | 3312 " return a + (arguments[0] = 10) + arguments[0];\n" |
3327 "}", | 3313 "}", |
3328 60}, | 3314 60}, |
3329 }; | 3315 }; |
3330 | 3316 |
3331 const int arg_value = 40; | 3317 const int arg_value = 40; |
3332 for (size_t i = 0; i < arraysize(samples); i++) { | 3318 for (size_t i = 0; i < arraysize(samples); i++) { |
3333 InterpreterTester tester(handles.main_isolate(), samples[i].first); | 3319 InterpreterTester tester(isolate, samples[i].first); |
3334 auto callable = tester.GetCallable<Handle<Object>>(); | 3320 auto callable = tester.GetCallable<Handle<Object>>(); |
3335 Handle<Object> return_val = | 3321 Handle<Object> return_val = |
3336 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) | 3322 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) |
3337 .ToHandleChecked(); | 3323 .ToHandleChecked(); |
3338 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); | 3324 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); |
3339 } | 3325 } |
3340 } | 3326 } |
3341 | 3327 |
3342 | 3328 |
3343 TEST(InterpreterToName) { | 3329 TEST(InterpreterToName) { |
3344 HandleAndZoneScope handles; | 3330 HandleAndZoneScope handles; |
3345 i::Isolate* isolate = handles.main_isolate(); | 3331 Isolate* isolate = handles.main_isolate(); |
3346 i::Factory* factory = isolate->factory(); | 3332 Factory* factory = isolate->factory(); |
3347 | 3333 |
3348 std::pair<const char*, Handle<Object>> to_name_tests[] = { | 3334 std::pair<const char*, Handle<Object>> to_name_tests[] = { |
3349 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", | 3335 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", |
3350 factory->NewNumberFromInt(10)}, | 3336 factory->NewNumberFromInt(10)}, |
3351 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", | 3337 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", |
3352 factory->NewNumberFromInt(10)}, | 3338 factory->NewNumberFromInt(10)}, |
3353 {"var a = 20; var obj = {[a] : 10}; return obj[20];", | 3339 {"var a = 20; var obj = {[a] : 10}; return obj[20];", |
3354 factory->NewNumberFromInt(10)}, | 3340 factory->NewNumberFromInt(10)}, |
3355 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", | 3341 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", |
3356 factory->NewNumberFromInt(10)}, | 3342 factory->NewNumberFromInt(10)}, |
(...skipping 10 matching lines...) Expand all Loading... |
3367 factory->undefined_value()}, | 3353 factory->undefined_value()}, |
3368 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n" | 3354 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n" |
3369 "var obj = {[a] : 10};\n" | 3355 "var obj = {[a] : 10};\n" |
3370 "return obj.x;", | 3356 "return obj.x;", |
3371 factory->NewNumberFromInt(10)}, | 3357 factory->NewNumberFromInt(10)}, |
3372 }; | 3358 }; |
3373 | 3359 |
3374 for (size_t i = 0; i < arraysize(to_name_tests); i++) { | 3360 for (size_t i = 0; i < arraysize(to_name_tests); i++) { |
3375 std::string source( | 3361 std::string source( |
3376 InterpreterTester::SourceForBody(to_name_tests[i].first)); | 3362 InterpreterTester::SourceForBody(to_name_tests[i].first)); |
3377 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3363 InterpreterTester tester(isolate, source.c_str()); |
3378 auto callable = tester.GetCallable<>(); | 3364 auto callable = tester.GetCallable<>(); |
3379 | 3365 |
3380 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3366 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3381 CHECK(return_value->SameValue(*to_name_tests[i].second)); | 3367 CHECK(return_value->SameValue(*to_name_tests[i].second)); |
3382 } | 3368 } |
3383 } | 3369 } |
3384 | 3370 |
3385 | 3371 |
3386 TEST(TemporaryRegisterAllocation) { | 3372 TEST(TemporaryRegisterAllocation) { |
3387 HandleAndZoneScope handles; | 3373 HandleAndZoneScope handles; |
3388 i::Isolate* isolate = handles.main_isolate(); | 3374 Isolate* isolate = handles.main_isolate(); |
3389 i::Factory* factory = isolate->factory(); | 3375 Factory* factory = isolate->factory(); |
3390 | 3376 |
3391 std::pair<const char*, Handle<Object>> reg_tests[] = { | 3377 std::pair<const char*, Handle<Object>> reg_tests[] = { |
3392 {"function add(a, b, c) {" | 3378 {"function add(a, b, c) {" |
3393 " return a + b + c;" | 3379 " return a + b + c;" |
3394 "}" | 3380 "}" |
3395 "function f() {" | 3381 "function f() {" |
3396 " var a = 10, b = 10;" | 3382 " var a = 10, b = 10;" |
3397 " return add(a, b++, b);" | 3383 " return add(a, b++, b);" |
3398 "}", | 3384 "}", |
3399 factory->NewNumberFromInt(31)}, | 3385 factory->NewNumberFromInt(31)}, |
3400 {"function add(a, b, c, d) {" | 3386 {"function add(a, b, c, d) {" |
3401 " return a + b + c + d;" | 3387 " return a + b + c + d;" |
3402 "}" | 3388 "}" |
3403 "function f() {" | 3389 "function f() {" |
3404 " var x = 10, y = 20, z = 30;" | 3390 " var x = 10, y = 20, z = 30;" |
3405 " return x + add(x, (y= x++), x, z);" | 3391 " return x + add(x, (y= x++), x, z);" |
3406 "}", | 3392 "}", |
3407 factory->NewNumberFromInt(71)}, | 3393 factory->NewNumberFromInt(71)}, |
3408 }; | 3394 }; |
3409 | 3395 |
3410 for (size_t i = 0; i < arraysize(reg_tests); i++) { | 3396 for (size_t i = 0; i < arraysize(reg_tests); i++) { |
3411 InterpreterTester tester(handles.main_isolate(), reg_tests[i].first); | 3397 InterpreterTester tester(isolate, reg_tests[i].first); |
3412 auto callable = tester.GetCallable<>(); | 3398 auto callable = tester.GetCallable<>(); |
3413 | 3399 |
3414 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3400 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3415 CHECK(return_value->SameValue(*reg_tests[i].second)); | 3401 CHECK(return_value->SameValue(*reg_tests[i].second)); |
3416 } | 3402 } |
3417 } | 3403 } |
3418 | 3404 |
3419 | 3405 |
3420 TEST(InterpreterLookupSlot) { | 3406 TEST(InterpreterLookupSlot) { |
3421 HandleAndZoneScope handles; | 3407 HandleAndZoneScope handles; |
3422 i::Isolate* isolate = handles.main_isolate(); | 3408 Isolate* isolate = handles.main_isolate(); |
3423 i::Factory* factory = isolate->factory(); | 3409 Factory* factory = isolate->factory(); |
3424 | 3410 |
3425 // TODO(mythria): Add more tests when we have support for eval/with. | 3411 // TODO(mythria): Add more tests when we have support for eval/with. |
3426 const char* function_prologue = "var f;" | 3412 const char* function_prologue = "var f;" |
3427 "var x = 1;" | 3413 "var x = 1;" |
3428 "function f1() {" | 3414 "function f1() {" |
3429 " eval(\"function t() {"; | 3415 " eval(\"function t() {"; |
3430 const char* function_epilogue = " }; f = t;\");" | 3416 const char* function_epilogue = " }; f = t;\");" |
3431 "}" | 3417 "}" |
3432 "f1();"; | 3418 "f1();"; |
3433 | 3419 |
3434 | 3420 |
3435 std::pair<const char*, Handle<Object>> lookup_slot[] = { | 3421 std::pair<const char*, Handle<Object>> lookup_slot[] = { |
3436 {"return x;", handle(Smi::FromInt(1), isolate)}, | 3422 {"return x;", handle(Smi::FromInt(1), isolate)}, |
3437 {"return typeof x;", factory->NewStringFromStaticChars("number")}, | 3423 {"return typeof x;", factory->NewStringFromStaticChars("number")}, |
3438 {"return typeof dummy;", factory->NewStringFromStaticChars("undefined")}, | 3424 {"return typeof dummy;", factory->NewStringFromStaticChars("undefined")}, |
3439 {"x = 10; return x;", handle(Smi::FromInt(10), isolate)}, | 3425 {"x = 10; return x;", handle(Smi::FromInt(10), isolate)}, |
3440 {"'use strict'; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, | 3426 {"'use strict'; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
3441 }; | 3427 }; |
3442 | 3428 |
3443 for (size_t i = 0; i < arraysize(lookup_slot); i++) { | 3429 for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
3444 std::string script = std::string(function_prologue) + | 3430 std::string script = std::string(function_prologue) + |
3445 std::string(lookup_slot[i].first) + | 3431 std::string(lookup_slot[i].first) + |
3446 std::string(function_epilogue); | 3432 std::string(function_epilogue); |
3447 | 3433 |
3448 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); | 3434 InterpreterTester tester(isolate, script.c_str(), "t"); |
3449 auto callable = tester.GetCallable<>(); | 3435 auto callable = tester.GetCallable<>(); |
3450 | 3436 |
3451 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3437 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3452 CHECK(return_value->SameValue(*lookup_slot[i].second)); | 3438 CHECK(return_value->SameValue(*lookup_slot[i].second)); |
3453 } | 3439 } |
3454 } | 3440 } |
3455 | 3441 |
3456 | 3442 |
3457 TEST(InterpreterCallLookupSlot) { | 3443 TEST(InterpreterCallLookupSlot) { |
3458 HandleAndZoneScope handles; | 3444 HandleAndZoneScope handles; |
3459 i::Isolate* isolate = handles.main_isolate(); | 3445 Isolate* isolate = handles.main_isolate(); |
3460 | 3446 |
3461 std::pair<const char*, Handle<Object>> call_lookup[] = { | 3447 std::pair<const char*, Handle<Object>> call_lookup[] = { |
3462 {"g = function(){ return 2 }; eval(''); return g();", | 3448 {"g = function(){ return 2 }; eval(''); return g();", |
3463 handle(Smi::FromInt(2), isolate)}, | 3449 handle(Smi::FromInt(2), isolate)}, |
3464 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" | 3450 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" |
3465 "return g();", | 3451 "return g();", |
3466 handle(Smi::FromInt(3), isolate)}, | 3452 handle(Smi::FromInt(3), isolate)}, |
3467 {"g = { x: function(){ return this.y }, y: 20 };\n" | 3453 {"g = { x: function(){ return this.y }, y: 20 };\n" |
3468 "eval('g = { x: g.x, y: 30 }');\n" | 3454 "eval('g = { x: g.x, y: 30 }');\n" |
3469 "return g.x();", | 3455 "return g.x();", |
3470 handle(Smi::FromInt(30), isolate)}, | 3456 handle(Smi::FromInt(30), isolate)}, |
3471 }; | 3457 }; |
3472 | 3458 |
3473 for (size_t i = 0; i < arraysize(call_lookup); i++) { | 3459 for (size_t i = 0; i < arraysize(call_lookup); i++) { |
3474 std::string source(InterpreterTester::SourceForBody(call_lookup[i].first)); | 3460 std::string source(InterpreterTester::SourceForBody(call_lookup[i].first)); |
3475 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3461 InterpreterTester tester(isolate, source.c_str()); |
3476 auto callable = tester.GetCallable<>(); | 3462 auto callable = tester.GetCallable<>(); |
3477 | 3463 |
3478 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3464 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3479 CHECK(return_value->SameValue(*call_lookup[i].second)); | 3465 CHECK(return_value->SameValue(*call_lookup[i].second)); |
3480 } | 3466 } |
3481 } | 3467 } |
3482 | 3468 |
3483 | 3469 |
3484 TEST(InterpreterLookupSlotWide) { | 3470 TEST(InterpreterLookupSlotWide) { |
3485 HandleAndZoneScope handles; | 3471 HandleAndZoneScope handles; |
3486 i::Isolate* isolate = handles.main_isolate(); | 3472 Isolate* isolate = handles.main_isolate(); |
3487 i::Factory* factory = isolate->factory(); | 3473 Factory* factory = isolate->factory(); |
3488 | 3474 |
3489 const char* function_prologue = | 3475 const char* function_prologue = |
3490 "var f;" | 3476 "var f;" |
3491 "var x = 1;" | 3477 "var x = 1;" |
3492 "function f1() {" | 3478 "function f1() {" |
3493 " eval(\"function t() {"; | 3479 " eval(\"function t() {"; |
3494 const char* function_epilogue = | 3480 const char* function_epilogue = |
3495 " }; f = t;\");" | 3481 " }; f = t;\");" |
3496 "}" | 3482 "}" |
3497 "f1();"; | 3483 "f1();"; |
(...skipping 11 matching lines...) Expand all Loading... |
3509 {init_function_body + "return x = 10;", | 3495 {init_function_body + "return x = 10;", |
3510 handle(Smi::FromInt(10), isolate)}, | 3496 handle(Smi::FromInt(10), isolate)}, |
3511 {"'use strict';" + init_function_body + "x = 20; return x;", | 3497 {"'use strict';" + init_function_body + "x = 20; return x;", |
3512 handle(Smi::FromInt(20), isolate)}, | 3498 handle(Smi::FromInt(20), isolate)}, |
3513 }; | 3499 }; |
3514 | 3500 |
3515 for (size_t i = 0; i < arraysize(lookup_slot); i++) { | 3501 for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
3516 std::string script = std::string(function_prologue) + lookup_slot[i].first + | 3502 std::string script = std::string(function_prologue) + lookup_slot[i].first + |
3517 std::string(function_epilogue); | 3503 std::string(function_epilogue); |
3518 | 3504 |
3519 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); | 3505 InterpreterTester tester(isolate, script.c_str(), "t"); |
3520 auto callable = tester.GetCallable<>(); | 3506 auto callable = tester.GetCallable<>(); |
3521 | 3507 |
3522 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3508 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3523 CHECK(return_value->SameValue(*lookup_slot[i].second)); | 3509 CHECK(return_value->SameValue(*lookup_slot[i].second)); |
3524 } | 3510 } |
3525 } | 3511 } |
3526 | 3512 |
3527 | 3513 |
3528 TEST(InterpreterDeleteLookupSlot) { | 3514 TEST(InterpreterDeleteLookupSlot) { |
3529 HandleAndZoneScope handles; | 3515 HandleAndZoneScope handles; |
3530 i::Isolate* isolate = handles.main_isolate(); | 3516 Isolate* isolate = handles.main_isolate(); |
3531 i::Factory* factory = isolate->factory(); | 3517 Factory* factory = isolate->factory(); |
3532 | 3518 |
3533 // TODO(mythria): Add more tests when we have support for eval/with. | 3519 // TODO(mythria): Add more tests when we have support for eval/with. |
3534 const char* function_prologue = "var f;" | 3520 const char* function_prologue = "var f;" |
3535 "var x = 1;" | 3521 "var x = 1;" |
3536 "y = 10;" | 3522 "y = 10;" |
3537 "var obj = {val:10};" | 3523 "var obj = {val:10};" |
3538 "var z = 30;" | 3524 "var z = 30;" |
3539 "function f1() {" | 3525 "function f1() {" |
3540 " var z = 20;" | 3526 " var z = 20;" |
3541 " eval(\"function t() {"; | 3527 " eval(\"function t() {"; |
3542 const char* function_epilogue = " }; f = t;\");" | 3528 const char* function_epilogue = " }; f = t;\");" |
3543 "}" | 3529 "}" |
3544 "f1();"; | 3530 "f1();"; |
3545 | 3531 |
3546 | 3532 |
3547 std::pair<const char*, Handle<Object>> delete_lookup_slot[] = { | 3533 std::pair<const char*, Handle<Object>> delete_lookup_slot[] = { |
3548 {"return delete x;", factory->false_value()}, | 3534 {"return delete x;", factory->false_value()}, |
3549 {"return delete y;", factory->true_value()}, | 3535 {"return delete y;", factory->true_value()}, |
3550 {"return delete z;", factory->false_value()}, | 3536 {"return delete z;", factory->false_value()}, |
3551 {"return delete obj.val;", factory->true_value()}, | 3537 {"return delete obj.val;", factory->true_value()}, |
3552 {"'use strict'; return delete obj.val;", factory->true_value()}, | 3538 {"'use strict'; return delete obj.val;", factory->true_value()}, |
3553 }; | 3539 }; |
3554 | 3540 |
3555 for (size_t i = 0; i < arraysize(delete_lookup_slot); i++) { | 3541 for (size_t i = 0; i < arraysize(delete_lookup_slot); i++) { |
3556 std::string script = std::string(function_prologue) + | 3542 std::string script = std::string(function_prologue) + |
3557 std::string(delete_lookup_slot[i].first) + | 3543 std::string(delete_lookup_slot[i].first) + |
3558 std::string(function_epilogue); | 3544 std::string(function_epilogue); |
3559 | 3545 |
3560 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); | 3546 InterpreterTester tester(isolate, script.c_str(), "t"); |
3561 auto callable = tester.GetCallable<>(); | 3547 auto callable = tester.GetCallable<>(); |
3562 | 3548 |
3563 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3549 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3564 CHECK(return_value->SameValue(*delete_lookup_slot[i].second)); | 3550 CHECK(return_value->SameValue(*delete_lookup_slot[i].second)); |
3565 } | 3551 } |
3566 } | 3552 } |
3567 | 3553 |
3568 | 3554 |
3569 TEST(JumpWithConstantsAndWideConstants) { | 3555 TEST(JumpWithConstantsAndWideConstants) { |
3570 HandleAndZoneScope handles; | 3556 HandleAndZoneScope handles; |
| 3557 Isolate* isolate = handles.main_isolate(); |
| 3558 Factory* factory = isolate->factory(); |
3571 const int kStep = 13; | 3559 const int kStep = 13; |
3572 for (int constants = 11; constants < 256 + 3 * kStep; constants += kStep) { | 3560 for (int constants = 11; constants < 256 + 3 * kStep; constants += kStep) { |
3573 auto isolate = handles.main_isolate(); | |
3574 auto factory = isolate->factory(); | |
3575 std::ostringstream filler_os; | 3561 std::ostringstream filler_os; |
3576 // Generate a string that consumes constant pool entries and | 3562 // Generate a string that consumes constant pool entries and |
3577 // spread out branch distances in script below. | 3563 // spread out branch distances in script below. |
3578 for (int i = 0; i < constants; i++) { | 3564 for (int i = 0; i < constants; i++) { |
3579 filler_os << "var x_ = 'x_" << i << "';\n"; | 3565 filler_os << "var x_ = 'x_" << i << "';\n"; |
3580 } | 3566 } |
3581 std::string filler(filler_os.str()); | 3567 std::string filler(filler_os.str()); |
3582 std::ostringstream script_os; | 3568 std::ostringstream script_os; |
3583 script_os << "function " << InterpreterTester::function_name() << "(a) {\n"; | 3569 script_os << "function " << InterpreterTester::function_name() << "(a) {\n"; |
3584 script_os << " " << filler; | 3570 script_os << " " << filler; |
3585 script_os << " for (var i = a; i < 2; i++) {\n"; | 3571 script_os << " for (var i = a; i < 2; i++) {\n"; |
3586 script_os << " " << filler; | 3572 script_os << " " << filler; |
3587 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; | 3573 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
3588 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; | 3574 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
3589 script_os << " else { " << filler << " }\n"; | 3575 script_os << " else { " << filler << " }\n"; |
3590 script_os << " }\n"; | 3576 script_os << " }\n"; |
3591 script_os << " return i;\n"; | 3577 script_os << " return i;\n"; |
3592 script_os << "}\n"; | 3578 script_os << "}\n"; |
3593 std::string script(script_os.str()); | 3579 std::string script(script_os.str()); |
3594 for (int a = 0; a < 3; a++) { | 3580 for (int a = 0; a < 3; a++) { |
3595 InterpreterTester tester(handles.main_isolate(), script.c_str()); | 3581 InterpreterTester tester(isolate, script.c_str()); |
3596 auto callable = tester.GetCallable<Handle<Object>>(); | 3582 auto callable = tester.GetCallable<Handle<Object>>(); |
3597 Handle<Object> argument = factory->NewNumberFromInt(a); | 3583 Handle<Object> argument = factory->NewNumberFromInt(a); |
3598 Handle<Object> return_val = callable(argument).ToHandleChecked(); | 3584 Handle<Object> return_val = callable(argument).ToHandleChecked(); |
3599 static const int results[] = {11, 12, 2}; | 3585 static const int results[] = {11, 12, 2}; |
3600 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); | 3586 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
3601 } | 3587 } |
3602 } | 3588 } |
3603 } | 3589 } |
3604 | 3590 |
3605 | 3591 |
3606 TEST(InterpreterEval) { | 3592 TEST(InterpreterEval) { |
3607 HandleAndZoneScope handles; | 3593 HandleAndZoneScope handles; |
3608 i::Isolate* isolate = handles.main_isolate(); | 3594 Isolate* isolate = handles.main_isolate(); |
3609 i::Factory* factory = isolate->factory(); | 3595 Factory* factory = isolate->factory(); |
3610 | 3596 |
3611 std::pair<const char*, Handle<Object>> eval[] = { | 3597 std::pair<const char*, Handle<Object>> eval[] = { |
3612 {"return eval('1;');", handle(Smi::FromInt(1), isolate)}, | 3598 {"return eval('1;');", handle(Smi::FromInt(1), isolate)}, |
3613 {"return eval('100 * 20;');", handle(Smi::FromInt(2000), isolate)}, | 3599 {"return eval('100 * 20;');", handle(Smi::FromInt(2000), isolate)}, |
3614 {"var x = 10; return eval('x + 20;');", | 3600 {"var x = 10; return eval('x + 20;');", |
3615 handle(Smi::FromInt(30), isolate)}, | 3601 handle(Smi::FromInt(30), isolate)}, |
3616 {"var x = 10; eval('x = 33;'); return x;", | 3602 {"var x = 10; eval('x = 33;'); return x;", |
3617 handle(Smi::FromInt(33), isolate)}, | 3603 handle(Smi::FromInt(33), isolate)}, |
3618 {"'use strict'; var x = 20; var z = 0;\n" | 3604 {"'use strict'; var x = 20; var z = 0;\n" |
3619 "eval('var x = 33; z = x;'); return x + z;", | 3605 "eval('var x = 33; z = x;'); return x + z;", |
(...skipping 17 matching lines...) Expand all Loading... |
3637 {"eval('var x = 10;'); return typeof x;", | 3623 {"eval('var x = 10;'); return typeof x;", |
3638 factory->NewStringFromStaticChars("number")}, | 3624 factory->NewStringFromStaticChars("number")}, |
3639 {"var x = {}; eval('var x = 10;'); return typeof x;", | 3625 {"var x = {}; eval('var x = 10;'); return typeof x;", |
3640 factory->NewStringFromStaticChars("number")}, | 3626 factory->NewStringFromStaticChars("number")}, |
3641 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", | 3627 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", |
3642 factory->NewStringFromStaticChars("object")}, | 3628 factory->NewStringFromStaticChars("object")}, |
3643 }; | 3629 }; |
3644 | 3630 |
3645 for (size_t i = 0; i < arraysize(eval); i++) { | 3631 for (size_t i = 0; i < arraysize(eval); i++) { |
3646 std::string source(InterpreterTester::SourceForBody(eval[i].first)); | 3632 std::string source(InterpreterTester::SourceForBody(eval[i].first)); |
3647 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3633 InterpreterTester tester(isolate, source.c_str()); |
3648 auto callable = tester.GetCallable<>(); | 3634 auto callable = tester.GetCallable<>(); |
3649 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3635 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3650 CHECK(return_value->SameValue(*eval[i].second)); | 3636 CHECK(return_value->SameValue(*eval[i].second)); |
3651 } | 3637 } |
3652 } | 3638 } |
3653 | 3639 |
3654 | 3640 |
3655 TEST(InterpreterEvalParams) { | 3641 TEST(InterpreterEvalParams) { |
3656 HandleAndZoneScope handles; | 3642 HandleAndZoneScope handles; |
3657 i::Isolate* isolate = handles.main_isolate(); | 3643 Isolate* isolate = handles.main_isolate(); |
3658 | 3644 |
3659 std::pair<const char*, Handle<Object>> eval_params[] = { | 3645 std::pair<const char*, Handle<Object>> eval_params[] = { |
3660 {"var x = 10; return eval('x + p1;');", | 3646 {"var x = 10; return eval('x + p1;');", |
3661 handle(Smi::FromInt(30), isolate)}, | 3647 handle(Smi::FromInt(30), isolate)}, |
3662 {"var x = 10; eval('p1 = x;'); return p1;", | 3648 {"var x = 10; eval('p1 = x;'); return p1;", |
3663 handle(Smi::FromInt(10), isolate)}, | 3649 handle(Smi::FromInt(10), isolate)}, |
3664 {"var a = 10;" | 3650 {"var a = 10;" |
3665 "function inner() { return eval('a + p1;');}" | 3651 "function inner() { return eval('a + p1;');}" |
3666 "return inner();", | 3652 "return inner();", |
3667 handle(Smi::FromInt(30), isolate)}, | 3653 handle(Smi::FromInt(30), isolate)}, |
3668 }; | 3654 }; |
3669 | 3655 |
3670 for (size_t i = 0; i < arraysize(eval_params); i++) { | 3656 for (size_t i = 0; i < arraysize(eval_params); i++) { |
3671 std::string source = "function " + InterpreterTester::function_name() + | 3657 std::string source = "function " + InterpreterTester::function_name() + |
3672 "(p1) {" + eval_params[i].first + "}"; | 3658 "(p1) {" + eval_params[i].first + "}"; |
3673 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3659 InterpreterTester tester(isolate, source.c_str()); |
3674 auto callable = tester.GetCallable<Handle<Object>>(); | 3660 auto callable = tester.GetCallable<Handle<Object>>(); |
3675 | 3661 |
3676 Handle<i::Object> return_value = | 3662 Handle<i::Object> return_value = |
3677 callable(handle(Smi::FromInt(20), isolate)).ToHandleChecked(); | 3663 callable(handle(Smi::FromInt(20), isolate)).ToHandleChecked(); |
3678 CHECK(return_value->SameValue(*eval_params[i].second)); | 3664 CHECK(return_value->SameValue(*eval_params[i].second)); |
3679 } | 3665 } |
3680 } | 3666 } |
3681 | 3667 |
3682 | 3668 |
3683 TEST(InterpreterEvalGlobal) { | 3669 TEST(InterpreterEvalGlobal) { |
3684 HandleAndZoneScope handles; | 3670 HandleAndZoneScope handles; |
3685 i::Isolate* isolate = handles.main_isolate(); | 3671 Isolate* isolate = handles.main_isolate(); |
3686 i::Factory* factory = isolate->factory(); | 3672 Factory* factory = isolate->factory(); |
3687 | 3673 |
3688 std::pair<const char*, Handle<Object>> eval_global[] = { | 3674 std::pair<const char*, Handle<Object>> eval_global[] = { |
3689 {"function add_global() { eval('function test() { z = 33; }; test()'); };" | 3675 {"function add_global() { eval('function test() { z = 33; }; test()'); };" |
3690 "function f() { add_global(); return z; }; f();", | 3676 "function f() { add_global(); return z; }; f();", |
3691 handle(Smi::FromInt(33), isolate)}, | 3677 handle(Smi::FromInt(33), isolate)}, |
3692 {"function add_global() {\n" | 3678 {"function add_global() {\n" |
3693 " eval('\"use strict\"; function test() { y = 33; };" | 3679 " eval('\"use strict\"; function test() { y = 33; };" |
3694 " try { test() } catch(e) {}');\n" | 3680 " try { test() } catch(e) {}');\n" |
3695 "}\n" | 3681 "}\n" |
3696 "function f() { add_global(); return typeof y; } f();", | 3682 "function f() { add_global(); return typeof y; } f();", |
3697 factory->NewStringFromStaticChars("undefined")}, | 3683 factory->NewStringFromStaticChars("undefined")}, |
3698 }; | 3684 }; |
3699 | 3685 |
3700 for (size_t i = 0; i < arraysize(eval_global); i++) { | 3686 for (size_t i = 0; i < arraysize(eval_global); i++) { |
3701 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, | 3687 InterpreterTester tester(isolate, eval_global[i].first, "test"); |
3702 "test"); | |
3703 auto callable = tester.GetCallable<>(); | 3688 auto callable = tester.GetCallable<>(); |
3704 | 3689 |
3705 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3690 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3706 CHECK(return_value->SameValue(*eval_global[i].second)); | 3691 CHECK(return_value->SameValue(*eval_global[i].second)); |
3707 } | 3692 } |
3708 } | 3693 } |
3709 | 3694 |
3710 | 3695 |
3711 TEST(InterpreterEvalVariableDecl) { | 3696 TEST(InterpreterEvalVariableDecl) { |
3712 HandleAndZoneScope handles; | 3697 HandleAndZoneScope handles; |
3713 i::Isolate* isolate = handles.main_isolate(); | 3698 Isolate* isolate = handles.main_isolate(); |
3714 i::Factory* factory = isolate->factory(); | 3699 Factory* factory = isolate->factory(); |
3715 | 3700 |
3716 std::pair<const char*, Handle<Object>> eval_global[] = { | 3701 std::pair<const char*, Handle<Object>> eval_global[] = { |
3717 {"function f() { eval('var x = 10; x++;'); return x; }", | 3702 {"function f() { eval('var x = 10; x++;'); return x; }", |
3718 handle(Smi::FromInt(11), isolate)}, | 3703 handle(Smi::FromInt(11), isolate)}, |
3719 {"function f() { var x = 20; eval('var x = 10; x++;'); return x; }", | 3704 {"function f() { var x = 20; eval('var x = 10; x++;'); return x; }", |
3720 handle(Smi::FromInt(11), isolate)}, | 3705 handle(Smi::FromInt(11), isolate)}, |
3721 {"function f() {" | 3706 {"function f() {" |
3722 " var x = 20;" | 3707 " var x = 20;" |
3723 " eval('\"use strict\"; var x = 10; x++;');" | 3708 " eval('\"use strict\"; var x = 10; x++;');" |
3724 " return x; }", | 3709 " return x; }", |
(...skipping 17 matching lines...) Expand all Loading... |
3742 " eval('\"use strict\"; " | 3727 " eval('\"use strict\"; " |
3743 " var x = 20; " | 3728 " var x = 20; " |
3744 " get_eval_x = function func() {return x;};');\n" | 3729 " get_eval_x = function func() {return x;};');\n" |
3745 " return get_eval_x() + x;\n" | 3730 " return get_eval_x() + x;\n" |
3746 "}", | 3731 "}", |
3747 handle(Smi::FromInt(23), isolate)}, | 3732 handle(Smi::FromInt(23), isolate)}, |
3748 // TODO(mythria): Add tests with const declarations. | 3733 // TODO(mythria): Add tests with const declarations. |
3749 }; | 3734 }; |
3750 | 3735 |
3751 for (size_t i = 0; i < arraysize(eval_global); i++) { | 3736 for (size_t i = 0; i < arraysize(eval_global); i++) { |
3752 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, "*"); | 3737 InterpreterTester tester(isolate, eval_global[i].first, "*"); |
3753 auto callable = tester.GetCallable<>(); | 3738 auto callable = tester.GetCallable<>(); |
3754 | 3739 |
3755 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3740 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3756 CHECK(return_value->SameValue(*eval_global[i].second)); | 3741 CHECK(return_value->SameValue(*eval_global[i].second)); |
3757 } | 3742 } |
3758 } | 3743 } |
3759 | 3744 |
3760 | 3745 |
3761 TEST(InterpreterEvalFunctionDecl) { | 3746 TEST(InterpreterEvalFunctionDecl) { |
3762 HandleAndZoneScope handles; | 3747 HandleAndZoneScope handles; |
3763 i::Isolate* isolate = handles.main_isolate(); | 3748 Isolate* isolate = handles.main_isolate(); |
3764 | 3749 |
3765 std::pair<const char*, Handle<Object>> eval_func_decl[] = { | 3750 std::pair<const char*, Handle<Object>> eval_func_decl[] = { |
3766 {"function f() {\n" | 3751 {"function f() {\n" |
3767 " var x = 3;\n" | 3752 " var x = 3;\n" |
3768 " eval('var x = 20;" | 3753 " eval('var x = 20;" |
3769 " function get_x() {return x;};');\n" | 3754 " function get_x() {return x;};');\n" |
3770 " return get_x() + x;\n" | 3755 " return get_x() + x;\n" |
3771 "}", | 3756 "}", |
3772 handle(Smi::FromInt(40), isolate)}, | 3757 handle(Smi::FromInt(40), isolate)}, |
3773 }; | 3758 }; |
3774 | 3759 |
3775 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { | 3760 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { |
3776 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first, | 3761 InterpreterTester tester(isolate, eval_func_decl[i].first, "*"); |
3777 "*"); | |
3778 auto callable = tester.GetCallable<>(); | 3762 auto callable = tester.GetCallable<>(); |
3779 | 3763 |
3780 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3764 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3781 CHECK(return_value->SameValue(*eval_func_decl[i].second)); | 3765 CHECK(return_value->SameValue(*eval_func_decl[i].second)); |
3782 } | 3766 } |
3783 } | 3767 } |
3784 | 3768 |
3785 TEST(InterpreterWideRegisterArithmetic) { | 3769 TEST(InterpreterWideRegisterArithmetic) { |
3786 HandleAndZoneScope handles; | 3770 HandleAndZoneScope handles; |
3787 i::Isolate* isolate = handles.main_isolate(); | 3771 Isolate* isolate = handles.main_isolate(); |
3788 | 3772 |
3789 static const size_t kMaxRegisterForTest = 150; | 3773 static const size_t kMaxRegisterForTest = 150; |
3790 std::ostringstream os; | 3774 std::ostringstream os; |
3791 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; | 3775 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
3792 os << " var retval = -77;\n"; | 3776 os << " var retval = -77;\n"; |
3793 for (size_t i = 0; i < kMaxRegisterForTest; i++) { | 3777 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
3794 os << " var x" << i << " = " << i << ";\n"; | 3778 os << " var x" << i << " = " << i << ";\n"; |
3795 } | 3779 } |
3796 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { | 3780 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
3797 size_t j = kMaxRegisterForTest - i - 1; | 3781 size_t j = kMaxRegisterForTest - i - 1; |
3798 os << " var tmp = x" << j << ";\n"; | 3782 os << " var tmp = x" << j << ";\n"; |
3799 os << " var x" << j << " = x" << i << ";\n"; | 3783 os << " var x" << j << " = x" << i << ";\n"; |
3800 os << " var x" << i << " = tmp;\n"; | 3784 os << " var x" << i << " = tmp;\n"; |
3801 } | 3785 } |
3802 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { | 3786 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
3803 size_t j = kMaxRegisterForTest - i - 1; | 3787 size_t j = kMaxRegisterForTest - i - 1; |
3804 os << " var tmp = x" << j << ";\n"; | 3788 os << " var tmp = x" << j << ";\n"; |
3805 os << " var x" << j << " = x" << i << ";\n"; | 3789 os << " var x" << j << " = x" << i << ";\n"; |
3806 os << " var x" << i << " = tmp;\n"; | 3790 os << " var x" << i << " = tmp;\n"; |
3807 } | 3791 } |
3808 for (size_t i = 0; i < kMaxRegisterForTest; i++) { | 3792 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
3809 os << " if (arg == " << i << ") {\n" // | 3793 os << " if (arg == " << i << ") {\n" // |
3810 << " retval = x" << i << ";\n" // | 3794 << " retval = x" << i << ";\n" // |
3811 << " }\n"; // | 3795 << " }\n"; // |
3812 } | 3796 } |
3813 os << " return retval;\n"; | 3797 os << " return retval;\n"; |
3814 os << "}\n"; | 3798 os << "}\n"; |
3815 | 3799 |
3816 std::string source = os.str(); | 3800 std::string source = os.str(); |
3817 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3801 InterpreterTester tester(isolate, source.c_str()); |
3818 auto callable = tester.GetCallable<Handle<Object>>(); | 3802 auto callable = tester.GetCallable<Handle<Object>>(); |
3819 for (size_t i = 0; i < kMaxRegisterForTest; i++) { | 3803 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
3820 Handle<Object> arg = handle(Smi::FromInt(static_cast<int>(i)), isolate); | 3804 Handle<Object> arg = handle(Smi::FromInt(static_cast<int>(i)), isolate); |
3821 Handle<Object> return_value = callable(arg).ToHandleChecked(); | 3805 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
3822 CHECK(return_value->SameValue(*arg)); | 3806 CHECK(return_value->SameValue(*arg)); |
3823 } | 3807 } |
3824 } | 3808 } |
3825 | 3809 |
3826 TEST(InterpreterCallWideRegisters) { | 3810 TEST(InterpreterCallWideRegisters) { |
3827 static const int kPeriod = 25; | 3811 static const int kPeriod = 25; |
3828 static const int kLength = 512; | 3812 static const int kLength = 512; |
3829 static const int kStartChar = 65; | 3813 static const int kStartChar = 65; |
3830 | 3814 |
| 3815 HandleAndZoneScope handles; |
| 3816 Isolate* isolate = handles.main_isolate(); |
| 3817 |
3831 for (int pass = 0; pass < 3; pass += 1) { | 3818 for (int pass = 0; pass < 3; pass += 1) { |
3832 std::ostringstream os; | 3819 std::ostringstream os; |
3833 for (int i = 0; i < pass * 97; i += 1) { | 3820 for (int i = 0; i < pass * 97; i += 1) { |
3834 os << "var x" << i << " = " << i << "\n"; | 3821 os << "var x" << i << " = " << i << "\n"; |
3835 } | 3822 } |
3836 os << "return String.fromCharCode("; | 3823 os << "return String.fromCharCode("; |
3837 os << kStartChar; | 3824 os << kStartChar; |
3838 for (int i = 1; i < kLength; i += 1) { | 3825 for (int i = 1; i < kLength; i += 1) { |
3839 os << "," << kStartChar + (i % kPeriod); | 3826 os << "," << kStartChar + (i % kPeriod); |
3840 } | 3827 } |
3841 os << ");"; | 3828 os << ");"; |
3842 std::string source = InterpreterTester::SourceForBody(os.str().c_str()); | 3829 std::string source = InterpreterTester::SourceForBody(os.str().c_str()); |
3843 HandleAndZoneScope handles; | 3830 InterpreterTester tester(isolate, source.c_str()); |
3844 InterpreterTester tester(handles.main_isolate(), source.c_str()); | |
3845 auto callable = tester.GetCallable(); | 3831 auto callable = tester.GetCallable(); |
3846 Handle<Object> return_val = callable().ToHandleChecked(); | 3832 Handle<Object> return_val = callable().ToHandleChecked(); |
3847 Handle<String> return_string = Handle<String>::cast(return_val); | 3833 Handle<String> return_string = Handle<String>::cast(return_val); |
3848 CHECK_EQ(return_string->length(), kLength); | 3834 CHECK_EQ(return_string->length(), kLength); |
3849 for (int i = 0; i < kLength; i += 1) { | 3835 for (int i = 0; i < kLength; i += 1) { |
3850 CHECK_EQ(return_string->Get(i), 65 + (i % kPeriod)); | 3836 CHECK_EQ(return_string->Get(i), 65 + (i % kPeriod)); |
3851 } | 3837 } |
3852 } | 3838 } |
3853 } | 3839 } |
3854 | 3840 |
3855 TEST(InterpreterWideParametersPickOne) { | 3841 TEST(InterpreterWideParametersPickOne) { |
| 3842 HandleAndZoneScope handles; |
| 3843 Isolate* isolate = handles.main_isolate(); |
3856 static const int kParameterCount = 130; | 3844 static const int kParameterCount = 130; |
3857 for (int parameter = 0; parameter < 10; parameter++) { | 3845 for (int parameter = 0; parameter < 10; parameter++) { |
3858 HandleAndZoneScope handles; | |
3859 i::Isolate* isolate = handles.main_isolate(); | |
3860 std::ostringstream os; | 3846 std::ostringstream os; |
3861 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; | 3847 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
3862 os << " function selector(i"; | 3848 os << " function selector(i"; |
3863 for (int i = 0; i < kParameterCount; i++) { | 3849 for (int i = 0; i < kParameterCount; i++) { |
3864 os << "," | 3850 os << "," |
3865 << "a" << i; | 3851 << "a" << i; |
3866 } | 3852 } |
3867 os << ") {\n"; | 3853 os << ") {\n"; |
3868 os << " return a" << parameter << ";\n"; | 3854 os << " return a" << parameter << ";\n"; |
3869 os << " };\n"; | 3855 os << " };\n"; |
3870 os << " return selector(arg"; | 3856 os << " return selector(arg"; |
3871 for (int i = 0; i < kParameterCount; i++) { | 3857 for (int i = 0; i < kParameterCount; i++) { |
3872 os << "," << i; | 3858 os << "," << i; |
3873 } | 3859 } |
3874 os << ");"; | 3860 os << ");"; |
3875 os << "}\n"; | 3861 os << "}\n"; |
3876 | 3862 |
3877 std::string source = os.str(); | 3863 std::string source = os.str(); |
3878 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 3864 InterpreterTester tester(isolate, source.c_str(), "*"); |
3879 auto callable = tester.GetCallable<Handle<Object>>(); | 3865 auto callable = tester.GetCallable<Handle<Object>>(); |
3880 Handle<Object> arg = handle(Smi::FromInt(0xaa55), isolate); | 3866 Handle<Object> arg = handle(Smi::FromInt(0xaa55), isolate); |
3881 Handle<Object> return_value = callable(arg).ToHandleChecked(); | 3867 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
3882 Handle<Smi> actual = Handle<Smi>::cast(return_value); | 3868 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
3883 CHECK_EQ(actual->value(), parameter); | 3869 CHECK_EQ(actual->value(), parameter); |
3884 } | 3870 } |
3885 } | 3871 } |
3886 | 3872 |
3887 TEST(InterpreterWideParametersSummation) { | 3873 TEST(InterpreterWideParametersSummation) { |
3888 static int kParameterCount = 200; | 3874 static int kParameterCount = 200; |
3889 static int kBaseValue = 17000; | 3875 static int kBaseValue = 17000; |
3890 HandleAndZoneScope handles; | 3876 HandleAndZoneScope handles; |
3891 i::Isolate* isolate = handles.main_isolate(); | 3877 Isolate* isolate = handles.main_isolate(); |
3892 std::ostringstream os; | 3878 std::ostringstream os; |
3893 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; | 3879 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
3894 os << " function summation(i"; | 3880 os << " function summation(i"; |
3895 for (int i = 0; i < kParameterCount; i++) { | 3881 for (int i = 0; i < kParameterCount; i++) { |
3896 os << "," | 3882 os << "," |
3897 << "a" << i; | 3883 << "a" << i; |
3898 } | 3884 } |
3899 os << ") {\n"; | 3885 os << ") {\n"; |
3900 os << " var sum = " << kBaseValue << ";\n"; | 3886 os << " var sum = " << kBaseValue << ";\n"; |
3901 os << " switch(i) {\n"; | 3887 os << " switch(i) {\n"; |
3902 for (int i = 0; i < kParameterCount; i++) { | 3888 for (int i = 0; i < kParameterCount; i++) { |
3903 int j = kParameterCount - i - 1; | 3889 int j = kParameterCount - i - 1; |
3904 os << " case " << j << ": sum += a" << j << ";\n"; | 3890 os << " case " << j << ": sum += a" << j << ";\n"; |
3905 } | 3891 } |
3906 os << " }\n"; | 3892 os << " }\n"; |
3907 os << " return sum;\n"; | 3893 os << " return sum;\n"; |
3908 os << " };\n"; | 3894 os << " };\n"; |
3909 os << " return summation(arg"; | 3895 os << " return summation(arg"; |
3910 for (int i = 0; i < kParameterCount; i++) { | 3896 for (int i = 0; i < kParameterCount; i++) { |
3911 os << "," << i; | 3897 os << "," << i; |
3912 } | 3898 } |
3913 os << ");"; | 3899 os << ");"; |
3914 os << "}\n"; | 3900 os << "}\n"; |
3915 | 3901 |
3916 std::string source = os.str(); | 3902 std::string source = os.str(); |
3917 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 3903 InterpreterTester tester(isolate, source.c_str(), "*"); |
3918 auto callable = tester.GetCallable<Handle<Object>>(); | 3904 auto callable = tester.GetCallable<Handle<Object>>(); |
3919 for (int i = 0; i < kParameterCount; i++) { | 3905 for (int i = 0; i < kParameterCount; i++) { |
3920 Handle<Object> arg = handle(Smi::FromInt(i), isolate); | 3906 Handle<Object> arg = handle(Smi::FromInt(i), isolate); |
3921 Handle<Object> return_value = callable(arg).ToHandleChecked(); | 3907 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
3922 int expected = kBaseValue + i * (i + 1) / 2; | 3908 int expected = kBaseValue + i * (i + 1) / 2; |
3923 Handle<Smi> actual = Handle<Smi>::cast(return_value); | 3909 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
3924 CHECK_EQ(actual->value(), expected); | 3910 CHECK_EQ(actual->value(), expected); |
3925 } | 3911 } |
3926 } | 3912 } |
3927 | 3913 |
3928 TEST(InterpreterDoExpression) { | 3914 TEST(InterpreterDoExpression) { |
3929 bool old_flag = FLAG_harmony_do_expressions; | 3915 bool old_flag = FLAG_harmony_do_expressions; |
3930 FLAG_harmony_do_expressions = true; | 3916 FLAG_harmony_do_expressions = true; |
3931 | 3917 |
3932 HandleAndZoneScope handles; | 3918 HandleAndZoneScope handles; |
3933 i::Isolate* isolate = handles.main_isolate(); | 3919 Isolate* isolate = handles.main_isolate(); |
3934 Factory* factory = isolate->factory(); | 3920 Factory* factory = isolate->factory(); |
3935 | 3921 |
3936 std::pair<const char*, Handle<Object>> do_expr[] = { | 3922 std::pair<const char*, Handle<Object>> do_expr[] = { |
3937 {"var a = do {}; return a;", factory->undefined_value()}, | 3923 {"var a = do {}; return a;", factory->undefined_value()}, |
3938 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, | 3924 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, |
3939 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, | 3925 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, |
3940 {"var a = do { var x = 100; x++; }; return a;", | 3926 {"var a = do { var x = 100; x++; }; return a;", |
3941 handle(Smi::FromInt(100), isolate)}, | 3927 handle(Smi::FromInt(100), isolate)}, |
3942 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" | 3928 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" |
3943 "return i;", | 3929 "return i;", |
3944 handle(Smi::FromInt(3), isolate)}, | 3930 handle(Smi::FromInt(3), isolate)}, |
3945 }; | 3931 }; |
3946 | 3932 |
3947 for (size_t i = 0; i < arraysize(do_expr); i++) { | 3933 for (size_t i = 0; i < arraysize(do_expr); i++) { |
3948 std::string source(InterpreterTester::SourceForBody(do_expr[i].first)); | 3934 std::string source(InterpreterTester::SourceForBody(do_expr[i].first)); |
3949 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3935 InterpreterTester tester(isolate, source.c_str()); |
3950 auto callable = tester.GetCallable<>(); | 3936 auto callable = tester.GetCallable<>(); |
3951 | 3937 |
3952 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3938 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3953 CHECK(return_value->SameValue(*do_expr[i].second)); | 3939 CHECK(return_value->SameValue(*do_expr[i].second)); |
3954 } | 3940 } |
3955 | 3941 |
3956 FLAG_harmony_do_expressions = old_flag; | 3942 FLAG_harmony_do_expressions = old_flag; |
3957 } | 3943 } |
3958 | 3944 |
3959 TEST(InterpreterWithStatement) { | 3945 TEST(InterpreterWithStatement) { |
3960 HandleAndZoneScope handles; | 3946 HandleAndZoneScope handles; |
3961 i::Isolate* isolate = handles.main_isolate(); | 3947 Isolate* isolate = handles.main_isolate(); |
3962 | 3948 |
3963 std::pair<const char*, Handle<Object>> with_stmt[] = { | 3949 std::pair<const char*, Handle<Object>> with_stmt[] = { |
3964 {"with({x:42}) return x;", handle(Smi::FromInt(42), isolate)}, | 3950 {"with({x:42}) return x;", handle(Smi::FromInt(42), isolate)}, |
3965 {"with({}) { var y = 10; return y;}", handle(Smi::FromInt(10), isolate)}, | 3951 {"with({}) { var y = 10; return y;}", handle(Smi::FromInt(10), isolate)}, |
3966 {"var y = {x:42};" | 3952 {"var y = {x:42};" |
3967 " function inner() {" | 3953 " function inner() {" |
3968 " var x = 20;" | 3954 " var x = 20;" |
3969 " with(y) return x;" | 3955 " with(y) return x;" |
3970 "}" | 3956 "}" |
3971 "return inner();", | 3957 "return inner();", |
3972 handle(Smi::FromInt(42), isolate)}, | 3958 handle(Smi::FromInt(42), isolate)}, |
3973 {"var y = {x:42};" | 3959 {"var y = {x:42};" |
3974 " function inner(o) {" | 3960 " function inner(o) {" |
3975 " var x = 20;" | 3961 " var x = 20;" |
3976 " with(o) return x;" | 3962 " with(o) return x;" |
3977 "}" | 3963 "}" |
3978 "return inner(y);", | 3964 "return inner(y);", |
3979 handle(Smi::FromInt(42), isolate)}, | 3965 handle(Smi::FromInt(42), isolate)}, |
3980 }; | 3966 }; |
3981 | 3967 |
3982 for (size_t i = 0; i < arraysize(with_stmt); i++) { | 3968 for (size_t i = 0; i < arraysize(with_stmt); i++) { |
3983 std::string source(InterpreterTester::SourceForBody(with_stmt[i].first)); | 3969 std::string source(InterpreterTester::SourceForBody(with_stmt[i].first)); |
3984 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3970 InterpreterTester tester(isolate, source.c_str()); |
3985 auto callable = tester.GetCallable<>(); | 3971 auto callable = tester.GetCallable<>(); |
3986 | 3972 |
3987 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3973 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3988 CHECK(return_value->SameValue(*with_stmt[i].second)); | 3974 CHECK(return_value->SameValue(*with_stmt[i].second)); |
3989 } | 3975 } |
3990 } | 3976 } |
3991 | 3977 |
3992 TEST(InterpreterClassLiterals) { | 3978 TEST(InterpreterClassLiterals) { |
3993 HandleAndZoneScope handles; | 3979 HandleAndZoneScope handles; |
3994 i::Isolate* isolate = handles.main_isolate(); | 3980 Isolate* isolate = handles.main_isolate(); |
3995 std::pair<const char*, Handle<Object>> examples[] = { | 3981 std::pair<const char*, Handle<Object>> examples[] = { |
3996 {"class C {\n" | 3982 {"class C {\n" |
3997 " constructor(x) { this.x_ = x; }\n" | 3983 " constructor(x) { this.x_ = x; }\n" |
3998 " method() { return this.x_; }\n" | 3984 " method() { return this.x_; }\n" |
3999 "}\n" | 3985 "}\n" |
4000 "return new C(99).method();", | 3986 "return new C(99).method();", |
4001 handle(Smi::FromInt(99), isolate)}, | 3987 handle(Smi::FromInt(99), isolate)}, |
4002 {"class C {\n" | 3988 {"class C {\n" |
4003 " constructor(x) { this.x_ = x; }\n" | 3989 " constructor(x) { this.x_ = x; }\n" |
4004 " static static_method(x) { return x; }\n" | 3990 " static static_method(x) { return x; }\n" |
(...skipping 30 matching lines...) Expand all Loading... |
4035 {"var method = 'f';" | 4021 {"var method = 'f';" |
4036 "class C {\n" | 4022 "class C {\n" |
4037 " [method]() { return 106; }\n" | 4023 " [method]() { return 106; }\n" |
4038 "}\n" | 4024 "}\n" |
4039 "return new C().f();", | 4025 "return new C().f();", |
4040 handle(Smi::FromInt(106), isolate)}, | 4026 handle(Smi::FromInt(106), isolate)}, |
4041 }; | 4027 }; |
4042 | 4028 |
4043 for (size_t i = 0; i < arraysize(examples); ++i) { | 4029 for (size_t i = 0; i < arraysize(examples); ++i) { |
4044 std::string source(InterpreterTester::SourceForBody(examples[i].first)); | 4030 std::string source(InterpreterTester::SourceForBody(examples[i].first)); |
4045 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 4031 InterpreterTester tester(isolate, source.c_str(), "*"); |
4046 auto callable = tester.GetCallable<>(); | 4032 auto callable = tester.GetCallable<>(); |
4047 | 4033 |
4048 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4034 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4049 CHECK(return_value->SameValue(*examples[i].second)); | 4035 CHECK(return_value->SameValue(*examples[i].second)); |
4050 } | 4036 } |
4051 } | 4037 } |
4052 | 4038 |
4053 TEST(InterpreterClassAndSuperClass) { | 4039 TEST(InterpreterClassAndSuperClass) { |
4054 HandleAndZoneScope handles; | 4040 HandleAndZoneScope handles; |
4055 i::Isolate* isolate = handles.main_isolate(); | 4041 Isolate* isolate = handles.main_isolate(); |
4056 std::pair<const char*, Handle<Object>> examples[] = { | 4042 std::pair<const char*, Handle<Object>> examples[] = { |
4057 {"class A {\n" | 4043 {"class A {\n" |
4058 " constructor(x) { this.x_ = x; }\n" | 4044 " constructor(x) { this.x_ = x; }\n" |
4059 " method() { return this.x_; }\n" | 4045 " method() { return this.x_; }\n" |
4060 "}\n" | 4046 "}\n" |
4061 "class B extends A {\n" | 4047 "class B extends A {\n" |
4062 " constructor(x, y) { super(x); this.y_ = y; }\n" | 4048 " constructor(x, y) { super(x); this.y_ = y; }\n" |
4063 " method() { return super.method() + 1; }\n" | 4049 " method() { return super.method() + 1; }\n" |
4064 "}\n" | 4050 "}\n" |
4065 "return new B(998, 0).method();\n", | 4051 "return new B(998, 0).method();\n", |
(...skipping 29 matching lines...) Expand all Loading... |
4095 "return new B().method();\n", | 4081 "return new B().method();\n", |
4096 handle(Smi::FromInt(1), isolate)}, | 4082 handle(Smi::FromInt(1), isolate)}, |
4097 {"var object = { setY(v) { super.y = v; }};\n" | 4083 {"var object = { setY(v) { super.y = v; }};\n" |
4098 "object.setY(10);\n" | 4084 "object.setY(10);\n" |
4099 "return object.y;\n", | 4085 "return object.y;\n", |
4100 handle(Smi::FromInt(10), isolate)}, | 4086 handle(Smi::FromInt(10), isolate)}, |
4101 }; | 4087 }; |
4102 | 4088 |
4103 for (size_t i = 0; i < arraysize(examples); ++i) { | 4089 for (size_t i = 0; i < arraysize(examples); ++i) { |
4104 std::string source(InterpreterTester::SourceForBody(examples[i].first)); | 4090 std::string source(InterpreterTester::SourceForBody(examples[i].first)); |
4105 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 4091 InterpreterTester tester(isolate, source.c_str(), "*"); |
4106 auto callable = tester.GetCallable<>(); | 4092 auto callable = tester.GetCallable<>(); |
4107 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4093 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4108 CHECK(return_value->SameValue(*examples[i].second)); | 4094 CHECK(return_value->SameValue(*examples[i].second)); |
4109 } | 4095 } |
4110 } | 4096 } |
4111 | 4097 |
4112 TEST(InterpreterConstDeclaration) { | 4098 TEST(InterpreterConstDeclaration) { |
4113 HandleAndZoneScope handles; | 4099 HandleAndZoneScope handles; |
4114 i::Isolate* isolate = handles.main_isolate(); | 4100 Isolate* isolate = handles.main_isolate(); |
4115 i::Factory* factory = isolate->factory(); | 4101 Factory* factory = isolate->factory(); |
4116 | 4102 |
4117 std::pair<const char*, Handle<Object>> const_decl[] = { | 4103 std::pair<const char*, Handle<Object>> const_decl[] = { |
4118 {"const x = 3; return x;", handle(Smi::FromInt(3), isolate)}, | 4104 {"const x = 3; return x;", handle(Smi::FromInt(3), isolate)}, |
4119 {"let x = 10; x = x + 20; return x;", handle(Smi::FromInt(30), isolate)}, | 4105 {"let x = 10; x = x + 20; return x;", handle(Smi::FromInt(30), isolate)}, |
4120 {"let x = 10; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, | 4106 {"let x = 10; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
4121 {"let x; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, | 4107 {"let x; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
4122 {"let x; return x;", factory->undefined_value()}, | 4108 {"let x; return x;", factory->undefined_value()}, |
4123 {"var x = 10; { let x = 30; } return x;", | 4109 {"var x = 10; { let x = 30; } return x;", |
4124 handle(Smi::FromInt(10), isolate)}, | 4110 handle(Smi::FromInt(10), isolate)}, |
4125 {"let x = 10; { let x = 20; } return x;", | 4111 {"let x = 10; { let x = 20; } return x;", |
(...skipping 11 matching lines...) Expand all Loading... |
4137 " const x = i;\n" // const declarations are block scoped. | 4123 " const x = i;\n" // const declarations are block scoped. |
4138 " a = a + x;\n" | 4124 " a = a + x;\n" |
4139 "}\n" | 4125 "}\n" |
4140 "return a;\n", | 4126 "return a;\n", |
4141 handle(Smi::FromInt(55), isolate)}, | 4127 handle(Smi::FromInt(55), isolate)}, |
4142 }; | 4128 }; |
4143 | 4129 |
4144 // Tests for sloppy mode. | 4130 // Tests for sloppy mode. |
4145 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4131 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4146 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); | 4132 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); |
4147 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4133 InterpreterTester tester(isolate, source.c_str()); |
4148 auto callable = tester.GetCallable<>(); | 4134 auto callable = tester.GetCallable<>(); |
4149 | 4135 |
4150 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4136 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4151 CHECK(return_value->SameValue(*const_decl[i].second)); | 4137 CHECK(return_value->SameValue(*const_decl[i].second)); |
4152 } | 4138 } |
4153 | 4139 |
4154 // Tests for strict mode. | 4140 // Tests for strict mode. |
4155 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4141 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4156 std::string strict_body = | 4142 std::string strict_body = |
4157 "'use strict'; " + std::string(const_decl[i].first); | 4143 "'use strict'; " + std::string(const_decl[i].first); |
4158 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); | 4144 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); |
4159 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4145 InterpreterTester tester(isolate, source.c_str()); |
4160 auto callable = tester.GetCallable<>(); | 4146 auto callable = tester.GetCallable<>(); |
4161 | 4147 |
4162 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4148 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4163 CHECK(return_value->SameValue(*const_decl[i].second)); | 4149 CHECK(return_value->SameValue(*const_decl[i].second)); |
4164 } | 4150 } |
4165 } | 4151 } |
4166 | 4152 |
4167 TEST(InterpreterConstDeclarationLookupSlots) { | 4153 TEST(InterpreterConstDeclarationLookupSlots) { |
4168 HandleAndZoneScope handles; | 4154 HandleAndZoneScope handles; |
4169 i::Isolate* isolate = handles.main_isolate(); | 4155 Isolate* isolate = handles.main_isolate(); |
4170 i::Factory* factory = isolate->factory(); | 4156 Factory* factory = isolate->factory(); |
4171 | 4157 |
4172 std::pair<const char*, Handle<Object>> const_decl[] = { | 4158 std::pair<const char*, Handle<Object>> const_decl[] = { |
4173 {"const x = 3; function f1() {return x;}; return x;", | 4159 {"const x = 3; function f1() {return x;}; return x;", |
4174 handle(Smi::FromInt(3), isolate)}, | 4160 handle(Smi::FromInt(3), isolate)}, |
4175 {"let x = 10; x = x + 20; function f1() {return x;}; return x;", | 4161 {"let x = 10; x = x + 20; function f1() {return x;}; return x;", |
4176 handle(Smi::FromInt(30), isolate)}, | 4162 handle(Smi::FromInt(30), isolate)}, |
4177 {"let x; x = 20; function f1() {return x;}; return x;", | 4163 {"let x; x = 20; function f1() {return x;}; return x;", |
4178 handle(Smi::FromInt(20), isolate)}, | 4164 handle(Smi::FromInt(20), isolate)}, |
4179 {"let x; function f1() {return x;}; return x;", | 4165 {"let x; function f1() {return x;}; return x;", |
4180 factory->undefined_value()}, | 4166 factory->undefined_value()}, |
4181 }; | 4167 }; |
4182 | 4168 |
4183 // Tests for sloppy mode. | 4169 // Tests for sloppy mode. |
4184 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4170 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4185 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); | 4171 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); |
4186 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4172 InterpreterTester tester(isolate, source.c_str()); |
4187 auto callable = tester.GetCallable<>(); | 4173 auto callable = tester.GetCallable<>(); |
4188 | 4174 |
4189 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4175 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4190 CHECK(return_value->SameValue(*const_decl[i].second)); | 4176 CHECK(return_value->SameValue(*const_decl[i].second)); |
4191 } | 4177 } |
4192 | 4178 |
4193 // Tests for strict mode. | 4179 // Tests for strict mode. |
4194 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4180 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4195 std::string strict_body = | 4181 std::string strict_body = |
4196 "'use strict'; " + std::string(const_decl[i].first); | 4182 "'use strict'; " + std::string(const_decl[i].first); |
4197 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); | 4183 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); |
4198 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4184 InterpreterTester tester(isolate, source.c_str()); |
4199 auto callable = tester.GetCallable<>(); | 4185 auto callable = tester.GetCallable<>(); |
4200 | 4186 |
4201 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4187 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4202 CHECK(return_value->SameValue(*const_decl[i].second)); | 4188 CHECK(return_value->SameValue(*const_decl[i].second)); |
4203 } | 4189 } |
4204 } | 4190 } |
4205 | 4191 |
4206 TEST(InterpreterConstInLookupContextChain) { | 4192 TEST(InterpreterConstInLookupContextChain) { |
4207 HandleAndZoneScope handles; | 4193 HandleAndZoneScope handles; |
4208 i::Isolate* isolate = handles.main_isolate(); | 4194 Isolate* isolate = handles.main_isolate(); |
4209 | 4195 |
4210 const char* prologue = | 4196 const char* prologue = |
4211 "function OuterMost() {\n" | 4197 "function OuterMost() {\n" |
4212 " const outerConst = 10;\n" | 4198 " const outerConst = 10;\n" |
4213 " let outerLet = 20;\n" | 4199 " let outerLet = 20;\n" |
4214 " function Outer() {\n" | 4200 " function Outer() {\n" |
4215 " function Inner() {\n" | 4201 " function Inner() {\n" |
4216 " this.innerFunc = function() { "; | 4202 " this.innerFunc = function() { "; |
4217 const char* epilogue = | 4203 const char* epilogue = |
4218 " }\n" | 4204 " }\n" |
(...skipping 14 matching lines...) Expand all Loading... |
4233 handle(Smi::FromInt(40), isolate)}, | 4219 handle(Smi::FromInt(40), isolate)}, |
4234 {"var outerConst = 50; return outerConst;", | 4220 {"var outerConst = 50; return outerConst;", |
4235 handle(Smi::FromInt(50), isolate)}, | 4221 handle(Smi::FromInt(50), isolate)}, |
4236 {"try { outerConst = 30 } catch(e) { return -1; }", | 4222 {"try { outerConst = 30 } catch(e) { return -1; }", |
4237 handle(Smi::FromInt(-1), isolate)}}; | 4223 handle(Smi::FromInt(-1), isolate)}}; |
4238 | 4224 |
4239 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4225 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4240 std::string script = std::string(prologue) + | 4226 std::string script = std::string(prologue) + |
4241 std::string(const_decl[i].first) + | 4227 std::string(const_decl[i].first) + |
4242 std::string(epilogue); | 4228 std::string(epilogue); |
4243 InterpreterTester tester(handles.main_isolate(), script.c_str(), "*"); | 4229 InterpreterTester tester(isolate, script.c_str(), "*"); |
4244 auto callable = tester.GetCallable<>(); | 4230 auto callable = tester.GetCallable<>(); |
4245 | 4231 |
4246 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4232 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4247 CHECK(return_value->SameValue(*const_decl[i].second)); | 4233 CHECK(return_value->SameValue(*const_decl[i].second)); |
4248 } | 4234 } |
4249 } | 4235 } |
4250 | 4236 |
4251 TEST(InterpreterIllegalConstDeclaration) { | 4237 TEST(InterpreterIllegalConstDeclaration) { |
4252 HandleAndZoneScope handles; | 4238 HandleAndZoneScope handles; |
| 4239 Isolate* isolate = handles.main_isolate(); |
4253 | 4240 |
4254 std::pair<const char*, const char*> const_decl[] = { | 4241 std::pair<const char*, const char*> const_decl[] = { |
4255 {"const x = x = 10 + 3; return x;", | 4242 {"const x = x = 10 + 3; return x;", |
4256 "Uncaught ReferenceError: x is not defined"}, | 4243 "Uncaught ReferenceError: x is not defined"}, |
4257 {"const x = 10; x = 20; return x;", | 4244 {"const x = 10; x = 20; return x;", |
4258 "Uncaught TypeError: Assignment to constant variable."}, | 4245 "Uncaught TypeError: Assignment to constant variable."}, |
4259 {"const x = 10; { x = 20; } return x;", | 4246 {"const x = 10; { x = 20; } return x;", |
4260 "Uncaught TypeError: Assignment to constant variable."}, | 4247 "Uncaught TypeError: Assignment to constant variable."}, |
4261 {"const x = 10; eval('x = 20;'); return x;", | 4248 {"const x = 10; eval('x = 20;'); return x;", |
4262 "Uncaught TypeError: Assignment to constant variable."}, | 4249 "Uncaught TypeError: Assignment to constant variable."}, |
4263 {"let x = x + 10; return x;", | 4250 {"let x = x + 10; return x;", |
4264 "Uncaught ReferenceError: x is not defined"}, | 4251 "Uncaught ReferenceError: x is not defined"}, |
4265 {"'use strict'; (function f1() { f1 = 123; })() ", | 4252 {"'use strict'; (function f1() { f1 = 123; })() ", |
4266 "Uncaught TypeError: Assignment to constant variable."}, | 4253 "Uncaught TypeError: Assignment to constant variable."}, |
4267 }; | 4254 }; |
4268 | 4255 |
4269 // Tests for sloppy mode. | 4256 // Tests for sloppy mode. |
4270 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4257 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4271 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); | 4258 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); |
4272 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4259 InterpreterTester tester(isolate, source.c_str()); |
4273 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 4260 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
4274 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); | 4261 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); |
4275 CHECK( | 4262 CHECK( |
4276 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 4263 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
4277 .FromJust()); | 4264 .FromJust()); |
4278 } | 4265 } |
4279 | 4266 |
4280 // Tests for strict mode. | 4267 // Tests for strict mode. |
4281 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4268 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4282 std::string strict_body = | 4269 std::string strict_body = |
4283 "'use strict'; " + std::string(const_decl[i].first); | 4270 "'use strict'; " + std::string(const_decl[i].first); |
4284 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); | 4271 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); |
4285 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4272 InterpreterTester tester(isolate, source.c_str()); |
4286 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 4273 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
4287 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); | 4274 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); |
4288 CHECK( | 4275 CHECK( |
4289 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 4276 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
4290 .FromJust()); | 4277 .FromJust()); |
4291 } | 4278 } |
4292 } | 4279 } |
4293 | 4280 |
4294 TEST(InterpreterGenerators) { | 4281 TEST(InterpreterGenerators) { |
4295 HandleAndZoneScope handles; | 4282 HandleAndZoneScope handles; |
4296 i::Isolate* isolate = handles.main_isolate(); | 4283 Isolate* isolate = handles.main_isolate(); |
4297 i::Factory* factory = isolate->factory(); | 4284 Factory* factory = isolate->factory(); |
4298 | 4285 |
4299 std::pair<const char*, Handle<Object>> tests[] = { | 4286 std::pair<const char*, Handle<Object>> tests[] = { |
4300 {"function* f() { }; return f().next().value", | 4287 {"function* f() { }; return f().next().value", |
4301 factory->undefined_value()}, | 4288 factory->undefined_value()}, |
4302 {"function* f() { yield 42 }; return f().next().value", | 4289 {"function* f() { yield 42 }; return f().next().value", |
4303 factory->NewNumberFromInt(42)}, | 4290 factory->NewNumberFromInt(42)}, |
4304 {"function* f() { for (let x of [42]) yield x}; return f().next().value", | 4291 {"function* f() { for (let x of [42]) yield x}; return f().next().value", |
4305 factory->NewNumberFromInt(42)}, | 4292 factory->NewNumberFromInt(42)}, |
4306 }; | 4293 }; |
4307 | 4294 |
4308 for (size_t i = 0; i < arraysize(tests); i++) { | 4295 for (size_t i = 0; i < arraysize(tests); i++) { |
4309 std::string source(InterpreterTester::SourceForBody(tests[i].first)); | 4296 std::string source(InterpreterTester::SourceForBody(tests[i].first)); |
4310 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4297 InterpreterTester tester(isolate, source.c_str()); |
4311 auto callable = tester.GetCallable<>(); | 4298 auto callable = tester.GetCallable<>(); |
4312 | 4299 |
4313 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4300 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4314 CHECK(return_value->SameValue(*tests[i].second)); | 4301 CHECK(return_value->SameValue(*tests[i].second)); |
4315 } | 4302 } |
4316 } | 4303 } |
4317 | 4304 |
4318 } // namespace interpreter | 4305 } // namespace interpreter |
4319 } // namespace internal | 4306 } // namespace internal |
4320 } // namespace v8 | 4307 } // namespace v8 |
OLD | NEW |