Chromium Code Reviews| Index: test/cctest/interpreter/test-interpreter.cc |
| diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc |
| index 188b3e61d99c5f8aef53684ba6eeff20819e06ac..279117ebbca2b8e0736c1ff068d9aa8a02560049 100644 |
| --- a/test/cctest/interpreter/test-interpreter.cc |
| +++ b/test/cctest/interpreter/test-interpreter.cc |
| @@ -1637,3 +1637,145 @@ TEST(InterpreterFunctionLiteral) { |
| Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); |
| CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
| } |
| + |
| + |
| +TEST(InterpreterCommaSmi) { |
|
rmcilroy
2015/10/13 15:43:24
I'm not sure these are really useful tests (also t
mythria
2015/10/14 13:33:42
Done.
|
| + HandleAndZoneScope handles; |
| + BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| + Register reg(0); |
| + i::Factory* factory = handles.main_isolate()->factory(); |
| + builder.set_locals_count(1); |
| + builder.set_parameter_count(0); |
| + |
| + builder.LoadLiteral(Smi::FromInt(10)) |
| + .StoreAccumulatorInRegister(reg) |
| + .LoadLiteral(Smi::FromInt(300)) |
| + .Return(); |
| + Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| + |
| + InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| + auto callable = tester.GetCallable<>(); |
| + Handle<Object> return_value = callable().ToHandleChecked(); |
| + Handle<Object> expected_value = factory->NewNumber(300); |
| + CHECK(return_value->SameValue(*expected_value)); |
| +} |
| + |
| + |
| +TEST(InterpreterCommaHeapNumber) { |
| + double lhs_inputs[] = {32.73, 56e-12}; |
| + double rhs_inputs[] = {8.3e-27, 32.73}; |
| + for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| + for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| + HandleAndZoneScope handles; |
| + BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| + Register reg(0); |
| + i::Factory* factory = handles.main_isolate()->factory(); |
| + builder.set_locals_count(1); |
| + builder.set_parameter_count(0); |
| + |
| + builder.LoadLiteral(factory->NewNumber(lhs_inputs[l])) |
| + .StoreAccumulatorInRegister(reg) |
| + .LoadLiteral(factory->NewNumber(rhs_inputs[r])) |
| + .Return(); |
| + Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| + |
| + InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| + auto callable = tester.GetCallable<>(); |
| + Handle<Object> return_value = callable().ToHandleChecked(); |
| + Handle<Object> expected_value = factory->NewNumber(rhs_inputs[r]); |
| + CHECK(return_value->SameValue(*expected_value)); |
| + } |
| + } |
| +} |
| + |
| + |
| +TEST(InterpreterCommaString) { |
| + HandleAndZoneScope handles; |
| + BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| + Register reg(0); |
| + i::Factory* factory = handles.main_isolate()->factory(); |
| + builder.set_locals_count(1); |
| + builder.set_parameter_count(0); |
| + |
| + builder.LoadLiteral(factory->NewNumber(20.34)) |
| + .StoreAccumulatorInRegister(reg) |
| + .LoadLiteral(factory->NewStringFromAsciiChecked("abc")) |
| + .Return(); |
| + Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| + |
| + InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| + auto callable = tester.GetCallable<>(); |
| + Handle<Object> return_value = callable().ToHandleChecked(); |
| + Handle<Object> expected_value = factory->NewStringFromAsciiChecked("abc"); |
| + CHECK(return_value->SameValue(*expected_value)); |
| +} |
| + |
| + |
| +TEST(InterpreterLogicalOr) { |
| + int lhs_inputs[] = {0, 1, 12, -345}; |
| + int rhs_inputs[] = {12, 0, -456, 1}; |
| + for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| + for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| + HandleAndZoneScope handles; |
| + BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| + builder.set_locals_count(1); |
| + builder.set_parameter_count(0); |
| + Register reg(0); |
| + BytecodeLabel label[2]; |
| + |
| + builder.LoadLiteral(Smi::FromInt(lhs_inputs[l])) |
| + .StoreAccumulatorInRegister(reg) |
| + .CastAccumulatorToBoolean() |
| + .JumpIfFalse(&label[0]) |
| + .LoadAccumulatorWithRegister(reg) |
| + .Jump(&label[1]) |
| + .Bind(&label[0]) |
| + .LoadLiteral(Smi::FromInt(rhs_inputs[r])) |
| + .Bind(&label[1]) |
| + .Return(); |
| + |
| + Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| + InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| + auto callable = tester.GetCallable<>(); |
| + Handle<Object> return_value = callable().ToHandleChecked(); |
| + int expected_value = lhs_inputs[l]; |
| + if (!lhs_inputs[l]) expected_value = rhs_inputs[r]; |
| + CHECK_EQ(Smi::cast(*return_value)->value(), expected_value); |
| + } |
| + } |
| +} |
| + |
| + |
| +TEST(InterpreterLogicalAnd) { |
| + int lhs_inputs[] = {0, 1, 12, -345}; |
| + int rhs_inputs[] = {12, 0, -456, 1}; |
| + for (size_t l = 0; l < arraysize(lhs_inputs); l++) { |
| + for (size_t r = 0; r < arraysize(rhs_inputs); r++) { |
| + HandleAndZoneScope handles; |
| + BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| + builder.set_locals_count(1); |
| + builder.set_parameter_count(0); |
| + Register reg(0); |
| + BytecodeLabel label[2]; |
| + |
| + builder.LoadLiteral(Smi::FromInt(lhs_inputs[l])) |
| + .StoreAccumulatorInRegister(reg) |
| + .CastAccumulatorToBoolean() |
| + .JumpIfTrue(&label[0]) |
| + .LoadAccumulatorWithRegister(reg) |
| + .Jump(&label[1]) |
| + .Bind(&label[0]) |
| + .LoadLiteral(Smi::FromInt(rhs_inputs[r])) |
| + .Bind(&label[1]) |
| + .Return(); |
| + |
| + Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| + InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| + auto callable = tester.GetCallable<>(); |
| + Handle<Object> return_value = callable().ToHandleChecked(); |
| + int expected_value = lhs_inputs[l]; |
| + if (lhs_inputs[l]) expected_value = rhs_inputs[r]; |
| + CHECK_EQ(Smi::cast(*return_value)->value(), expected_value); |
| + } |
| + } |
| +} |