OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } // namespace interpreter | 148 } // namespace interpreter |
149 } // namespace internal | 149 } // namespace internal |
150 } // namespace v8 | 150 } // namespace v8 |
151 | 151 |
152 using v8::internal::BytecodeArray; | 152 using v8::internal::BytecodeArray; |
153 using v8::internal::Handle; | 153 using v8::internal::Handle; |
154 using v8::internal::LanguageMode; | 154 using v8::internal::LanguageMode; |
155 using v8::internal::Object; | 155 using v8::internal::Object; |
156 using v8::internal::Runtime; | 156 using v8::internal::Runtime; |
157 using v8::internal::Smi; | 157 using v8::internal::Smi; |
| 158 using v8::internal::Strength; |
158 using v8::internal::Token; | 159 using v8::internal::Token; |
159 using namespace v8::internal::interpreter; | 160 using namespace v8::internal::interpreter; |
160 | 161 |
161 TEST(InterpreterReturn) { | 162 TEST(InterpreterReturn) { |
162 HandleAndZoneScope handles; | 163 HandleAndZoneScope handles; |
163 Handle<Object> undefined_value = | 164 Handle<Object> undefined_value = |
164 handles.main_isolate()->factory()->undefined_value(); | 165 handles.main_isolate()->factory()->undefined_value(); |
165 | 166 |
166 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 167 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
167 builder.set_locals_count(0); | 168 builder.set_locals_count(0); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 BytecodeArrayBuilder builder(handles.main_isolate(), | 385 BytecodeArrayBuilder builder(handles.main_isolate(), |
385 handles.main_zone()); | 386 handles.main_zone()); |
386 builder.set_locals_count(1); | 387 builder.set_locals_count(1); |
387 builder.set_parameter_count(1); | 388 builder.set_parameter_count(1); |
388 Register reg(0); | 389 Register reg(0); |
389 int lhs = lhs_inputs[l]; | 390 int lhs = lhs_inputs[l]; |
390 int rhs = rhs_inputs[l]; | 391 int rhs = rhs_inputs[l]; |
391 builder.LoadLiteral(Smi::FromInt(lhs)) | 392 builder.LoadLiteral(Smi::FromInt(lhs)) |
392 .StoreAccumulatorInRegister(reg) | 393 .StoreAccumulatorInRegister(reg) |
393 .LoadLiteral(Smi::FromInt(rhs)) | 394 .LoadLiteral(Smi::FromInt(rhs)) |
394 .BinaryOperation(kArithmeticOperators[o], reg) | 395 .BinaryOperation(kArithmeticOperators[o], reg, Strength::WEAK) |
395 .Return(); | 396 .Return(); |
396 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 397 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
397 | 398 |
398 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 399 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
399 auto callable = tester.GetCallable<>(); | 400 auto callable = tester.GetCallable<>(); |
400 Handle<Object> return_value = callable().ToHandleChecked(); | 401 Handle<Object> return_value = callable().ToHandleChecked(); |
401 Handle<Object> expected_value = | 402 Handle<Object> expected_value = |
402 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); | 403 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); |
403 CHECK(return_value->SameValue(*expected_value)); | 404 CHECK(return_value->SameValue(*expected_value)); |
404 } | 405 } |
(...skipping 14 matching lines...) Expand all Loading... |
419 BytecodeArrayBuilder builder(handles.main_isolate(), | 420 BytecodeArrayBuilder builder(handles.main_isolate(), |
420 handles.main_zone()); | 421 handles.main_zone()); |
421 builder.set_locals_count(1); | 422 builder.set_locals_count(1); |
422 builder.set_parameter_count(1); | 423 builder.set_parameter_count(1); |
423 Register reg(0); | 424 Register reg(0); |
424 double lhs = lhs_inputs[l]; | 425 double lhs = lhs_inputs[l]; |
425 double rhs = rhs_inputs[l]; | 426 double rhs = rhs_inputs[l]; |
426 builder.LoadLiteral(factory->NewNumber(lhs)) | 427 builder.LoadLiteral(factory->NewNumber(lhs)) |
427 .StoreAccumulatorInRegister(reg) | 428 .StoreAccumulatorInRegister(reg) |
428 .LoadLiteral(factory->NewNumber(rhs)) | 429 .LoadLiteral(factory->NewNumber(rhs)) |
429 .BinaryOperation(kArithmeticOperators[o], reg) | 430 .BinaryOperation(kArithmeticOperators[o], reg, Strength::WEAK) |
430 .Return(); | 431 .Return(); |
431 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 432 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
432 | 433 |
433 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 434 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
434 auto callable = tester.GetCallable<>(); | 435 auto callable = tester.GetCallable<>(); |
435 Handle<Object> return_value = callable().ToHandleChecked(); | 436 Handle<Object> return_value = callable().ToHandleChecked(); |
436 Handle<Object> expected_value = | 437 Handle<Object> expected_value = |
437 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); | 438 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); |
438 CHECK(return_value->SameValue(*expected_value)); | 439 CHECK(return_value->SameValue(*expected_value)); |
439 } | 440 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 }; | 476 }; |
476 | 477 |
477 for (size_t i = 0; i < arraysize(test_cases); i++) { | 478 for (size_t i = 0; i < arraysize(test_cases); i++) { |
478 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 479 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
479 builder.set_locals_count(1); | 480 builder.set_locals_count(1); |
480 builder.set_parameter_count(1); | 481 builder.set_parameter_count(1); |
481 Register reg(0); | 482 Register reg(0); |
482 builder.LoadLiteral(test_cases[i].lhs) | 483 builder.LoadLiteral(test_cases[i].lhs) |
483 .StoreAccumulatorInRegister(reg) | 484 .StoreAccumulatorInRegister(reg) |
484 .LoadLiteral(test_cases[i].rhs) | 485 .LoadLiteral(test_cases[i].rhs) |
485 .BinaryOperation(Token::Value::ADD, reg) | 486 .BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
486 .Return(); | 487 .Return(); |
487 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 488 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
488 | 489 |
489 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 490 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
490 auto callable = tester.GetCallable<>(); | 491 auto callable = tester.GetCallable<>(); |
491 Handle<Object> return_value = callable().ToHandleChecked(); | 492 Handle<Object> return_value = callable().ToHandleChecked(); |
492 CHECK(return_value->SameValue(*test_cases[i].expected_value)); | 493 CHECK(return_value->SameValue(*test_cases[i].expected_value)); |
493 } | 494 } |
494 } | 495 } |
495 | 496 |
(...skipping 20 matching lines...) Expand all Loading... |
516 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 517 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
517 } | 518 } |
518 | 519 |
519 | 520 |
520 TEST(InterpreterParameter8) { | 521 TEST(InterpreterParameter8) { |
521 HandleAndZoneScope handles; | 522 HandleAndZoneScope handles; |
522 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 523 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
523 builder.set_locals_count(0); | 524 builder.set_locals_count(0); |
524 builder.set_parameter_count(8); | 525 builder.set_parameter_count(8); |
525 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) | 526 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) |
526 .BinaryOperation(Token::Value::ADD, builder.Parameter(1)) | 527 .BinaryOperation(Token::Value::ADD, builder.Parameter(1), Strength::WEAK) |
527 .BinaryOperation(Token::Value::ADD, builder.Parameter(2)) | 528 .BinaryOperation(Token::Value::ADD, builder.Parameter(2), Strength::WEAK) |
528 .BinaryOperation(Token::Value::ADD, builder.Parameter(3)) | 529 .BinaryOperation(Token::Value::ADD, builder.Parameter(3), Strength::WEAK) |
529 .BinaryOperation(Token::Value::ADD, builder.Parameter(4)) | 530 .BinaryOperation(Token::Value::ADD, builder.Parameter(4), Strength::WEAK) |
530 .BinaryOperation(Token::Value::ADD, builder.Parameter(5)) | 531 .BinaryOperation(Token::Value::ADD, builder.Parameter(5), Strength::WEAK) |
531 .BinaryOperation(Token::Value::ADD, builder.Parameter(6)) | 532 .BinaryOperation(Token::Value::ADD, builder.Parameter(6), Strength::WEAK) |
532 .BinaryOperation(Token::Value::ADD, builder.Parameter(7)) | 533 .BinaryOperation(Token::Value::ADD, builder.Parameter(7), Strength::WEAK) |
533 .Return(); | 534 .Return(); |
534 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 535 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
535 | 536 |
536 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 537 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
537 typedef Handle<Object> H; | 538 typedef Handle<Object> H; |
538 auto callable = tester.GetCallable<H, H, H, H, H, H, H, H>(); | 539 auto callable = tester.GetCallable<H, H, H, H, H, H, H, H>(); |
539 | 540 |
540 Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(1), handles.main_isolate()); | 541 Handle<Smi> arg1 = Handle<Smi>(Smi::FromInt(1), handles.main_isolate()); |
541 Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), handles.main_isolate()); | 542 Handle<Smi> arg2 = Handle<Smi>(Smi::FromInt(2), handles.main_isolate()); |
542 Handle<Smi> arg3 = Handle<Smi>(Smi::FromInt(3), handles.main_isolate()); | 543 Handle<Smi> arg3 = Handle<Smi>(Smi::FromInt(3), handles.main_isolate()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 i::TypeFeedbackVector::New(isolate, &feedback_spec); | 657 i::TypeFeedbackVector::New(isolate, &feedback_spec); |
657 | 658 |
658 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); | 659 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); |
659 key = factory->string_table()->LookupString(isolate, key); | 660 key = factory->string_table()->LookupString(isolate, key); |
660 | 661 |
661 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 662 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
662 builder.set_locals_count(1); | 663 builder.set_locals_count(1); |
663 builder.set_parameter_count(1); | 664 builder.set_parameter_count(1); |
664 builder.LoadLiteral(key) | 665 builder.LoadLiteral(key) |
665 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot), | 666 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot), |
666 i::SLOPPY) | 667 i::STRICT) |
667 .Return(); | 668 .Return(); |
668 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 669 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
669 | 670 |
670 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 671 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
671 auto callable = tester.GetCallable<Handle<Object>>(); | 672 auto callable = tester.GetCallable<Handle<Object>>(); |
672 | 673 |
673 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); | 674 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); |
674 // Test IC miss. | 675 // Test IC miss. |
675 Handle<Object> return_val = callable(object).ToHandleChecked(); | 676 Handle<Object> return_val = callable(object).ToHandleChecked(); |
676 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 677 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
(...skipping 25 matching lines...) Expand all Loading... |
702 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 703 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
703 name = factory->string_table()->LookupString(isolate, name); | 704 name = factory->string_table()->LookupString(isolate, name); |
704 | 705 |
705 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 706 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
706 builder.set_locals_count(1); | 707 builder.set_locals_count(1); |
707 builder.set_parameter_count(1); | 708 builder.set_parameter_count(1); |
708 builder.LoadLiteral(name) | 709 builder.LoadLiteral(name) |
709 .StoreAccumulatorInRegister(Register(0)) | 710 .StoreAccumulatorInRegister(Register(0)) |
710 .LoadLiteral(Smi::FromInt(999)) | 711 .LoadLiteral(Smi::FromInt(999)) |
711 .StoreNamedProperty(builder.Parameter(0), Register(0), | 712 .StoreNamedProperty(builder.Parameter(0), Register(0), |
712 vector->GetIndex(slot), i::SLOPPY) | 713 vector->GetIndex(slot), i::STRICT) |
713 .Return(); | 714 .Return(); |
714 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 715 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
715 | 716 |
716 InterpreterTester tester(isolate, bytecode_array, vector); | 717 InterpreterTester tester(isolate, bytecode_array, vector); |
717 auto callable = tester.GetCallable<Handle<Object>>(); | 718 auto callable = tester.GetCallable<Handle<Object>>(); |
718 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); | 719 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
719 // Test IC miss. | 720 // Test IC miss. |
720 Handle<Object> result; | 721 Handle<Object> result; |
721 callable(object).ToHandleChecked(); | 722 callable(object).ToHandleChecked(); |
722 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 723 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 .StoreAccumulatorInRegister(reg) | 949 .StoreAccumulatorInRegister(reg) |
949 .LoadAccumulatorWithRegister(scratch); | 950 .LoadAccumulatorWithRegister(scratch); |
950 } | 951 } |
951 | 952 |
952 | 953 |
953 static BytecodeArrayBuilder& IncrementRegister(BytecodeArrayBuilder& builder, | 954 static BytecodeArrayBuilder& IncrementRegister(BytecodeArrayBuilder& builder, |
954 Register reg, int value, | 955 Register reg, int value, |
955 Register scratch) { | 956 Register scratch) { |
956 return builder.StoreAccumulatorInRegister(scratch) | 957 return builder.StoreAccumulatorInRegister(scratch) |
957 .LoadLiteral(Smi::FromInt(value)) | 958 .LoadLiteral(Smi::FromInt(value)) |
958 .BinaryOperation(Token::Value::ADD, reg) | 959 .BinaryOperation(Token::Value::ADD, reg, Strength::WEAK) |
959 .StoreAccumulatorInRegister(reg) | 960 .StoreAccumulatorInRegister(reg) |
960 .LoadAccumulatorWithRegister(scratch); | 961 .LoadAccumulatorWithRegister(scratch); |
961 } | 962 } |
962 | 963 |
963 | 964 |
964 TEST(InterpreterJumps) { | 965 TEST(InterpreterJumps) { |
965 HandleAndZoneScope handles; | 966 HandleAndZoneScope handles; |
966 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 967 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
967 builder.set_locals_count(2); | 968 builder.set_locals_count(2); |
968 builder.set_parameter_count(0); | 969 builder.set_parameter_count(0); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 for (size_t j = 0; j < arraysize(inputs); j++) { | 1079 for (size_t j = 0; j < arraysize(inputs); j++) { |
1079 HandleAndZoneScope handles; | 1080 HandleAndZoneScope handles; |
1080 BytecodeArrayBuilder builder(handles.main_isolate(), | 1081 BytecodeArrayBuilder builder(handles.main_isolate(), |
1081 handles.main_zone()); | 1082 handles.main_zone()); |
1082 Register r0(0); | 1083 Register r0(0); |
1083 builder.set_locals_count(1); | 1084 builder.set_locals_count(1); |
1084 builder.set_parameter_count(0); | 1085 builder.set_parameter_count(0); |
1085 builder.LoadLiteral(Smi::FromInt(inputs[i])) | 1086 builder.LoadLiteral(Smi::FromInt(inputs[i])) |
1086 .StoreAccumulatorInRegister(r0) | 1087 .StoreAccumulatorInRegister(r0) |
1087 .LoadLiteral(Smi::FromInt(inputs[j])) | 1088 .LoadLiteral(Smi::FromInt(inputs[j])) |
1088 .CompareOperation(comparison, r0, LanguageMode::SLOPPY) | 1089 .CompareOperation(comparison, r0, Strength::WEAK) |
1089 .Return(); | 1090 .Return(); |
1090 | 1091 |
1091 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1092 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1092 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1093 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1093 auto callable = tester.GetCallable<>(); | 1094 auto callable = tester.GetCallable<>(); |
1094 Handle<Object> return_value = callable().ToHandleChecked(); | 1095 Handle<Object> return_value = callable().ToHandleChecked(); |
1095 CHECK(return_value->IsBoolean()); | 1096 CHECK(return_value->IsBoolean()); |
1096 CHECK_EQ(return_value->BooleanValue(), | 1097 CHECK_EQ(return_value->BooleanValue(), |
1097 CompareC(comparison, inputs[i], inputs[j])); | 1098 CompareC(comparison, inputs[i], inputs[j])); |
1098 } | 1099 } |
(...skipping 17 matching lines...) Expand all Loading... |
1116 HandleAndZoneScope handles; | 1117 HandleAndZoneScope handles; |
1117 i::Factory* factory = handles.main_isolate()->factory(); | 1118 i::Factory* factory = handles.main_isolate()->factory(); |
1118 BytecodeArrayBuilder builder(handles.main_isolate(), | 1119 BytecodeArrayBuilder builder(handles.main_isolate(), |
1119 handles.main_zone()); | 1120 handles.main_zone()); |
1120 Register r0(0); | 1121 Register r0(0); |
1121 builder.set_locals_count(1); | 1122 builder.set_locals_count(1); |
1122 builder.set_parameter_count(0); | 1123 builder.set_parameter_count(0); |
1123 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) | 1124 builder.LoadLiteral(factory->NewHeapNumber(inputs[i])) |
1124 .StoreAccumulatorInRegister(r0) | 1125 .StoreAccumulatorInRegister(r0) |
1125 .LoadLiteral(factory->NewHeapNumber(inputs[j])) | 1126 .LoadLiteral(factory->NewHeapNumber(inputs[j])) |
1126 .CompareOperation(comparison, r0, LanguageMode::SLOPPY) | 1127 .CompareOperation(comparison, r0, Strength::WEAK) |
1127 .Return(); | 1128 .Return(); |
1128 | 1129 |
1129 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1130 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1130 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1131 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1131 auto callable = tester.GetCallable<>(); | 1132 auto callable = tester.GetCallable<>(); |
1132 Handle<Object> return_value = callable().ToHandleChecked(); | 1133 Handle<Object> return_value = callable().ToHandleChecked(); |
1133 CHECK(return_value->IsBoolean()); | 1134 CHECK(return_value->IsBoolean()); |
1134 CHECK_EQ(return_value->BooleanValue(), | 1135 CHECK_EQ(return_value->BooleanValue(), |
1135 CompareC(comparison, inputs[i], inputs[j])); | 1136 CompareC(comparison, inputs[i], inputs[j])); |
1136 } | 1137 } |
(...skipping 14 matching lines...) Expand all Loading... |
1151 HandleAndZoneScope handles; | 1152 HandleAndZoneScope handles; |
1152 i::Factory* factory = handles.main_isolate()->factory(); | 1153 i::Factory* factory = handles.main_isolate()->factory(); |
1153 BytecodeArrayBuilder builder(handles.main_isolate(), | 1154 BytecodeArrayBuilder builder(handles.main_isolate(), |
1154 handles.main_zone()); | 1155 handles.main_zone()); |
1155 Register r0(0); | 1156 Register r0(0); |
1156 builder.set_locals_count(1); | 1157 builder.set_locals_count(1); |
1157 builder.set_parameter_count(0); | 1158 builder.set_parameter_count(0); |
1158 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) | 1159 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs)) |
1159 .StoreAccumulatorInRegister(r0) | 1160 .StoreAccumulatorInRegister(r0) |
1160 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) | 1161 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs)) |
1161 .CompareOperation(comparison, r0, LanguageMode::SLOPPY) | 1162 .CompareOperation(comparison, r0, Strength::WEAK) |
1162 .Return(); | 1163 .Return(); |
1163 | 1164 |
1164 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1165 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1165 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1166 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1166 auto callable = tester.GetCallable<>(); | 1167 auto callable = tester.GetCallable<>(); |
1167 Handle<Object> return_value = callable().ToHandleChecked(); | 1168 Handle<Object> return_value = callable().ToHandleChecked(); |
1168 CHECK(return_value->IsBoolean()); | 1169 CHECK(return_value->IsBoolean()); |
1169 CHECK_EQ(return_value->BooleanValue(), | 1170 CHECK_EQ(return_value->BooleanValue(), |
1170 CompareC(comparison, inputs[i], inputs[j])); | 1171 CompareC(comparison, inputs[i], inputs[j])); |
1171 } | 1172 } |
(...skipping 27 matching lines...) Expand all Loading... |
1199 BytecodeArrayBuilder builder(handles.main_isolate(), | 1200 BytecodeArrayBuilder builder(handles.main_isolate(), |
1200 handles.main_zone()); | 1201 handles.main_zone()); |
1201 Register r0(0); | 1202 Register r0(0); |
1202 builder.set_locals_count(1); | 1203 builder.set_locals_count(1); |
1203 builder.set_parameter_count(0); | 1204 builder.set_parameter_count(0); |
1204 if (pass == 0) { | 1205 if (pass == 0) { |
1205 // Comparison with HeapNumber on the lhs and String on the rhs | 1206 // Comparison with HeapNumber on the lhs and String on the rhs |
1206 builder.LoadLiteral(factory->NewNumber(lhs)) | 1207 builder.LoadLiteral(factory->NewNumber(lhs)) |
1207 .StoreAccumulatorInRegister(r0) | 1208 .StoreAccumulatorInRegister(r0) |
1208 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) | 1209 .LoadLiteral(factory->NewStringFromAsciiChecked(rhs_cstr)) |
1209 .CompareOperation(comparison, r0, LanguageMode::SLOPPY) | 1210 .CompareOperation(comparison, r0, Strength::WEAK) |
1210 .Return(); | 1211 .Return(); |
1211 } else { | 1212 } else { |
1212 // Comparison with HeapNumber on the rhs and String on the lhs | 1213 // Comparison with HeapNumber on the rhs and String on the lhs |
1213 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs_cstr)) | 1214 builder.LoadLiteral(factory->NewStringFromAsciiChecked(lhs_cstr)) |
1214 .StoreAccumulatorInRegister(r0) | 1215 .StoreAccumulatorInRegister(r0) |
1215 .LoadLiteral(factory->NewNumber(rhs)) | 1216 .LoadLiteral(factory->NewNumber(rhs)) |
1216 .CompareOperation(comparison, r0, LanguageMode::SLOPPY) | 1217 .CompareOperation(comparison, r0, Strength::WEAK) |
1217 .Return(); | 1218 .Return(); |
1218 } | 1219 } |
1219 | 1220 |
1220 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1221 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1221 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1222 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1222 auto callable = tester.GetCallable<>(); | 1223 auto callable = tester.GetCallable<>(); |
1223 Handle<Object> return_value = callable().ToHandleChecked(); | 1224 Handle<Object> return_value = callable().ToHandleChecked(); |
1224 CHECK(return_value->IsBoolean()); | 1225 CHECK(return_value->IsBoolean()); |
1225 CHECK_EQ(return_value->BooleanValue(), | 1226 CHECK_EQ(return_value->BooleanValue(), |
1226 CompareC(comparison, lhs, rhs, true)); | 1227 CompareC(comparison, lhs, rhs, true)); |
(...skipping 14 matching lines...) Expand all Loading... |
1241 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; | 1242 Handle<i::Object> cases[] = {Handle<i::Object>::cast(instance), other}; |
1242 for (size_t i = 0; i < arraysize(cases); i++) { | 1243 for (size_t i = 0; i < arraysize(cases); i++) { |
1243 bool expected_value = (i == 0); | 1244 bool expected_value = (i == 0); |
1244 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 1245 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
1245 Register r0(0); | 1246 Register r0(0); |
1246 builder.set_locals_count(1); | 1247 builder.set_locals_count(1); |
1247 builder.set_parameter_count(0); | 1248 builder.set_parameter_count(0); |
1248 builder.LoadLiteral(cases[i]); | 1249 builder.LoadLiteral(cases[i]); |
1249 builder.StoreAccumulatorInRegister(r0) | 1250 builder.StoreAccumulatorInRegister(r0) |
1250 .LoadLiteral(func) | 1251 .LoadLiteral(func) |
1251 .CompareOperation(Token::Value::INSTANCEOF, r0, LanguageMode::SLOPPY) | 1252 .CompareOperation(Token::Value::INSTANCEOF, r0, Strength::WEAK) |
1252 .Return(); | 1253 .Return(); |
1253 | 1254 |
1254 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1255 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1255 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1256 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1256 auto callable = tester.GetCallable<>(); | 1257 auto callable = tester.GetCallable<>(); |
1257 Handle<Object> return_value = callable().ToHandleChecked(); | 1258 Handle<Object> return_value = callable().ToHandleChecked(); |
1258 CHECK(return_value->IsBoolean()); | 1259 CHECK(return_value->IsBoolean()); |
1259 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1260 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1260 } | 1261 } |
1261 } | 1262 } |
1262 | 1263 |
1263 | 1264 |
1264 TEST(InterpreterTestIn) { | 1265 TEST(InterpreterTestIn) { |
1265 HandleAndZoneScope handles; | 1266 HandleAndZoneScope handles; |
1266 i::Factory* factory = handles.main_isolate()->factory(); | 1267 i::Factory* factory = handles.main_isolate()->factory(); |
1267 // Allocate an array | 1268 // Allocate an array |
1268 Handle<i::JSArray> array = | 1269 Handle<i::JSArray> array = |
1269 factory->NewJSArray(i::ElementsKind::FAST_SMI_ELEMENTS); | 1270 factory->NewJSArray(i::ElementsKind::FAST_SMI_ELEMENTS); |
1270 // Check for these properties on the array object | 1271 // Check for these properties on the array object |
1271 const char* properties[] = {"length", "fuzzle", "x", "0"}; | 1272 const char* properties[] = {"length", "fuzzle", "x", "0"}; |
1272 for (size_t i = 0; i < arraysize(properties); i++) { | 1273 for (size_t i = 0; i < arraysize(properties); i++) { |
1273 bool expected_value = (i == 0); | 1274 bool expected_value = (i == 0); |
1274 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 1275 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
1275 Register r0(0); | 1276 Register r0(0); |
1276 builder.set_locals_count(1); | 1277 builder.set_locals_count(1); |
1277 builder.set_parameter_count(0); | 1278 builder.set_parameter_count(0); |
1278 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) | 1279 builder.LoadLiteral(factory->NewStringFromAsciiChecked(properties[i])) |
1279 .StoreAccumulatorInRegister(r0) | 1280 .StoreAccumulatorInRegister(r0) |
1280 .LoadLiteral(Handle<Object>::cast(array)) | 1281 .LoadLiteral(Handle<Object>::cast(array)) |
1281 .CompareOperation(Token::Value::IN, r0, LanguageMode::SLOPPY) | 1282 .CompareOperation(Token::Value::IN, r0, Strength::WEAK) |
1282 .Return(); | 1283 .Return(); |
1283 | 1284 |
1284 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1285 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1285 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1286 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1286 auto callable = tester.GetCallable<>(); | 1287 auto callable = tester.GetCallable<>(); |
1287 Handle<Object> return_value = callable().ToHandleChecked(); | 1288 Handle<Object> return_value = callable().ToHandleChecked(); |
1288 CHECK(return_value->IsBoolean()); | 1289 CHECK(return_value->IsBoolean()); |
1289 CHECK_EQ(return_value->BooleanValue(), expected_value); | 1290 CHECK_EQ(return_value->BooleanValue(), expected_value); |
1290 } | 1291 } |
1291 } | 1292 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1463 .CallRuntime(Runtime::kAdd, Register(0), 2) |
1463 .Return(); | 1464 .Return(); |
1464 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1465 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1465 | 1466 |
1466 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1467 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1467 auto callable = tester.GetCallable<>(); | 1468 auto callable = tester.GetCallable<>(); |
1468 | 1469 |
1469 Handle<Object> return_val = callable().ToHandleChecked(); | 1470 Handle<Object> return_val = callable().ToHandleChecked(); |
1470 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1471 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
1471 } | 1472 } |
OLD | NEW |