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 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1546 .CallRuntime(Runtime::kAdd, Register(0), 2) |
1547 .Return(); | 1547 .Return(); |
1548 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1548 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1549 | 1549 |
1550 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1550 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1551 auto callable = tester.GetCallable<>(); | 1551 auto callable = tester.GetCallable<>(); |
1552 | 1552 |
1553 Handle<Object> return_val = callable().ToHandleChecked(); | 1553 Handle<Object> return_val = callable().ToHandleChecked(); |
1554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
1555 } | 1555 } |
| 1556 |
| 1557 |
| 1558 TEST(InterpreterCommaSmi) { |
| 1559 HandleAndZoneScope handles; |
| 1560 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 1561 Register reg(0); |
| 1562 i::Factory* factory = handles.main_isolate()->factory(); |
| 1563 builder.set_locals_count(1); |
| 1564 builder.set_parameter_count(0); |
| 1565 |
| 1566 builder.LoadLiteral(Smi::FromInt(10)) |
| 1567 .StoreAccumulatorInRegister(reg) |
| 1568 .LoadLiteral(Smi::FromInt(300)) |
| 1569 .Return(); |
| 1570 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1571 |
| 1572 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1573 auto callable = tester.GetCallable<>(); |
| 1574 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1575 Handle<Object> expected_value = factory->NewNumber(300); |
| 1576 CHECK(return_value->SameValue(*expected_value)); |
| 1577 } |
| 1578 |
| 1579 |
| 1580 TEST(InterpreterCommaHeapNumber) { |
| 1581 double lhs_inputs[] = {32.73, 56e-12}; |
| 1582 double rhs_inputs[] = {8.3e-27, 32.73}; |
| 1583 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| 1584 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| 1585 HandleAndZoneScope handles; |
| 1586 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 1587 Register reg(0); |
| 1588 i::Factory* factory = handles.main_isolate()->factory(); |
| 1589 builder.set_locals_count(1); |
| 1590 builder.set_parameter_count(0); |
| 1591 |
| 1592 builder.LoadLiteral(factory->NewNumber(lhs_inputs[l])) |
| 1593 .StoreAccumulatorInRegister(reg) |
| 1594 .LoadLiteral(factory->NewNumber(rhs_inputs[r])) |
| 1595 .Return(); |
| 1596 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1597 |
| 1598 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1599 auto callable = tester.GetCallable<>(); |
| 1600 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1601 Handle<Object> expected_value = factory->NewNumber(rhs_inputs[r]); |
| 1602 CHECK(return_value->SameValue(*expected_value)); |
| 1603 } |
| 1604 } |
| 1605 } |
| 1606 |
| 1607 |
| 1608 TEST(InterpreterCommaString) { |
| 1609 HandleAndZoneScope handles; |
| 1610 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 1611 Register reg(0); |
| 1612 i::Factory* factory = handles.main_isolate()->factory(); |
| 1613 builder.set_locals_count(1); |
| 1614 builder.set_parameter_count(0); |
| 1615 |
| 1616 builder.LoadLiteral(factory->NewNumber(20.34)) |
| 1617 .StoreAccumulatorInRegister(reg) |
| 1618 .LoadLiteral(factory->NewStringFromAsciiChecked("abc")) |
| 1619 .Return(); |
| 1620 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1621 |
| 1622 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1623 auto callable = tester.GetCallable<>(); |
| 1624 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1625 Handle<Object> expected_value = factory->NewStringFromAsciiChecked("abc"); |
| 1626 CHECK(return_value->SameValue(*expected_value)); |
| 1627 } |
| 1628 |
| 1629 |
| 1630 TEST(InterpreterLogicalOr) { |
| 1631 int lhs_inputs[] = {0, 1, 12, -345}; |
| 1632 int rhs_inputs[] = {12, 0, -456, 1}; |
| 1633 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| 1634 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| 1635 HandleAndZoneScope handles; |
| 1636 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 1637 builder.set_locals_count(1); |
| 1638 builder.set_parameter_count(0); |
| 1639 Register reg(0); |
| 1640 BytecodeLabel label[2]; |
| 1641 |
| 1642 builder.LoadLiteral(Smi::FromInt(lhs_inputs[l])) |
| 1643 .StoreAccumulatorInRegister(reg) |
| 1644 .CastAccumulatorToBoolean() |
| 1645 .JumpIfFalse(&label[0]) |
| 1646 .LoadAccumulatorWithRegister(reg) |
| 1647 .Jump(&label[1]) |
| 1648 .Bind(&label[0]) |
| 1649 .LoadLiteral(Smi::FromInt(rhs_inputs[r])) |
| 1650 .Bind(&label[1]) |
| 1651 .Return(); |
| 1652 |
| 1653 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1654 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1655 auto callable = tester.GetCallable<>(); |
| 1656 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1657 int expected_value = lhs_inputs[l]; |
| 1658 if (!lhs_inputs[l]) expected_value = rhs_inputs[r]; |
| 1659 CHECK_EQ(Smi::cast(*return_value)->value(), expected_value); |
| 1660 } |
| 1661 } |
| 1662 } |
| 1663 |
| 1664 |
| 1665 TEST(InterpreterLogicalAnd) { |
| 1666 int lhs_inputs[] = {0, 1, 12, -345}; |
| 1667 int rhs_inputs[] = {12, 0, -456, 1}; |
| 1668 for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| 1669 for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| 1670 HandleAndZoneScope handles; |
| 1671 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 1672 builder.set_locals_count(1); |
| 1673 builder.set_parameter_count(0); |
| 1674 Register reg(0); |
| 1675 BytecodeLabel label[2]; |
| 1676 |
| 1677 builder.LoadLiteral(Smi::FromInt(lhs_inputs[l])) |
| 1678 .StoreAccumulatorInRegister(reg) |
| 1679 .CastAccumulatorToBoolean() |
| 1680 .JumpIfTrue(&label[0]) |
| 1681 .LoadAccumulatorWithRegister(reg) |
| 1682 .Jump(&label[1]) |
| 1683 .Bind(&label[0]) |
| 1684 .LoadLiteral(Smi::FromInt(rhs_inputs[r])) |
| 1685 .Bind(&label[1]) |
| 1686 .Return(); |
| 1687 |
| 1688 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1689 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1690 auto callable = tester.GetCallable<>(); |
| 1691 Handle<Object> return_value = callable().ToHandleChecked(); |
| 1692 int expected_value = lhs_inputs[l]; |
| 1693 if (lhs_inputs[l]) expected_value = rhs_inputs[r]; |
| 1694 CHECK_EQ(Smi::cast(*return_value)->value(), expected_value); |
| 1695 } |
| 1696 } |
| 1697 } |
OLD | NEW |