| Index: test/unittests/compiler/js-operator-unittest.cc
|
| diff --git a/test/unittests/compiler/js-operator-unittest.cc b/test/unittests/compiler/js-operator-unittest.cc
|
| index e69a99c6193c7639cbf983cfbabda16e8b8dd499..566133d8e2aa73e0026925a25486f12d8b58a9ce 100644
|
| --- a/test/unittests/compiler/js-operator-unittest.cc
|
| +++ b/test/unittests/compiler/js-operator-unittest.cc
|
| @@ -12,14 +12,18 @@ namespace v8 {
|
| namespace internal {
|
| namespace compiler {
|
|
|
| -// -----------------------------------------------------------------------------
|
| -// Shared operators.
|
| -
|
|
|
| namespace {
|
|
|
| +typedef const Operator* (JSOperatorBuilder::*no_params_t) () ;
|
| +
|
| +typedef const Operator* (JSOperatorBuilder::*with_language_mode_t)
|
| + (LanguageMode language_mode) ;
|
| +
|
| +
|
| +template <typename T>
|
| struct SharedOperator {
|
| - const Operator* (JSOperatorBuilder::*constructor)();
|
| + T constructor;
|
| IrOpcode::Value opcode;
|
| Operator::Properties properties;
|
| int value_input_count;
|
| @@ -32,12 +36,7 @@ struct SharedOperator {
|
| };
|
|
|
|
|
| -std::ostream& operator<<(std::ostream& os, const SharedOperator& sop) {
|
| - return os << IrOpcode::Mnemonic(sop.opcode);
|
| -}
|
| -
|
| -
|
| -const SharedOperator kSharedOperators[] = {
|
| +const SharedOperator<no_params_t> kSharedOperators[] = {
|
| #define SHARED(Name, properties, value_input_count, frame_state_input_count, \
|
| effect_input_count, control_input_count, value_output_count, \
|
| effect_output_count, control_output_count) \
|
| @@ -51,22 +50,6 @@ const SharedOperator kSharedOperators[] = {
|
| SHARED(NotEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| SHARED(StrictEqual, Operator::kPure, 2, 0, 0, 0, 1, 0, 0),
|
| SHARED(StrictNotEqual, Operator::kPure, 2, 0, 0, 0, 1, 0, 0),
|
| - SHARED(LessThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| - SHARED(GreaterThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| - SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| - SHARED(GreaterThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| - SHARED(BitwiseOr, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(BitwiseXor, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(BitwiseAnd, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(ShiftLeft, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(ShiftRight, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(ShiftRightLogical, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(Add, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(Subtract, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(Multiply, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(Divide, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(Modulus, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| - SHARED(UnaryNot, Operator::kPure, 1, 0, 0, 0, 1, 0, 0),
|
| SHARED(ToBoolean, Operator::kPure, 1, 0, 0, 0, 1, 0, 0),
|
| SHARED(ToNumber, Operator::kNoProperties, 1, 1, 1, 1, 1, 1, 2),
|
| SHARED(ToString, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2),
|
| @@ -85,27 +68,41 @@ const SharedOperator kSharedOperators[] = {
|
| #undef SHARED
|
| };
|
|
|
| -} // namespace
|
| -
|
| -
|
| -class JSSharedOperatorTest
|
| - : public TestWithZone,
|
| - public ::testing::WithParamInterface<SharedOperator> {};
|
| -
|
| -
|
| -TEST_P(JSSharedOperatorTest, InstancesAreGloballyShared) {
|
| - const SharedOperator& sop = GetParam();
|
| - JSOperatorBuilder javascript1(zone());
|
| - JSOperatorBuilder javascript2(zone());
|
| - EXPECT_EQ((javascript1.*sop.constructor)(), (javascript2.*sop.constructor)());
|
| -}
|
|
|
| +const SharedOperator<with_language_mode_t>
|
| + kSharedOperatorsWithlanguageMode[] = {
|
| +#define SHARED(Name, properties, value_input_count, frame_state_input_count, \
|
| + effect_input_count, control_input_count, value_output_count, \
|
| + effect_output_count, control_output_count) \
|
| + { \
|
| + &JSOperatorBuilder::Name, IrOpcode::kJS##Name, properties, \
|
| + value_input_count, frame_state_input_count, effect_input_count, \
|
| + control_input_count, value_output_count, effect_output_count, \
|
| + control_output_count \
|
| + }
|
| + SHARED(LessThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| + SHARED(GreaterThan, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| + SHARED(LessThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| + SHARED(GreaterThanOrEqual, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
|
| + SHARED(BitwiseOr, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(BitwiseXor, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(BitwiseAnd, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(ShiftLeft, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(ShiftRight, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(ShiftRightLogical, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(Add, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(Subtract, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(Multiply, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(Divide, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(Modulus, Operator::kNoProperties, 2, 2, 1, 1, 1, 1, 2),
|
| + SHARED(UnaryNot, Operator::kPure, 1, 0, 0, 0, 1, 0, 0),
|
| +#undef SHARED
|
| +};
|
|
|
| -TEST_P(JSSharedOperatorTest, NumberOfInputsAndOutputs) {
|
| - JSOperatorBuilder javascript(zone());
|
| - const SharedOperator& sop = GetParam();
|
| - const Operator* op = (javascript.*sop.constructor)();
|
|
|
| +template <typename T>
|
| +void testNumberOfInputsAndOutputs(const SharedOperator<T>& sop,
|
| + const Operator* op) {
|
| const int context_input_count = 1;
|
| EXPECT_EQ(sop.value_input_count, op->ValueInputCount());
|
| EXPECT_EQ(context_input_count, OperatorProperties::GetContextInputCount(op));
|
| @@ -124,9 +121,48 @@ TEST_P(JSSharedOperatorTest, NumberOfInputsAndOutputs) {
|
| }
|
|
|
|
|
| +std::ostream& operator<<(std::ostream& os,
|
| + const SharedOperator<no_params_t>& sop) {
|
| + return os << IrOpcode::Mnemonic(sop.opcode);
|
| +}
|
| +
|
| +
|
| +std::ostream& operator<<(std::ostream& os,
|
| + const SharedOperator<with_language_mode_t>& sop) {
|
| + return os << IrOpcode::Mnemonic(sop.opcode);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +
|
| +// -----------------------------------------------------------------------------
|
| +// Shared operators.
|
| +
|
| +
|
| +class JSSharedOperatorTest
|
| + : public TestWithZone,
|
| + public ::testing::WithParamInterface<SharedOperator<no_params_t>> {};
|
| +
|
| +
|
| +TEST_P(JSSharedOperatorTest, InstancesAreGloballyShared) {
|
| + const SharedOperator<no_params_t>& sop = GetParam();
|
| + JSOperatorBuilder javascript1(zone());
|
| + JSOperatorBuilder javascript2(zone());
|
| + EXPECT_EQ((javascript1.*sop.constructor)(), (javascript2.*sop.constructor)());
|
| +}
|
| +
|
| +
|
| +TEST_P(JSSharedOperatorTest, NumberOfInputsAndOutputs) {
|
| + JSOperatorBuilder javascript(zone());
|
| + const SharedOperator<no_params_t>& sop = GetParam();
|
| + const Operator* op = (javascript.*sop.constructor)();
|
| + testNumberOfInputsAndOutputs(sop, op);
|
| +}
|
| +
|
| +
|
| TEST_P(JSSharedOperatorTest, OpcodeIsCorrect) {
|
| JSOperatorBuilder javascript(zone());
|
| - const SharedOperator& sop = GetParam();
|
| + const SharedOperator<no_params_t>& sop = GetParam();
|
| const Operator* op = (javascript.*sop.constructor)();
|
| EXPECT_EQ(sop.opcode, op->opcode());
|
| }
|
| @@ -134,7 +170,7 @@ TEST_P(JSSharedOperatorTest, OpcodeIsCorrect) {
|
|
|
| TEST_P(JSSharedOperatorTest, Properties) {
|
| JSOperatorBuilder javascript(zone());
|
| - const SharedOperator& sop = GetParam();
|
| + const SharedOperator<no_params_t>& sop = GetParam();
|
| const Operator* op = (javascript.*sop.constructor)();
|
| EXPECT_EQ(sop.properties, op->properties());
|
| }
|
| @@ -143,6 +179,65 @@ TEST_P(JSSharedOperatorTest, Properties) {
|
| INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorTest,
|
| ::testing::ValuesIn(kSharedOperators));
|
|
|
| +// -----------------------------------------------------------------------------
|
| +// Shared operators which behave differently in strong mode
|
| +
|
| +
|
| +class JSSharedOperatorWithStrongTest
|
| + : public TestWithZone,
|
| + public ::testing::WithParamInterface<
|
| + SharedOperator<with_language_mode_t>>{};
|
| +
|
| +
|
| +TEST_P(JSSharedOperatorWithStrongTest, InstancesAreGloballyShared) {
|
| + const SharedOperator<with_language_mode_t>& sop = GetParam();
|
| + JSOperatorBuilder javascript1(zone());
|
| + JSOperatorBuilder javascript2(zone());
|
| + EXPECT_EQ((javascript1.*sop.constructor)(LanguageMode::SLOPPY),
|
| + (javascript2.*sop.constructor)(LanguageMode::SLOPPY));
|
| + EXPECT_EQ((javascript1.*sop.constructor)(LanguageMode::STRONG),
|
| + (javascript2.*sop.constructor)(LanguageMode::STRONG));
|
| +}
|
| +
|
| +
|
| +TEST_P(JSSharedOperatorWithStrongTest, NumberOfInputsAndOutputs) {
|
| + JSOperatorBuilder javascript(zone());
|
| + const SharedOperator<with_language_mode_t>& sop = GetParam();
|
| + const Operator* op_sloppy = (javascript.*sop.constructor)
|
| + (LanguageMode::SLOPPY);
|
| + testNumberOfInputsAndOutputs(sop, op_sloppy);
|
| + const Operator* op_strong = (javascript.*sop.constructor)
|
| + (LanguageMode::STRONG);
|
| + testNumberOfInputsAndOutputs(sop, op_strong);
|
| +}
|
| +
|
| +
|
| +TEST_P(JSSharedOperatorWithStrongTest, OpcodeIsCorrect) {
|
| + JSOperatorBuilder javascript(zone());
|
| + const SharedOperator<with_language_mode_t>& sop = GetParam();
|
| + const Operator* op_sloppy = (javascript.*sop.constructor)
|
| + (LanguageMode::SLOPPY);
|
| + EXPECT_EQ(sop.opcode, op_sloppy->opcode());
|
| + const Operator* op_strong = (javascript.*sop.constructor)
|
| + (LanguageMode::STRONG);
|
| + EXPECT_EQ(sop.opcode, op_strong->opcode());
|
| +}
|
| +
|
| +
|
| +TEST_P(JSSharedOperatorWithStrongTest, Properties) {
|
| + JSOperatorBuilder javascript(zone());
|
| + const SharedOperator<with_language_mode_t>& sop = GetParam();
|
| + const Operator* op_sloppy = (javascript.*sop.constructor)
|
| + (LanguageMode::SLOPPY);
|
| + EXPECT_EQ(sop.properties, op_sloppy->properties());
|
| + const Operator* op_strong = (javascript.*sop.constructor)
|
| + (LanguageMode::STRONG);
|
| + EXPECT_EQ(sop.properties, op_strong->properties());
|
| +}
|
| +
|
| +
|
| +INSTANTIATE_TEST_CASE_P(JSOperatorTest, JSSharedOperatorWithStrongTest,
|
| + ::testing::ValuesIn(kSharedOperatorsWithlanguageMode));
|
|
|
| // -----------------------------------------------------------------------------
|
| // JSStoreProperty.
|
|
|