| Index: test/cctest/interpreter/test-interpreter.cc
|
| diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
|
| index 7343d0818269cf8865a0cb32fcc52094e06b861b..658af24a4937bd0a7f9e3c540ed65eb692639da6 100644
|
| --- a/test/cctest/interpreter/test-interpreter.cc
|
| +++ b/test/cctest/interpreter/test-interpreter.cc
|
| @@ -1553,3 +1553,145 @@ TEST(InterpreterCallRuntime) {
|
| Handle<Object> return_val = callable().ToHandleChecked();
|
| CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55));
|
| }
|
| +
|
| +
|
| +TEST(InterpreterCommaSmi) {
|
| + 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);
|
| + }
|
| + }
|
| +}
|
|
|