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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "src/compilation-info.h" | 7 #include "src/compilation-info.h" |
8 #include "src/compiler/pipeline.h" | 8 #include "src/compiler/pipeline.h" |
9 #include "src/execution.h" | 9 #include "src/execution.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 Isolate* isolate_; | 70 Isolate* isolate_; |
71 Handle<JSFunction> function_; | 71 Handle<JSFunction> function_; |
72 }; | 72 }; |
73 | 73 |
74 | 74 |
75 class BytecodeGraphTester { | 75 class BytecodeGraphTester { |
76 public: | 76 public: |
77 BytecodeGraphTester(Isolate* isolate, const char* script, | 77 BytecodeGraphTester(Isolate* isolate, Zone* zone, const char* script, |
78 const char* filter = kFunctionName) | 78 const char* filter = kFunctionName) |
79 : isolate_(isolate), script_(script) { | 79 : isolate_(isolate), zone_(zone), script_(script) { |
80 i::FLAG_ignition = true; | 80 i::FLAG_ignition = true; |
81 i::FLAG_always_opt = false; | 81 i::FLAG_always_opt = false; |
82 i::FLAG_allow_natives_syntax = true; | 82 i::FLAG_allow_natives_syntax = true; |
83 i::FLAG_loop_assignment_analysis = false; | 83 i::FLAG_loop_assignment_analysis = false; |
84 } | 84 } |
85 virtual ~BytecodeGraphTester() {} | 85 virtual ~BytecodeGraphTester() {} |
86 | 86 |
87 template <class... A> | 87 template <class... A> |
88 BytecodeGraphCallable<A...> GetCallable( | 88 BytecodeGraphCallable<A...> GetCallable( |
89 const char* functionName = kFunctionName) { | 89 const char* functionName = kFunctionName) { |
(...skipping 11 matching lines...) Expand all Loading... |
101 CHECK(!try_catch.Message().IsEmpty()); | 101 CHECK(!try_catch.Message().IsEmpty()); |
102 return try_catch.Message(); | 102 return try_catch.Message(); |
103 } | 103 } |
104 | 104 |
105 static Handle<Object> NewObject(const char* script) { | 105 static Handle<Object> NewObject(const char* script) { |
106 return v8::Utils::OpenHandle(*CompileRun(script)); | 106 return v8::Utils::OpenHandle(*CompileRun(script)); |
107 } | 107 } |
108 | 108 |
109 private: | 109 private: |
110 Isolate* isolate_; | 110 Isolate* isolate_; |
| 111 Zone* zone_; |
111 const char* script_; | 112 const char* script_; |
112 | 113 |
113 Handle<JSFunction> GetFunction(const char* functionName) { | 114 Handle<JSFunction> GetFunction(const char* functionName) { |
114 CompileRun(script_); | 115 CompileRun(script_); |
115 Local<Function> api_function = Local<Function>::Cast( | 116 Local<Function> api_function = Local<Function>::Cast( |
116 CcTest::global() | 117 CcTest::global() |
117 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(functionName)) | 118 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(functionName)) |
118 .ToLocalChecked()); | 119 .ToLocalChecked()); |
119 Handle<JSFunction> function = | 120 Handle<JSFunction> function = |
120 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); | 121 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); |
121 CHECK(function->shared()->HasBytecodeArray()); | 122 CHECK(function->shared()->HasBytecodeArray()); |
122 | 123 |
123 // TODO(mstarzinger): We should be able to prime CompilationInfo without | 124 // TODO(mstarzinger): We should be able to prime CompilationInfo without |
124 // having to instantiate a ParseInfo first. Fix this! | 125 // having to instantiate a ParseInfo first. Fix this! |
125 ParseInfo parse_info(handle(function->shared())); | 126 ParseInfo parse_info(zone_, handle(function->shared())); |
126 | 127 |
127 CompilationInfo compilation_info(&parse_info, function); | 128 CompilationInfo compilation_info(&parse_info, function); |
128 compilation_info.SetOptimizing(); | 129 compilation_info.SetOptimizing(); |
129 compilation_info.MarkAsDeoptimizationEnabled(); | 130 compilation_info.MarkAsDeoptimizationEnabled(); |
130 compilation_info.MarkAsOptimizeFromBytecode(); | 131 compilation_info.MarkAsOptimizeFromBytecode(); |
131 Handle<Code> code = Pipeline::GenerateCodeForTesting(&compilation_info); | 132 Handle<Code> code = Pipeline::GenerateCodeForTesting(&compilation_info); |
132 function->ReplaceCode(*code); | 133 function->ReplaceCode(*code); |
133 | 134 |
134 return function; | 135 return function; |
135 } | 136 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 CHECK_GE(i, 0); | 180 CHECK_GE(i, 0); |
180 CHECK_LT(i, N); | 181 CHECK_LT(i, N); |
181 return return_value_and_parameters[1 + i]; | 182 return return_value_and_parameters[1 + i]; |
182 } | 183 } |
183 }; | 184 }; |
184 | 185 |
185 | 186 |
186 TEST(BytecodeGraphBuilderReturnStatements) { | 187 TEST(BytecodeGraphBuilderReturnStatements) { |
187 HandleAndZoneScope scope; | 188 HandleAndZoneScope scope; |
188 Isolate* isolate = scope.main_isolate(); | 189 Isolate* isolate = scope.main_isolate(); |
| 190 Zone* zone = scope.main_zone(); |
189 Factory* factory = isolate->factory(); | 191 Factory* factory = isolate->factory(); |
190 | 192 |
191 ExpectedSnippet<0> snippets[] = { | 193 ExpectedSnippet<0> snippets[] = { |
192 {"return;", {factory->undefined_value()}}, | 194 {"return;", {factory->undefined_value()}}, |
193 {"return null;", {factory->null_value()}}, | 195 {"return null;", {factory->null_value()}}, |
194 {"return true;", {factory->true_value()}}, | 196 {"return true;", {factory->true_value()}}, |
195 {"return false;", {factory->false_value()}}, | 197 {"return false;", {factory->false_value()}}, |
196 {"return 0;", {factory->NewNumberFromInt(0)}}, | 198 {"return 0;", {factory->NewNumberFromInt(0)}}, |
197 {"return +1;", {factory->NewNumberFromInt(1)}}, | 199 {"return +1;", {factory->NewNumberFromInt(1)}}, |
198 {"return -1;", {factory->NewNumberFromInt(-1)}}, | 200 {"return -1;", {factory->NewNumberFromInt(-1)}}, |
199 {"return +127;", {factory->NewNumberFromInt(127)}}, | 201 {"return +127;", {factory->NewNumberFromInt(127)}}, |
200 {"return -128;", {factory->NewNumberFromInt(-128)}}, | 202 {"return -128;", {factory->NewNumberFromInt(-128)}}, |
201 {"return 0.001;", {factory->NewNumber(0.001)}}, | 203 {"return 0.001;", {factory->NewNumber(0.001)}}, |
202 {"return 3.7e-60;", {factory->NewNumber(3.7e-60)}}, | 204 {"return 3.7e-60;", {factory->NewNumber(3.7e-60)}}, |
203 {"return -3.7e60;", {factory->NewNumber(-3.7e60)}}, | 205 {"return -3.7e60;", {factory->NewNumber(-3.7e60)}}, |
204 {"return '';", {factory->NewStringFromStaticChars("")}}, | 206 {"return '';", {factory->NewStringFromStaticChars("")}}, |
205 {"return 'catfood';", {factory->NewStringFromStaticChars("catfood")}}, | 207 {"return 'catfood';", {factory->NewStringFromStaticChars("catfood")}}, |
206 {"return NaN;", {factory->nan_value()}}}; | 208 {"return NaN;", {factory->nan_value()}}}; |
207 | 209 |
208 for (size_t i = 0; i < arraysize(snippets); i++) { | 210 for (size_t i = 0; i < arraysize(snippets); i++) { |
209 ScopedVector<char> script(1024); | 211 ScopedVector<char> script(1024); |
210 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 212 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
211 snippets[i].code_snippet, kFunctionName); | 213 snippets[i].code_snippet, kFunctionName); |
212 | 214 |
213 BytecodeGraphTester tester(isolate, script.start()); | 215 BytecodeGraphTester tester(isolate, zone, script.start()); |
214 auto callable = tester.GetCallable<>(); | 216 auto callable = tester.GetCallable<>(); |
215 Handle<Object> return_value = callable().ToHandleChecked(); | 217 Handle<Object> return_value = callable().ToHandleChecked(); |
216 CHECK(return_value->SameValue(*snippets[i].return_value())); | 218 CHECK(return_value->SameValue(*snippets[i].return_value())); |
217 } | 219 } |
218 } | 220 } |
219 | 221 |
220 | 222 |
221 TEST(BytecodeGraphBuilderPrimitiveExpressions) { | 223 TEST(BytecodeGraphBuilderPrimitiveExpressions) { |
222 HandleAndZoneScope scope; | 224 HandleAndZoneScope scope; |
223 Isolate* isolate = scope.main_isolate(); | 225 Isolate* isolate = scope.main_isolate(); |
| 226 Zone* zone = scope.main_zone(); |
224 Factory* factory = isolate->factory(); | 227 Factory* factory = isolate->factory(); |
225 | 228 |
226 ExpectedSnippet<0> snippets[] = { | 229 ExpectedSnippet<0> snippets[] = { |
227 {"return 1 + 1;", {factory->NewNumberFromInt(2)}}, | 230 {"return 1 + 1;", {factory->NewNumberFromInt(2)}}, |
228 {"return 20 - 30;", {factory->NewNumberFromInt(-10)}}, | 231 {"return 20 - 30;", {factory->NewNumberFromInt(-10)}}, |
229 {"return 4 * 100;", {factory->NewNumberFromInt(400)}}, | 232 {"return 4 * 100;", {factory->NewNumberFromInt(400)}}, |
230 {"return 100 / 5;", {factory->NewNumberFromInt(20)}}, | 233 {"return 100 / 5;", {factory->NewNumberFromInt(20)}}, |
231 {"return 25 % 7;", {factory->NewNumberFromInt(4)}}, | 234 {"return 25 % 7;", {factory->NewNumberFromInt(4)}}, |
232 }; | 235 }; |
233 | 236 |
234 for (size_t i = 0; i < arraysize(snippets); i++) { | 237 for (size_t i = 0; i < arraysize(snippets); i++) { |
235 ScopedVector<char> script(1024); | 238 ScopedVector<char> script(1024); |
236 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 239 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
237 snippets[i].code_snippet, kFunctionName); | 240 snippets[i].code_snippet, kFunctionName); |
238 | 241 |
239 BytecodeGraphTester tester(isolate, script.start()); | 242 BytecodeGraphTester tester(isolate, zone, script.start()); |
240 auto callable = tester.GetCallable<>(); | 243 auto callable = tester.GetCallable<>(); |
241 Handle<Object> return_value = callable().ToHandleChecked(); | 244 Handle<Object> return_value = callable().ToHandleChecked(); |
242 CHECK(return_value->SameValue(*snippets[i].return_value())); | 245 CHECK(return_value->SameValue(*snippets[i].return_value())); |
243 } | 246 } |
244 } | 247 } |
245 | 248 |
246 | 249 |
247 TEST(BytecodeGraphBuilderTwoParameterTests) { | 250 TEST(BytecodeGraphBuilderTwoParameterTests) { |
248 HandleAndZoneScope scope; | 251 HandleAndZoneScope scope; |
249 Isolate* isolate = scope.main_isolate(); | 252 Isolate* isolate = scope.main_isolate(); |
| 253 Zone* zone = scope.main_zone(); |
250 Factory* factory = isolate->factory(); | 254 Factory* factory = isolate->factory(); |
251 | 255 |
252 ExpectedSnippet<2> snippets[] = { | 256 ExpectedSnippet<2> snippets[] = { |
253 // Integers | 257 // Integers |
254 {"return p1 + p2;", | 258 {"return p1 + p2;", |
255 {factory->NewNumberFromInt(-70), factory->NewNumberFromInt(3), | 259 {factory->NewNumberFromInt(-70), factory->NewNumberFromInt(3), |
256 factory->NewNumberFromInt(-73)}}, | 260 factory->NewNumberFromInt(-73)}}, |
257 {"return p1 + p2 + 3;", | 261 {"return p1 + p2 + 3;", |
258 {factory->NewNumberFromInt(1139044), factory->NewNumberFromInt(300), | 262 {factory->NewNumberFromInt(1139044), factory->NewNumberFromInt(300), |
259 factory->NewNumberFromInt(1138741)}}, | 263 factory->NewNumberFromInt(1138741)}}, |
(...skipping 26 matching lines...) Expand all Loading... |
286 {"return p1 + p2;", | 290 {"return p1 + p2;", |
287 {factory->NewStringFromStaticChars("abcdef"), | 291 {factory->NewStringFromStaticChars("abcdef"), |
288 factory->NewStringFromStaticChars("abc"), | 292 factory->NewStringFromStaticChars("abc"), |
289 factory->NewStringFromStaticChars("def")}}}; | 293 factory->NewStringFromStaticChars("def")}}}; |
290 | 294 |
291 for (size_t i = 0; i < arraysize(snippets); i++) { | 295 for (size_t i = 0; i < arraysize(snippets); i++) { |
292 ScopedVector<char> script(1024); | 296 ScopedVector<char> script(1024); |
293 SNPrintF(script, "function %s(p1, p2) { %s }\n%s(0, 0);", kFunctionName, | 297 SNPrintF(script, "function %s(p1, p2) { %s }\n%s(0, 0);", kFunctionName, |
294 snippets[i].code_snippet, kFunctionName); | 298 snippets[i].code_snippet, kFunctionName); |
295 | 299 |
296 BytecodeGraphTester tester(isolate, script.start()); | 300 BytecodeGraphTester tester(isolate, zone, script.start()); |
297 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 301 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
298 Handle<Object> return_value = | 302 Handle<Object> return_value = |
299 callable(snippets[i].parameter(0), snippets[i].parameter(1)) | 303 callable(snippets[i].parameter(0), snippets[i].parameter(1)) |
300 .ToHandleChecked(); | 304 .ToHandleChecked(); |
301 CHECK(return_value->SameValue(*snippets[i].return_value())); | 305 CHECK(return_value->SameValue(*snippets[i].return_value())); |
302 } | 306 } |
303 } | 307 } |
304 | 308 |
305 | 309 |
306 TEST(BytecodeGraphBuilderNamedLoad) { | 310 TEST(BytecodeGraphBuilderNamedLoad) { |
307 HandleAndZoneScope scope; | 311 HandleAndZoneScope scope; |
308 Isolate* isolate = scope.main_isolate(); | 312 Isolate* isolate = scope.main_isolate(); |
| 313 Zone* zone = scope.main_zone(); |
309 Factory* factory = isolate->factory(); | 314 Factory* factory = isolate->factory(); |
310 | 315 |
311 ExpectedSnippet<1> snippets[] = { | 316 ExpectedSnippet<1> snippets[] = { |
312 {"return p1.val;", | 317 {"return p1.val;", |
313 {factory->NewNumberFromInt(10), | 318 {factory->NewNumberFromInt(10), |
314 BytecodeGraphTester::NewObject("({val : 10})")}}, | 319 BytecodeGraphTester::NewObject("({val : 10})")}}, |
315 {"return p1[\"name\"];", | 320 {"return p1[\"name\"];", |
316 {factory->NewStringFromStaticChars("abc"), | 321 {factory->NewStringFromStaticChars("abc"), |
317 BytecodeGraphTester::NewObject("({name : 'abc'})")}}, | 322 BytecodeGraphTester::NewObject("({name : 'abc'})")}}, |
318 {"'use strict'; return p1.val;", | 323 {"'use strict'; return p1.val;", |
(...skipping 10 matching lines...) Expand all Loading... |
329 "return p1.name;\n", | 334 "return p1.name;\n", |
330 {factory->NewStringFromStaticChars("abc"), | 335 {factory->NewStringFromStaticChars("abc"), |
331 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, | 336 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, |
332 }; | 337 }; |
333 | 338 |
334 for (size_t i = 0; i < arraysize(snippets); i++) { | 339 for (size_t i = 0; i < arraysize(snippets); i++) { |
335 ScopedVector<char> script(2048); | 340 ScopedVector<char> script(2048); |
336 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, | 341 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, |
337 snippets[i].code_snippet, kFunctionName); | 342 snippets[i].code_snippet, kFunctionName); |
338 | 343 |
339 BytecodeGraphTester tester(isolate, script.start()); | 344 BytecodeGraphTester tester(isolate, zone, script.start()); |
340 auto callable = tester.GetCallable<Handle<Object>>(); | 345 auto callable = tester.GetCallable<Handle<Object>>(); |
341 Handle<Object> return_value = | 346 Handle<Object> return_value = |
342 callable(snippets[i].parameter(0)).ToHandleChecked(); | 347 callable(snippets[i].parameter(0)).ToHandleChecked(); |
343 CHECK(return_value->SameValue(*snippets[i].return_value())); | 348 CHECK(return_value->SameValue(*snippets[i].return_value())); |
344 } | 349 } |
345 } | 350 } |
346 | 351 |
347 | 352 |
348 TEST(BytecodeGraphBuilderKeyedLoad) { | 353 TEST(BytecodeGraphBuilderKeyedLoad) { |
349 HandleAndZoneScope scope; | 354 HandleAndZoneScope scope; |
350 Isolate* isolate = scope.main_isolate(); | 355 Isolate* isolate = scope.main_isolate(); |
| 356 Zone* zone = scope.main_zone(); |
351 Factory* factory = isolate->factory(); | 357 Factory* factory = isolate->factory(); |
352 | 358 |
353 ExpectedSnippet<2> snippets[] = { | 359 ExpectedSnippet<2> snippets[] = { |
354 {"return p1[p2];", | 360 {"return p1[p2];", |
355 {factory->NewNumberFromInt(10), | 361 {factory->NewNumberFromInt(10), |
356 BytecodeGraphTester::NewObject("({val : 10})"), | 362 BytecodeGraphTester::NewObject("({val : 10})"), |
357 factory->NewStringFromStaticChars("val")}}, | 363 factory->NewStringFromStaticChars("val")}}, |
358 {"return p1[100];", | 364 {"return p1[100];", |
359 {factory->NewStringFromStaticChars("abc"), | 365 {factory->NewStringFromStaticChars("abc"), |
360 BytecodeGraphTester::NewObject("({100 : 'abc'})"), | 366 BytecodeGraphTester::NewObject("({100 : 'abc'})"), |
(...skipping 23 matching lines...) Expand all Loading... |
384 {factory->NewStringFromStaticChars("abc"), | 390 {factory->NewStringFromStaticChars("abc"), |
385 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"), | 391 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"), |
386 factory->NewNumberFromInt(100)}}, | 392 factory->NewNumberFromInt(100)}}, |
387 }; | 393 }; |
388 | 394 |
389 for (size_t i = 0; i < arraysize(snippets); i++) { | 395 for (size_t i = 0; i < arraysize(snippets); i++) { |
390 ScopedVector<char> script(2048); | 396 ScopedVector<char> script(2048); |
391 SNPrintF(script, "function %s(p1, p2) { %s };\n%s(0);", kFunctionName, | 397 SNPrintF(script, "function %s(p1, p2) { %s };\n%s(0);", kFunctionName, |
392 snippets[i].code_snippet, kFunctionName); | 398 snippets[i].code_snippet, kFunctionName); |
393 | 399 |
394 BytecodeGraphTester tester(isolate, script.start()); | 400 BytecodeGraphTester tester(isolate, zone, script.start()); |
395 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 401 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
396 Handle<Object> return_value = | 402 Handle<Object> return_value = |
397 callable(snippets[i].parameter(0), snippets[i].parameter(1)) | 403 callable(snippets[i].parameter(0), snippets[i].parameter(1)) |
398 .ToHandleChecked(); | 404 .ToHandleChecked(); |
399 CHECK(return_value->SameValue(*snippets[i].return_value())); | 405 CHECK(return_value->SameValue(*snippets[i].return_value())); |
400 } | 406 } |
401 } | 407 } |
402 | 408 |
403 void TestBytecodeGraphBuilderNamedStore(size_t shard) { | 409 void TestBytecodeGraphBuilderNamedStore(size_t shard) { |
404 HandleAndZoneScope scope; | 410 HandleAndZoneScope scope; |
405 Isolate* isolate = scope.main_isolate(); | 411 Isolate* isolate = scope.main_isolate(); |
| 412 Zone* zone = scope.main_zone(); |
406 Factory* factory = isolate->factory(); | 413 Factory* factory = isolate->factory(); |
407 | 414 |
408 ExpectedSnippet<1> snippets[] = { | 415 ExpectedSnippet<1> snippets[] = { |
409 {"return p1.val = 20;", | 416 {"return p1.val = 20;", |
410 {factory->NewNumberFromInt(20), | 417 {factory->NewNumberFromInt(20), |
411 BytecodeGraphTester::NewObject("({val : 10})")}}, | 418 BytecodeGraphTester::NewObject("({val : 10})")}}, |
412 {"p1.type = 'int'; return p1.type;", | 419 {"p1.type = 'int'; return p1.type;", |
413 {factory->NewStringFromStaticChars("int"), | 420 {factory->NewStringFromStaticChars("int"), |
414 BytecodeGraphTester::NewObject("({val : 10})")}}, | 421 BytecodeGraphTester::NewObject("({val : 10})")}}, |
415 {"p1.name = 'def'; return p1[\"name\"];", | 422 {"p1.name = 'def'; return p1[\"name\"];", |
(...skipping 17 matching lines...) Expand all Loading... |
433 {factory->NewStringFromStaticChars("def"), | 440 {factory->NewStringFromStaticChars("def"), |
434 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, | 441 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, |
435 }; | 442 }; |
436 | 443 |
437 for (size_t i = 0; i < arraysize(snippets); i++) { | 444 for (size_t i = 0; i < arraysize(snippets); i++) { |
438 if ((i % 2) != shard) continue; | 445 if ((i % 2) != shard) continue; |
439 ScopedVector<char> script(3072); | 446 ScopedVector<char> script(3072); |
440 SNPrintF(script, "function %s(p1) { %s };\n%s({});", kFunctionName, | 447 SNPrintF(script, "function %s(p1) { %s };\n%s({});", kFunctionName, |
441 snippets[i].code_snippet, kFunctionName); | 448 snippets[i].code_snippet, kFunctionName); |
442 | 449 |
443 BytecodeGraphTester tester(isolate, script.start()); | 450 BytecodeGraphTester tester(isolate, zone, script.start()); |
444 auto callable = tester.GetCallable<Handle<Object>>(); | 451 auto callable = tester.GetCallable<Handle<Object>>(); |
445 Handle<Object> return_value = | 452 Handle<Object> return_value = |
446 callable(snippets[i].parameter(0)).ToHandleChecked(); | 453 callable(snippets[i].parameter(0)).ToHandleChecked(); |
447 CHECK(return_value->SameValue(*snippets[i].return_value())); | 454 CHECK(return_value->SameValue(*snippets[i].return_value())); |
448 } | 455 } |
449 } | 456 } |
450 | 457 |
451 SHARD_TEST_BY_2(BytecodeGraphBuilderNamedStore) | 458 SHARD_TEST_BY_2(BytecodeGraphBuilderNamedStore) |
452 | 459 |
453 void TestBytecodeGraphBuilderKeyedStore(size_t shard) { | 460 void TestBytecodeGraphBuilderKeyedStore(size_t shard) { |
454 HandleAndZoneScope scope; | 461 HandleAndZoneScope scope; |
455 Isolate* isolate = scope.main_isolate(); | 462 Isolate* isolate = scope.main_isolate(); |
| 463 Zone* zone = scope.main_zone(); |
456 Factory* factory = isolate->factory(); | 464 Factory* factory = isolate->factory(); |
457 | 465 |
458 ExpectedSnippet<2> snippets[] = { | 466 ExpectedSnippet<2> snippets[] = { |
459 {"p1[p2] = 20; return p1[p2];", | 467 {"p1[p2] = 20; return p1[p2];", |
460 {factory->NewNumberFromInt(20), | 468 {factory->NewNumberFromInt(20), |
461 BytecodeGraphTester::NewObject("({val : 10})"), | 469 BytecodeGraphTester::NewObject("({val : 10})"), |
462 factory->NewStringFromStaticChars("val")}}, | 470 factory->NewStringFromStaticChars("val")}}, |
463 {"return p1[100] = 'def';", | 471 {"return p1[100] = 'def';", |
464 {factory->NewStringFromStaticChars("def"), | 472 {factory->NewStringFromStaticChars("def"), |
465 BytecodeGraphTester::NewObject("({100 : 'abc'})"), | 473 BytecodeGraphTester::NewObject("({100 : 'abc'})"), |
(...skipping 25 matching lines...) Expand all Loading... |
491 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"), | 499 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"), |
492 factory->NewNumberFromInt(100)}}, | 500 factory->NewNumberFromInt(100)}}, |
493 }; | 501 }; |
494 | 502 |
495 for (size_t i = 0; i < arraysize(snippets); i++) { | 503 for (size_t i = 0; i < arraysize(snippets); i++) { |
496 if ((i % 2) != shard) continue; | 504 if ((i % 2) != shard) continue; |
497 ScopedVector<char> script(2048); | 505 ScopedVector<char> script(2048); |
498 SNPrintF(script, "function %s(p1, p2) { %s };\n%s({});", kFunctionName, | 506 SNPrintF(script, "function %s(p1, p2) { %s };\n%s({});", kFunctionName, |
499 snippets[i].code_snippet, kFunctionName); | 507 snippets[i].code_snippet, kFunctionName); |
500 | 508 |
501 BytecodeGraphTester tester(isolate, script.start()); | 509 BytecodeGraphTester tester(isolate, zone, script.start()); |
502 auto callable = tester.GetCallable<Handle<Object>>(); | 510 auto callable = tester.GetCallable<Handle<Object>>(); |
503 Handle<Object> return_value = | 511 Handle<Object> return_value = |
504 callable(snippets[i].parameter(0)).ToHandleChecked(); | 512 callable(snippets[i].parameter(0)).ToHandleChecked(); |
505 CHECK(return_value->SameValue(*snippets[i].return_value())); | 513 CHECK(return_value->SameValue(*snippets[i].return_value())); |
506 } | 514 } |
507 } | 515 } |
508 | 516 |
509 SHARD_TEST_BY_2(BytecodeGraphBuilderKeyedStore) | 517 SHARD_TEST_BY_2(BytecodeGraphBuilderKeyedStore) |
510 | 518 |
511 TEST(BytecodeGraphBuilderPropertyCall) { | 519 TEST(BytecodeGraphBuilderPropertyCall) { |
512 HandleAndZoneScope scope; | 520 HandleAndZoneScope scope; |
513 Isolate* isolate = scope.main_isolate(); | 521 Isolate* isolate = scope.main_isolate(); |
| 522 Zone* zone = scope.main_zone(); |
514 Factory* factory = isolate->factory(); | 523 Factory* factory = isolate->factory(); |
515 | 524 |
516 ExpectedSnippet<1> snippets[] = { | 525 ExpectedSnippet<1> snippets[] = { |
517 {"return p1.func();", | 526 {"return p1.func();", |
518 {factory->NewNumberFromInt(25), | 527 {factory->NewNumberFromInt(25), |
519 BytecodeGraphTester::NewObject("({func() { return 25; }})")}}, | 528 BytecodeGraphTester::NewObject("({func() { return 25; }})")}}, |
520 {"return p1.func('abc');", | 529 {"return p1.func('abc');", |
521 {factory->NewStringFromStaticChars("abc"), | 530 {factory->NewStringFromStaticChars("abc"), |
522 BytecodeGraphTester::NewObject("({func(a) { return a; }})")}}, | 531 BytecodeGraphTester::NewObject("({func(a) { return a; }})")}}, |
523 {"return p1.func(1, 2, 3, 4, 5, 6, 7, 8);", | 532 {"return p1.func(1, 2, 3, 4, 5, 6, 7, 8);", |
524 {factory->NewNumberFromInt(36), | 533 {factory->NewNumberFromInt(36), |
525 BytecodeGraphTester::NewObject( | 534 BytecodeGraphTester::NewObject( |
526 "({func(a, b, c, d, e, f, g, h) {\n" | 535 "({func(a, b, c, d, e, f, g, h) {\n" |
527 " return a + b + c + d + e + f + g + h;}})")}}, | 536 " return a + b + c + d + e + f + g + h;}})")}}, |
528 }; | 537 }; |
529 | 538 |
530 for (size_t i = 0; i < arraysize(snippets); i++) { | 539 for (size_t i = 0; i < arraysize(snippets); i++) { |
531 ScopedVector<char> script(2048); | 540 ScopedVector<char> script(2048); |
532 SNPrintF(script, "function %s(p1) { %s };\n%s({func() {}});", kFunctionName, | 541 SNPrintF(script, "function %s(p1) { %s };\n%s({func() {}});", kFunctionName, |
533 snippets[i].code_snippet, kFunctionName); | 542 snippets[i].code_snippet, kFunctionName); |
534 | 543 |
535 BytecodeGraphTester tester(isolate, script.start()); | 544 BytecodeGraphTester tester(isolate, zone, script.start()); |
536 auto callable = tester.GetCallable<Handle<Object>>(); | 545 auto callable = tester.GetCallable<Handle<Object>>(); |
537 Handle<Object> return_value = | 546 Handle<Object> return_value = |
538 callable(snippets[i].parameter(0)).ToHandleChecked(); | 547 callable(snippets[i].parameter(0)).ToHandleChecked(); |
539 CHECK(return_value->SameValue(*snippets[i].return_value())); | 548 CHECK(return_value->SameValue(*snippets[i].return_value())); |
540 } | 549 } |
541 } | 550 } |
542 | 551 |
543 | 552 |
544 TEST(BytecodeGraphBuilderCallNew) { | 553 TEST(BytecodeGraphBuilderCallNew) { |
545 HandleAndZoneScope scope; | 554 HandleAndZoneScope scope; |
546 Isolate* isolate = scope.main_isolate(); | 555 Isolate* isolate = scope.main_isolate(); |
| 556 Zone* zone = scope.main_zone(); |
547 Factory* factory = isolate->factory(); | 557 Factory* factory = isolate->factory(); |
548 | 558 |
549 ExpectedSnippet<0> snippets[] = { | 559 ExpectedSnippet<0> snippets[] = { |
550 {"function counter() { this.count = 20; }\n" | 560 {"function counter() { this.count = 20; }\n" |
551 "function f() {\n" | 561 "function f() {\n" |
552 " var c = new counter();\n" | 562 " var c = new counter();\n" |
553 " return c.count;\n" | 563 " return c.count;\n" |
554 "}; f()", | 564 "}; f()", |
555 {factory->NewNumberFromInt(20)}}, | 565 {factory->NewNumberFromInt(20)}}, |
556 {"function counter(arg0) { this.count = 17; this.x = arg0; }\n" | 566 {"function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
557 "function f() {\n" | 567 "function f() {\n" |
558 " var c = new counter(6);\n" | 568 " var c = new counter(6);\n" |
559 " return c.count + c.x;\n" | 569 " return c.count + c.x;\n" |
560 "}; f()", | 570 "}; f()", |
561 {factory->NewNumberFromInt(23)}}, | 571 {factory->NewNumberFromInt(23)}}, |
562 {"function counter(arg0, arg1) {\n" | 572 {"function counter(arg0, arg1) {\n" |
563 " this.count = 17; this.x = arg0; this.y = arg1;\n" | 573 " this.count = 17; this.x = arg0; this.y = arg1;\n" |
564 "}\n" | 574 "}\n" |
565 "function f() {\n" | 575 "function f() {\n" |
566 " var c = new counter(3, 5);\n" | 576 " var c = new counter(3, 5);\n" |
567 " return c.count + c.x + c.y;\n" | 577 " return c.count + c.x + c.y;\n" |
568 "}; f()", | 578 "}; f()", |
569 {factory->NewNumberFromInt(25)}}, | 579 {factory->NewNumberFromInt(25)}}, |
570 }; | 580 }; |
571 | 581 |
572 for (size_t i = 0; i < arraysize(snippets); i++) { | 582 for (size_t i = 0; i < arraysize(snippets); i++) { |
573 BytecodeGraphTester tester(isolate, snippets[i].code_snippet); | 583 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
574 auto callable = tester.GetCallable<>(); | 584 auto callable = tester.GetCallable<>(); |
575 Handle<Object> return_value = callable().ToHandleChecked(); | 585 Handle<Object> return_value = callable().ToHandleChecked(); |
576 CHECK(return_value->SameValue(*snippets[i].return_value())); | 586 CHECK(return_value->SameValue(*snippets[i].return_value())); |
577 } | 587 } |
578 } | 588 } |
579 | 589 |
580 | 590 |
581 TEST(BytecodeGraphBuilderCreateClosure) { | 591 TEST(BytecodeGraphBuilderCreateClosure) { |
582 HandleAndZoneScope scope; | 592 HandleAndZoneScope scope; |
583 Isolate* isolate = scope.main_isolate(); | 593 Isolate* isolate = scope.main_isolate(); |
| 594 Zone* zone = scope.main_zone(); |
584 Factory* factory = isolate->factory(); | 595 Factory* factory = isolate->factory(); |
585 | 596 |
586 ExpectedSnippet<0> snippets[] = { | 597 ExpectedSnippet<0> snippets[] = { |
587 {"function f() {\n" | 598 {"function f() {\n" |
588 " function counter() { this.count = 20; }\n" | 599 " function counter() { this.count = 20; }\n" |
589 " var c = new counter();\n" | 600 " var c = new counter();\n" |
590 " return c.count;\n" | 601 " return c.count;\n" |
591 "}; f()", | 602 "}; f()", |
592 {factory->NewNumberFromInt(20)}}, | 603 {factory->NewNumberFromInt(20)}}, |
593 {"function f() {\n" | 604 {"function f() {\n" |
594 " function counter(arg0) { this.count = 17; this.x = arg0; }\n" | 605 " function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
595 " var c = new counter(6);\n" | 606 " var c = new counter(6);\n" |
596 " return c.count + c.x;\n" | 607 " return c.count + c.x;\n" |
597 "}; f()", | 608 "}; f()", |
598 {factory->NewNumberFromInt(23)}}, | 609 {factory->NewNumberFromInt(23)}}, |
599 {"function f() {\n" | 610 {"function f() {\n" |
600 " function counter(arg0, arg1) {\n" | 611 " function counter(arg0, arg1) {\n" |
601 " this.count = 17; this.x = arg0; this.y = arg1;\n" | 612 " this.count = 17; this.x = arg0; this.y = arg1;\n" |
602 " }\n" | 613 " }\n" |
603 " var c = new counter(3, 5);\n" | 614 " var c = new counter(3, 5);\n" |
604 " return c.count + c.x + c.y;\n" | 615 " return c.count + c.x + c.y;\n" |
605 "}; f()", | 616 "}; f()", |
606 {factory->NewNumberFromInt(25)}}, | 617 {factory->NewNumberFromInt(25)}}, |
607 }; | 618 }; |
608 | 619 |
609 for (size_t i = 0; i < arraysize(snippets); i++) { | 620 for (size_t i = 0; i < arraysize(snippets); i++) { |
610 BytecodeGraphTester tester(isolate, snippets[i].code_snippet); | 621 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
611 auto callable = tester.GetCallable<>(); | 622 auto callable = tester.GetCallable<>(); |
612 Handle<Object> return_value = callable().ToHandleChecked(); | 623 Handle<Object> return_value = callable().ToHandleChecked(); |
613 CHECK(return_value->SameValue(*snippets[i].return_value())); | 624 CHECK(return_value->SameValue(*snippets[i].return_value())); |
614 } | 625 } |
615 } | 626 } |
616 | 627 |
617 | 628 |
618 TEST(BytecodeGraphBuilderCallRuntime) { | 629 TEST(BytecodeGraphBuilderCallRuntime) { |
619 HandleAndZoneScope scope; | 630 HandleAndZoneScope scope; |
620 Isolate* isolate = scope.main_isolate(); | 631 Isolate* isolate = scope.main_isolate(); |
| 632 Zone* zone = scope.main_zone(); |
621 Factory* factory = isolate->factory(); | 633 Factory* factory = isolate->factory(); |
622 | 634 |
623 ExpectedSnippet<1> snippets[] = { | 635 ExpectedSnippet<1> snippets[] = { |
624 {"function f(arg0) { return %MaxSmi(); }\nf()", | 636 {"function f(arg0) { return %MaxSmi(); }\nf()", |
625 {factory->NewNumberFromInt(Smi::kMaxValue), factory->undefined_value()}}, | 637 {factory->NewNumberFromInt(Smi::kMaxValue), factory->undefined_value()}}, |
626 {"function f(arg0) { return %IsArray(arg0) }\nf(undefined)", | 638 {"function f(arg0) { return %IsArray(arg0) }\nf(undefined)", |
627 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, | 639 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
628 {"function f(arg0) { return %Add(arg0, 2) }\nf(1)", | 640 {"function f(arg0) { return %Add(arg0, 2) }\nf(1)", |
629 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(3)}}, | 641 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(3)}}, |
630 {"function f(arg0) { return %spread_arguments(arg0).length }\nf([])", | 642 {"function f(arg0) { return %spread_arguments(arg0).length }\nf([])", |
631 {factory->NewNumberFromInt(3), | 643 {factory->NewNumberFromInt(3), |
632 BytecodeGraphTester::NewObject("[1, 2, 3]")}}, | 644 BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
633 }; | 645 }; |
634 | 646 |
635 for (size_t i = 0; i < arraysize(snippets); i++) { | 647 for (size_t i = 0; i < arraysize(snippets); i++) { |
636 BytecodeGraphTester tester(isolate, snippets[i].code_snippet); | 648 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
637 auto callable = tester.GetCallable<Handle<Object>>(); | 649 auto callable = tester.GetCallable<Handle<Object>>(); |
638 Handle<Object> return_value = | 650 Handle<Object> return_value = |
639 callable(snippets[i].parameter(0)).ToHandleChecked(); | 651 callable(snippets[i].parameter(0)).ToHandleChecked(); |
640 CHECK(return_value->SameValue(*snippets[i].return_value())); | 652 CHECK(return_value->SameValue(*snippets[i].return_value())); |
641 } | 653 } |
642 } | 654 } |
643 | 655 |
644 TEST(BytecodeGraphBuilderInvokeIntrinsic) { | 656 TEST(BytecodeGraphBuilderInvokeIntrinsic) { |
645 HandleAndZoneScope scope; | 657 HandleAndZoneScope scope; |
646 Isolate* isolate = scope.main_isolate(); | 658 Isolate* isolate = scope.main_isolate(); |
| 659 Zone* zone = scope.main_zone(); |
647 Factory* factory = isolate->factory(); | 660 Factory* factory = isolate->factory(); |
648 | 661 |
649 ExpectedSnippet<1> snippets[] = { | 662 ExpectedSnippet<1> snippets[] = { |
650 {"function f(arg0) { return %_IsJSReceiver(arg0); }\nf()", | 663 {"function f(arg0) { return %_IsJSReceiver(arg0); }\nf()", |
651 {factory->false_value(), factory->NewNumberFromInt(1)}}, | 664 {factory->false_value(), factory->NewNumberFromInt(1)}}, |
652 {"function f(arg0) { return %_IsArray(arg0) }\nf(undefined)", | 665 {"function f(arg0) { return %_IsArray(arg0) }\nf(undefined)", |
653 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, | 666 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, |
654 }; | 667 }; |
655 | 668 |
656 for (size_t i = 0; i < arraysize(snippets); i++) { | 669 for (size_t i = 0; i < arraysize(snippets); i++) { |
657 BytecodeGraphTester tester(isolate, snippets[i].code_snippet); | 670 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
658 auto callable = tester.GetCallable<Handle<Object>>(); | 671 auto callable = tester.GetCallable<Handle<Object>>(); |
659 Handle<Object> return_value = | 672 Handle<Object> return_value = |
660 callable(snippets[i].parameter(0)).ToHandleChecked(); | 673 callable(snippets[i].parameter(0)).ToHandleChecked(); |
661 CHECK(return_value->SameValue(*snippets[i].return_value())); | 674 CHECK(return_value->SameValue(*snippets[i].return_value())); |
662 } | 675 } |
663 } | 676 } |
664 | 677 |
665 void TestBytecodeGraphBuilderGlobals(size_t shard) { | 678 void TestBytecodeGraphBuilderGlobals(size_t shard) { |
666 HandleAndZoneScope scope; | 679 HandleAndZoneScope scope; |
667 Isolate* isolate = scope.main_isolate(); | 680 Isolate* isolate = scope.main_isolate(); |
| 681 Zone* zone = scope.main_zone(); |
668 Factory* factory = isolate->factory(); | 682 Factory* factory = isolate->factory(); |
669 | 683 |
670 ExpectedSnippet<0> snippets[] = { | 684 ExpectedSnippet<0> snippets[] = { |
671 {"var global = 321;\n function f() { return global; };\n f();", | 685 {"var global = 321;\n function f() { return global; };\n f();", |
672 {factory->NewNumberFromInt(321)}}, | 686 {factory->NewNumberFromInt(321)}}, |
673 {"var global = 321;\n" | 687 {"var global = 321;\n" |
674 "function f() { global = 123; return global };\n f();", | 688 "function f() { global = 123; return global };\n f();", |
675 {factory->NewNumberFromInt(123)}}, | 689 {factory->NewNumberFromInt(123)}}, |
676 {"var global = function() { return 'abc'};\n" | 690 {"var global = function() { return 'abc'};\n" |
677 "function f() { return global(); };\n f();", | 691 "function f() { return global(); };\n f();", |
(...skipping 18 matching lines...) Expand all Loading... |
696 {factory->NewStringFromStaticChars("xyz")}}, | 710 {factory->NewStringFromStaticChars("xyz")}}, |
697 {"function f() { return typeof(undeclared_var); }\n; f();\n", | 711 {"function f() { return typeof(undeclared_var); }\n; f();\n", |
698 {factory->NewStringFromStaticChars("undefined")}}, | 712 {factory->NewStringFromStaticChars("undefined")}}, |
699 {"var defined_var = 10; function f() { return typeof(defined_var); }\n; " | 713 {"var defined_var = 10; function f() { return typeof(defined_var); }\n; " |
700 "f();\n", | 714 "f();\n", |
701 {factory->NewStringFromStaticChars("number")}}, | 715 {factory->NewStringFromStaticChars("number")}}, |
702 }; | 716 }; |
703 | 717 |
704 for (size_t i = 0; i < arraysize(snippets); i++) { | 718 for (size_t i = 0; i < arraysize(snippets); i++) { |
705 if ((i % 2) != shard) continue; | 719 if ((i % 2) != shard) continue; |
706 BytecodeGraphTester tester(isolate, snippets[i].code_snippet); | 720 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
707 auto callable = tester.GetCallable<>(); | 721 auto callable = tester.GetCallable<>(); |
708 Handle<Object> return_value = callable().ToHandleChecked(); | 722 Handle<Object> return_value = callable().ToHandleChecked(); |
709 CHECK(return_value->SameValue(*snippets[i].return_value())); | 723 CHECK(return_value->SameValue(*snippets[i].return_value())); |
710 } | 724 } |
711 } | 725 } |
712 | 726 |
713 SHARD_TEST_BY_2(BytecodeGraphBuilderGlobals) | 727 SHARD_TEST_BY_2(BytecodeGraphBuilderGlobals) |
714 | 728 |
715 TEST(BytecodeGraphBuilderToObject) { | 729 TEST(BytecodeGraphBuilderToObject) { |
716 // TODO(mythria): tests for ToObject. Needs ForIn. | 730 // TODO(mythria): tests for ToObject. Needs ForIn. |
717 } | 731 } |
718 | 732 |
719 | 733 |
720 TEST(BytecodeGraphBuilderToName) { | 734 TEST(BytecodeGraphBuilderToName) { |
721 HandleAndZoneScope scope; | 735 HandleAndZoneScope scope; |
722 Isolate* isolate = scope.main_isolate(); | 736 Isolate* isolate = scope.main_isolate(); |
| 737 Zone* zone = scope.main_zone(); |
723 Factory* factory = isolate->factory(); | 738 Factory* factory = isolate->factory(); |
724 | 739 |
725 ExpectedSnippet<0> snippets[] = { | 740 ExpectedSnippet<0> snippets[] = { |
726 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", | 741 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", |
727 {factory->NewNumberFromInt(10)}}, | 742 {factory->NewNumberFromInt(10)}}, |
728 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", | 743 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", |
729 {factory->NewNumberFromInt(10)}}, | 744 {factory->NewNumberFromInt(10)}}, |
730 {"var a = 20; var obj = {[a] : 10}; return obj[20];", | 745 {"var a = 20; var obj = {[a] : 10}; return obj[20];", |
731 {factory->NewNumberFromInt(10)}}, | 746 {factory->NewNumberFromInt(10)}}, |
732 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", | 747 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", |
(...skipping 12 matching lines...) Expand all Loading... |
745 "var obj = {[a] : 10};\n" | 760 "var obj = {[a] : 10};\n" |
746 "return obj.x;", | 761 "return obj.x;", |
747 {factory->NewNumberFromInt(10)}}, | 762 {factory->NewNumberFromInt(10)}}, |
748 }; | 763 }; |
749 | 764 |
750 for (size_t i = 0; i < arraysize(snippets); i++) { | 765 for (size_t i = 0; i < arraysize(snippets); i++) { |
751 ScopedVector<char> script(1024); | 766 ScopedVector<char> script(1024); |
752 SNPrintF(script, "function %s() { %s }\n%s({});", kFunctionName, | 767 SNPrintF(script, "function %s() { %s }\n%s({});", kFunctionName, |
753 snippets[i].code_snippet, kFunctionName); | 768 snippets[i].code_snippet, kFunctionName); |
754 | 769 |
755 BytecodeGraphTester tester(isolate, script.start()); | 770 BytecodeGraphTester tester(isolate, zone, script.start()); |
756 auto callable = tester.GetCallable<>(); | 771 auto callable = tester.GetCallable<>(); |
757 Handle<Object> return_value = callable().ToHandleChecked(); | 772 Handle<Object> return_value = callable().ToHandleChecked(); |
758 CHECK(return_value->SameValue(*snippets[i].return_value())); | 773 CHECK(return_value->SameValue(*snippets[i].return_value())); |
759 } | 774 } |
760 } | 775 } |
761 | 776 |
762 | 777 |
763 TEST(BytecodeGraphBuilderLogicalNot) { | 778 TEST(BytecodeGraphBuilderLogicalNot) { |
764 HandleAndZoneScope scope; | 779 HandleAndZoneScope scope; |
765 Isolate* isolate = scope.main_isolate(); | 780 Isolate* isolate = scope.main_isolate(); |
| 781 Zone* zone = scope.main_zone(); |
766 Factory* factory = isolate->factory(); | 782 Factory* factory = isolate->factory(); |
767 | 783 |
768 ExpectedSnippet<1> snippets[] = { | 784 ExpectedSnippet<1> snippets[] = { |
769 {"return !p1;", | 785 {"return !p1;", |
770 {factory->false_value(), | 786 {factory->false_value(), |
771 BytecodeGraphTester::NewObject("({val : 10})")}}, | 787 BytecodeGraphTester::NewObject("({val : 10})")}}, |
772 {"return !p1;", {factory->true_value(), factory->NewNumberFromInt(0)}}, | 788 {"return !p1;", {factory->true_value(), factory->NewNumberFromInt(0)}}, |
773 {"return !p1;", {factory->true_value(), factory->undefined_value()}}, | 789 {"return !p1;", {factory->true_value(), factory->undefined_value()}}, |
774 {"return !p1;", {factory->false_value(), factory->NewNumberFromInt(10)}}, | 790 {"return !p1;", {factory->false_value(), factory->NewNumberFromInt(10)}}, |
775 {"return !p1;", {factory->false_value(), factory->true_value()}}, | 791 {"return !p1;", {factory->false_value(), factory->true_value()}}, |
776 {"return !p1;", | 792 {"return !p1;", |
777 {factory->false_value(), factory->NewStringFromStaticChars("abc")}}, | 793 {factory->false_value(), factory->NewStringFromStaticChars("abc")}}, |
778 }; | 794 }; |
779 | 795 |
780 for (size_t i = 0; i < arraysize(snippets); i++) { | 796 for (size_t i = 0; i < arraysize(snippets); i++) { |
781 ScopedVector<char> script(1024); | 797 ScopedVector<char> script(1024); |
782 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, | 798 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, |
783 snippets[i].code_snippet, kFunctionName); | 799 snippets[i].code_snippet, kFunctionName); |
784 | 800 |
785 BytecodeGraphTester tester(isolate, script.start()); | 801 BytecodeGraphTester tester(isolate, zone, script.start()); |
786 auto callable = tester.GetCallable<Handle<Object>>(); | 802 auto callable = tester.GetCallable<Handle<Object>>(); |
787 Handle<Object> return_value = | 803 Handle<Object> return_value = |
788 callable(snippets[i].parameter(0)).ToHandleChecked(); | 804 callable(snippets[i].parameter(0)).ToHandleChecked(); |
789 CHECK(return_value->SameValue(*snippets[i].return_value())); | 805 CHECK(return_value->SameValue(*snippets[i].return_value())); |
790 } | 806 } |
791 } | 807 } |
792 | 808 |
793 | 809 |
794 TEST(BytecodeGraphBuilderTypeOf) { | 810 TEST(BytecodeGraphBuilderTypeOf) { |
795 HandleAndZoneScope scope; | 811 HandleAndZoneScope scope; |
796 Isolate* isolate = scope.main_isolate(); | 812 Isolate* isolate = scope.main_isolate(); |
| 813 Zone* zone = scope.main_zone(); |
797 Factory* factory = isolate->factory(); | 814 Factory* factory = isolate->factory(); |
798 | 815 |
799 ExpectedSnippet<1> snippets[] = { | 816 ExpectedSnippet<1> snippets[] = { |
800 {"return typeof p1;", | 817 {"return typeof p1;", |
801 {factory->NewStringFromStaticChars("object"), | 818 {factory->NewStringFromStaticChars("object"), |
802 BytecodeGraphTester::NewObject("({val : 10})")}}, | 819 BytecodeGraphTester::NewObject("({val : 10})")}}, |
803 {"return typeof p1;", | 820 {"return typeof p1;", |
804 {factory->NewStringFromStaticChars("undefined"), | 821 {factory->NewStringFromStaticChars("undefined"), |
805 factory->undefined_value()}}, | 822 factory->undefined_value()}}, |
806 {"return typeof p1;", | 823 {"return typeof p1;", |
807 {factory->NewStringFromStaticChars("number"), | 824 {factory->NewStringFromStaticChars("number"), |
808 factory->NewNumberFromInt(10)}}, | 825 factory->NewNumberFromInt(10)}}, |
809 {"return typeof p1;", | 826 {"return typeof p1;", |
810 {factory->NewStringFromStaticChars("boolean"), factory->true_value()}}, | 827 {factory->NewStringFromStaticChars("boolean"), factory->true_value()}}, |
811 {"return typeof p1;", | 828 {"return typeof p1;", |
812 {factory->NewStringFromStaticChars("string"), | 829 {factory->NewStringFromStaticChars("string"), |
813 factory->NewStringFromStaticChars("abc")}}, | 830 factory->NewStringFromStaticChars("abc")}}, |
814 }; | 831 }; |
815 | 832 |
816 for (size_t i = 0; i < arraysize(snippets); i++) { | 833 for (size_t i = 0; i < arraysize(snippets); i++) { |
817 ScopedVector<char> script(1024); | 834 ScopedVector<char> script(1024); |
818 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, | 835 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, |
819 snippets[i].code_snippet, kFunctionName); | 836 snippets[i].code_snippet, kFunctionName); |
820 | 837 |
821 BytecodeGraphTester tester(isolate, script.start()); | 838 BytecodeGraphTester tester(isolate, zone, script.start()); |
822 auto callable = tester.GetCallable<Handle<Object>>(); | 839 auto callable = tester.GetCallable<Handle<Object>>(); |
823 Handle<Object> return_value = | 840 Handle<Object> return_value = |
824 callable(snippets[i].parameter(0)).ToHandleChecked(); | 841 callable(snippets[i].parameter(0)).ToHandleChecked(); |
825 CHECK(return_value->SameValue(*snippets[i].return_value())); | 842 CHECK(return_value->SameValue(*snippets[i].return_value())); |
826 } | 843 } |
827 } | 844 } |
828 | 845 |
829 | 846 |
830 TEST(BytecodeGraphBuilderCountOperation) { | 847 TEST(BytecodeGraphBuilderCountOperation) { |
831 HandleAndZoneScope scope; | 848 HandleAndZoneScope scope; |
832 Isolate* isolate = scope.main_isolate(); | 849 Isolate* isolate = scope.main_isolate(); |
| 850 Zone* zone = scope.main_zone(); |
833 Factory* factory = isolate->factory(); | 851 Factory* factory = isolate->factory(); |
834 | 852 |
835 ExpectedSnippet<1> snippets[] = { | 853 ExpectedSnippet<1> snippets[] = { |
836 {"return ++p1;", | 854 {"return ++p1;", |
837 {factory->NewNumberFromInt(11), factory->NewNumberFromInt(10)}}, | 855 {factory->NewNumberFromInt(11), factory->NewNumberFromInt(10)}}, |
838 {"return p1++;", | 856 {"return p1++;", |
839 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(10)}}, | 857 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(10)}}, |
840 {"return p1++ + 10;", | 858 {"return p1++ + 10;", |
841 {factory->NewHeapNumber(15.23), factory->NewHeapNumber(5.23)}}, | 859 {factory->NewHeapNumber(15.23), factory->NewHeapNumber(5.23)}}, |
842 {"return 20 + ++p1;", | 860 {"return 20 + ++p1;", |
(...skipping 21 matching lines...) Expand all Loading... |
864 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(10)}}, | 882 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(10)}}, |
865 {"return ++p1;", | 883 {"return ++p1;", |
866 {factory->nan_value(), factory->NewStringFromStaticChars("String")}}, | 884 {factory->nan_value(), factory->NewStringFromStaticChars("String")}}, |
867 }; | 885 }; |
868 | 886 |
869 for (size_t i = 0; i < arraysize(snippets); i++) { | 887 for (size_t i = 0; i < arraysize(snippets); i++) { |
870 ScopedVector<char> script(1024); | 888 ScopedVector<char> script(1024); |
871 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, | 889 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, |
872 snippets[i].code_snippet, kFunctionName); | 890 snippets[i].code_snippet, kFunctionName); |
873 | 891 |
874 BytecodeGraphTester tester(isolate, script.start()); | 892 BytecodeGraphTester tester(isolate, zone, script.start()); |
875 auto callable = tester.GetCallable<Handle<Object>>(); | 893 auto callable = tester.GetCallable<Handle<Object>>(); |
876 Handle<Object> return_value = | 894 Handle<Object> return_value = |
877 callable(snippets[i].parameter(0)).ToHandleChecked(); | 895 callable(snippets[i].parameter(0)).ToHandleChecked(); |
878 CHECK(return_value->SameValue(*snippets[i].return_value())); | 896 CHECK(return_value->SameValue(*snippets[i].return_value())); |
879 } | 897 } |
880 } | 898 } |
881 | 899 |
882 | 900 |
883 TEST(BytecodeGraphBuilderDelete) { | 901 TEST(BytecodeGraphBuilderDelete) { |
884 HandleAndZoneScope scope; | 902 HandleAndZoneScope scope; |
885 Isolate* isolate = scope.main_isolate(); | 903 Isolate* isolate = scope.main_isolate(); |
| 904 Zone* zone = scope.main_zone(); |
886 Factory* factory = isolate->factory(); | 905 Factory* factory = isolate->factory(); |
887 | 906 |
888 ExpectedSnippet<1> snippets[] = { | 907 ExpectedSnippet<1> snippets[] = { |
889 {"return delete p1.val;", | 908 {"return delete p1.val;", |
890 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, | 909 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, |
891 {"delete p1.val; return p1.val;", | 910 {"delete p1.val; return p1.val;", |
892 {factory->undefined_value(), | 911 {factory->undefined_value(), |
893 BytecodeGraphTester::NewObject("({val : 10})")}}, | 912 BytecodeGraphTester::NewObject("({val : 10})")}}, |
894 {"delete p1.name; return p1.val;", | 913 {"delete p1.name; return p1.val;", |
895 {factory->NewNumberFromInt(10), | 914 {factory->NewNumberFromInt(10), |
896 BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}}, | 915 BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}}, |
897 {"'use strict'; return delete p1.val;", | 916 {"'use strict'; return delete p1.val;", |
898 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, | 917 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, |
899 {"'use strict'; delete p1.val; return p1.val;", | 918 {"'use strict'; delete p1.val; return p1.val;", |
900 {factory->undefined_value(), | 919 {factory->undefined_value(), |
901 BytecodeGraphTester::NewObject("({val : 10})")}}, | 920 BytecodeGraphTester::NewObject("({val : 10})")}}, |
902 {"'use strict'; delete p1.name; return p1.val;", | 921 {"'use strict'; delete p1.name; return p1.val;", |
903 {factory->NewNumberFromInt(10), | 922 {factory->NewNumberFromInt(10), |
904 BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}}, | 923 BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}}, |
905 }; | 924 }; |
906 | 925 |
907 for (size_t i = 0; i < arraysize(snippets); i++) { | 926 for (size_t i = 0; i < arraysize(snippets); i++) { |
908 ScopedVector<char> script(1024); | 927 ScopedVector<char> script(1024); |
909 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, | 928 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, |
910 snippets[i].code_snippet, kFunctionName); | 929 snippets[i].code_snippet, kFunctionName); |
911 | 930 |
912 BytecodeGraphTester tester(isolate, script.start()); | 931 BytecodeGraphTester tester(isolate, zone, script.start()); |
913 auto callable = tester.GetCallable<Handle<Object>>(); | 932 auto callable = tester.GetCallable<Handle<Object>>(); |
914 Handle<Object> return_value = | 933 Handle<Object> return_value = |
915 callable(snippets[i].parameter(0)).ToHandleChecked(); | 934 callable(snippets[i].parameter(0)).ToHandleChecked(); |
916 CHECK(return_value->SameValue(*snippets[i].return_value())); | 935 CHECK(return_value->SameValue(*snippets[i].return_value())); |
917 } | 936 } |
918 } | 937 } |
919 | 938 |
920 | 939 |
921 TEST(BytecodeGraphBuilderDeleteGlobal) { | 940 TEST(BytecodeGraphBuilderDeleteGlobal) { |
922 HandleAndZoneScope scope; | 941 HandleAndZoneScope scope; |
923 Isolate* isolate = scope.main_isolate(); | 942 Isolate* isolate = scope.main_isolate(); |
| 943 Zone* zone = scope.main_zone(); |
924 Factory* factory = isolate->factory(); | 944 Factory* factory = isolate->factory(); |
925 | 945 |
926 ExpectedSnippet<0> snippets[] = { | 946 ExpectedSnippet<0> snippets[] = { |
927 {"var obj = {val : 10, type : 'int'};" | 947 {"var obj = {val : 10, type : 'int'};" |
928 "function f() {return delete obj;};", | 948 "function f() {return delete obj;};", |
929 {factory->false_value()}}, | 949 {factory->false_value()}}, |
930 {"function f() {return delete this;};", {factory->true_value()}}, | 950 {"function f() {return delete this;};", {factory->true_value()}}, |
931 {"var obj = {val : 10, type : 'int'};" | 951 {"var obj = {val : 10, type : 'int'};" |
932 "function f() {return delete obj.val;};", | 952 "function f() {return delete obj.val;};", |
933 {factory->true_value()}}, | 953 {factory->true_value()}}, |
(...skipping 20 matching lines...) Expand all Loading... |
954 " function inner() { return obj[1]; };" | 974 " function inner() { return obj[1]; };" |
955 " return delete obj[1];" | 975 " return delete obj[1];" |
956 "}", | 976 "}", |
957 {factory->true_value()}}, | 977 {factory->true_value()}}, |
958 }; | 978 }; |
959 | 979 |
960 for (size_t i = 0; i < arraysize(snippets); i++) { | 980 for (size_t i = 0; i < arraysize(snippets); i++) { |
961 ScopedVector<char> script(1024); | 981 ScopedVector<char> script(1024); |
962 SNPrintF(script, "%s %s({});", snippets[i].code_snippet, kFunctionName); | 982 SNPrintF(script, "%s %s({});", snippets[i].code_snippet, kFunctionName); |
963 | 983 |
964 BytecodeGraphTester tester(isolate, script.start()); | 984 BytecodeGraphTester tester(isolate, zone, script.start()); |
965 auto callable = tester.GetCallable<>(); | 985 auto callable = tester.GetCallable<>(); |
966 Handle<Object> return_value = callable().ToHandleChecked(); | 986 Handle<Object> return_value = callable().ToHandleChecked(); |
967 CHECK(return_value->SameValue(*snippets[i].return_value())); | 987 CHECK(return_value->SameValue(*snippets[i].return_value())); |
968 } | 988 } |
969 } | 989 } |
970 | 990 |
971 | 991 |
972 TEST(BytecodeGraphBuilderDeleteLookupSlot) { | 992 TEST(BytecodeGraphBuilderDeleteLookupSlot) { |
973 HandleAndZoneScope scope; | 993 HandleAndZoneScope scope; |
974 Isolate* isolate = scope.main_isolate(); | 994 Isolate* isolate = scope.main_isolate(); |
| 995 Zone* zone = scope.main_zone(); |
975 Factory* factory = isolate->factory(); | 996 Factory* factory = isolate->factory(); |
976 | 997 |
977 // TODO(mythria): Add more tests when we have support for LdaLookupSlot. | 998 // TODO(mythria): Add more tests when we have support for LdaLookupSlot. |
978 const char* function_prologue = "var f;" | 999 const char* function_prologue = "var f;" |
979 "var x = 1;" | 1000 "var x = 1;" |
980 "y = 10;" | 1001 "y = 10;" |
981 "var obj = {val:10};" | 1002 "var obj = {val:10};" |
982 "var z = 30;" | 1003 "var z = 30;" |
983 "function f1() {" | 1004 "function f1() {" |
984 " var z = 20;" | 1005 " var z = 20;" |
985 " eval(\"function t() {"; | 1006 " eval(\"function t() {"; |
986 const char* function_epilogue = " }; f = t; t();\");" | 1007 const char* function_epilogue = " }; f = t; t();\");" |
987 "}" | 1008 "}" |
988 "f1();"; | 1009 "f1();"; |
989 | 1010 |
990 ExpectedSnippet<0> snippets[] = { | 1011 ExpectedSnippet<0> snippets[] = { |
991 {"return delete y;", {factory->true_value()}}, | 1012 {"return delete y;", {factory->true_value()}}, |
992 {"return delete z;", {factory->false_value()}}, | 1013 {"return delete z;", {factory->false_value()}}, |
993 }; | 1014 }; |
994 | 1015 |
995 for (size_t i = 0; i < arraysize(snippets); i++) { | 1016 for (size_t i = 0; i < arraysize(snippets); i++) { |
996 ScopedVector<char> script(1024); | 1017 ScopedVector<char> script(1024); |
997 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, | 1018 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, |
998 function_epilogue); | 1019 function_epilogue); |
999 | 1020 |
1000 BytecodeGraphTester tester(isolate, script.start(), "t"); | 1021 BytecodeGraphTester tester(isolate, zone, script.start(), "t"); |
1001 auto callable = tester.GetCallable<>(); | 1022 auto callable = tester.GetCallable<>(); |
1002 Handle<Object> return_value = callable().ToHandleChecked(); | 1023 Handle<Object> return_value = callable().ToHandleChecked(); |
1003 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1024 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1004 } | 1025 } |
1005 } | 1026 } |
1006 | 1027 |
1007 | 1028 |
1008 TEST(BytecodeGraphBuilderLookupSlot) { | 1029 TEST(BytecodeGraphBuilderLookupSlot) { |
1009 HandleAndZoneScope scope; | 1030 HandleAndZoneScope scope; |
1010 Isolate* isolate = scope.main_isolate(); | 1031 Isolate* isolate = scope.main_isolate(); |
| 1032 Zone* zone = scope.main_zone(); |
1011 Factory* factory = isolate->factory(); | 1033 Factory* factory = isolate->factory(); |
1012 | 1034 |
1013 const char* function_prologue = "var f;" | 1035 const char* function_prologue = "var f;" |
1014 "var x = 12;" | 1036 "var x = 12;" |
1015 "y = 10;" | 1037 "y = 10;" |
1016 "var obj = {val:3.1414};" | 1038 "var obj = {val:3.1414};" |
1017 "var z = 30;" | 1039 "var z = 30;" |
1018 "function f1() {" | 1040 "function f1() {" |
1019 " var z = 20;" | 1041 " var z = 20;" |
1020 " eval(\"function t() {"; | 1042 " eval(\"function t() {"; |
1021 const char* function_epilogue = " }; f = t; t();\");" | 1043 const char* function_epilogue = " }; f = t; t();\");" |
1022 "}" | 1044 "}" |
1023 "f1();"; | 1045 "f1();"; |
1024 | 1046 |
1025 ExpectedSnippet<0> snippets[] = { | 1047 ExpectedSnippet<0> snippets[] = { |
1026 {"return x;", {factory->NewNumber(12)}}, | 1048 {"return x;", {factory->NewNumber(12)}}, |
1027 {"return obj.val;", {factory->NewNumber(3.1414)}}, | 1049 {"return obj.val;", {factory->NewNumber(3.1414)}}, |
1028 {"return typeof x;", {factory->NewStringFromStaticChars("number")}}, | 1050 {"return typeof x;", {factory->NewStringFromStaticChars("number")}}, |
1029 {"return typeof dummy;", | 1051 {"return typeof dummy;", |
1030 {factory->NewStringFromStaticChars("undefined")}}, | 1052 {factory->NewStringFromStaticChars("undefined")}}, |
1031 {"x = 23; return x;", {factory->NewNumber(23)}}, | 1053 {"x = 23; return x;", {factory->NewNumber(23)}}, |
1032 {"'use strict'; obj.val = 23.456; return obj.val;", | 1054 {"'use strict'; obj.val = 23.456; return obj.val;", |
1033 {factory->NewNumber(23.456)}}}; | 1055 {factory->NewNumber(23.456)}}}; |
1034 | 1056 |
1035 for (size_t i = 0; i < arraysize(snippets); i++) { | 1057 for (size_t i = 0; i < arraysize(snippets); i++) { |
1036 ScopedVector<char> script(1024); | 1058 ScopedVector<char> script(1024); |
1037 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, | 1059 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, |
1038 function_epilogue); | 1060 function_epilogue); |
1039 | 1061 |
1040 BytecodeGraphTester tester(isolate, script.start(), "t"); | 1062 BytecodeGraphTester tester(isolate, zone, script.start(), "t"); |
1041 auto callable = tester.GetCallable<>(); | 1063 auto callable = tester.GetCallable<>(); |
1042 Handle<Object> return_value = callable().ToHandleChecked(); | 1064 Handle<Object> return_value = callable().ToHandleChecked(); |
1043 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1065 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1044 } | 1066 } |
1045 } | 1067 } |
1046 | 1068 |
1047 TEST(BytecodeGraphBuilderLookupContextSlot) { | 1069 TEST(BytecodeGraphBuilderLookupContextSlot) { |
1048 HandleAndZoneScope scope; | 1070 HandleAndZoneScope scope; |
1049 Isolate* isolate = scope.main_isolate(); | 1071 Isolate* isolate = scope.main_isolate(); |
| 1072 Zone* zone = scope.main_zone(); |
1050 Factory* factory = isolate->factory(); | 1073 Factory* factory = isolate->factory(); |
1051 | 1074 |
1052 // Testing with eval called in the current context. | 1075 // Testing with eval called in the current context. |
1053 const char* inner_eval_prologue = "var x = 0; function inner() {"; | 1076 const char* inner_eval_prologue = "var x = 0; function inner() {"; |
1054 const char* inner_eval_epilogue = "}; return inner();"; | 1077 const char* inner_eval_epilogue = "}; return inner();"; |
1055 | 1078 |
1056 ExpectedSnippet<0> inner_eval_snippets[] = { | 1079 ExpectedSnippet<0> inner_eval_snippets[] = { |
1057 {"eval(''); return x;", {factory->NewNumber(0)}}, | 1080 {"eval(''); return x;", {factory->NewNumber(0)}}, |
1058 {"eval('var x = 1'); return x;", {factory->NewNumber(1)}}, | 1081 {"eval('var x = 1'); return x;", {factory->NewNumber(1)}}, |
1059 {"'use strict'; eval('var x = 1'); return x;", {factory->NewNumber(0)}}}; | 1082 {"'use strict'; eval('var x = 1'); return x;", {factory->NewNumber(0)}}}; |
1060 | 1083 |
1061 for (size_t i = 0; i < arraysize(inner_eval_snippets); i++) { | 1084 for (size_t i = 0; i < arraysize(inner_eval_snippets); i++) { |
1062 ScopedVector<char> script(1024); | 1085 ScopedVector<char> script(1024); |
1063 SNPrintF(script, "function %s(p1) { %s %s %s } ; %s() ;", kFunctionName, | 1086 SNPrintF(script, "function %s(p1) { %s %s %s } ; %s() ;", kFunctionName, |
1064 inner_eval_prologue, inner_eval_snippets[i].code_snippet, | 1087 inner_eval_prologue, inner_eval_snippets[i].code_snippet, |
1065 inner_eval_epilogue, kFunctionName); | 1088 inner_eval_epilogue, kFunctionName); |
1066 | 1089 |
1067 BytecodeGraphTester tester(isolate, script.start()); | 1090 BytecodeGraphTester tester(isolate, zone, script.start()); |
1068 auto callable = tester.GetCallable<>(); | 1091 auto callable = tester.GetCallable<>(); |
1069 Handle<Object> return_value = callable().ToHandleChecked(); | 1092 Handle<Object> return_value = callable().ToHandleChecked(); |
1070 CHECK(return_value->SameValue(*inner_eval_snippets[i].return_value())); | 1093 CHECK(return_value->SameValue(*inner_eval_snippets[i].return_value())); |
1071 } | 1094 } |
1072 | 1095 |
1073 // Testing with eval called in a parent context. | 1096 // Testing with eval called in a parent context. |
1074 const char* outer_eval_prologue = ""; | 1097 const char* outer_eval_prologue = ""; |
1075 const char* outer_eval_epilogue = | 1098 const char* outer_eval_epilogue = |
1076 "function inner() { return x; }; return inner();"; | 1099 "function inner() { return x; }; return inner();"; |
1077 | 1100 |
1078 ExpectedSnippet<0> outer_eval_snippets[] = { | 1101 ExpectedSnippet<0> outer_eval_snippets[] = { |
1079 {"var x = 0; eval('');", {factory->NewNumber(0)}}, | 1102 {"var x = 0; eval('');", {factory->NewNumber(0)}}, |
1080 {"var x = 0; eval('var x = 1');", {factory->NewNumber(1)}}, | 1103 {"var x = 0; eval('var x = 1');", {factory->NewNumber(1)}}, |
1081 {"'use strict'; var x = 0; eval('var x = 1');", {factory->NewNumber(0)}}}; | 1104 {"'use strict'; var x = 0; eval('var x = 1');", {factory->NewNumber(0)}}}; |
1082 | 1105 |
1083 for (size_t i = 0; i < arraysize(outer_eval_snippets); i++) { | 1106 for (size_t i = 0; i < arraysize(outer_eval_snippets); i++) { |
1084 ScopedVector<char> script(1024); | 1107 ScopedVector<char> script(1024); |
1085 SNPrintF(script, "function %s() { %s %s %s } ; %s() ;", kFunctionName, | 1108 SNPrintF(script, "function %s() { %s %s %s } ; %s() ;", kFunctionName, |
1086 outer_eval_prologue, outer_eval_snippets[i].code_snippet, | 1109 outer_eval_prologue, outer_eval_snippets[i].code_snippet, |
1087 outer_eval_epilogue, kFunctionName); | 1110 outer_eval_epilogue, kFunctionName); |
1088 | 1111 |
1089 BytecodeGraphTester tester(isolate, script.start()); | 1112 BytecodeGraphTester tester(isolate, zone, script.start()); |
1090 auto callable = tester.GetCallable<>(); | 1113 auto callable = tester.GetCallable<>(); |
1091 Handle<Object> return_value = callable().ToHandleChecked(); | 1114 Handle<Object> return_value = callable().ToHandleChecked(); |
1092 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); | 1115 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); |
1093 } | 1116 } |
1094 } | 1117 } |
1095 | 1118 |
1096 TEST(BytecodeGraphBuilderLookupGlobalSlot) { | 1119 TEST(BytecodeGraphBuilderLookupGlobalSlot) { |
1097 HandleAndZoneScope scope; | 1120 HandleAndZoneScope scope; |
1098 Isolate* isolate = scope.main_isolate(); | 1121 Isolate* isolate = scope.main_isolate(); |
| 1122 Zone* zone = scope.main_zone(); |
1099 Factory* factory = isolate->factory(); | 1123 Factory* factory = isolate->factory(); |
1100 | 1124 |
1101 // Testing with eval called in the current context. | 1125 // Testing with eval called in the current context. |
1102 const char* inner_eval_prologue = "x = 0; function inner() {"; | 1126 const char* inner_eval_prologue = "x = 0; function inner() {"; |
1103 const char* inner_eval_epilogue = "}; return inner();"; | 1127 const char* inner_eval_epilogue = "}; return inner();"; |
1104 | 1128 |
1105 ExpectedSnippet<0> inner_eval_snippets[] = { | 1129 ExpectedSnippet<0> inner_eval_snippets[] = { |
1106 {"eval(''); return x;", {factory->NewNumber(0)}}, | 1130 {"eval(''); return x;", {factory->NewNumber(0)}}, |
1107 {"eval('var x = 1'); return x;", {factory->NewNumber(1)}}, | 1131 {"eval('var x = 1'); return x;", {factory->NewNumber(1)}}, |
1108 {"'use strict'; eval('var x = 1'); return x;", {factory->NewNumber(0)}}}; | 1132 {"'use strict'; eval('var x = 1'); return x;", {factory->NewNumber(0)}}}; |
1109 | 1133 |
1110 for (size_t i = 0; i < arraysize(inner_eval_snippets); i++) { | 1134 for (size_t i = 0; i < arraysize(inner_eval_snippets); i++) { |
1111 ScopedVector<char> script(1024); | 1135 ScopedVector<char> script(1024); |
1112 SNPrintF(script, "function %s(p1) { %s %s %s } ; %s() ;", kFunctionName, | 1136 SNPrintF(script, "function %s(p1) { %s %s %s } ; %s() ;", kFunctionName, |
1113 inner_eval_prologue, inner_eval_snippets[i].code_snippet, | 1137 inner_eval_prologue, inner_eval_snippets[i].code_snippet, |
1114 inner_eval_epilogue, kFunctionName); | 1138 inner_eval_epilogue, kFunctionName); |
1115 | 1139 |
1116 BytecodeGraphTester tester(isolate, script.start()); | 1140 BytecodeGraphTester tester(isolate, zone, script.start()); |
1117 auto callable = tester.GetCallable<>(); | 1141 auto callable = tester.GetCallable<>(); |
1118 Handle<Object> return_value = callable().ToHandleChecked(); | 1142 Handle<Object> return_value = callable().ToHandleChecked(); |
1119 CHECK(return_value->SameValue(*inner_eval_snippets[i].return_value())); | 1143 CHECK(return_value->SameValue(*inner_eval_snippets[i].return_value())); |
1120 } | 1144 } |
1121 | 1145 |
1122 // Testing with eval called in a parent context. | 1146 // Testing with eval called in a parent context. |
1123 const char* outer_eval_prologue = ""; | 1147 const char* outer_eval_prologue = ""; |
1124 const char* outer_eval_epilogue = | 1148 const char* outer_eval_epilogue = |
1125 "function inner() { return x; }; return inner();"; | 1149 "function inner() { return x; }; return inner();"; |
1126 | 1150 |
1127 ExpectedSnippet<0> outer_eval_snippets[] = { | 1151 ExpectedSnippet<0> outer_eval_snippets[] = { |
1128 {"x = 0; eval('');", {factory->NewNumber(0)}}, | 1152 {"x = 0; eval('');", {factory->NewNumber(0)}}, |
1129 {"x = 0; eval('var x = 1');", {factory->NewNumber(1)}}, | 1153 {"x = 0; eval('var x = 1');", {factory->NewNumber(1)}}, |
1130 {"'use strict'; x = 0; eval('var x = 1');", {factory->NewNumber(0)}}}; | 1154 {"'use strict'; x = 0; eval('var x = 1');", {factory->NewNumber(0)}}}; |
1131 | 1155 |
1132 for (size_t i = 0; i < arraysize(outer_eval_snippets); i++) { | 1156 for (size_t i = 0; i < arraysize(outer_eval_snippets); i++) { |
1133 ScopedVector<char> script(1024); | 1157 ScopedVector<char> script(1024); |
1134 SNPrintF(script, "function %s() { %s %s %s } ; %s() ;", kFunctionName, | 1158 SNPrintF(script, "function %s() { %s %s %s } ; %s() ;", kFunctionName, |
1135 outer_eval_prologue, outer_eval_snippets[i].code_snippet, | 1159 outer_eval_prologue, outer_eval_snippets[i].code_snippet, |
1136 outer_eval_epilogue, kFunctionName); | 1160 outer_eval_epilogue, kFunctionName); |
1137 | 1161 |
1138 BytecodeGraphTester tester(isolate, script.start()); | 1162 BytecodeGraphTester tester(isolate, zone, script.start()); |
1139 auto callable = tester.GetCallable<>(); | 1163 auto callable = tester.GetCallable<>(); |
1140 Handle<Object> return_value = callable().ToHandleChecked(); | 1164 Handle<Object> return_value = callable().ToHandleChecked(); |
1141 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); | 1165 CHECK(return_value->SameValue(*outer_eval_snippets[i].return_value())); |
1142 } | 1166 } |
1143 } | 1167 } |
1144 | 1168 |
1145 TEST(BytecodeGraphBuilderLookupSlotWide) { | 1169 TEST(BytecodeGraphBuilderLookupSlotWide) { |
1146 HandleAndZoneScope scope; | 1170 HandleAndZoneScope scope; |
1147 Isolate* isolate = scope.main_isolate(); | 1171 Isolate* isolate = scope.main_isolate(); |
| 1172 Zone* zone = scope.main_zone(); |
1148 Factory* factory = isolate->factory(); | 1173 Factory* factory = isolate->factory(); |
1149 | 1174 |
1150 const char* function_prologue = | 1175 const char* function_prologue = |
1151 "var f;" | 1176 "var f;" |
1152 "var x = 12;" | 1177 "var x = 12;" |
1153 "y = 10;" | 1178 "y = 10;" |
1154 "var obj = {val:3.1414};" | 1179 "var obj = {val:3.1414};" |
1155 "var z = 30;" | 1180 "var z = 30;" |
1156 "function f1() {" | 1181 "function f1() {" |
1157 " var z = 20;" | 1182 " var z = 20;" |
(...skipping 11 matching lines...) Expand all Loading... |
1169 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return x = 23;", | 1194 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return x = 23;", |
1170 {factory->NewNumber(23)}}, | 1195 {factory->NewNumber(23)}}, |
1171 {"'use strict';" REPEAT_256(SPACE, "y = 2.3;") "return obj.val = 23.456;", | 1196 {"'use strict';" REPEAT_256(SPACE, "y = 2.3;") "return obj.val = 23.456;", |
1172 {factory->NewNumber(23.456)}}}; | 1197 {factory->NewNumber(23.456)}}}; |
1173 | 1198 |
1174 for (size_t i = 0; i < arraysize(snippets); i++) { | 1199 for (size_t i = 0; i < arraysize(snippets); i++) { |
1175 ScopedVector<char> script(3072); | 1200 ScopedVector<char> script(3072); |
1176 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, | 1201 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, |
1177 function_epilogue); | 1202 function_epilogue); |
1178 | 1203 |
1179 BytecodeGraphTester tester(isolate, script.start(), "t"); | 1204 BytecodeGraphTester tester(isolate, zone, script.start(), "t"); |
1180 auto callable = tester.GetCallable<>(); | 1205 auto callable = tester.GetCallable<>(); |
1181 Handle<Object> return_value = callable().ToHandleChecked(); | 1206 Handle<Object> return_value = callable().ToHandleChecked(); |
1182 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1207 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1183 } | 1208 } |
1184 } | 1209 } |
1185 | 1210 |
1186 | 1211 |
1187 TEST(BytecodeGraphBuilderCallLookupSlot) { | 1212 TEST(BytecodeGraphBuilderCallLookupSlot) { |
1188 HandleAndZoneScope scope; | 1213 HandleAndZoneScope scope; |
1189 Isolate* isolate = scope.main_isolate(); | 1214 Isolate* isolate = scope.main_isolate(); |
| 1215 Zone* zone = scope.main_zone(); |
1190 | 1216 |
1191 ExpectedSnippet<0> snippets[] = { | 1217 ExpectedSnippet<0> snippets[] = { |
1192 {"g = function(){ return 2 }; eval(''); return g();", | 1218 {"g = function(){ return 2 }; eval(''); return g();", |
1193 {handle(Smi::FromInt(2), isolate)}}, | 1219 {handle(Smi::FromInt(2), isolate)}}, |
1194 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" | 1220 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" |
1195 "return g();", | 1221 "return g();", |
1196 {handle(Smi::FromInt(3), isolate)}}, | 1222 {handle(Smi::FromInt(3), isolate)}}, |
1197 {"g = { x: function(){ return this.y }, y: 20 };\n" | 1223 {"g = { x: function(){ return this.y }, y: 20 };\n" |
1198 "eval('g = { x: g.x, y: 30 }');\n" | 1224 "eval('g = { x: g.x, y: 30 }');\n" |
1199 "return g.x();", | 1225 "return g.x();", |
1200 {handle(Smi::FromInt(30), isolate)}}, | 1226 {handle(Smi::FromInt(30), isolate)}}, |
1201 }; | 1227 }; |
1202 | 1228 |
1203 for (size_t i = 0; i < arraysize(snippets); i++) { | 1229 for (size_t i = 0; i < arraysize(snippets); i++) { |
1204 ScopedVector<char> script(1024); | 1230 ScopedVector<char> script(1024); |
1205 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1231 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1206 snippets[i].code_snippet, kFunctionName); | 1232 snippets[i].code_snippet, kFunctionName); |
1207 BytecodeGraphTester tester(isolate, script.start()); | 1233 BytecodeGraphTester tester(isolate, zone, script.start()); |
1208 auto callable = tester.GetCallable<>(); | 1234 auto callable = tester.GetCallable<>(); |
1209 Handle<Object> return_value = callable().ToHandleChecked(); | 1235 Handle<Object> return_value = callable().ToHandleChecked(); |
1210 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1236 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1211 } | 1237 } |
1212 } | 1238 } |
1213 | 1239 |
1214 | 1240 |
1215 TEST(BytecodeGraphBuilderEval) { | 1241 TEST(BytecodeGraphBuilderEval) { |
1216 HandleAndZoneScope scope; | 1242 HandleAndZoneScope scope; |
1217 Isolate* isolate = scope.main_isolate(); | 1243 Isolate* isolate = scope.main_isolate(); |
| 1244 Zone* zone = scope.main_zone(); |
1218 Factory* factory = isolate->factory(); | 1245 Factory* factory = isolate->factory(); |
1219 | 1246 |
1220 ExpectedSnippet<0> snippets[] = { | 1247 ExpectedSnippet<0> snippets[] = { |
1221 {"return eval('1;');", {handle(Smi::FromInt(1), isolate)}}, | 1248 {"return eval('1;');", {handle(Smi::FromInt(1), isolate)}}, |
1222 {"return eval('100 * 20;');", {handle(Smi::FromInt(2000), isolate)}}, | 1249 {"return eval('100 * 20;');", {handle(Smi::FromInt(2000), isolate)}}, |
1223 {"var x = 10; return eval('x + 20;');", | 1250 {"var x = 10; return eval('x + 20;');", |
1224 {handle(Smi::FromInt(30), isolate)}}, | 1251 {handle(Smi::FromInt(30), isolate)}}, |
1225 {"var x = 10; eval('x = 33;'); return x;", | 1252 {"var x = 10; eval('x = 33;'); return x;", |
1226 {handle(Smi::FromInt(33), isolate)}}, | 1253 {handle(Smi::FromInt(33), isolate)}}, |
1227 {"'use strict'; var x = 20; var z = 0;\n" | 1254 {"'use strict'; var x = 20; var z = 0;\n" |
(...skipping 20 matching lines...) Expand all Loading... |
1248 {"var x = {}; eval('var x = 10;'); return typeof x;", | 1275 {"var x = {}; eval('var x = 10;'); return typeof x;", |
1249 {factory->NewStringFromStaticChars("number")}}, | 1276 {factory->NewStringFromStaticChars("number")}}, |
1250 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", | 1277 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", |
1251 {factory->NewStringFromStaticChars("object")}}, | 1278 {factory->NewStringFromStaticChars("object")}}, |
1252 }; | 1279 }; |
1253 | 1280 |
1254 for (size_t i = 0; i < arraysize(snippets); i++) { | 1281 for (size_t i = 0; i < arraysize(snippets); i++) { |
1255 ScopedVector<char> script(1024); | 1282 ScopedVector<char> script(1024); |
1256 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1283 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1257 snippets[i].code_snippet, kFunctionName); | 1284 snippets[i].code_snippet, kFunctionName); |
1258 BytecodeGraphTester tester(isolate, script.start()); | 1285 BytecodeGraphTester tester(isolate, zone, script.start()); |
1259 auto callable = tester.GetCallable<>(); | 1286 auto callable = tester.GetCallable<>(); |
1260 Handle<Object> return_value = callable().ToHandleChecked(); | 1287 Handle<Object> return_value = callable().ToHandleChecked(); |
1261 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1288 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1262 } | 1289 } |
1263 } | 1290 } |
1264 | 1291 |
1265 | 1292 |
1266 TEST(BytecodeGraphBuilderEvalParams) { | 1293 TEST(BytecodeGraphBuilderEvalParams) { |
1267 HandleAndZoneScope scope; | 1294 HandleAndZoneScope scope; |
1268 Isolate* isolate = scope.main_isolate(); | 1295 Isolate* isolate = scope.main_isolate(); |
| 1296 Zone* zone = scope.main_zone(); |
1269 | 1297 |
1270 ExpectedSnippet<1> snippets[] = { | 1298 ExpectedSnippet<1> snippets[] = { |
1271 {"var x = 10; return eval('x + p1;');", | 1299 {"var x = 10; return eval('x + p1;');", |
1272 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}}, | 1300 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}}, |
1273 {"var x = 10; eval('p1 = x;'); return p1;", | 1301 {"var x = 10; eval('p1 = x;'); return p1;", |
1274 {handle(Smi::FromInt(10), isolate), handle(Smi::FromInt(20), isolate)}}, | 1302 {handle(Smi::FromInt(10), isolate), handle(Smi::FromInt(20), isolate)}}, |
1275 {"var a = 10;" | 1303 {"var a = 10;" |
1276 "function inner() { return eval('a + p1;');}" | 1304 "function inner() { return eval('a + p1;');}" |
1277 "return inner();", | 1305 "return inner();", |
1278 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}}, | 1306 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}}, |
1279 }; | 1307 }; |
1280 | 1308 |
1281 for (size_t i = 0; i < arraysize(snippets); i++) { | 1309 for (size_t i = 0; i < arraysize(snippets); i++) { |
1282 ScopedVector<char> script(1024); | 1310 ScopedVector<char> script(1024); |
1283 SNPrintF(script, "function %s(p1) { %s }\n%s(0);", kFunctionName, | 1311 SNPrintF(script, "function %s(p1) { %s }\n%s(0);", kFunctionName, |
1284 snippets[i].code_snippet, kFunctionName); | 1312 snippets[i].code_snippet, kFunctionName); |
1285 BytecodeGraphTester tester(isolate, script.start()); | 1313 BytecodeGraphTester tester(isolate, zone, script.start()); |
1286 auto callable = tester.GetCallable<Handle<Object>>(); | 1314 auto callable = tester.GetCallable<Handle<Object>>(); |
1287 Handle<Object> return_value = | 1315 Handle<Object> return_value = |
1288 callable(snippets[i].parameter(0)).ToHandleChecked(); | 1316 callable(snippets[i].parameter(0)).ToHandleChecked(); |
1289 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1317 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1290 } | 1318 } |
1291 } | 1319 } |
1292 | 1320 |
1293 | 1321 |
1294 TEST(BytecodeGraphBuilderEvalGlobal) { | 1322 TEST(BytecodeGraphBuilderEvalGlobal) { |
1295 HandleAndZoneScope scope; | 1323 HandleAndZoneScope scope; |
1296 Isolate* isolate = scope.main_isolate(); | 1324 Isolate* isolate = scope.main_isolate(); |
| 1325 Zone* zone = scope.main_zone(); |
1297 Factory* factory = isolate->factory(); | 1326 Factory* factory = isolate->factory(); |
1298 | 1327 |
1299 ExpectedSnippet<0> snippets[] = { | 1328 ExpectedSnippet<0> snippets[] = { |
1300 {"function add_global() { eval('function f() { z = 33; }; f()'); };" | 1329 {"function add_global() { eval('function f() { z = 33; }; f()'); };" |
1301 "function f() { add_global(); return z; }; f();", | 1330 "function f() { add_global(); return z; }; f();", |
1302 {handle(Smi::FromInt(33), isolate)}}, | 1331 {handle(Smi::FromInt(33), isolate)}}, |
1303 {"function add_global() {\n" | 1332 {"function add_global() {\n" |
1304 " eval('\"use strict\"; function f() { y = 33; };" | 1333 " eval('\"use strict\"; function f() { y = 33; };" |
1305 " try { f() } catch(e) {}');\n" | 1334 " try { f() } catch(e) {}');\n" |
1306 "}\n" | 1335 "}\n" |
1307 "function f() { add_global(); return typeof y; } f();", | 1336 "function f() { add_global(); return typeof y; } f();", |
1308 {factory->NewStringFromStaticChars("undefined")}}, | 1337 {factory->NewStringFromStaticChars("undefined")}}, |
1309 }; | 1338 }; |
1310 | 1339 |
1311 for (size_t i = 0; i < arraysize(snippets); i++) { | 1340 for (size_t i = 0; i < arraysize(snippets); i++) { |
1312 BytecodeGraphTester tester(isolate, snippets[i].code_snippet); | 1341 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); |
1313 auto callable = tester.GetCallable<>(); | 1342 auto callable = tester.GetCallable<>(); |
1314 Handle<Object> return_value = callable().ToHandleChecked(); | 1343 Handle<Object> return_value = callable().ToHandleChecked(); |
1315 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1344 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1316 } | 1345 } |
1317 } | 1346 } |
1318 | 1347 |
1319 | 1348 |
1320 bool get_compare_result(Token::Value opcode, Handle<Object> lhs_value, | 1349 bool get_compare_result(Token::Value opcode, Handle<Object> lhs_value, |
1321 Handle<Object> rhs_value) { | 1350 Handle<Object> rhs_value) { |
1322 switch (opcode) { | 1351 switch (opcode) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 default: | 1393 default: |
1365 UNREACHABLE(); | 1394 UNREACHABLE(); |
1366 return ""; | 1395 return ""; |
1367 } | 1396 } |
1368 } | 1397 } |
1369 | 1398 |
1370 | 1399 |
1371 TEST(BytecodeGraphBuilderCompare) { | 1400 TEST(BytecodeGraphBuilderCompare) { |
1372 HandleAndZoneScope scope; | 1401 HandleAndZoneScope scope; |
1373 Isolate* isolate = scope.main_isolate(); | 1402 Isolate* isolate = scope.main_isolate(); |
| 1403 Zone* zone = scope.main_zone(); |
1374 Factory* factory = isolate->factory(); | 1404 Factory* factory = isolate->factory(); |
1375 Handle<Object> lhs_values[] = { | 1405 Handle<Object> lhs_values[] = { |
1376 factory->NewNumberFromInt(10), factory->NewHeapNumber(3.45), | 1406 factory->NewNumberFromInt(10), factory->NewHeapNumber(3.45), |
1377 factory->NewStringFromStaticChars("abc"), | 1407 factory->NewStringFromStaticChars("abc"), |
1378 factory->NewNumberFromInt(SMI_MAX), factory->NewNumberFromInt(SMI_MIN)}; | 1408 factory->NewNumberFromInt(SMI_MAX), factory->NewNumberFromInt(SMI_MIN)}; |
1379 Handle<Object> rhs_values[] = {factory->NewNumberFromInt(10), | 1409 Handle<Object> rhs_values[] = {factory->NewNumberFromInt(10), |
1380 factory->NewStringFromStaticChars("10"), | 1410 factory->NewStringFromStaticChars("10"), |
1381 factory->NewNumberFromInt(20), | 1411 factory->NewNumberFromInt(20), |
1382 factory->NewStringFromStaticChars("abc"), | 1412 factory->NewStringFromStaticChars("abc"), |
1383 factory->NewHeapNumber(3.45), | 1413 factory->NewHeapNumber(3.45), |
1384 factory->NewNumberFromInt(SMI_MAX), | 1414 factory->NewNumberFromInt(SMI_MAX), |
1385 factory->NewNumberFromInt(SMI_MIN)}; | 1415 factory->NewNumberFromInt(SMI_MIN)}; |
1386 | 1416 |
1387 for (size_t i = 0; i < arraysize(kCompareOperators); i++) { | 1417 for (size_t i = 0; i < arraysize(kCompareOperators); i++) { |
1388 ScopedVector<char> script(1024); | 1418 ScopedVector<char> script(1024); |
1389 SNPrintF(script, "function %s(p1, p2) { %s }\n%s({}, {});", kFunctionName, | 1419 SNPrintF(script, "function %s(p1, p2) { %s }\n%s({}, {});", kFunctionName, |
1390 get_code_snippet(kCompareOperators[i]), kFunctionName); | 1420 get_code_snippet(kCompareOperators[i]), kFunctionName); |
1391 | 1421 |
1392 BytecodeGraphTester tester(isolate, script.start()); | 1422 BytecodeGraphTester tester(isolate, zone, script.start()); |
1393 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 1423 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
1394 for (size_t j = 0; j < arraysize(lhs_values); j++) { | 1424 for (size_t j = 0; j < arraysize(lhs_values); j++) { |
1395 for (size_t k = 0; k < arraysize(rhs_values); k++) { | 1425 for (size_t k = 0; k < arraysize(rhs_values); k++) { |
1396 Handle<Object> return_value = | 1426 Handle<Object> return_value = |
1397 callable(lhs_values[j], rhs_values[k]).ToHandleChecked(); | 1427 callable(lhs_values[j], rhs_values[k]).ToHandleChecked(); |
1398 bool result = get_compare_result(kCompareOperators[i], lhs_values[j], | 1428 bool result = get_compare_result(kCompareOperators[i], lhs_values[j], |
1399 rhs_values[k]); | 1429 rhs_values[k]); |
1400 CHECK(return_value->SameValue(*factory->ToBoolean(result))); | 1430 CHECK(return_value->SameValue(*factory->ToBoolean(result))); |
1401 } | 1431 } |
1402 } | 1432 } |
1403 } | 1433 } |
1404 } | 1434 } |
1405 | 1435 |
1406 | 1436 |
1407 TEST(BytecodeGraphBuilderTestIn) { | 1437 TEST(BytecodeGraphBuilderTestIn) { |
1408 HandleAndZoneScope scope; | 1438 HandleAndZoneScope scope; |
1409 Isolate* isolate = scope.main_isolate(); | 1439 Isolate* isolate = scope.main_isolate(); |
| 1440 Zone* zone = scope.main_zone(); |
1410 Factory* factory = isolate->factory(); | 1441 Factory* factory = isolate->factory(); |
1411 | 1442 |
1412 ExpectedSnippet<2> snippets[] = { | 1443 ExpectedSnippet<2> snippets[] = { |
1413 {"return p2 in p1;", | 1444 {"return p2 in p1;", |
1414 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})"), | 1445 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})"), |
1415 factory->NewStringFromStaticChars("val")}}, | 1446 factory->NewStringFromStaticChars("val")}}, |
1416 {"return p2 in p1;", | 1447 {"return p2 in p1;", |
1417 {factory->true_value(), BytecodeGraphTester::NewObject("[]"), | 1448 {factory->true_value(), BytecodeGraphTester::NewObject("[]"), |
1418 factory->NewStringFromStaticChars("length")}}, | 1449 factory->NewStringFromStaticChars("length")}}, |
1419 {"return p2 in p1;", | 1450 {"return p2 in p1;", |
(...skipping 15 matching lines...) Expand all Loading... |
1435 {factory->false_value(), | 1466 {factory->false_value(), |
1436 BytecodeGraphTester::NewObject("({10 : 'val'})"), | 1467 BytecodeGraphTester::NewObject("({10 : 'val'})"), |
1437 factory->NewNumberFromInt(1)}}, | 1468 factory->NewNumberFromInt(1)}}, |
1438 }; | 1469 }; |
1439 | 1470 |
1440 for (size_t i = 0; i < arraysize(snippets); i++) { | 1471 for (size_t i = 0; i < arraysize(snippets); i++) { |
1441 ScopedVector<char> script(1024); | 1472 ScopedVector<char> script(1024); |
1442 SNPrintF(script, "function %s(p1, p2) { %s }\n%s({}, {});", kFunctionName, | 1473 SNPrintF(script, "function %s(p1, p2) { %s }\n%s({}, {});", kFunctionName, |
1443 snippets[i].code_snippet, kFunctionName); | 1474 snippets[i].code_snippet, kFunctionName); |
1444 | 1475 |
1445 BytecodeGraphTester tester(isolate, script.start()); | 1476 BytecodeGraphTester tester(isolate, zone, script.start()); |
1446 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 1477 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
1447 Handle<Object> return_value = | 1478 Handle<Object> return_value = |
1448 callable(snippets[i].parameter(0), snippets[i].parameter(1)) | 1479 callable(snippets[i].parameter(0), snippets[i].parameter(1)) |
1449 .ToHandleChecked(); | 1480 .ToHandleChecked(); |
1450 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1481 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1451 } | 1482 } |
1452 } | 1483 } |
1453 | 1484 |
1454 | 1485 |
1455 TEST(BytecodeGraphBuilderTestInstanceOf) { | 1486 TEST(BytecodeGraphBuilderTestInstanceOf) { |
1456 HandleAndZoneScope scope; | 1487 HandleAndZoneScope scope; |
1457 Isolate* isolate = scope.main_isolate(); | 1488 Isolate* isolate = scope.main_isolate(); |
| 1489 Zone* zone = scope.main_zone(); |
1458 Factory* factory = isolate->factory(); | 1490 Factory* factory = isolate->factory(); |
1459 | 1491 |
1460 ExpectedSnippet<1> snippets[] = { | 1492 ExpectedSnippet<1> snippets[] = { |
1461 {"return p1 instanceof Object;", | 1493 {"return p1 instanceof Object;", |
1462 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, | 1494 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, |
1463 {"return p1 instanceof String;", | 1495 {"return p1 instanceof String;", |
1464 {factory->false_value(), factory->NewStringFromStaticChars("string")}}, | 1496 {factory->false_value(), factory->NewStringFromStaticChars("string")}}, |
1465 {"var cons = function() {};" | 1497 {"var cons = function() {};" |
1466 "var obj = new cons();" | 1498 "var obj = new cons();" |
1467 "return obj instanceof cons;", | 1499 "return obj instanceof cons;", |
1468 {factory->true_value(), factory->undefined_value()}}, | 1500 {factory->true_value(), factory->undefined_value()}}, |
1469 }; | 1501 }; |
1470 | 1502 |
1471 for (size_t i = 0; i < arraysize(snippets); i++) { | 1503 for (size_t i = 0; i < arraysize(snippets); i++) { |
1472 ScopedVector<char> script(1024); | 1504 ScopedVector<char> script(1024); |
1473 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, | 1505 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, |
1474 snippets[i].code_snippet, kFunctionName); | 1506 snippets[i].code_snippet, kFunctionName); |
1475 | 1507 |
1476 BytecodeGraphTester tester(isolate, script.start()); | 1508 BytecodeGraphTester tester(isolate, zone, script.start()); |
1477 auto callable = tester.GetCallable<Handle<Object>>(); | 1509 auto callable = tester.GetCallable<Handle<Object>>(); |
1478 Handle<Object> return_value = | 1510 Handle<Object> return_value = |
1479 callable(snippets[i].parameter(0)).ToHandleChecked(); | 1511 callable(snippets[i].parameter(0)).ToHandleChecked(); |
1480 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1512 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1481 } | 1513 } |
1482 } | 1514 } |
1483 | 1515 |
1484 TEST(BytecodeGraphBuilderTryCatch) { | 1516 TEST(BytecodeGraphBuilderTryCatch) { |
1485 HandleAndZoneScope scope; | 1517 HandleAndZoneScope scope; |
1486 Isolate* isolate = scope.main_isolate(); | 1518 Isolate* isolate = scope.main_isolate(); |
| 1519 Zone* zone = scope.main_zone(); |
1487 | 1520 |
1488 ExpectedSnippet<0> snippets[] = { | 1521 ExpectedSnippet<0> snippets[] = { |
1489 {"var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", | 1522 {"var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", |
1490 {handle(Smi::FromInt(2), isolate)}}, | 1523 {handle(Smi::FromInt(2), isolate)}}, |
1491 {"var a; try { undef.x } catch(e) { a = 2 }; return a;", | 1524 {"var a; try { undef.x } catch(e) { a = 2 }; return a;", |
1492 {handle(Smi::FromInt(2), isolate)}}, | 1525 {handle(Smi::FromInt(2), isolate)}}, |
1493 {"var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", | 1526 {"var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", |
1494 {handle(Smi::FromInt(3), isolate)}}, | 1527 {handle(Smi::FromInt(3), isolate)}}, |
1495 {"var a; try { throw 1 } catch(e) { a = e + 2 };" | 1528 {"var a; try { throw 1 } catch(e) { a = e + 2 };" |
1496 " try { throw a } catch(e) { a = e + 3 }; return a;", | 1529 " try { throw a } catch(e) { a = e + 3 }; return a;", |
1497 {handle(Smi::FromInt(6), isolate)}}, | 1530 {handle(Smi::FromInt(6), isolate)}}, |
1498 }; | 1531 }; |
1499 | 1532 |
1500 for (size_t i = 0; i < arraysize(snippets); i++) { | 1533 for (size_t i = 0; i < arraysize(snippets); i++) { |
1501 ScopedVector<char> script(1024); | 1534 ScopedVector<char> script(1024); |
1502 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1535 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1503 snippets[i].code_snippet, kFunctionName); | 1536 snippets[i].code_snippet, kFunctionName); |
1504 | 1537 |
1505 BytecodeGraphTester tester(isolate, script.start()); | 1538 BytecodeGraphTester tester(isolate, zone, script.start()); |
1506 auto callable = tester.GetCallable<>(); | 1539 auto callable = tester.GetCallable<>(); |
1507 Handle<Object> return_value = callable().ToHandleChecked(); | 1540 Handle<Object> return_value = callable().ToHandleChecked(); |
1508 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1541 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1509 } | 1542 } |
1510 } | 1543 } |
1511 | 1544 |
1512 TEST(BytecodeGraphBuilderTryFinally1) { | 1545 TEST(BytecodeGraphBuilderTryFinally1) { |
1513 HandleAndZoneScope scope; | 1546 HandleAndZoneScope scope; |
1514 Isolate* isolate = scope.main_isolate(); | 1547 Isolate* isolate = scope.main_isolate(); |
| 1548 Zone* zone = scope.main_zone(); |
1515 | 1549 |
1516 ExpectedSnippet<0> snippets[] = { | 1550 ExpectedSnippet<0> snippets[] = { |
1517 {"var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", | 1551 {"var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;", |
1518 {handle(Smi::FromInt(4), isolate)}}, | 1552 {handle(Smi::FromInt(4), isolate)}}, |
1519 {"var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", | 1553 {"var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;", |
1520 {handle(Smi::FromInt(23), isolate)}}, | 1554 {handle(Smi::FromInt(23), isolate)}}, |
1521 {"var a = 1; try { a = 2; throw 23; } finally { return a; };", | 1555 {"var a = 1; try { a = 2; throw 23; } finally { return a; };", |
1522 {handle(Smi::FromInt(2), isolate)}}, | 1556 {handle(Smi::FromInt(2), isolate)}}, |
1523 {"var a = 1; for (var i = 10; i < 20; i += 5) {" | 1557 {"var a = 1; for (var i = 10; i < 20; i += 5) {" |
1524 " try { a = 2; break; } finally { a = 3; }" | 1558 " try { a = 2; break; } finally { a = 3; }" |
1525 "} return a + i;", | 1559 "} return a + i;", |
1526 {handle(Smi::FromInt(13), isolate)}}, | 1560 {handle(Smi::FromInt(13), isolate)}}, |
1527 {"var a = 1; for (var i = 10; i < 20; i += 5) {" | 1561 {"var a = 1; for (var i = 10; i < 20; i += 5) {" |
1528 " try { a = 2; continue; } finally { a = 3; }" | 1562 " try { a = 2; continue; } finally { a = 3; }" |
1529 "} return a + i;", | 1563 "} return a + i;", |
1530 {handle(Smi::FromInt(23), isolate)}}, | 1564 {handle(Smi::FromInt(23), isolate)}}, |
1531 {"var a = 1; try { a = 2;" | 1565 {"var a = 1; try { a = 2;" |
1532 " try { a = 3; throw 23; } finally { a = 4; }" | 1566 " try { a = 3; throw 23; } finally { a = 4; }" |
1533 "} catch(e) { a = a + e; } return a;", | 1567 "} catch(e) { a = a + e; } return a;", |
1534 {handle(Smi::FromInt(27), isolate)}}, | 1568 {handle(Smi::FromInt(27), isolate)}}, |
1535 }; | 1569 }; |
1536 | 1570 |
1537 for (size_t i = 0; i < arraysize(snippets); i++) { | 1571 for (size_t i = 0; i < arraysize(snippets); i++) { |
1538 ScopedVector<char> script(1024); | 1572 ScopedVector<char> script(1024); |
1539 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1573 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1540 snippets[i].code_snippet, kFunctionName); | 1574 snippets[i].code_snippet, kFunctionName); |
1541 | 1575 |
1542 BytecodeGraphTester tester(isolate, script.start()); | 1576 BytecodeGraphTester tester(isolate, zone, script.start()); |
1543 auto callable = tester.GetCallable<>(); | 1577 auto callable = tester.GetCallable<>(); |
1544 Handle<Object> return_value = callable().ToHandleChecked(); | 1578 Handle<Object> return_value = callable().ToHandleChecked(); |
1545 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1579 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1546 } | 1580 } |
1547 } | 1581 } |
1548 | 1582 |
1549 TEST(BytecodeGraphBuilderTryFinally2) { | 1583 TEST(BytecodeGraphBuilderTryFinally2) { |
1550 HandleAndZoneScope scope; | 1584 HandleAndZoneScope scope; |
1551 Isolate* isolate = scope.main_isolate(); | 1585 Isolate* isolate = scope.main_isolate(); |
| 1586 Zone* zone = scope.main_zone(); |
1552 | 1587 |
1553 ExpectedSnippet<0, const char*> snippets[] = { | 1588 ExpectedSnippet<0, const char*> snippets[] = { |
1554 {"var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", | 1589 {"var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", |
1555 {"Uncaught 23"}}, | 1590 {"Uncaught 23"}}, |
1556 {"var a = 1; try { a = 2; throw 23; } finally { throw 42; };", | 1591 {"var a = 1; try { a = 2; throw 23; } finally { throw 42; };", |
1557 {"Uncaught 42"}}, | 1592 {"Uncaught 42"}}, |
1558 }; | 1593 }; |
1559 | 1594 |
1560 for (size_t i = 0; i < arraysize(snippets); i++) { | 1595 for (size_t i = 0; i < arraysize(snippets); i++) { |
1561 ScopedVector<char> script(1024); | 1596 ScopedVector<char> script(1024); |
1562 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1597 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1563 snippets[i].code_snippet, kFunctionName); | 1598 snippets[i].code_snippet, kFunctionName); |
1564 | 1599 |
1565 BytecodeGraphTester tester(isolate, script.start()); | 1600 BytecodeGraphTester tester(isolate, zone, script.start()); |
1566 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 1601 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
1567 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); | 1602 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); |
1568 CHECK( | 1603 CHECK( |
1569 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 1604 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
1570 .FromJust()); | 1605 .FromJust()); |
1571 } | 1606 } |
1572 } | 1607 } |
1573 | 1608 |
1574 TEST(BytecodeGraphBuilderThrow) { | 1609 TEST(BytecodeGraphBuilderThrow) { |
1575 HandleAndZoneScope scope; | 1610 HandleAndZoneScope scope; |
1576 Isolate* isolate = scope.main_isolate(); | 1611 Isolate* isolate = scope.main_isolate(); |
| 1612 Zone* zone = scope.main_zone(); |
1577 | 1613 |
1578 // TODO(mythria): Add more tests when real try-catch and deoptimization | 1614 // TODO(mythria): Add more tests when real try-catch and deoptimization |
1579 // information are supported. | 1615 // information are supported. |
1580 ExpectedSnippet<0, const char*> snippets[] = { | 1616 ExpectedSnippet<0, const char*> snippets[] = { |
1581 {"throw undefined;", {"Uncaught undefined"}}, | 1617 {"throw undefined;", {"Uncaught undefined"}}, |
1582 {"throw 1;", {"Uncaught 1"}}, | 1618 {"throw 1;", {"Uncaught 1"}}, |
1583 {"throw 'Error';", {"Uncaught Error"}}, | 1619 {"throw 'Error';", {"Uncaught Error"}}, |
1584 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}}, | 1620 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}}, |
1585 {"var a = true; if (a) { throw 'Error'; }", {"Uncaught Error"}}, | 1621 {"var a = true; if (a) { throw 'Error'; }", {"Uncaught Error"}}, |
1586 }; | 1622 }; |
1587 | 1623 |
1588 for (size_t i = 0; i < arraysize(snippets); i++) { | 1624 for (size_t i = 0; i < arraysize(snippets); i++) { |
1589 ScopedVector<char> script(1024); | 1625 ScopedVector<char> script(1024); |
1590 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1626 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1591 snippets[i].code_snippet, kFunctionName); | 1627 snippets[i].code_snippet, kFunctionName); |
1592 | 1628 |
1593 BytecodeGraphTester tester(isolate, script.start()); | 1629 BytecodeGraphTester tester(isolate, zone, script.start()); |
1594 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 1630 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
1595 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); | 1631 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); |
1596 CHECK( | 1632 CHECK( |
1597 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 1633 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
1598 .FromJust()); | 1634 .FromJust()); |
1599 } | 1635 } |
1600 } | 1636 } |
1601 | 1637 |
1602 | 1638 |
1603 TEST(BytecodeGraphBuilderContext) { | 1639 TEST(BytecodeGraphBuilderContext) { |
1604 HandleAndZoneScope scope; | 1640 HandleAndZoneScope scope; |
1605 Isolate* isolate = scope.main_isolate(); | 1641 Isolate* isolate = scope.main_isolate(); |
| 1642 Zone* zone = scope.main_zone(); |
1606 Factory* factory = isolate->factory(); | 1643 Factory* factory = isolate->factory(); |
1607 | 1644 |
1608 ExpectedSnippet<0> snippets[] = { | 1645 ExpectedSnippet<0> snippets[] = { |
1609 {"var x = 'outer';" | 1646 {"var x = 'outer';" |
1610 "function f() {" | 1647 "function f() {" |
1611 " 'use strict';" | 1648 " 'use strict';" |
1612 " {" | 1649 " {" |
1613 " let x = 'inner';" | 1650 " let x = 'inner';" |
1614 " (function() {x});" | 1651 " (function() {x});" |
1615 " }" | 1652 " }" |
(...skipping 27 matching lines...) Expand all Loading... |
1643 " return(innerMostFunc() + x);" | 1680 " return(innerMostFunc() + x);" |
1644 "}" | 1681 "}" |
1645 "f();", | 1682 "f();", |
1646 {factory->NewStringFromStaticChars("innermost inner_changed outer")}}, | 1683 {factory->NewStringFromStaticChars("innermost inner_changed outer")}}, |
1647 }; | 1684 }; |
1648 | 1685 |
1649 for (size_t i = 0; i < arraysize(snippets); i++) { | 1686 for (size_t i = 0; i < arraysize(snippets); i++) { |
1650 ScopedVector<char> script(1024); | 1687 ScopedVector<char> script(1024); |
1651 SNPrintF(script, "%s", snippets[i].code_snippet); | 1688 SNPrintF(script, "%s", snippets[i].code_snippet); |
1652 | 1689 |
1653 BytecodeGraphTester tester(isolate, script.start(), "f"); | 1690 BytecodeGraphTester tester(isolate, zone, script.start(), "f"); |
1654 auto callable = tester.GetCallable<>("f"); | 1691 auto callable = tester.GetCallable<>("f"); |
1655 Handle<Object> return_value = callable().ToHandleChecked(); | 1692 Handle<Object> return_value = callable().ToHandleChecked(); |
1656 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1693 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1657 } | 1694 } |
1658 } | 1695 } |
1659 | 1696 |
1660 | 1697 |
1661 TEST(BytecodeGraphBuilderLoadContext) { | 1698 TEST(BytecodeGraphBuilderLoadContext) { |
1662 HandleAndZoneScope scope; | 1699 HandleAndZoneScope scope; |
1663 Isolate* isolate = scope.main_isolate(); | 1700 Isolate* isolate = scope.main_isolate(); |
| 1701 Zone* zone = scope.main_zone(); |
1664 Factory* factory = isolate->factory(); | 1702 Factory* factory = isolate->factory(); |
1665 | 1703 |
1666 ExpectedSnippet<1> snippets[] = { | 1704 ExpectedSnippet<1> snippets[] = { |
1667 {"function Outer() {" | 1705 {"function Outer() {" |
1668 " var outerVar = 2;" | 1706 " var outerVar = 2;" |
1669 " function Inner(innerArg) {" | 1707 " function Inner(innerArg) {" |
1670 " this.innerFunc = function () {" | 1708 " this.innerFunc = function () {" |
1671 " return outerVar * innerArg;" | 1709 " return outerVar * innerArg;" |
1672 " };" | 1710 " };" |
1673 " };" | 1711 " };" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 " }" | 1745 " }" |
1708 "}" | 1746 "}" |
1709 "var f = new testOuter(10).testinnerFunc;" | 1747 "var f = new testOuter(10).testinnerFunc;" |
1710 "f(0);", | 1748 "f(0);", |
1711 {factory->NewNumberFromInt(24), factory->NewNumberFromInt(4)}}}; | 1749 {factory->NewNumberFromInt(24), factory->NewNumberFromInt(4)}}}; |
1712 | 1750 |
1713 for (size_t i = 0; i < arraysize(snippets); i++) { | 1751 for (size_t i = 0; i < arraysize(snippets); i++) { |
1714 ScopedVector<char> script(1024); | 1752 ScopedVector<char> script(1024); |
1715 SNPrintF(script, "%s", snippets[i].code_snippet); | 1753 SNPrintF(script, "%s", snippets[i].code_snippet); |
1716 | 1754 |
1717 BytecodeGraphTester tester(isolate, script.start(), "*"); | 1755 BytecodeGraphTester tester(isolate, zone, script.start(), "*"); |
1718 auto callable = tester.GetCallable<Handle<Object>>("f"); | 1756 auto callable = tester.GetCallable<Handle<Object>>("f"); |
1719 Handle<Object> return_value = | 1757 Handle<Object> return_value = |
1720 callable(snippets[i].parameter(0)).ToHandleChecked(); | 1758 callable(snippets[i].parameter(0)).ToHandleChecked(); |
1721 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1759 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1722 } | 1760 } |
1723 } | 1761 } |
1724 | 1762 |
1725 | 1763 |
1726 TEST(BytecodeGraphBuilderCreateArgumentsNoParameters) { | 1764 TEST(BytecodeGraphBuilderCreateArgumentsNoParameters) { |
1727 HandleAndZoneScope scope; | 1765 HandleAndZoneScope scope; |
1728 Isolate* isolate = scope.main_isolate(); | 1766 Isolate* isolate = scope.main_isolate(); |
| 1767 Zone* zone = scope.main_zone(); |
1729 Factory* factory = isolate->factory(); | 1768 Factory* factory = isolate->factory(); |
1730 | 1769 |
1731 ExpectedSnippet<0> snippets[] = { | 1770 ExpectedSnippet<0> snippets[] = { |
1732 {"function f() {return arguments[0];}", {factory->undefined_value()}}, | 1771 {"function f() {return arguments[0];}", {factory->undefined_value()}}, |
1733 {"function f(a) {return arguments[0];}", {factory->undefined_value()}}, | 1772 {"function f(a) {return arguments[0];}", {factory->undefined_value()}}, |
1734 {"function f() {'use strict'; return arguments[0];}", | 1773 {"function f() {'use strict'; return arguments[0];}", |
1735 {factory->undefined_value()}}, | 1774 {factory->undefined_value()}}, |
1736 {"function f(a) {'use strict'; return arguments[0];}", | 1775 {"function f(a) {'use strict'; return arguments[0];}", |
1737 {factory->undefined_value()}}, | 1776 {factory->undefined_value()}}, |
1738 {"function f(...restArgs) {return restArgs[0];}", | 1777 {"function f(...restArgs) {return restArgs[0];}", |
1739 {factory->undefined_value()}}, | 1778 {factory->undefined_value()}}, |
1740 {"function f(a, ...restArgs) {return restArgs[0];}", | 1779 {"function f(a, ...restArgs) {return restArgs[0];}", |
1741 {factory->undefined_value()}}, | 1780 {factory->undefined_value()}}, |
1742 }; | 1781 }; |
1743 | 1782 |
1744 for (size_t i = 0; i < arraysize(snippets); i++) { | 1783 for (size_t i = 0; i < arraysize(snippets); i++) { |
1745 ScopedVector<char> script(1024); | 1784 ScopedVector<char> script(1024); |
1746 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); | 1785 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); |
1747 | 1786 |
1748 BytecodeGraphTester tester(isolate, script.start()); | 1787 BytecodeGraphTester tester(isolate, zone, script.start()); |
1749 auto callable = tester.GetCallable<>(); | 1788 auto callable = tester.GetCallable<>(); |
1750 Handle<Object> return_value = callable().ToHandleChecked(); | 1789 Handle<Object> return_value = callable().ToHandleChecked(); |
1751 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1790 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1752 } | 1791 } |
1753 } | 1792 } |
1754 | 1793 |
1755 | 1794 |
1756 TEST(BytecodeGraphBuilderCreateArguments) { | 1795 TEST(BytecodeGraphBuilderCreateArguments) { |
1757 HandleAndZoneScope scope; | 1796 HandleAndZoneScope scope; |
1758 Isolate* isolate = scope.main_isolate(); | 1797 Isolate* isolate = scope.main_isolate(); |
| 1798 Zone* zone = scope.main_zone(); |
1759 Factory* factory = isolate->factory(); | 1799 Factory* factory = isolate->factory(); |
1760 | 1800 |
1761 ExpectedSnippet<3> snippets[] = { | 1801 ExpectedSnippet<3> snippets[] = { |
1762 {"function f(a, b, c) {return arguments[0];}", | 1802 {"function f(a, b, c) {return arguments[0];}", |
1763 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(1), | 1803 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(1), |
1764 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1804 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1765 {"function f(a, b, c) {return arguments[3];}", | 1805 {"function f(a, b, c) {return arguments[3];}", |
1766 {factory->undefined_value(), factory->NewNumberFromInt(1), | 1806 {factory->undefined_value(), factory->NewNumberFromInt(1), |
1767 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1807 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1768 {"function f(a, b, c) { b = c; return arguments[1];}", | 1808 {"function f(a, b, c) { b = c; return arguments[1];}", |
(...skipping 11 matching lines...) Expand all Loading... |
1780 {"function inline_func(a, b) { return arguments[0] }" | 1820 {"function inline_func(a, b) { return arguments[0] }" |
1781 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}", | 1821 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}", |
1782 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), | 1822 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), |
1783 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}}, | 1823 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}}, |
1784 }; | 1824 }; |
1785 | 1825 |
1786 for (size_t i = 0; i < arraysize(snippets); i++) { | 1826 for (size_t i = 0; i < arraysize(snippets); i++) { |
1787 ScopedVector<char> script(1024); | 1827 ScopedVector<char> script(1024); |
1788 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); | 1828 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); |
1789 | 1829 |
1790 BytecodeGraphTester tester(isolate, script.start()); | 1830 BytecodeGraphTester tester(isolate, zone, script.start()); |
1791 auto callable = | 1831 auto callable = |
1792 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 1832 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
1793 Handle<Object> return_value = | 1833 Handle<Object> return_value = |
1794 callable(snippets[i].parameter(0), snippets[i].parameter(1), | 1834 callable(snippets[i].parameter(0), snippets[i].parameter(1), |
1795 snippets[i].parameter(2)) | 1835 snippets[i].parameter(2)) |
1796 .ToHandleChecked(); | 1836 .ToHandleChecked(); |
1797 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1837 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1798 } | 1838 } |
1799 } | 1839 } |
1800 | 1840 |
1801 TEST(BytecodeGraphBuilderCreateRestArguments) { | 1841 TEST(BytecodeGraphBuilderCreateRestArguments) { |
1802 HandleAndZoneScope scope; | 1842 HandleAndZoneScope scope; |
1803 Isolate* isolate = scope.main_isolate(); | 1843 Isolate* isolate = scope.main_isolate(); |
| 1844 Zone* zone = scope.main_zone(); |
1804 Factory* factory = isolate->factory(); | 1845 Factory* factory = isolate->factory(); |
1805 | 1846 |
1806 ExpectedSnippet<3> snippets[] = { | 1847 ExpectedSnippet<3> snippets[] = { |
1807 {"function f(...restArgs) {return restArgs[0];}", | 1848 {"function f(...restArgs) {return restArgs[0];}", |
1808 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(1), | 1849 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(1), |
1809 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1850 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1810 {"function f(a, b, ...restArgs) {return restArgs[0];}", | 1851 {"function f(a, b, ...restArgs) {return restArgs[0];}", |
1811 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), | 1852 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), |
1812 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1853 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1813 {"function f(a, b, ...restArgs) {return arguments[2];}", | 1854 {"function f(a, b, ...restArgs) {return arguments[2];}", |
1814 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), | 1855 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), |
1815 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1856 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1816 {"function f(a, ...restArgs) { return restArgs[2];}", | 1857 {"function f(a, ...restArgs) { return restArgs[2];}", |
1817 {factory->undefined_value(), factory->NewNumberFromInt(1), | 1858 {factory->undefined_value(), factory->NewNumberFromInt(1), |
1818 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1859 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1819 {"function f(a, ...restArgs) { return arguments[0] + restArgs[1];}", | 1860 {"function f(a, ...restArgs) { return arguments[0] + restArgs[1];}", |
1820 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(1), | 1861 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(1), |
1821 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, | 1862 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, |
1822 {"function inline_func(a, ...restArgs) { return restArgs[0] }" | 1863 {"function inline_func(a, ...restArgs) { return restArgs[0] }" |
1823 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}", | 1864 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}", |
1824 {factory->NewNumberFromInt(31), factory->NewNumberFromInt(1), | 1865 {factory->NewNumberFromInt(31), factory->NewNumberFromInt(1), |
1825 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}}, | 1866 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}}, |
1826 }; | 1867 }; |
1827 | 1868 |
1828 for (size_t i = 0; i < arraysize(snippets); i++) { | 1869 for (size_t i = 0; i < arraysize(snippets); i++) { |
1829 ScopedVector<char> script(1024); | 1870 ScopedVector<char> script(1024); |
1830 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); | 1871 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); |
1831 | 1872 |
1832 BytecodeGraphTester tester(isolate, script.start()); | 1873 BytecodeGraphTester tester(isolate, zone, script.start()); |
1833 auto callable = | 1874 auto callable = |
1834 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); | 1875 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
1835 Handle<Object> return_value = | 1876 Handle<Object> return_value = |
1836 callable(snippets[i].parameter(0), snippets[i].parameter(1), | 1877 callable(snippets[i].parameter(0), snippets[i].parameter(1), |
1837 snippets[i].parameter(2)) | 1878 snippets[i].parameter(2)) |
1838 .ToHandleChecked(); | 1879 .ToHandleChecked(); |
1839 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1880 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1840 } | 1881 } |
1841 } | 1882 } |
1842 | 1883 |
1843 TEST(BytecodeGraphBuilderRegExpLiterals) { | 1884 TEST(BytecodeGraphBuilderRegExpLiterals) { |
1844 HandleAndZoneScope scope; | 1885 HandleAndZoneScope scope; |
1845 Isolate* isolate = scope.main_isolate(); | 1886 Isolate* isolate = scope.main_isolate(); |
| 1887 Zone* zone = scope.main_zone(); |
1846 Factory* factory = isolate->factory(); | 1888 Factory* factory = isolate->factory(); |
1847 | 1889 |
1848 ExpectedSnippet<0> snippets[] = { | 1890 ExpectedSnippet<0> snippets[] = { |
1849 {"return /abd/.exec('cccabbdd');", {factory->null_value()}}, | 1891 {"return /abd/.exec('cccabbdd');", {factory->null_value()}}, |
1850 {"return /ab+d/.exec('cccabbdd')[0];", | 1892 {"return /ab+d/.exec('cccabbdd')[0];", |
1851 {factory->NewStringFromStaticChars("abbd")}}, | 1893 {factory->NewStringFromStaticChars("abbd")}}, |
1852 {"var a = 3.1414;" | 1894 {"var a = 3.1414;" |
1853 REPEAT_256(SPACE, "a = 3.1414;") | 1895 REPEAT_256(SPACE, "a = 3.1414;") |
1854 "return /ab+d/.exec('cccabbdd')[0];", | 1896 "return /ab+d/.exec('cccabbdd')[0];", |
1855 {factory->NewStringFromStaticChars("abbd")}}, | 1897 {factory->NewStringFromStaticChars("abbd")}}, |
1856 {"return /ab+d/.exec('cccabbdd')[1];", {factory->undefined_value()}}, | 1898 {"return /ab+d/.exec('cccabbdd')[1];", {factory->undefined_value()}}, |
1857 {"return /AbC/i.exec('ssaBC')[0];", | 1899 {"return /AbC/i.exec('ssaBC')[0];", |
1858 {factory->NewStringFromStaticChars("aBC")}}, | 1900 {factory->NewStringFromStaticChars("aBC")}}, |
1859 {"return 'ssaBC'.match(/AbC/i)[0];", | 1901 {"return 'ssaBC'.match(/AbC/i)[0];", |
1860 {factory->NewStringFromStaticChars("aBC")}}, | 1902 {factory->NewStringFromStaticChars("aBC")}}, |
1861 {"return 'ssaBCtAbC'.match(/(AbC)/gi)[1];", | 1903 {"return 'ssaBCtAbC'.match(/(AbC)/gi)[1];", |
1862 {factory->NewStringFromStaticChars("AbC")}}, | 1904 {factory->NewStringFromStaticChars("AbC")}}, |
1863 }; | 1905 }; |
1864 | 1906 |
1865 for (size_t i = 0; i < arraysize(snippets); i++) { | 1907 for (size_t i = 0; i < arraysize(snippets); i++) { |
1866 ScopedVector<char> script(4096); | 1908 ScopedVector<char> script(4096); |
1867 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1909 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1868 snippets[i].code_snippet, kFunctionName); | 1910 snippets[i].code_snippet, kFunctionName); |
1869 | 1911 |
1870 BytecodeGraphTester tester(isolate, script.start()); | 1912 BytecodeGraphTester tester(isolate, zone, script.start()); |
1871 auto callable = tester.GetCallable<>(); | 1913 auto callable = tester.GetCallable<>(); |
1872 Handle<Object> return_value = callable().ToHandleChecked(); | 1914 Handle<Object> return_value = callable().ToHandleChecked(); |
1873 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1915 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1874 } | 1916 } |
1875 } | 1917 } |
1876 | 1918 |
1877 | 1919 |
1878 TEST(BytecodeGraphBuilderArrayLiterals) { | 1920 TEST(BytecodeGraphBuilderArrayLiterals) { |
1879 HandleAndZoneScope scope; | 1921 HandleAndZoneScope scope; |
1880 Isolate* isolate = scope.main_isolate(); | 1922 Isolate* isolate = scope.main_isolate(); |
| 1923 Zone* zone = scope.main_zone(); |
1881 Factory* factory = isolate->factory(); | 1924 Factory* factory = isolate->factory(); |
1882 | 1925 |
1883 ExpectedSnippet<0> snippets[] = { | 1926 ExpectedSnippet<0> snippets[] = { |
1884 {"return [][0];", {factory->undefined_value()}}, | 1927 {"return [][0];", {factory->undefined_value()}}, |
1885 {"return [1, 3, 2][1];", {factory->NewNumberFromInt(3)}}, | 1928 {"return [1, 3, 2][1];", {factory->NewNumberFromInt(3)}}, |
1886 {"var a;" REPEAT_256(SPACE, "a = 9.87;") "return [1, 3, 2][1];", | 1929 {"var a;" REPEAT_256(SPACE, "a = 9.87;") "return [1, 3, 2][1];", |
1887 {factory->NewNumberFromInt(3)}}, | 1930 {factory->NewNumberFromInt(3)}}, |
1888 {"return ['a', 'b', 'c'][2];", {factory->NewStringFromStaticChars("c")}}, | 1931 {"return ['a', 'b', 'c'][2];", {factory->NewStringFromStaticChars("c")}}, |
1889 {"var a = 100; return [a, a++, a + 2, a + 3][2];", | 1932 {"var a = 100; return [a, a++, a + 2, a + 3][2];", |
1890 {factory->NewNumberFromInt(103)}}, | 1933 {factory->NewNumberFromInt(103)}}, |
1891 {"var a = 100; return [a, ++a, a + 2, a + 3][1];", | 1934 {"var a = 100; return [a, ++a, a + 2, a + 3][1];", |
1892 {factory->NewNumberFromInt(101)}}, | 1935 {factory->NewNumberFromInt(101)}}, |
1893 {"var a = 9.2;" | 1936 {"var a = 9.2;" |
1894 REPEAT_256(SPACE, "a = 9.34;") | 1937 REPEAT_256(SPACE, "a = 9.34;") |
1895 "return [a, ++a, a + 2, a + 3][2];", | 1938 "return [a, ++a, a + 2, a + 3][2];", |
1896 {factory->NewHeapNumber(12.34)}}, | 1939 {factory->NewHeapNumber(12.34)}}, |
1897 {"return [[1, 2, 3], ['a', 'b', 'c']][1][0];", | 1940 {"return [[1, 2, 3], ['a', 'b', 'c']][1][0];", |
1898 {factory->NewStringFromStaticChars("a")}}, | 1941 {factory->NewStringFromStaticChars("a")}}, |
1899 {"var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];", | 1942 {"var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];", |
1900 {factory->NewStringFromStaticChars("test")}}, | 1943 {factory->NewStringFromStaticChars("test")}}, |
1901 {"var t = 't'; return [[t, t + 'est'], [1 + t]][1][0];", | 1944 {"var t = 't'; return [[t, t + 'est'], [1 + t]][1][0];", |
1902 {factory->NewStringFromStaticChars("1t")}}}; | 1945 {factory->NewStringFromStaticChars("1t")}}}; |
1903 | 1946 |
1904 for (size_t i = 0; i < arraysize(snippets); i++) { | 1947 for (size_t i = 0; i < arraysize(snippets); i++) { |
1905 ScopedVector<char> script(4096); | 1948 ScopedVector<char> script(4096); |
1906 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 1949 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1907 snippets[i].code_snippet, kFunctionName); | 1950 snippets[i].code_snippet, kFunctionName); |
1908 | 1951 |
1909 BytecodeGraphTester tester(isolate, script.start()); | 1952 BytecodeGraphTester tester(isolate, zone, script.start()); |
1910 auto callable = tester.GetCallable<>(); | 1953 auto callable = tester.GetCallable<>(); |
1911 Handle<Object> return_value = callable().ToHandleChecked(); | 1954 Handle<Object> return_value = callable().ToHandleChecked(); |
1912 CHECK(return_value->SameValue(*snippets[i].return_value())); | 1955 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1913 } | 1956 } |
1914 } | 1957 } |
1915 | 1958 |
1916 | 1959 |
1917 TEST(BytecodeGraphBuilderObjectLiterals) { | 1960 TEST(BytecodeGraphBuilderObjectLiterals) { |
1918 HandleAndZoneScope scope; | 1961 HandleAndZoneScope scope; |
1919 Isolate* isolate = scope.main_isolate(); | 1962 Isolate* isolate = scope.main_isolate(); |
| 1963 Zone* zone = scope.main_zone(); |
1920 Factory* factory = isolate->factory(); | 1964 Factory* factory = isolate->factory(); |
1921 | 1965 |
1922 ExpectedSnippet<0> snippets[] = { | 1966 ExpectedSnippet<0> snippets[] = { |
1923 {"return { }.name;", {factory->undefined_value()}}, | 1967 {"return { }.name;", {factory->undefined_value()}}, |
1924 {"return { name: 'string', val: 9.2 }.name;", | 1968 {"return { name: 'string', val: 9.2 }.name;", |
1925 {factory->NewStringFromStaticChars("string")}}, | 1969 {factory->NewStringFromStaticChars("string")}}, |
1926 {"var a;\n" | 1970 {"var a;\n" |
1927 REPEAT_256(SPACE, "a = 1.23;\n") | 1971 REPEAT_256(SPACE, "a = 1.23;\n") |
1928 "return { name: 'string', val: 9.2 }.name;", | 1972 "return { name: 'string', val: 9.2 }.name;", |
1929 {factory->NewStringFromStaticChars("string")}}, | 1973 {factory->NewStringFromStaticChars("string")}}, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 {factory->NewStringFromStaticChars("proto_str")}}, | 2006 {factory->NewStringFromStaticChars("proto_str")}}, |
1963 {"var n = 'name';\n" | 2007 {"var n = 'name';\n" |
1964 "return { [n]: 'val', get a() { return 987 } }['a'];", | 2008 "return { [n]: 'val', get a() { return 987 } }['a'];", |
1965 {factory->NewNumberFromInt(987)}}, | 2009 {factory->NewNumberFromInt(987)}}, |
1966 }; | 2010 }; |
1967 | 2011 |
1968 for (size_t i = 0; i < arraysize(snippets); i++) { | 2012 for (size_t i = 0; i < arraysize(snippets); i++) { |
1969 ScopedVector<char> script(4096); | 2013 ScopedVector<char> script(4096); |
1970 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2014 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
1971 snippets[i].code_snippet, kFunctionName); | 2015 snippets[i].code_snippet, kFunctionName); |
1972 BytecodeGraphTester tester(isolate, script.start()); | 2016 BytecodeGraphTester tester(isolate, zone, script.start()); |
1973 auto callable = tester.GetCallable<>(); | 2017 auto callable = tester.GetCallable<>(); |
1974 Handle<Object> return_value = callable().ToHandleChecked(); | 2018 Handle<Object> return_value = callable().ToHandleChecked(); |
1975 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2019 CHECK(return_value->SameValue(*snippets[i].return_value())); |
1976 } | 2020 } |
1977 } | 2021 } |
1978 | 2022 |
1979 | 2023 |
1980 TEST(BytecodeGraphBuilderIf) { | 2024 TEST(BytecodeGraphBuilderIf) { |
1981 HandleAndZoneScope scope; | 2025 HandleAndZoneScope scope; |
1982 Isolate* isolate = scope.main_isolate(); | 2026 Isolate* isolate = scope.main_isolate(); |
| 2027 Zone* zone = scope.main_zone(); |
1983 Factory* factory = isolate->factory(); | 2028 Factory* factory = isolate->factory(); |
1984 | 2029 |
1985 ExpectedSnippet<1> snippets[] = { | 2030 ExpectedSnippet<1> snippets[] = { |
1986 {"if (p1 > 1) return 1;\n" | 2031 {"if (p1 > 1) return 1;\n" |
1987 "return -1;", | 2032 "return -1;", |
1988 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(2)}}, | 2033 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(2)}}, |
1989 {"if (p1 > 1) return 1;\n" | 2034 {"if (p1 > 1) return 1;\n" |
1990 "return -1;", | 2035 "return -1;", |
1991 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(1)}}, | 2036 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(1)}}, |
1992 {"if (p1 > 1) { return 1; } else { return -1; }", | 2037 {"if (p1 > 1) { return 1; } else { return -1; }", |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 "function f1() {x}" | 2115 "function f1() {x}" |
2071 "return x + c;", | 2116 "return x + c;", |
2072 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(-1)}}, | 2117 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(-1)}}, |
2073 }; | 2118 }; |
2074 | 2119 |
2075 for (size_t i = 0; i < arraysize(snippets); i++) { | 2120 for (size_t i = 0; i < arraysize(snippets); i++) { |
2076 ScopedVector<char> script(2048); | 2121 ScopedVector<char> script(2048); |
2077 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, | 2122 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, |
2078 snippets[i].code_snippet, kFunctionName); | 2123 snippets[i].code_snippet, kFunctionName); |
2079 | 2124 |
2080 BytecodeGraphTester tester(isolate, script.start()); | 2125 BytecodeGraphTester tester(isolate, zone, script.start()); |
2081 auto callable = tester.GetCallable<Handle<Object>>(); | 2126 auto callable = tester.GetCallable<Handle<Object>>(); |
2082 Handle<Object> return_value = | 2127 Handle<Object> return_value = |
2083 callable(snippets[i].parameter(0)).ToHandleChecked(); | 2128 callable(snippets[i].parameter(0)).ToHandleChecked(); |
2084 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2129 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2085 } | 2130 } |
2086 } | 2131 } |
2087 | 2132 |
2088 | 2133 |
2089 TEST(BytecodeGraphBuilderConditionalOperator) { | 2134 TEST(BytecodeGraphBuilderConditionalOperator) { |
2090 HandleAndZoneScope scope; | 2135 HandleAndZoneScope scope; |
2091 Isolate* isolate = scope.main_isolate(); | 2136 Isolate* isolate = scope.main_isolate(); |
| 2137 Zone* zone = scope.main_zone(); |
2092 Factory* factory = isolate->factory(); | 2138 Factory* factory = isolate->factory(); |
2093 | 2139 |
2094 ExpectedSnippet<1> snippets[] = { | 2140 ExpectedSnippet<1> snippets[] = { |
2095 {"return (p1 > 1) ? 1 : -1;", | 2141 {"return (p1 > 1) ? 1 : -1;", |
2096 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(2)}}, | 2142 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(2)}}, |
2097 {"return (p1 > 1) ? 1 : -1;", | 2143 {"return (p1 > 1) ? 1 : -1;", |
2098 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(0)}}, | 2144 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(0)}}, |
2099 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);", | 2145 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);", |
2100 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(2)}}, | 2146 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(2)}}, |
2101 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);", | 2147 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);", |
2102 {factory->NewNumberFromInt(-10), factory->NewNumberFromInt(20)}}, | 2148 {factory->NewNumberFromInt(-10), factory->NewNumberFromInt(20)}}, |
2103 }; | 2149 }; |
2104 | 2150 |
2105 for (size_t i = 0; i < arraysize(snippets); i++) { | 2151 for (size_t i = 0; i < arraysize(snippets); i++) { |
2106 ScopedVector<char> script(2048); | 2152 ScopedVector<char> script(2048); |
2107 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, | 2153 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, |
2108 snippets[i].code_snippet, kFunctionName); | 2154 snippets[i].code_snippet, kFunctionName); |
2109 | 2155 |
2110 BytecodeGraphTester tester(isolate, script.start()); | 2156 BytecodeGraphTester tester(isolate, zone, script.start()); |
2111 auto callable = tester.GetCallable<Handle<Object>>(); | 2157 auto callable = tester.GetCallable<Handle<Object>>(); |
2112 Handle<Object> return_value = | 2158 Handle<Object> return_value = |
2113 callable(snippets[i].parameter(0)).ToHandleChecked(); | 2159 callable(snippets[i].parameter(0)).ToHandleChecked(); |
2114 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2160 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2115 } | 2161 } |
2116 } | 2162 } |
2117 | 2163 |
2118 | 2164 |
2119 TEST(BytecodeGraphBuilderSwitch) { | 2165 TEST(BytecodeGraphBuilderSwitch) { |
2120 HandleAndZoneScope scope; | 2166 HandleAndZoneScope scope; |
2121 Isolate* isolate = scope.main_isolate(); | 2167 Isolate* isolate = scope.main_isolate(); |
| 2168 Zone* zone = scope.main_zone(); |
2122 Factory* factory = isolate->factory(); | 2169 Factory* factory = isolate->factory(); |
2123 | 2170 |
2124 const char* switch_code = | 2171 const char* switch_code = |
2125 "switch (p1) {\n" | 2172 "switch (p1) {\n" |
2126 " case 1: return 0;\n" | 2173 " case 1: return 0;\n" |
2127 " case 2: return 1;\n" | 2174 " case 2: return 1;\n" |
2128 " case 3:\n" | 2175 " case 3:\n" |
2129 " case 4: return 2;\n" | 2176 " case 4: return 2;\n" |
2130 " case 9: break;\n" | 2177 " case 9: break;\n" |
2131 " default: return 3;\n" | 2178 " default: return 3;\n" |
(...skipping 15 matching lines...) Expand all Loading... |
2147 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(5)}}, | 2194 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(5)}}, |
2148 {switch_code, | 2195 {switch_code, |
2149 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(6)}}, | 2196 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(6)}}, |
2150 }; | 2197 }; |
2151 | 2198 |
2152 for (size_t i = 0; i < arraysize(snippets); i++) { | 2199 for (size_t i = 0; i < arraysize(snippets); i++) { |
2153 ScopedVector<char> script(2048); | 2200 ScopedVector<char> script(2048); |
2154 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, | 2201 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, |
2155 snippets[i].code_snippet, kFunctionName); | 2202 snippets[i].code_snippet, kFunctionName); |
2156 | 2203 |
2157 BytecodeGraphTester tester(isolate, script.start()); | 2204 BytecodeGraphTester tester(isolate, zone, script.start()); |
2158 auto callable = tester.GetCallable<Handle<Object>>(); | 2205 auto callable = tester.GetCallable<Handle<Object>>(); |
2159 Handle<Object> return_value = | 2206 Handle<Object> return_value = |
2160 callable(snippets[i].parameter(0)).ToHandleChecked(); | 2207 callable(snippets[i].parameter(0)).ToHandleChecked(); |
2161 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2208 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2162 } | 2209 } |
2163 } | 2210 } |
2164 | 2211 |
2165 TEST(BytecodeGraphBuilderSwitchMerge) { | 2212 TEST(BytecodeGraphBuilderSwitchMerge) { |
2166 HandleAndZoneScope scope; | 2213 HandleAndZoneScope scope; |
2167 Isolate* isolate = scope.main_isolate(); | 2214 Isolate* isolate = scope.main_isolate(); |
| 2215 Zone* zone = scope.main_zone(); |
2168 Factory* factory = isolate->factory(); | 2216 Factory* factory = isolate->factory(); |
2169 | 2217 |
2170 const char* switch_code = | 2218 const char* switch_code = |
2171 "var x = 10;" | 2219 "var x = 10;" |
2172 "switch (p1) {\n" | 2220 "switch (p1) {\n" |
2173 " case 1: x = 0;\n" | 2221 " case 1: x = 0;\n" |
2174 " case 2: x = 1;\n" | 2222 " case 2: x = 1;\n" |
2175 " case 3:\n" | 2223 " case 3:\n" |
2176 " case 4: x = 2; break;\n" | 2224 " case 4: x = 2; break;\n" |
2177 " case 5: x = 3;\n" | 2225 " case 5: x = 3;\n" |
(...skipping 17 matching lines...) Expand all Loading... |
2195 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(9)}}, | 2243 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(9)}}, |
2196 {switch_code, | 2244 {switch_code, |
2197 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(6)}}, | 2245 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(6)}}, |
2198 }; | 2246 }; |
2199 | 2247 |
2200 for (size_t i = 0; i < arraysize(snippets); i++) { | 2248 for (size_t i = 0; i < arraysize(snippets); i++) { |
2201 ScopedVector<char> script(2048); | 2249 ScopedVector<char> script(2048); |
2202 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, | 2250 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, |
2203 snippets[i].code_snippet, kFunctionName); | 2251 snippets[i].code_snippet, kFunctionName); |
2204 | 2252 |
2205 BytecodeGraphTester tester(isolate, script.start()); | 2253 BytecodeGraphTester tester(isolate, zone, script.start()); |
2206 auto callable = tester.GetCallable<Handle<Object>>(); | 2254 auto callable = tester.GetCallable<Handle<Object>>(); |
2207 Handle<Object> return_value = | 2255 Handle<Object> return_value = |
2208 callable(snippets[i].parameter(0)).ToHandleChecked(); | 2256 callable(snippets[i].parameter(0)).ToHandleChecked(); |
2209 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2257 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2210 } | 2258 } |
2211 } | 2259 } |
2212 | 2260 |
2213 TEST(BytecodeGraphBuilderNestedSwitch) { | 2261 TEST(BytecodeGraphBuilderNestedSwitch) { |
2214 HandleAndZoneScope scope; | 2262 HandleAndZoneScope scope; |
2215 Isolate* isolate = scope.main_isolate(); | 2263 Isolate* isolate = scope.main_isolate(); |
| 2264 Zone* zone = scope.main_zone(); |
2216 Factory* factory = isolate->factory(); | 2265 Factory* factory = isolate->factory(); |
2217 | 2266 |
2218 const char* switch_code = | 2267 const char* switch_code = |
2219 "switch (p1) {\n" | 2268 "switch (p1) {\n" |
2220 " case 0: {" | 2269 " case 0: {" |
2221 " switch (p2) { case 0: return 0; case 1: return 1; case 2: break; }\n" | 2270 " switch (p2) { case 0: return 0; case 1: return 1; case 2: break; }\n" |
2222 " return -1;" | 2271 " return -1;" |
2223 " }\n" | 2272 " }\n" |
2224 " case 1: {" | 2273 " case 1: {" |
2225 " switch (p2) { case 0: return 2; case 1: return 3; }\n" | 2274 " switch (p2) { case 0: return 2; case 1: return 3; }\n" |
(...skipping 27 matching lines...) Expand all Loading... |
2253 {switch_code, | 2302 {switch_code, |
2254 {factory->NewNumberFromInt(-2), factory->NewNumberFromInt(2), | 2303 {factory->NewNumberFromInt(-2), factory->NewNumberFromInt(2), |
2255 factory->NewNumberFromInt(0)}}, | 2304 factory->NewNumberFromInt(0)}}, |
2256 }; | 2305 }; |
2257 | 2306 |
2258 for (size_t i = 0; i < arraysize(snippets); i++) { | 2307 for (size_t i = 0; i < arraysize(snippets); i++) { |
2259 ScopedVector<char> script(2048); | 2308 ScopedVector<char> script(2048); |
2260 SNPrintF(script, "function %s(p1, p2) { %s };\n%s(0, 0);", kFunctionName, | 2309 SNPrintF(script, "function %s(p1, p2) { %s };\n%s(0, 0);", kFunctionName, |
2261 snippets[i].code_snippet, kFunctionName); | 2310 snippets[i].code_snippet, kFunctionName); |
2262 | 2311 |
2263 BytecodeGraphTester tester(isolate, script.start()); | 2312 BytecodeGraphTester tester(isolate, zone, script.start()); |
2264 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); | 2313 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); |
2265 Handle<Object> return_value = | 2314 Handle<Object> return_value = |
2266 callable(snippets[i].parameter(0), snippets[i].parameter(1)) | 2315 callable(snippets[i].parameter(0), snippets[i].parameter(1)) |
2267 .ToHandleChecked(); | 2316 .ToHandleChecked(); |
2268 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2317 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2269 } | 2318 } |
2270 } | 2319 } |
2271 | 2320 |
2272 | 2321 |
2273 TEST(BytecodeGraphBuilderBreakableBlocks) { | 2322 TEST(BytecodeGraphBuilderBreakableBlocks) { |
2274 HandleAndZoneScope scope; | 2323 HandleAndZoneScope scope; |
2275 Isolate* isolate = scope.main_isolate(); | 2324 Isolate* isolate = scope.main_isolate(); |
| 2325 Zone* zone = scope.main_zone(); |
2276 Factory* factory = isolate->factory(); | 2326 Factory* factory = isolate->factory(); |
2277 | 2327 |
2278 ExpectedSnippet<0> snippets[] = { | 2328 ExpectedSnippet<0> snippets[] = { |
2279 {"var x = 0;\n" | 2329 {"var x = 0;\n" |
2280 "my_heart: {\n" | 2330 "my_heart: {\n" |
2281 " x = x + 1;\n" | 2331 " x = x + 1;\n" |
2282 " break my_heart;\n" | 2332 " break my_heart;\n" |
2283 " x = x + 2;\n" | 2333 " x = x + 2;\n" |
2284 "}\n" | 2334 "}\n" |
2285 "return x;\n", | 2335 "return x;\n", |
2286 {factory->NewNumberFromInt(1)}}, | 2336 {factory->NewNumberFromInt(1)}}, |
2287 {"var sum = 0;\n" | 2337 {"var sum = 0;\n" |
2288 "outta_here: {\n" | 2338 "outta_here: {\n" |
2289 " for (var x = 0; x < 10; ++x) {\n" | 2339 " for (var x = 0; x < 10; ++x) {\n" |
2290 " for (var y = 0; y < 3; ++y) {\n" | 2340 " for (var y = 0; y < 3; ++y) {\n" |
2291 " ++sum;\n" | 2341 " ++sum;\n" |
2292 " if (x + y == 12) { break outta_here; }\n" | 2342 " if (x + y == 12) { break outta_here; }\n" |
2293 " }\n" | 2343 " }\n" |
2294 " }\n" | 2344 " }\n" |
2295 "}\n" | 2345 "}\n" |
2296 "return sum;", | 2346 "return sum;", |
2297 {factory->NewNumber(30)}}, | 2347 {factory->NewNumber(30)}}, |
2298 }; | 2348 }; |
2299 | 2349 |
2300 for (size_t i = 0; i < arraysize(snippets); i++) { | 2350 for (size_t i = 0; i < arraysize(snippets); i++) { |
2301 ScopedVector<char> script(1024); | 2351 ScopedVector<char> script(1024); |
2302 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2352 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2303 snippets[i].code_snippet, kFunctionName); | 2353 snippets[i].code_snippet, kFunctionName); |
2304 | 2354 |
2305 BytecodeGraphTester tester(isolate, script.start()); | 2355 BytecodeGraphTester tester(isolate, zone, script.start()); |
2306 auto callable = tester.GetCallable<>(); | 2356 auto callable = tester.GetCallable<>(); |
2307 Handle<Object> return_value = callable().ToHandleChecked(); | 2357 Handle<Object> return_value = callable().ToHandleChecked(); |
2308 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2358 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2309 } | 2359 } |
2310 } | 2360 } |
2311 | 2361 |
2312 | 2362 |
2313 TEST(BytecodeGraphBuilderWhile) { | 2363 TEST(BytecodeGraphBuilderWhile) { |
2314 HandleAndZoneScope scope; | 2364 HandleAndZoneScope scope; |
2315 Isolate* isolate = scope.main_isolate(); | 2365 Isolate* isolate = scope.main_isolate(); |
| 2366 Zone* zone = scope.main_zone(); |
2316 Factory* factory = isolate->factory(); | 2367 Factory* factory = isolate->factory(); |
2317 | 2368 |
2318 ExpectedSnippet<0> snippets[] = { | 2369 ExpectedSnippet<0> snippets[] = { |
2319 {"var x = 1; while (x < 1) { x *= 100; } return x;", | 2370 {"var x = 1; while (x < 1) { x *= 100; } return x;", |
2320 {factory->NewNumberFromInt(1)}}, | 2371 {factory->NewNumberFromInt(1)}}, |
2321 {"var x = 1, y = 0; while (x < 7) { y += x * x; x += 1; } return y;", | 2372 {"var x = 1, y = 0; while (x < 7) { y += x * x; x += 1; } return y;", |
2322 {factory->NewNumberFromInt(91)}}, | 2373 {factory->NewNumberFromInt(91)}}, |
2323 {"var x = 1; while (true) { x += 1; if (x == 10) break; } return x;", | 2374 {"var x = 1; while (true) { x += 1; if (x == 10) break; } return x;", |
2324 {factory->NewNumberFromInt(10)}}, | 2375 {factory->NewNumberFromInt(10)}}, |
2325 {"var x = 1; while (false) { x += 1; } return x;", | 2376 {"var x = 1; while (false) { x += 1; } return x;", |
(...skipping 17 matching lines...) Expand all Loading... |
2343 " if (x == 4) break;\n" | 2394 " if (x == 4) break;\n" |
2344 "}\n" | 2395 "}\n" |
2345 "return y;", | 2396 "return y;", |
2346 {factory->NewNumberFromInt(16)}}}; | 2397 {factory->NewNumberFromInt(16)}}}; |
2347 | 2398 |
2348 for (size_t i = 0; i < arraysize(snippets); i++) { | 2399 for (size_t i = 0; i < arraysize(snippets); i++) { |
2349 ScopedVector<char> script(1024); | 2400 ScopedVector<char> script(1024); |
2350 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2401 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2351 snippets[i].code_snippet, kFunctionName); | 2402 snippets[i].code_snippet, kFunctionName); |
2352 | 2403 |
2353 BytecodeGraphTester tester(isolate, script.start()); | 2404 BytecodeGraphTester tester(isolate, zone, script.start()); |
2354 auto callable = tester.GetCallable<>(); | 2405 auto callable = tester.GetCallable<>(); |
2355 Handle<Object> return_value = callable().ToHandleChecked(); | 2406 Handle<Object> return_value = callable().ToHandleChecked(); |
2356 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2407 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2357 } | 2408 } |
2358 } | 2409 } |
2359 | 2410 |
2360 | 2411 |
2361 TEST(BytecodeGraphBuilderDo) { | 2412 TEST(BytecodeGraphBuilderDo) { |
2362 HandleAndZoneScope scope; | 2413 HandleAndZoneScope scope; |
2363 Isolate* isolate = scope.main_isolate(); | 2414 Isolate* isolate = scope.main_isolate(); |
| 2415 Zone* zone = scope.main_zone(); |
2364 Factory* factory = isolate->factory(); | 2416 Factory* factory = isolate->factory(); |
2365 | 2417 |
2366 ExpectedSnippet<0> snippets[] = { | 2418 ExpectedSnippet<0> snippets[] = { |
2367 {"var x = 1; do { x *= 100; } while (x < 100); return x;", | 2419 {"var x = 1; do { x *= 100; } while (x < 100); return x;", |
2368 {factory->NewNumberFromInt(100)}}, | 2420 {factory->NewNumberFromInt(100)}}, |
2369 {"var x = 1; do { x = x * x + 1; } while (x < 7) return x;", | 2421 {"var x = 1; do { x = x * x + 1; } while (x < 7) return x;", |
2370 {factory->NewNumberFromInt(26)}}, | 2422 {factory->NewNumberFromInt(26)}}, |
2371 {"var x = 1; do { x += 1; } while (false); return x;", | 2423 {"var x = 1; do { x += 1; } while (false); return x;", |
2372 {factory->NewNumberFromInt(2)}}, | 2424 {factory->NewNumberFromInt(2)}}, |
2373 {"var x = 1, y = 0;\n" | 2425 {"var x = 1, y = 0;\n" |
(...skipping 17 matching lines...) Expand all Loading... |
2391 " } while (x < 1)\n" | 2443 " } while (x < 1)\n" |
2392 "} while (sum < 3)\n" | 2444 "} while (sum < 3)\n" |
2393 "return sum;", | 2445 "return sum;", |
2394 {factory->NewNumber(3)}}}; | 2446 {factory->NewNumber(3)}}}; |
2395 | 2447 |
2396 for (size_t i = 0; i < arraysize(snippets); i++) { | 2448 for (size_t i = 0; i < arraysize(snippets); i++) { |
2397 ScopedVector<char> script(1024); | 2449 ScopedVector<char> script(1024); |
2398 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2450 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2399 snippets[i].code_snippet, kFunctionName); | 2451 snippets[i].code_snippet, kFunctionName); |
2400 | 2452 |
2401 BytecodeGraphTester tester(isolate, script.start()); | 2453 BytecodeGraphTester tester(isolate, zone, script.start()); |
2402 auto callable = tester.GetCallable<>(); | 2454 auto callable = tester.GetCallable<>(); |
2403 Handle<Object> return_value = callable().ToHandleChecked(); | 2455 Handle<Object> return_value = callable().ToHandleChecked(); |
2404 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2456 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2405 } | 2457 } |
2406 } | 2458 } |
2407 | 2459 |
2408 | 2460 |
2409 TEST(BytecodeGraphBuilderFor) { | 2461 TEST(BytecodeGraphBuilderFor) { |
2410 HandleAndZoneScope scope; | 2462 HandleAndZoneScope scope; |
2411 Isolate* isolate = scope.main_isolate(); | 2463 Isolate* isolate = scope.main_isolate(); |
| 2464 Zone* zone = scope.main_zone(); |
2412 Factory* factory = isolate->factory(); | 2465 Factory* factory = isolate->factory(); |
2413 | 2466 |
2414 ExpectedSnippet<0> snippets[] = { | 2467 ExpectedSnippet<0> snippets[] = { |
2415 {"for (var x = 0;; x = 2 * x + 1) { if (x > 10) return x; }", | 2468 {"for (var x = 0;; x = 2 * x + 1) { if (x > 10) return x; }", |
2416 {factory->NewNumberFromInt(15)}}, | 2469 {factory->NewNumberFromInt(15)}}, |
2417 {"for (var x = 0; true; x = 2 * x + 1) { if (x > 100) return x; }", | 2470 {"for (var x = 0; true; x = 2 * x + 1) { if (x > 100) return x; }", |
2418 {factory->NewNumberFromInt(127)}}, | 2471 {factory->NewNumberFromInt(127)}}, |
2419 {"for (var x = 0; false; x = 2 * x + 1) { if (x > 100) return x; } " | 2472 {"for (var x = 0; false; x = 2 * x + 1) { if (x > 100) return x; } " |
2420 "return 0;", | 2473 "return 0;", |
2421 {factory->NewNumberFromInt(0)}}, | 2474 {factory->NewNumberFromInt(0)}}, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2484 "}\n" | 2537 "}\n" |
2485 "return sum;", | 2538 "return sum;", |
2486 {factory->NewNumberFromInt(50)}}, | 2539 {factory->NewNumberFromInt(50)}}, |
2487 }; | 2540 }; |
2488 | 2541 |
2489 for (size_t i = 0; i < arraysize(snippets); i++) { | 2542 for (size_t i = 0; i < arraysize(snippets); i++) { |
2490 ScopedVector<char> script(1024); | 2543 ScopedVector<char> script(1024); |
2491 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2544 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2492 snippets[i].code_snippet, kFunctionName); | 2545 snippets[i].code_snippet, kFunctionName); |
2493 | 2546 |
2494 BytecodeGraphTester tester(isolate, script.start()); | 2547 BytecodeGraphTester tester(isolate, zone, script.start()); |
2495 auto callable = tester.GetCallable<>(); | 2548 auto callable = tester.GetCallable<>(); |
2496 Handle<Object> return_value = callable().ToHandleChecked(); | 2549 Handle<Object> return_value = callable().ToHandleChecked(); |
2497 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2550 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2498 } | 2551 } |
2499 } | 2552 } |
2500 | 2553 |
2501 | 2554 |
2502 TEST(BytecodeGraphBuilderForIn) { | 2555 TEST(BytecodeGraphBuilderForIn) { |
2503 HandleAndZoneScope scope; | 2556 HandleAndZoneScope scope; |
2504 Isolate* isolate = scope.main_isolate(); | 2557 Isolate* isolate = scope.main_isolate(); |
| 2558 Zone* zone = scope.main_zone(); |
2505 Factory* factory = isolate->factory(); | 2559 Factory* factory = isolate->factory(); |
2506 ExpectedSnippet<0> snippets[] = { | 2560 ExpectedSnippet<0> snippets[] = { |
2507 {"var sum = 0;\n" | 2561 {"var sum = 0;\n" |
2508 "var empty = null;\n" | 2562 "var empty = null;\n" |
2509 "for (var x in empty) { sum++; }\n" | 2563 "for (var x in empty) { sum++; }\n" |
2510 "return sum;", | 2564 "return sum;", |
2511 {factory->NewNumberFromInt(0)}}, | 2565 {factory->NewNumberFromInt(0)}}, |
2512 {"var sum = 100;\n" | 2566 {"var sum = 100;\n" |
2513 "var empty = 1;\n" | 2567 "var empty = 1;\n" |
2514 "for (var x in empty) { sum++; }\n" | 2568 "for (var x in empty) { sum++; }\n" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2555 "}\n" | 2609 "}\n" |
2556 "return sum;", | 2610 "return sum;", |
2557 {factory->NewNumberFromInt(6)}}, | 2611 {factory->NewNumberFromInt(6)}}, |
2558 }; | 2612 }; |
2559 | 2613 |
2560 for (size_t i = 0; i < arraysize(snippets); i++) { | 2614 for (size_t i = 0; i < arraysize(snippets); i++) { |
2561 ScopedVector<char> script(1024); | 2615 ScopedVector<char> script(1024); |
2562 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2616 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2563 snippets[i].code_snippet, kFunctionName); | 2617 snippets[i].code_snippet, kFunctionName); |
2564 | 2618 |
2565 BytecodeGraphTester tester(isolate, script.start()); | 2619 BytecodeGraphTester tester(isolate, zone, script.start()); |
2566 auto callable = tester.GetCallable<>(); | 2620 auto callable = tester.GetCallable<>(); |
2567 Handle<Object> return_value = callable().ToHandleChecked(); | 2621 Handle<Object> return_value = callable().ToHandleChecked(); |
2568 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2622 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2569 } | 2623 } |
2570 } | 2624 } |
2571 | 2625 |
2572 | 2626 |
2573 TEST(BytecodeGraphBuilderForOf) { | 2627 TEST(BytecodeGraphBuilderForOf) { |
2574 HandleAndZoneScope scope; | 2628 HandleAndZoneScope scope; |
2575 Isolate* isolate = scope.main_isolate(); | 2629 Isolate* isolate = scope.main_isolate(); |
| 2630 Zone* zone = scope.main_zone(); |
2576 Factory* factory = isolate->factory(); | 2631 Factory* factory = isolate->factory(); |
2577 ExpectedSnippet<0> snippets[] = { | 2632 ExpectedSnippet<0> snippets[] = { |
2578 {" var r = 0;\n" | 2633 {" var r = 0;\n" |
2579 " for (var a of [0,6,7,9]) { r += a; }\n" | 2634 " for (var a of [0,6,7,9]) { r += a; }\n" |
2580 " return r;\n", | 2635 " return r;\n", |
2581 {handle(Smi::FromInt(22), isolate)}}, | 2636 {handle(Smi::FromInt(22), isolate)}}, |
2582 {" var r = '';\n" | 2637 {" var r = '';\n" |
2583 " for (var a of 'foobar') { r = a + r; }\n" | 2638 " for (var a of 'foobar') { r = a + r; }\n" |
2584 " return r;\n", | 2639 " return r;\n", |
2585 {factory->NewStringFromStaticChars("raboof")}}, | 2640 {factory->NewStringFromStaticChars("raboof")}}, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2647 " for (a of obj) { r += a }\n" | 2702 " for (a of obj) { r += a }\n" |
2648 " return r;\n", | 2703 " return r;\n", |
2649 {factory->NewStringFromStaticChars("dcba")}}, | 2704 {factory->NewStringFromStaticChars("dcba")}}, |
2650 }; | 2705 }; |
2651 | 2706 |
2652 for (size_t i = 0; i < arraysize(snippets); i++) { | 2707 for (size_t i = 0; i < arraysize(snippets); i++) { |
2653 ScopedVector<char> script(1024); | 2708 ScopedVector<char> script(1024); |
2654 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2709 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2655 snippets[i].code_snippet, kFunctionName); | 2710 snippets[i].code_snippet, kFunctionName); |
2656 | 2711 |
2657 BytecodeGraphTester tester(isolate, script.start()); | 2712 BytecodeGraphTester tester(isolate, zone, script.start()); |
2658 auto callable = tester.GetCallable<>(); | 2713 auto callable = tester.GetCallable<>(); |
2659 Handle<Object> return_value = callable().ToHandleChecked(); | 2714 Handle<Object> return_value = callable().ToHandleChecked(); |
2660 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2715 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2661 } | 2716 } |
2662 } | 2717 } |
2663 | 2718 |
2664 void TestJumpWithConstantsAndWideConstants(size_t shard) { | 2719 void TestJumpWithConstantsAndWideConstants(size_t shard) { |
2665 const int kStep = 46; | 2720 const int kStep = 46; |
2666 int start = static_cast<int>(7 + 17 * shard); | 2721 int start = static_cast<int>(7 + 17 * shard); |
2667 for (int constants = start; constants < 300; constants += kStep) { | 2722 for (int constants = start; constants < 300; constants += kStep) { |
(...skipping 15 matching lines...) Expand all Loading... |
2683 script_os << " else { " << filler << " }\n"; | 2738 script_os << " else { " << filler << " }\n"; |
2684 script_os << " }\n"; | 2739 script_os << " }\n"; |
2685 script_os << " return i;\n"; | 2740 script_os << " return i;\n"; |
2686 script_os << "}\n"; | 2741 script_os << "}\n"; |
2687 script_os << kFunctionName << "(0);\n"; | 2742 script_os << kFunctionName << "(0);\n"; |
2688 std::string script(script_os.str()); | 2743 std::string script(script_os.str()); |
2689 | 2744 |
2690 HandleAndZoneScope scope; | 2745 HandleAndZoneScope scope; |
2691 auto isolate = scope.main_isolate(); | 2746 auto isolate = scope.main_isolate(); |
2692 auto factory = isolate->factory(); | 2747 auto factory = isolate->factory(); |
2693 BytecodeGraphTester tester(isolate, script.c_str()); | 2748 auto zone = scope.main_zone(); |
| 2749 BytecodeGraphTester tester(isolate, zone, script.c_str()); |
2694 auto callable = tester.GetCallable<Handle<Object>>(); | 2750 auto callable = tester.GetCallable<Handle<Object>>(); |
2695 for (int a = 0; a < 3; a++) { | 2751 for (int a = 0; a < 3; a++) { |
2696 Handle<Object> return_val = | 2752 Handle<Object> return_val = |
2697 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); | 2753 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); |
2698 static const int results[] = {11, 12, 2}; | 2754 static const int results[] = {11, 12, 2}; |
2699 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); | 2755 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); |
2700 } | 2756 } |
2701 } | 2757 } |
2702 } | 2758 } |
2703 | 2759 |
2704 SHARD_TEST_BY_4(JumpWithConstantsAndWideConstants) | 2760 SHARD_TEST_BY_4(JumpWithConstantsAndWideConstants) |
2705 | 2761 |
2706 TEST(BytecodeGraphBuilderDoExpressions) { | 2762 TEST(BytecodeGraphBuilderDoExpressions) { |
2707 bool old_flag = FLAG_harmony_do_expressions; | 2763 bool old_flag = FLAG_harmony_do_expressions; |
2708 FLAG_harmony_do_expressions = true; | 2764 FLAG_harmony_do_expressions = true; |
2709 HandleAndZoneScope scope; | 2765 HandleAndZoneScope scope; |
2710 Isolate* isolate = scope.main_isolate(); | 2766 Isolate* isolate = scope.main_isolate(); |
| 2767 Zone* zone = scope.main_zone(); |
2711 Factory* factory = isolate->factory(); | 2768 Factory* factory = isolate->factory(); |
2712 ExpectedSnippet<0> snippets[] = { | 2769 ExpectedSnippet<0> snippets[] = { |
2713 {"var a = do {}; return a;", {factory->undefined_value()}}, | 2770 {"var a = do {}; return a;", {factory->undefined_value()}}, |
2714 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, | 2771 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, |
2715 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, | 2772 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, |
2716 {"var a = do { var x = 100; x++; }; return a;", | 2773 {"var a = do { var x = 100; x++; }; return a;", |
2717 {handle(Smi::FromInt(100), isolate)}}, | 2774 {handle(Smi::FromInt(100), isolate)}}, |
2718 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" | 2775 {"var i = 0; for (; i < 5;) { i = do { if (i == 3) { break; }; i + 1; }};" |
2719 "return i;", | 2776 "return i;", |
2720 {handle(Smi::FromInt(3), isolate)}}, | 2777 {handle(Smi::FromInt(3), isolate)}}, |
2721 }; | 2778 }; |
2722 | 2779 |
2723 for (size_t i = 0; i < arraysize(snippets); i++) { | 2780 for (size_t i = 0; i < arraysize(snippets); i++) { |
2724 ScopedVector<char> script(1024); | 2781 ScopedVector<char> script(1024); |
2725 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2782 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2726 snippets[i].code_snippet, kFunctionName); | 2783 snippets[i].code_snippet, kFunctionName); |
2727 | 2784 |
2728 BytecodeGraphTester tester(isolate, script.start()); | 2785 BytecodeGraphTester tester(isolate, zone, script.start()); |
2729 auto callable = tester.GetCallable<>(); | 2786 auto callable = tester.GetCallable<>(); |
2730 Handle<Object> return_value = callable().ToHandleChecked(); | 2787 Handle<Object> return_value = callable().ToHandleChecked(); |
2731 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2788 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2732 } | 2789 } |
2733 | 2790 |
2734 FLAG_harmony_do_expressions = old_flag; | 2791 FLAG_harmony_do_expressions = old_flag; |
2735 } | 2792 } |
2736 | 2793 |
2737 TEST(BytecodeGraphBuilderWithStatement) { | 2794 TEST(BytecodeGraphBuilderWithStatement) { |
2738 HandleAndZoneScope scope; | 2795 HandleAndZoneScope scope; |
2739 Isolate* isolate = scope.main_isolate(); | 2796 Isolate* isolate = scope.main_isolate(); |
| 2797 Zone* zone = scope.main_zone(); |
2740 | 2798 |
2741 ExpectedSnippet<0> snippets[] = { | 2799 ExpectedSnippet<0> snippets[] = { |
2742 {"with({x:42}) return x;", {handle(Smi::FromInt(42), isolate)}}, | 2800 {"with({x:42}) return x;", {handle(Smi::FromInt(42), isolate)}}, |
2743 {"with({}) { var y = 10; return y;}", | 2801 {"with({}) { var y = 10; return y;}", |
2744 {handle(Smi::FromInt(10), isolate)}}, | 2802 {handle(Smi::FromInt(10), isolate)}}, |
2745 {"var y = {x:42};" | 2803 {"var y = {x:42};" |
2746 " function inner() {" | 2804 " function inner() {" |
2747 " var x = 20;" | 2805 " var x = 20;" |
2748 " with(y) return x;" | 2806 " with(y) return x;" |
2749 "}" | 2807 "}" |
2750 "return inner();", | 2808 "return inner();", |
2751 {handle(Smi::FromInt(42), isolate)}}, | 2809 {handle(Smi::FromInt(42), isolate)}}, |
2752 {"var y = {x:42};" | 2810 {"var y = {x:42};" |
2753 " function inner(o) {" | 2811 " function inner(o) {" |
2754 " var x = 20;" | 2812 " var x = 20;" |
2755 " with(o) return x;" | 2813 " with(o) return x;" |
2756 "}" | 2814 "}" |
2757 "return inner(y);", | 2815 "return inner(y);", |
2758 {handle(Smi::FromInt(42), isolate)}}, | 2816 {handle(Smi::FromInt(42), isolate)}}, |
2759 }; | 2817 }; |
2760 | 2818 |
2761 for (size_t i = 0; i < arraysize(snippets); i++) { | 2819 for (size_t i = 0; i < arraysize(snippets); i++) { |
2762 ScopedVector<char> script(1024); | 2820 ScopedVector<char> script(1024); |
2763 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2821 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2764 snippets[i].code_snippet, kFunctionName); | 2822 snippets[i].code_snippet, kFunctionName); |
2765 | 2823 |
2766 BytecodeGraphTester tester(isolate, script.start()); | 2824 BytecodeGraphTester tester(isolate, zone, script.start()); |
2767 auto callable = tester.GetCallable<>(); | 2825 auto callable = tester.GetCallable<>(); |
2768 Handle<Object> return_value = callable().ToHandleChecked(); | 2826 Handle<Object> return_value = callable().ToHandleChecked(); |
2769 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2827 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2770 } | 2828 } |
2771 } | 2829 } |
2772 | 2830 |
2773 TEST(BytecodeGraphBuilderConstDeclaration) { | 2831 TEST(BytecodeGraphBuilderConstDeclaration) { |
2774 HandleAndZoneScope scope; | 2832 HandleAndZoneScope scope; |
2775 Isolate* isolate = scope.main_isolate(); | 2833 Isolate* isolate = scope.main_isolate(); |
| 2834 Zone* zone = scope.main_zone(); |
2776 Factory* factory = isolate->factory(); | 2835 Factory* factory = isolate->factory(); |
2777 | 2836 |
2778 ExpectedSnippet<0> snippets[] = { | 2837 ExpectedSnippet<0> snippets[] = { |
2779 {"const x = 3; return x;", {handle(Smi::FromInt(3), isolate)}}, | 2838 {"const x = 3; return x;", {handle(Smi::FromInt(3), isolate)}}, |
2780 {"let x = 10; x = x + 20; return x;", | 2839 {"let x = 10; x = x + 20; return x;", |
2781 {handle(Smi::FromInt(30), isolate)}}, | 2840 {handle(Smi::FromInt(30), isolate)}}, |
2782 {"let x = 10; x = 20; return x;", {handle(Smi::FromInt(20), isolate)}}, | 2841 {"let x = 10; x = 20; return x;", {handle(Smi::FromInt(20), isolate)}}, |
2783 {"let x; x = 20; return x;", {handle(Smi::FromInt(20), isolate)}}, | 2842 {"let x; x = 20; return x;", {handle(Smi::FromInt(20), isolate)}}, |
2784 {"let x; return x;", {factory->undefined_value()}}, | 2843 {"let x; return x;", {factory->undefined_value()}}, |
2785 {"var x = 10; { let x = 30; } return x;", | 2844 {"var x = 10; { let x = 30; } return x;", |
(...skipping 16 matching lines...) Expand all Loading... |
2802 "return a;\n", | 2861 "return a;\n", |
2803 {handle(Smi::FromInt(55), isolate)}}, | 2862 {handle(Smi::FromInt(55), isolate)}}, |
2804 }; | 2863 }; |
2805 | 2864 |
2806 // Tests for sloppy mode. | 2865 // Tests for sloppy mode. |
2807 for (size_t i = 0; i < arraysize(snippets); i++) { | 2866 for (size_t i = 0; i < arraysize(snippets); i++) { |
2808 ScopedVector<char> script(1024); | 2867 ScopedVector<char> script(1024); |
2809 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2868 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2810 snippets[i].code_snippet, kFunctionName); | 2869 snippets[i].code_snippet, kFunctionName); |
2811 | 2870 |
2812 BytecodeGraphTester tester(isolate, script.start()); | 2871 BytecodeGraphTester tester(isolate, zone, script.start()); |
2813 auto callable = tester.GetCallable<>(); | 2872 auto callable = tester.GetCallable<>(); |
2814 Handle<Object> return_value = callable().ToHandleChecked(); | 2873 Handle<Object> return_value = callable().ToHandleChecked(); |
2815 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2874 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2816 } | 2875 } |
2817 | 2876 |
2818 // Tests for strict mode. | 2877 // Tests for strict mode. |
2819 for (size_t i = 0; i < arraysize(snippets); i++) { | 2878 for (size_t i = 0; i < arraysize(snippets); i++) { |
2820 ScopedVector<char> script(1024); | 2879 ScopedVector<char> script(1024); |
2821 SNPrintF(script, "function %s() {'use strict'; %s }\n%s();", kFunctionName, | 2880 SNPrintF(script, "function %s() {'use strict'; %s }\n%s();", kFunctionName, |
2822 snippets[i].code_snippet, kFunctionName); | 2881 snippets[i].code_snippet, kFunctionName); |
2823 | 2882 |
2824 BytecodeGraphTester tester(isolate, script.start()); | 2883 BytecodeGraphTester tester(isolate, zone, script.start()); |
2825 auto callable = tester.GetCallable<>(); | 2884 auto callable = tester.GetCallable<>(); |
2826 Handle<Object> return_value = callable().ToHandleChecked(); | 2885 Handle<Object> return_value = callable().ToHandleChecked(); |
2827 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2886 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2828 } | 2887 } |
2829 } | 2888 } |
2830 | 2889 |
2831 TEST(BytecodeGraphBuilderConstDeclarationLookupSlots) { | 2890 TEST(BytecodeGraphBuilderConstDeclarationLookupSlots) { |
2832 HandleAndZoneScope scope; | 2891 HandleAndZoneScope scope; |
2833 Isolate* isolate = scope.main_isolate(); | 2892 Isolate* isolate = scope.main_isolate(); |
| 2893 Zone* zone = scope.main_zone(); |
2834 Factory* factory = isolate->factory(); | 2894 Factory* factory = isolate->factory(); |
2835 | 2895 |
2836 ExpectedSnippet<0> snippets[] = { | 2896 ExpectedSnippet<0> snippets[] = { |
2837 {"const x = 3; function f1() {return x;}; return x;", | 2897 {"const x = 3; function f1() {return x;}; return x;", |
2838 {handle(Smi::FromInt(3), isolate)}}, | 2898 {handle(Smi::FromInt(3), isolate)}}, |
2839 {"let x = 10; x = x + 20; function f1() {return x;}; return x;", | 2899 {"let x = 10; x = x + 20; function f1() {return x;}; return x;", |
2840 {handle(Smi::FromInt(30), isolate)}}, | 2900 {handle(Smi::FromInt(30), isolate)}}, |
2841 {"let x; x = 20; function f1() {return x;}; return x;", | 2901 {"let x; x = 20; function f1() {return x;}; return x;", |
2842 {handle(Smi::FromInt(20), isolate)}}, | 2902 {handle(Smi::FromInt(20), isolate)}}, |
2843 {"let x; function f1() {return x;}; return x;", | 2903 {"let x; function f1() {return x;}; return x;", |
2844 {factory->undefined_value()}}, | 2904 {factory->undefined_value()}}, |
2845 }; | 2905 }; |
2846 | 2906 |
2847 // Tests for sloppy mode. | 2907 // Tests for sloppy mode. |
2848 for (size_t i = 0; i < arraysize(snippets); i++) { | 2908 for (size_t i = 0; i < arraysize(snippets); i++) { |
2849 ScopedVector<char> script(1024); | 2909 ScopedVector<char> script(1024); |
2850 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 2910 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2851 snippets[i].code_snippet, kFunctionName); | 2911 snippets[i].code_snippet, kFunctionName); |
2852 | 2912 |
2853 BytecodeGraphTester tester(isolate, script.start()); | 2913 BytecodeGraphTester tester(isolate, zone, script.start()); |
2854 auto callable = tester.GetCallable<>(); | 2914 auto callable = tester.GetCallable<>(); |
2855 Handle<Object> return_value = callable().ToHandleChecked(); | 2915 Handle<Object> return_value = callable().ToHandleChecked(); |
2856 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2916 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2857 } | 2917 } |
2858 | 2918 |
2859 // Tests for strict mode. | 2919 // Tests for strict mode. |
2860 for (size_t i = 0; i < arraysize(snippets); i++) { | 2920 for (size_t i = 0; i < arraysize(snippets); i++) { |
2861 ScopedVector<char> script(1024); | 2921 ScopedVector<char> script(1024); |
2862 SNPrintF(script, "function %s() {'use strict'; %s }\n%s();", kFunctionName, | 2922 SNPrintF(script, "function %s() {'use strict'; %s }\n%s();", kFunctionName, |
2863 snippets[i].code_snippet, kFunctionName); | 2923 snippets[i].code_snippet, kFunctionName); |
2864 | 2924 |
2865 BytecodeGraphTester tester(isolate, script.start()); | 2925 BytecodeGraphTester tester(isolate, zone, script.start()); |
2866 auto callable = tester.GetCallable<>(); | 2926 auto callable = tester.GetCallable<>(); |
2867 Handle<Object> return_value = callable().ToHandleChecked(); | 2927 Handle<Object> return_value = callable().ToHandleChecked(); |
2868 CHECK(return_value->SameValue(*snippets[i].return_value())); | 2928 CHECK(return_value->SameValue(*snippets[i].return_value())); |
2869 } | 2929 } |
2870 } | 2930 } |
2871 | 2931 |
2872 TEST(BytecodeGraphBuilderConstInLookupContextChain) { | 2932 TEST(BytecodeGraphBuilderConstInLookupContextChain) { |
2873 HandleAndZoneScope scope; | 2933 HandleAndZoneScope scope; |
2874 Isolate* isolate = scope.main_isolate(); | 2934 Isolate* isolate = scope.main_isolate(); |
| 2935 Zone* zone = scope.main_zone(); |
2875 | 2936 |
2876 const char* prologue = | 2937 const char* prologue = |
2877 "function OuterMost() {\n" | 2938 "function OuterMost() {\n" |
2878 " const outerConst = 10;\n" | 2939 " const outerConst = 10;\n" |
2879 " let outerLet = 20;\n" | 2940 " let outerLet = 20;\n" |
2880 " function Outer() {\n" | 2941 " function Outer() {\n" |
2881 " function Inner() {\n" | 2942 " function Inner() {\n" |
2882 " this.innerFunc = function() { "; | 2943 " this.innerFunc = function() { "; |
2883 const char* epilogue = | 2944 const char* epilogue = |
2884 " }\n" | 2945 " }\n" |
(...skipping 17 matching lines...) Expand all Loading... |
2902 {"var outerConst = 50; return outerConst;", | 2963 {"var outerConst = 50; return outerConst;", |
2903 {handle(Smi::FromInt(50), isolate)}}, | 2964 {handle(Smi::FromInt(50), isolate)}}, |
2904 {"try { outerConst = 30 } catch(e) { return -1; }", | 2965 {"try { outerConst = 30 } catch(e) { return -1; }", |
2905 {handle(Smi::FromInt(-1), isolate)}}}; | 2966 {handle(Smi::FromInt(-1), isolate)}}}; |
2906 | 2967 |
2907 for (size_t i = 0; i < arraysize(const_decl); i++) { | 2968 for (size_t i = 0; i < arraysize(const_decl); i++) { |
2908 ScopedVector<char> script(1024); | 2969 ScopedVector<char> script(1024); |
2909 SNPrintF(script, "%s %s %s", prologue, const_decl[i].code_snippet, | 2970 SNPrintF(script, "%s %s %s", prologue, const_decl[i].code_snippet, |
2910 epilogue); | 2971 epilogue); |
2911 | 2972 |
2912 BytecodeGraphTester tester(isolate, script.start(), "*"); | 2973 BytecodeGraphTester tester(isolate, zone, script.start(), "*"); |
2913 auto callable = tester.GetCallable<>(); | 2974 auto callable = tester.GetCallable<>(); |
2914 Handle<Object> return_value = callable().ToHandleChecked(); | 2975 Handle<Object> return_value = callable().ToHandleChecked(); |
2915 CHECK(return_value->SameValue(*const_decl[i].return_value())); | 2976 CHECK(return_value->SameValue(*const_decl[i].return_value())); |
2916 } | 2977 } |
2917 } | 2978 } |
2918 | 2979 |
2919 TEST(BytecodeGraphBuilderIllegalConstDeclaration) { | 2980 TEST(BytecodeGraphBuilderIllegalConstDeclaration) { |
2920 HandleAndZoneScope scope; | 2981 HandleAndZoneScope scope; |
2921 Isolate* isolate = scope.main_isolate(); | 2982 Isolate* isolate = scope.main_isolate(); |
| 2983 Zone* zone = scope.main_zone(); |
2922 | 2984 |
2923 ExpectedSnippet<0, const char*> illegal_const_decl[] = { | 2985 ExpectedSnippet<0, const char*> illegal_const_decl[] = { |
2924 {"const x = x = 10 + 3; return x;", | 2986 {"const x = x = 10 + 3; return x;", |
2925 {"Uncaught ReferenceError: x is not defined"}}, | 2987 {"Uncaught ReferenceError: x is not defined"}}, |
2926 {"const x = 10; x = 20; return x;", | 2988 {"const x = 10; x = 20; return x;", |
2927 {"Uncaught TypeError: Assignment to constant variable."}}, | 2989 {"Uncaught TypeError: Assignment to constant variable."}}, |
2928 {"const x = 10; { x = 20; } return x;", | 2990 {"const x = 10; { x = 20; } return x;", |
2929 {"Uncaught TypeError: Assignment to constant variable."}}, | 2991 {"Uncaught TypeError: Assignment to constant variable."}}, |
2930 {"const x = 10; eval('x = 20;'); return x;", | 2992 {"const x = 10; eval('x = 20;'); return x;", |
2931 {"Uncaught TypeError: Assignment to constant variable."}}, | 2993 {"Uncaught TypeError: Assignment to constant variable."}}, |
2932 {"let x = x + 10; return x;", | 2994 {"let x = x + 10; return x;", |
2933 {"Uncaught ReferenceError: x is not defined"}}, | 2995 {"Uncaught ReferenceError: x is not defined"}}, |
2934 {"'use strict'; (function f1() { f1 = 123; })() ", | 2996 {"'use strict'; (function f1() { f1 = 123; })() ", |
2935 {"Uncaught TypeError: Assignment to constant variable."}}, | 2997 {"Uncaught TypeError: Assignment to constant variable."}}, |
2936 }; | 2998 }; |
2937 | 2999 |
2938 // Tests for sloppy mode. | 3000 // Tests for sloppy mode. |
2939 for (size_t i = 0; i < arraysize(illegal_const_decl); i++) { | 3001 for (size_t i = 0; i < arraysize(illegal_const_decl); i++) { |
2940 ScopedVector<char> script(1024); | 3002 ScopedVector<char> script(1024); |
2941 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, | 3003 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
2942 illegal_const_decl[i].code_snippet, kFunctionName); | 3004 illegal_const_decl[i].code_snippet, kFunctionName); |
2943 | 3005 |
2944 BytecodeGraphTester tester(isolate, script.start()); | 3006 BytecodeGraphTester tester(isolate, zone, script.start()); |
2945 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 3007 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
2946 v8::Local<v8::String> expected_string = | 3008 v8::Local<v8::String> expected_string = |
2947 v8_str(illegal_const_decl[i].return_value()); | 3009 v8_str(illegal_const_decl[i].return_value()); |
2948 CHECK( | 3010 CHECK( |
2949 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 3011 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
2950 .FromJust()); | 3012 .FromJust()); |
2951 } | 3013 } |
2952 | 3014 |
2953 // Tests for strict mode. | 3015 // Tests for strict mode. |
2954 for (size_t i = 0; i < arraysize(illegal_const_decl); i++) { | 3016 for (size_t i = 0; i < arraysize(illegal_const_decl); i++) { |
2955 ScopedVector<char> script(1024); | 3017 ScopedVector<char> script(1024); |
2956 SNPrintF(script, "function %s() {'use strict'; %s }\n%s();", kFunctionName, | 3018 SNPrintF(script, "function %s() {'use strict'; %s }\n%s();", kFunctionName, |
2957 illegal_const_decl[i].code_snippet, kFunctionName); | 3019 illegal_const_decl[i].code_snippet, kFunctionName); |
2958 | 3020 |
2959 BytecodeGraphTester tester(isolate, script.start()); | 3021 BytecodeGraphTester tester(isolate, zone, script.start()); |
2960 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); | 3022 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); |
2961 v8::Local<v8::String> expected_string = | 3023 v8::Local<v8::String> expected_string = |
2962 v8_str(illegal_const_decl[i].return_value()); | 3024 v8_str(illegal_const_decl[i].return_value()); |
2963 CHECK( | 3025 CHECK( |
2964 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) | 3026 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) |
2965 .FromJust()); | 3027 .FromJust()); |
2966 } | 3028 } |
2967 } | 3029 } |
2968 | 3030 |
2969 static int debug_break_count = 0; | 3031 static int debug_break_count = 0; |
2970 static void DebugEventCounter(const v8::Debug::EventDetails& event_details) { | 3032 static void DebugEventCounter(const v8::Debug::EventDetails& event_details) { |
2971 if (event_details.GetEvent() == v8::Break) debug_break_count++; | 3033 if (event_details.GetEvent() == v8::Break) debug_break_count++; |
2972 } | 3034 } |
2973 | 3035 |
2974 TEST(BytecodeGraphBuilderDebuggerStatement) { | 3036 TEST(BytecodeGraphBuilderDebuggerStatement) { |
2975 HandleAndZoneScope scope; | 3037 HandleAndZoneScope scope; |
2976 Isolate* isolate = scope.main_isolate(); | 3038 Isolate* isolate = scope.main_isolate(); |
| 3039 Zone* zone = scope.main_zone(); |
2977 | 3040 |
2978 v8::Debug::SetDebugEventListener(CcTest::isolate(), DebugEventCounter); | 3041 v8::Debug::SetDebugEventListener(CcTest::isolate(), DebugEventCounter); |
2979 | 3042 |
2980 ExpectedSnippet<0> snippet = { | 3043 ExpectedSnippet<0> snippet = { |
2981 "function f() {" | 3044 "function f() {" |
2982 " debugger;" | 3045 " debugger;" |
2983 "}" | 3046 "}" |
2984 "f();", | 3047 "f();", |
2985 {isolate->factory()->undefined_value()}}; | 3048 {isolate->factory()->undefined_value()}}; |
2986 | 3049 |
2987 BytecodeGraphTester tester(isolate, snippet.code_snippet); | 3050 BytecodeGraphTester tester(isolate, zone, snippet.code_snippet); |
2988 auto callable = tester.GetCallable<>(); | 3051 auto callable = tester.GetCallable<>(); |
2989 Handle<Object> return_value = callable().ToHandleChecked(); | 3052 Handle<Object> return_value = callable().ToHandleChecked(); |
2990 | 3053 |
2991 v8::Debug::SetDebugEventListener(CcTest::isolate(), nullptr); | 3054 v8::Debug::SetDebugEventListener(CcTest::isolate(), nullptr); |
2992 CHECK(return_value.is_identical_to(snippet.return_value())); | 3055 CHECK(return_value.is_identical_to(snippet.return_value())); |
2993 CHECK_EQ(2, debug_break_count); | 3056 CHECK_EQ(2, debug_break_count); |
2994 } | 3057 } |
2995 | 3058 |
2996 } // namespace compiler | 3059 } // namespace compiler |
2997 } // namespace internal | 3060 } // namespace internal |
2998 } // namespace v8 | 3061 } // namespace v8 |
OLD | NEW |