Index: test/unittests/wasm/module-decoder-unittest.cc |
diff --git a/test/unittests/wasm/module-decoder-unittest.cc b/test/unittests/wasm/module-decoder-unittest.cc |
index 28ec527fbe39701a16d97c3f608a321b6bfeeeb5..74157d57f7c096032bee5ad94ed3a4a346c4c23d 100644 |
--- a/test/unittests/wasm/module-decoder-unittest.cc |
+++ b/test/unittests/wasm/module-decoder-unittest.cc |
@@ -14,7 +14,16 @@ namespace v8 { |
namespace internal { |
namespace wasm { |
-#define EMPTY_FUNCTION(sig_index) 0, SIG_INDEX(sig_index), U16_LE(0) |
+#define WASM_INIT_EXPR_I32V_1(val) WASM_I32V_1(val), kExprEnd |
+#define WASM_INIT_EXPR_I32V_2(val) WASM_I32V_2(val), kExprEnd |
+#define WASM_INIT_EXPR_I32V_3(val) WASM_I32V_3(val), kExprEnd |
+#define WASM_INIT_EXPR_I32V_4(val) WASM_I32V_4(val), kExprEnd |
+#define WASM_INIT_EXPR_I32V_5(val) WASM_I32V_5(val), kExprEnd |
+#define WASM_INIT_EXPR_F32(val) WASM_F32(val), kExprEnd |
+#define WASM_INIT_EXPR_I64(val) WASM_I64(val), kExprEnd |
+#define WASM_INIT_EXPR_F64(val) WASM_F64(val), kExprEnd |
+#define WASM_INIT_EXPR_GLOBAL(index) WASM_GET_GLOBAL(index), kExprEnd |
+ |
#define SIZEOF_EMPTY_FUNCTION ((size_t)5) |
#define EMPTY_BODY 0 |
#define SIZEOF_EMPTY_BODY ((size_t)1) |
@@ -23,64 +32,64 @@ namespace wasm { |
#define SIG_ENTRY_i_i SIG_ENTRY_x_x(kLocalI32, kLocalI32) |
-#define UNKNOWN_EMPTY_SECTION_NAME 1, '\0' |
-#define UNKNOWN_SECTION_NAME 4, 'l', 'u', 'l', 'z' |
+#define UNKNOWN_SECTION(size) 0, U32V_1(size + 5), 4, 'l', 'u', 'l', 'z' |
-#define SECTION(NAME, EXTRA_SIZE) WASM_SECTION_##NAME, U32V_1(EXTRA_SIZE) |
+#define SECTION(name, size) k##name##SectionCode, U32V_1(size) |
#define SIGNATURES_SECTION(count, ...) \ |
- SECTION(SIGNATURES, 1 + 3 * (count)), U32V_1(count), __VA_ARGS__ |
+ SECTION(Type, 1 + 3 * (count)), U32V_1(count), __VA_ARGS__ |
#define FUNCTION_SIGNATURES_SECTION(count, ...) \ |
- SECTION(FUNCTION_SIGNATURES, 1 + (count)), U32V_1(count), __VA_ARGS__ |
+ SECTION(Function, 1 + (count)), U32V_1(count), __VA_ARGS__ |
#define FOO_STRING 3, 'f', 'o', 'o' |
#define NO_LOCAL_NAMES 0 |
-#define EMPTY_SIGNATURES_SECTION SECTION(SIGNATURES, 1), 0 |
-#define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(FUNCTION_SIGNATURES, 1), 0 |
-#define EMPTY_FUNCTION_BODIES_SECTION SECTION(FUNCTION_BODIES, 1), 0 |
-#define EMPTY_NAMES_SECTION SECTION(NAMES, 1), 0 |
+#define EMPTY_SIGNATURES_SECTION SECTION(Type, 1), 0 |
+#define EMPTY_FUNCTION_SIGNATURES_SECTION SECTION(Function, 1), 0 |
+#define EMPTY_FUNCTION_BODIES_SECTION SECTION(Code, 1), 0 |
+#define SECTION_NAMES(size) \ |
+ kUnknownSectionCode, U32V_1(size + 5), 4, 'n', 'a', 'm', 'e' |
+#define EMPTY_NAMES_SECTION SECTION_NAMES(1), 0 |
#define X1(...) __VA_ARGS__ |
#define X2(...) __VA_ARGS__, __VA_ARGS__ |
#define X3(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ |
#define X4(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ |
-#define ONE_EMPTY_FUNCTION WASM_SECTION_FUNCTION_SIGNATURES, 1 + 1 * 1, 1, X1(0) |
+#define ONE_EMPTY_FUNCTION SECTION(Function, 1 + 1 * 1), 1, X1(0) |
-#define TWO_EMPTY_FUNCTIONS \ |
- WASM_SECTION_FUNCTION_SIGNATURES, 1 + 2 * 1, 2, X2(0) |
+#define TWO_EMPTY_FUNCTIONS SECTION(Function, 1 + 2 * 1), 2, X2(0) |
-#define THREE_EMPTY_FUNCTIONS \ |
- WASM_SECTION_FUNCTION_SIGNATURES, 1 + 3 * 1, 3, X3(0) |
+#define THREE_EMPTY_FUNCTIONS SECTION(Function, 1 + 3 * 1), 3, X3(0) |
-#define FOUR_EMPTY_FUNCTIONS \ |
- WASM_SECTION_FUNCTION_SIGNATURES, 1 + 4 * 1, 4, X4(0) |
+#define FOUR_EMPTY_FUNCTIONS SECTION(Function, 1 + 4 * 1), 4, X4(0) |
-#define ONE_EMPTY_BODY \ |
- WASM_SECTION_FUNCTION_BODIES, 1 + 1 * (1 + SIZEOF_EMPTY_BODY), 1, \ |
- X1(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+#define ONE_EMPTY_BODY \ |
+ SECTION(Code, 1 + 1 * (1 + SIZEOF_EMPTY_BODY)) \ |
+ , 1, X1(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
-#define TWO_EMPTY_BODIES \ |
- WASM_SECTION_FUNCTION_BODIES, 1 + 2 * (1 + SIZEOF_EMPTY_BODY), 2, \ |
- X2(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+#define TWO_EMPTY_BODIES \ |
+ SECTION(Code, 1 + 2 * (1 + SIZEOF_EMPTY_BODY)) \ |
+ , 2, X2(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
-#define THREE_EMPTY_BODIES \ |
- WASM_SECTION_FUNCTION_BODIES, 1 + 3 * (1 + SIZEOF_EMPTY_BODY), 3, \ |
- X3(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+#define THREE_EMPTY_BODIES \ |
+ SECTION(Code, 1 + 3 * (1 + SIZEOF_EMPTY_BODY)) \ |
+ , 3, X3(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
-#define FOUR_EMPTY_BODIES \ |
- WASM_SECTION_FUNCTION_BODIES, 1 + 4 * (1 + SIZEOF_EMPTY_BODY), 4, \ |
- X4(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+#define FOUR_EMPTY_BODIES \ |
+ SECTION(Code, 1 + 4 * (1 + SIZEOF_EMPTY_BODY)) \ |
+ , 4, X4(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
#define SIGNATURES_SECTION_VOID_VOID \ |
- SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v |
+ SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v |
+ |
+#define LINEAR_MEMORY_INDEX_0 0 |
-#define EXPECT_VERIFIES(data) \ |
- do { \ |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); \ |
- EXPECT_TRUE(result.ok()); \ |
- if (result.val) delete result.val; \ |
+#define EXPECT_VERIFIES(data) \ |
+ do { \ |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); \ |
+ EXPECT_TRUE(result.ok()); \ |
+ if (result.val) delete result.val; \ |
} while (false) |
#define EXPECT_FAILURE_LEN(data, length) \ |
@@ -149,8 +158,7 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone { |
TEST_F(WasmModuleVerifyTest, WrongMagic) { |
for (uint32_t x = 1; x; x <<= 1) { |
- const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion), |
- SECTION(END, 0)}; |
+ const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; |
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); |
EXPECT_FALSE(result.ok()); |
if (result.val) delete result.val; |
@@ -159,8 +167,7 @@ TEST_F(WasmModuleVerifyTest, WrongMagic) { |
TEST_F(WasmModuleVerifyTest, WrongVersion) { |
for (uint32_t x = 1; x; x <<= 1) { |
- const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x), |
- SECTION(END, 0)}; |
+ const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)}; |
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); |
EXPECT_FALSE(result.ok()); |
if (result.val) delete result.val; |
@@ -168,23 +175,23 @@ TEST_F(WasmModuleVerifyTest, WrongVersion) { |
} |
TEST_F(WasmModuleVerifyTest, DecodeEmpty) { |
- static const byte data[] = {SECTION(END, 0)}; |
- EXPECT_VERIFIES(data); |
+ ModuleResult result = DecodeModule(nullptr, 0); |
+ EXPECT_TRUE(result.ok()); |
+ if (result.val) delete result.val; |
} |
TEST_F(WasmModuleVerifyTest, OneGlobal) { |
static const byte data[] = { |
- SECTION(GLOBALS, 5), // -- |
+ SECTION(Global, 6), // -- |
1, |
- NAME_LENGTH(1), |
- 'g', // name |
- kLocalI32, // local type |
- 0, // exported |
+ kLocalI32, // local type |
+ 0, // immutable |
+ WASM_INIT_EXPR_I32V_1(13) // init |
}; |
{ |
// Should decode to exactly one global. |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(1, result.val->globals.size()); |
EXPECT_EQ(0, result.val->functions.size()); |
@@ -192,10 +199,11 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) { |
const WasmGlobal* global = &result.val->globals.back(); |
- EXPECT_EQ(1, global->name_length); |
EXPECT_EQ(kAstI32, global->type); |
EXPECT_EQ(0, global->offset); |
- EXPECT_FALSE(global->exported); |
+ EXPECT_EQ(false, global->mutability); |
+ EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind); |
+ EXPECT_EQ(13, global->init.val.i32_const); |
if (result.val) delete result.val; |
} |
@@ -205,12 +213,11 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) { |
TEST_F(WasmModuleVerifyTest, Global_invalid_type) { |
static const byte data[] = { |
- SECTION(GLOBALS, 5), // -- |
+ SECTION(Global, 6), // -- |
1, |
- NAME_LENGTH(1), |
- 'g', // name |
- 64, // invalid memory type |
- 0, // exported |
+ 64, // invalid memory type |
+ 1, // mutable |
+ WASM_INIT_EXPR_I32V_1(33), // init |
}; |
ModuleResult result = DecodeModule(data, data + sizeof(data)); |
@@ -220,12 +227,11 @@ TEST_F(WasmModuleVerifyTest, Global_invalid_type) { |
TEST_F(WasmModuleVerifyTest, Global_invalid_type2) { |
static const byte data[] = { |
- SECTION(GLOBALS, 5), // -- |
+ SECTION(Global, 6), // -- |
1, |
- NAME_LENGTH(1), |
- 'g', // name |
- kLocalVoid, // invalid memory type |
- 0, // exported |
+ kLocalVoid, // invalid memory type |
+ 1, // mutable |
+ WASM_INIT_EXPR_I32V_1(33), // init |
}; |
ModuleResult result = DecodeModule(data, data + sizeof(data)); |
@@ -235,10 +241,10 @@ TEST_F(WasmModuleVerifyTest, Global_invalid_type2) { |
TEST_F(WasmModuleVerifyTest, ZeroGlobals) { |
static const byte data[] = { |
- SECTION(GLOBALS, 1), // -- |
- 0, // declare 0 globals |
+ SECTION(Global, 1), // -- |
+ 0, // declare 0 globals |
}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
if (result.val) delete result.val; |
} |
@@ -259,15 +265,15 @@ static void AppendUint32v(std::vector<byte>& buffer, uint32_t val) { |
TEST_F(WasmModuleVerifyTest, NGlobals) { |
static const byte data[] = { |
- NO_NAME, // name length |
- kLocalF32, // memory type |
- 0, // exported |
+ kLocalF32, // memory type |
+ 0, // immutable |
+ WASM_INIT_EXPR_F32(7.7), // init |
}; |
for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) { |
std::vector<byte> buffer; |
size_t size = SizeOfVarInt(i) + i * sizeof(data); |
- const byte globals[] = {WASM_SECTION_GLOBALS, U32V_5(size)}; |
+ const byte globals[] = {kGlobalSectionCode, U32V_5(size)}; |
for (size_t g = 0; g != sizeof(globals); ++g) { |
buffer.push_back(globals[g]); |
} |
@@ -282,74 +288,48 @@ TEST_F(WasmModuleVerifyTest, NGlobals) { |
} |
} |
-TEST_F(WasmModuleVerifyTest, GlobalWithInvalidNameOffset) { |
- static const byte data[] = { |
- SECTION(GLOBALS, 7), |
- 1, // declare one global |
- NO_NAME, // name offset |
- 33, // memory type |
- 0, // exported |
- }; |
- |
- EXPECT_FAILURE(data); |
-} |
- |
-TEST_F(WasmModuleVerifyTest, GlobalWithInvalidNameLength) { |
- static const byte data[] = { |
- SECTION(GLOBALS, 5), // -- |
- 1, |
- NAME_LENGTH(56), // invalid length |
- 'g', // name |
- kLocalI32, // memory type |
- 0, // exported |
- }; |
- EXPECT_FAILURE(data); |
-} |
- |
TEST_F(WasmModuleVerifyTest, GlobalWithInvalidMemoryType) { |
- static const byte data[] = { |
- SECTION(GLOBALS, 7), |
- 1, // declare one global |
- NO_NAME, // name offset |
- 33, // memory type |
- 0, // exported |
- }; |
+ static const byte data[] = {SECTION(Global, 7), |
+ 33, // memory type |
+ 0, // exported |
+ WASM_INIT_EXPR_I32V_1(1)}; |
EXPECT_FAILURE(data); |
} |
TEST_F(WasmModuleVerifyTest, TwoGlobals) { |
static const byte data[] = { |
- SECTION(GLOBALS, 7), |
+ SECTION(Global, 21), |
2, |
- NO_NAME, // #0: name length |
kLocalF32, // type |
- 0, // exported |
- NO_NAME, // #1: name length |
+ 0, // immutable |
+ WASM_INIT_EXPR_F32(22.0), |
kLocalF64, // type |
- 1, // exported |
+ 1, // mutable |
+ WASM_INIT_EXPR_F64(23.0), |
}; |
{ |
// Should decode to exactly two globals. |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(2, result.val->globals.size()); |
EXPECT_EQ(0, result.val->functions.size()); |
EXPECT_EQ(0, result.val->data_segments.size()); |
const WasmGlobal* g0 = &result.val->globals[0]; |
- const WasmGlobal* g1 = &result.val->globals[1]; |
- EXPECT_EQ(0, g0->name_length); |
EXPECT_EQ(kAstF32, g0->type); |
EXPECT_EQ(0, g0->offset); |
- EXPECT_FALSE(g0->exported); |
+ EXPECT_EQ(false, g0->mutability); |
+ EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind); |
+ |
+ const WasmGlobal* g1 = &result.val->globals[1]; |
- EXPECT_EQ(0, g1->name_length); |
EXPECT_EQ(kAstF64, g1->type); |
EXPECT_EQ(8, g1->offset); |
- EXPECT_TRUE(g1->exported); |
+ EXPECT_EQ(true, g1->mutability); |
+ EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind); |
if (result.val) delete result.val; |
} |
@@ -364,23 +344,23 @@ TEST_F(WasmModuleVerifyTest, OneSignature) { |
} |
{ |
- static const byte data[] = {SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_x_x), |
- 1, SIG_ENTRY_i_i}; |
+ static const byte data[] = {SECTION(Type, 1 + SIZEOF_SIG_ENTRY_x_x), 1, |
+ SIG_ENTRY_i_i}; |
EXPECT_VERIFIES(data); |
} |
} |
TEST_F(WasmModuleVerifyTest, MultipleSignatures) { |
static const byte data[] = { |
- SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x + |
- SIZEOF_SIG_ENTRY_x_xx), // -- |
+ SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x + |
+ SIZEOF_SIG_ENTRY_x_xx), // -- |
3, // -- |
SIG_ENTRY_v_v, // void -> void |
SIG_ENTRY_x_x(kLocalI32, kLocalF32), // f32 -> i32 |
SIG_ENTRY_x_xx(kLocalI32, kLocalF64, kLocalF64), // f64,f64 -> i32 |
}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(3, result.val->signatures.size()); |
if (result.val->signatures.size() == 3) { |
@@ -398,16 +378,18 @@ TEST_F(WasmModuleVerifyTest, MultipleSignatures) { |
} |
TEST_F(WasmModuleVerifyTest, OneDataSegment) { |
- const byte kDataSegmentSourceOffset = 30; |
+ const byte kDataSegmentSourceOffset = 24; |
const byte data[] = { |
- SECTION(MEMORY, 3), |
+ SECTION(Memory, 4), |
+ ENTRY_COUNT(1), |
+ kResizableMaximumFlag, |
28, |
28, |
- 1, |
- SECTION(DATA_SEGMENTS, 8), |
- 1, |
- U32V_3(0x9bbaa), // dest addr |
- U32V_1(3), // source size |
+ SECTION(Data, 11), |
+ ENTRY_COUNT(1), |
+ LINEAR_MEMORY_INDEX_0, |
+ WASM_INIT_EXPR_I32V_3(0x9bbaa), // dest addr |
+ U32V_1(3), // source size |
'a', |
'b', |
'c' // data bytes |
@@ -415,7 +397,7 @@ TEST_F(WasmModuleVerifyTest, OneDataSegment) { |
{ |
EXPECT_VERIFIES(data); |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(0, result.val->globals.size()); |
EXPECT_EQ(0, result.val->functions.size()); |
@@ -423,36 +405,39 @@ TEST_F(WasmModuleVerifyTest, OneDataSegment) { |
const WasmDataSegment* segment = &result.val->data_segments.back(); |
- EXPECT_EQ(0x9bbaa, segment->dest_addr); |
+ EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind); |
+ EXPECT_EQ(0x9bbaa, segment->dest_addr.val.i32_const); |
EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); |
EXPECT_EQ(3, segment->source_size); |
- EXPECT_TRUE(segment->init); |
if (result.val) delete result.val; |
} |
- EXPECT_OFF_END_FAILURE(data, 13, sizeof(data)); |
+ EXPECT_OFF_END_FAILURE(data, 14, sizeof(data)); |
} |
TEST_F(WasmModuleVerifyTest, TwoDataSegments) { |
- const byte kDataSegment0SourceOffset = 30; |
- const byte kDataSegment1SourceOffset = 30 + 8; |
+ const byte kDataSegment0SourceOffset = 24; |
+ const byte kDataSegment1SourceOffset = kDataSegment0SourceOffset + 11; |
const byte data[] = { |
- SECTION(MEMORY, 3), |
+ SECTION(Memory, 4), |
+ ENTRY_COUNT(1), |
+ kResizableMaximumFlag, |
28, |
28, |
- 1, |
- SECTION(DATA_SEGMENTS, 23), |
- 2, // segment count |
- U32V_3(0x7ffee), // #0: dest addr |
- U32V_1(4), // source size |
+ SECTION(Data, 29), |
+ ENTRY_COUNT(2), // segment count |
+ LINEAR_MEMORY_INDEX_0, |
+ WASM_INIT_EXPR_I32V_3(0x7ffee), // #0: dest addr |
+ U32V_1(4), // source size |
1, |
2, |
3, |
- 4, // data bytes |
- U32V_3(0x6ddcc), // #1: dest addr |
- U32V_1(10), // source size |
+ 4, // data bytes |
+ LINEAR_MEMORY_INDEX_0, |
+ WASM_INIT_EXPR_I32V_3(0x6ddcc), // #1: dest addr |
+ U32V_1(10), // source size |
1, |
2, |
3, |
@@ -466,7 +451,7 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) { |
}; |
{ |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(0, result.val->globals.size()); |
EXPECT_EQ(0, result.val->functions.size()); |
@@ -475,61 +460,79 @@ TEST_F(WasmModuleVerifyTest, TwoDataSegments) { |
const WasmDataSegment* s0 = &result.val->data_segments[0]; |
const WasmDataSegment* s1 = &result.val->data_segments[1]; |
- EXPECT_EQ(0x7ffee, s0->dest_addr); |
+ EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind); |
+ EXPECT_EQ(0x7ffee, s0->dest_addr.val.i32_const); |
EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset); |
EXPECT_EQ(4, s0->source_size); |
- EXPECT_TRUE(s0->init); |
- EXPECT_EQ(0x6ddcc, s1->dest_addr); |
+ EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind); |
+ EXPECT_EQ(0x6ddcc, s1->dest_addr.val.i32_const); |
EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset); |
EXPECT_EQ(10, s1->source_size); |
- EXPECT_TRUE(s1->init); |
if (result.val) delete result.val; |
} |
- EXPECT_OFF_END_FAILURE(data, 13, sizeof(data)); |
-} |
- |
-TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) { |
- const int source_size = 3; |
- |
- for (byte mem_pages = 1; mem_pages < 16; mem_pages++) { |
- int mem_size = mem_pages * 0x10000; // 64k pages. |
- |
- for (int dest_addr = mem_size - source_size; |
- dest_addr < mem_size + source_size; dest_addr++) { |
- byte data[] = {SECTION(MEMORY, 3), |
- mem_pages, |
- mem_pages, |
- 1, |
- SECTION(DATA_SEGMENTS, 8), |
- 1, |
- U32V_3(dest_addr), |
- U32V_1(source_size), |
- 'a', |
- 'b', |
- 'c'}; |
- |
- if (dest_addr <= (mem_size - source_size)) { |
- EXPECT_VERIFIES(data); |
- } else { |
- EXPECT_FAILURE(data); |
- } |
- } |
- } |
+ EXPECT_OFF_END_FAILURE(data, 14, sizeof(data)); |
+} |
+ |
+TEST_F(WasmModuleVerifyTest, DataSegment_wrong_init_type) { |
+ const byte data[] = { |
+ SECTION(Memory, 4), |
+ ENTRY_COUNT(1), |
+ kResizableMaximumFlag, |
+ 28, |
+ 28, |
+ SECTION(Data, 11), |
+ ENTRY_COUNT(1), |
+ LINEAR_MEMORY_INDEX_0, |
+ WASM_INIT_EXPR_F64(9.9), // dest addr |
+ U32V_1(3), // source size |
+ 'a', |
+ 'b', |
+ 'c' // data bytes |
+ }; |
+ |
+ EXPECT_FAILURE(data); |
} |
TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { |
static const byte data[] = { |
- // sig#0 ------------------------------------------------------- |
+ // sig#0 --------------------------------------------------------------- |
SIGNATURES_SECTION_VOID_VOID, |
- // funcs ------------------------------------------------------ |
+ // funcs --------------------------------------------------------------- |
ONE_EMPTY_FUNCTION, |
- // indirect table ---------------------------------------------- |
- SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)}; |
+ // table declaration --------------------------------------------------- |
+ SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
+ EXPECT_OK(result); |
+ if (result.ok()) { |
+ EXPECT_EQ(1, result.val->signatures.size()); |
+ EXPECT_EQ(1, result.val->functions.size()); |
+ EXPECT_EQ(1, result.val->function_tables.size()); |
+ EXPECT_EQ(1, result.val->function_tables[0].values.size()); |
+ EXPECT_EQ(-1, result.val->function_tables[0].values[0]); |
+ } |
+ if (result.val) delete result.val; |
+} |
+ |
+TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) { |
+ static const byte data[] = { |
+ // sig#0 --------------------------------------------------------------- |
+ SIGNATURES_SECTION_VOID_VOID, |
+ // funcs --------------------------------------------------------------- |
+ ONE_EMPTY_FUNCTION, |
+ // table declaration --------------------------------------------------- |
+ SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1, |
+ // elements ------------------------------------------------------------ |
+ SECTION(Element, 7), |
+ 1, // entry count |
+ TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0), |
+ 1, // elements count |
+ FUNC_INDEX(0)}; |
+ |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
if (result.ok()) { |
EXPECT_EQ(1, result.val->signatures.size()); |
@@ -544,25 +547,30 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { |
TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
static const byte data[] = { |
// sig#0 ------------------------------------------------------- |
- SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), |
+ SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), |
2, // -- |
SIG_ENTRY_v_v, // void -> void |
SIG_ENTRY_v_x(kLocalI32), // void -> i32 |
// funcs ------------------------------------------------------ |
FOUR_EMPTY_FUNCTIONS, |
- // indirect table ---------------------------------------------- |
- SECTION(FUNCTION_TABLE, 9), 8, |
- U32V_1(0), // -- |
- U32V_1(1), // -- |
- U32V_1(2), // -- |
- U32V_1(3), // -- |
- U32V_1(0), // -- |
- U32V_1(1), // -- |
- U32V_1(2), // -- |
- U32V_1(3), // -- |
+ // table declaration ------------------------------------------- |
+ SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 8, |
+ // table elements ---------------------------------------------- |
+ SECTION(Element, 14), |
+ 1, // entry count |
+ TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0), |
+ 8, // elements count |
+ FUNC_INDEX(0), // -- |
+ FUNC_INDEX(1), // -- |
+ FUNC_INDEX(2), // -- |
+ FUNC_INDEX(3), // -- |
+ FUNC_INDEX(0), // -- |
+ FUNC_INDEX(1), // -- |
+ FUNC_INDEX(2), // -- |
+ FUNC_INDEX(3), // -- |
FOUR_EMPTY_BODIES}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
if (result.ok()) { |
EXPECT_EQ(2, result.val->signatures.size()); |
@@ -581,7 +589,7 @@ TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) { |
// sig#0 ------------------------------------------------------- |
SIGNATURES_SECTION_VOID_VOID, |
// indirect table ---------------------------------------------- |
- SECTION(FUNCTION_TABLE, 3), 1, 0, 0, |
+ SECTION(Table, 4), ENTRY_COUNT(1), 1, 0, 0, |
}; |
EXPECT_FAILURE(data); |
@@ -594,7 +602,7 @@ TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) { |
// functions --------------------------------------------------- |
ONE_EMPTY_FUNCTION, |
// indirect table ---------------------------------------------- |
- SECTION(FUNCTION_TABLE, 3), 1, 1, 0, |
+ SECTION(Table, 4), ENTRY_COUNT(1), 1, 1, 0, |
}; |
EXPECT_FAILURE(data); |
@@ -607,7 +615,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) { |
v8::internal::AccountingAllocator allocator; |
Zone zone(&allocator); |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(&zone, data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(&zone, data, data + sizeof(data)); |
EXPECT_TRUE(sig != nullptr); |
EXPECT_EQ(0, sig->parameter_count()); |
@@ -619,7 +627,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) { |
LocalTypePair ret_type = kLocalTypes[i]; |
const byte data[] = {SIG_ENTRY_x(ret_type.code)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_TRUE(sig != nullptr); |
EXPECT_EQ(0, sig->parameter_count()); |
@@ -633,7 +641,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) { |
LocalTypePair param_type = kLocalTypes[i]; |
const byte data[] = {SIG_ENTRY_v_x(param_type.code)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_TRUE(sig != nullptr); |
EXPECT_EQ(1, sig->parameter_count()); |
@@ -649,7 +657,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) { |
LocalTypePair param_type = kLocalTypes[j]; |
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_TRUE(sig != nullptr); |
EXPECT_EQ(1, sig->parameter_count()); |
@@ -668,7 +676,7 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) { |
const byte data[] = { |
SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_TRUE(sig != nullptr); |
EXPECT_EQ(2, sig->parameter_count()); |
@@ -699,7 +707,7 @@ TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) { |
byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalI32)}; |
data[i] = kInvalidType; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_EQ(nullptr, sig); |
} |
} |
@@ -707,21 +715,21 @@ TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) { |
TEST_F(WasmSignatureDecodeTest, Fail_invalid_ret_type1) { |
static const byte data[] = {SIG_ENTRY_x_x(kLocalVoid, kLocalI32)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_EQ(nullptr, sig); |
} |
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type1) { |
static const byte data[] = {SIG_ENTRY_x_x(kLocalI32, kLocalVoid)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_EQ(nullptr, sig); |
} |
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) { |
static const byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalVoid)}; |
FunctionSig* sig = |
- DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
+ DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
EXPECT_EQ(nullptr, sig); |
} |
@@ -742,8 +750,8 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { |
kExprNop // body |
}; |
- FunctionResult result = DecodeWasmFunction(isolate(), zone(), nullptr, data, |
- data + arraysize(data)); |
+ FunctionResult result = |
+ DecodeWasmFunction(isolate(), zone(), nullptr, data, data + sizeof(data)); |
EXPECT_OK(result); |
if (result.val && result.ok()) { |
@@ -752,7 +760,7 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { |
EXPECT_EQ(0, function->sig->return_count()); |
EXPECT_EQ(0, function->name_offset); |
EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); |
- EXPECT_EQ(arraysize(data), function->code_end_offset); |
+ EXPECT_EQ(sizeof(data), function->code_end_offset); |
// TODO(titzer): verify encoding of local declarations |
} |
@@ -766,6 +774,7 @@ TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) { |
TEST_F(WasmModuleVerifyTest, TheLoneliestOfValidModulesTheTrulyEmptyOne) { |
const byte data[] = { |
+ 0, // unknown section code. |
0, // Empty section name. |
// No section name, no content, nothing but sadness. |
0, // No section content. |
@@ -775,15 +784,14 @@ TEST_F(WasmModuleVerifyTest, TheLoneliestOfValidModulesTheTrulyEmptyOne) { |
TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionEmpty) { |
const byte data[] = { |
- UNKNOWN_SECTION_NAME, 0, |
+ UNKNOWN_SECTION(0), |
}; |
EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionNonEmpty) { |
const byte data[] = { |
- UNKNOWN_SECTION_NAME, |
- 5, // section size |
+ UNKNOWN_SECTION(5), |
0xff, |
0xff, |
0xff, |
@@ -798,9 +806,7 @@ TEST_F(WasmModuleVerifyTest, SignatureFollowedByEmptyUnknownSection) { |
// signatures |
SIGNATURES_SECTION_VOID_VOID, |
// ----------------------------------------------------------- |
- UNKNOWN_SECTION_NAME, |
- 0 // empty section |
- }; |
+ UNKNOWN_SECTION(0)}; |
EXPECT_VERIFIES(data); |
} |
@@ -809,29 +815,14 @@ TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSection) { |
// signatures |
SIGNATURES_SECTION_VOID_VOID, |
// ----------------------------------------------------------- |
- UNKNOWN_SECTION_NAME, |
- 5, // section size |
- 0xff, 0xff, 0xff, 0xff, 0xff, |
- }; |
- EXPECT_VERIFIES(data); |
-} |
- |
-TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSectionWithLongLEB) { |
- const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- // ----------------------------------------------------------- |
- UNKNOWN_SECTION_NAME, 0x81, 0x80, 0x80, 0x80, |
- 0x00, // section size: 1 but in a 5-byte LEB |
- 0, |
+ UNKNOWN_SECTION(5), 0xff, 0xff, 0xff, 0xff, 0xff, |
}; |
EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) { |
static const byte data[] = { |
- UNKNOWN_EMPTY_SECTION_NAME, |
- 9, // section size |
+ UNKNOWN_SECTION(9), |
1, |
2, |
3, |
@@ -848,49 +839,26 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) { |
TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) { |
static const byte data[] = { |
- UNKNOWN_EMPTY_SECTION_NAME, |
- 0xff, |
- 0xff, |
- 0xff, |
- 0xff, |
- 0x0f, // Section size LEB128 0xffffffff |
- 1, |
- 2, |
- 3, |
- 4, // 4 byte section |
- }; |
- EXPECT_FAILURE(data); |
-} |
- |
-TEST_F(WasmModuleVerifyTest, UnknownSectionLoop) { |
- // Would infinite loop decoding if wrapping and allowed. |
- static const byte data[] = { |
- UNKNOWN_EMPTY_SECTION_NAME, |
+ UNKNOWN_SECTION(333), |
1, |
2, |
3, |
4, // 4 byte section |
- 0xfa, |
- 0xff, |
- 0xff, |
- 0xff, |
- 0x0f, // Section size LEB128 0xfffffffa |
}; |
EXPECT_FAILURE(data); |
} |
TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) { |
static const byte data[] = { |
- UNKNOWN_EMPTY_SECTION_NAME, |
- 1, // section size |
+ UNKNOWN_SECTION(1), |
0, // one byte section |
- SECTION(GLOBALS, 4), |
+ SECTION(Global, 6), |
1, |
- 0, // name length |
- kLocalI32, // memory type |
- 0, // exported |
+ kLocalI32, // memory type |
+ 0, // exported |
+ WASM_INIT_EXPR_I32V_1(33), // init |
}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(1, result.val->globals.size()); |
@@ -899,42 +867,41 @@ TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) { |
const WasmGlobal* global = &result.val->globals.back(); |
- EXPECT_EQ(0, global->name_length); |
EXPECT_EQ(kAstI32, global->type); |
EXPECT_EQ(0, global->offset); |
- EXPECT_FALSE(global->exported); |
if (result.val) delete result.val; |
} |
TEST_F(WasmModuleVerifyTest, ImportTable_empty) { |
- static const byte data[] = {SECTION(SIGNATURES, 1), 0, |
- SECTION(IMPORT_TABLE, 1), 0}; |
+ static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 1), 0}; |
EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) { |
- static const byte data[] = {SECTION(IMPORT_TABLE, 1), 0}; |
+ static const byte data[] = {SECTION(Import, 1), 0}; |
EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs2) { |
static const byte data[] = { |
- SECTION(IMPORT_TABLE, 6), 1, // sig table |
- IMPORT_SIG_INDEX(0), // sig index |
- NAME_LENGTH(1), 'm', // module name |
- NAME_LENGTH(1), 'f', // function name |
+ SECTION(Import, 6), 1, // sig table |
+ NAME_LENGTH(1), 'm', // module name |
+ NAME_LENGTH(1), 'f', // function name |
+ kExternalFunction, // import kind |
+ IMPORT_SIG_INDEX(0), // sig index |
}; |
EXPECT_FAILURE(data); |
} |
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_sig) { |
static const byte data[] = { |
- SECTION(SIGNATURES, 1), 0, // -- |
- SECTION(IMPORT_TABLE, 6), 1, // -- |
- IMPORT_SIG_INDEX(0), // sig index |
- NAME_LENGTH(1), 'm', // module name |
- NAME_LENGTH(1), 'f', // function name |
+ SECTION(Type, 1), 0, // -- |
+ SECTION(Import, 6), 1, // -- |
+ NAME_LENGTH(1), 'm', // module name |
+ NAME_LENGTH(1), 'f', // function name |
+ kExternalFunction, // import kind |
+ IMPORT_SIG_INDEX(0), // sig index |
}; |
EXPECT_FAILURE(data); |
} |
@@ -943,13 +910,14 @@ TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) { |
static const byte data[] = { |
// signatures |
SIGNATURES_SECTION_VOID_VOID, |
- SECTION(IMPORT_TABLE, 6), |
- 1, // -- |
- IMPORT_SIG_INDEX(0), // sig index |
+ SECTION(Import, 7), |
+ 1, // -- |
NAME_LENGTH(1), |
'm', // module name |
NAME_LENGTH(1), |
- 'f', // function name |
+ 'f', // function name |
+ kExternalFunction, // import kind |
+ IMPORT_SIG_INDEX(0), // sig index |
}; |
EXPECT_VERIFIES(data); |
} |
@@ -957,13 +925,14 @@ TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) { |
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) { |
static const byte data[] = { |
// signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- SECTION(IMPORT_TABLE, 6), |
- 1, // -- |
- IMPORT_SIG_INDEX(0), // sig index |
- NO_NAME, // module name |
- NAME_LENGTH(1), |
- 'f' // function name |
+ SIGNATURES_SECTION_VOID_VOID, // -- |
+ SECTION(Import, 7), // -- |
+ 1, // -- |
+ NO_NAME, // module name |
+ NAME_LENGTH(1), // -- |
+ 'f', // function name |
+ kExternalFunction, // import kind |
+ IMPORT_SIG_INDEX(0), // sig index |
}; |
EXPECT_FAILURE(data); |
} |
@@ -972,26 +941,27 @@ TEST_F(WasmModuleVerifyTest, ImportTable_off_end) { |
static const byte data[] = { |
// signatures |
SIGNATURES_SECTION_VOID_VOID, |
- SECTION(IMPORT_TABLE, 6), |
+ SECTION(Import, 6), |
1, |
- IMPORT_SIG_INDEX(0), // sig index |
NAME_LENGTH(1), |
'm', // module name |
NAME_LENGTH(1), |
- 'f', // function name |
+ 'f', // function name |
+ kExternalFunction, // import kind |
+ IMPORT_SIG_INDEX(0), // sig index |
}; |
EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); |
} |
TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { |
- static const byte data[] = {// signatures |
- SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION, |
- SECTION(EXPORT_TABLE, 1), |
- 0, // -- |
+ static const byte data[] = { // signatures |
+ SIGNATURES_SECTION_VOID_VOID, // -- |
+ ONE_EMPTY_FUNCTION, SECTION(Export, 1), // -- |
+ 0, // -- |
ONE_EMPTY_BODY}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(1, result.val->functions.size()); |
@@ -1002,34 +972,27 @@ TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { |
TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { |
static const byte data[] = { |
- SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // -- |
+ SECTION(Type, 1), 0, SECTION(Export, 1), 0 // -- |
}; |
- // TODO(titzer): current behavior treats empty functions section as missing. |
- EXPECT_FAILURE(data); |
-} |
- |
-TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions1) { |
- static const byte data[] = { |
- SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // -- |
- }; |
- EXPECT_FAILURE(data); |
+ EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { |
- static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0}; |
- EXPECT_FAILURE(data); |
+ static const byte data[] = {SECTION(Export, 1), 0}; |
+ EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, ExportTableOne) { |
static const byte data[] = {// signatures |
SIGNATURES_SECTION_VOID_VOID, |
ONE_EMPTY_FUNCTION, |
- SECTION(EXPORT_TABLE, 3), |
- 1, // exports |
- FUNC_INDEX(0), // -- |
- NO_NAME, // -- |
+ SECTION(Export, 4), |
+ 1, // exports |
+ NO_NAME, // -- |
+ kExternalFunction, // -- |
+ FUNC_INDEX(0), // -- |
ONE_EMPTY_BODY}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(1, result.val->functions.size()); |
@@ -1042,12 +1005,12 @@ TEST_F(WasmModuleVerifyTest, ExportNameWithInvalidStringLength) { |
static const byte data[] = {// signatures |
SIGNATURES_SECTION_VOID_VOID, |
ONE_EMPTY_FUNCTION, |
- SECTION(EXPORT_TABLE, 12), |
- 1, // exports |
- FUNC_INDEX(0), // -- |
- NAME_LENGTH(84), // invalid string length |
- 'e', // -- |
- ONE_EMPTY_BODY}; |
+ SECTION(Export, 12), |
+ 1, // exports |
+ NAME_LENGTH(84), // invalid string length |
+ 'e', // -- |
+ kExternalFunction, // -- |
+ FUNC_INDEX(0)}; |
EXPECT_FAILURE(data); |
} |
@@ -1056,22 +1019,24 @@ TEST_F(WasmModuleVerifyTest, ExportTableTwo) { |
static const byte data[] = {// signatures |
SIGNATURES_SECTION_VOID_VOID, |
ONE_EMPTY_FUNCTION, |
- SECTION(EXPORT_TABLE, 12), |
- 2, // exports |
- FUNC_INDEX(0), // -- |
+ SECTION(Export, 14), |
+ 2, // exports |
NAME_LENGTH(4), |
'n', |
'a', |
'm', |
- 'e', // -- |
+ 'e', // -- |
+ kExternalFunction, |
FUNC_INDEX(0), // -- |
NAME_LENGTH(3), |
'n', |
'o', |
- 'm', // -- |
+ 'm', // -- |
+ kExternalFunction, // -- |
+ FUNC_INDEX(0), // -- |
ONE_EMPTY_BODY}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(1, result.val->functions.size()); |
@@ -1084,19 +1049,22 @@ TEST_F(WasmModuleVerifyTest, ExportTableThree) { |
static const byte data[] = {// signatures |
SIGNATURES_SECTION_VOID_VOID, |
THREE_EMPTY_FUNCTIONS, |
- SECTION(EXPORT_TABLE, 10), |
- 3, // exports |
+ SECTION(Export, 13), |
+ 3, // exports |
+ NAME_LENGTH(1), |
+ 'a', // -- |
+ kExternalFunction, |
FUNC_INDEX(0), // -- |
NAME_LENGTH(1), |
- 'a', // -- |
+ 'b', // -- |
+ kExternalFunction, |
FUNC_INDEX(1), // -- |
NAME_LENGTH(1), |
- 'b', // -- |
- FUNC_INDEX(2), // -- |
- NAME_LENGTH(1), |
'c', // -- |
+ kExternalFunction, |
+ FUNC_INDEX(2), // -- |
THREE_EMPTY_BODIES}; |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ ModuleResult result = DecodeModule(data, data + sizeof(data)); |
EXPECT_OK(result); |
EXPECT_EQ(3, result.val->functions.size()); |
@@ -1110,12 +1078,13 @@ TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { |
const byte data[] = {// signatures |
SIGNATURES_SECTION_VOID_VOID, |
THREE_EMPTY_FUNCTIONS, |
- SECTION(EXPORT_TABLE, 5), |
- 1, // exports |
- FUNC_INDEX(i), // -- |
+ SECTION(Export, 6), |
+ 1, // exports |
NAME_LENGTH(2), |
'e', |
'x', // -- |
+ kExternalFunction, |
+ FUNC_INDEX(i), // -- |
THREE_EMPTY_BODIES}; |
if (i < 3) { |
@@ -1131,10 +1100,11 @@ TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { |
// signatures |
SIGNATURES_SECTION_VOID_VOID, |
ONE_EMPTY_FUNCTION, |
- SECTION(EXPORT_TABLE, 1 + 6), |
- 1, // exports |
+ SECTION(Export, 1 + 6), |
+ 1, // exports |
+ NO_NAME, // -- |
+ kExternalFunction, |
FUNC_INDEX(0), // -- |
- NO_NAME // -- |
}; |
for (int length = 33; length < sizeof(data); length++) { |
@@ -1146,9 +1116,9 @@ TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { |
TEST_F(WasmModuleVerifyTest, FunctionSignatures_empty) { |
static const byte data[] = { |
- SECTION(SIGNATURES, 1), 0, // -- |
- SECTION(FUNCTION_SIGNATURES, 1), 0 // -- |
- }; // -- |
+ SECTION(Type, 1), 0, // -- |
+ SECTION(Function, 1), 0 // -- |
+ }; // -- |
EXPECT_VERIFIES(data); |
} |
@@ -1162,10 +1132,10 @@ TEST_F(WasmModuleVerifyTest, FunctionSignatures_one) { |
TEST_F(WasmModuleVerifyTest, Regression_648070) { |
static const byte data[] = { |
- SECTION(SIGNATURES, 1), 0, // -- |
- SECTION(FUNCTION_SIGNATURES, 5), // -- |
- U32V_5(3500228624) // function count = 3500228624 |
- }; // -- |
+ SECTION(Type, 1), 0, // -- |
+ SECTION(Function, 5), // -- |
+ U32V_5(3500228624) // function count = 3500228624 |
+ }; // -- |
EXPECT_FAILURE(data); |
} |
@@ -1180,40 +1150,40 @@ TEST_F(WasmModuleVerifyTest, FunctionBodies_empty) { |
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_empty) { |
static const byte data[] = { |
- SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
- FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
- SECTION(FUNCTION_BODIES, 1 + SIZEOF_EMPTY_BODY), 1, EMPTY_BODY // -- |
+ SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
+ FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
+ SECTION(Code, 1 + SIZEOF_EMPTY_BODY), 1, EMPTY_BODY // -- |
}; |
EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_nop) { |
static const byte data[] = { |
- SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
- FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
- SECTION(FUNCTION_BODIES, 1 + SIZEOF_NOP_BODY), 1, NOP_BODY // -- |
+ SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
+ FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
+ SECTION(Code, 1 + SIZEOF_NOP_BODY), 1, NOP_BODY // -- |
}; |
EXPECT_VERIFIES(data); |
} |
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch1) { |
static const byte data[] = { |
- SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
- FUNCTION_SIGNATURES_SECTION(2, 0, 0), // -- |
- SECTION(FUNCTION_BODIES, 1 + SIZEOF_EMPTY_BODY), 1, // -- |
- EMPTY_BODY // -- |
+ SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
+ FUNCTION_SIGNATURES_SECTION(2, 0, 0), // -- |
+ SECTION(Code, 1 + SIZEOF_EMPTY_BODY), 1, // -- |
+ EMPTY_BODY // -- |
}; |
EXPECT_FAILURE(data); |
} |
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch2) { |
static const byte data[] = { |
- SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
- FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
- SECTION(FUNCTION_BODIES, 1 + 2 * SIZEOF_NOP_BODY), // -- |
- 2, // -- |
- NOP_BODY, // -- |
- NOP_BODY // -- |
+ SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
+ FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
+ SECTION(Code, 1 + 2 * SIZEOF_NOP_BODY), // -- |
+ ENTRY_COUNT(2), // -- |
+ NOP_BODY, // -- |
+ NOP_BODY // -- |
}; |
EXPECT_FAILURE(data); |
} |
@@ -1229,11 +1199,11 @@ TEST_F(WasmModuleVerifyTest, Names_one_empty) { |
static const byte data[] = { |
SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
FUNCTION_SIGNATURES_SECTION(1, 0), // -- |
- SECTION(FUNCTION_BODIES, 1 + SIZEOF_EMPTY_BODY), |
- 1, |
+ SECTION(Code, 1 + SIZEOF_EMPTY_BODY), |
+ ENTRY_COUNT(1), |
EMPTY_BODY, // -- |
- SECTION(NAMES, 1 + 5), |
- 1, |
+ SECTION_NAMES(1 + 5), |
+ ENTRY_COUNT(1), |
FOO_STRING, |
NO_LOCAL_NAMES // -- |
}; |
@@ -1242,14 +1212,14 @@ TEST_F(WasmModuleVerifyTest, Names_one_empty) { |
TEST_F(WasmModuleVerifyTest, Names_two_empty) { |
static const byte data[] = { |
- SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
- FUNCTION_SIGNATURES_SECTION(2, 0, 0), // -- |
- SECTION(FUNCTION_BODIES, 1 + 2 * SIZEOF_EMPTY_BODY), // -- |
- 2, |
+ SIGNATURES_SECTION(1, SIG_ENTRY_v_v), // -- |
+ FUNCTION_SIGNATURES_SECTION(2, 0, 0), // -- |
+ SECTION(Code, 1 + 2 * SIZEOF_EMPTY_BODY), // -- |
+ ENTRY_COUNT(2), |
EMPTY_BODY, |
EMPTY_BODY, // -- |
- SECTION(NAMES, 1 + 10), |
- 2, // -- |
+ SECTION_NAMES(1 + 10), |
+ ENTRY_COUNT(2), // -- |
FOO_STRING, |
NO_LOCAL_NAMES, // -- |
FOO_STRING, |
@@ -1258,6 +1228,66 @@ TEST_F(WasmModuleVerifyTest, Names_two_empty) { |
EXPECT_VERIFIES(data); |
} |
+#define EXPECT_INIT_EXPR(Type, type, value, ...) \ |
+ { \ |
+ static const byte data[] = {__VA_ARGS__, kExprEnd}; \ |
+ WasmInitExpr expr = \ |
+ DecodeWasmInitExprForTesting(data, data + sizeof(data)); \ |
+ EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind); \ |
+ EXPECT_EQ(value, expr.val.type##_const); \ |
+ } |
+ |
+TEST_F(WasmModuleVerifyTest, InitExpr_i32) { |
+ EXPECT_INIT_EXPR(I32, i32, 33, WASM_I32V_1(33)); |
+ EXPECT_INIT_EXPR(I32, i32, -21, WASM_I32V_1(-21)); |
+ EXPECT_INIT_EXPR(I32, i32, 437, WASM_I32V_2(437)); |
+ EXPECT_INIT_EXPR(I32, i32, 77777, WASM_I32V_3(77777)); |
+} |
+ |
+TEST_F(WasmModuleVerifyTest, InitExpr_f32) { |
+ EXPECT_INIT_EXPR(F32, f32, static_cast<float>(13.1), WASM_F32(13.1)); |
+ EXPECT_INIT_EXPR(F32, f32, static_cast<float>(-21.1), WASM_F32(-21.1)); |
+ EXPECT_INIT_EXPR(F32, f32, static_cast<float>(437.2), WASM_F32(437.2)); |
+ EXPECT_INIT_EXPR(F32, f32, static_cast<float>(77777.3), WASM_F32(77777.3)); |
+} |
+ |
+TEST_F(WasmModuleVerifyTest, InitExpr_i64) { |
+ EXPECT_INIT_EXPR(I64, i64, 33, WASM_I64V_1(33)); |
+ EXPECT_INIT_EXPR(I64, i64, -21, WASM_I64V_2(-21)); |
+ EXPECT_INIT_EXPR(I64, i64, 437, WASM_I64V_5(437)); |
+ EXPECT_INIT_EXPR(I64, i64, 77777, WASM_I64V_7(77777)); |
+} |
+ |
+TEST_F(WasmModuleVerifyTest, InitExpr_f64) { |
+ EXPECT_INIT_EXPR(F64, f64, 83.22, WASM_F64(83.22)); |
+ EXPECT_INIT_EXPR(F64, f64, -771.3, WASM_F64(-771.3)); |
+ EXPECT_INIT_EXPR(F64, f64, 43703.0, WASM_F64(43703.0)); |
+ EXPECT_INIT_EXPR(F64, f64, 77999.1, WASM_F64(77999.1)); |
+} |
+ |
+#define EXPECT_INIT_EXPR_FAIL(...) \ |
+ { \ |
+ static const byte data[] = {__VA_ARGS__, kExprEnd}; \ |
+ WasmInitExpr expr = \ |
+ DecodeWasmInitExprForTesting(data, data + sizeof(data)); \ |
+ EXPECT_EQ(WasmInitExpr::kNone, expr.kind); \ |
+ } |
+ |
+TEST_F(WasmModuleVerifyTest, InitExpr_illegal) { |
+ EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0)); |
+ EXPECT_INIT_EXPR_FAIL(WASM_GET_LOCAL(0)); |
+ EXPECT_INIT_EXPR_FAIL(WASM_SET_LOCAL(0, WASM_I32V_1(0))); |
+ EXPECT_INIT_EXPR_FAIL(WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0))); |
+ EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
+} |
+ |
+TEST_F(WasmModuleVerifyTest, InitExpr_global) { |
+ static const byte data[] = {WASM_INIT_EXPR_GLOBAL(37)}; |
+ WasmInitExpr expr = DecodeWasmInitExprForTesting(data, data + sizeof(data)); |
+ EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind); |
+ EXPECT_EQ(37, expr.val.global_index); |
+} |
+ |
} // namespace wasm |
} // namespace internal |
} // namespace v8 |