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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 2396353002: Revert "Add Smi::Zero and replace all Smi::FromInt(0) calls" (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/heap/test-heap.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <tuple> 5 #include <tuple>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/execution.h" 9 #include "src/execution.h"
10 #include "src/handles.h" 10 #include "src/handles.h"
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(2), isolate), 42, 701 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(2), isolate), 42,
702 Handle<Smi>(Smi::FromInt(-40), isolate), 702 Handle<Smi>(Smi::FromInt(-40), isolate),
703 BinaryOperationFeedback::kSignedSmall}, 703 BinaryOperationFeedback::kSignedSmall},
704 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(Smi::kMinValue), isolate), 1, 704 {Token::Value::SUB, Handle<Smi>(Smi::FromInt(Smi::kMinValue), isolate), 1,
705 isolate->factory()->NewHeapNumber(Smi::kMinValue - 1.0), 705 isolate->factory()->NewHeapNumber(Smi::kMinValue - 1.0),
706 BinaryOperationFeedback::kNumber}, 706 BinaryOperationFeedback::kNumber},
707 {Token::Value::SUB, isolate->factory()->NewHeapNumber(3.1415), 2, 707 {Token::Value::SUB, isolate->factory()->NewHeapNumber(3.1415), 2,
708 isolate->factory()->NewHeapNumber(3.1415 - 2.0), 708 isolate->factory()->NewHeapNumber(3.1415 - 2.0),
709 BinaryOperationFeedback::kNumber}, 709 BinaryOperationFeedback::kNumber},
710 {Token::Value::SUB, isolate->factory()->NewStringFromAsciiChecked("2"), 2, 710 {Token::Value::SUB, isolate->factory()->NewStringFromAsciiChecked("2"), 2,
711 Handle<Smi>(Smi::kZero, isolate), BinaryOperationFeedback::kAny}, 711 Handle<Smi>(Smi::FromInt(0), isolate), BinaryOperationFeedback::kAny},
712 // BIT_OR 712 // BIT_OR
713 {Token::Value::BIT_OR, Handle<Smi>(Smi::FromInt(4), isolate), 1, 713 {Token::Value::BIT_OR, Handle<Smi>(Smi::FromInt(4), isolate), 1,
714 Handle<Smi>(Smi::FromInt(5), isolate), 714 Handle<Smi>(Smi::FromInt(5), isolate),
715 BinaryOperationFeedback::kSignedSmall}, 715 BinaryOperationFeedback::kSignedSmall},
716 {Token::Value::BIT_OR, isolate->factory()->NewHeapNumber(3.1415), 8, 716 {Token::Value::BIT_OR, isolate->factory()->NewHeapNumber(3.1415), 8,
717 Handle<Smi>(Smi::FromInt(11), isolate), 717 Handle<Smi>(Smi::FromInt(11), isolate),
718 BinaryOperationFeedback::kNumber}, 718 BinaryOperationFeedback::kNumber},
719 {Token::Value::BIT_OR, isolate->factory()->NewStringFromAsciiChecked("2"), 719 {Token::Value::BIT_OR, isolate->factory()->NewStringFromAsciiChecked("2"),
720 1, Handle<Smi>(Smi::FromInt(3), isolate), BinaryOperationFeedback::kAny}, 720 1, Handle<Smi>(Smi::FromInt(3), isolate), BinaryOperationFeedback::kAny},
721 // BIT_AND 721 // BIT_AND
722 {Token::Value::BIT_AND, Handle<Smi>(Smi::FromInt(3), isolate), 1, 722 {Token::Value::BIT_AND, Handle<Smi>(Smi::FromInt(3), isolate), 1,
723 Handle<Smi>(Smi::FromInt(1), isolate), 723 Handle<Smi>(Smi::FromInt(1), isolate),
724 BinaryOperationFeedback::kSignedSmall}, 724 BinaryOperationFeedback::kSignedSmall},
725 {Token::Value::BIT_AND, isolate->factory()->NewHeapNumber(3.1415), 2, 725 {Token::Value::BIT_AND, isolate->factory()->NewHeapNumber(3.1415), 2,
726 Handle<Smi>(Smi::FromInt(2), isolate), BinaryOperationFeedback::kNumber}, 726 Handle<Smi>(Smi::FromInt(2), isolate), BinaryOperationFeedback::kNumber},
727 {Token::Value::BIT_AND, 727 {Token::Value::BIT_AND,
728 isolate->factory()->NewStringFromAsciiChecked("2"), 1, 728 isolate->factory()->NewStringFromAsciiChecked("2"), 1,
729 Handle<Smi>(Smi::kZero, isolate), BinaryOperationFeedback::kAny}, 729 Handle<Smi>(Smi::FromInt(0), isolate), BinaryOperationFeedback::kAny},
730 // SHL 730 // SHL
731 {Token::Value::SHL, Handle<Smi>(Smi::FromInt(3), isolate), 1, 731 {Token::Value::SHL, Handle<Smi>(Smi::FromInt(3), isolate), 1,
732 Handle<Smi>(Smi::FromInt(6), isolate), 732 Handle<Smi>(Smi::FromInt(6), isolate),
733 BinaryOperationFeedback::kSignedSmall}, 733 BinaryOperationFeedback::kSignedSmall},
734 {Token::Value::SHL, isolate->factory()->NewHeapNumber(3.1415), 2, 734 {Token::Value::SHL, isolate->factory()->NewHeapNumber(3.1415), 2,
735 Handle<Smi>(Smi::FromInt(12), isolate), 735 Handle<Smi>(Smi::FromInt(12), isolate),
736 BinaryOperationFeedback::kNumber}, 736 BinaryOperationFeedback::kNumber},
737 {Token::Value::SHL, isolate->factory()->NewStringFromAsciiChecked("2"), 1, 737 {Token::Value::SHL, isolate->factory()->NewStringFromAsciiChecked("2"), 1,
738 Handle<Smi>(Smi::FromInt(4), isolate), BinaryOperationFeedback::kAny}, 738 Handle<Smi>(Smi::FromInt(4), isolate), BinaryOperationFeedback::kAny},
739 // SAR 739 // SAR
740 {Token::Value::SAR, Handle<Smi>(Smi::FromInt(3), isolate), 1, 740 {Token::Value::SAR, Handle<Smi>(Smi::FromInt(3), isolate), 1,
741 Handle<Smi>(Smi::FromInt(1), isolate), 741 Handle<Smi>(Smi::FromInt(1), isolate),
742 BinaryOperationFeedback::kSignedSmall}, 742 BinaryOperationFeedback::kSignedSmall},
743 {Token::Value::SAR, isolate->factory()->NewHeapNumber(3.1415), 2, 743 {Token::Value::SAR, isolate->factory()->NewHeapNumber(3.1415), 2,
744 Handle<Smi>(Smi::kZero, isolate), BinaryOperationFeedback::kNumber}, 744 Handle<Smi>(Smi::FromInt(0), isolate), BinaryOperationFeedback::kNumber},
745 {Token::Value::SAR, isolate->factory()->NewStringFromAsciiChecked("2"), 1, 745 {Token::Value::SAR, isolate->factory()->NewStringFromAsciiChecked("2"), 1,
746 Handle<Smi>(Smi::FromInt(1), isolate), BinaryOperationFeedback::kAny}}; 746 Handle<Smi>(Smi::FromInt(1), isolate), BinaryOperationFeedback::kAny}};
747 747
748 for (const BinaryOpExpectation& test_case : kTestCases) { 748 for (const BinaryOpExpectation& test_case : kTestCases) {
749 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); 749 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1);
750 750
751 i::FeedbackVectorSpec feedback_spec(&zone); 751 i::FeedbackVectorSpec feedback_spec(&zone);
752 i::FeedbackVectorSlot slot0 = feedback_spec.AddInterpreterBinaryOpICSlot(); 752 i::FeedbackVectorSlot slot0 = feedback_spec.AddInterpreterBinaryOpICSlot();
753 753
754 Handle<i::TypeFeedbackVector> vector = 754 Handle<i::TypeFeedbackVector> vector =
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 FeedbackVectorSlot slot = feedback_spec.AddInterpreterBinaryOpICSlot(); 1414 FeedbackVectorSlot slot = feedback_spec.AddInterpreterBinaryOpICSlot();
1415 FeedbackVectorSlot slot1 = feedback_spec.AddInterpreterBinaryOpICSlot(); 1415 FeedbackVectorSlot slot1 = feedback_spec.AddInterpreterBinaryOpICSlot();
1416 FeedbackVectorSlot slot2 = feedback_spec.AddInterpreterBinaryOpICSlot(); 1416 FeedbackVectorSlot slot2 = feedback_spec.AddInterpreterBinaryOpICSlot();
1417 1417
1418 Handle<i::TypeFeedbackVector> vector = 1418 Handle<i::TypeFeedbackVector> vector =
1419 NewTypeFeedbackVector(isolate, &feedback_spec); 1419 NewTypeFeedbackVector(isolate, &feedback_spec);
1420 1420
1421 Register reg(0), scratch(1); 1421 Register reg(0), scratch(1);
1422 BytecodeLabel label[3]; 1422 BytecodeLabel label[3];
1423 1423
1424 builder.LoadLiteral(Smi::kZero) 1424 builder.LoadLiteral(Smi::FromInt(0))
1425 .StoreAccumulatorInRegister(reg) 1425 .StoreAccumulatorInRegister(reg)
1426 .Jump(&label[1]); 1426 .Jump(&label[1]);
1427 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]); 1427 SetRegister(builder, reg, 1024, scratch).Bind(&label[0]);
1428 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot)) 1428 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot))
1429 .Jump(&label[2]); 1429 .Jump(&label[2]);
1430 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); 1430 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]);
1431 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1)) 1431 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1))
1432 .JumpLoop(&label[0], 0); 1432 .JumpLoop(&label[0], 0);
1433 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); 1433 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]);
1434 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2)) 1434 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2))
(...skipping 21 matching lines...) Expand all
1456 FeedbackVectorSlot slot3 = feedback_spec.AddInterpreterBinaryOpICSlot(); 1456 FeedbackVectorSlot slot3 = feedback_spec.AddInterpreterBinaryOpICSlot();
1457 FeedbackVectorSlot slot4 = feedback_spec.AddInterpreterBinaryOpICSlot(); 1457 FeedbackVectorSlot slot4 = feedback_spec.AddInterpreterBinaryOpICSlot();
1458 1458
1459 Handle<i::TypeFeedbackVector> vector = 1459 Handle<i::TypeFeedbackVector> vector =
1460 NewTypeFeedbackVector(isolate, &feedback_spec); 1460 NewTypeFeedbackVector(isolate, &feedback_spec);
1461 1461
1462 Register reg(0), scratch(1); 1462 Register reg(0), scratch(1);
1463 BytecodeLabel label[2]; 1463 BytecodeLabel label[2];
1464 BytecodeLabel done, done1; 1464 BytecodeLabel done, done1;
1465 1465
1466 builder.LoadLiteral(Smi::kZero) 1466 builder.LoadLiteral(Smi::FromInt(0))
1467 .StoreAccumulatorInRegister(reg) 1467 .StoreAccumulatorInRegister(reg)
1468 .LoadFalse() 1468 .LoadFalse()
1469 .JumpIfFalse(&label[0]); 1469 .JumpIfFalse(&label[0]);
1470 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) 1470 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot))
1471 .Bind(&label[0]) 1471 .Bind(&label[0])
1472 .LoadTrue() 1472 .LoadTrue()
1473 .JumpIfFalse(&done); 1473 .JumpIfFalse(&done);
1474 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) 1474 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1))
1475 .LoadTrue() 1475 .LoadTrue()
1476 .JumpIfTrue(&label[1]); 1476 .JumpIfTrue(&label[1]);
(...skipping 29 matching lines...) Expand all
1506 FeedbackVectorSlot slot3 = feedback_spec.AddInterpreterBinaryOpICSlot(); 1506 FeedbackVectorSlot slot3 = feedback_spec.AddInterpreterBinaryOpICSlot();
1507 FeedbackVectorSlot slot4 = feedback_spec.AddInterpreterBinaryOpICSlot(); 1507 FeedbackVectorSlot slot4 = feedback_spec.AddInterpreterBinaryOpICSlot();
1508 1508
1509 Handle<i::TypeFeedbackVector> vector = 1509 Handle<i::TypeFeedbackVector> vector =
1510 NewTypeFeedbackVector(isolate, &feedback_spec); 1510 NewTypeFeedbackVector(isolate, &feedback_spec);
1511 1511
1512 Register reg(0), scratch(1); 1512 Register reg(0), scratch(1);
1513 BytecodeLabel label[2]; 1513 BytecodeLabel label[2];
1514 BytecodeLabel done, done1; 1514 BytecodeLabel done, done1;
1515 1515
1516 builder.LoadLiteral(Smi::kZero) 1516 builder.LoadLiteral(Smi::FromInt(0))
1517 .StoreAccumulatorInRegister(reg) 1517 .StoreAccumulatorInRegister(reg)
1518 .LoadFalse() 1518 .LoadFalse()
1519 .JumpIfFalse(&label[0]); 1519 .JumpIfFalse(&label[0]);
1520 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot)) 1520 IncrementRegister(builder, reg, 1024, scratch, vector->GetIndex(slot))
1521 .Bind(&label[0]) 1521 .Bind(&label[0])
1522 .LoadTrue() 1522 .LoadTrue()
1523 .JumpIfFalse(&done); 1523 .JumpIfFalse(&done);
1524 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1)) 1524 IncrementRegister(builder, reg, 1, scratch, vector->GetIndex(slot1))
1525 .LoadTrue() 1525 .LoadTrue()
1526 .JumpIfTrue(&label[1]); 1526 .JumpIfTrue(&label[1]);
(...skipping 23 matching lines...) Expand all
1550 Zone zone(isolate->allocator()); 1550 Zone zone(isolate->allocator());
1551 1551
1552 FeedbackVectorSpec feedback_spec(&zone); 1552 FeedbackVectorSpec feedback_spec(&zone);
1553 FeedbackVectorSlot slot = feedback_spec.AddInterpreterBinaryOpICSlot(); 1553 FeedbackVectorSlot slot = feedback_spec.AddInterpreterBinaryOpICSlot();
1554 Handle<i::TypeFeedbackVector> vector = 1554 Handle<i::TypeFeedbackVector> vector =
1555 NewTypeFeedbackVector(isolate, &feedback_spec); 1555 NewTypeFeedbackVector(isolate, &feedback_spec);
1556 1556
1557 Register reg(0), scratch(256); 1557 Register reg(0), scratch(256);
1558 BytecodeLabel done, fake; 1558 BytecodeLabel done, fake;
1559 1559
1560 builder.LoadLiteral(Smi::kZero); 1560 builder.LoadLiteral(Smi::FromInt(0));
1561 builder.StoreAccumulatorInRegister(reg); 1561 builder.StoreAccumulatorInRegister(reg);
1562 // Consume all 8-bit operands 1562 // Consume all 8-bit operands
1563 for (int i = 1; i <= 256; i++) { 1563 for (int i = 1; i <= 256; i++) {
1564 builder.LoadLiteral(isolate->factory()->NewNumber(i)); 1564 builder.LoadLiteral(isolate->factory()->NewNumber(i));
1565 builder.BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot)); 1565 builder.BinaryOperation(Token::Value::ADD, reg, vector->GetIndex(slot));
1566 builder.StoreAccumulatorInRegister(reg); 1566 builder.StoreAccumulatorInRegister(reg);
1567 } 1567 }
1568 builder.Jump(&done); 1568 builder.Jump(&done);
1569 1569
1570 // Emit more than 16-bit immediate operands worth of code to jump over. 1570 // Emit more than 16-bit immediate operands worth of code to jump over.
1571 builder.Bind(&fake); 1571 builder.Bind(&fake);
1572 for (int i = 0; i < 6600; i++) { 1572 for (int i = 0; i < 6600; i++) {
1573 builder.LoadLiteral(Smi::kZero); // 1-byte 1573 builder.LoadLiteral(Smi::FromInt(0)); // 1-byte
1574 builder.BinaryOperation(Token::Value::ADD, scratch, 1574 builder.BinaryOperation(Token::Value::ADD, scratch,
1575 vector->GetIndex(slot)); // 6-bytes 1575 vector->GetIndex(slot)); // 6-bytes
1576 builder.StoreAccumulatorInRegister(scratch); // 4-bytes 1576 builder.StoreAccumulatorInRegister(scratch); // 4-bytes
1577 builder.MoveRegister(scratch, reg); // 6-bytes 1577 builder.MoveRegister(scratch, reg); // 6-bytes
1578 } 1578 }
1579 builder.Bind(&done); 1579 builder.Bind(&done);
1580 builder.LoadAccumulatorWithRegister(reg); 1580 builder.LoadAccumulatorWithRegister(reg);
1581 builder.Return(); 1581 builder.Return();
1582 1582
1583 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 1583 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
(...skipping 16 matching lines...) Expand all
1600 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256)); 1600 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256));
1601 } 1601 }
1602 1602
1603 TEST(InterpreterJumpWith32BitOperand) { 1603 TEST(InterpreterJumpWith32BitOperand) {
1604 HandleAndZoneScope handles; 1604 HandleAndZoneScope handles;
1605 Isolate* isolate = handles.main_isolate(); 1605 Isolate* isolate = handles.main_isolate();
1606 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); 1606 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1);
1607 Register reg(0); 1607 Register reg(0);
1608 BytecodeLabel done; 1608 BytecodeLabel done;
1609 1609
1610 builder.LoadLiteral(Smi::kZero); 1610 builder.LoadLiteral(Smi::FromInt(0));
1611 builder.StoreAccumulatorInRegister(reg); 1611 builder.StoreAccumulatorInRegister(reg);
1612 // Consume all 16-bit constant pool entries 1612 // Consume all 16-bit constant pool entries
1613 for (int i = 1; i <= 65536; i++) { 1613 for (int i = 1; i <= 65536; i++) {
1614 builder.LoadLiteral(isolate->factory()->NewNumber(i)); 1614 builder.LoadLiteral(isolate->factory()->NewNumber(i));
1615 } 1615 }
1616 builder.Jump(&done); 1616 builder.Jump(&done);
1617 builder.LoadLiteral(Smi::kZero); 1617 builder.LoadLiteral(Smi::FromInt(0));
1618 builder.Bind(&done); 1618 builder.Bind(&done);
1619 builder.Return(); 1619 builder.Return();
1620 1620
1621 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 1621 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
1622 BytecodeArrayIterator iterator(bytecode_array); 1622 BytecodeArrayIterator iterator(bytecode_array);
1623 1623
1624 bool found_32bit_jump = false; 1624 bool found_32bit_jump = false;
1625 while (!iterator.done()) { 1625 while (!iterator.done()) {
1626 if (iterator.current_bytecode() == Bytecode::kJump && 1626 if (iterator.current_bytecode() == Bytecode::kJump &&
1627 iterator.current_operand_scale() == OperandScale::kQuadruple) { 1627 iterator.current_operand_scale() == OperandScale::kQuadruple) {
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 "function " + 2308 "function " +
2309 InterpreterTester::function_name() + 2309 InterpreterTester::function_name() +
2310 "() {\n" 2310 "() {\n"
2311 " var c = new counter();\n" 2311 " var c = new counter();\n"
2312 " return c.count;\n" 2312 " return c.count;\n"
2313 "}"); 2313 "}");
2314 InterpreterTester tester(isolate, source.c_str()); 2314 InterpreterTester tester(isolate, source.c_str());
2315 auto callable = tester.GetCallable<>(); 2315 auto callable = tester.GetCallable<>();
2316 2316
2317 Handle<Object> return_val = callable().ToHandleChecked(); 2317 Handle<Object> return_val = callable().ToHandleChecked();
2318 CHECK_EQ(Smi::cast(*return_val), Smi::kZero); 2318 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0));
2319 } 2319 }
2320 2320
2321 2321
2322 TEST(InterpreterConstructWithArgument) { 2322 TEST(InterpreterConstructWithArgument) {
2323 HandleAndZoneScope handles; 2323 HandleAndZoneScope handles;
2324 Isolate* isolate = handles.main_isolate(); 2324 Isolate* isolate = handles.main_isolate();
2325 2325
2326 std::string source( 2326 std::string source(
2327 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" 2327 "function counter(arg0) { this.count = 17; this.x = arg0; }\n"
2328 "function " + 2328 "function " +
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 2521
2522 TEST(InterpreterLogicalAnd) { 2522 TEST(InterpreterLogicalAnd) {
2523 HandleAndZoneScope handles; 2523 HandleAndZoneScope handles;
2524 Isolate* isolate = handles.main_isolate(); 2524 Isolate* isolate = handles.main_isolate();
2525 Factory* factory = isolate->factory(); 2525 Factory* factory = isolate->factory();
2526 2526
2527 std::pair<const char*, Handle<Object>> literals[] = { 2527 std::pair<const char*, Handle<Object>> literals[] = {
2528 std::make_pair("var a, b = 10; return a && b;\n", 2528 std::make_pair("var a, b = 10; return a && b;\n",
2529 factory->undefined_value()), 2529 factory->undefined_value()),
2530 std::make_pair("var a = 0, b = 10; return a && b / a;\n", 2530 std::make_pair("var a = 0, b = 10; return a && b / a;\n",
2531 handle(Smi::kZero, isolate)), 2531 handle(Smi::FromInt(0), isolate)),
2532 std::make_pair("var a = '0', b = 10; return a && b;\n", 2532 std::make_pair("var a = '0', b = 10; return a && b;\n",
2533 handle(Smi::FromInt(10), isolate)), 2533 handle(Smi::FromInt(10), isolate)),
2534 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::kZero, isolate)), 2534 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)),
2535 std::make_pair("return 'a' && 'b';\n", 2535 std::make_pair("return 'a' && 'b';\n",
2536 factory->NewStringFromStaticChars("b")), 2536 factory->NewStringFromStaticChars("b")),
2537 std::make_pair("return 'a' && 0 || 'b', 'c';\n", 2537 std::make_pair("return 'a' && 0 || 'b', 'c';\n",
2538 factory->NewStringFromStaticChars("c")), 2538 factory->NewStringFromStaticChars("c")),
2539 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", 2539 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n",
2540 handle(Smi::FromInt(1), isolate)), 2540 handle(Smi::FromInt(1), isolate)),
2541 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n", 2541 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n",
2542 factory->true_value())}; 2542 factory->true_value())};
2543 2543
2544 for (size_t i = 0; i < arraysize(literals); i++) { 2544 for (size_t i = 0; i < arraysize(literals); i++) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 2676
2677 std::pair<const char*, Handle<Object>> count_ops[] = { 2677 std::pair<const char*, Handle<Object>> count_ops[] = {
2678 std::make_pair("var a = 1; return ++a;", 2678 std::make_pair("var a = 1; return ++a;",
2679 handle(Smi::FromInt(2), isolate)), 2679 handle(Smi::FromInt(2), isolate)),
2680 std::make_pair("var a = 1; return a++;", 2680 std::make_pair("var a = 1; return a++;",
2681 handle(Smi::FromInt(1), isolate)), 2681 handle(Smi::FromInt(1), isolate)),
2682 std::make_pair("var a = 5; return --a;", 2682 std::make_pair("var a = 5; return --a;",
2683 handle(Smi::FromInt(4), isolate)), 2683 handle(Smi::FromInt(4), isolate)),
2684 std::make_pair("var a = 5; return a--;", 2684 std::make_pair("var a = 5; return a--;",
2685 handle(Smi::FromInt(5), isolate)), 2685 handle(Smi::FromInt(5), isolate)),
2686 std::make_pair("var a = 5.2; return --a;", factory->NewHeapNumber(4.2)), 2686 std::make_pair("var a = 5.2; return --a;",
2687 std::make_pair("var a = 'string'; return ++a;", factory->nan_value()), 2687 factory->NewHeapNumber(4.2)),
2688 std::make_pair("var a = 'string'; return a--;", factory->nan_value()), 2688 std::make_pair("var a = 'string'; return ++a;",
2689 factory->nan_value()),
2690 std::make_pair("var a = 'string'; return a--;",
2691 factory->nan_value()),
2689 std::make_pair("var a = true; return ++a;", 2692 std::make_pair("var a = true; return ++a;",
2690 handle(Smi::FromInt(2), isolate)), 2693 handle(Smi::FromInt(2), isolate)),
2691 std::make_pair("var a = false; return a--;", handle(Smi::kZero, isolate)), 2694 std::make_pair("var a = false; return a--;",
2695 handle(Smi::FromInt(0), isolate)),
2692 std::make_pair("var a = { val: 11 }; return ++a.val;", 2696 std::make_pair("var a = { val: 11 }; return ++a.val;",
2693 handle(Smi::FromInt(12), isolate)), 2697 handle(Smi::FromInt(12), isolate)),
2694 std::make_pair("var a = { val: 11 }; return a.val--;", 2698 std::make_pair("var a = { val: 11 }; return a.val--;",
2695 handle(Smi::FromInt(11), isolate)), 2699 handle(Smi::FromInt(11), isolate)),
2696 std::make_pair("var a = { val: 11 }; return ++a.val;", 2700 std::make_pair("var a = { val: 11 }; return ++a.val;",
2697 handle(Smi::FromInt(12), isolate)), 2701 handle(Smi::FromInt(12), isolate)),
2698 std::make_pair("var name = 'val'; var a = { val: 22 }; return --a[name];", 2702 std::make_pair("var name = 'val'; var a = { val: 22 }; return --a[name];",
2699 handle(Smi::FromInt(21), isolate)), 2703 handle(Smi::FromInt(21), isolate)),
2700 std::make_pair("var name = 'val'; var a = { val: 22 }; return a[name]++;", 2704 std::make_pair("var name = 'val'; var a = { val: 22 }; return a[name]++;",
2701 handle(Smi::FromInt(22), isolate)), 2705 handle(Smi::FromInt(22), isolate)),
2702 std::make_pair("var a = 1; (function() { a = 2 })(); return ++a;", 2706 std::make_pair("var a = 1; (function() { a = 2 })(); return ++a;",
2703 handle(Smi::FromInt(3), isolate)), 2707 handle(Smi::FromInt(3), isolate)),
2704 std::make_pair("var a = 1; (function() { a = 2 })(); return a--;", 2708 std::make_pair("var a = 1; (function() { a = 2 })(); return a--;",
2705 handle(Smi::FromInt(2), isolate)), 2709 handle(Smi::FromInt(2), isolate)),
2706 std::make_pair("var i = 5; while(i--) {}; return i;", 2710 std::make_pair("var i = 5; while(i--) {}; return i;",
2707 handle(Smi::FromInt(-1), isolate)), 2711 handle(Smi::FromInt(-1), isolate)),
2708 std::make_pair("var i = 1; if(i--) { return 1; } else { return 2; };", 2712 std::make_pair("var i = 1; if(i--) { return 1; } else { return 2; };",
2709 handle(Smi::FromInt(1), isolate)), 2713 handle(Smi::FromInt(1), isolate)),
2710 std::make_pair("var i = -2; do {} while(i++) {}; return i;", 2714 std::make_pair("var i = -2; do {} while(i++) {}; return i;",
2711 handle(Smi::FromInt(1), isolate)), 2715 handle(Smi::FromInt(1), isolate)),
2712 std::make_pair("var i = -1; for(; i++; ) {}; return i", 2716 std::make_pair("var i = -1; for(; i++; ) {}; return i",
2713 handle(Smi::FromInt(1), isolate)), 2717 handle(Smi::FromInt(1), isolate)),
2714 std::make_pair("var i = 20; switch(i++) {\n" 2718 std::make_pair("var i = 20; switch(i++) {\n"
2715 " case 20: return 1;\n" 2719 " case 20: return 1;\n"
2716 " default: return 2;\n" 2720 " default: return 2;\n"
2717 "}", 2721 "}",
2718 handle(Smi::FromInt(1), isolate)), 2722 handle(Smi::FromInt(1), isolate)),
2719 }; 2723 };
2720 2724
2721 for (size_t i = 0; i < arraysize(count_ops); i++) { 2725 for (size_t i = 0; i < arraysize(count_ops); i++) {
2722 std::string source(InterpreterTester::SourceForBody(count_ops[i].first)); 2726 std::string source(InterpreterTester::SourceForBody(count_ops[i].first));
2723 InterpreterTester tester(isolate, source.c_str()); 2727 InterpreterTester tester(isolate, source.c_str());
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
3884 HandleAndZoneScope handles; 3888 HandleAndZoneScope handles;
3885 Isolate* isolate = handles.main_isolate(); 3889 Isolate* isolate = handles.main_isolate();
3886 3890
3887 const char* inner_function_prologue = "function inner() {"; 3891 const char* inner_function_prologue = "function inner() {";
3888 const char* inner_function_epilogue = "};"; 3892 const char* inner_function_epilogue = "};";
3889 const char* outer_function_epilogue = "return inner();"; 3893 const char* outer_function_epilogue = "return inner();";
3890 3894
3891 std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = { 3895 std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = {
3892 // Eval in inner context. 3896 // Eval in inner context.
3893 std::make_tuple("var x = 0;", "eval(''); return x;", 3897 std::make_tuple("var x = 0;", "eval(''); return x;",
3894 handle(Smi::kZero, isolate)), 3898 handle(Smi::FromInt(0), isolate)),
3895 std::make_tuple("var x = 0;", "eval('var x = 1'); return x;", 3899 std::make_tuple("var x = 0;", "eval('var x = 1'); return x;",
3896 handle(Smi::FromInt(1), isolate)), 3900 handle(Smi::FromInt(1), isolate)),
3897 std::make_tuple("var x = 0;", 3901 std::make_tuple("var x = 0;",
3898 "'use strict'; eval('var x = 1'); return x;", 3902 "'use strict'; eval('var x = 1'); return x;",
3899 handle(Smi::kZero, isolate)), 3903 handle(Smi::FromInt(0), isolate)),
3900 // Eval in outer context. 3904 // Eval in outer context.
3901 std::make_tuple("var x = 0; eval('');", "return x;", 3905 std::make_tuple("var x = 0; eval('');", "return x;",
3902 handle(Smi::kZero, isolate)), 3906 handle(Smi::FromInt(0), isolate)),
3903 std::make_tuple("var x = 0; eval('var x = 1');", "return x;", 3907 std::make_tuple("var x = 0; eval('var x = 1');", "return x;",
3904 handle(Smi::FromInt(1), isolate)), 3908 handle(Smi::FromInt(1), isolate)),
3905 std::make_tuple("'use strict'; var x = 0; eval('var x = 1');", 3909 std::make_tuple("'use strict'; var x = 0; eval('var x = 1');",
3906 "return x;", handle(Smi::kZero, isolate)), 3910 "return x;", handle(Smi::FromInt(0), isolate)),
3907 }; 3911 };
3908 3912
3909 for (size_t i = 0; i < arraysize(lookup_slot); i++) { 3913 for (size_t i = 0; i < arraysize(lookup_slot); i++) {
3910 std::string body = std::string(std::get<0>(lookup_slot[i])) + 3914 std::string body = std::string(std::get<0>(lookup_slot[i])) +
3911 std::string(inner_function_prologue) + 3915 std::string(inner_function_prologue) +
3912 std::string(std::get<1>(lookup_slot[i])) + 3916 std::string(std::get<1>(lookup_slot[i])) +
3913 std::string(inner_function_epilogue) + 3917 std::string(inner_function_epilogue) +
3914 std::string(outer_function_epilogue); 3918 std::string(outer_function_epilogue);
3915 std::string script = InterpreterTester::SourceForBody(body.c_str()); 3919 std::string script = InterpreterTester::SourceForBody(body.c_str());
3916 3920
3917 InterpreterTester tester(isolate, script.c_str()); 3921 InterpreterTester tester(isolate, script.c_str());
3918 auto callable = tester.GetCallable<>(); 3922 auto callable = tester.GetCallable<>();
3919 3923
3920 Handle<i::Object> return_value = callable().ToHandleChecked(); 3924 Handle<i::Object> return_value = callable().ToHandleChecked();
3921 CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i]))); 3925 CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i])));
3922 } 3926 }
3923 } 3927 }
3924 3928
3925 TEST(InterpreterLookupGlobalSlot) { 3929 TEST(InterpreterLookupGlobalSlot) {
3926 HandleAndZoneScope handles; 3930 HandleAndZoneScope handles;
3927 Isolate* isolate = handles.main_isolate(); 3931 Isolate* isolate = handles.main_isolate();
3928 3932
3929 const char* inner_function_prologue = "function inner() {"; 3933 const char* inner_function_prologue = "function inner() {";
3930 const char* inner_function_epilogue = "};"; 3934 const char* inner_function_epilogue = "};";
3931 const char* outer_function_epilogue = "return inner();"; 3935 const char* outer_function_epilogue = "return inner();";
3932 3936
3933 std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = { 3937 std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = {
3934 // Eval in inner context. 3938 // Eval in inner context.
3935 std::make_tuple("x = 0;", "eval(''); return x;", 3939 std::make_tuple("x = 0;", "eval(''); return x;",
3936 handle(Smi::kZero, isolate)), 3940 handle(Smi::FromInt(0), isolate)),
3937 std::make_tuple("x = 0;", "eval('var x = 1'); return x;", 3941 std::make_tuple("x = 0;", "eval('var x = 1'); return x;",
3938 handle(Smi::FromInt(1), isolate)), 3942 handle(Smi::FromInt(1), isolate)),
3939 std::make_tuple("x = 0;", "'use strict'; eval('var x = 1'); return x;", 3943 std::make_tuple("x = 0;", "'use strict'; eval('var x = 1'); return x;",
3940 handle(Smi::kZero, isolate)), 3944 handle(Smi::FromInt(0), isolate)),
3941 // Eval in outer context. 3945 // Eval in outer context.
3942 std::make_tuple("x = 0; eval('');", "return x;", 3946 std::make_tuple("x = 0; eval('');", "return x;",
3943 handle(Smi::kZero, isolate)), 3947 handle(Smi::FromInt(0), isolate)),
3944 std::make_tuple("x = 0; eval('var x = 1');", "return x;", 3948 std::make_tuple("x = 0; eval('var x = 1');", "return x;",
3945 handle(Smi::FromInt(1), isolate)), 3949 handle(Smi::FromInt(1), isolate)),
3946 std::make_tuple("'use strict'; x = 0; eval('var x = 1');", "return x;", 3950 std::make_tuple("'use strict'; x = 0; eval('var x = 1');", "return x;",
3947 handle(Smi::kZero, isolate)), 3951 handle(Smi::FromInt(0), isolate)),
3948 }; 3952 };
3949 3953
3950 for (size_t i = 0; i < arraysize(lookup_slot); i++) { 3954 for (size_t i = 0; i < arraysize(lookup_slot); i++) {
3951 std::string body = std::string(std::get<0>(lookup_slot[i])) + 3955 std::string body = std::string(std::get<0>(lookup_slot[i])) +
3952 std::string(inner_function_prologue) + 3956 std::string(inner_function_prologue) +
3953 std::string(std::get<1>(lookup_slot[i])) + 3957 std::string(std::get<1>(lookup_slot[i])) +
3954 std::string(inner_function_epilogue) + 3958 std::string(inner_function_epilogue) +
3955 std::string(outer_function_epilogue); 3959 std::string(outer_function_epilogue);
3956 std::string script = InterpreterTester::SourceForBody(body.c_str()); 3960 std::string script = InterpreterTester::SourceForBody(body.c_str());
3957 3961
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
4821 auto callable = tester.GetCallable<>(); 4825 auto callable = tester.GetCallable<>();
4822 4826
4823 Handle<i::Object> return_value = callable().ToHandleChecked(); 4827 Handle<i::Object> return_value = callable().ToHandleChecked();
4824 CHECK(return_value->SameValue(*tests[i].second)); 4828 CHECK(return_value->SameValue(*tests[i].second));
4825 } 4829 }
4826 } 4830 }
4827 4831
4828 } // namespace interpreter 4832 } // namespace interpreter
4829 } // namespace internal 4833 } // namespace internal
4830 } // namespace v8 4834 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/heap/test-heap.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698