2017-06-27 08:44:35 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2017-06-27 08:44:35 +00:00
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/source-position-table.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2017-06-27 08:44:35 +00:00
|
|
|
#include "src/interpreter/bytecode-array-writer.h"
|
|
|
|
#include "src/interpreter/bytecode-label.h"
|
|
|
|
#include "src/interpreter/bytecode-node.h"
|
|
|
|
#include "src/interpreter/bytecode-register.h"
|
|
|
|
#include "src/interpreter/bytecode-source-info.h"
|
|
|
|
#include "src/interpreter/constant-array-builder.h"
|
2019-05-23 13:27:57 +00:00
|
|
|
#include "src/utils/utils.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2017-06-27 08:44:35 +00:00
|
|
|
#include "test/unittests/interpreter/bytecode-utils.h"
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
2017-10-18 17:01:45 +00:00
|
|
|
namespace bytecode_array_writer_unittest {
|
2017-06-27 08:44:35 +00:00
|
|
|
|
2017-11-09 09:05:52 +00:00
|
|
|
#define B(Name) static_cast<uint8_t>(Bytecode::k##Name)
|
2017-06-27 08:44:35 +00:00
|
|
|
#define R(i) static_cast<uint32_t>(Register(i).ToOperand())
|
|
|
|
|
|
|
|
class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
|
|
|
BytecodeArrayWriterUnittest()
|
|
|
|
: constant_array_builder_(zone()),
|
|
|
|
bytecode_array_writer_(
|
|
|
|
zone(), &constant_array_builder_,
|
|
|
|
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {}
|
2018-09-13 09:22:50 +00:00
|
|
|
~BytecodeArrayWriterUnittest() override = default;
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
void Write(Bytecode bytecode, BytecodeSourceInfo info = BytecodeSourceInfo());
|
|
|
|
void Write(Bytecode bytecode, uint32_t operand0,
|
|
|
|
BytecodeSourceInfo info = BytecodeSourceInfo());
|
|
|
|
void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
|
|
|
|
BytecodeSourceInfo info = BytecodeSourceInfo());
|
|
|
|
void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
|
|
|
|
uint32_t operand2, BytecodeSourceInfo info = BytecodeSourceInfo());
|
|
|
|
void Write(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
|
|
|
|
uint32_t operand2, uint32_t operand3,
|
|
|
|
BytecodeSourceInfo info = BytecodeSourceInfo());
|
|
|
|
|
|
|
|
void WriteJump(Bytecode bytecode, BytecodeLabel* label,
|
|
|
|
BytecodeSourceInfo info = BytecodeSourceInfo());
|
2019-02-28 13:34:26 +00:00
|
|
|
void WriteJumpLoop(Bytecode bytecode, BytecodeLoopHeader* loop_header,
|
|
|
|
int depth, BytecodeSourceInfo info = BytecodeSourceInfo());
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
BytecodeArrayWriter* writer() { return &bytecode_array_writer_; }
|
|
|
|
ZoneVector<unsigned char>* bytecodes() { return writer()->bytecodes(); }
|
|
|
|
SourcePositionTableBuilder* source_position_table_builder() {
|
|
|
|
return writer()->source_position_table_builder();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ConstantArrayBuilder constant_array_builder_;
|
|
|
|
BytecodeArrayWriter bytecode_array_writer_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode,
|
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, info);
|
|
|
|
writer()->Write(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0,
|
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, operand0, info);
|
|
|
|
writer()->Write(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0,
|
|
|
|
uint32_t operand1,
|
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, operand0, operand1, info);
|
|
|
|
writer()->Write(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0,
|
|
|
|
uint32_t operand1, uint32_t operand2,
|
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, operand0, operand1, operand2, info);
|
|
|
|
writer()->Write(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::Write(Bytecode bytecode, uint32_t operand0,
|
|
|
|
uint32_t operand1, uint32_t operand2,
|
|
|
|
uint32_t operand3,
|
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, operand0, operand1, operand2, operand3, info);
|
|
|
|
writer()->Write(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::WriteJump(Bytecode bytecode,
|
|
|
|
BytecodeLabel* label,
|
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, 0, info);
|
|
|
|
writer()->WriteJump(&node, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BytecodeArrayWriterUnittest::WriteJumpLoop(Bytecode bytecode,
|
2019-02-28 13:34:26 +00:00
|
|
|
BytecodeLoopHeader* loop_header,
|
|
|
|
int depth,
|
2017-06-27 08:44:35 +00:00
|
|
|
BytecodeSourceInfo info) {
|
|
|
|
BytecodeNode node(bytecode, 0, depth, info);
|
2019-02-28 13:34:26 +00:00
|
|
|
writer()->WriteJumpLoop(&node, loop_header);
|
2017-06-27 08:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeArrayWriterUnittest, SimpleExample) {
|
|
|
|
CHECK_EQ(bytecodes()->size(), 0u);
|
|
|
|
|
|
|
|
Write(Bytecode::kLdaSmi, 127, {55, true});
|
2020-03-20 14:28:41 +00:00
|
|
|
CHECK_EQ(bytecodes()->size(), 2u);
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
Write(Bytecode::kStar, Register(20).ToOperand());
|
2020-03-20 14:28:41 +00:00
|
|
|
CHECK_EQ(bytecodes()->size(), 4u);
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
Write(Bytecode::kLdar, Register(200).ToOperand());
|
2020-03-20 14:28:41 +00:00
|
|
|
CHECK_EQ(bytecodes()->size(), 8u);
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
Write(Bytecode::kReturn, {70, true});
|
2020-03-20 14:28:41 +00:00
|
|
|
CHECK_EQ(bytecodes()->size(), 9u);
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
static const uint8_t expected_bytes[] = {
|
|
|
|
// clang-format off
|
2020-03-20 14:28:41 +00:00
|
|
|
/* 0 55 S> */ B(LdaSmi), U8(127),
|
|
|
|
/* 2 */ B(Star), R8(20),
|
|
|
|
/* 4 */ B(Wide), B(Ldar), R16(200),
|
|
|
|
/* 8 70 S> */ B(Return),
|
2017-06-27 08:44:35 +00:00
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes));
|
|
|
|
for (size_t i = 0; i < arraysize(expected_bytes); ++i) {
|
|
|
|
CHECK_EQ(bytecodes()->at(i), expected_bytes[i]);
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:23:48 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
writer()->ToBytecodeArray(isolate(), 0, 0, factory()->empty_byte_array());
|
2020-10-05 09:22:13 +00:00
|
|
|
bytecode_array->set_source_position_table(
|
|
|
|
*writer()->ToSourcePositionTable(isolate()), kReleaseStore);
|
2017-06-27 08:44:35 +00:00
|
|
|
CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes));
|
|
|
|
|
2020-03-20 14:28:41 +00:00
|
|
|
PositionTableEntry expected_positions[] = {{0, 55, true}, {8, 70, true}};
|
2017-06-27 08:44:35 +00:00
|
|
|
SourcePositionTableIterator source_iterator(
|
|
|
|
bytecode_array->SourcePositionTable());
|
|
|
|
for (size_t i = 0; i < arraysize(expected_positions); ++i) {
|
|
|
|
const PositionTableEntry& expected = expected_positions[i];
|
|
|
|
CHECK_EQ(source_iterator.code_offset(), expected.code_offset);
|
|
|
|
CHECK_EQ(source_iterator.source_position().ScriptOffset(),
|
|
|
|
expected.source_position);
|
|
|
|
CHECK_EQ(source_iterator.is_statement(), expected.is_statement);
|
|
|
|
source_iterator.Advance();
|
|
|
|
}
|
|
|
|
CHECK(source_iterator.done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeArrayWriterUnittest, ComplexExample) {
|
|
|
|
static const uint8_t expected_bytes[] = {
|
|
|
|
// clang-format off
|
2020-03-20 14:28:41 +00:00
|
|
|
/* 0 42 S> */ B(LdaConstant), U8(0),
|
|
|
|
/* 2 42 E> */ B(Add), R8(1), U8(1),
|
|
|
|
/* 4 68 S> */ B(JumpIfUndefined), U8(38),
|
|
|
|
/* 6 */ B(JumpIfNull), U8(36),
|
|
|
|
/* 8 */ B(ToObject), R8(3),
|
|
|
|
/* 10 */ B(ForInPrepare), R8(3), U8(4),
|
|
|
|
/* 13 */ B(LdaZero),
|
|
|
|
/* 14 */ B(Star), R8(7),
|
|
|
|
/* 16 63 S> */ B(ForInContinue), R8(7), R8(6),
|
|
|
|
/* 19 */ B(JumpIfFalse), U8(23),
|
|
|
|
/* 21 */ B(ForInNext), R8(3), R8(7), R8(4), U8(1),
|
|
|
|
/* 26 */ B(JumpIfUndefined), U8(9),
|
|
|
|
/* 28 */ B(Star), R8(0),
|
|
|
|
/* 30 */ B(Ldar), R8(0),
|
|
|
|
/* 32 */ B(Star), R8(2),
|
|
|
|
/* 34 85 S> */ B(Return),
|
|
|
|
/* 35 */ B(ForInStep), R8(7),
|
|
|
|
/* 37 */ B(Star), R8(7),
|
|
|
|
/* 39 */ B(JumpLoop), U8(23), U8(0),
|
|
|
|
/* 42 */ B(LdaUndefined),
|
|
|
|
/* 43 85 S> */ B(Return),
|
2017-06-27 08:44:35 +00:00
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
|
|
|
|
static const PositionTableEntry expected_positions[] = {
|
2020-03-20 14:28:41 +00:00
|
|
|
{0, 42, true}, {2, 42, false}, {5, 68, true},
|
|
|
|
{17, 63, true}, {35, 85, true}, {44, 85, true}};
|
2017-06-27 08:44:35 +00:00
|
|
|
|
2019-02-28 13:34:26 +00:00
|
|
|
BytecodeLoopHeader loop_header;
|
|
|
|
BytecodeLabel jump_for_in, jump_end_1, jump_end_2, jump_end_3;
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
Write(Bytecode::kLdaConstant, U8(0), {42, true});
|
|
|
|
Write(Bytecode::kAdd, R(1), U8(1), {42, false});
|
|
|
|
WriteJump(Bytecode::kJumpIfUndefined, &jump_end_1, {68, true});
|
|
|
|
WriteJump(Bytecode::kJumpIfNull, &jump_end_2);
|
|
|
|
Write(Bytecode::kToObject, R(3));
|
2017-09-01 10:49:06 +00:00
|
|
|
Write(Bytecode::kForInPrepare, R(3), U8(4));
|
2017-06-27 08:44:35 +00:00
|
|
|
Write(Bytecode::kLdaZero);
|
|
|
|
Write(Bytecode::kStar, R(7));
|
2019-02-28 13:34:26 +00:00
|
|
|
writer()->BindLoopHeader(&loop_header);
|
2017-06-27 08:44:35 +00:00
|
|
|
Write(Bytecode::kForInContinue, R(7), R(6), {63, true});
|
|
|
|
WriteJump(Bytecode::kJumpIfFalse, &jump_end_3);
|
|
|
|
Write(Bytecode::kForInNext, R(3), R(7), R(4), U8(1));
|
|
|
|
WriteJump(Bytecode::kJumpIfUndefined, &jump_for_in);
|
|
|
|
Write(Bytecode::kStar, R(0));
|
|
|
|
Write(Bytecode::kLdar, R(0));
|
|
|
|
Write(Bytecode::kStar, R(2));
|
|
|
|
Write(Bytecode::kReturn, {85, true});
|
|
|
|
writer()->BindLabel(&jump_for_in);
|
|
|
|
Write(Bytecode::kForInStep, R(7));
|
|
|
|
Write(Bytecode::kStar, R(7));
|
2019-02-28 13:34:26 +00:00
|
|
|
WriteJumpLoop(Bytecode::kJumpLoop, &loop_header, 0);
|
2017-06-27 08:44:35 +00:00
|
|
|
writer()->BindLabel(&jump_end_1);
|
|
|
|
writer()->BindLabel(&jump_end_2);
|
|
|
|
writer()->BindLabel(&jump_end_3);
|
|
|
|
Write(Bytecode::kLdaUndefined);
|
|
|
|
Write(Bytecode::kReturn, {85, true});
|
|
|
|
|
|
|
|
CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes));
|
|
|
|
for (size_t i = 0; i < arraysize(expected_bytes); ++i) {
|
|
|
|
CHECK_EQ(static_cast<int>(bytecodes()->at(i)),
|
|
|
|
static_cast<int>(expected_bytes[i]));
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:23:48 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
writer()->ToBytecodeArray(isolate(), 0, 0, factory()->empty_byte_array());
|
2020-10-05 09:22:13 +00:00
|
|
|
bytecode_array->set_source_position_table(
|
|
|
|
*writer()->ToSourcePositionTable(isolate()), kReleaseStore);
|
2017-06-27 08:44:35 +00:00
|
|
|
SourcePositionTableIterator source_iterator(
|
|
|
|
bytecode_array->SourcePositionTable());
|
|
|
|
for (size_t i = 0; i < arraysize(expected_positions); ++i) {
|
|
|
|
const PositionTableEntry& expected = expected_positions[i];
|
|
|
|
CHECK_EQ(source_iterator.code_offset(), expected.code_offset);
|
|
|
|
CHECK_EQ(source_iterator.source_position().ScriptOffset(),
|
|
|
|
expected.source_position);
|
|
|
|
CHECK_EQ(source_iterator.is_statement(), expected.is_statement);
|
|
|
|
source_iterator.Advance();
|
|
|
|
}
|
|
|
|
CHECK(source_iterator.done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeArrayWriterUnittest, ElideNoneffectfulBytecodes) {
|
|
|
|
if (!i::FLAG_ignition_elide_noneffectful_bytecodes) return;
|
|
|
|
|
|
|
|
static const uint8_t expected_bytes[] = {
|
|
|
|
// clang-format off
|
2020-03-20 14:28:41 +00:00
|
|
|
/* 0 55 S> */ B(Ldar), R8(20),
|
|
|
|
/* 2 */ B(Star), R8(20),
|
|
|
|
/* 4 */ B(CreateMappedArguments),
|
|
|
|
/* 5 60 S> */ B(LdaSmi), U8(127),
|
|
|
|
/* 7 70 S> */ B(Ldar), R8(20),
|
|
|
|
/* 9 75 S> */ B(Return),
|
2017-06-27 08:44:35 +00:00
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
|
2020-03-20 14:28:41 +00:00
|
|
|
static const PositionTableEntry expected_positions[] = {
|
|
|
|
{0, 55, true}, {5, 60, false}, {7, 70, true}, {9, 75, true}};
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
Write(Bytecode::kLdaSmi, 127, {55, true}); // Should be elided.
|
|
|
|
Write(Bytecode::kLdar, Register(20).ToOperand());
|
|
|
|
Write(Bytecode::kStar, Register(20).ToOperand());
|
|
|
|
Write(Bytecode::kLdar, Register(20).ToOperand()); // Should be elided.
|
|
|
|
Write(Bytecode::kCreateMappedArguments);
|
|
|
|
Write(Bytecode::kLdaSmi, 127, {60, false}); // Not elided due to source info.
|
|
|
|
Write(Bytecode::kLdar, Register(20).ToOperand(), {70, true});
|
|
|
|
Write(Bytecode::kReturn, {75, true});
|
|
|
|
|
|
|
|
CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes));
|
|
|
|
for (size_t i = 0; i < arraysize(expected_bytes); ++i) {
|
|
|
|
CHECK_EQ(static_cast<int>(bytecodes()->at(i)),
|
|
|
|
static_cast<int>(expected_bytes[i]));
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:23:48 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
writer()->ToBytecodeArray(isolate(), 0, 0, factory()->empty_byte_array());
|
2020-10-05 09:22:13 +00:00
|
|
|
bytecode_array->set_source_position_table(
|
|
|
|
*writer()->ToSourcePositionTable(isolate()), kReleaseStore);
|
2017-06-27 08:44:35 +00:00
|
|
|
SourcePositionTableIterator source_iterator(
|
|
|
|
bytecode_array->SourcePositionTable());
|
|
|
|
for (size_t i = 0; i < arraysize(expected_positions); ++i) {
|
|
|
|
const PositionTableEntry& expected = expected_positions[i];
|
|
|
|
CHECK_EQ(source_iterator.code_offset(), expected.code_offset);
|
|
|
|
CHECK_EQ(source_iterator.source_position().ScriptOffset(),
|
|
|
|
expected.source_position);
|
|
|
|
CHECK_EQ(source_iterator.is_statement(), expected.is_statement);
|
|
|
|
source_iterator.Advance();
|
|
|
|
}
|
|
|
|
CHECK(source_iterator.done());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeArrayWriterUnittest, DeadcodeElimination) {
|
|
|
|
static const uint8_t expected_bytes[] = {
|
|
|
|
// clang-format off
|
2020-03-20 14:28:41 +00:00
|
|
|
/* 0 55 S> */ B(LdaSmi), U8(127),
|
|
|
|
/* 2 */ B(Jump), U8(2),
|
|
|
|
/* 4 65 S> */ B(LdaSmi), U8(127),
|
|
|
|
/* 6 */ B(JumpIfFalse), U8(3),
|
|
|
|
/* 8 75 S> */ B(Return),
|
|
|
|
/* 9 */ B(JumpIfFalse), U8(3),
|
|
|
|
/* 11 */ B(Throw),
|
|
|
|
/* 12 */ B(JumpIfFalse), U8(3),
|
|
|
|
/* 14 */ B(ReThrow),
|
|
|
|
/* 15 */ B(Return),
|
2017-06-27 08:44:35 +00:00
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
|
|
|
|
static const PositionTableEntry expected_positions[] = {
|
2020-03-20 14:28:41 +00:00
|
|
|
{0, 55, true}, {4, 65, true}, {8, 75, true}};
|
2017-06-27 08:44:35 +00:00
|
|
|
|
|
|
|
BytecodeLabel after_jump, after_conditional_jump, after_return, after_throw,
|
|
|
|
after_rethrow;
|
|
|
|
|
|
|
|
Write(Bytecode::kLdaSmi, 127, {55, true});
|
|
|
|
WriteJump(Bytecode::kJump, &after_jump);
|
|
|
|
Write(Bytecode::kLdaSmi, 127); // Dead code.
|
|
|
|
WriteJump(Bytecode::kJumpIfFalse, &after_conditional_jump); // Dead code.
|
|
|
|
writer()->BindLabel(&after_jump);
|
2019-02-28 13:34:26 +00:00
|
|
|
// We would bind the after_conditional_jump label here, but the jump to it is
|
|
|
|
// dead.
|
|
|
|
CHECK(!after_conditional_jump.has_referrer_jump());
|
2017-06-27 08:44:35 +00:00
|
|
|
Write(Bytecode::kLdaSmi, 127, {65, true});
|
|
|
|
WriteJump(Bytecode::kJumpIfFalse, &after_return);
|
|
|
|
Write(Bytecode::kReturn, {75, true});
|
|
|
|
Write(Bytecode::kLdaSmi, 127, {100, true}); // Dead code.
|
|
|
|
writer()->BindLabel(&after_return);
|
|
|
|
WriteJump(Bytecode::kJumpIfFalse, &after_throw);
|
|
|
|
Write(Bytecode::kThrow);
|
|
|
|
Write(Bytecode::kLdaSmi, 127); // Dead code.
|
|
|
|
writer()->BindLabel(&after_throw);
|
|
|
|
WriteJump(Bytecode::kJumpIfFalse, &after_rethrow);
|
|
|
|
Write(Bytecode::kReThrow);
|
|
|
|
Write(Bytecode::kLdaSmi, 127); // Dead code.
|
|
|
|
writer()->BindLabel(&after_rethrow);
|
|
|
|
Write(Bytecode::kReturn);
|
|
|
|
|
|
|
|
CHECK_EQ(bytecodes()->size(), arraysize(expected_bytes));
|
|
|
|
for (size_t i = 0; i < arraysize(expected_bytes); ++i) {
|
|
|
|
CHECK_EQ(static_cast<int>(bytecodes()->at(i)),
|
|
|
|
static_cast<int>(expected_bytes[i]));
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:23:48 +00:00
|
|
|
Handle<BytecodeArray> bytecode_array =
|
|
|
|
writer()->ToBytecodeArray(isolate(), 0, 0, factory()->empty_byte_array());
|
2020-10-05 09:22:13 +00:00
|
|
|
bytecode_array->set_source_position_table(
|
|
|
|
*writer()->ToSourcePositionTable(isolate()), kReleaseStore);
|
2017-06-27 08:44:35 +00:00
|
|
|
SourcePositionTableIterator source_iterator(
|
|
|
|
bytecode_array->SourcePositionTable());
|
|
|
|
for (size_t i = 0; i < arraysize(expected_positions); ++i) {
|
|
|
|
const PositionTableEntry& expected = expected_positions[i];
|
|
|
|
CHECK_EQ(source_iterator.code_offset(), expected.code_offset);
|
|
|
|
CHECK_EQ(source_iterator.source_position().ScriptOffset(),
|
|
|
|
expected.source_position);
|
|
|
|
CHECK_EQ(source_iterator.is_statement(), expected.is_statement);
|
|
|
|
source_iterator.Advance();
|
|
|
|
}
|
|
|
|
CHECK(source_iterator.done());
|
|
|
|
}
|
|
|
|
|
2017-11-09 09:05:52 +00:00
|
|
|
#undef B
|
2017-10-18 17:01:45 +00:00
|
|
|
#undef R
|
|
|
|
|
|
|
|
} // namespace bytecode_array_writer_unittest
|
2017-06-27 08:44:35 +00:00
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|