Merge V8 5.3.332.45. DO NOT MERGE
Test: Manual
FPIIM-449
Change-Id: Id3254828b068abdea3cb10442e0172a8c9a98e03
(cherry picked from commit 13e2dadd00298019ed862f2b2fc5068bba730bcf)
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc
index 05edd62..7a79d67 100644
--- a/test/cctest/wasm/test-run-wasm-module.cc
+++ b/test/cctest/wasm/test-run-wasm-module.cc
@@ -20,14 +20,24 @@
using namespace v8::internal::wasm;
namespace {
-void TestModule(WasmModuleIndex* module, int32_t expected_result) {
+void TestModule(Zone* zone, WasmModuleBuilder* builder,
+ int32_t expected_result) {
+ ZoneBuffer buffer(zone);
+ builder->WriteTo(buffer);
+
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context());
int32_t result =
- CompileAndRunWasmModule(isolate, module->Begin(), module->End());
+ testing::CompileAndRunWasmModule(isolate, buffer.begin(), buffer.end());
CHECK_EQ(expected_result, result);
}
+
+void ExportAsMain(WasmFunctionBuilder* f) {
+ static const char kMainName[] = "main";
+ f->SetExported();
+ f->SetName(kMainName, arraysize(kMainName) - 1);
+}
} // namespace
TEST(Run_WasmModule_Return114) {
@@ -40,11 +50,10 @@
uint16_t f_index = builder->AddFunction();
WasmFunctionBuilder* f = builder->FunctionAt(f_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {WASM_I8(kReturnValue)};
f->EmitCode(code, sizeof(code));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), kReturnValue);
+ TestModule(&zone, builder, kReturnValue);
}
TEST(Run_WasmModule_CallAdd) {
@@ -66,11 +75,10 @@
f = builder->FunctionAt(f2_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code2[] = {WASM_CALL_FUNCTION2(f1_index, WASM_I8(77), WASM_I8(22))};
f->EmitCode(code2, sizeof(code2));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 99);
+ TestModule(&zone, builder, 99);
}
TEST(Run_WasmModule_ReadLoadedDataSegment) {
@@ -84,15 +92,14 @@
WasmFunctionBuilder* f = builder->FunctionAt(f_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))};
f->EmitCode(code, sizeof(code));
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder(
&zone, data, sizeof(data), kDataSegmentDest0));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 0xddccbbaa);
+ TestModule(&zone, builder, 0xddccbbaa);
}
TEST(Run_WasmModule_CheckMemoryIsZero) {
@@ -107,7 +114,7 @@
f->SetSignature(sigs.i_v());
uint16_t localIndex = f->AddLocal(kAstI32);
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {WASM_BLOCK(
2,
WASM_WHILE(
@@ -117,8 +124,7 @@
WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I8(11))};
f->EmitCode(code, sizeof(code));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 11);
+ TestModule(&zone, builder, 11);
}
TEST(Run_WasmModule_CallMain_recursive) {
@@ -132,7 +138,7 @@
f->SetSignature(sigs.i_v());
uint16_t localIndex = f->AddLocal(kAstI32);
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {WASM_BLOCK(
2, WASM_SET_LOCAL(localIndex,
WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
@@ -142,8 +148,7 @@
WASM_BRV(1, WASM_CALL_FUNCTION0(0))),
WASM_BRV(0, WASM_I8(55))))};
f->EmitCode(code, sizeof(code));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 55);
+ TestModule(&zone, builder, 55);
}
TEST(Run_WasmModule_Global) {
@@ -163,11 +168,10 @@
uint16_t f2_index = builder->AddFunction();
f = builder->FunctionAt(f2_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)),
WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)),
WASM_RETURN1(WASM_CALL_FUNCTION0(f1_index))};
f->EmitCode(code2, sizeof(code2));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 97);
+ TestModule(&zone, builder, 97);
}