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()); |
(...skipping 23 matching lines...) Expand all Loading... |
538 | 527 |
539 Handle<i::TypeFeedbackVector> vector = | 528 Handle<i::TypeFeedbackVector> vector = |
540 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 529 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
541 | 530 |
542 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) | 531 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) |
543 .BinaryOperation(op, builder.Parameter(1), vector->GetIndex(slot0)) | 532 .BinaryOperation(op, builder.Parameter(1), vector->GetIndex(slot0)) |
544 .BinaryOperation(op, builder.Parameter(2), vector->GetIndex(slot1)) | 533 .BinaryOperation(op, builder.Parameter(2), vector->GetIndex(slot1)) |
545 .BinaryOperation(op, builder.Parameter(3), vector->GetIndex(slot2)) | 534 .BinaryOperation(op, builder.Parameter(3), vector->GetIndex(slot2)) |
546 .Return(); | 535 .Return(); |
547 | 536 |
548 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 537 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
549 | 538 |
550 InterpreterTester tester(isolate, bytecode_array, vector); | 539 InterpreterTester tester(isolate, bytecode_array, vector); |
551 typedef Handle<Object> H; | 540 typedef Handle<Object> H; |
552 auto callable = tester.GetCallable<H, H, H, H>(); | 541 auto callable = tester.GetCallable<H, H, H, H>(); |
553 | 542 |
554 Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(2), isolate); | 543 Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(2), isolate); |
555 Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), isolate); | 544 Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), isolate); |
556 Handle<HeapNumber> arg3 = isolate->factory()->NewHeapNumber(2.2); | 545 Handle<HeapNumber> arg3 = isolate->factory()->NewHeapNumber(2.2); |
557 Handle<String> arg4 = isolate->factory()->NewStringFromAsciiChecked("2"); | 546 Handle<String> arg4 = isolate->factory()->NewStringFromAsciiChecked("2"); |
558 | 547 |
(...skipping 12 matching lines...) Expand all Loading... |
571 | 560 |
572 Object* feedback2 = vector->Get(slot2); | 561 Object* feedback2 = vector->Get(slot2); |
573 CHECK(feedback2->IsSmi()); | 562 CHECK(feedback2->IsSmi()); |
574 CHECK_EQ(BinaryOperationFeedback::kAny, | 563 CHECK_EQ(BinaryOperationFeedback::kAny, |
575 static_cast<Smi*>(feedback2)->value()); | 564 static_cast<Smi*>(feedback2)->value()); |
576 } | 565 } |
577 } | 566 } |
578 | 567 |
579 TEST(InterpreterParameter1Assign) { | 568 TEST(InterpreterParameter1Assign) { |
580 HandleAndZoneScope handles; | 569 HandleAndZoneScope handles; |
581 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 570 Isolate* isolate = handles.main_isolate(); |
582 0, 0); | 571 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
583 | 572 |
584 builder.LoadLiteral(Smi::FromInt(5)) | 573 builder.LoadLiteral(Smi::FromInt(5)) |
585 .StoreAccumulatorInRegister(builder.Parameter(0)) | 574 .StoreAccumulatorInRegister(builder.Parameter(0)) |
586 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 575 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
587 .Return(); | 576 .Return(); |
588 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 577 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
589 | 578 |
590 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 579 InterpreterTester tester(isolate, bytecode_array); |
591 auto callable = tester.GetCallable<Handle<Object>>(); | 580 auto callable = tester.GetCallable<Handle<Object>>(); |
592 | 581 |
593 Handle<Object> return_val = | 582 Handle<Object> return_val = |
594 callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) | 583 callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) |
595 .ToHandleChecked(); | 584 .ToHandleChecked(); |
596 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); | 585 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
597 } | 586 } |
598 | 587 |
599 | 588 |
600 TEST(InterpreterLoadGlobal) { | 589 TEST(InterpreterLoadGlobal) { |
601 HandleAndZoneScope handles; | 590 HandleAndZoneScope handles; |
| 591 Isolate* isolate = handles.main_isolate(); |
602 | 592 |
603 // Test loading a global. | 593 // Test loading a global. |
604 std::string source( | 594 std::string source( |
605 "var global = 321;\n" | 595 "var global = 321;\n" |
606 "function " + InterpreterTester::function_name() + "() {\n" | 596 "function " + InterpreterTester::function_name() + "() {\n" |
607 " return global;\n" | 597 " return global;\n" |
608 "}"); | 598 "}"); |
609 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 599 InterpreterTester tester(isolate, source.c_str()); |
610 auto callable = tester.GetCallable<>(); | 600 auto callable = tester.GetCallable<>(); |
611 | 601 |
612 Handle<Object> return_val = callable().ToHandleChecked(); | 602 Handle<Object> return_val = callable().ToHandleChecked(); |
613 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); | 603 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); |
614 } | 604 } |
615 | 605 |
616 | 606 |
617 TEST(InterpreterStoreGlobal) { | 607 TEST(InterpreterStoreGlobal) { |
618 HandleAndZoneScope handles; | 608 HandleAndZoneScope handles; |
619 i::Isolate* isolate = handles.main_isolate(); | 609 Isolate* isolate = handles.main_isolate(); |
620 i::Factory* factory = isolate->factory(); | 610 Factory* factory = isolate->factory(); |
621 | 611 |
622 // Test storing to a global. | 612 // Test storing to a global. |
623 std::string source( | 613 std::string source( |
624 "var global = 321;\n" | 614 "var global = 321;\n" |
625 "function " + InterpreterTester::function_name() + "() {\n" | 615 "function " + InterpreterTester::function_name() + "() {\n" |
626 " global = 999;\n" | 616 " global = 999;\n" |
627 "}"); | 617 "}"); |
628 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 618 InterpreterTester tester(isolate, source.c_str()); |
629 auto callable = tester.GetCallable<>(); | 619 auto callable = tester.GetCallable<>(); |
630 | 620 |
631 callable().ToHandleChecked(); | 621 callable().ToHandleChecked(); |
632 Handle<i::String> name = factory->InternalizeUtf8String("global"); | 622 Handle<i::String> name = factory->InternalizeUtf8String("global"); |
633 Handle<i::Object> global_obj = | 623 Handle<i::Object> global_obj = |
634 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); | 624 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); |
635 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); | 625 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); |
636 } | 626 } |
637 | 627 |
638 | 628 |
639 TEST(InterpreterCallGlobal) { | 629 TEST(InterpreterCallGlobal) { |
640 HandleAndZoneScope handles; | 630 HandleAndZoneScope handles; |
| 631 Isolate* isolate = handles.main_isolate(); |
641 | 632 |
642 // Test calling a global function. | 633 // Test calling a global function. |
643 std::string source( | 634 std::string source( |
644 "function g_add(a, b) { return a + b; }\n" | 635 "function g_add(a, b) { return a + b; }\n" |
645 "function " + InterpreterTester::function_name() + "() {\n" | 636 "function " + InterpreterTester::function_name() + "() {\n" |
646 " return g_add(5, 10);\n" | 637 " return g_add(5, 10);\n" |
647 "}"); | 638 "}"); |
648 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 639 InterpreterTester tester(isolate, source.c_str()); |
649 auto callable = tester.GetCallable<>(); | 640 auto callable = tester.GetCallable<>(); |
650 | 641 |
651 Handle<Object> return_val = callable().ToHandleChecked(); | 642 Handle<Object> return_val = callable().ToHandleChecked(); |
652 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); | 643 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
653 } | 644 } |
654 | 645 |
655 | 646 |
656 TEST(InterpreterLoadUnallocated) { | 647 TEST(InterpreterLoadUnallocated) { |
657 HandleAndZoneScope handles; | 648 HandleAndZoneScope handles; |
| 649 Isolate* isolate = handles.main_isolate(); |
658 | 650 |
659 // Test loading an unallocated global. | 651 // Test loading an unallocated global. |
660 std::string source( | 652 std::string source( |
661 "unallocated = 123;\n" | 653 "unallocated = 123;\n" |
662 "function " + InterpreterTester::function_name() + "() {\n" | 654 "function " + InterpreterTester::function_name() + "() {\n" |
663 " return unallocated;\n" | 655 " return unallocated;\n" |
664 "}"); | 656 "}"); |
665 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 657 InterpreterTester tester(isolate, source.c_str()); |
666 auto callable = tester.GetCallable<>(); | 658 auto callable = tester.GetCallable<>(); |
667 | 659 |
668 Handle<Object> return_val = callable().ToHandleChecked(); | 660 Handle<Object> return_val = callable().ToHandleChecked(); |
669 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 661 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
670 } | 662 } |
671 | 663 |
672 | 664 |
673 TEST(InterpreterStoreUnallocated) { | 665 TEST(InterpreterStoreUnallocated) { |
674 HandleAndZoneScope handles; | 666 HandleAndZoneScope handles; |
675 i::Isolate* isolate = handles.main_isolate(); | 667 Isolate* isolate = handles.main_isolate(); |
676 i::Factory* factory = isolate->factory(); | 668 Factory* factory = isolate->factory(); |
677 | 669 |
678 // Test storing to an unallocated global. | 670 // Test storing to an unallocated global. |
679 std::string source( | 671 std::string source( |
680 "unallocated = 321;\n" | 672 "unallocated = 321;\n" |
681 "function " + InterpreterTester::function_name() + "() {\n" | 673 "function " + InterpreterTester::function_name() + "() {\n" |
682 " unallocated = 999;\n" | 674 " unallocated = 999;\n" |
683 "}"); | 675 "}"); |
684 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 676 InterpreterTester tester(isolate, source.c_str()); |
685 auto callable = tester.GetCallable<>(); | 677 auto callable = tester.GetCallable<>(); |
686 | 678 |
687 callable().ToHandleChecked(); | 679 callable().ToHandleChecked(); |
688 Handle<i::String> name = factory->InternalizeUtf8String("unallocated"); | 680 Handle<i::String> name = factory->InternalizeUtf8String("unallocated"); |
689 Handle<i::Object> global_obj = | 681 Handle<i::Object> global_obj = |
690 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); | 682 Object::GetProperty(isolate->global_object(), name).ToHandleChecked(); |
691 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); | 683 CHECK_EQ(Smi::cast(*global_obj), Smi::FromInt(999)); |
692 } | 684 } |
693 | 685 |
694 | 686 |
695 TEST(InterpreterLoadNamedProperty) { | 687 TEST(InterpreterLoadNamedProperty) { |
696 HandleAndZoneScope handles; | 688 HandleAndZoneScope handles; |
697 i::Isolate* isolate = handles.main_isolate(); | 689 Isolate* isolate = handles.main_isolate(); |
698 i::Factory* factory = isolate->factory(); | 690 Factory* factory = isolate->factory(); |
699 i::Zone zone(isolate->allocator()); | 691 Zone zone(isolate->allocator()); |
700 | 692 |
701 i::FeedbackVectorSpec feedback_spec(&zone); | 693 FeedbackVectorSpec feedback_spec(&zone); |
702 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 694 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
703 | 695 |
704 Handle<i::TypeFeedbackVector> vector = | 696 Handle<i::TypeFeedbackVector> vector = |
705 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 697 NewTypeFeedbackVector(isolate, &feedback_spec); |
706 | 698 |
707 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 699 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
708 name = factory->string_table()->LookupString(isolate, name); | 700 name = factory->string_table()->LookupString(isolate, name); |
709 | 701 |
710 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 702 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
711 0, 0); | |
712 | 703 |
713 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot)) | 704 builder.LoadNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot)) |
714 .Return(); | 705 .Return(); |
715 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 706 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
716 | 707 |
717 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 708 InterpreterTester tester(isolate, bytecode_array, vector); |
718 auto callable = tester.GetCallable<Handle<Object>>(); | 709 auto callable = tester.GetCallable<Handle<Object>>(); |
719 | 710 |
720 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 711 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
721 // Test IC miss. | 712 // Test IC miss. |
722 Handle<Object> return_val = callable(object).ToHandleChecked(); | 713 Handle<Object> return_val = callable(object).ToHandleChecked(); |
723 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 714 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
724 | 715 |
725 // Test transition to monomorphic IC. | 716 // Test transition to monomorphic IC. |
726 return_val = callable(object).ToHandleChecked(); | 717 return_val = callable(object).ToHandleChecked(); |
727 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 718 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
(...skipping 13 matching lines...) Expand all Loading... |
741 callable(object4).ToHandleChecked(); | 732 callable(object4).ToHandleChecked(); |
742 Handle<Object> object5 = | 733 Handle<Object> object5 = |
743 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); | 734 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
744 return_val = callable(object5).ToHandleChecked(); | 735 return_val = callable(object5).ToHandleChecked(); |
745 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 736 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
746 } | 737 } |
747 | 738 |
748 | 739 |
749 TEST(InterpreterLoadKeyedProperty) { | 740 TEST(InterpreterLoadKeyedProperty) { |
750 HandleAndZoneScope handles; | 741 HandleAndZoneScope handles; |
751 i::Isolate* isolate = handles.main_isolate(); | 742 Isolate* isolate = handles.main_isolate(); |
752 i::Factory* factory = isolate->factory(); | 743 Factory* factory = isolate->factory(); |
753 i::Zone zone(isolate->allocator()); | 744 Zone zone(isolate->allocator()); |
754 | 745 |
755 i::FeedbackVectorSpec feedback_spec(&zone); | 746 FeedbackVectorSpec feedback_spec(&zone); |
756 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); | 747 FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
757 | 748 |
758 Handle<i::TypeFeedbackVector> vector = | 749 Handle<i::TypeFeedbackVector> vector = |
759 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 750 NewTypeFeedbackVector(isolate, &feedback_spec); |
760 | 751 |
761 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); | 752 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); |
762 key = factory->string_table()->LookupString(isolate, key); | 753 key = factory->string_table()->LookupString(isolate, key); |
763 | 754 |
764 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 755 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
765 0, 1); | |
766 | 756 |
767 builder.LoadLiteral(key) | 757 builder.LoadLiteral(key) |
768 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot)) | 758 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot)) |
769 .Return(); | 759 .Return(); |
770 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 760 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
771 | 761 |
772 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 762 InterpreterTester tester(isolate, bytecode_array, vector); |
773 auto callable = tester.GetCallable<Handle<Object>>(); | 763 auto callable = tester.GetCallable<Handle<Object>>(); |
774 | 764 |
775 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); | 765 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); |
776 // Test IC miss. | 766 // Test IC miss. |
777 Handle<Object> return_val = callable(object).ToHandleChecked(); | 767 Handle<Object> return_val = callable(object).ToHandleChecked(); |
778 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 768 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
779 | 769 |
780 // Test transition to monomorphic IC. | 770 // Test transition to monomorphic IC. |
781 return_val = callable(object).ToHandleChecked(); | 771 return_val = callable(object).ToHandleChecked(); |
782 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 772 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
783 | 773 |
784 // Test transition to megamorphic IC. | 774 // Test transition to megamorphic IC. |
785 Handle<Object> object3 = | 775 Handle<Object> object3 = |
786 InterpreterTester::NewObject("({ key : 789, val2 : 123 })"); | 776 InterpreterTester::NewObject("({ key : 789, val2 : 123 })"); |
787 return_val = callable(object3).ToHandleChecked(); | 777 return_val = callable(object3).ToHandleChecked(); |
788 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 778 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
789 } | 779 } |
790 | 780 |
791 | 781 |
792 TEST(InterpreterStoreNamedProperty) { | 782 TEST(InterpreterStoreNamedProperty) { |
793 HandleAndZoneScope handles; | 783 HandleAndZoneScope handles; |
794 i::Isolate* isolate = handles.main_isolate(); | 784 Isolate* isolate = handles.main_isolate(); |
795 i::Factory* factory = isolate->factory(); | 785 Factory* factory = isolate->factory(); |
796 i::Zone zone(isolate->allocator()); | 786 Zone zone(isolate->allocator()); |
797 | 787 |
798 i::FeedbackVectorSpec feedback_spec(&zone); | 788 FeedbackVectorSpec feedback_spec(&zone); |
799 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); | 789 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); |
800 | 790 |
801 Handle<i::TypeFeedbackVector> vector = | 791 Handle<i::TypeFeedbackVector> vector = |
802 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 792 NewTypeFeedbackVector(isolate, &feedback_spec); |
803 | 793 |
804 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 794 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
805 name = factory->string_table()->LookupString(isolate, name); | 795 name = factory->string_table()->LookupString(isolate, name); |
806 | 796 |
807 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 797 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 0); |
808 0, 0); | |
809 | 798 |
810 builder.LoadLiteral(Smi::FromInt(999)) | 799 builder.LoadLiteral(Smi::FromInt(999)) |
811 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot), | 800 .StoreNamedProperty(builder.Parameter(0), name, vector->GetIndex(slot), |
812 i::STRICT) | 801 STRICT) |
813 .Return(); | 802 .Return(); |
814 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 803 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
815 | 804 |
816 InterpreterTester tester(isolate, bytecode_array, vector); | 805 InterpreterTester tester(isolate, bytecode_array, vector); |
817 auto callable = tester.GetCallable<Handle<Object>>(); | 806 auto callable = tester.GetCallable<Handle<Object>>(); |
818 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 807 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
819 // Test IC miss. | 808 // Test IC miss. |
820 Handle<Object> result; | 809 Handle<Object> result; |
821 callable(object).ToHandleChecked(); | 810 callable(object).ToHandleChecked(); |
822 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 811 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
823 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 812 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
824 | 813 |
(...skipping 19 matching lines...) Expand all Loading... |
844 Handle<Object> object5 = | 833 Handle<Object> object5 = |
845 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); | 834 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
846 callable(object5).ToHandleChecked(); | 835 callable(object5).ToHandleChecked(); |
847 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); | 836 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); |
848 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 837 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
849 } | 838 } |
850 | 839 |
851 | 840 |
852 TEST(InterpreterStoreKeyedProperty) { | 841 TEST(InterpreterStoreKeyedProperty) { |
853 HandleAndZoneScope handles; | 842 HandleAndZoneScope handles; |
854 i::Isolate* isolate = handles.main_isolate(); | 843 Isolate* isolate = handles.main_isolate(); |
855 i::Factory* factory = isolate->factory(); | 844 Factory* factory = isolate->factory(); |
856 i::Zone zone(isolate->allocator()); | 845 Zone zone(isolate->allocator()); |
857 | 846 |
858 i::FeedbackVectorSpec feedback_spec(&zone); | 847 FeedbackVectorSpec feedback_spec(&zone); |
859 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); | 848 FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); |
860 | 849 |
861 Handle<i::TypeFeedbackVector> vector = | 850 Handle<i::TypeFeedbackVector> vector = |
862 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 851 NewTypeFeedbackVector(isolate, &feedback_spec); |
863 | 852 |
864 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 853 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
865 name = factory->string_table()->LookupString(isolate, name); | 854 name = factory->string_table()->LookupString(isolate, name); |
866 | 855 |
867 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 856 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
868 0, 1); | |
869 | 857 |
870 builder.LoadLiteral(name) | 858 builder.LoadLiteral(name) |
871 .StoreAccumulatorInRegister(Register(0)) | 859 .StoreAccumulatorInRegister(Register(0)) |
872 .LoadLiteral(Smi::FromInt(999)) | 860 .LoadLiteral(Smi::FromInt(999)) |
873 .StoreKeyedProperty(builder.Parameter(0), Register(0), | 861 .StoreKeyedProperty(builder.Parameter(0), Register(0), |
874 vector->GetIndex(slot), i::SLOPPY) | 862 vector->GetIndex(slot), i::SLOPPY) |
875 .Return(); | 863 .Return(); |
876 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 864 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
877 | 865 |
878 InterpreterTester tester(isolate, bytecode_array, vector); | 866 InterpreterTester tester(isolate, bytecode_array, vector); |
879 auto callable = tester.GetCallable<Handle<Object>>(); | 867 auto callable = tester.GetCallable<Handle<Object>>(); |
880 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 868 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
881 // Test IC miss. | 869 // Test IC miss. |
882 Handle<Object> result; | 870 Handle<Object> result; |
883 callable(object).ToHandleChecked(); | 871 callable(object).ToHandleChecked(); |
884 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 872 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
885 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 873 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
886 | 874 |
887 // Test transition to monomorphic IC. | 875 // Test transition to monomorphic IC. |
888 callable(object).ToHandleChecked(); | 876 callable(object).ToHandleChecked(); |
889 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 877 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
890 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 878 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
891 | 879 |
892 // Test transition to megamorphic IC. | 880 // Test transition to megamorphic IC. |
893 Handle<Object> object2 = | 881 Handle<Object> object2 = |
894 InterpreterTester::NewObject("({ val : 456, other : 123 })"); | 882 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
895 callable(object2).ToHandleChecked(); | 883 callable(object2).ToHandleChecked(); |
896 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); | 884 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); |
897 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 885 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
898 } | 886 } |
899 | 887 |
900 static void TestInterpreterCall(TailCallMode tail_call_mode) { | 888 static void TestInterpreterCall(TailCallMode tail_call_mode) { |
901 HandleAndZoneScope handles; | 889 HandleAndZoneScope handles; |
902 i::Isolate* isolate = handles.main_isolate(); | 890 Isolate* isolate = handles.main_isolate(); |
903 i::Factory* factory = isolate->factory(); | 891 Factory* factory = isolate->factory(); |
904 i::Zone zone(isolate->allocator()); | 892 Zone zone(isolate->allocator()); |
905 | 893 |
906 i::FeedbackVectorSpec feedback_spec(&zone); | 894 FeedbackVectorSpec feedback_spec(&zone); |
907 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 895 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
908 i::FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot(); | 896 FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot(); |
909 | 897 |
910 Handle<i::TypeFeedbackVector> vector = | 898 Handle<i::TypeFeedbackVector> vector = |
911 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 899 NewTypeFeedbackVector(isolate, &feedback_spec); |
912 int slot_index = vector->GetIndex(slot); | 900 int slot_index = vector->GetIndex(slot); |
913 int call_slot_index = -1; | 901 int call_slot_index = -1; |
914 call_slot_index = vector->GetIndex(call_slot); | 902 call_slot_index = vector->GetIndex(call_slot); |
915 | 903 |
916 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); | 904 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); |
917 name = factory->string_table()->LookupString(isolate, name); | 905 name = factory->string_table()->LookupString(isolate, name); |
918 | 906 |
919 // Check with no args. | 907 // Check with no args. |
920 { | 908 { |
921 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 909 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
922 0, 1); | |
923 | 910 |
924 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 911 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
925 .StoreAccumulatorInRegister(Register(0)); | 912 .StoreAccumulatorInRegister(Register(0)); |
926 | 913 |
927 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, | 914 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, |
928 tail_call_mode); | 915 tail_call_mode); |
929 | 916 |
930 builder.Return(); | 917 builder.Return(); |
931 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 918 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
932 | 919 |
933 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 920 InterpreterTester tester(isolate, bytecode_array, vector); |
934 auto callable = tester.GetCallable<Handle<Object>>(); | 921 auto callable = tester.GetCallable<Handle<Object>>(); |
935 | 922 |
936 Handle<Object> object = InterpreterTester::NewObject( | 923 Handle<Object> object = InterpreterTester::NewObject( |
937 "new (function Obj() { this.func = function() { return 0x265; }})()"); | 924 "new (function Obj() { this.func = function() { return 0x265; }})()"); |
938 Handle<Object> return_val = callable(object).ToHandleChecked(); | 925 Handle<Object> return_val = callable(object).ToHandleChecked(); |
939 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); | 926 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); |
940 } | 927 } |
941 | 928 |
942 // Check that receiver is passed properly. | 929 // Check that receiver is passed properly. |
943 { | 930 { |
944 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 931 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
945 0, 1); | |
946 | 932 |
947 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 933 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
948 .StoreAccumulatorInRegister(Register(0)); | 934 .StoreAccumulatorInRegister(Register(0)); |
949 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, | 935 builder.Call(Register(0), builder.Parameter(0), 1, call_slot_index, |
950 tail_call_mode); | 936 tail_call_mode); |
951 builder.Return(); | 937 builder.Return(); |
952 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 938 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
953 | 939 |
954 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 940 InterpreterTester tester(isolate, bytecode_array, vector); |
955 auto callable = tester.GetCallable<Handle<Object>>(); | 941 auto callable = tester.GetCallable<Handle<Object>>(); |
956 | 942 |
957 Handle<Object> object = InterpreterTester::NewObject( | 943 Handle<Object> object = InterpreterTester::NewObject( |
958 "new (function Obj() {" | 944 "new (function Obj() {" |
959 " this.val = 1234;" | 945 " this.val = 1234;" |
960 " this.func = function() { return this.val; };" | 946 " this.func = function() { return this.val; };" |
961 "})()"); | 947 "})()"); |
962 Handle<Object> return_val = callable(object).ToHandleChecked(); | 948 Handle<Object> return_val = callable(object).ToHandleChecked(); |
963 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); | 949 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); |
964 } | 950 } |
965 | 951 |
966 // Check with two parameters (+ receiver). | 952 // Check with two parameters (+ receiver). |
967 { | 953 { |
968 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 954 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 4); |
969 0, 4); | |
970 | 955 |
971 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 956 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
972 .StoreAccumulatorInRegister(Register(0)) | 957 .StoreAccumulatorInRegister(Register(0)) |
973 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 958 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
974 .StoreAccumulatorInRegister(Register(1)) | 959 .StoreAccumulatorInRegister(Register(1)) |
975 .LoadLiteral(Smi::FromInt(51)) | 960 .LoadLiteral(Smi::FromInt(51)) |
976 .StoreAccumulatorInRegister(Register(2)) | 961 .StoreAccumulatorInRegister(Register(2)) |
977 .LoadLiteral(Smi::FromInt(11)) | 962 .LoadLiteral(Smi::FromInt(11)) |
978 .StoreAccumulatorInRegister(Register(3)); | 963 .StoreAccumulatorInRegister(Register(3)); |
979 | 964 |
980 builder.Call(Register(0), Register(1), 3, call_slot_index, tail_call_mode); | 965 builder.Call(Register(0), Register(1), 3, call_slot_index, tail_call_mode); |
981 | 966 |
982 builder.Return(); | 967 builder.Return(); |
983 | 968 |
984 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 969 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
985 | 970 |
986 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 971 InterpreterTester tester(isolate, bytecode_array, vector); |
987 auto callable = tester.GetCallable<Handle<Object>>(); | 972 auto callable = tester.GetCallable<Handle<Object>>(); |
988 | 973 |
989 Handle<Object> object = InterpreterTester::NewObject( | 974 Handle<Object> object = InterpreterTester::NewObject( |
990 "new (function Obj() { " | 975 "new (function Obj() { " |
991 " this.func = function(a, b) { return a - b; }" | 976 " this.func = function(a, b) { return a - b; }" |
992 "})()"); | 977 "})()"); |
993 Handle<Object> return_val = callable(object).ToHandleChecked(); | 978 Handle<Object> return_val = callable(object).ToHandleChecked(); |
994 CHECK(return_val->SameValue(Smi::FromInt(40))); | 979 CHECK(return_val->SameValue(Smi::FromInt(40))); |
995 } | 980 } |
996 | 981 |
997 // Check with 10 parameters (+ receiver). | 982 // Check with 10 parameters (+ receiver). |
998 { | 983 { |
999 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 984 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 12); |
1000 0, 12); | |
1001 | 985 |
1002 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) | 986 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) |
1003 .StoreAccumulatorInRegister(Register(0)) | 987 .StoreAccumulatorInRegister(Register(0)) |
1004 .LoadAccumulatorWithRegister(builder.Parameter(0)) | 988 .LoadAccumulatorWithRegister(builder.Parameter(0)) |
1005 .StoreAccumulatorInRegister(Register(1)) | 989 .StoreAccumulatorInRegister(Register(1)) |
1006 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) | 990 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) |
1007 .StoreAccumulatorInRegister(Register(2)) | 991 .StoreAccumulatorInRegister(Register(2)) |
1008 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) | 992 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) |
1009 .StoreAccumulatorInRegister(Register(3)) | 993 .StoreAccumulatorInRegister(Register(3)) |
1010 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) | 994 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) |
(...skipping 10 matching lines...) Expand all Loading... |
1021 .StoreAccumulatorInRegister(Register(9)) | 1005 .StoreAccumulatorInRegister(Register(9)) |
1022 .LoadLiteral(factory->NewStringFromAsciiChecked("i")) | 1006 .LoadLiteral(factory->NewStringFromAsciiChecked("i")) |
1023 .StoreAccumulatorInRegister(Register(10)) | 1007 .StoreAccumulatorInRegister(Register(10)) |
1024 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) | 1008 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) |
1025 .StoreAccumulatorInRegister(Register(11)); | 1009 .StoreAccumulatorInRegister(Register(11)); |
1026 | 1010 |
1027 builder.Call(Register(0), Register(1), 11, call_slot_index, tail_call_mode); | 1011 builder.Call(Register(0), Register(1), 11, call_slot_index, tail_call_mode); |
1028 | 1012 |
1029 builder.Return(); | 1013 builder.Return(); |
1030 | 1014 |
1031 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1015 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1032 | 1016 |
1033 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 1017 InterpreterTester tester(isolate, bytecode_array, vector); |
1034 auto callable = tester.GetCallable<Handle<Object>>(); | 1018 auto callable = tester.GetCallable<Handle<Object>>(); |
1035 | 1019 |
1036 Handle<Object> object = InterpreterTester::NewObject( | 1020 Handle<Object> object = InterpreterTester::NewObject( |
1037 "new (function Obj() { " | 1021 "new (function Obj() { " |
1038 " this.prefix = \"prefix_\";" | 1022 " this.prefix = \"prefix_\";" |
1039 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" | 1023 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" |
1040 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" | 1024 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" |
1041 " }" | 1025 " }" |
1042 "})()"); | 1026 "})()"); |
1043 Handle<Object> return_val = callable(object).ToHandleChecked(); | 1027 Handle<Object> return_val = callable(object).ToHandleChecked(); |
(...skipping 23 matching lines...) Expand all Loading... |
1067 return builder.StoreAccumulatorInRegister(scratch) | 1051 return builder.StoreAccumulatorInRegister(scratch) |
1068 .LoadLiteral(Smi::FromInt(value)) | 1052 .LoadLiteral(Smi::FromInt(value)) |
1069 .BinaryOperation(Token::Value::ADD, reg, slot_index) | 1053 .BinaryOperation(Token::Value::ADD, reg, slot_index) |
1070 .StoreAccumulatorInRegister(reg) | 1054 .StoreAccumulatorInRegister(reg) |
1071 .LoadAccumulatorWithRegister(scratch); | 1055 .LoadAccumulatorWithRegister(scratch); |
1072 } | 1056 } |
1073 | 1057 |
1074 | 1058 |
1075 TEST(InterpreterJumps) { | 1059 TEST(InterpreterJumps) { |
1076 HandleAndZoneScope handles; | 1060 HandleAndZoneScope handles; |
1077 i::Isolate* isolate = handles.main_isolate(); | 1061 Isolate* isolate = handles.main_isolate(); |
1078 i::Zone zone(isolate->allocator()); | 1062 Zone zone(isolate->allocator()); |
1079 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1063 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 2); |
1080 0, 2); | |
1081 | 1064 |
1082 i::FeedbackVectorSpec feedback_spec(&zone); | 1065 FeedbackVectorSpec feedback_spec(&zone); |
1083 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1066 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1084 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 1067 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
1085 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 1068 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
1086 | 1069 |
1087 Handle<i::TypeFeedbackVector> vector = | 1070 Handle<i::TypeFeedbackVector> vector = |
1088 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1071 NewTypeFeedbackVector(isolate, &feedback_spec); |
1089 | 1072 |
1090 Register reg(0), scratch(1); | 1073 Register reg(0), scratch(1); |
1091 BytecodeLabel label[3]; | 1074 BytecodeLabel label[3]; |
1092 | 1075 |
1093 builder.LoadLiteral(Smi::FromInt(0)) | 1076 builder.LoadLiteral(Smi::FromInt(0)) |
1094 .StoreAccumulatorInRegister(reg) | 1077 .StoreAccumulatorInRegister(reg) |
1095 .Jump(&label[1]); | 1078 .Jump(&label[1]); |
1096 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); | 1079 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); |
1097 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot)) | 1080 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot)) |
1098 .Jump(&label[2]); | 1081 .Jump(&label[2]); |
1099 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); | 1082 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); |
1100 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1)) | 1083 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1)) |
1101 .Jump(&label[0]); | 1084 .Jump(&label[0]); |
1102 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); | 1085 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); |
1103 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2)) | 1086 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2)) |
1104 .LoadAccumulatorWithRegister(reg) | 1087 .LoadAccumulatorWithRegister(reg) |
1105 .Return(); | 1088 .Return(); |
1106 | 1089 |
1107 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1090 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1108 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1091 InterpreterTester tester(isolate, bytecode_array); |
1109 auto callable = tester.GetCallable<>(); | 1092 auto callable = tester.GetCallable<>(); |
1110 Handle<Object> return_value = callable().ToHandleChecked(); | 1093 Handle<Object> return_value = callable().ToHandleChecked(); |
1111 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1094 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
1112 } | 1095 } |
1113 | 1096 |
1114 | 1097 |
1115 TEST(InterpreterConditionalJumps) { | 1098 TEST(InterpreterConditionalJumps) { |
1116 HandleAndZoneScope handles; | 1099 HandleAndZoneScope handles; |
1117 i::Isolate* isolate = handles.main_isolate(); | 1100 Isolate* isolate = handles.main_isolate(); |
1118 i::Zone zone(isolate->allocator()); | 1101 Zone zone(isolate->allocator()); |
1119 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1102 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 2); |
1120 0, 2); | |
1121 | 1103 |
1122 i::FeedbackVectorSpec feedback_spec(&zone); | 1104 FeedbackVectorSpec feedback_spec(&zone); |
1123 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1105 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1124 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 1106 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
1125 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 1107 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
1126 i::FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); | 1108 FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); |
1127 i::FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); | 1109 FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); |
1128 | 1110 |
1129 Handle<i::TypeFeedbackVector> vector = | 1111 Handle<i::TypeFeedbackVector> vector = |
1130 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1112 NewTypeFeedbackVector(isolate, &feedback_spec); |
1131 | 1113 |
1132 Register reg(0), scratch(1); | 1114 Register reg(0), scratch(1); |
1133 BytecodeLabel label[2]; | 1115 BytecodeLabel label[2]; |
1134 BytecodeLabel done, done1; | 1116 BytecodeLabel done, done1; |
1135 | 1117 |
1136 builder.LoadLiteral(Smi::FromInt(0)) | 1118 builder.LoadLiteral(Smi::FromInt(0)) |
1137 .StoreAccumulatorInRegister(reg) | 1119 .StoreAccumulatorInRegister(reg) |
1138 .LoadFalse() | 1120 .LoadFalse() |
1139 .JumpIfFalse(&label[0]); | 1121 .JumpIfFalse(&label[0]); |
1140 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) | 1122 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) |
1141 .Bind(&label[0]) | 1123 .Bind(&label[0]) |
1142 .LoadTrue() | 1124 .LoadTrue() |
1143 .JumpIfFalse(&done); | 1125 .JumpIfFalse(&done); |
1144 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) | 1126 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) |
1145 .LoadTrue() | 1127 .LoadTrue() |
1146 .JumpIfTrue(&label[1]); | 1128 .JumpIfTrue(&label[1]); |
1147 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) | 1129 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) |
1148 .Bind(&label[1]); | 1130 .Bind(&label[1]); |
1149 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) | 1131 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) |
1150 .LoadFalse() | 1132 .LoadFalse() |
1151 .JumpIfTrue(&done1); | 1133 .JumpIfTrue(&done1); |
1152 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) | 1134 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) |
1153 .LoadAccumulatorWithRegister(reg) | 1135 .LoadAccumulatorWithRegister(reg) |
1154 .Bind(&done) | 1136 .Bind(&done) |
1155 .Bind(&done1) | 1137 .Bind(&done1) |
1156 .Return(); | 1138 .Return(); |
1157 | 1139 |
1158 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1140 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1159 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1141 InterpreterTester tester(isolate, bytecode_array); |
1160 auto callable = tester.GetCallable<>(); | 1142 auto callable = tester.GetCallable<>(); |
1161 Handle<Object> return_value = callable().ToHandleChecked(); | 1143 Handle<Object> return_value = callable().ToHandleChecked(); |
1162 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1144 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
1163 } | 1145 } |
1164 | 1146 |
1165 TEST(InterpreterConditionalJumps2) { | 1147 TEST(InterpreterConditionalJumps2) { |
1166 // TODO(oth): Add tests for all conditional jumps near and far. | 1148 // TODO(oth): Add tests for all conditional jumps near and far. |
1167 HandleAndZoneScope handles; | 1149 HandleAndZoneScope handles; |
1168 i::Isolate* isolate = handles.main_isolate(); | 1150 Isolate* isolate = handles.main_isolate(); |
1169 i::Zone zone(isolate->allocator()); | 1151 Zone zone(isolate->allocator()); |
1170 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1152 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 2); |
1171 0, 2); | |
1172 | 1153 |
1173 i::FeedbackVectorSpec feedback_spec(&zone); | 1154 FeedbackVectorSpec feedback_spec(&zone); |
1174 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1155 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1175 i::FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 1156 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
1176 i::FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); | 1157 FeedbackVectorSlot slot2 = feedback_spec.AddGeneralSlot(); |
1177 i::FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); | 1158 FeedbackVectorSlot slot3 = feedback_spec.AddGeneralSlot(); |
1178 i::FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); | 1159 FeedbackVectorSlot slot4 = feedback_spec.AddGeneralSlot(); |
1179 | 1160 |
1180 Handle<i::TypeFeedbackVector> vector = | 1161 Handle<i::TypeFeedbackVector> vector = |
1181 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1162 NewTypeFeedbackVector(isolate, &feedback_spec); |
1182 | 1163 |
1183 Register reg(0), scratch(1); | 1164 Register reg(0), scratch(1); |
1184 BytecodeLabel label[2]; | 1165 BytecodeLabel label[2]; |
1185 BytecodeLabel done, done1; | 1166 BytecodeLabel done, done1; |
1186 | 1167 |
1187 builder.LoadLiteral(Smi::FromInt(0)) | 1168 builder.LoadLiteral(Smi::FromInt(0)) |
1188 .StoreAccumulatorInRegister(reg) | 1169 .StoreAccumulatorInRegister(reg) |
1189 .LoadFalse() | 1170 .LoadFalse() |
1190 .JumpIfFalse(&label[0]); | 1171 .JumpIfFalse(&label[0]); |
1191 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) | 1172 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) |
1192 .Bind(&label[0]) | 1173 .Bind(&label[0]) |
1193 .LoadTrue() | 1174 .LoadTrue() |
1194 .JumpIfFalse(&done); | 1175 .JumpIfFalse(&done); |
1195 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) | 1176 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) |
1196 .LoadTrue() | 1177 .LoadTrue() |
1197 .JumpIfTrue(&label[1]); | 1178 .JumpIfTrue(&label[1]); |
1198 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) | 1179 IncrementRegister(builder, reg, 2048, scratch, vector->GetIndex(slot2)) |
1199 .Bind(&label[1]); | 1180 .Bind(&label[1]); |
1200 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) | 1181 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) |
1201 .LoadFalse() | 1182 .LoadFalse() |
1202 .JumpIfTrue(&done1); | 1183 .JumpIfTrue(&done1); |
1203 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) | 1184 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) |
1204 .LoadAccumulatorWithRegister(reg) | 1185 .LoadAccumulatorWithRegister(reg) |
1205 .Bind(&done) | 1186 .Bind(&done) |
1206 .Bind(&done1) | 1187 .Bind(&done1) |
1207 .Return(); | 1188 .Return(); |
1208 | 1189 |
1209 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1190 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1210 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1191 InterpreterTester tester(isolate, bytecode_array); |
1211 auto callable = tester.GetCallable<>(); | 1192 auto callable = tester.GetCallable<>(); |
1212 Handle<Object> return_value = callable().ToHandleChecked(); | 1193 Handle<Object> return_value = callable().ToHandleChecked(); |
1213 CHECK_EQ(Smi::cast(*return_value)->value(), 7); | 1194 CHECK_EQ(Smi::cast(*return_value)->value(), 7); |
1214 } | 1195 } |
1215 | 1196 |
1216 TEST(InterpreterJumpConstantWith16BitOperand) { | 1197 TEST(InterpreterJumpConstantWith16BitOperand) { |
1217 HandleAndZoneScope handles; | 1198 HandleAndZoneScope handles; |
1218 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1199 Isolate* isolate = handles.main_isolate(); |
1219 0, 257); | 1200 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 257); |
1220 | 1201 |
1221 i::Isolate* isolate = handles.main_isolate(); | 1202 Zone zone(isolate->allocator()); |
1222 i::Zone zone(isolate->allocator()); | |
1223 | 1203 |
1224 i::FeedbackVectorSpec feedback_spec(&zone); | 1204 FeedbackVectorSpec feedback_spec(&zone); |
1225 i::FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); | 1205 FeedbackVectorSlot slot = feedback_spec.AddGeneralSlot(); |
1226 Handle<i::TypeFeedbackVector> vector = | 1206 Handle<i::TypeFeedbackVector> vector = |
1227 i::NewTypeFeedbackVector(isolate, &feedback_spec); | 1207 NewTypeFeedbackVector(isolate, &feedback_spec); |
1228 | 1208 |
1229 Register reg(0), scratch(256); | 1209 Register reg(0), scratch(256); |
1230 BytecodeLabel done, fake; | 1210 BytecodeLabel done, fake; |
1231 | 1211 |
1232 builder.LoadLiteral(Smi::FromInt(0)); | 1212 builder.LoadLiteral(Smi::FromInt(0)); |
1233 builder.StoreAccumulatorInRegister(reg); | 1213 builder.StoreAccumulatorInRegister(reg); |
1234 // Consume all 8-bit operands | 1214 // Consume all 8-bit operands |
1235 for (int i = 1; i <= 256; i++) { | 1215 for (int i = 1; i <= 256; i++) { |
1236 builder.LoadLiteral(handles.main_isolate()->factory()->NewNumber(i)); | 1216 builder.LoadLiteral(isolate->factory()->NewNumber(i)); |
1237 builder.BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)); | 1217 builder.BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)); |
1238 builder.StoreAccumulatorInRegister(reg); | 1218 builder.StoreAccumulatorInRegister(reg); |
1239 } | 1219 } |
1240 builder.Jump(&done); | 1220 builder.Jump(&done); |
1241 | 1221 |
1242 // Emit more than 16-bit immediate operands worth of code to jump over. | 1222 // Emit more than 16-bit immediate operands worth of code to jump over. |
1243 builder.Bind(&fake); | 1223 builder.Bind(&fake); |
1244 for (int i = 0; i < 6600; i++) { | 1224 for (int i = 0; i < 6600; i++) { |
1245 builder.LoadLiteral(Smi::FromInt(0)); // 1-byte | 1225 builder.LoadLiteral(Smi::FromInt(0)); // 1-byte |
1246 builder.BinaryOperation(Token::Value::ADD, scratch, | 1226 builder.BinaryOperation(Token::Value::ADD, scratch, |
1247 vector->GetIndex(slot)); // 6-bytes | 1227 vector->GetIndex(slot)); // 6-bytes |
1248 builder.StoreAccumulatorInRegister(scratch); // 4-bytes | 1228 builder.StoreAccumulatorInRegister(scratch); // 4-bytes |
1249 builder.MoveRegister(scratch, reg); // 6-bytes | 1229 builder.MoveRegister(scratch, reg); // 6-bytes |
1250 } | 1230 } |
1251 builder.Bind(&done); | 1231 builder.Bind(&done); |
1252 builder.LoadAccumulatorWithRegister(reg); | 1232 builder.LoadAccumulatorWithRegister(reg); |
1253 builder.Return(); | 1233 builder.Return(); |
1254 | 1234 |
1255 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1235 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1256 BytecodeArrayIterator iterator(bytecode_array); | 1236 BytecodeArrayIterator iterator(bytecode_array); |
1257 | 1237 |
1258 bool found_16bit_constant_jump = false; | 1238 bool found_16bit_constant_jump = false; |
1259 while (!iterator.done()) { | 1239 while (!iterator.done()) { |
1260 if (iterator.current_bytecode() == Bytecode::kJumpConstant && | 1240 if (iterator.current_bytecode() == Bytecode::kJumpConstant && |
1261 iterator.current_operand_scale() == OperandScale::kDouble) { | 1241 iterator.current_operand_scale() == OperandScale::kDouble) { |
1262 found_16bit_constant_jump = true; | 1242 found_16bit_constant_jump = true; |
1263 break; | 1243 break; |
1264 } | 1244 } |
1265 iterator.Advance(); | 1245 iterator.Advance(); |
1266 } | 1246 } |
1267 CHECK(found_16bit_constant_jump); | 1247 CHECK(found_16bit_constant_jump); |
1268 | 1248 |
1269 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1249 InterpreterTester tester(isolate, bytecode_array); |
1270 auto callable = tester.GetCallable<>(); | 1250 auto callable = tester.GetCallable<>(); |
1271 Handle<Object> return_value = callable().ToHandleChecked(); | 1251 Handle<Object> return_value = callable().ToHandleChecked(); |
1272 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256)); | 1252 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256)); |
1273 } | 1253 } |
1274 | 1254 |
1275 TEST(InterpreterJumpWith32BitOperand) { | 1255 TEST(InterpreterJumpWith32BitOperand) { |
1276 HandleAndZoneScope handles; | 1256 HandleAndZoneScope handles; |
1277 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1257 Isolate* isolate = handles.main_isolate(); |
1278 0, 1); | 1258 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); |
1279 Register reg(0); | 1259 Register reg(0); |
1280 BytecodeLabel done; | 1260 BytecodeLabel done; |
1281 | 1261 |
1282 builder.LoadLiteral(Smi::FromInt(0)); | 1262 builder.LoadLiteral(Smi::FromInt(0)); |
1283 builder.StoreAccumulatorInRegister(reg); | 1263 builder.StoreAccumulatorInRegister(reg); |
1284 // Consume all 16-bit constant pool entries | 1264 // Consume all 16-bit constant pool entries |
1285 for (int i = 1; i <= 65536; i++) { | 1265 for (int i = 1; i <= 65536; i++) { |
1286 builder.LoadLiteral(handles.main_isolate()->factory()->NewNumber(i)); | 1266 builder.LoadLiteral(isolate->factory()->NewNumber(i)); |
1287 } | 1267 } |
1288 builder.Jump(&done); | 1268 builder.Jump(&done); |
1289 builder.LoadLiteral(Smi::FromInt(0)); | 1269 builder.LoadLiteral(Smi::FromInt(0)); |
1290 builder.Bind(&done); | 1270 builder.Bind(&done); |
1291 builder.Return(); | 1271 builder.Return(); |
1292 | 1272 |
1293 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1273 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1294 BytecodeArrayIterator iterator(bytecode_array); | 1274 BytecodeArrayIterator iterator(bytecode_array); |
1295 | 1275 |
1296 bool found_32bit_jump = false; | 1276 bool found_32bit_jump = false; |
1297 while (!iterator.done()) { | 1277 while (!iterator.done()) { |
1298 if (iterator.current_bytecode() == Bytecode::kJump && | 1278 if (iterator.current_bytecode() == Bytecode::kJump && |
1299 iterator.current_operand_scale() == OperandScale::kQuadruple) { | 1279 iterator.current_operand_scale() == OperandScale::kQuadruple) { |
1300 found_32bit_jump = true; | 1280 found_32bit_jump = true; |
1301 break; | 1281 break; |
1302 } | 1282 } |
1303 iterator.Advance(); | 1283 iterator.Advance(); |
1304 } | 1284 } |
1305 CHECK(found_32bit_jump); | 1285 CHECK(found_32bit_jump); |
1306 | 1286 |
1307 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1287 InterpreterTester tester(isolate, bytecode_array); |
1308 auto callable = tester.GetCallable<>(); | 1288 auto callable = tester.GetCallable<>(); |
1309 Handle<Object> return_value = callable().ToHandleChecked(); | 1289 Handle<Object> return_value = callable().ToHandleChecked(); |
1310 CHECK_EQ(Smi::cast(*return_value)->value(), 65536.0); | 1290 CHECK_EQ(Smi::cast(*return_value)->value(), 65536.0); |
1311 } | 1291 } |
1312 | 1292 |
1313 static const Token::Value kComparisonTypes[] = { | 1293 static const Token::Value kComparisonTypes[] = { |
1314 Token::Value::EQ, Token::Value::NE, Token::Value::EQ_STRICT, | 1294 Token::Value::EQ, Token::Value::NE, Token::Value::EQ_STRICT, |
1315 Token::Value::LT, Token::Value::LTE, Token::Value::GT, | 1295 Token::Value::LT, Token::Value::LTE, Token::Value::GT, |
1316 Token::Value::GTE}; | 1296 Token::Value::GTE}; |
1317 | 1297 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 42, | 1336 42, |
1357 12345678, | 1337 12345678, |
1358 v8::internal::kMaxInt / 4, | 1338 v8::internal::kMaxInt / 4, |
1359 v8::internal::kMaxInt / 2}; | 1339 v8::internal::kMaxInt / 2}; |
1360 | 1340 |
1361 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1341 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1362 Token::Value comparison = kComparisonTypes[c]; | 1342 Token::Value comparison = kComparisonTypes[c]; |
1363 for (size_t i = 0; i < arraysize(inputs); i++) { | 1343 for (size_t i = 0; i < arraysize(inputs); i++) { |
1364 for (size_t j = 0; j < arraysize(inputs); j++) { | 1344 for (size_t j = 0; j < arraysize(inputs); j++) { |
1365 HandleAndZoneScope handles; | 1345 HandleAndZoneScope handles; |
1366 BytecodeArrayBuilder builder(handles.main_isolate(), | 1346 Isolate* isolate = handles.main_isolate(); |
1367 handles.main_zone(), 0, 0, 1); | 1347 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1368 | 1348 |
1369 Register r0(0); | 1349 Register r0(0); |
1370 builder.LoadLiteral(Smi::FromInt(inputs[i])) | 1350 builder.LoadLiteral(Smi::FromInt(inputs[i])) |
1371 .StoreAccumulatorInRegister(r0) | 1351 .StoreAccumulatorInRegister(r0) |
1372 .LoadLiteral(Smi::FromInt(inputs[j])) | 1352 .LoadLiteral(Smi::FromInt(inputs[j])) |
1373 .CompareOperation(comparison, r0) | 1353 .CompareOperation(comparison, r0) |
1374 .Return(); | 1354 .Return(); |
1375 | 1355 |
1376 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1356 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1377 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1357 InterpreterTester tester(isolate, bytecode_array); |
1378 auto callable = tester.GetCallable<>(); | 1358 auto callable = tester.GetCallable<>(); |
1379 Handle<Object> return_value = callable().ToHandleChecked(); | 1359 Handle<Object> return_value = callable().ToHandleChecked(); |
1380 CHECK(return_value->IsBoolean()); | 1360 CHECK(return_value->IsBoolean()); |
1381 CHECK_EQ(return_value->BooleanValue(), | 1361 CHECK_EQ(return_value->BooleanValue(), |
1382 CompareC(comparison, inputs[i], inputs[j])); | 1362 CompareC(comparison, inputs[i], inputs[j])); |
1383 } | 1363 } |
1384 } | 1364 } |
1385 } | 1365 } |
1386 } | 1366 } |
1387 | 1367 |
1388 | 1368 |
1389 TEST(InterpreterHeapNumberComparisons) { | 1369 TEST(InterpreterHeapNumberComparisons) { |
1390 double inputs[] = {std::numeric_limits<double>::min(), | 1370 double inputs[] = {std::numeric_limits<double>::min(), |
1391 std::numeric_limits<double>::max(), | 1371 std::numeric_limits<double>::max(), |
1392 -0.001, | 1372 -0.001, |
1393 0.01, | 1373 0.01, |
1394 0.1000001, | 1374 0.1000001, |
1395 1e99, | 1375 1e99, |
1396 -1e-99}; | 1376 -1e-99}; |
1397 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1377 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1398 Token::Value comparison = kComparisonTypes[c]; | 1378 Token::Value comparison = kComparisonTypes[c]; |
1399 for (size_t i = 0; i < arraysize(inputs); i++) { | 1379 for (size_t i = 0; i < arraysize(inputs); i++) { |
1400 for (size_t j = 0; j < arraysize(inputs); j++) { | 1380 for (size_t j = 0; j < arraysize(inputs); j++) { |
1401 HandleAndZoneScope handles; | 1381 HandleAndZoneScope handles; |
1402 i::Factory* factory = handles.main_isolate()->factory(); | 1382 Isolate* isolate = handles.main_isolate(); |
1403 BytecodeArrayBuilder builder(handles.main_isolate(), | 1383 Factory* factory = isolate->factory(); |
1404 handles.main_zone(), 0, 0, 1); | 1384 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1405 | 1385 |
1406 Register r0(0); | 1386 Register r0(0); |
1407 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) | 1387 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) |
1408 .StoreAccumulatorInRegister(r0) | 1388 .StoreAccumulatorInRegister(r0) |
1409 .LoadLiteral(factory->NewHeapNumber(inputs[j])) | 1389 .LoadLiteral(factory->NewHeapNumber(inputs[j])) |
1410 .CompareOperation(comparison, r0) | 1390 .CompareOperation(comparison, r0) |
1411 .Return(); | 1391 .Return(); |
1412 | 1392 |
1413 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1393 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1414 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1394 InterpreterTester tester(isolate, bytecode_array); |
1415 auto callable = tester.GetCallable<>(); | 1395 auto callable = tester.GetCallable<>(); |
1416 Handle<Object> return_value = callable().ToHandleChecked(); | 1396 Handle<Object> return_value = callable().ToHandleChecked(); |
1417 CHECK(return_value->IsBoolean()); | 1397 CHECK(return_value->IsBoolean()); |
1418 CHECK_EQ(return_value->BooleanValue(), | 1398 CHECK_EQ(return_value->BooleanValue(), |
1419 CompareC(comparison, inputs[i], inputs[j])); | 1399 CompareC(comparison, inputs[i], inputs[j])); |
1420 } | 1400 } |
1421 } | 1401 } |
1422 } | 1402 } |
1423 } | 1403 } |
1424 | 1404 |
1425 | 1405 |
1426 TEST(InterpreterStringComparisons) { | 1406 TEST(InterpreterStringComparisons) { |
1427 HandleAndZoneScope handles; | 1407 HandleAndZoneScope handles; |
1428 i::Isolate* isolate = handles.main_isolate(); | 1408 Isolate* isolate = handles.main_isolate(); |
1429 i::Factory* factory = isolate->factory(); | 1409 Factory* factory = isolate->factory(); |
1430 | 1410 |
1431 std::string inputs[] = {"A", "abc", "z", "", "Foo!", "Foo"}; | 1411 std::string inputs[] = {"A", "abc", "z", "", "Foo!", "Foo"}; |
1432 | 1412 |
1433 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1413 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1434 Token::Value comparison = kComparisonTypes[c]; | 1414 Token::Value comparison = kComparisonTypes[c]; |
1435 for (size_t i = 0; i < arraysize(inputs); i++) { | 1415 for (size_t i = 0; i < arraysize(inputs); i++) { |
1436 for (size_t j = 0; j < arraysize(inputs); j++) { | 1416 for (size_t j = 0; j < arraysize(inputs); j++) { |
1437 CanonicalHandleScope canonical(isolate); | 1417 CanonicalHandleScope canonical(isolate); |
1438 const char* lhs = inputs[i].c_str(); | 1418 const char* lhs = inputs[i].c_str(); |
1439 const char* rhs = inputs[j].c_str(); | 1419 const char* rhs = inputs[j].c_str(); |
1440 BytecodeArrayBuilder builder(handles.main_isolate(), | 1420 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1441 handles.main_zone(), 0, 0, 1); | |
1442 Register r0(0); | 1421 Register r0(0); |
1443 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) | 1422 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) |
1444 .StoreAccumulatorInRegister(r0) | 1423 .StoreAccumulatorInRegister(r0) |
1445 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) | 1424 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) |
1446 .CompareOperation(comparison, r0) | 1425 .CompareOperation(comparison, r0) |
1447 .Return(); | 1426 .Return(); |
1448 | 1427 |
1449 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1428 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1450 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1429 InterpreterTester tester(isolate, bytecode_array); |
1451 auto callable = tester.GetCallable<>(); | 1430 auto callable = tester.GetCallable<>(); |
1452 Handle<Object> return_value = callable().ToHandleChecked(); | 1431 Handle<Object> return_value = callable().ToHandleChecked(); |
1453 CHECK(return_value->IsBoolean()); | 1432 CHECK(return_value->IsBoolean()); |
1454 CHECK_EQ(return_value->BooleanValue(), | 1433 CHECK_EQ(return_value->BooleanValue(), |
1455 CompareC(comparison, inputs[i], inputs[j])); | 1434 CompareC(comparison, inputs[i], inputs[j])); |
1456 } | 1435 } |
1457 } | 1436 } |
1458 } | 1437 } |
1459 } | 1438 } |
1460 | 1439 |
1461 | 1440 |
1462 TEST(InterpreterMixedComparisons) { | 1441 TEST(InterpreterMixedComparisons) { |
1463 // This test compares a HeapNumber with a String. The latter is | 1442 // This test compares a HeapNumber with a String. The latter is |
1464 // convertible to a HeapNumber so comparison will be between numeric | 1443 // convertible to a HeapNumber so comparison will be between numeric |
1465 // values except for the strict comparisons where no conversion is | 1444 // values except for the strict comparisons where no conversion is |
1466 // performed. | 1445 // performed. |
1467 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; | 1446 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; |
1468 | 1447 |
1469 i::UnicodeCache unicode_cache; | 1448 UnicodeCache unicode_cache; |
1470 | 1449 |
1471 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { | 1450 for (size_t c = 0; c < arraysize(kComparisonTypes); c++) { |
1472 Token::Value comparison = kComparisonTypes[c]; | 1451 Token::Value comparison = kComparisonTypes[c]; |
1473 for (size_t i = 0; i < arraysize(inputs); i++) { | 1452 for (size_t i = 0; i < arraysize(inputs); i++) { |
1474 for (size_t j = 0; j < arraysize(inputs); j++) { | 1453 for (size_t j = 0; j < arraysize(inputs); j++) { |
1475 for (int pass = 0; pass < 2; pass++) { | 1454 for (int pass = 0; pass < 2; pass++) { |
1476 const char* lhs_cstr = inputs[i]; | 1455 const char* lhs_cstr = inputs[i]; |
1477 const char* rhs_cstr = inputs[j]; | 1456 const char* rhs_cstr = inputs[j]; |
1478 double lhs = StringToDouble(&unicode_cache, lhs_cstr, | 1457 double lhs = StringToDouble(&unicode_cache, lhs_cstr, |
1479 i::ConversionFlags::NO_FLAGS); | 1458 ConversionFlags::NO_FLAGS); |
1480 double rhs = StringToDouble(&unicode_cache, rhs_cstr, | 1459 double rhs = StringToDouble(&unicode_cache, rhs_cstr, |
1481 i::ConversionFlags::NO_FLAGS); | 1460 ConversionFlags::NO_FLAGS); |
1482 HandleAndZoneScope handles; | 1461 HandleAndZoneScope handles; |
1483 i::Factory* factory = handles.main_isolate()->factory(); | 1462 Isolate* isolate = handles.main_isolate(); |
1484 BytecodeArrayBuilder builder(handles.main_isolate(), | 1463 Factory* factory = isolate->factory(); |
1485 handles.main_zone(), 0, 0, 1); | 1464 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1486 | 1465 |
1487 Register r0(0); | 1466 Register r0(0); |
1488 if (pass == 0) { | 1467 if (pass == 0) { |
1489 // Comparison with HeapNumber on the lhs and String on the rhs | 1468 // Comparison with HeapNumber on the lhs and String on the rhs |
1490 builder.LoadLiteral(factory->NewNumber(lhs)) | 1469 builder.LoadLiteral(factory->NewNumber(lhs)) |
1491 .StoreAccumulatorInRegister(r0) | 1470 .StoreAccumulatorInRegister(r0) |
1492 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) | 1471 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) |
1493 .CompareOperation(comparison, r0) | 1472 .CompareOperation(comparison, r0) |
1494 .Return(); | 1473 .Return(); |
1495 } else { | 1474 } else { |
1496 // Comparison with HeapNumber on the rhs and String on the lhs | 1475 // Comparison with HeapNumber on the rhs and String on the lhs |
1497 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs_cstr)) | 1476 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs_cstr)) |
1498 .StoreAccumulatorInRegister(r0) | 1477 .StoreAccumulatorInRegister(r0) |
1499 .LoadLiteral(factory->NewNumber(rhs)) | 1478 .LoadLiteral(factory->NewNumber(rhs)) |
1500 .CompareOperation(comparison, r0) | 1479 .CompareOperation(comparison, r0) |
1501 .Return(); | 1480 .Return(); |
1502 } | 1481 } |
1503 | 1482 |
1504 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1483 Handle<BytecodeArray> bytecode_array = |
1505 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1484 builder.ToBytecodeArray(isolate); |
| 1485 InterpreterTester tester(isolate, bytecode_array); |
1506 auto callable = tester.GetCallable<>(); | 1486 auto callable = tester.GetCallable<>(); |
1507 Handle<Object> return_value = callable().ToHandleChecked(); | 1487 Handle<Object> return_value = callable().ToHandleChecked(); |
1508 CHECK(return_value->IsBoolean()); | 1488 CHECK(return_value->IsBoolean()); |
1509 CHECK_EQ(return_value->BooleanValue(), | 1489 CHECK_EQ(return_value->BooleanValue(), |
1510 CompareC(comparison, lhs, rhs, true)); | 1490 CompareC(comparison, lhs, rhs, true)); |
1511 } | 1491 } |
1512 } | 1492 } |
1513 } | 1493 } |
1514 } | 1494 } |
1515 } | 1495 } |
1516 | 1496 |
1517 TEST(InterpreterStrictNotEqual) { | 1497 TEST(InterpreterStrictNotEqual) { |
1518 HandleAndZoneScope handles; | 1498 HandleAndZoneScope handles; |
1519 i::Factory* factory = handles.main_isolate()->factory(); | 1499 Isolate* isolate = handles.main_isolate(); |
| 1500 Factory* factory = isolate->factory(); |
1520 const char* code_snippet = | 1501 const char* code_snippet = |
1521 "function f(lhs, rhs) {\n" | 1502 "function f(lhs, rhs) {\n" |
1522 " return lhs !== rhs;\n" | 1503 " return lhs !== rhs;\n" |
1523 "}\n" | 1504 "}\n" |
1524 "f(0, 0);\n"; | 1505 "f(0, 0);\n"; |
1525 InterpreterTester tester(handles.main_isolate(), code_snippet); | 1506 InterpreterTester tester(isolate, code_snippet); |
1526 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 1507 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
1527 | 1508 |
1528 // Test passing different types. | 1509 // Test passing different types. |
1529 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; | 1510 const char* inputs[] = {"-1.77", "-40.333", "0.01", "55.77e5", "2.01"}; |
1530 i::UnicodeCache unicode_cache; | 1511 UnicodeCache unicode_cache; |
1531 for (size_t i = 0; i < arraysize(inputs); i++) { | 1512 for (size_t i = 0; i < arraysize(inputs); i++) { |
1532 for (size_t j = 0; j < arraysize(inputs); j++) { | 1513 for (size_t j = 0; j < arraysize(inputs); j++) { |
1533 double lhs = StringToDouble(&unicode_cache, inputs[i], | 1514 double lhs = |
1534 i::ConversionFlags::NO_FLAGS); | 1515 StringToDouble(&unicode_cache, inputs[i], ConversionFlags::NO_FLAGS); |
1535 double rhs = StringToDouble(&unicode_cache, inputs[j], | 1516 double rhs = |
1536 i::ConversionFlags::NO_FLAGS); | 1517 StringToDouble(&unicode_cache, inputs[j], ConversionFlags::NO_FLAGS); |
1537 Handle<Object> lhs_obj = factory->NewNumber(lhs); | 1518 Handle<Object> lhs_obj = factory->NewNumber(lhs); |
1538 Handle<Object> rhs_obj = factory->NewStringFromAsciiChecked(inputs[j]); | 1519 Handle<Object> rhs_obj = factory->NewStringFromAsciiChecked(inputs[j]); |
1539 | 1520 |
1540 Handle<Object> return_value = | 1521 Handle<Object> return_value = |
1541 callable(lhs_obj, rhs_obj).ToHandleChecked(); | 1522 callable(lhs_obj, rhs_obj).ToHandleChecked(); |
1542 CHECK(return_value->IsBoolean()); | 1523 CHECK(return_value->IsBoolean()); |
1543 CHECK_EQ(return_value->BooleanValue(), | 1524 CHECK_EQ(return_value->BooleanValue(), |
1544 CompareC(Token::Value::NE_STRICT, lhs, rhs, true)); | 1525 CompareC(Token::Value::NE_STRICT, lhs, rhs, true)); |
1545 } | 1526 } |
1546 } | 1527 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 CHECK(return_value->IsBoolean()); | 1561 CHECK(return_value->IsBoolean()); |
1581 CHECK_EQ(return_value->BooleanValue(), | 1562 CHECK_EQ(return_value->BooleanValue(), |
1582 CompareC(Token::Value::NE_STRICT, inputs_number[i], | 1563 CompareC(Token::Value::NE_STRICT, inputs_number[i], |
1583 inputs_number[j])); | 1564 inputs_number[j])); |
1584 } | 1565 } |
1585 } | 1566 } |
1586 } | 1567 } |
1587 | 1568 |
1588 TEST(InterpreterInstanceOf) { | 1569 TEST(InterpreterInstanceOf) { |
1589 HandleAndZoneScope handles; | 1570 HandleAndZoneScope handles; |
1590 i::Factory* factory = handles.main_isolate()->factory(); | 1571 Isolate* isolate = handles.main_isolate(); |
| 1572 Factory* factory = isolate->factory(); |
1591 Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); | 1573 Handle<i::String> name = factory->NewStringFromAsciiChecked("cons"); |
1592 Handle<i::JSFunction> func = factory->NewFunction(name); | 1574 Handle<i::JSFunction> func = factory->NewFunction(name); |
1593 Handle<i::JSObject> instance = factory->NewJSObject(func); | 1575 Handle<i::JSObject> instance = factory->NewJSObject(func); |
1594 Handle<i::Object> other = factory->NewNumber(3.3333); | 1576 Handle<i::Object> other = factory->NewNumber(3.3333); |
1595 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; | 1577 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; |
1596 for (size_t i = 0; i < arraysize(cases); i++) { | 1578 for (size_t i = 0; i < arraysize(cases); i++) { |
1597 bool expected_value = (i == 0); | 1579 bool expected_value = (i == 0); |
1598 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1580 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1599 0, 1); | |
1600 | 1581 |
1601 Register r0(0); | 1582 Register r0(0); |
1602 builder.LoadLiteral(cases[i]); | 1583 builder.LoadLiteral(cases[i]); |
1603 builder.StoreAccumulatorInRegister(r0) | 1584 builder.StoreAccumulatorInRegister(r0) |
1604 .LoadLiteral(func) | 1585 .LoadLiteral(func) |
1605 .CompareOperation(Token::Value::INSTANCEOF, r0) | 1586 .CompareOperation(Token::Value::INSTANCEOF, r0) |
1606 .Return(); | 1587 .Return(); |
1607 | 1588 |
1608 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1589 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1609 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1590 InterpreterTester tester(isolate, bytecode_array); |
1610 auto callable = tester.GetCallable<>(); | 1591 auto callable = tester.GetCallable<>(); |
1611 Handle<Object> return_value = callable().ToHandleChecked(); | 1592 Handle<Object> return_value = callable().ToHandleChecked(); |
1612 CHECK(return_value->IsBoolean()); | 1593 CHECK(return_value->IsBoolean()); |
1613 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1594 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1614 } | 1595 } |
1615 } | 1596 } |
1616 | 1597 |
1617 | 1598 |
1618 TEST(InterpreterTestIn) { | 1599 TEST(InterpreterTestIn) { |
1619 HandleAndZoneScope handles; | 1600 HandleAndZoneScope handles; |
1620 i::Factory* factory = handles.main_isolate()->factory(); | 1601 Isolate* isolate = handles.main_isolate(); |
| 1602 Factory* factory = isolate->factory(); |
1621 // Allocate an array | 1603 // Allocate an array |
1622 Handle<i::JSArray> array = | 1604 Handle<i::JSArray> array = |
1623 factory->NewJSArray(0, i::ElementsKind::FAST_SMI_ELEMENTS); | 1605 factory->NewJSArray(0, i::ElementsKind::FAST_SMI_ELEMENTS); |
1624 // Check for these properties on the array object | 1606 // Check for these properties on the array object |
1625 const char* properties[] = {"length", "fuzzle", "x", "0"}; | 1607 const char* properties[] = {"length", "fuzzle", "x", "0"}; |
1626 for (size_t i = 0; i < arraysize(properties); i++) { | 1608 for (size_t i = 0; i < arraysize(properties); i++) { |
1627 bool expected_value = (i == 0); | 1609 bool expected_value = (i == 0); |
1628 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1610 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 1); |
1629 0, 1); | |
1630 | 1611 |
1631 Register r0(0); | 1612 Register r0(0); |
1632 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) | 1613 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) |
1633 .StoreAccumulatorInRegister(r0) | 1614 .StoreAccumulatorInRegister(r0) |
1634 .LoadLiteral(Handle<Object>::cast(array)) | 1615 .LoadLiteral(Handle<Object>::cast(array)) |
1635 .CompareOperation(Token::Value::IN, r0) | 1616 .CompareOperation(Token::Value::IN, r0) |
1636 .Return(); | 1617 .Return(); |
1637 | 1618 |
1638 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1619 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1639 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1620 InterpreterTester tester(isolate, bytecode_array); |
1640 auto callable = tester.GetCallable<>(); | 1621 auto callable = tester.GetCallable<>(); |
1641 Handle<Object> return_value = callable().ToHandleChecked(); | 1622 Handle<Object> return_value = callable().ToHandleChecked(); |
1642 CHECK(return_value->IsBoolean()); | 1623 CHECK(return_value->IsBoolean()); |
1643 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1624 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1644 } | 1625 } |
1645 } | 1626 } |
1646 | 1627 |
1647 | 1628 |
1648 TEST(InterpreterUnaryNot) { | 1629 TEST(InterpreterUnaryNot) { |
1649 HandleAndZoneScope handles; | 1630 HandleAndZoneScope handles; |
| 1631 Isolate* isolate = handles.main_isolate(); |
1650 for (size_t i = 1; i < 10; i++) { | 1632 for (size_t i = 1; i < 10; i++) { |
1651 bool expected_value = ((i & 1) == 1); | 1633 bool expected_value = ((i & 1) == 1); |
1652 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1634 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 0); |
1653 0, 0); | |
1654 | 1635 |
1655 Register r0(0); | 1636 Register r0(0); |
1656 builder.LoadFalse(); | 1637 builder.LoadFalse(); |
1657 for (size_t j = 0; j < i; j++) { | 1638 for (size_t j = 0; j < i; j++) { |
1658 builder.LogicalNot(); | 1639 builder.LogicalNot(); |
1659 } | 1640 } |
1660 builder.Return(); | 1641 builder.Return(); |
1661 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1642 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1662 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1643 InterpreterTester tester(isolate, bytecode_array); |
1663 auto callable = tester.GetCallable<>(); | 1644 auto callable = tester.GetCallable<>(); |
1664 Handle<Object> return_value = callable().ToHandleChecked(); | 1645 Handle<Object> return_value = callable().ToHandleChecked(); |
1665 CHECK(return_value->IsBoolean()); | 1646 CHECK(return_value->IsBoolean()); |
1666 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1647 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1667 } | 1648 } |
1668 } | 1649 } |
1669 | 1650 |
1670 | 1651 |
1671 static void LoadAny(BytecodeArrayBuilder* builder, | 1652 static void LoadAny(BytecodeArrayBuilder* builder, |
1672 v8::internal::Factory* factory, Handle<Object> obj) { | 1653 v8::internal::Factory* factory, Handle<Object> obj) { |
(...skipping 14 matching lines...) Expand all Loading... |
1687 } else if (obj->IsSmi()) { | 1668 } else if (obj->IsSmi()) { |
1688 builder->LoadLiteral(*Handle<Smi>::cast(obj)); | 1669 builder->LoadLiteral(*Handle<Smi>::cast(obj)); |
1689 } else { | 1670 } else { |
1690 builder->LoadLiteral(obj); | 1671 builder->LoadLiteral(obj); |
1691 } | 1672 } |
1692 } | 1673 } |
1693 | 1674 |
1694 | 1675 |
1695 TEST(InterpreterUnaryNotNonBoolean) { | 1676 TEST(InterpreterUnaryNotNonBoolean) { |
1696 HandleAndZoneScope handles; | 1677 HandleAndZoneScope handles; |
1697 i::Factory* factory = handles.main_isolate()->factory(); | 1678 Isolate* isolate = handles.main_isolate(); |
| 1679 Factory* factory = isolate->factory(); |
1698 | 1680 |
1699 std::pair<Handle<Object>, bool> object_type_tuples[] = { | 1681 std::pair<Handle<Object>, bool> object_type_tuples[] = { |
1700 std::make_pair(factory->undefined_value(), true), | 1682 std::make_pair(factory->undefined_value(), true), |
1701 std::make_pair(factory->null_value(), true), | 1683 std::make_pair(factory->null_value(), true), |
1702 std::make_pair(factory->false_value(), true), | 1684 std::make_pair(factory->false_value(), true), |
1703 std::make_pair(factory->true_value(), false), | 1685 std::make_pair(factory->true_value(), false), |
1704 std::make_pair(factory->NewNumber(9.1), false), | 1686 std::make_pair(factory->NewNumber(9.1), false), |
1705 std::make_pair(factory->NewNumberFromInt(0), true), | 1687 std::make_pair(factory->NewNumberFromInt(0), true), |
1706 std::make_pair( | 1688 std::make_pair( |
1707 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), | 1689 Handle<Object>::cast(factory->NewStringFromStaticChars("hello")), |
1708 false), | 1690 false), |
1709 std::make_pair( | 1691 std::make_pair( |
1710 Handle<Object>::cast(factory->NewStringFromStaticChars("")), true), | 1692 Handle<Object>::cast(factory->NewStringFromStaticChars("")), true), |
1711 }; | 1693 }; |
1712 | 1694 |
1713 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { | 1695 for (size_t i = 0; i < arraysize(object_type_tuples); i++) { |
1714 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 0, | 1696 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 0, 0, 0); |
1715 0, 0); | |
1716 | 1697 |
1717 Register r0(0); | 1698 Register r0(0); |
1718 LoadAny(&builder, factory, object_type_tuples[i].first); | 1699 LoadAny(&builder, factory, object_type_tuples[i].first); |
1719 builder.LogicalNot(); | 1700 builder.LogicalNot(); |
1720 builder.Return(); | 1701 builder.Return(); |
1721 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1702 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1722 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1703 InterpreterTester tester(isolate, bytecode_array); |
1723 auto callable = tester.GetCallable<>(); | 1704 auto callable = tester.GetCallable<>(); |
1724 Handle<Object> return_value = callable().ToHandleChecked(); | 1705 Handle<Object> return_value = callable().ToHandleChecked(); |
1725 CHECK(return_value->IsBoolean()); | 1706 CHECK(return_value->IsBoolean()); |
1726 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); | 1707 CHECK_EQ(return_value->BooleanValue(), object_type_tuples[i].second); |
1727 } | 1708 } |
1728 } | 1709 } |
1729 | 1710 |
1730 | 1711 |
1731 TEST(InterpreterTypeof) { | 1712 TEST(InterpreterTypeof) { |
1732 HandleAndZoneScope handles; | 1713 HandleAndZoneScope handles; |
| 1714 Isolate* isolate = handles.main_isolate(); |
1733 | 1715 |
1734 std::pair<const char*, const char*> typeof_vals[] = { | 1716 std::pair<const char*, const char*> typeof_vals[] = { |
1735 std::make_pair("return typeof undefined;", "undefined"), | 1717 std::make_pair("return typeof undefined;", "undefined"), |
1736 std::make_pair("return typeof null;", "object"), | 1718 std::make_pair("return typeof null;", "object"), |
1737 std::make_pair("return typeof true;", "boolean"), | 1719 std::make_pair("return typeof true;", "boolean"), |
1738 std::make_pair("return typeof false;", "boolean"), | 1720 std::make_pair("return typeof false;", "boolean"), |
1739 std::make_pair("return typeof 9.1;", "number"), | 1721 std::make_pair("return typeof 9.1;", "number"), |
1740 std::make_pair("return typeof 7771;", "number"), | 1722 std::make_pair("return typeof 7771;", "number"), |
1741 std::make_pair("return typeof 'hello';", "string"), | 1723 std::make_pair("return typeof 'hello';", "string"), |
1742 std::make_pair("return typeof global_unallocated;", "undefined"), | 1724 std::make_pair("return typeof global_unallocated;", "undefined"), |
1743 }; | 1725 }; |
1744 | 1726 |
1745 for (size_t i = 0; i < arraysize(typeof_vals); i++) { | 1727 for (size_t i = 0; i < arraysize(typeof_vals); i++) { |
1746 std::string source(InterpreterTester::SourceForBody(typeof_vals[i].first)); | 1728 std::string source(InterpreterTester::SourceForBody(typeof_vals[i].first)); |
1747 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1729 InterpreterTester tester(isolate, source.c_str()); |
1748 | 1730 |
1749 auto callable = tester.GetCallable<>(); | 1731 auto callable = tester.GetCallable<>(); |
1750 Handle<v8::internal::String> return_value = | 1732 Handle<v8::internal::String> return_value = |
1751 Handle<v8::internal::String>::cast(callable().ToHandleChecked()); | 1733 Handle<v8::internal::String>::cast(callable().ToHandleChecked()); |
1752 auto actual = return_value->ToCString(); | 1734 auto actual = return_value->ToCString(); |
1753 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0); | 1735 CHECK_EQ(strcmp(&actual[0], typeof_vals[i].second), 0); |
1754 } | 1736 } |
1755 } | 1737 } |
1756 | 1738 |
1757 | 1739 |
1758 TEST(InterpreterCallRuntime) { | 1740 TEST(InterpreterCallRuntime) { |
1759 HandleAndZoneScope handles; | 1741 HandleAndZoneScope handles; |
| 1742 Isolate* isolate = handles.main_isolate(); |
1760 | 1743 |
1761 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1744 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 2); |
1762 0, 2); | |
1763 | 1745 |
1764 builder.LoadLiteral(Smi::FromInt(15)) | 1746 builder.LoadLiteral(Smi::FromInt(15)) |
1765 .StoreAccumulatorInRegister(Register(0)) | 1747 .StoreAccumulatorInRegister(Register(0)) |
1766 .LoadLiteral(Smi::FromInt(40)) | 1748 .LoadLiteral(Smi::FromInt(40)) |
1767 .StoreAccumulatorInRegister(Register(1)) | 1749 .StoreAccumulatorInRegister(Register(1)) |
1768 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1750 .CallRuntime(Runtime::kAdd, Register(0), 2) |
1769 .Return(); | 1751 .Return(); |
1770 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1752 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1771 | 1753 |
1772 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1754 InterpreterTester tester(isolate, bytecode_array); |
1773 auto callable = tester.GetCallable<>(); | 1755 auto callable = tester.GetCallable<>(); |
1774 | 1756 |
1775 Handle<Object> return_val = callable().ToHandleChecked(); | 1757 Handle<Object> return_val = callable().ToHandleChecked(); |
1776 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1758 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
1777 } | 1759 } |
1778 | 1760 |
1779 TEST(InterpreterInvokeIntrinsic) { | 1761 TEST(InterpreterInvokeIntrinsic) { |
1780 HandleAndZoneScope handles; | 1762 HandleAndZoneScope handles; |
| 1763 Isolate* isolate = handles.main_isolate(); |
1781 | 1764 |
1782 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, | 1765 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 2); |
1783 0, 2); | |
1784 | 1766 |
1785 builder.LoadLiteral(Smi::FromInt(15)) | 1767 builder.LoadLiteral(Smi::FromInt(15)) |
1786 .StoreAccumulatorInRegister(Register(0)) | 1768 .StoreAccumulatorInRegister(Register(0)) |
1787 .CallRuntime(Runtime::kInlineIsArray, Register(0), 1) | 1769 .CallRuntime(Runtime::kInlineIsArray, Register(0), 1) |
1788 .Return(); | 1770 .Return(); |
1789 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1771 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); |
1790 | 1772 |
1791 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1773 InterpreterTester tester(isolate, bytecode_array); |
1792 auto callable = tester.GetCallable<>(); | 1774 auto callable = tester.GetCallable<>(); |
1793 | 1775 |
1794 Handle<Object> return_val = callable().ToHandleChecked(); | 1776 Handle<Object> return_val = callable().ToHandleChecked(); |
1795 CHECK(return_val->IsBoolean()); | 1777 CHECK(return_val->IsBoolean()); |
1796 CHECK_EQ(return_val->BooleanValue(), false); | 1778 CHECK_EQ(return_val->BooleanValue(), false); |
1797 } | 1779 } |
1798 | 1780 |
1799 TEST(InterpreterFunctionLiteral) { | 1781 TEST(InterpreterFunctionLiteral) { |
1800 HandleAndZoneScope handles; | 1782 HandleAndZoneScope handles; |
| 1783 Isolate* isolate = handles.main_isolate(); |
1801 | 1784 |
1802 // Test calling a function literal. | 1785 // Test calling a function literal. |
1803 std::string source( | 1786 std::string source( |
1804 "function " + InterpreterTester::function_name() + "(a) {\n" | 1787 "function " + InterpreterTester::function_name() + "(a) {\n" |
1805 " return (function(x){ return x + 2; })(a);\n" | 1788 " return (function(x){ return x + 2; })(a);\n" |
1806 "}"); | 1789 "}"); |
1807 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1790 InterpreterTester tester(isolate, source.c_str()); |
1808 auto callable = tester.GetCallable<Handle<Object>>(); | 1791 auto callable = tester.GetCallable<Handle<Object>>(); |
1809 | 1792 |
1810 Handle<i::Object> return_val = callable( | 1793 Handle<i::Object> return_val = callable( |
1811 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); | 1794 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); |
1812 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); | 1795 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
1813 } | 1796 } |
1814 | 1797 |
1815 | 1798 |
1816 TEST(InterpreterRegExpLiterals) { | 1799 TEST(InterpreterRegExpLiterals) { |
1817 HandleAndZoneScope handles; | 1800 HandleAndZoneScope handles; |
1818 i::Isolate* isolate = handles.main_isolate(); | 1801 Isolate* isolate = handles.main_isolate(); |
1819 i::Factory* factory = isolate->factory(); | 1802 Factory* factory = isolate->factory(); |
1820 | 1803 |
1821 std::pair<const char*, Handle<Object>> literals[] = { | 1804 std::pair<const char*, Handle<Object>> literals[] = { |
1822 std::make_pair("return /abd/.exec('cccabbdd');\n", | 1805 std::make_pair("return /abd/.exec('cccabbdd');\n", |
1823 factory->null_value()), | 1806 factory->null_value()), |
1824 std::make_pair("return /ab+d/.exec('cccabbdd')[0];\n", | 1807 std::make_pair("return /ab+d/.exec('cccabbdd')[0];\n", |
1825 factory->NewStringFromStaticChars("abbd")), | 1808 factory->NewStringFromStaticChars("abbd")), |
1826 std::make_pair("return /AbC/i.exec('ssaBC')[0];\n", | 1809 std::make_pair("return /AbC/i.exec('ssaBC')[0];\n", |
1827 factory->NewStringFromStaticChars("aBC")), | 1810 factory->NewStringFromStaticChars("aBC")), |
1828 std::make_pair("return 'ssaBC'.match(/AbC/i)[0];\n", | 1811 std::make_pair("return 'ssaBC'.match(/AbC/i)[0];\n", |
1829 factory->NewStringFromStaticChars("aBC")), | 1812 factory->NewStringFromStaticChars("aBC")), |
1830 std::make_pair("return 'ssaBCtAbC'.match(/(AbC)/gi)[1];\n", | 1813 std::make_pair("return 'ssaBCtAbC'.match(/(AbC)/gi)[1];\n", |
1831 factory->NewStringFromStaticChars("AbC")), | 1814 factory->NewStringFromStaticChars("AbC")), |
1832 }; | 1815 }; |
1833 | 1816 |
1834 for (size_t i = 0; i < arraysize(literals); i++) { | 1817 for (size_t i = 0; i < arraysize(literals); i++) { |
1835 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1818 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1836 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1819 InterpreterTester tester(isolate, source.c_str()); |
1837 auto callable = tester.GetCallable<>(); | 1820 auto callable = tester.GetCallable<>(); |
1838 | 1821 |
1839 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1822 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1840 CHECK(return_value->SameValue(*literals[i].second)); | 1823 CHECK(return_value->SameValue(*literals[i].second)); |
1841 } | 1824 } |
1842 } | 1825 } |
1843 | 1826 |
1844 | 1827 |
1845 TEST(InterpreterArrayLiterals) { | 1828 TEST(InterpreterArrayLiterals) { |
1846 HandleAndZoneScope handles; | 1829 HandleAndZoneScope handles; |
1847 i::Isolate* isolate = handles.main_isolate(); | 1830 Isolate* isolate = handles.main_isolate(); |
1848 i::Factory* factory = isolate->factory(); | 1831 Factory* factory = isolate->factory(); |
1849 | 1832 |
1850 std::pair<const char*, Handle<Object>> literals[] = { | 1833 std::pair<const char*, Handle<Object>> literals[] = { |
1851 std::make_pair("return [][0];\n", | 1834 std::make_pair("return [][0];\n", |
1852 factory->undefined_value()), | 1835 factory->undefined_value()), |
1853 std::make_pair("return [1, 3, 2][1];\n", | 1836 std::make_pair("return [1, 3, 2][1];\n", |
1854 handle(Smi::FromInt(3), isolate)), | 1837 handle(Smi::FromInt(3), isolate)), |
1855 std::make_pair("return ['a', 'b', 'c'][2];\n", | 1838 std::make_pair("return ['a', 'b', 'c'][2];\n", |
1856 factory->NewStringFromStaticChars("c")), | 1839 factory->NewStringFromStaticChars("c")), |
1857 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n", | 1840 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n", |
1858 handle(Smi::FromInt(102), isolate)), | 1841 handle(Smi::FromInt(102), isolate)), |
1859 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n", | 1842 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n", |
1860 factory->NewStringFromStaticChars("a")), | 1843 factory->NewStringFromStaticChars("a")), |
1861 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n", | 1844 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n", |
1862 factory->NewStringFromStaticChars("test")) | 1845 factory->NewStringFromStaticChars("test")) |
1863 }; | 1846 }; |
1864 | 1847 |
1865 for (size_t i = 0; i < arraysize(literals); i++) { | 1848 for (size_t i = 0; i < arraysize(literals); i++) { |
1866 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1849 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1867 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1850 InterpreterTester tester(isolate, source.c_str()); |
1868 auto callable = tester.GetCallable<>(); | 1851 auto callable = tester.GetCallable<>(); |
1869 | 1852 |
1870 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1853 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1871 CHECK(return_value->SameValue(*literals[i].second)); | 1854 CHECK(return_value->SameValue(*literals[i].second)); |
1872 } | 1855 } |
1873 } | 1856 } |
1874 | 1857 |
1875 | 1858 |
1876 TEST(InterpreterObjectLiterals) { | 1859 TEST(InterpreterObjectLiterals) { |
1877 HandleAndZoneScope handles; | 1860 HandleAndZoneScope handles; |
1878 i::Isolate* isolate = handles.main_isolate(); | 1861 Isolate* isolate = handles.main_isolate(); |
1879 i::Factory* factory = isolate->factory(); | 1862 Factory* factory = isolate->factory(); |
1880 | 1863 |
1881 std::pair<const char*, Handle<Object>> literals[] = { | 1864 std::pair<const char*, Handle<Object>> literals[] = { |
1882 std::make_pair("return { }.name;", | 1865 std::make_pair("return { }.name;", |
1883 factory->undefined_value()), | 1866 factory->undefined_value()), |
1884 std::make_pair("return { name: 'string', val: 9.2 }.name;", | 1867 std::make_pair("return { name: 'string', val: 9.2 }.name;", |
1885 factory->NewStringFromStaticChars("string")), | 1868 factory->NewStringFromStaticChars("string")), |
1886 std::make_pair("var a = 15; return { name: 'string', val: a }.val;", | 1869 std::make_pair("var a = 15; return { name: 'string', val: a }.val;", |
1887 handle(Smi::FromInt(15), isolate)), | 1870 handle(Smi::FromInt(15), isolate)), |
1888 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;", | 1871 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;", |
1889 handle(Smi::FromInt(6), isolate)), | 1872 handle(Smi::FromInt(6), isolate)), |
(...skipping 20 matching lines...) Expand all Loading... |
1910 "var b = { [a]: 1, __proto__: { var : a } };\n" | 1893 "var b = { [a]: 1, __proto__: { var : a } };\n" |
1911 "return Object.getPrototypeOf(b).var", | 1894 "return Object.getPrototypeOf(b).var", |
1912 factory->NewStringFromStaticChars("proto_str")), | 1895 factory->NewStringFromStaticChars("proto_str")), |
1913 std::make_pair("var n = 'name';\n" | 1896 std::make_pair("var n = 'name';\n" |
1914 "return { [n]: 'val', get a() { return 987 } }['a'];", | 1897 "return { [n]: 'val', get a() { return 987 } }['a'];", |
1915 handle(Smi::FromInt(987), isolate)), | 1898 handle(Smi::FromInt(987), isolate)), |
1916 }; | 1899 }; |
1917 | 1900 |
1918 for (size_t i = 0; i < arraysize(literals); i++) { | 1901 for (size_t i = 0; i < arraysize(literals); i++) { |
1919 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1902 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1920 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1903 InterpreterTester tester(isolate, source.c_str()); |
1921 auto callable = tester.GetCallable<>(); | 1904 auto callable = tester.GetCallable<>(); |
1922 | 1905 |
1923 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1906 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1924 CHECK(return_value->SameValue(*literals[i].second)); | 1907 CHECK(return_value->SameValue(*literals[i].second)); |
1925 } | 1908 } |
1926 } | 1909 } |
1927 | 1910 |
1928 | 1911 |
1929 TEST(InterpreterConstruct) { | 1912 TEST(InterpreterConstruct) { |
1930 HandleAndZoneScope handles; | 1913 HandleAndZoneScope handles; |
| 1914 Isolate* isolate = handles.main_isolate(); |
1931 | 1915 |
1932 std::string source( | 1916 std::string source( |
1933 "function counter() { this.count = 0; }\n" | 1917 "function counter() { this.count = 0; }\n" |
1934 "function " + | 1918 "function " + |
1935 InterpreterTester::function_name() + | 1919 InterpreterTester::function_name() + |
1936 "() {\n" | 1920 "() {\n" |
1937 " var c = new counter();\n" | 1921 " var c = new counter();\n" |
1938 " return c.count;\n" | 1922 " return c.count;\n" |
1939 "}"); | 1923 "}"); |
1940 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1924 InterpreterTester tester(isolate, source.c_str()); |
1941 auto callable = tester.GetCallable<>(); | 1925 auto callable = tester.GetCallable<>(); |
1942 | 1926 |
1943 Handle<Object> return_val = callable().ToHandleChecked(); | 1927 Handle<Object> return_val = callable().ToHandleChecked(); |
1944 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); | 1928 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); |
1945 } | 1929 } |
1946 | 1930 |
1947 | 1931 |
1948 TEST(InterpreterConstructWithArgument) { | 1932 TEST(InterpreterConstructWithArgument) { |
1949 HandleAndZoneScope handles; | 1933 HandleAndZoneScope handles; |
| 1934 Isolate* isolate = handles.main_isolate(); |
1950 | 1935 |
1951 std::string source( | 1936 std::string source( |
1952 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" | 1937 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
1953 "function " + | 1938 "function " + |
1954 InterpreterTester::function_name() + | 1939 InterpreterTester::function_name() + |
1955 "() {\n" | 1940 "() {\n" |
1956 " var c = new counter(3);\n" | 1941 " var c = new counter(3);\n" |
1957 " return c.x;\n" | 1942 " return c.x;\n" |
1958 "}"); | 1943 "}"); |
1959 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1944 InterpreterTester tester(isolate, source.c_str()); |
1960 auto callable = tester.GetCallable<>(); | 1945 auto callable = tester.GetCallable<>(); |
1961 | 1946 |
1962 Handle<Object> return_val = callable().ToHandleChecked(); | 1947 Handle<Object> return_val = callable().ToHandleChecked(); |
1963 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 1948 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
1964 } | 1949 } |
1965 | 1950 |
1966 | 1951 |
1967 TEST(InterpreterConstructWithArguments) { | 1952 TEST(InterpreterConstructWithArguments) { |
1968 HandleAndZoneScope handles; | 1953 HandleAndZoneScope handles; |
| 1954 Isolate* isolate = handles.main_isolate(); |
1969 | 1955 |
1970 std::string source( | 1956 std::string source( |
1971 "function counter(arg0, arg1) {\n" | 1957 "function counter(arg0, arg1) {\n" |
1972 " this.count = 7; this.x = arg0; this.y = arg1;\n" | 1958 " this.count = 7; this.x = arg0; this.y = arg1;\n" |
1973 "}\n" | 1959 "}\n" |
1974 "function " + | 1960 "function " + |
1975 InterpreterTester::function_name() + | 1961 InterpreterTester::function_name() + |
1976 "() {\n" | 1962 "() {\n" |
1977 " var c = new counter(3, 5);\n" | 1963 " var c = new counter(3, 5);\n" |
1978 " return c.count + c.x + c.y;\n" | 1964 " return c.count + c.x + c.y;\n" |
1979 "}"); | 1965 "}"); |
1980 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1966 InterpreterTester tester(isolate, source.c_str()); |
1981 auto callable = tester.GetCallable<>(); | 1967 auto callable = tester.GetCallable<>(); |
1982 | 1968 |
1983 Handle<Object> return_val = callable().ToHandleChecked(); | 1969 Handle<Object> return_val = callable().ToHandleChecked(); |
1984 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); | 1970 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
1985 } | 1971 } |
1986 | 1972 |
1987 | 1973 |
1988 TEST(InterpreterContextVariables) { | 1974 TEST(InterpreterContextVariables) { |
1989 HandleAndZoneScope handles; | 1975 HandleAndZoneScope handles; |
1990 i::Isolate* isolate = handles.main_isolate(); | 1976 Isolate* isolate = handles.main_isolate(); |
1991 | 1977 |
1992 std::ostringstream unique_vars; | 1978 std::ostringstream unique_vars; |
1993 for (int i = 0; i < 250; i++) { | 1979 for (int i = 0; i < 250; i++) { |
1994 unique_vars << "var a" << i << " = 0;"; | 1980 unique_vars << "var a" << i << " = 0;"; |
1995 } | 1981 } |
1996 std::pair<std::string, Handle<Object>> context_vars[] = { | 1982 std::pair<std::string, Handle<Object>> context_vars[] = { |
1997 std::make_pair("var a; (function() { a = 1; })(); return a;", | 1983 std::make_pair("var a; (function() { a = 1; })(); return a;", |
1998 handle(Smi::FromInt(1), isolate)), | 1984 handle(Smi::FromInt(1), isolate)), |
1999 std::make_pair("var a = 10; (function() { a; })(); return a;", | 1985 std::make_pair("var a = 10; (function() { a; })(); return a;", |
2000 handle(Smi::FromInt(10), isolate)), | 1986 handle(Smi::FromInt(10), isolate)), |
2001 std::make_pair("var a = 20; var b = 30;\n" | 1987 std::make_pair("var a = 20; var b = 30;\n" |
2002 "return (function() { return a + b; })();", | 1988 "return (function() { return a + b; })();", |
2003 handle(Smi::FromInt(50), isolate)), | 1989 handle(Smi::FromInt(50), isolate)), |
2004 std::make_pair("'use strict'; let a = 1;\n" | 1990 std::make_pair("'use strict'; let a = 1;\n" |
2005 "{ let b = 2; return (function() { return a + b; })(); }", | 1991 "{ let b = 2; return (function() { return a + b; })(); }", |
2006 handle(Smi::FromInt(3), isolate)), | 1992 handle(Smi::FromInt(3), isolate)), |
2007 std::make_pair("'use strict'; let a = 10;\n" | 1993 std::make_pair("'use strict'; let a = 10;\n" |
2008 "{ let b = 20; var c = function() { [a, b] };\n" | 1994 "{ let b = 20; var c = function() { [a, b] };\n" |
2009 " return a + b; }", | 1995 " return a + b; }", |
2010 handle(Smi::FromInt(30), isolate)), | 1996 handle(Smi::FromInt(30), isolate)), |
2011 std::make_pair("'use strict';" + unique_vars.str() + | 1997 std::make_pair("'use strict';" + unique_vars.str() + |
2012 "eval(); var b = 100; return b;", | 1998 "eval(); var b = 100; return b;", |
2013 handle(Smi::FromInt(100), isolate)), | 1999 handle(Smi::FromInt(100), isolate)), |
2014 }; | 2000 }; |
2015 | 2001 |
2016 for (size_t i = 0; i < arraysize(context_vars); i++) { | 2002 for (size_t i = 0; i < arraysize(context_vars); i++) { |
2017 std::string source( | 2003 std::string source( |
2018 InterpreterTester::SourceForBody(context_vars[i].first.c_str())); | 2004 InterpreterTester::SourceForBody(context_vars[i].first.c_str())); |
2019 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2005 InterpreterTester tester(isolate, source.c_str()); |
2020 auto callable = tester.GetCallable<>(); | 2006 auto callable = tester.GetCallable<>(); |
2021 | 2007 |
2022 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2008 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2023 CHECK(return_value->SameValue(*context_vars[i].second)); | 2009 CHECK(return_value->SameValue(*context_vars[i].second)); |
2024 } | 2010 } |
2025 } | 2011 } |
2026 | 2012 |
2027 | 2013 |
2028 TEST(InterpreterContextParameters) { | 2014 TEST(InterpreterContextParameters) { |
2029 HandleAndZoneScope handles; | 2015 HandleAndZoneScope handles; |
2030 i::Isolate* isolate = handles.main_isolate(); | 2016 Isolate* isolate = handles.main_isolate(); |
2031 | 2017 |
2032 std::pair<const char*, Handle<Object>> context_params[] = { | 2018 std::pair<const char*, Handle<Object>> context_params[] = { |
2033 std::make_pair("return (function() { return arg1; })();", | 2019 std::make_pair("return (function() { return arg1; })();", |
2034 handle(Smi::FromInt(1), isolate)), | 2020 handle(Smi::FromInt(1), isolate)), |
2035 std::make_pair("(function() { arg1 = 4; })(); return arg1;", | 2021 std::make_pair("(function() { arg1 = 4; })(); return arg1;", |
2036 handle(Smi::FromInt(4), isolate)), | 2022 handle(Smi::FromInt(4), isolate)), |
2037 std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;", | 2023 std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;", |
2038 handle(Smi::FromInt(1), isolate)), | 2024 handle(Smi::FromInt(1), isolate)), |
2039 }; | 2025 }; |
2040 | 2026 |
2041 for (size_t i = 0; i < arraysize(context_params); i++) { | 2027 for (size_t i = 0; i < arraysize(context_params); i++) { |
2042 std::string source = "function " + InterpreterTester::function_name() + | 2028 std::string source = "function " + InterpreterTester::function_name() + |
2043 "(arg1, arg2, arg3) {" + context_params[i].first + "}"; | 2029 "(arg1, arg2, arg3) {" + context_params[i].first + "}"; |
2044 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2030 InterpreterTester tester(isolate, source.c_str()); |
2045 auto callable = | 2031 auto callable = |
2046 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 2032 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
2047 | 2033 |
2048 Handle<Object> a1 = handle(Smi::FromInt(1), isolate); | 2034 Handle<Object> a1 = handle(Smi::FromInt(1), isolate); |
2049 Handle<Object> a2 = handle(Smi::FromInt(2), isolate); | 2035 Handle<Object> a2 = handle(Smi::FromInt(2), isolate); |
2050 Handle<Object> a3 = handle(Smi::FromInt(3), isolate); | 2036 Handle<Object> a3 = handle(Smi::FromInt(3), isolate); |
2051 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); | 2037 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); |
2052 CHECK(return_value->SameValue(*context_params[i].second)); | 2038 CHECK(return_value->SameValue(*context_params[i].second)); |
2053 } | 2039 } |
2054 } | 2040 } |
2055 | 2041 |
2056 | 2042 |
2057 TEST(InterpreterOuterContextVariables) { | 2043 TEST(InterpreterOuterContextVariables) { |
2058 HandleAndZoneScope handles; | 2044 HandleAndZoneScope handles; |
2059 i::Isolate* isolate = handles.main_isolate(); | 2045 Isolate* isolate = handles.main_isolate(); |
2060 | 2046 |
2061 std::pair<const char*, Handle<Object>> context_vars[] = { | 2047 std::pair<const char*, Handle<Object>> context_vars[] = { |
2062 std::make_pair("return outerVar * innerArg;", | 2048 std::make_pair("return outerVar * innerArg;", |
2063 handle(Smi::FromInt(200), isolate)), | 2049 handle(Smi::FromInt(200), isolate)), |
2064 std::make_pair("outerVar = innerArg; return outerVar", | 2050 std::make_pair("outerVar = innerArg; return outerVar", |
2065 handle(Smi::FromInt(20), isolate)), | 2051 handle(Smi::FromInt(20), isolate)), |
2066 }; | 2052 }; |
2067 | 2053 |
2068 std::string header( | 2054 std::string header( |
2069 "function Outer() {" | 2055 "function Outer() {" |
2070 " var outerVar = 10;" | 2056 " var outerVar = 10;" |
2071 " function Inner(innerArg) {" | 2057 " function Inner(innerArg) {" |
2072 " this.innerFunc = function() { "); | 2058 " this.innerFunc = function() { "); |
2073 std::string footer( | 2059 std::string footer( |
2074 " }}" | 2060 " }}" |
2075 " this.getInnerFunc = function() { return new Inner(20).innerFunc; }" | 2061 " this.getInnerFunc = function() { return new Inner(20).innerFunc; }" |
2076 "}" | 2062 "}" |
2077 "var f = new Outer().getInnerFunc();"); | 2063 "var f = new Outer().getInnerFunc();"); |
2078 | 2064 |
2079 for (size_t i = 0; i < arraysize(context_vars); i++) { | 2065 for (size_t i = 0; i < arraysize(context_vars); i++) { |
2080 std::string source = header + context_vars[i].first + footer; | 2066 std::string source = header + context_vars[i].first + footer; |
2081 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 2067 InterpreterTester tester(isolate, source.c_str(), "*"); |
2082 auto callable = tester.GetCallable<>(); | 2068 auto callable = tester.GetCallable<>(); |
2083 | 2069 |
2084 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2070 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2085 CHECK(return_value->SameValue(*context_vars[i].second)); | 2071 CHECK(return_value->SameValue(*context_vars[i].second)); |
2086 } | 2072 } |
2087 } | 2073 } |
2088 | 2074 |
2089 | 2075 |
2090 TEST(InterpreterComma) { | 2076 TEST(InterpreterComma) { |
2091 HandleAndZoneScope handles; | 2077 HandleAndZoneScope handles; |
2092 i::Isolate* isolate = handles.main_isolate(); | 2078 Isolate* isolate = handles.main_isolate(); |
2093 i::Factory* factory = isolate->factory(); | 2079 Factory* factory = isolate->factory(); |
2094 | 2080 |
2095 std::pair<const char*, Handle<Object>> literals[] = { | 2081 std::pair<const char*, Handle<Object>> literals[] = { |
2096 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), | 2082 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), |
2097 std::make_pair("return 'a', 2.2, 3;\n", | 2083 std::make_pair("return 'a', 2.2, 3;\n", |
2098 handle(Smi::FromInt(3), isolate)), | 2084 handle(Smi::FromInt(3), isolate)), |
2099 std::make_pair("return 'a', 'b', 'c';\n", | 2085 std::make_pair("return 'a', 'b', 'c';\n", |
2100 factory->NewStringFromStaticChars("c")), | 2086 factory->NewStringFromStaticChars("c")), |
2101 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)), | 2087 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)), |
2102 std::make_pair("var a = 10; return b = a, b = b+1;\n", | 2088 std::make_pair("var a = 10; return b = a, b = b+1;\n", |
2103 handle(Smi::FromInt(11), isolate)), | 2089 handle(Smi::FromInt(11), isolate)), |
2104 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n", | 2090 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n", |
2105 handle(Smi::FromInt(21), isolate))}; | 2091 handle(Smi::FromInt(21), isolate))}; |
2106 | 2092 |
2107 for (size_t i = 0; i < arraysize(literals); i++) { | 2093 for (size_t i = 0; i < arraysize(literals); i++) { |
2108 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 2094 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
2109 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2095 InterpreterTester tester(isolate, source.c_str()); |
2110 auto callable = tester.GetCallable<>(); | 2096 auto callable = tester.GetCallable<>(); |
2111 | 2097 |
2112 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2098 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2113 CHECK(return_value->SameValue(*literals[i].second)); | 2099 CHECK(return_value->SameValue(*literals[i].second)); |
2114 } | 2100 } |
2115 } | 2101 } |
2116 | 2102 |
2117 | 2103 |
2118 TEST(InterpreterLogicalOr) { | 2104 TEST(InterpreterLogicalOr) { |
2119 HandleAndZoneScope handles; | 2105 HandleAndZoneScope handles; |
2120 i::Isolate* isolate = handles.main_isolate(); | 2106 Isolate* isolate = handles.main_isolate(); |
2121 i::Factory* factory = isolate->factory(); | 2107 Factory* factory = isolate->factory(); |
2122 | 2108 |
2123 std::pair<const char*, Handle<Object>> literals[] = { | 2109 std::pair<const char*, Handle<Object>> literals[] = { |
2124 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), | 2110 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), |
2125 std::make_pair("var a, b = 10; return a || b;\n", | 2111 std::make_pair("var a, b = 10; return a || b;\n", |
2126 handle(Smi::FromInt(10), isolate)), | 2112 handle(Smi::FromInt(10), isolate)), |
2127 std::make_pair("var a = '0', b = 10; return a || b;\n", | 2113 std::make_pair("var a = '0', b = 10; return a || b;\n", |
2128 factory->NewStringFromStaticChars("0")), | 2114 factory->NewStringFromStaticChars("0")), |
2129 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), | 2115 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), |
2130 std::make_pair("return 'a' || 0;\n", | 2116 std::make_pair("return 'a' || 0;\n", |
2131 factory->NewStringFromStaticChars("a")), | 2117 factory->NewStringFromStaticChars("a")), |
2132 std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n", | 2118 std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n", |
2133 factory->true_value())}; | 2119 factory->true_value())}; |
2134 | 2120 |
2135 for (size_t i = 0; i < arraysize(literals); i++) { | 2121 for (size_t i = 0; i < arraysize(literals); i++) { |
2136 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 2122 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
2137 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2123 InterpreterTester tester(isolate, source.c_str()); |
2138 auto callable = tester.GetCallable<>(); | 2124 auto callable = tester.GetCallable<>(); |
2139 | 2125 |
2140 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2126 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2141 CHECK(return_value->SameValue(*literals[i].second)); | 2127 CHECK(return_value->SameValue(*literals[i].second)); |
2142 } | 2128 } |
2143 } | 2129 } |
2144 | 2130 |
2145 | 2131 |
2146 TEST(InterpreterLogicalAnd) { | 2132 TEST(InterpreterLogicalAnd) { |
2147 HandleAndZoneScope handles; | 2133 HandleAndZoneScope handles; |
2148 i::Isolate* isolate = handles.main_isolate(); | 2134 Isolate* isolate = handles.main_isolate(); |
2149 i::Factory* factory = isolate->factory(); | 2135 Factory* factory = isolate->factory(); |
2150 | 2136 |
2151 std::pair<const char*, Handle<Object>> literals[] = { | 2137 std::pair<const char*, Handle<Object>> literals[] = { |
2152 std::make_pair("var a, b = 10; return a && b;\n", | 2138 std::make_pair("var a, b = 10; return a && b;\n", |
2153 factory->undefined_value()), | 2139 factory->undefined_value()), |
2154 std::make_pair("var a = 0, b = 10; return a && b / a;\n", | 2140 std::make_pair("var a = 0, b = 10; return a && b / a;\n", |
2155 handle(Smi::FromInt(0), isolate)), | 2141 handle(Smi::FromInt(0), isolate)), |
2156 std::make_pair("var a = '0', b = 10; return a && b;\n", | 2142 std::make_pair("var a = '0', b = 10; return a && b;\n", |
2157 handle(Smi::FromInt(10), isolate)), | 2143 handle(Smi::FromInt(10), isolate)), |
2158 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)), | 2144 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)), |
2159 std::make_pair("return 'a' && 'b';\n", | 2145 std::make_pair("return 'a' && 'b';\n", |
2160 factory->NewStringFromStaticChars("b")), | 2146 factory->NewStringFromStaticChars("b")), |
2161 std::make_pair("return 'a' && 0 || 'b', 'c';\n", | 2147 std::make_pair("return 'a' && 0 || 'b', 'c';\n", |
2162 factory->NewStringFromStaticChars("c")), | 2148 factory->NewStringFromStaticChars("c")), |
2163 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", | 2149 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", |
2164 handle(Smi::FromInt(1), isolate)), | 2150 handle(Smi::FromInt(1), isolate)), |
2165 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n", | 2151 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n", |
2166 factory->true_value())}; | 2152 factory->true_value())}; |
2167 | 2153 |
2168 for (size_t i = 0; i < arraysize(literals); i++) { | 2154 for (size_t i = 0; i < arraysize(literals); i++) { |
2169 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 2155 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
2170 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2156 InterpreterTester tester(isolate, source.c_str()); |
2171 auto callable = tester.GetCallable<>(); | 2157 auto callable = tester.GetCallable<>(); |
2172 | 2158 |
2173 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2159 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2174 CHECK(return_value->SameValue(*literals[i].second)); | 2160 CHECK(return_value->SameValue(*literals[i].second)); |
2175 } | 2161 } |
2176 } | 2162 } |
2177 | 2163 |
2178 | 2164 |
2179 TEST(InterpreterTryCatch) { | 2165 TEST(InterpreterTryCatch) { |
2180 HandleAndZoneScope handles; | 2166 HandleAndZoneScope handles; |
2181 i::Isolate* isolate = handles.main_isolate(); | 2167 Isolate* isolate = handles.main_isolate(); |
2182 | 2168 |
2183 std::pair<const char*, Handle<Object>> catches[] = { | 2169 std::pair<const char*, Handle<Object>> catches[] = { |
2184 std::make_pair("var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", | 2170 std::make_pair("var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", |
2185 handle(Smi::FromInt(2), isolate)), | 2171 handle(Smi::FromInt(2), isolate)), |
2186 std::make_pair("var a; try { undef.x } catch(e) { a = 2 }; return a;", | 2172 std::make_pair("var a; try { undef.x } catch(e) { a = 2 }; return a;", |
2187 handle(Smi::FromInt(2), isolate)), | 2173 handle(Smi::FromInt(2), isolate)), |
2188 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", | 2174 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", |
2189 handle(Smi::FromInt(3), isolate)), | 2175 handle(Smi::FromInt(3), isolate)), |
2190 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 };" | 2176 std::make_pair("var a; try { throw 1 } catch(e) { a = e + 2 };" |
2191 " try { throw a } catch(e) { a = e + 3 }; return a;", | 2177 " try { throw a } catch(e) { a = e + 3 }; return a;", |
2192 handle(Smi::FromInt(6), isolate)), | 2178 handle(Smi::FromInt(6), isolate)), |
2193 }; | 2179 }; |
2194 | 2180 |
2195 for (size_t i = 0; i < arraysize(catches); i++) { | 2181 for (size_t i = 0; i < arraysize(catches); i++) { |
2196 std::string source(InterpreterTester::SourceForBody(catches[i].first)); | 2182 std::string source(InterpreterTester::SourceForBody(catches[i].first)); |
2197 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2183 InterpreterTester tester(isolate, source.c_str()); |
2198 auto callable = tester.GetCallable<>(); | 2184 auto callable = tester.GetCallable<>(); |
2199 | 2185 |
2200 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2186 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2201 CHECK(return_value->SameValue(*catches[i].second)); | 2187 CHECK(return_value->SameValue(*catches[i].second)); |
2202 } | 2188 } |
2203 } | 2189 } |
2204 | 2190 |
2205 | 2191 |
2206 TEST(InterpreterTryFinally) { | 2192 TEST(InterpreterTryFinally) { |
2207 HandleAndZoneScope handles; | 2193 HandleAndZoneScope handles; |
2208 i::Isolate* isolate = handles.main_isolate(); | 2194 Isolate* isolate = handles.main_isolate(); |
2209 i::Factory* factory = isolate->factory(); | 2195 Factory* factory = isolate->factory(); |
2210 | 2196 |
2211 std::pair<const char*, Handle<Object>> finallies[] = { | 2197 std::pair<const char*, Handle<Object>> finallies[] = { |
2212 std::make_pair( | 2198 std::make_pair( |
2213 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", | 2199 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", |
2214 factory->NewStringFromStaticChars("R4")), | 2200 factory->NewStringFromStaticChars("R4")), |
2215 std::make_pair( | 2201 std::make_pair( |
2216 "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", | 2202 "var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", |
2217 factory->NewStringFromStaticChars("R23")), | 2203 factory->NewStringFromStaticChars("R23")), |
2218 std::make_pair( | 2204 std::make_pair( |
2219 "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", | 2205 "var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", |
(...skipping 25 matching lines...) Expand all Loading... |
2245 "tcf2();" | 2231 "tcf2();" |
2246 "return func_name;", | 2232 "return func_name;", |
2247 factory->NewStringFromStaticChars("Rtcf2")), | 2233 factory->NewStringFromStaticChars("Rtcf2")), |
2248 }; | 2234 }; |
2249 | 2235 |
2250 const char* try_wrapper = | 2236 const char* try_wrapper = |
2251 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()"; | 2237 "(function() { try { return 'R' + f() } catch(e) { return 'E' + e }})()"; |
2252 | 2238 |
2253 for (size_t i = 0; i < arraysize(finallies); i++) { | 2239 for (size_t i = 0; i < arraysize(finallies); i++) { |
2254 std::string source(InterpreterTester::SourceForBody(finallies[i].first)); | 2240 std::string source(InterpreterTester::SourceForBody(finallies[i].first)); |
2255 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2241 InterpreterTester tester(isolate, source.c_str()); |
2256 tester.GetCallable<>(); | 2242 tester.GetCallable<>(); |
2257 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | 2243 Handle<Object> wrapped = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); |
2258 CHECK(wrapped->SameValue(*finallies[i].second)); | 2244 CHECK(wrapped->SameValue(*finallies[i].second)); |
2259 } | 2245 } |
2260 } | 2246 } |
2261 | 2247 |
2262 | 2248 |
2263 TEST(InterpreterThrow) { | 2249 TEST(InterpreterThrow) { |
2264 HandleAndZoneScope handles; | 2250 HandleAndZoneScope handles; |
2265 i::Isolate* isolate = handles.main_isolate(); | 2251 Isolate* isolate = handles.main_isolate(); |
2266 i::Factory* factory = isolate->factory(); | 2252 Factory* factory = isolate->factory(); |
2267 | 2253 |
2268 std::pair<const char*, Handle<Object>> throws[] = { | 2254 std::pair<const char*, Handle<Object>> throws[] = { |
2269 std::make_pair("throw undefined;\n", | 2255 std::make_pair("throw undefined;\n", |
2270 factory->undefined_value()), | 2256 factory->undefined_value()), |
2271 std::make_pair("throw 1;\n", | 2257 std::make_pair("throw 1;\n", |
2272 handle(Smi::FromInt(1), isolate)), | 2258 handle(Smi::FromInt(1), isolate)), |
2273 std::make_pair("throw 'Error';\n", | 2259 std::make_pair("throw 'Error';\n", |
2274 factory->NewStringFromStaticChars("Error")), | 2260 factory->NewStringFromStaticChars("Error")), |
2275 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", | 2261 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", |
2276 factory->NewStringFromStaticChars("Error")), | 2262 factory->NewStringFromStaticChars("Error")), |
2277 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", | 2263 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", |
2278 factory->undefined_value()), | 2264 factory->undefined_value()), |
2279 std::make_pair("throw 'Error1'; throw 'Error2'\n", | 2265 std::make_pair("throw 'Error1'; throw 'Error2'\n", |
2280 factory->NewStringFromStaticChars("Error1")), | 2266 factory->NewStringFromStaticChars("Error1")), |
2281 }; | 2267 }; |
2282 | 2268 |
2283 const char* try_wrapper = | 2269 const char* try_wrapper = |
2284 "(function() { try { f(); } catch(e) { return e; }})()"; | 2270 "(function() { try { f(); } catch(e) { return e; }})()"; |
2285 | 2271 |
2286 for (size_t i = 0; i < arraysize(throws); i++) { | 2272 for (size_t i = 0; i < arraysize(throws); i++) { |
2287 std::string source(InterpreterTester::SourceForBody(throws[i].first)); | 2273 std::string source(InterpreterTester::SourceForBody(throws[i].first)); |
2288 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2274 InterpreterTester tester(isolate, source.c_str()); |
2289 tester.GetCallable<>(); | 2275 tester.GetCallable<>(); |
2290 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | 2276 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); |
2291 CHECK(thrown_obj->SameValue(*throws[i].second)); | 2277 CHECK(thrown_obj->SameValue(*throws[i].second)); |
2292 } | 2278 } |
2293 } | 2279 } |
2294 | 2280 |
2295 | 2281 |
2296 TEST(InterpreterCountOperators) { | 2282 TEST(InterpreterCountOperators) { |
2297 HandleAndZoneScope handles; | 2283 HandleAndZoneScope handles; |
2298 i::Isolate* isolate = handles.main_isolate(); | 2284 Isolate* isolate = handles.main_isolate(); |
2299 i::Factory* factory = isolate->factory(); | 2285 Factory* factory = isolate->factory(); |
2300 | 2286 |
2301 std::pair<const char*, Handle<Object>> count_ops[] = { | 2287 std::pair<const char*, Handle<Object>> count_ops[] = { |
2302 std::make_pair("var a = 1; return ++a;", | 2288 std::make_pair("var a = 1; return ++a;", |
2303 handle(Smi::FromInt(2), isolate)), | 2289 handle(Smi::FromInt(2), isolate)), |
2304 std::make_pair("var a = 1; return a++;", | 2290 std::make_pair("var a = 1; return a++;", |
2305 handle(Smi::FromInt(1), isolate)), | 2291 handle(Smi::FromInt(1), isolate)), |
2306 std::make_pair("var a = 5; return --a;", | 2292 std::make_pair("var a = 5; return --a;", |
2307 handle(Smi::FromInt(4), isolate)), | 2293 handle(Smi::FromInt(4), isolate)), |
2308 std::make_pair("var a = 5; return a--;", | 2294 std::make_pair("var a = 5; return a--;", |
2309 handle(Smi::FromInt(5), isolate)), | 2295 handle(Smi::FromInt(5), isolate)), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2341 handle(Smi::FromInt(1), isolate)), | 2327 handle(Smi::FromInt(1), isolate)), |
2342 std::make_pair("var i = 20; switch(i++) {\n" | 2328 std::make_pair("var i = 20; switch(i++) {\n" |
2343 " case 20: return 1;\n" | 2329 " case 20: return 1;\n" |
2344 " default: return 2;\n" | 2330 " default: return 2;\n" |
2345 "}", | 2331 "}", |
2346 handle(Smi::FromInt(1), isolate)), | 2332 handle(Smi::FromInt(1), isolate)), |
2347 }; | 2333 }; |
2348 | 2334 |
2349 for (size_t i = 0; i < arraysize(count_ops); i++) { | 2335 for (size_t i = 0; i < arraysize(count_ops); i++) { |
2350 std::string source(InterpreterTester::SourceForBody(count_ops[i].first)); | 2336 std::string source(InterpreterTester::SourceForBody(count_ops[i].first)); |
2351 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2337 InterpreterTester tester(isolate, source.c_str()); |
2352 auto callable = tester.GetCallable<>(); | 2338 auto callable = tester.GetCallable<>(); |
2353 | 2339 |
2354 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2340 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2355 CHECK(return_value->SameValue(*count_ops[i].second)); | 2341 CHECK(return_value->SameValue(*count_ops[i].second)); |
2356 } | 2342 } |
2357 } | 2343 } |
2358 | 2344 |
2359 | 2345 |
2360 TEST(InterpreterGlobalCountOperators) { | 2346 TEST(InterpreterGlobalCountOperators) { |
2361 HandleAndZoneScope handles; | 2347 HandleAndZoneScope handles; |
2362 i::Isolate* isolate = handles.main_isolate(); | 2348 Isolate* isolate = handles.main_isolate(); |
2363 | 2349 |
2364 std::pair<const char*, Handle<Object>> count_ops[] = { | 2350 std::pair<const char*, Handle<Object>> count_ops[] = { |
2365 std::make_pair("var global = 100;function f(){ return ++global; }", | 2351 std::make_pair("var global = 100;function f(){ return ++global; }", |
2366 handle(Smi::FromInt(101), isolate)), | 2352 handle(Smi::FromInt(101), isolate)), |
2367 std::make_pair("var global = 100; function f(){ return --global; }", | 2353 std::make_pair("var global = 100; function f(){ return --global; }", |
2368 handle(Smi::FromInt(99), isolate)), | 2354 handle(Smi::FromInt(99), isolate)), |
2369 std::make_pair("var global = 100; function f(){ return global++; }", | 2355 std::make_pair("var global = 100; function f(){ return global++; }", |
2370 handle(Smi::FromInt(100), isolate)), | 2356 handle(Smi::FromInt(100), isolate)), |
2371 std::make_pair("unallocated = 200; function f(){ return ++unallocated; }", | 2357 std::make_pair("unallocated = 200; function f(){ return ++unallocated; }", |
2372 handle(Smi::FromInt(201), isolate)), | 2358 handle(Smi::FromInt(201), isolate)), |
2373 std::make_pair("unallocated = 200; function f(){ return --unallocated; }", | 2359 std::make_pair("unallocated = 200; function f(){ return --unallocated; }", |
2374 handle(Smi::FromInt(199), isolate)), | 2360 handle(Smi::FromInt(199), isolate)), |
2375 std::make_pair("unallocated = 200; function f(){ return unallocated++; }", | 2361 std::make_pair("unallocated = 200; function f(){ return unallocated++; }", |
2376 handle(Smi::FromInt(200), isolate)), | 2362 handle(Smi::FromInt(200), isolate)), |
2377 }; | 2363 }; |
2378 | 2364 |
2379 for (size_t i = 0; i < arraysize(count_ops); i++) { | 2365 for (size_t i = 0; i < arraysize(count_ops); i++) { |
2380 InterpreterTester tester(handles.main_isolate(), count_ops[i].first); | 2366 InterpreterTester tester(isolate, count_ops[i].first); |
2381 auto callable = tester.GetCallable<>(); | 2367 auto callable = tester.GetCallable<>(); |
2382 | 2368 |
2383 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2369 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2384 CHECK(return_value->SameValue(*count_ops[i].second)); | 2370 CHECK(return_value->SameValue(*count_ops[i].second)); |
2385 } | 2371 } |
2386 } | 2372 } |
2387 | 2373 |
2388 | 2374 |
2389 TEST(InterpreterCompoundExpressions) { | 2375 TEST(InterpreterCompoundExpressions) { |
2390 HandleAndZoneScope handles; | 2376 HandleAndZoneScope handles; |
2391 i::Isolate* isolate = handles.main_isolate(); | 2377 Isolate* isolate = handles.main_isolate(); |
2392 i::Factory* factory = isolate->factory(); | 2378 Factory* factory = isolate->factory(); |
2393 | 2379 |
2394 std::pair<const char*, Handle<Object>> compound_expr[] = { | 2380 std::pair<const char*, Handle<Object>> compound_expr[] = { |
2395 std::make_pair("var a = 1; a += 2; return a;", | 2381 std::make_pair("var a = 1; a += 2; return a;", |
2396 Handle<Object>(Smi::FromInt(3), isolate)), | 2382 Handle<Object>(Smi::FromInt(3), isolate)), |
2397 std::make_pair("var a = 10; a /= 2; return a;", | 2383 std::make_pair("var a = 10; a /= 2; return a;", |
2398 Handle<Object>(Smi::FromInt(5), isolate)), | 2384 Handle<Object>(Smi::FromInt(5), isolate)), |
2399 std::make_pair("var a = 'test'; a += 'ing'; return a;", | 2385 std::make_pair("var a = 'test'; a += 'ing'; return a;", |
2400 factory->NewStringFromStaticChars("testing")), | 2386 factory->NewStringFromStaticChars("testing")), |
2401 std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;", | 2387 std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;", |
2402 Handle<Object>(Smi::FromInt(4), isolate)), | 2388 Handle<Object>(Smi::FromInt(4), isolate)), |
2403 std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;" | 2389 std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;" |
2404 "return a;", | 2390 "return a;", |
2405 Handle<Object>(Smi::FromInt(26), isolate)), | 2391 Handle<Object>(Smi::FromInt(26), isolate)), |
2406 }; | 2392 }; |
2407 | 2393 |
2408 for (size_t i = 0; i < arraysize(compound_expr); i++) { | 2394 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
2409 std::string source( | 2395 std::string source( |
2410 InterpreterTester::SourceForBody(compound_expr[i].first)); | 2396 InterpreterTester::SourceForBody(compound_expr[i].first)); |
2411 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2397 InterpreterTester tester(isolate, source.c_str()); |
2412 auto callable = tester.GetCallable<>(); | 2398 auto callable = tester.GetCallable<>(); |
2413 | 2399 |
2414 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2400 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2415 CHECK(return_value->SameValue(*compound_expr[i].second)); | 2401 CHECK(return_value->SameValue(*compound_expr[i].second)); |
2416 } | 2402 } |
2417 } | 2403 } |
2418 | 2404 |
2419 | 2405 |
2420 TEST(InterpreterGlobalCompoundExpressions) { | 2406 TEST(InterpreterGlobalCompoundExpressions) { |
2421 HandleAndZoneScope handles; | 2407 HandleAndZoneScope handles; |
2422 i::Isolate* isolate = handles.main_isolate(); | 2408 Isolate* isolate = handles.main_isolate(); |
2423 | 2409 |
2424 std::pair<const char*, Handle<Object>> compound_expr[2] = { | 2410 std::pair<const char*, Handle<Object>> compound_expr[2] = { |
2425 std::make_pair("var global = 100;" | 2411 std::make_pair("var global = 100;" |
2426 "function f() { global += 20; return global; }", | 2412 "function f() { global += 20; return global; }", |
2427 Handle<Object>(Smi::FromInt(120), isolate)), | 2413 Handle<Object>(Smi::FromInt(120), isolate)), |
2428 std::make_pair("unallocated = 100;" | 2414 std::make_pair("unallocated = 100;" |
2429 "function f() { unallocated -= 20; return unallocated; }", | 2415 "function f() { unallocated -= 20; return unallocated; }", |
2430 Handle<Object>(Smi::FromInt(80), isolate)), | 2416 Handle<Object>(Smi::FromInt(80), isolate)), |
2431 }; | 2417 }; |
2432 | 2418 |
2433 for (size_t i = 0; i < arraysize(compound_expr); i++) { | 2419 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
2434 InterpreterTester tester(handles.main_isolate(), compound_expr[i].first); | 2420 InterpreterTester tester(isolate, compound_expr[i].first); |
2435 auto callable = tester.GetCallable<>(); | 2421 auto callable = tester.GetCallable<>(); |
2436 | 2422 |
2437 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2423 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2438 CHECK(return_value->SameValue(*compound_expr[i].second)); | 2424 CHECK(return_value->SameValue(*compound_expr[i].second)); |
2439 } | 2425 } |
2440 } | 2426 } |
2441 | 2427 |
2442 | 2428 |
2443 TEST(InterpreterCreateArguments) { | 2429 TEST(InterpreterCreateArguments) { |
2444 HandleAndZoneScope handles; | 2430 HandleAndZoneScope handles; |
2445 i::Isolate* isolate = handles.main_isolate(); | 2431 Isolate* isolate = handles.main_isolate(); |
2446 i::Factory* factory = isolate->factory(); | 2432 Factory* factory = isolate->factory(); |
2447 | 2433 |
2448 std::pair<const char*, int> create_args[] = { | 2434 std::pair<const char*, int> create_args[] = { |
2449 std::make_pair("function f() { return arguments[0]; }", 0), | 2435 std::make_pair("function f() { return arguments[0]; }", 0), |
2450 std::make_pair("function f(a) { return arguments[0]; }", 0), | 2436 std::make_pair("function f(a) { return arguments[0]; }", 0), |
2451 std::make_pair("function f() { return arguments[2]; }", 2), | 2437 std::make_pair("function f() { return arguments[2]; }", 2), |
2452 std::make_pair("function f(a) { return arguments[2]; }", 2), | 2438 std::make_pair("function f(a) { return arguments[2]; }", 2), |
2453 std::make_pair("function f(a, b, c, d) { return arguments[2]; }", 2), | 2439 std::make_pair("function f(a, b, c, d) { return arguments[2]; }", 2), |
2454 std::make_pair("function f(a) {" | 2440 std::make_pair("function f(a) {" |
2455 "'use strict'; return arguments[0]; }", | 2441 "'use strict'; return arguments[0]; }", |
2456 0), | 2442 0), |
(...skipping 15 matching lines...) Expand all Loading... |
2472 std::make_pair("function f(a, ...restArray) { return arguments[0]; }", 0), | 2458 std::make_pair("function f(a, ...restArray) { return arguments[0]; }", 0), |
2473 std::make_pair("function f(a, ...restArray) { return arguments[1]; }", 1), | 2459 std::make_pair("function f(a, ...restArray) { return arguments[1]; }", 1), |
2474 std::make_pair("function f(a, ...restArray) { return restArray[1]; }", 2), | 2460 std::make_pair("function f(a, ...restArray) { return restArray[1]; }", 2), |
2475 std::make_pair("function f(a, ...arguments) { return arguments[0]; }", 1), | 2461 std::make_pair("function f(a, ...arguments) { return arguments[0]; }", 1), |
2476 std::make_pair("function f(a, b, ...restArray) { return restArray[0]; }", | 2462 std::make_pair("function f(a, b, ...restArray) { return restArray[0]; }", |
2477 2), | 2463 2), |
2478 }; | 2464 }; |
2479 | 2465 |
2480 // Test passing no arguments. | 2466 // Test passing no arguments. |
2481 for (size_t i = 0; i < arraysize(create_args); i++) { | 2467 for (size_t i = 0; i < arraysize(create_args); i++) { |
2482 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2468 InterpreterTester tester(isolate, create_args[i].first); |
2483 auto callable = tester.GetCallable<>(); | 2469 auto callable = tester.GetCallable<>(); |
2484 Handle<Object> return_val = callable().ToHandleChecked(); | 2470 Handle<Object> return_val = callable().ToHandleChecked(); |
2485 CHECK(return_val.is_identical_to(factory->undefined_value())); | 2471 CHECK(return_val.is_identical_to(factory->undefined_value())); |
2486 } | 2472 } |
2487 | 2473 |
2488 // Test passing one argument. | 2474 // Test passing one argument. |
2489 for (size_t i = 0; i < arraysize(create_args); i++) { | 2475 for (size_t i = 0; i < arraysize(create_args); i++) { |
2490 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2476 InterpreterTester tester(isolate, create_args[i].first); |
2491 auto callable = tester.GetCallable<Handle<Object>>(); | 2477 auto callable = tester.GetCallable<Handle<Object>>(); |
2492 Handle<Object> return_val = | 2478 Handle<Object> return_val = |
2493 callable(handle(Smi::FromInt(40), isolate)).ToHandleChecked(); | 2479 callable(handle(Smi::FromInt(40), isolate)).ToHandleChecked(); |
2494 if (create_args[i].second == 0) { | 2480 if (create_args[i].second == 0) { |
2495 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(40)); | 2481 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(40)); |
2496 } else { | 2482 } else { |
2497 CHECK(return_val.is_identical_to(factory->undefined_value())); | 2483 CHECK(return_val.is_identical_to(factory->undefined_value())); |
2498 } | 2484 } |
2499 } | 2485 } |
2500 | 2486 |
2501 // Test passing three argument. | 2487 // Test passing three argument. |
2502 for (size_t i = 0; i < arraysize(create_args); i++) { | 2488 for (size_t i = 0; i < arraysize(create_args); i++) { |
2503 Handle<Object> args[3] = { | 2489 Handle<Object> args[3] = { |
2504 handle(Smi::FromInt(40), isolate), | 2490 handle(Smi::FromInt(40), isolate), |
2505 handle(Smi::FromInt(60), isolate), | 2491 handle(Smi::FromInt(60), isolate), |
2506 handle(Smi::FromInt(80), isolate), | 2492 handle(Smi::FromInt(80), isolate), |
2507 }; | 2493 }; |
2508 | 2494 |
2509 InterpreterTester tester(handles.main_isolate(), create_args[i].first); | 2495 InterpreterTester tester(isolate, create_args[i].first); |
2510 auto callable = | 2496 auto callable = |
2511 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 2497 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
2512 Handle<Object> return_val = | 2498 Handle<Object> return_val = |
2513 callable(args[0], args[1], args[2]).ToHandleChecked(); | 2499 callable(args[0], args[1], args[2]).ToHandleChecked(); |
2514 CHECK(return_val->SameValue(*args[create_args[i].second])); | 2500 CHECK(return_val->SameValue(*args[create_args[i].second])); |
2515 } | 2501 } |
2516 } | 2502 } |
2517 | 2503 |
2518 | 2504 |
2519 TEST(InterpreterConditional) { | 2505 TEST(InterpreterConditional) { |
2520 HandleAndZoneScope handles; | 2506 HandleAndZoneScope handles; |
2521 i::Isolate* isolate = handles.main_isolate(); | 2507 Isolate* isolate = handles.main_isolate(); |
2522 | 2508 |
2523 std::pair<const char*, Handle<Object>> conditional[] = { | 2509 std::pair<const char*, Handle<Object>> conditional[] = { |
2524 std::make_pair("return true ? 2 : 3;", | 2510 std::make_pair("return true ? 2 : 3;", |
2525 handle(Smi::FromInt(2), isolate)), | 2511 handle(Smi::FromInt(2), isolate)), |
2526 std::make_pair("return false ? 2 : 3;", | 2512 std::make_pair("return false ? 2 : 3;", |
2527 handle(Smi::FromInt(3), isolate)), | 2513 handle(Smi::FromInt(3), isolate)), |
2528 std::make_pair("var a = 1; return a ? 20 : 30;", | 2514 std::make_pair("var a = 1; return a ? 20 : 30;", |
2529 handle(Smi::FromInt(20), isolate)), | 2515 handle(Smi::FromInt(20), isolate)), |
2530 std::make_pair("var a = 1; return a ? 20 : 30;", | 2516 std::make_pair("var a = 1; return a ? 20 : 30;", |
2531 handle(Smi::FromInt(20), isolate)), | 2517 handle(Smi::FromInt(20), isolate)), |
2532 std::make_pair("var a = 'string'; return a ? 20 : 30;", | 2518 std::make_pair("var a = 'string'; return a ? 20 : 30;", |
2533 handle(Smi::FromInt(20), isolate)), | 2519 handle(Smi::FromInt(20), isolate)), |
2534 std::make_pair("var a = undefined; return a ? 20 : 30;", | 2520 std::make_pair("var a = undefined; return a ? 20 : 30;", |
2535 handle(Smi::FromInt(30), isolate)), | 2521 handle(Smi::FromInt(30), isolate)), |
2536 std::make_pair("return 1 ? 2 ? 3 : 4 : 5;", | 2522 std::make_pair("return 1 ? 2 ? 3 : 4 : 5;", |
2537 handle(Smi::FromInt(3), isolate)), | 2523 handle(Smi::FromInt(3), isolate)), |
2538 std::make_pair("return 0 ? 2 ? 3 : 4 : 5;", | 2524 std::make_pair("return 0 ? 2 ? 3 : 4 : 5;", |
2539 handle(Smi::FromInt(5), isolate)), | 2525 handle(Smi::FromInt(5), isolate)), |
2540 }; | 2526 }; |
2541 | 2527 |
2542 for (size_t i = 0; i < arraysize(conditional); i++) { | 2528 for (size_t i = 0; i < arraysize(conditional); i++) { |
2543 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); | 2529 std::string source(InterpreterTester::SourceForBody(conditional[i].first)); |
2544 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2530 InterpreterTester tester(isolate, source.c_str()); |
2545 auto callable = tester.GetCallable<>(); | 2531 auto callable = tester.GetCallable<>(); |
2546 | 2532 |
2547 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2533 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2548 CHECK(return_value->SameValue(*conditional[i].second)); | 2534 CHECK(return_value->SameValue(*conditional[i].second)); |
2549 } | 2535 } |
2550 } | 2536 } |
2551 | 2537 |
2552 | 2538 |
2553 TEST(InterpreterDelete) { | 2539 TEST(InterpreterDelete) { |
2554 HandleAndZoneScope handles; | 2540 HandleAndZoneScope handles; |
2555 i::Isolate* isolate = handles.main_isolate(); | 2541 Isolate* isolate = handles.main_isolate(); |
2556 i::Factory* factory = isolate->factory(); | 2542 Factory* factory = isolate->factory(); |
2557 | 2543 |
2558 // Tests for delete for local variables that work both in strict | 2544 // Tests for delete for local variables that work both in strict |
2559 // and sloppy modes | 2545 // and sloppy modes |
2560 std::pair<const char*, Handle<Object>> test_delete[] = { | 2546 std::pair<const char*, Handle<Object>> test_delete[] = { |
2561 std::make_pair( | 2547 std::make_pair( |
2562 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n", | 2548 "var a = { x:10, y:'abc', z:30.2}; delete a.x; return a.x;\n", |
2563 factory->undefined_value()), | 2549 factory->undefined_value()), |
2564 std::make_pair( | 2550 std::make_pair( |
2565 "var b = { x:10, y:'abc', z:30.2}; delete b.x; return b.y;\n", | 2551 "var b = { x:10, y:'abc', z:30.2}; delete b.x; return b.y;\n", |
2566 factory->NewStringFromStaticChars("abc")), | 2552 factory->NewStringFromStaticChars("abc")), |
(...skipping 11 matching lines...) Expand all Loading... |
2578 std::make_pair("var a = {1:10};\n" | 2564 std::make_pair("var a = {1:10};\n" |
2579 "(function f1() {return a;});" | 2565 "(function f1() {return a;});" |
2580 "return delete a[1];", | 2566 "return delete a[1];", |
2581 factory->ToBoolean(true)), | 2567 factory->ToBoolean(true)), |
2582 std::make_pair("return delete this;", factory->ToBoolean(true)), | 2568 std::make_pair("return delete this;", factory->ToBoolean(true)), |
2583 std::make_pair("return delete 'test';", factory->ToBoolean(true))}; | 2569 std::make_pair("return delete 'test';", factory->ToBoolean(true))}; |
2584 | 2570 |
2585 // Test delete in sloppy mode | 2571 // Test delete in sloppy mode |
2586 for (size_t i = 0; i < arraysize(test_delete); i++) { | 2572 for (size_t i = 0; i < arraysize(test_delete); i++) { |
2587 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); | 2573 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); |
2588 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2574 InterpreterTester tester(isolate, source.c_str()); |
2589 auto callable = tester.GetCallable<>(); | 2575 auto callable = tester.GetCallable<>(); |
2590 | 2576 |
2591 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2577 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2592 CHECK(return_value->SameValue(*test_delete[i].second)); | 2578 CHECK(return_value->SameValue(*test_delete[i].second)); |
2593 } | 2579 } |
2594 | 2580 |
2595 // Test delete in strict mode | 2581 // Test delete in strict mode |
2596 for (size_t i = 0; i < arraysize(test_delete); i++) { | 2582 for (size_t i = 0; i < arraysize(test_delete); i++) { |
2597 std::string strict_test = | 2583 std::string strict_test = |
2598 "'use strict'; " + std::string(test_delete[i].first); | 2584 "'use strict'; " + std::string(test_delete[i].first); |
2599 std::string source(InterpreterTester::SourceForBody(strict_test.c_str())); | 2585 std::string source(InterpreterTester::SourceForBody(strict_test.c_str())); |
2600 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2586 InterpreterTester tester(isolate, source.c_str()); |
2601 auto callable = tester.GetCallable<>(); | 2587 auto callable = tester.GetCallable<>(); |
2602 | 2588 |
2603 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2589 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2604 CHECK(return_value->SameValue(*test_delete[i].second)); | 2590 CHECK(return_value->SameValue(*test_delete[i].second)); |
2605 } | 2591 } |
2606 } | 2592 } |
2607 | 2593 |
2608 | 2594 |
2609 TEST(InterpreterDeleteSloppyUnqualifiedIdentifier) { | 2595 TEST(InterpreterDeleteSloppyUnqualifiedIdentifier) { |
2610 HandleAndZoneScope handles; | 2596 HandleAndZoneScope handles; |
2611 i::Isolate* isolate = handles.main_isolate(); | 2597 Isolate* isolate = handles.main_isolate(); |
2612 i::Factory* factory = isolate->factory(); | 2598 Factory* factory = isolate->factory(); |
2613 | 2599 |
2614 // These tests generate a syntax error for strict mode. We don't | 2600 // These tests generate a syntax error for strict mode. We don't |
2615 // test for it here. | 2601 // test for it here. |
2616 std::pair<const char*, Handle<Object>> test_delete[] = { | 2602 std::pair<const char*, Handle<Object>> test_delete[] = { |
2617 std::make_pair("var sloppy_a = { x:10, y:'abc'};\n" | 2603 std::make_pair("var sloppy_a = { x:10, y:'abc'};\n" |
2618 "var sloppy_b = delete sloppy_a;\n" | 2604 "var sloppy_b = delete sloppy_a;\n" |
2619 "if (delete sloppy_a) {\n" | 2605 "if (delete sloppy_a) {\n" |
2620 " return undefined;\n" | 2606 " return undefined;\n" |
2621 "} else {\n" | 2607 "} else {\n" |
2622 " return sloppy_a.x;\n" | 2608 " return sloppy_a.x;\n" |
2623 "}\n", | 2609 "}\n", |
2624 Handle<Object>(Smi::FromInt(10), isolate)), | 2610 Handle<Object>(Smi::FromInt(10), isolate)), |
2625 // TODO(mythria) When try-catch is implemented change the tests to check | 2611 // TODO(mythria) When try-catch is implemented change the tests to check |
2626 // if delete actually deletes | 2612 // if delete actually deletes |
2627 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" | 2613 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" |
2628 "var sloppy_b = delete sloppy_a;\n" | 2614 "var sloppy_b = delete sloppy_a;\n" |
2629 // "try{return a.x;} catch(e) {return b;}\n" | 2615 // "try{return a.x;} catch(e) {return b;}\n" |
2630 "return sloppy_b;", | 2616 "return sloppy_b;", |
2631 factory->ToBoolean(true)), | 2617 factory->ToBoolean(true)), |
2632 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" | 2618 std::make_pair("sloppy_a = { x:10, y:'abc'};\n" |
2633 "var sloppy_b = delete sloppy_c;\n" | 2619 "var sloppy_b = delete sloppy_c;\n" |
2634 "return sloppy_b;", | 2620 "return sloppy_b;", |
2635 factory->ToBoolean(true))}; | 2621 factory->ToBoolean(true))}; |
2636 | 2622 |
2637 for (size_t i = 0; i < arraysize(test_delete); i++) { | 2623 for (size_t i = 0; i < arraysize(test_delete); i++) { |
2638 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); | 2624 std::string source(InterpreterTester::SourceForBody(test_delete[i].first)); |
2639 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2625 InterpreterTester tester(isolate, source.c_str()); |
2640 auto callable = tester.GetCallable<>(); | 2626 auto callable = tester.GetCallable<>(); |
2641 | 2627 |
2642 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2628 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2643 CHECK(return_value->SameValue(*test_delete[i].second)); | 2629 CHECK(return_value->SameValue(*test_delete[i].second)); |
2644 } | 2630 } |
2645 } | 2631 } |
2646 | 2632 |
2647 | 2633 |
2648 TEST(InterpreterGlobalDelete) { | 2634 TEST(InterpreterGlobalDelete) { |
2649 HandleAndZoneScope handles; | 2635 HandleAndZoneScope handles; |
2650 i::Isolate* isolate = handles.main_isolate(); | 2636 Isolate* isolate = handles.main_isolate(); |
2651 i::Factory* factory = isolate->factory(); | 2637 Factory* factory = isolate->factory(); |
2652 | 2638 |
2653 std::pair<const char*, Handle<Object>> test_global_delete[] = { | 2639 std::pair<const char*, Handle<Object>> test_global_delete[] = { |
2654 std::make_pair("var a = { x:10, y:'abc', z:30.2 };\n" | 2640 std::make_pair("var a = { x:10, y:'abc', z:30.2 };\n" |
2655 "function f() {\n" | 2641 "function f() {\n" |
2656 " delete a.x;\n" | 2642 " delete a.x;\n" |
2657 " return a.x;\n" | 2643 " return a.x;\n" |
2658 "}\n" | 2644 "}\n" |
2659 "f();\n", | 2645 "f();\n", |
2660 factory->undefined_value()), | 2646 factory->undefined_value()), |
2661 std::make_pair("var b = {1:10, 2:'abc', 3:30.2 };\n" | 2647 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... |
2695 " var obj = {h:10,\n" | 2681 " var obj = {h:10,\n" |
2696 " f1() {\n" | 2682 " f1() {\n" |
2697 " 'use strict';\n" | 2683 " 'use strict';\n" |
2698 " return delete this.h;}};\n" | 2684 " return delete this.h;}};\n" |
2699 " return obj.f1();\n" | 2685 " return obj.f1();\n" |
2700 "}\n" | 2686 "}\n" |
2701 "f();", | 2687 "f();", |
2702 factory->ToBoolean(true))}; | 2688 factory->ToBoolean(true))}; |
2703 | 2689 |
2704 for (size_t i = 0; i < arraysize(test_global_delete); i++) { | 2690 for (size_t i = 0; i < arraysize(test_global_delete); i++) { |
2705 InterpreterTester tester(handles.main_isolate(), | 2691 InterpreterTester tester(isolate, test_global_delete[i].first); |
2706 test_global_delete[i].first); | |
2707 auto callable = tester.GetCallable<>(); | 2692 auto callable = tester.GetCallable<>(); |
2708 | 2693 |
2709 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2694 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2710 CHECK(return_value->SameValue(*test_global_delete[i].second)); | 2695 CHECK(return_value->SameValue(*test_global_delete[i].second)); |
2711 } | 2696 } |
2712 } | 2697 } |
2713 | 2698 |
2714 | 2699 |
2715 TEST(InterpreterBasicLoops) { | 2700 TEST(InterpreterBasicLoops) { |
2716 HandleAndZoneScope handles; | 2701 HandleAndZoneScope handles; |
2717 i::Isolate* isolate = handles.main_isolate(); | 2702 Isolate* isolate = handles.main_isolate(); |
2718 i::Factory* factory = isolate->factory(); | 2703 Factory* factory = isolate->factory(); |
2719 | 2704 |
2720 std::pair<const char*, Handle<Object>> loops[] = { | 2705 std::pair<const char*, Handle<Object>> loops[] = { |
2721 std::make_pair("var a = 10; var b = 1;\n" | 2706 std::make_pair("var a = 10; var b = 1;\n" |
2722 "while (a) {\n" | 2707 "while (a) {\n" |
2723 " b = b * 2;\n" | 2708 " b = b * 2;\n" |
2724 " a = a - 1;\n" | 2709 " a = a - 1;\n" |
2725 "};\n" | 2710 "};\n" |
2726 "return b;\n", | 2711 "return b;\n", |
2727 factory->NewHeapNumber(1024)), | 2712 factory->NewHeapNumber(1024)), |
2728 std::make_pair("var a = 1; var b = 1;\n" | 2713 std::make_pair("var a = 1; var b = 1;\n" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2792 Handle<Object>(Smi::FromInt(2), isolate)), | 2777 Handle<Object>(Smi::FromInt(2), isolate)), |
2793 std::make_pair("var a = 10; var b = 1;\n" | 2778 std::make_pair("var a = 10; var b = 1;\n" |
2794 "for ( a = 1, b = 30; false; ) {\n" | 2779 "for ( a = 1, b = 30; false; ) {\n" |
2795 " b = b * 2;\n" | 2780 " b = b * 2;\n" |
2796 "}\n" | 2781 "}\n" |
2797 "return b;\n", | 2782 "return b;\n", |
2798 Handle<Object>(Smi::FromInt(30), isolate))}; | 2783 Handle<Object>(Smi::FromInt(30), isolate))}; |
2799 | 2784 |
2800 for (size_t i = 0; i < arraysize(loops); i++) { | 2785 for (size_t i = 0; i < arraysize(loops); i++) { |
2801 std::string source(InterpreterTester::SourceForBody(loops[i].first)); | 2786 std::string source(InterpreterTester::SourceForBody(loops[i].first)); |
2802 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2787 InterpreterTester tester(isolate, source.c_str()); |
2803 auto callable = tester.GetCallable<>(); | 2788 auto callable = tester.GetCallable<>(); |
2804 | 2789 |
2805 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2790 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2806 CHECK(return_value->SameValue(*loops[i].second)); | 2791 CHECK(return_value->SameValue(*loops[i].second)); |
2807 } | 2792 } |
2808 } | 2793 } |
2809 | 2794 |
2810 | 2795 |
2811 TEST(InterpreterForIn) { | 2796 TEST(InterpreterForIn) { |
2812 std::pair<const char*, int> for_in_samples[] = { | 2797 std::pair<const char*, int> for_in_samples[] = { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2969 "for (o[i++] in data)\n" // This is to test if value is loaded | 2954 "for (o[i++] in data)\n" // This is to test if value is loaded |
2970 " result += data[o[i-1]];\n" // back from accumulator before | 2955 " result += data[o[i-1]];\n" // back from accumulator before |
2971 "return result;\n", // storing keyed properties. | 2956 "return result;\n", // storing keyed properties. |
2972 57}}; | 2957 57}}; |
2973 | 2958 |
2974 // Two passes are made for this test. On the first, 8-bit register | 2959 // Two passes are made for this test. On the first, 8-bit register |
2975 // operands are employed, and on the 16-bit register operands are | 2960 // operands are employed, and on the 16-bit register operands are |
2976 // used. | 2961 // used. |
2977 for (int pass = 0; pass < 2; pass++) { | 2962 for (int pass = 0; pass < 2; pass++) { |
2978 HandleAndZoneScope handles; | 2963 HandleAndZoneScope handles; |
| 2964 Isolate* isolate = handles.main_isolate(); |
2979 std::ostringstream wide_os; | 2965 std::ostringstream wide_os; |
2980 if (pass == 1) { | 2966 if (pass == 1) { |
2981 for (int i = 0; i < 200; i++) { | 2967 for (int i = 0; i < 200; i++) { |
2982 wide_os << "var local" << i << " = 0;\n"; | 2968 wide_os << "var local" << i << " = 0;\n"; |
2983 } | 2969 } |
2984 } | 2970 } |
2985 | 2971 |
2986 for (size_t i = 0; i < arraysize(for_in_samples); i++) { | 2972 for (size_t i = 0; i < arraysize(for_in_samples); i++) { |
2987 std::ostringstream body_os; | 2973 std::ostringstream body_os; |
2988 body_os << wide_os.str() << for_in_samples[i].first; | 2974 body_os << wide_os.str() << for_in_samples[i].first; |
2989 std::string body(body_os.str()); | 2975 std::string body(body_os.str()); |
2990 std::string function = InterpreterTester::SourceForBody(body.c_str()); | 2976 std::string function = InterpreterTester::SourceForBody(body.c_str()); |
2991 InterpreterTester tester(handles.main_isolate(), function.c_str()); | 2977 InterpreterTester tester(isolate, function.c_str()); |
2992 auto callable = tester.GetCallable<>(); | 2978 auto callable = tester.GetCallable<>(); |
2993 Handle<Object> return_val = callable().ToHandleChecked(); | 2979 Handle<Object> return_val = callable().ToHandleChecked(); |
2994 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), | 2980 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), |
2995 for_in_samples[i].second); | 2981 for_in_samples[i].second); |
2996 } | 2982 } |
2997 } | 2983 } |
2998 } | 2984 } |
2999 | 2985 |
3000 | 2986 |
3001 TEST(InterpreterForOf) { | 2987 TEST(InterpreterForOf) { |
3002 HandleAndZoneScope handles; | 2988 HandleAndZoneScope handles; |
3003 i::Isolate* isolate = handles.main_isolate(); | 2989 Isolate* isolate = handles.main_isolate(); |
3004 i::Factory* factory = isolate->factory(); | 2990 Factory* factory = isolate->factory(); |
3005 | 2991 |
3006 std::pair<const char*, Handle<Object>> for_of[] = { | 2992 std::pair<const char*, Handle<Object>> for_of[] = { |
3007 {"function f() {\n" | 2993 {"function f() {\n" |
3008 " var r = 0;\n" | 2994 " var r = 0;\n" |
3009 " for (var a of [0,6,7,9]) { r += a; }\n" | 2995 " for (var a of [0,6,7,9]) { r += a; }\n" |
3010 " return r;\n" | 2996 " return r;\n" |
3011 "}", | 2997 "}", |
3012 handle(Smi::FromInt(22), isolate)}, | 2998 handle(Smi::FromInt(22), isolate)}, |
3013 {"function f() {\n" | 2999 {"function f() {\n" |
3014 " var r = '';\n" | 3000 " var r = '';\n" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3093 " }\n" | 3079 " }\n" |
3094 " }\n" | 3080 " }\n" |
3095 " }}\n" | 3081 " }}\n" |
3096 " for (a of obj) { r += a }\n" | 3082 " for (a of obj) { r += a }\n" |
3097 " return r;\n" | 3083 " return r;\n" |
3098 "}", | 3084 "}", |
3099 factory->NewStringFromStaticChars("dcba")}, | 3085 factory->NewStringFromStaticChars("dcba")}, |
3100 }; | 3086 }; |
3101 | 3087 |
3102 for (size_t i = 0; i < arraysize(for_of); i++) { | 3088 for (size_t i = 0; i < arraysize(for_of); i++) { |
3103 InterpreterTester tester(handles.main_isolate(), for_of[i].first); | 3089 InterpreterTester tester(isolate, for_of[i].first); |
3104 auto callable = tester.GetCallable<>(); | 3090 auto callable = tester.GetCallable<>(); |
3105 Handle<Object> return_val = callable().ToHandleChecked(); | 3091 Handle<Object> return_val = callable().ToHandleChecked(); |
3106 CHECK(return_val->SameValue(*for_of[i].second)); | 3092 CHECK(return_val->SameValue(*for_of[i].second)); |
3107 } | 3093 } |
3108 } | 3094 } |
3109 | 3095 |
3110 | 3096 |
3111 TEST(InterpreterSwitch) { | 3097 TEST(InterpreterSwitch) { |
3112 HandleAndZoneScope handles; | 3098 HandleAndZoneScope handles; |
3113 i::Isolate* isolate = handles.main_isolate(); | 3099 Isolate* isolate = handles.main_isolate(); |
3114 i::Factory* factory = isolate->factory(); | 3100 Factory* factory = isolate->factory(); |
3115 | 3101 |
3116 std::pair<const char*, Handle<Object>> switch_ops[] = { | 3102 std::pair<const char*, Handle<Object>> switch_ops[] = { |
3117 std::make_pair("var a = 1;\n" | 3103 std::make_pair("var a = 1;\n" |
3118 "switch(a) {\n" | 3104 "switch(a) {\n" |
3119 " case 1: return 2;\n" | 3105 " case 1: return 2;\n" |
3120 " case 2: return 3;\n" | 3106 " case 2: return 3;\n" |
3121 "}\n", | 3107 "}\n", |
3122 handle(Smi::FromInt(2), isolate)), | 3108 handle(Smi::FromInt(2), isolate)), |
3123 std::make_pair("var a = 1;\n" | 3109 std::make_pair("var a = 1;\n" |
3124 "switch(a) {\n" | 3110 "switch(a) {\n" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3172 " default : a += 2; break;\n" | 3158 " default : a += 2; break;\n" |
3173 " } // fall-through\n" | 3159 " } // fall-through\n" |
3174 " case 2: a += 3;\n" | 3160 " case 2: a += 3;\n" |
3175 "}\n" | 3161 "}\n" |
3176 "return a;", | 3162 "return a;", |
3177 handle(Smi::FromInt(5), isolate)), | 3163 handle(Smi::FromInt(5), isolate)), |
3178 }; | 3164 }; |
3179 | 3165 |
3180 for (size_t i = 0; i < arraysize(switch_ops); i++) { | 3166 for (size_t i = 0; i < arraysize(switch_ops); i++) { |
3181 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first)); | 3167 std::string source(InterpreterTester::SourceForBody(switch_ops[i].first)); |
3182 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3168 InterpreterTester tester(isolate, source.c_str()); |
3183 auto callable = tester.GetCallable<>(); | 3169 auto callable = tester.GetCallable<>(); |
3184 | 3170 |
3185 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3171 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3186 CHECK(return_value->SameValue(*switch_ops[i].second)); | 3172 CHECK(return_value->SameValue(*switch_ops[i].second)); |
3187 } | 3173 } |
3188 } | 3174 } |
3189 | 3175 |
3190 | 3176 |
3191 TEST(InterpreterSloppyThis) { | 3177 TEST(InterpreterSloppyThis) { |
3192 HandleAndZoneScope handles; | 3178 HandleAndZoneScope handles; |
3193 i::Isolate* isolate = handles.main_isolate(); | 3179 Isolate* isolate = handles.main_isolate(); |
3194 i::Factory* factory = isolate->factory(); | 3180 Factory* factory = isolate->factory(); |
3195 | 3181 |
3196 std::pair<const char*, Handle<Object>> sloppy_this[] = { | 3182 std::pair<const char*, Handle<Object>> sloppy_this[] = { |
3197 std::make_pair("var global_val = 100;\n" | 3183 std::make_pair("var global_val = 100;\n" |
3198 "function f() { return this.global_val; }\n", | 3184 "function f() { return this.global_val; }\n", |
3199 handle(Smi::FromInt(100), isolate)), | 3185 handle(Smi::FromInt(100), isolate)), |
3200 std::make_pair("var global_val = 110;\n" | 3186 std::make_pair("var global_val = 110;\n" |
3201 "function g() { return this.global_val; };" | 3187 "function g() { return this.global_val; };" |
3202 "function f() { return g(); }\n", | 3188 "function f() { return g(); }\n", |
3203 handle(Smi::FromInt(110), isolate)), | 3189 handle(Smi::FromInt(110), isolate)), |
3204 std::make_pair("var global_val = 110;\n" | 3190 std::make_pair("var global_val = 110;\n" |
3205 "function g() { return this.global_val };" | 3191 "function g() { return this.global_val };" |
3206 "function f() { 'use strict'; return g(); }\n", | 3192 "function f() { 'use strict'; return g(); }\n", |
3207 handle(Smi::FromInt(110), isolate)), | 3193 handle(Smi::FromInt(110), isolate)), |
3208 std::make_pair("function f() { 'use strict'; return this; }\n", | 3194 std::make_pair("function f() { 'use strict'; return this; }\n", |
3209 factory->undefined_value()), | 3195 factory->undefined_value()), |
3210 std::make_pair("function g() { 'use strict'; return this; };" | 3196 std::make_pair("function g() { 'use strict'; return this; };" |
3211 "function f() { return g(); }\n", | 3197 "function f() { return g(); }\n", |
3212 factory->undefined_value()), | 3198 factory->undefined_value()), |
3213 }; | 3199 }; |
3214 | 3200 |
3215 for (size_t i = 0; i < arraysize(sloppy_this); i++) { | 3201 for (size_t i = 0; i < arraysize(sloppy_this); i++) { |
3216 InterpreterTester tester(handles.main_isolate(), sloppy_this[i].first); | 3202 InterpreterTester tester(isolate, sloppy_this[i].first); |
3217 auto callable = tester.GetCallable<>(); | 3203 auto callable = tester.GetCallable<>(); |
3218 | 3204 |
3219 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3205 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3220 CHECK(return_value->SameValue(*sloppy_this[i].second)); | 3206 CHECK(return_value->SameValue(*sloppy_this[i].second)); |
3221 } | 3207 } |
3222 } | 3208 } |
3223 | 3209 |
3224 | 3210 |
3225 TEST(InterpreterThisFunction) { | 3211 TEST(InterpreterThisFunction) { |
3226 HandleAndZoneScope handles; | 3212 HandleAndZoneScope handles; |
3227 i::Isolate* isolate = handles.main_isolate(); | 3213 Isolate* isolate = handles.main_isolate(); |
3228 i::Factory* factory = isolate->factory(); | 3214 Factory* factory = isolate->factory(); |
3229 | 3215 |
3230 InterpreterTester tester(handles.main_isolate(), | 3216 InterpreterTester tester(isolate, |
3231 "var f;\n f = function f() { return f.name; }"); | 3217 "var f;\n f = function f() { return f.name; }"); |
3232 auto callable = tester.GetCallable<>(); | 3218 auto callable = tester.GetCallable<>(); |
3233 | 3219 |
3234 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3220 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3235 CHECK(return_value->SameValue(*factory->NewStringFromStaticChars("f"))); | 3221 CHECK(return_value->SameValue(*factory->NewStringFromStaticChars("f"))); |
3236 } | 3222 } |
3237 | 3223 |
3238 | 3224 |
3239 TEST(InterpreterNewTarget) { | 3225 TEST(InterpreterNewTarget) { |
3240 HandleAndZoneScope handles; | 3226 HandleAndZoneScope handles; |
3241 i::Isolate* isolate = handles.main_isolate(); | 3227 Isolate* isolate = handles.main_isolate(); |
3242 i::Factory* factory = isolate->factory(); | 3228 Factory* factory = isolate->factory(); |
3243 | 3229 |
3244 // TODO(rmcilroy): Add tests that we get the original constructor for | 3230 // TODO(rmcilroy): Add tests that we get the original constructor for |
3245 // superclass constructors once we have class support. | 3231 // superclass constructors once we have class support. |
3246 InterpreterTester tester(handles.main_isolate(), | 3232 InterpreterTester tester(isolate, "function f() { this.a = new.target; }"); |
3247 "function f() { this.a = new.target; }"); | |
3248 auto callable = tester.GetCallable<>(); | 3233 auto callable = tester.GetCallable<>(); |
3249 callable().ToHandleChecked(); | 3234 callable().ToHandleChecked(); |
3250 | 3235 |
3251 Handle<Object> new_target_name = v8::Utils::OpenHandle( | 3236 Handle<Object> new_target_name = v8::Utils::OpenHandle( |
3252 *CompileRun("(function() { return (new f()).a.name; })();")); | 3237 *CompileRun("(function() { return (new f()).a.name; })();")); |
3253 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f"))); | 3238 CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f"))); |
3254 } | 3239 } |
3255 | 3240 |
3256 | 3241 |
3257 TEST(InterpreterAssignmentInExpressions) { | 3242 TEST(InterpreterAssignmentInExpressions) { |
3258 HandleAndZoneScope handles; | 3243 HandleAndZoneScope handles; |
| 3244 Isolate* isolate = handles.main_isolate(); |
3259 | 3245 |
3260 std::pair<const char*, int> samples[] = { | 3246 std::pair<const char*, int> samples[] = { |
3261 {"function f() {\n" | 3247 {"function f() {\n" |
3262 " var x = 7;\n" | 3248 " var x = 7;\n" |
3263 " var y = x + (x = 1) + (x = 2);\n" | 3249 " var y = x + (x = 1) + (x = 2);\n" |
3264 " return y;\n" | 3250 " return y;\n" |
3265 "}", | 3251 "}", |
3266 10}, | 3252 10}, |
3267 {"function f() {\n" | 3253 {"function f() {\n" |
3268 " var x = 7;\n" | 3254 " var x = 7;\n" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 "}", | 3364 "}", |
3379 60}, | 3365 60}, |
3380 {"function f(a) {\n" | 3366 {"function f(a) {\n" |
3381 " return a + (arguments[0] = 10) + arguments[0];\n" | 3367 " return a + (arguments[0] = 10) + arguments[0];\n" |
3382 "}", | 3368 "}", |
3383 60}, | 3369 60}, |
3384 }; | 3370 }; |
3385 | 3371 |
3386 const int arg_value = 40; | 3372 const int arg_value = 40; |
3387 for (size_t i = 0; i < arraysize(samples); i++) { | 3373 for (size_t i = 0; i < arraysize(samples); i++) { |
3388 InterpreterTester tester(handles.main_isolate(), samples[i].first); | 3374 InterpreterTester tester(isolate, samples[i].first); |
3389 auto callable = tester.GetCallable<Handle<Object>>(); | 3375 auto callable = tester.GetCallable<Handle<Object>>(); |
3390 Handle<Object> return_val = | 3376 Handle<Object> return_val = |
3391 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) | 3377 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) |
3392 .ToHandleChecked(); | 3378 .ToHandleChecked(); |
3393 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); | 3379 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); |
3394 } | 3380 } |
3395 } | 3381 } |
3396 | 3382 |
3397 | 3383 |
3398 TEST(InterpreterToName) { | 3384 TEST(InterpreterToName) { |
3399 HandleAndZoneScope handles; | 3385 HandleAndZoneScope handles; |
3400 i::Isolate* isolate = handles.main_isolate(); | 3386 Isolate* isolate = handles.main_isolate(); |
3401 i::Factory* factory = isolate->factory(); | 3387 Factory* factory = isolate->factory(); |
3402 | 3388 |
3403 std::pair<const char*, Handle<Object>> to_name_tests[] = { | 3389 std::pair<const char*, Handle<Object>> to_name_tests[] = { |
3404 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", | 3390 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", |
3405 factory->NewNumberFromInt(10)}, | 3391 factory->NewNumberFromInt(10)}, |
3406 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", | 3392 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", |
3407 factory->NewNumberFromInt(10)}, | 3393 factory->NewNumberFromInt(10)}, |
3408 {"var a = 20; var obj = {[a] : 10}; return obj[20];", | 3394 {"var a = 20; var obj = {[a] : 10}; return obj[20];", |
3409 factory->NewNumberFromInt(10)}, | 3395 factory->NewNumberFromInt(10)}, |
3410 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", | 3396 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", |
3411 factory->NewNumberFromInt(10)}, | 3397 factory->NewNumberFromInt(10)}, |
(...skipping 10 matching lines...) Expand all Loading... |
3422 factory->undefined_value()}, | 3408 factory->undefined_value()}, |
3423 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n" | 3409 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n" |
3424 "var obj = {[a] : 10};\n" | 3410 "var obj = {[a] : 10};\n" |
3425 "return obj.x;", | 3411 "return obj.x;", |
3426 factory->NewNumberFromInt(10)}, | 3412 factory->NewNumberFromInt(10)}, |
3427 }; | 3413 }; |
3428 | 3414 |
3429 for (size_t i = 0; i < arraysize(to_name_tests); i++) { | 3415 for (size_t i = 0; i < arraysize(to_name_tests); i++) { |
3430 std::string source( | 3416 std::string source( |
3431 InterpreterTester::SourceForBody(to_name_tests[i].first)); | 3417 InterpreterTester::SourceForBody(to_name_tests[i].first)); |
3432 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3418 InterpreterTester tester(isolate, source.c_str()); |
3433 auto callable = tester.GetCallable<>(); | 3419 auto callable = tester.GetCallable<>(); |
3434 | 3420 |
3435 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3421 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3436 CHECK(return_value->SameValue(*to_name_tests[i].second)); | 3422 CHECK(return_value->SameValue(*to_name_tests[i].second)); |
3437 } | 3423 } |
3438 } | 3424 } |
3439 | 3425 |
3440 | 3426 |
3441 TEST(TemporaryRegisterAllocation) { | 3427 TEST(TemporaryRegisterAllocation) { |
3442 HandleAndZoneScope handles; | 3428 HandleAndZoneScope handles; |
3443 i::Isolate* isolate = handles.main_isolate(); | 3429 Isolate* isolate = handles.main_isolate(); |
3444 i::Factory* factory = isolate->factory(); | 3430 Factory* factory = isolate->factory(); |
3445 | 3431 |
3446 std::pair<const char*, Handle<Object>> reg_tests[] = { | 3432 std::pair<const char*, Handle<Object>> reg_tests[] = { |
3447 {"function add(a, b, c) {" | 3433 {"function add(a, b, c) {" |
3448 " return a + b + c;" | 3434 " return a + b + c;" |
3449 "}" | 3435 "}" |
3450 "function f() {" | 3436 "function f() {" |
3451 " var a = 10, b = 10;" | 3437 " var a = 10, b = 10;" |
3452 " return add(a, b++, b);" | 3438 " return add(a, b++, b);" |
3453 "}", | 3439 "}", |
3454 factory->NewNumberFromInt(31)}, | 3440 factory->NewNumberFromInt(31)}, |
3455 {"function add(a, b, c, d) {" | 3441 {"function add(a, b, c, d) {" |
3456 " return a + b + c + d;" | 3442 " return a + b + c + d;" |
3457 "}" | 3443 "}" |
3458 "function f() {" | 3444 "function f() {" |
3459 " var x = 10, y = 20, z = 30;" | 3445 " var x = 10, y = 20, z = 30;" |
3460 " return x + add(x, (y= x++), x, z);" | 3446 " return x + add(x, (y= x++), x, z);" |
3461 "}", | 3447 "}", |
3462 factory->NewNumberFromInt(71)}, | 3448 factory->NewNumberFromInt(71)}, |
3463 }; | 3449 }; |
3464 | 3450 |
3465 for (size_t i = 0; i < arraysize(reg_tests); i++) { | 3451 for (size_t i = 0; i < arraysize(reg_tests); i++) { |
3466 InterpreterTester tester(handles.main_isolate(), reg_tests[i].first); | 3452 InterpreterTester tester(isolate, reg_tests[i].first); |
3467 auto callable = tester.GetCallable<>(); | 3453 auto callable = tester.GetCallable<>(); |
3468 | 3454 |
3469 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3455 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3470 CHECK(return_value->SameValue(*reg_tests[i].second)); | 3456 CHECK(return_value->SameValue(*reg_tests[i].second)); |
3471 } | 3457 } |
3472 } | 3458 } |
3473 | 3459 |
3474 | 3460 |
3475 TEST(InterpreterLookupSlot) { | 3461 TEST(InterpreterLookupSlot) { |
3476 HandleAndZoneScope handles; | 3462 HandleAndZoneScope handles; |
3477 i::Isolate* isolate = handles.main_isolate(); | 3463 Isolate* isolate = handles.main_isolate(); |
3478 i::Factory* factory = isolate->factory(); | 3464 Factory* factory = isolate->factory(); |
3479 | 3465 |
3480 // TODO(mythria): Add more tests when we have support for eval/with. | 3466 // TODO(mythria): Add more tests when we have support for eval/with. |
3481 const char* function_prologue = "var f;" | 3467 const char* function_prologue = "var f;" |
3482 "var x = 1;" | 3468 "var x = 1;" |
3483 "function f1() {" | 3469 "function f1() {" |
3484 " eval(\"function t() {"; | 3470 " eval(\"function t() {"; |
3485 const char* function_epilogue = " }; f = t;\");" | 3471 const char* function_epilogue = " }; f = t;\");" |
3486 "}" | 3472 "}" |
3487 "f1();"; | 3473 "f1();"; |
3488 | 3474 |
3489 | 3475 |
3490 std::pair<const char*, Handle<Object>> lookup_slot[] = { | 3476 std::pair<const char*, Handle<Object>> lookup_slot[] = { |
3491 {"return x;", handle(Smi::FromInt(1), isolate)}, | 3477 {"return x;", handle(Smi::FromInt(1), isolate)}, |
3492 {"return typeof x;", factory->NewStringFromStaticChars("number")}, | 3478 {"return typeof x;", factory->NewStringFromStaticChars("number")}, |
3493 {"return typeof dummy;", factory->NewStringFromStaticChars("undefined")}, | 3479 {"return typeof dummy;", factory->NewStringFromStaticChars("undefined")}, |
3494 {"x = 10; return x;", handle(Smi::FromInt(10), isolate)}, | 3480 {"x = 10; return x;", handle(Smi::FromInt(10), isolate)}, |
3495 {"'use strict'; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, | 3481 {"'use strict'; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
3496 }; | 3482 }; |
3497 | 3483 |
3498 for (size_t i = 0; i < arraysize(lookup_slot); i++) { | 3484 for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
3499 std::string script = std::string(function_prologue) + | 3485 std::string script = std::string(function_prologue) + |
3500 std::string(lookup_slot[i].first) + | 3486 std::string(lookup_slot[i].first) + |
3501 std::string(function_epilogue); | 3487 std::string(function_epilogue); |
3502 | 3488 |
3503 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); | 3489 InterpreterTester tester(isolate, script.c_str(), "t"); |
3504 auto callable = tester.GetCallable<>(); | 3490 auto callable = tester.GetCallable<>(); |
3505 | 3491 |
3506 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3492 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3507 CHECK(return_value->SameValue(*lookup_slot[i].second)); | 3493 CHECK(return_value->SameValue(*lookup_slot[i].second)); |
3508 } | 3494 } |
3509 } | 3495 } |
3510 | 3496 |
3511 | 3497 |
3512 TEST(InterpreterCallLookupSlot) { | 3498 TEST(InterpreterCallLookupSlot) { |
3513 HandleAndZoneScope handles; | 3499 HandleAndZoneScope handles; |
3514 i::Isolate* isolate = handles.main_isolate(); | 3500 Isolate* isolate = handles.main_isolate(); |
3515 | 3501 |
3516 std::pair<const char*, Handle<Object>> call_lookup[] = { | 3502 std::pair<const char*, Handle<Object>> call_lookup[] = { |
3517 {"g = function(){ return 2 }; eval(''); return g();", | 3503 {"g = function(){ return 2 }; eval(''); return g();", |
3518 handle(Smi::FromInt(2), isolate)}, | 3504 handle(Smi::FromInt(2), isolate)}, |
3519 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" | 3505 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" |
3520 "return g();", | 3506 "return g();", |
3521 handle(Smi::FromInt(3), isolate)}, | 3507 handle(Smi::FromInt(3), isolate)}, |
3522 {"g = { x: function(){ return this.y }, y: 20 };\n" | 3508 {"g = { x: function(){ return this.y }, y: 20 };\n" |
3523 "eval('g = { x: g.x, y: 30 }');\n" | 3509 "eval('g = { x: g.x, y: 30 }');\n" |
3524 "return g.x();", | 3510 "return g.x();", |
3525 handle(Smi::FromInt(30), isolate)}, | 3511 handle(Smi::FromInt(30), isolate)}, |
3526 }; | 3512 }; |
3527 | 3513 |
3528 for (size_t i = 0; i < arraysize(call_lookup); i++) { | 3514 for (size_t i = 0; i < arraysize(call_lookup); i++) { |
3529 std::string source(InterpreterTester::SourceForBody(call_lookup[i].first)); | 3515 std::string source(InterpreterTester::SourceForBody(call_lookup[i].first)); |
3530 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3516 InterpreterTester tester(isolate, source.c_str()); |
3531 auto callable = tester.GetCallable<>(); | 3517 auto callable = tester.GetCallable<>(); |
3532 | 3518 |
3533 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3519 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3534 CHECK(return_value->SameValue(*call_lookup[i].second)); | 3520 CHECK(return_value->SameValue(*call_lookup[i].second)); |
3535 } | 3521 } |
3536 } | 3522 } |
3537 | 3523 |
3538 | 3524 |
3539 TEST(InterpreterLookupSlotWide) { | 3525 TEST(InterpreterLookupSlotWide) { |
3540 HandleAndZoneScope handles; | 3526 HandleAndZoneScope handles; |
3541 i::Isolate* isolate = handles.main_isolate(); | 3527 Isolate* isolate = handles.main_isolate(); |
3542 i::Factory* factory = isolate->factory(); | 3528 Factory* factory = isolate->factory(); |
3543 | 3529 |
3544 const char* function_prologue = | 3530 const char* function_prologue = |
3545 "var f;" | 3531 "var f;" |
3546 "var x = 1;" | 3532 "var x = 1;" |
3547 "function f1() {" | 3533 "function f1() {" |
3548 " eval(\"function t() {"; | 3534 " eval(\"function t() {"; |
3549 const char* function_epilogue = | 3535 const char* function_epilogue = |
3550 " }; f = t;\");" | 3536 " }; f = t;\");" |
3551 "}" | 3537 "}" |
3552 "f1();"; | 3538 "f1();"; |
(...skipping 11 matching lines...) Expand all Loading... |
3564 {init_function_body + "return x = 10;", | 3550 {init_function_body + "return x = 10;", |
3565 handle(Smi::FromInt(10), isolate)}, | 3551 handle(Smi::FromInt(10), isolate)}, |
3566 {"'use strict';" + init_function_body + "x = 20; return x;", | 3552 {"'use strict';" + init_function_body + "x = 20; return x;", |
3567 handle(Smi::FromInt(20), isolate)}, | 3553 handle(Smi::FromInt(20), isolate)}, |
3568 }; | 3554 }; |
3569 | 3555 |
3570 for (size_t i = 0; i < arraysize(lookup_slot); i++) { | 3556 for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
3571 std::string script = std::string(function_prologue) + lookup_slot[i].first + | 3557 std::string script = std::string(function_prologue) + lookup_slot[i].first + |
3572 std::string(function_epilogue); | 3558 std::string(function_epilogue); |
3573 | 3559 |
3574 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); | 3560 InterpreterTester tester(isolate, script.c_str(), "t"); |
3575 auto callable = tester.GetCallable<>(); | 3561 auto callable = tester.GetCallable<>(); |
3576 | 3562 |
3577 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3563 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3578 CHECK(return_value->SameValue(*lookup_slot[i].second)); | 3564 CHECK(return_value->SameValue(*lookup_slot[i].second)); |
3579 } | 3565 } |
3580 } | 3566 } |
3581 | 3567 |
3582 | 3568 |
3583 TEST(InterpreterDeleteLookupSlot) { | 3569 TEST(InterpreterDeleteLookupSlot) { |
3584 HandleAndZoneScope handles; | 3570 HandleAndZoneScope handles; |
3585 i::Isolate* isolate = handles.main_isolate(); | 3571 Isolate* isolate = handles.main_isolate(); |
3586 i::Factory* factory = isolate->factory(); | 3572 Factory* factory = isolate->factory(); |
3587 | 3573 |
3588 // TODO(mythria): Add more tests when we have support for eval/with. | 3574 // TODO(mythria): Add more tests when we have support for eval/with. |
3589 const char* function_prologue = "var f;" | 3575 const char* function_prologue = "var f;" |
3590 "var x = 1;" | 3576 "var x = 1;" |
3591 "y = 10;" | 3577 "y = 10;" |
3592 "var obj = {val:10};" | 3578 "var obj = {val:10};" |
3593 "var z = 30;" | 3579 "var z = 30;" |
3594 "function f1() {" | 3580 "function f1() {" |
3595 " var z = 20;" | 3581 " var z = 20;" |
3596 " eval(\"function t() {"; | 3582 " eval(\"function t() {"; |
3597 const char* function_epilogue = " }; f = t;\");" | 3583 const char* function_epilogue = " }; f = t;\");" |
3598 "}" | 3584 "}" |
3599 "f1();"; | 3585 "f1();"; |
3600 | 3586 |
3601 | 3587 |
3602 std::pair<const char*, Handle<Object>> delete_lookup_slot[] = { | 3588 std::pair<const char*, Handle<Object>> delete_lookup_slot[] = { |
3603 {"return delete x;", factory->false_value()}, | 3589 {"return delete x;", factory->false_value()}, |
3604 {"return delete y;", factory->true_value()}, | 3590 {"return delete y;", factory->true_value()}, |
3605 {"return delete z;", factory->false_value()}, | 3591 {"return delete z;", factory->false_value()}, |
3606 {"return delete obj.val;", factory->true_value()}, | 3592 {"return delete obj.val;", factory->true_value()}, |
3607 {"'use strict'; return delete obj.val;", factory->true_value()}, | 3593 {"'use strict'; return delete obj.val;", factory->true_value()}, |
3608 }; | 3594 }; |
3609 | 3595 |
3610 for (size_t i = 0; i < arraysize(delete_lookup_slot); i++) { | 3596 for (size_t i = 0; i < arraysize(delete_lookup_slot); i++) { |
3611 std::string script = std::string(function_prologue) + | 3597 std::string script = std::string(function_prologue) + |
3612 std::string(delete_lookup_slot[i].first) + | 3598 std::string(delete_lookup_slot[i].first) + |
3613 std::string(function_epilogue); | 3599 std::string(function_epilogue); |
3614 | 3600 |
3615 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); | 3601 InterpreterTester tester(isolate, script.c_str(), "t"); |
3616 auto callable = tester.GetCallable<>(); | 3602 auto callable = tester.GetCallable<>(); |
3617 | 3603 |
3618 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3604 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3619 CHECK(return_value->SameValue(*delete_lookup_slot[i].second)); | 3605 CHECK(return_value->SameValue(*delete_lookup_slot[i].second)); |
3620 } | 3606 } |
3621 } | 3607 } |
3622 | 3608 |
3623 | 3609 |
3624 TEST(JumpWithConstantsAndWideConstants) { | 3610 TEST(JumpWithConstantsAndWideConstants) { |
3625 HandleAndZoneScope handles; | 3611 HandleAndZoneScope handles; |
| 3612 Isolate* isolate = handles.main_isolate(); |
| 3613 Factory* factory = isolate->factory(); |
3626 const int kStep = 13; | 3614 const int kStep = 13; |
3627 for (int constants = 11; constants < 256 + 3 * kStep; constants += kStep) { | 3615 for (int constants = 11; constants < 256 + 3 * kStep; constants += kStep) { |
3628 auto isolate = handles.main_isolate(); | |
3629 auto factory = isolate->factory(); | |
3630 std::ostringstream filler_os; | 3616 std::ostringstream filler_os; |
3631 // Generate a string that consumes constant pool entries and | 3617 // Generate a string that consumes constant pool entries and |
3632 // spread out branch distances in script below. | 3618 // spread out branch distances in script below. |
3633 for (int i = 0; i < constants; i++) { | 3619 for (int i = 0; i < constants; i++) { |
3634 filler_os << "var x_ = 'x_" << i << "';\n"; | 3620 filler_os << "var x_ = 'x_" << i << "';\n"; |
3635 } | 3621 } |
3636 std::string filler(filler_os.str()); | 3622 std::string filler(filler_os.str()); |
3637 std::ostringstream script_os; | 3623 std::ostringstream script_os; |
3638 script_os << "function " << InterpreterTester::function_name() << "(a) {\n"; | 3624 script_os << "function " << InterpreterTester::function_name() << "(a) {\n"; |
3639 script_os << " " << filler; | 3625 script_os << " " << filler; |
3640 script_os << " for (var i = a; i < 2; i++) {\n"; | 3626 script_os << " for (var i = a; i < 2; i++) {\n"; |
3641 script_os << " " << filler; | 3627 script_os << " " << filler; |
3642 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; | 3628 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; |
3643 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; | 3629 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; |
3644 script_os << " else { " << filler << " }\n"; | 3630 script_os << " else { " << filler << " }\n"; |
3645 script_os << " }\n"; | 3631 script_os << " }\n"; |
3646 script_os << " return i;\n"; | 3632 script_os << " return i;\n"; |
3647 script_os << "}\n"; | 3633 script_os << "}\n"; |
3648 std::string script(script_os.str()); | 3634 std::string script(script_os.str()); |
3649 for (int a = 0; a < 3; a++) { | 3635 for (int a = 0; a < 3; a++) { |
3650 InterpreterTester tester(handles.main_isolate(), script.c_str()); | 3636 InterpreterTester tester(isolate, script.c_str()); |
3651 auto callable = tester.GetCallable<Handle<Object>>(); | 3637 auto callable = tester.GetCallable<Handle<Object>>(); |
3652 Handle<Object> argument = factory->NewNumberFromInt(a); | 3638 Handle<Object> argument = factory->NewNumberFromInt(a); |
3653 Handle<Object> return_val = callable(argument).ToHandleChecked(); | 3639 Handle<Object> return_val = callable(argument).ToHandleChecked(); |
3654 static const int results[] = {11, 12, 2}; | 3640 static const int results[] = {11, 12, 2}; |
3655 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); | 3641 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
3656 } | 3642 } |
3657 } | 3643 } |
3658 } | 3644 } |
3659 | 3645 |
3660 | 3646 |
3661 TEST(InterpreterEval) { | 3647 TEST(InterpreterEval) { |
3662 HandleAndZoneScope handles; | 3648 HandleAndZoneScope handles; |
3663 i::Isolate* isolate = handles.main_isolate(); | 3649 Isolate* isolate = handles.main_isolate(); |
3664 i::Factory* factory = isolate->factory(); | 3650 Factory* factory = isolate->factory(); |
3665 | 3651 |
3666 std::pair<const char*, Handle<Object>> eval[] = { | 3652 std::pair<const char*, Handle<Object>> eval[] = { |
3667 {"return eval('1;');", handle(Smi::FromInt(1), isolate)}, | 3653 {"return eval('1;');", handle(Smi::FromInt(1), isolate)}, |
3668 {"return eval('100 * 20;');", handle(Smi::FromInt(2000), isolate)}, | 3654 {"return eval('100 * 20;');", handle(Smi::FromInt(2000), isolate)}, |
3669 {"var x = 10; return eval('x + 20;');", | 3655 {"var x = 10; return eval('x + 20;');", |
3670 handle(Smi::FromInt(30), isolate)}, | 3656 handle(Smi::FromInt(30), isolate)}, |
3671 {"var x = 10; eval('x = 33;'); return x;", | 3657 {"var x = 10; eval('x = 33;'); return x;", |
3672 handle(Smi::FromInt(33), isolate)}, | 3658 handle(Smi::FromInt(33), isolate)}, |
3673 {"'use strict'; var x = 20; var z = 0;\n" | 3659 {"'use strict'; var x = 20; var z = 0;\n" |
3674 "eval('var x = 33; z = x;'); return x + z;", | 3660 "eval('var x = 33; z = x;'); return x + z;", |
(...skipping 17 matching lines...) Expand all Loading... |
3692 {"eval('var x = 10;'); return typeof x;", | 3678 {"eval('var x = 10;'); return typeof x;", |
3693 factory->NewStringFromStaticChars("number")}, | 3679 factory->NewStringFromStaticChars("number")}, |
3694 {"var x = {}; eval('var x = 10;'); return typeof x;", | 3680 {"var x = {}; eval('var x = 10;'); return typeof x;", |
3695 factory->NewStringFromStaticChars("number")}, | 3681 factory->NewStringFromStaticChars("number")}, |
3696 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", | 3682 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", |
3697 factory->NewStringFromStaticChars("object")}, | 3683 factory->NewStringFromStaticChars("object")}, |
3698 }; | 3684 }; |
3699 | 3685 |
3700 for (size_t i = 0; i < arraysize(eval); i++) { | 3686 for (size_t i = 0; i < arraysize(eval); i++) { |
3701 std::string source(InterpreterTester::SourceForBody(eval[i].first)); | 3687 std::string source(InterpreterTester::SourceForBody(eval[i].first)); |
3702 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3688 InterpreterTester tester(isolate, source.c_str()); |
3703 auto callable = tester.GetCallable<>(); | 3689 auto callable = tester.GetCallable<>(); |
3704 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3690 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3705 CHECK(return_value->SameValue(*eval[i].second)); | 3691 CHECK(return_value->SameValue(*eval[i].second)); |
3706 } | 3692 } |
3707 } | 3693 } |
3708 | 3694 |
3709 | 3695 |
3710 TEST(InterpreterEvalParams) { | 3696 TEST(InterpreterEvalParams) { |
3711 HandleAndZoneScope handles; | 3697 HandleAndZoneScope handles; |
3712 i::Isolate* isolate = handles.main_isolate(); | 3698 Isolate* isolate = handles.main_isolate(); |
3713 | 3699 |
3714 std::pair<const char*, Handle<Object>> eval_params[] = { | 3700 std::pair<const char*, Handle<Object>> eval_params[] = { |
3715 {"var x = 10; return eval('x + p1;');", | 3701 {"var x = 10; return eval('x + p1;');", |
3716 handle(Smi::FromInt(30), isolate)}, | 3702 handle(Smi::FromInt(30), isolate)}, |
3717 {"var x = 10; eval('p1 = x;'); return p1;", | 3703 {"var x = 10; eval('p1 = x;'); return p1;", |
3718 handle(Smi::FromInt(10), isolate)}, | 3704 handle(Smi::FromInt(10), isolate)}, |
3719 {"var a = 10;" | 3705 {"var a = 10;" |
3720 "function inner() { return eval('a + p1;');}" | 3706 "function inner() { return eval('a + p1;');}" |
3721 "return inner();", | 3707 "return inner();", |
3722 handle(Smi::FromInt(30), isolate)}, | 3708 handle(Smi::FromInt(30), isolate)}, |
3723 }; | 3709 }; |
3724 | 3710 |
3725 for (size_t i = 0; i < arraysize(eval_params); i++) { | 3711 for (size_t i = 0; i < arraysize(eval_params); i++) { |
3726 std::string source = "function " + InterpreterTester::function_name() + | 3712 std::string source = "function " + InterpreterTester::function_name() + |
3727 "(p1) {" + eval_params[i].first + "}"; | 3713 "(p1) {" + eval_params[i].first + "}"; |
3728 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3714 InterpreterTester tester(isolate, source.c_str()); |
3729 auto callable = tester.GetCallable<Handle<Object>>(); | 3715 auto callable = tester.GetCallable<Handle<Object>>(); |
3730 | 3716 |
3731 Handle<i::Object> return_value = | 3717 Handle<i::Object> return_value = |
3732 callable(handle(Smi::FromInt(20), isolate)).ToHandleChecked(); | 3718 callable(handle(Smi::FromInt(20), isolate)).ToHandleChecked(); |
3733 CHECK(return_value->SameValue(*eval_params[i].second)); | 3719 CHECK(return_value->SameValue(*eval_params[i].second)); |
3734 } | 3720 } |
3735 } | 3721 } |
3736 | 3722 |
3737 | 3723 |
3738 TEST(InterpreterEvalGlobal) { | 3724 TEST(InterpreterEvalGlobal) { |
3739 HandleAndZoneScope handles; | 3725 HandleAndZoneScope handles; |
3740 i::Isolate* isolate = handles.main_isolate(); | 3726 Isolate* isolate = handles.main_isolate(); |
3741 i::Factory* factory = isolate->factory(); | 3727 Factory* factory = isolate->factory(); |
3742 | 3728 |
3743 std::pair<const char*, Handle<Object>> eval_global[] = { | 3729 std::pair<const char*, Handle<Object>> eval_global[] = { |
3744 {"function add_global() { eval('function test() { z = 33; }; test()'); };" | 3730 {"function add_global() { eval('function test() { z = 33; }; test()'); };" |
3745 "function f() { add_global(); return z; }; f();", | 3731 "function f() { add_global(); return z; }; f();", |
3746 handle(Smi::FromInt(33), isolate)}, | 3732 handle(Smi::FromInt(33), isolate)}, |
3747 {"function add_global() {\n" | 3733 {"function add_global() {\n" |
3748 " eval('\"use strict\"; function test() { y = 33; };" | 3734 " eval('\"use strict\"; function test() { y = 33; };" |
3749 " try { test() } catch(e) {}');\n" | 3735 " try { test() } catch(e) {}');\n" |
3750 "}\n" | 3736 "}\n" |
3751 "function f() { add_global(); return typeof y; } f();", | 3737 "function f() { add_global(); return typeof y; } f();", |
3752 factory->NewStringFromStaticChars("undefined")}, | 3738 factory->NewStringFromStaticChars("undefined")}, |
3753 }; | 3739 }; |
3754 | 3740 |
3755 for (size_t i = 0; i < arraysize(eval_global); i++) { | 3741 for (size_t i = 0; i < arraysize(eval_global); i++) { |
3756 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, | 3742 InterpreterTester tester(isolate, eval_global[i].first, "test"); |
3757 "test"); | |
3758 auto callable = tester.GetCallable<>(); | 3743 auto callable = tester.GetCallable<>(); |
3759 | 3744 |
3760 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3745 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3761 CHECK(return_value->SameValue(*eval_global[i].second)); | 3746 CHECK(return_value->SameValue(*eval_global[i].second)); |
3762 } | 3747 } |
3763 } | 3748 } |
3764 | 3749 |
3765 | 3750 |
3766 TEST(InterpreterEvalVariableDecl) { | 3751 TEST(InterpreterEvalVariableDecl) { |
3767 HandleAndZoneScope handles; | 3752 HandleAndZoneScope handles; |
3768 i::Isolate* isolate = handles.main_isolate(); | 3753 Isolate* isolate = handles.main_isolate(); |
3769 i::Factory* factory = isolate->factory(); | 3754 Factory* factory = isolate->factory(); |
3770 | 3755 |
3771 std::pair<const char*, Handle<Object>> eval_global[] = { | 3756 std::pair<const char*, Handle<Object>> eval_global[] = { |
3772 {"function f() { eval('var x = 10; x++;'); return x; }", | 3757 {"function f() { eval('var x = 10; x++;'); return x; }", |
3773 handle(Smi::FromInt(11), isolate)}, | 3758 handle(Smi::FromInt(11), isolate)}, |
3774 {"function f() { var x = 20; eval('var x = 10; x++;'); return x; }", | 3759 {"function f() { var x = 20; eval('var x = 10; x++;'); return x; }", |
3775 handle(Smi::FromInt(11), isolate)}, | 3760 handle(Smi::FromInt(11), isolate)}, |
3776 {"function f() {" | 3761 {"function f() {" |
3777 " var x = 20;" | 3762 " var x = 20;" |
3778 " eval('\"use strict\"; var x = 10; x++;');" | 3763 " eval('\"use strict\"; var x = 10; x++;');" |
3779 " return x; }", | 3764 " return x; }", |
(...skipping 17 matching lines...) Expand all Loading... |
3797 " eval('\"use strict\"; " | 3782 " eval('\"use strict\"; " |
3798 " var x = 20; " | 3783 " var x = 20; " |
3799 " get_eval_x = function func() {return x;};');\n" | 3784 " get_eval_x = function func() {return x;};');\n" |
3800 " return get_eval_x() + x;\n" | 3785 " return get_eval_x() + x;\n" |
3801 "}", | 3786 "}", |
3802 handle(Smi::FromInt(23), isolate)}, | 3787 handle(Smi::FromInt(23), isolate)}, |
3803 // TODO(mythria): Add tests with const declarations. | 3788 // TODO(mythria): Add tests with const declarations. |
3804 }; | 3789 }; |
3805 | 3790 |
3806 for (size_t i = 0; i < arraysize(eval_global); i++) { | 3791 for (size_t i = 0; i < arraysize(eval_global); i++) { |
3807 InterpreterTester tester(handles.main_isolate(), eval_global[i].first, "*"); | 3792 InterpreterTester tester(isolate, eval_global[i].first, "*"); |
3808 auto callable = tester.GetCallable<>(); | 3793 auto callable = tester.GetCallable<>(); |
3809 | 3794 |
3810 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3795 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3811 CHECK(return_value->SameValue(*eval_global[i].second)); | 3796 CHECK(return_value->SameValue(*eval_global[i].second)); |
3812 } | 3797 } |
3813 } | 3798 } |
3814 | 3799 |
3815 | 3800 |
3816 TEST(InterpreterEvalFunctionDecl) { | 3801 TEST(InterpreterEvalFunctionDecl) { |
3817 HandleAndZoneScope handles; | 3802 HandleAndZoneScope handles; |
3818 i::Isolate* isolate = handles.main_isolate(); | 3803 Isolate* isolate = handles.main_isolate(); |
3819 | 3804 |
3820 std::pair<const char*, Handle<Object>> eval_func_decl[] = { | 3805 std::pair<const char*, Handle<Object>> eval_func_decl[] = { |
3821 {"function f() {\n" | 3806 {"function f() {\n" |
3822 " var x = 3;\n" | 3807 " var x = 3;\n" |
3823 " eval('var x = 20;" | 3808 " eval('var x = 20;" |
3824 " function get_x() {return x;};');\n" | 3809 " function get_x() {return x;};');\n" |
3825 " return get_x() + x;\n" | 3810 " return get_x() + x;\n" |
3826 "}", | 3811 "}", |
3827 handle(Smi::FromInt(40), isolate)}, | 3812 handle(Smi::FromInt(40), isolate)}, |
3828 }; | 3813 }; |
3829 | 3814 |
3830 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { | 3815 for (size_t i = 0; i < arraysize(eval_func_decl); i++) { |
3831 InterpreterTester tester(handles.main_isolate(), eval_func_decl[i].first, | 3816 InterpreterTester tester(isolate, eval_func_decl[i].first, "*"); |
3832 "*"); | |
3833 auto callable = tester.GetCallable<>(); | 3817 auto callable = tester.GetCallable<>(); |
3834 | 3818 |
3835 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3819 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3836 CHECK(return_value->SameValue(*eval_func_decl[i].second)); | 3820 CHECK(return_value->SameValue(*eval_func_decl[i].second)); |
3837 } | 3821 } |
3838 } | 3822 } |
3839 | 3823 |
3840 TEST(InterpreterWideRegisterArithmetic) { | 3824 TEST(InterpreterWideRegisterArithmetic) { |
3841 HandleAndZoneScope handles; | 3825 HandleAndZoneScope handles; |
3842 i::Isolate* isolate = handles.main_isolate(); | 3826 Isolate* isolate = handles.main_isolate(); |
3843 | 3827 |
3844 static const size_t kMaxRegisterForTest = 150; | 3828 static const size_t kMaxRegisterForTest = 150; |
3845 std::ostringstream os; | 3829 std::ostringstream os; |
3846 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; | 3830 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
3847 os << " var retval = -77;\n"; | 3831 os << " var retval = -77;\n"; |
3848 for (size_t i = 0; i < kMaxRegisterForTest; i++) { | 3832 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
3849 os << " var x" << i << " = " << i << ";\n"; | 3833 os << " var x" << i << " = " << i << ";\n"; |
3850 } | 3834 } |
3851 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { | 3835 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
3852 size_t j = kMaxRegisterForTest - i - 1; | 3836 size_t j = kMaxRegisterForTest - i - 1; |
3853 os << " var tmp = x" << j << ";\n"; | 3837 os << " var tmp = x" << j << ";\n"; |
3854 os << " var x" << j << " = x" << i << ";\n"; | 3838 os << " var x" << j << " = x" << i << ";\n"; |
3855 os << " var x" << i << " = tmp;\n"; | 3839 os << " var x" << i << " = tmp;\n"; |
3856 } | 3840 } |
3857 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { | 3841 for (size_t i = 0; i < kMaxRegisterForTest / 2; i++) { |
3858 size_t j = kMaxRegisterForTest - i - 1; | 3842 size_t j = kMaxRegisterForTest - i - 1; |
3859 os << " var tmp = x" << j << ";\n"; | 3843 os << " var tmp = x" << j << ";\n"; |
3860 os << " var x" << j << " = x" << i << ";\n"; | 3844 os << " var x" << j << " = x" << i << ";\n"; |
3861 os << " var x" << i << " = tmp;\n"; | 3845 os << " var x" << i << " = tmp;\n"; |
3862 } | 3846 } |
3863 for (size_t i = 0; i < kMaxRegisterForTest; i++) { | 3847 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
3864 os << " if (arg == " << i << ") {\n" // | 3848 os << " if (arg == " << i << ") {\n" // |
3865 << " retval = x" << i << ";\n" // | 3849 << " retval = x" << i << ";\n" // |
3866 << " }\n"; // | 3850 << " }\n"; // |
3867 } | 3851 } |
3868 os << " return retval;\n"; | 3852 os << " return retval;\n"; |
3869 os << "}\n"; | 3853 os << "}\n"; |
3870 | 3854 |
3871 std::string source = os.str(); | 3855 std::string source = os.str(); |
3872 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3856 InterpreterTester tester(isolate, source.c_str()); |
3873 auto callable = tester.GetCallable<Handle<Object>>(); | 3857 auto callable = tester.GetCallable<Handle<Object>>(); |
3874 for (size_t i = 0; i < kMaxRegisterForTest; i++) { | 3858 for (size_t i = 0; i < kMaxRegisterForTest; i++) { |
3875 Handle<Object> arg = handle(Smi::FromInt(static_cast<int>(i)), isolate); | 3859 Handle<Object> arg = handle(Smi::FromInt(static_cast<int>(i)), isolate); |
3876 Handle<Object> return_value = callable(arg).ToHandleChecked(); | 3860 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
3877 CHECK(return_value->SameValue(*arg)); | 3861 CHECK(return_value->SameValue(*arg)); |
3878 } | 3862 } |
3879 } | 3863 } |
3880 | 3864 |
3881 TEST(InterpreterCallWideRegisters) { | 3865 TEST(InterpreterCallWideRegisters) { |
3882 static const int kPeriod = 25; | 3866 static const int kPeriod = 25; |
3883 static const int kLength = 512; | 3867 static const int kLength = 512; |
3884 static const int kStartChar = 65; | 3868 static const int kStartChar = 65; |
3885 | 3869 |
| 3870 HandleAndZoneScope handles; |
| 3871 Isolate* isolate = handles.main_isolate(); |
| 3872 |
3886 for (int pass = 0; pass < 3; pass += 1) { | 3873 for (int pass = 0; pass < 3; pass += 1) { |
3887 std::ostringstream os; | 3874 std::ostringstream os; |
3888 for (int i = 0; i < pass * 97; i += 1) { | 3875 for (int i = 0; i < pass * 97; i += 1) { |
3889 os << "var x" << i << " = " << i << "\n"; | 3876 os << "var x" << i << " = " << i << "\n"; |
3890 } | 3877 } |
3891 os << "return String.fromCharCode("; | 3878 os << "return String.fromCharCode("; |
3892 os << kStartChar; | 3879 os << kStartChar; |
3893 for (int i = 1; i < kLength; i += 1) { | 3880 for (int i = 1; i < kLength; i += 1) { |
3894 os << "," << kStartChar + (i % kPeriod); | 3881 os << "," << kStartChar + (i % kPeriod); |
3895 } | 3882 } |
3896 os << ");"; | 3883 os << ");"; |
3897 std::string source = InterpreterTester::SourceForBody(os.str().c_str()); | 3884 std::string source = InterpreterTester::SourceForBody(os.str().c_str()); |
3898 HandleAndZoneScope handles; | 3885 InterpreterTester tester(isolate, source.c_str()); |
3899 InterpreterTester tester(handles.main_isolate(), source.c_str()); | |
3900 auto callable = tester.GetCallable(); | 3886 auto callable = tester.GetCallable(); |
3901 Handle<Object> return_val = callable().ToHandleChecked(); | 3887 Handle<Object> return_val = callable().ToHandleChecked(); |
3902 Handle<String> return_string = Handle<String>::cast(return_val); | 3888 Handle<String> return_string = Handle<String>::cast(return_val); |
3903 CHECK_EQ(return_string->length(), kLength); | 3889 CHECK_EQ(return_string->length(), kLength); |
3904 for (int i = 0; i < kLength; i += 1) { | 3890 for (int i = 0; i < kLength; i += 1) { |
3905 CHECK_EQ(return_string->Get(i), 65 + (i % kPeriod)); | 3891 CHECK_EQ(return_string->Get(i), 65 + (i % kPeriod)); |
3906 } | 3892 } |
3907 } | 3893 } |
3908 } | 3894 } |
3909 | 3895 |
3910 TEST(InterpreterWideParametersPickOne) { | 3896 TEST(InterpreterWideParametersPickOne) { |
| 3897 HandleAndZoneScope handles; |
| 3898 Isolate* isolate = handles.main_isolate(); |
3911 static const int kParameterCount = 130; | 3899 static const int kParameterCount = 130; |
3912 for (int parameter = 0; parameter < 10; parameter++) { | 3900 for (int parameter = 0; parameter < 10; parameter++) { |
3913 HandleAndZoneScope handles; | |
3914 i::Isolate* isolate = handles.main_isolate(); | |
3915 std::ostringstream os; | 3901 std::ostringstream os; |
3916 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; | 3902 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
3917 os << " function selector(i"; | 3903 os << " function selector(i"; |
3918 for (int i = 0; i < kParameterCount; i++) { | 3904 for (int i = 0; i < kParameterCount; i++) { |
3919 os << "," | 3905 os << "," |
3920 << "a" << i; | 3906 << "a" << i; |
3921 } | 3907 } |
3922 os << ") {\n"; | 3908 os << ") {\n"; |
3923 os << " return a" << parameter << ";\n"; | 3909 os << " return a" << parameter << ";\n"; |
3924 os << " };\n"; | 3910 os << " };\n"; |
3925 os << " return selector(arg"; | 3911 os << " return selector(arg"; |
3926 for (int i = 0; i < kParameterCount; i++) { | 3912 for (int i = 0; i < kParameterCount; i++) { |
3927 os << "," << i; | 3913 os << "," << i; |
3928 } | 3914 } |
3929 os << ");"; | 3915 os << ");"; |
3930 os << "}\n"; | 3916 os << "}\n"; |
3931 | 3917 |
3932 std::string source = os.str(); | 3918 std::string source = os.str(); |
3933 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 3919 InterpreterTester tester(isolate, source.c_str(), "*"); |
3934 auto callable = tester.GetCallable<Handle<Object>>(); | 3920 auto callable = tester.GetCallable<Handle<Object>>(); |
3935 Handle<Object> arg = handle(Smi::FromInt(0xaa55), isolate); | 3921 Handle<Object> arg = handle(Smi::FromInt(0xaa55), isolate); |
3936 Handle<Object> return_value = callable(arg).ToHandleChecked(); | 3922 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
3937 Handle<Smi> actual = Handle<Smi>::cast(return_value); | 3923 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
3938 CHECK_EQ(actual->value(), parameter); | 3924 CHECK_EQ(actual->value(), parameter); |
3939 } | 3925 } |
3940 } | 3926 } |
3941 | 3927 |
3942 TEST(InterpreterWideParametersSummation) { | 3928 TEST(InterpreterWideParametersSummation) { |
3943 static int kParameterCount = 200; | 3929 static int kParameterCount = 200; |
3944 static int kBaseValue = 17000; | 3930 static int kBaseValue = 17000; |
3945 HandleAndZoneScope handles; | 3931 HandleAndZoneScope handles; |
3946 i::Isolate* isolate = handles.main_isolate(); | 3932 Isolate* isolate = handles.main_isolate(); |
3947 std::ostringstream os; | 3933 std::ostringstream os; |
3948 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; | 3934 os << "function " << InterpreterTester::function_name() << "(arg) {\n"; |
3949 os << " function summation(i"; | 3935 os << " function summation(i"; |
3950 for (int i = 0; i < kParameterCount; i++) { | 3936 for (int i = 0; i < kParameterCount; i++) { |
3951 os << "," | 3937 os << "," |
3952 << "a" << i; | 3938 << "a" << i; |
3953 } | 3939 } |
3954 os << ") {\n"; | 3940 os << ") {\n"; |
3955 os << " var sum = " << kBaseValue << ";\n"; | 3941 os << " var sum = " << kBaseValue << ";\n"; |
3956 os << " switch(i) {\n"; | 3942 os << " switch(i) {\n"; |
3957 for (int i = 0; i < kParameterCount; i++) { | 3943 for (int i = 0; i < kParameterCount; i++) { |
3958 int j = kParameterCount - i - 1; | 3944 int j = kParameterCount - i - 1; |
3959 os << " case " << j << ": sum += a" << j << ";\n"; | 3945 os << " case " << j << ": sum += a" << j << ";\n"; |
3960 } | 3946 } |
3961 os << " }\n"; | 3947 os << " }\n"; |
3962 os << " return sum;\n"; | 3948 os << " return sum;\n"; |
3963 os << " };\n"; | 3949 os << " };\n"; |
3964 os << " return summation(arg"; | 3950 os << " return summation(arg"; |
3965 for (int i = 0; i < kParameterCount; i++) { | 3951 for (int i = 0; i < kParameterCount; i++) { |
3966 os << "," << i; | 3952 os << "," << i; |
3967 } | 3953 } |
3968 os << ");"; | 3954 os << ");"; |
3969 os << "}\n"; | 3955 os << "}\n"; |
3970 | 3956 |
3971 std::string source = os.str(); | 3957 std::string source = os.str(); |
3972 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 3958 InterpreterTester tester(isolate, source.c_str(), "*"); |
3973 auto callable = tester.GetCallable<Handle<Object>>(); | 3959 auto callable = tester.GetCallable<Handle<Object>>(); |
3974 for (int i = 0; i < kParameterCount; i++) { | 3960 for (int i = 0; i < kParameterCount; i++) { |
3975 Handle<Object> arg = handle(Smi::FromInt(i), isolate); | 3961 Handle<Object> arg = handle(Smi::FromInt(i), isolate); |
3976 Handle<Object> return_value = callable(arg).ToHandleChecked(); | 3962 Handle<Object> return_value = callable(arg).ToHandleChecked(); |
3977 int expected = kBaseValue + i * (i + 1) / 2; | 3963 int expected = kBaseValue + i * (i + 1) / 2; |
3978 Handle<Smi> actual = Handle<Smi>::cast(return_value); | 3964 Handle<Smi> actual = Handle<Smi>::cast(return_value); |
3979 CHECK_EQ(actual->value(), expected); | 3965 CHECK_EQ(actual->value(), expected); |
3980 } | 3966 } |
3981 } | 3967 } |
3982 | 3968 |
3983 TEST(InterpreterDoExpression) { | 3969 TEST(InterpreterDoExpression) { |
3984 bool old_flag = FLAG_harmony_do_expressions; | 3970 bool old_flag = FLAG_harmony_do_expressions; |
3985 FLAG_harmony_do_expressions = true; | 3971 FLAG_harmony_do_expressions = true; |
3986 | 3972 |
3987 HandleAndZoneScope handles; | 3973 HandleAndZoneScope handles; |
3988 i::Isolate* isolate = handles.main_isolate(); | 3974 Isolate* isolate = handles.main_isolate(); |
3989 Factory* factory = isolate->factory(); | 3975 Factory* factory = isolate->factory(); |
3990 | 3976 |
3991 std::pair<const char*, Handle<Object>> do_expr[] = { | 3977 std::pair<const char*, Handle<Object>> do_expr[] = { |
3992 {"var a = do {}; return a;", factory->undefined_value()}, | 3978 {"var a = do {}; return a;", factory->undefined_value()}, |
3993 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, | 3979 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, |
3994 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, | 3980 {"var a = do { var x = 100; }; return a;", factory->undefined_value()}, |
3995 {"var a = do { var x = 100; x++; }; return a;", | 3981 {"var a = do { var x = 100; x++; }; return a;", |
3996 handle(Smi::FromInt(100), isolate)}, | 3982 handle(Smi::FromInt(100), isolate)}, |
3997 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" | 3983 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" |
3998 "return i;", | 3984 "return i;", |
3999 handle(Smi::FromInt(3), isolate)}, | 3985 handle(Smi::FromInt(3), isolate)}, |
4000 }; | 3986 }; |
4001 | 3987 |
4002 for (size_t i = 0; i < arraysize(do_expr); i++) { | 3988 for (size_t i = 0; i < arraysize(do_expr); i++) { |
4003 std::string source(InterpreterTester::SourceForBody(do_expr[i].first)); | 3989 std::string source(InterpreterTester::SourceForBody(do_expr[i].first)); |
4004 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3990 InterpreterTester tester(isolate, source.c_str()); |
4005 auto callable = tester.GetCallable<>(); | 3991 auto callable = tester.GetCallable<>(); |
4006 | 3992 |
4007 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3993 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4008 CHECK(return_value->SameValue(*do_expr[i].second)); | 3994 CHECK(return_value->SameValue(*do_expr[i].second)); |
4009 } | 3995 } |
4010 | 3996 |
4011 FLAG_harmony_do_expressions = old_flag; | 3997 FLAG_harmony_do_expressions = old_flag; |
4012 } | 3998 } |
4013 | 3999 |
4014 TEST(InterpreterWithStatement) { | 4000 TEST(InterpreterWithStatement) { |
4015 HandleAndZoneScope handles; | 4001 HandleAndZoneScope handles; |
4016 i::Isolate* isolate = handles.main_isolate(); | 4002 Isolate* isolate = handles.main_isolate(); |
4017 | 4003 |
4018 std::pair<const char*, Handle<Object>> with_stmt[] = { | 4004 std::pair<const char*, Handle<Object>> with_stmt[] = { |
4019 {"with({x:42}) return x;", handle(Smi::FromInt(42), isolate)}, | 4005 {"with({x:42}) return x;", handle(Smi::FromInt(42), isolate)}, |
4020 {"with({}) { var y = 10; return y;}", handle(Smi::FromInt(10), isolate)}, | 4006 {"with({}) { var y = 10; return y;}", handle(Smi::FromInt(10), isolate)}, |
4021 {"var y = {x:42};" | 4007 {"var y = {x:42};" |
4022 " function inner() {" | 4008 " function inner() {" |
4023 " var x = 20;" | 4009 " var x = 20;" |
4024 " with(y) return x;" | 4010 " with(y) return x;" |
4025 "}" | 4011 "}" |
4026 "return inner();", | 4012 "return inner();", |
4027 handle(Smi::FromInt(42), isolate)}, | 4013 handle(Smi::FromInt(42), isolate)}, |
4028 {"var y = {x:42};" | 4014 {"var y = {x:42};" |
4029 " function inner(o) {" | 4015 " function inner(o) {" |
4030 " var x = 20;" | 4016 " var x = 20;" |
4031 " with(o) return x;" | 4017 " with(o) return x;" |
4032 "}" | 4018 "}" |
4033 "return inner(y);", | 4019 "return inner(y);", |
4034 handle(Smi::FromInt(42), isolate)}, | 4020 handle(Smi::FromInt(42), isolate)}, |
4035 }; | 4021 }; |
4036 | 4022 |
4037 for (size_t i = 0; i < arraysize(with_stmt); i++) { | 4023 for (size_t i = 0; i < arraysize(with_stmt); i++) { |
4038 std::string source(InterpreterTester::SourceForBody(with_stmt[i].first)); | 4024 std::string source(InterpreterTester::SourceForBody(with_stmt[i].first)); |
4039 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4025 InterpreterTester tester(isolate, source.c_str()); |
4040 auto callable = tester.GetCallable<>(); | 4026 auto callable = tester.GetCallable<>(); |
4041 | 4027 |
4042 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4028 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4043 CHECK(return_value->SameValue(*with_stmt[i].second)); | 4029 CHECK(return_value->SameValue(*with_stmt[i].second)); |
4044 } | 4030 } |
4045 } | 4031 } |
4046 | 4032 |
4047 TEST(InterpreterClassLiterals) { | 4033 TEST(InterpreterClassLiterals) { |
4048 HandleAndZoneScope handles; | 4034 HandleAndZoneScope handles; |
4049 i::Isolate* isolate = handles.main_isolate(); | 4035 Isolate* isolate = handles.main_isolate(); |
4050 std::pair<const char*, Handle<Object>> examples[] = { | 4036 std::pair<const char*, Handle<Object>> examples[] = { |
4051 {"class C {\n" | 4037 {"class C {\n" |
4052 " constructor(x) { this.x_ = x; }\n" | 4038 " constructor(x) { this.x_ = x; }\n" |
4053 " method() { return this.x_; }\n" | 4039 " method() { return this.x_; }\n" |
4054 "}\n" | 4040 "}\n" |
4055 "return new C(99).method();", | 4041 "return new C(99).method();", |
4056 handle(Smi::FromInt(99), isolate)}, | 4042 handle(Smi::FromInt(99), isolate)}, |
4057 {"class C {\n" | 4043 {"class C {\n" |
4058 " constructor(x) { this.x_ = x; }\n" | 4044 " constructor(x) { this.x_ = x; }\n" |
4059 " static static_method(x) { return x; }\n" | 4045 " static static_method(x) { return x; }\n" |
(...skipping 30 matching lines...) Expand all Loading... |
4090 {"var method = 'f';" | 4076 {"var method = 'f';" |
4091 "class C {\n" | 4077 "class C {\n" |
4092 " [method]() { return 106; }\n" | 4078 " [method]() { return 106; }\n" |
4093 "}\n" | 4079 "}\n" |
4094 "return new C().f();", | 4080 "return new C().f();", |
4095 handle(Smi::FromInt(106), isolate)}, | 4081 handle(Smi::FromInt(106), isolate)}, |
4096 }; | 4082 }; |
4097 | 4083 |
4098 for (size_t i = 0; i < arraysize(examples); ++i) { | 4084 for (size_t i = 0; i < arraysize(examples); ++i) { |
4099 std::string source(InterpreterTester::SourceForBody(examples[i].first)); | 4085 std::string source(InterpreterTester::SourceForBody(examples[i].first)); |
4100 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 4086 InterpreterTester tester(isolate, source.c_str(), "*"); |
4101 auto callable = tester.GetCallable<>(); | 4087 auto callable = tester.GetCallable<>(); |
4102 | 4088 |
4103 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4089 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4104 CHECK(return_value->SameValue(*examples[i].second)); | 4090 CHECK(return_value->SameValue(*examples[i].second)); |
4105 } | 4091 } |
4106 } | 4092 } |
4107 | 4093 |
4108 TEST(InterpreterClassAndSuperClass) { | 4094 TEST(InterpreterClassAndSuperClass) { |
4109 HandleAndZoneScope handles; | 4095 HandleAndZoneScope handles; |
4110 i::Isolate* isolate = handles.main_isolate(); | 4096 Isolate* isolate = handles.main_isolate(); |
4111 std::pair<const char*, Handle<Object>> examples[] = { | 4097 std::pair<const char*, Handle<Object>> examples[] = { |
4112 {"class A {\n" | 4098 {"class A {\n" |
4113 " constructor(x) { this.x_ = x; }\n" | 4099 " constructor(x) { this.x_ = x; }\n" |
4114 " method() { return this.x_; }\n" | 4100 " method() { return this.x_; }\n" |
4115 "}\n" | 4101 "}\n" |
4116 "class B extends A {\n" | 4102 "class B extends A {\n" |
4117 " constructor(x, y) { super(x); this.y_ = y; }\n" | 4103 " constructor(x, y) { super(x); this.y_ = y; }\n" |
4118 " method() { return super.method() + 1; }\n" | 4104 " method() { return super.method() + 1; }\n" |
4119 "}\n" | 4105 "}\n" |
4120 "return new B(998, 0).method();\n", | 4106 "return new B(998, 0).method();\n", |
(...skipping 29 matching lines...) Expand all Loading... |
4150 "return new B().method();\n", | 4136 "return new B().method();\n", |
4151 handle(Smi::FromInt(1), isolate)}, | 4137 handle(Smi::FromInt(1), isolate)}, |
4152 {"var object = { setY(v) { super.y = v; }};\n" | 4138 {"var object = { setY(v) { super.y = v; }};\n" |
4153 "object.setY(10);\n" | 4139 "object.setY(10);\n" |
4154 "return object.y;\n", | 4140 "return object.y;\n", |
4155 handle(Smi::FromInt(10), isolate)}, | 4141 handle(Smi::FromInt(10), isolate)}, |
4156 }; | 4142 }; |
4157 | 4143 |
4158 for (size_t i = 0; i < arraysize(examples); ++i) { | 4144 for (size_t i = 0; i < arraysize(examples); ++i) { |
4159 std::string source(InterpreterTester::SourceForBody(examples[i].first)); | 4145 std::string source(InterpreterTester::SourceForBody(examples[i].first)); |
4160 InterpreterTester tester(handles.main_isolate(), source.c_str(), "*"); | 4146 InterpreterTester tester(isolate, source.c_str(), "*"); |
4161 auto callable = tester.GetCallable<>(); | 4147 auto callable = tester.GetCallable<>(); |
4162 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4148 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4163 CHECK(return_value->SameValue(*examples[i].second)); | 4149 CHECK(return_value->SameValue(*examples[i].second)); |
4164 } | 4150 } |
4165 } | 4151 } |
4166 | 4152 |
4167 TEST(InterpreterConstDeclaration) { | 4153 TEST(InterpreterConstDeclaration) { |
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; return x;", handle(Smi::FromInt(3), isolate)}, | 4159 {"const x = 3; return x;", handle(Smi::FromInt(3), isolate)}, |
4174 {"let x = 10; x = x + 20; return x;", handle(Smi::FromInt(30), isolate)}, | 4160 {"let x = 10; x = x + 20; return x;", handle(Smi::FromInt(30), isolate)}, |
4175 {"let x = 10; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, | 4161 {"let x = 10; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
4176 {"let x; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, | 4162 {"let x; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
4177 {"let x; return x;", factory->undefined_value()}, | 4163 {"let x; return x;", factory->undefined_value()}, |
4178 {"var x = 10; { let x = 30; } return x;", | 4164 {"var x = 10; { let x = 30; } return x;", |
4179 handle(Smi::FromInt(10), isolate)}, | 4165 handle(Smi::FromInt(10), isolate)}, |
4180 {"let x = 10; { let x = 20; } return x;", | 4166 {"let x = 10; { let x = 20; } return x;", |
(...skipping 11 matching lines...) Expand all Loading... |
4192 " const x = i;\n" // const declarations are block scoped. | 4178 " const x = i;\n" // const declarations are block scoped. |
4193 " a = a + x;\n" | 4179 " a = a + x;\n" |
4194 "}\n" | 4180 "}\n" |
4195 "return a;\n", | 4181 "return a;\n", |
4196 handle(Smi::FromInt(55), isolate)}, | 4182 handle(Smi::FromInt(55), isolate)}, |
4197 }; | 4183 }; |
4198 | 4184 |
4199 // Tests for sloppy mode. | 4185 // Tests for sloppy mode. |
4200 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4186 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4201 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); | 4187 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); |
4202 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4188 InterpreterTester tester(isolate, source.c_str()); |
4203 auto callable = tester.GetCallable<>(); | 4189 auto callable = tester.GetCallable<>(); |
4204 | 4190 |
4205 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4191 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4206 CHECK(return_value->SameValue(*const_decl[i].second)); | 4192 CHECK(return_value->SameValue(*const_decl[i].second)); |
4207 } | 4193 } |
4208 | 4194 |
4209 // Tests for strict mode. | 4195 // Tests for strict mode. |
4210 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4196 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4211 std::string strict_body = | 4197 std::string strict_body = |
4212 "'use strict'; " + std::string(const_decl[i].first); | 4198 "'use strict'; " + std::string(const_decl[i].first); |
4213 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); | 4199 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); |
4214 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4200 InterpreterTester tester(isolate, source.c_str()); |
4215 auto callable = tester.GetCallable<>(); | 4201 auto callable = tester.GetCallable<>(); |
4216 | 4202 |
4217 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4203 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4218 CHECK(return_value->SameValue(*const_decl[i].second)); | 4204 CHECK(return_value->SameValue(*const_decl[i].second)); |
4219 } | 4205 } |
4220 } | 4206 } |
4221 | 4207 |
4222 TEST(InterpreterConstDeclarationLookupSlots) { | 4208 TEST(InterpreterConstDeclarationLookupSlots) { |
4223 HandleAndZoneScope handles; | 4209 HandleAndZoneScope handles; |
4224 i::Isolate* isolate = handles.main_isolate(); | 4210 Isolate* isolate = handles.main_isolate(); |
4225 i::Factory* factory = isolate->factory(); | 4211 Factory* factory = isolate->factory(); |
4226 | 4212 |
4227 std::pair<const char*, Handle<Object>> const_decl[] = { | 4213 std::pair<const char*, Handle<Object>> const_decl[] = { |
4228 {"const x = 3; function f1() {return x;}; return x;", | 4214 {"const x = 3; function f1() {return x;}; return x;", |
4229 handle(Smi::FromInt(3), isolate)}, | 4215 handle(Smi::FromInt(3), isolate)}, |
4230 {"let x = 10; x = x + 20; function f1() {return x;}; return x;", | 4216 {"let x = 10; x = x + 20; function f1() {return x;}; return x;", |
4231 handle(Smi::FromInt(30), isolate)}, | 4217 handle(Smi::FromInt(30), isolate)}, |
4232 {"let x; x = 20; function f1() {return x;}; return x;", | 4218 {"let x; x = 20; function f1() {return x;}; return x;", |
4233 handle(Smi::FromInt(20), isolate)}, | 4219 handle(Smi::FromInt(20), isolate)}, |
4234 {"let x; function f1() {return x;}; return x;", | 4220 {"let x; function f1() {return x;}; return x;", |
4235 factory->undefined_value()}, | 4221 factory->undefined_value()}, |
4236 }; | 4222 }; |
4237 | 4223 |
4238 // Tests for sloppy mode. | 4224 // Tests for sloppy mode. |
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 source(InterpreterTester::SourceForBody(const_decl[i].first)); | 4226 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); |
4241 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4227 InterpreterTester tester(isolate, source.c_str()); |
4242 auto callable = tester.GetCallable<>(); | 4228 auto callable = tester.GetCallable<>(); |
4243 | 4229 |
4244 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4230 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4245 CHECK(return_value->SameValue(*const_decl[i].second)); | 4231 CHECK(return_value->SameValue(*const_decl[i].second)); |
4246 } | 4232 } |
4247 | 4233 |
4248 // Tests for strict mode. | 4234 // Tests for strict mode. |
4249 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4235 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4250 std::string strict_body = | 4236 std::string strict_body = |
4251 "'use strict'; " + std::string(const_decl[i].first); | 4237 "'use strict'; " + std::string(const_decl[i].first); |
4252 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); | 4238 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); |
4253 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4239 InterpreterTester tester(isolate, source.c_str()); |
4254 auto callable = tester.GetCallable<>(); | 4240 auto callable = tester.GetCallable<>(); |
4255 | 4241 |
4256 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4242 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4257 CHECK(return_value->SameValue(*const_decl[i].second)); | 4243 CHECK(return_value->SameValue(*const_decl[i].second)); |
4258 } | 4244 } |
4259 } | 4245 } |
4260 | 4246 |
4261 TEST(InterpreterConstInLookupContextChain) { | 4247 TEST(InterpreterConstInLookupContextChain) { |
4262 HandleAndZoneScope handles; | 4248 HandleAndZoneScope handles; |
4263 i::Isolate* isolate = handles.main_isolate(); | 4249 Isolate* isolate = handles.main_isolate(); |
4264 | 4250 |
4265 const char* prologue = | 4251 const char* prologue = |
4266 "function OuterMost() {\n" | 4252 "function OuterMost() {\n" |
4267 " const outerConst = 10;\n" | 4253 " const outerConst = 10;\n" |
4268 " let outerLet = 20;\n" | 4254 " let outerLet = 20;\n" |
4269 " function Outer() {\n" | 4255 " function Outer() {\n" |
4270 " function Inner() {\n" | 4256 " function Inner() {\n" |
4271 " this.innerFunc = function() { "; | 4257 " this.innerFunc = function() { "; |
4272 const char* epilogue = | 4258 const char* epilogue = |
4273 " }\n" | 4259 " }\n" |
(...skipping 14 matching lines...) Expand all Loading... |
4288 handle(Smi::FromInt(40), isolate)}, | 4274 handle(Smi::FromInt(40), isolate)}, |
4289 {"var outerConst = 50; return outerConst;", | 4275 {"var outerConst = 50; return outerConst;", |
4290 handle(Smi::FromInt(50), isolate)}, | 4276 handle(Smi::FromInt(50), isolate)}, |
4291 {"try { outerConst = 30 } catch(e) { return -1; }", | 4277 {"try { outerConst = 30 } catch(e) { return -1; }", |
4292 handle(Smi::FromInt(-1), isolate)}}; | 4278 handle(Smi::FromInt(-1), isolate)}}; |
4293 | 4279 |
4294 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4280 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4295 std::string script = std::string(prologue) + | 4281 std::string script = std::string(prologue) + |
4296 std::string(const_decl[i].first) + | 4282 std::string(const_decl[i].first) + |
4297 std::string(epilogue); | 4283 std::string(epilogue); |
4298 InterpreterTester tester(handles.main_isolate(), script.c_str(), "*"); | 4284 InterpreterTester tester(isolate, script.c_str(), "*"); |
4299 auto callable = tester.GetCallable<>(); | 4285 auto callable = tester.GetCallable<>(); |
4300 | 4286 |
4301 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4287 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4302 CHECK(return_value->SameValue(*const_decl[i].second)); | 4288 CHECK(return_value->SameValue(*const_decl[i].second)); |
4303 } | 4289 } |
4304 } | 4290 } |
4305 | 4291 |
4306 TEST(InterpreterIllegalConstDeclaration) { | 4292 TEST(InterpreterIllegalConstDeclaration) { |
4307 HandleAndZoneScope handles; | 4293 HandleAndZoneScope handles; |
| 4294 Isolate* isolate = handles.main_isolate(); |
4308 | 4295 |
4309 std::pair<const char*, const char*> const_decl[] = { | 4296 std::pair<const char*, const char*> const_decl[] = { |
4310 {"const x = x = 10 + 3; return x;", | 4297 {"const x = x = 10 + 3; return x;", |
4311 "Uncaught ReferenceError: x is not defined"}, | 4298 "Uncaught ReferenceError: x is not defined"}, |
4312 {"const x = 10; x = 20; return x;", | 4299 {"const x = 10; x = 20; return x;", |
4313 "Uncaught TypeError: Assignment to constant variable."}, | 4300 "Uncaught TypeError: Assignment to constant variable."}, |
4314 {"const x = 10; { x = 20; } return x;", | 4301 {"const x = 10; { x = 20; } return x;", |
4315 "Uncaught TypeError: Assignment to constant variable."}, | 4302 "Uncaught TypeError: Assignment to constant variable."}, |
4316 {"const x = 10; eval('x = 20;'); return x;", | 4303 {"const x = 10; eval('x = 20;'); return x;", |
4317 "Uncaught TypeError: Assignment to constant variable."}, | 4304 "Uncaught TypeError: Assignment to constant variable."}, |
4318 {"let x = x + 10; return x;", | 4305 {"let x = x + 10; return x;", |
4319 "Uncaught ReferenceError: x is not defined"}, | 4306 "Uncaught ReferenceError: x is not defined"}, |
4320 {"'use strict'; (function f1() { f1 = 123; })() ", | 4307 {"'use strict'; (function f1() { f1 = 123; })() ", |
4321 "Uncaught TypeError: Assignment to constant variable."}, | 4308 "Uncaught TypeError: Assignment to constant variable."}, |
4322 }; | 4309 }; |
4323 | 4310 |
4324 // Tests for sloppy mode. | 4311 // Tests for sloppy mode. |
4325 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4312 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4326 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); | 4313 std::string source(InterpreterTester::SourceForBody(const_decl[i].first)); |
4327 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4314 InterpreterTester tester(isolate, source.c_str()); |
4328 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 4315 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
4329 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); | 4316 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); |
4330 CHECK( | 4317 CHECK( |
4331 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 4318 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
4332 .FromJust()); | 4319 .FromJust()); |
4333 } | 4320 } |
4334 | 4321 |
4335 // Tests for strict mode. | 4322 // Tests for strict mode. |
4336 for (size_t i = 0; i < arraysize(const_decl); i++) { | 4323 for (size_t i = 0; i < arraysize(const_decl); i++) { |
4337 std::string strict_body = | 4324 std::string strict_body = |
4338 "'use strict'; " + std::string(const_decl[i].first); | 4325 "'use strict'; " + std::string(const_decl[i].first); |
4339 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); | 4326 std::string source(InterpreterTester::SourceForBody(strict_body.c_str())); |
4340 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4327 InterpreterTester tester(isolate, source.c_str()); |
4341 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 4328 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
4342 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); | 4329 v8::Local<v8::String> expected_string = v8_str(const_decl[i].second); |
4343 CHECK( | 4330 CHECK( |
4344 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 4331 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
4345 .FromJust()); | 4332 .FromJust()); |
4346 } | 4333 } |
4347 } | 4334 } |
4348 | 4335 |
4349 TEST(InterpreterGenerators) { | 4336 TEST(InterpreterGenerators) { |
4350 HandleAndZoneScope handles; | 4337 HandleAndZoneScope handles; |
4351 i::Isolate* isolate = handles.main_isolate(); | 4338 Isolate* isolate = handles.main_isolate(); |
4352 i::Factory* factory = isolate->factory(); | 4339 Factory* factory = isolate->factory(); |
4353 | 4340 |
4354 std::pair<const char*, Handle<Object>> tests[] = { | 4341 std::pair<const char*, Handle<Object>> tests[] = { |
4355 {"function* f() { }; return f().next().value", | 4342 {"function* f() { }; return f().next().value", |
4356 factory->undefined_value()}, | 4343 factory->undefined_value()}, |
4357 {"function* f() { yield 42 }; return f().next().value", | 4344 {"function* f() { yield 42 }; return f().next().value", |
4358 factory->NewNumberFromInt(42)}, | 4345 factory->NewNumberFromInt(42)}, |
4359 {"function* f() { for (let x of [42]) yield x}; return f().next().value", | 4346 {"function* f() { for (let x of [42]) yield x}; return f().next().value", |
4360 factory->NewNumberFromInt(42)}, | 4347 factory->NewNumberFromInt(42)}, |
4361 }; | 4348 }; |
4362 | 4349 |
4363 for (size_t i = 0; i < arraysize(tests); i++) { | 4350 for (size_t i = 0; i < arraysize(tests); i++) { |
4364 std::string source(InterpreterTester::SourceForBody(tests[i].first)); | 4351 std::string source(InterpreterTester::SourceForBody(tests[i].first)); |
4365 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 4352 InterpreterTester tester(isolate, source.c_str()); |
4366 auto callable = tester.GetCallable<>(); | 4353 auto callable = tester.GetCallable<>(); |
4367 | 4354 |
4368 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4355 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4369 CHECK(return_value->SameValue(*tests[i].second)); | 4356 CHECK(return_value->SameValue(*tests[i].second)); |
4370 } | 4357 } |
4371 } | 4358 } |
4372 | 4359 |
4373 } // namespace interpreter | 4360 } // namespace interpreter |
4374 } // namespace internal | 4361 } // namespace internal |
4375 } // namespace v8 | 4362 } // namespace v8 |
OLD | NEW |