| Index: test/unittests/interpreter/bytecode-array-builder-unittest.cc
|
| diff --git a/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
|
| index 779361ffcff34c4b9bccdf6258becc055cff534f..6ae888bd31e0ebb852938470d696e616fd34c86d 100644
|
| --- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc
|
| +++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
|
| @@ -94,13 +94,12 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
|
| // Build scorecard of bytecodes encountered in the BytecodeArray.
|
| std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1);
|
| Bytecode final_bytecode = Bytecode::kLdaZero;
|
| - for (int i = 0; i < the_array->length(); i++) {
|
| + int i = 0;
|
| + while (i < the_array->length()) {
|
| uint8_t code = the_array->get(i);
|
| scorecard[code] += 1;
|
| - int operands = Bytecodes::NumberOfOperands(Bytecodes::FromByte(code));
|
| - CHECK_LE(operands, Bytecodes::MaximumNumberOfOperands());
|
| final_bytecode = Bytecodes::FromByte(code);
|
| - i += operands;
|
| + i += Bytecodes::Size(Bytecodes::FromByte(code));
|
| }
|
|
|
| // Check return occurs at the end and only once in the BytecodeArray.
|
| @@ -392,6 +391,53 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
|
| }
|
|
|
|
|
| +TEST_F(BytecodeArrayBuilderTest, ToBoolean) {
|
| + BytecodeArrayBuilder builder(isolate(), zone());
|
| + builder.set_parameter_count(0);
|
| + builder.set_locals_count(0);
|
| +
|
| + // Check ToBoolean emitted at start of block.
|
| + builder.EnterBlock().CastAccumulatorToBoolean();
|
| +
|
| + // Check ToBoolean emitted preceding bytecode is non-boolean.
|
| + builder.LoadNull().CastAccumulatorToBoolean();
|
| +
|
| + // Check ToBoolean omitted if preceding bytecode is boolean.
|
| + builder.LoadFalse().CastAccumulatorToBoolean();
|
| +
|
| + // Check ToBoolean emitted if it is at the start of the next block.
|
| + builder.LoadFalse()
|
| + .LeaveBlock()
|
| + .EnterBlock()
|
| + .CastAccumulatorToBoolean()
|
| + .LeaveBlock();
|
| +
|
| + builder.Return();
|
| +
|
| + Handle<BytecodeArray> array = builder.ToBytecodeArray();
|
| + BytecodeArrayIterator iterator(array);
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
|
| + iterator.Advance();
|
| +
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaNull);
|
| + iterator.Advance();
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
|
| + iterator.Advance();
|
| +
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
|
| + iterator.Advance();
|
| +
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
|
| + iterator.Advance();
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
|
| + iterator.Advance();
|
| +
|
| + CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
|
| + iterator.Advance();
|
| + CHECK(iterator.done());
|
| +}
|
| +
|
| +
|
| } // namespace interpreter
|
| } // namespace internal
|
| } // namespace v8
|
|
|