Index: test/unittests/wasm/ast-decoder-unittest.cc |
diff --git a/test/unittests/wasm/ast-decoder-unittest.cc b/test/unittests/wasm/ast-decoder-unittest.cc |
index 889cfb1b1a3ed1695f729675aafc22a5f5acd37f..05a0e95f6a73e5c87a644d1a1f2a5c88eebc497e 100644 |
--- a/test/unittests/wasm/ast-decoder-unittest.cc |
+++ b/test/unittests/wasm/ast-decoder-unittest.cc |
@@ -2437,6 +2437,60 @@ TEST_F(LocalDeclDecoderTest, UseEncoder) { |
pos = ExpectRun(map, pos, kAstI64, 212); |
} |
+class BytecodeIteratorTest : public TestWithZone {}; |
+ |
+TEST_F(BytecodeIteratorTest, SimpleForeach) { |
+ byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; |
+ BytecodeIterator iter(code, code + sizeof(code)); |
+ WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, |
+ kExprElse, kExprI8Const, kExprEnd}; |
+ size_t pos = 0; |
+ for (WasmOpcode opcode : iter) { |
+ if (pos >= arraysize(expected)) { |
+ EXPECT_TRUE(false); |
ahaas
2016/07/11 12:31:19
why don't you say
EXPECT_TRUE(pos < arraysize(exp
|
+ break; |
+ } |
+ EXPECT_EQ(expected[pos++], opcode); |
+ } |
+ EXPECT_EQ(arraysize(expected), pos); |
+} |
+ |
+TEST_F(BytecodeIteratorTest, ForeachTwice) { |
+ byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; |
+ BytecodeIterator iter(code, code + sizeof(code)); |
+ int count = 0; |
+ |
+ count = 0; |
+ for (WasmOpcode opcode : iter) { |
+ USE(opcode); |
+ count++; |
+ } |
+ EXPECT_EQ(6, count); |
+ |
+ count = 0; |
+ for (WasmOpcode opcode : iter) { |
+ USE(opcode); |
+ count++; |
+ } |
+ EXPECT_EQ(6, count); |
+} |
+ |
+TEST_F(BytecodeIteratorTest, WithAstDecls) { |
+ byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; |
+ AstLocalDecls decls(zone()); |
+ BytecodeIterator iter(code, code + sizeof(code), &decls); |
+ |
+ EXPECT_EQ(3, decls.decls_encoded_size); |
+ EXPECT_EQ(3, iter.pc_offset()); |
+ EXPECT_TRUE(iter.has_next()); |
+ EXPECT_EQ(kExprI8Const, iter.current()); |
+ iter.next(); |
+ EXPECT_TRUE(iter.has_next()); |
+ EXPECT_EQ(kExprI8Const, iter.current()); |
+ iter.next(); |
+ EXPECT_FALSE(iter.has_next()); |
+} |
+ |
} // namespace wasm |
} // namespace internal |
} // namespace v8 |