Merge V8 5.2.361.47  DO NOT MERGE

https://chromium.googlesource.com/v8/v8/+/5.2.361.47

FPIIM-449

Change-Id: Ibec421b85a9b88cb3a432ada642e469fe7e78346
(cherry picked from commit bcf72ee8e3b26f1d0726869c7ddb3921c68b09a8)
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc
index 118a91f..05edd62 100644
--- a/test/cctest/wasm/test-run-wasm-module.cc
+++ b/test/cctest/wasm/test-run-wasm-module.cc
@@ -12,14 +12,13 @@
 #include "src/wasm/wasm-opcodes.h"
 
 #include "test/cctest/cctest.h"
+#include "test/cctest/wasm/test-signatures.h"
 
 using namespace v8::base;
 using namespace v8::internal;
 using namespace v8::internal::compiler;
 using namespace v8::internal::wasm;
 
-
-// TODO(titzer): fix arm64 frame alignment.
 namespace {
 void TestModule(WasmModuleIndex* module, int32_t expected_result) {
   Isolate* isolate = CcTest::InitIsolateOnce();
@@ -31,50 +30,16 @@
 }
 }  // namespace
 
-
-// A raw test that skips the WasmModuleBuilder.
-TEST(Run_WasmModule_CallAdd_rev) {
-  static const byte data[] = {
-      WASM_MODULE_HEADER,
-      // sig#0 ------------------------------------------
-      WASM_SECTION_SIGNATURES_SIZE + 7,          // Section size.
-      WASM_SECTION_SIGNATURES, 2, 0, kLocalI32,  // void -> int
-      2, kLocalI32, kLocalI32, kLocalI32,        // int,int -> int
-      // func#0 (main) ----------------------------------
-      WASM_SECTION_FUNCTIONS_SIZE + 24, WASM_SECTION_FUNCTIONS, 2,
-      kDeclFunctionExport, 0, 0,  // sig index
-      7, 0,                       // body size
-      0,                          // locals
-      kExprCallFunction, 1,       // --
-      kExprI8Const, 77,           // --
-      kExprI8Const, 22,           // --
-      // func#1 -----------------------------------------
-      0,                 // no name, not exported
-      1, 0,              // sig index
-      6, 0,              // body size
-      0,                 // locals
-      kExprI32Add,       // --
-      kExprGetLocal, 0,  // --
-      kExprGetLocal, 1,  // --
-  };
-
-  Isolate* isolate = CcTest::InitIsolateOnce();
-  HandleScope scope(isolate);
-  WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context());
-  int32_t result =
-      CompileAndRunWasmModule(isolate, data, data + arraysize(data));
-  CHECK_EQ(99, result);
-}
-
-
 TEST(Run_WasmModule_Return114) {
   static const int32_t kReturnValue = 114;
+  TestSignatures sigs;
   v8::base::AccountingAllocator allocator;
   Zone zone(&allocator);
+
   WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
   uint16_t f_index = builder->AddFunction();
   WasmFunctionBuilder* f = builder->FunctionAt(f_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
   f->Exported(1);
   byte code[] = {WASM_I8(kReturnValue)};
   f->EmitCode(code, sizeof(code));
@@ -82,38 +47,43 @@
   TestModule(writer->WriteTo(&zone), kReturnValue);
 }
 
-
 TEST(Run_WasmModule_CallAdd) {
   v8::base::AccountingAllocator allocator;
   Zone zone(&allocator);
+  TestSignatures sigs;
+
   WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
+
   uint16_t f1_index = builder->AddFunction();
   WasmFunctionBuilder* f = builder->FunctionAt(f1_index);
-  f->ReturnType(kAstI32);
-  uint16_t param1 = f->AddParam(kAstI32);
-  uint16_t param2 = f->AddParam(kAstI32);
+  f->SetSignature(sigs.i_ii());
+  uint16_t param1 = 0;
+  uint16_t param2 = 1;
   byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))};
-  uint32_t local_indices1[] = {2, 4};
-  f->EmitCode(code1, sizeof(code1), local_indices1, sizeof(local_indices1) / 4);
+  f->EmitCode(code1, sizeof(code1));
+
   uint16_t f2_index = builder->AddFunction();
   f = builder->FunctionAt(f2_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
+
   f->Exported(1);
-  byte code2[] = {WASM_CALL_FUNCTION(f1_index, WASM_I8(77), WASM_I8(22))};
+  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);
 }
 
-
 TEST(Run_WasmModule_ReadLoadedDataSegment) {
   static const byte kDataSegmentDest0 = 12;
   v8::base::AccountingAllocator allocator;
   Zone zone(&allocator);
+  TestSignatures sigs;
+
   WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
   uint16_t f_index = builder->AddFunction();
   WasmFunctionBuilder* f = builder->FunctionAt(f_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
+
   f->Exported(1);
   byte code[] = {
       WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))};
@@ -129,10 +99,13 @@
   static const int kCheckSize = 16 * 1024;
   v8::base::AccountingAllocator allocator;
   Zone zone(&allocator);
+  TestSignatures sigs;
+
   WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
   uint16_t f_index = builder->AddFunction();
   WasmFunctionBuilder* f = builder->FunctionAt(f_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
+
   uint16_t localIndex = f->AddLocal(kAstI32);
   f->Exported(1);
   byte code[] = {WASM_BLOCK(
@@ -143,7 +116,7 @@
               WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)),
               WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))),
       WASM_I8(11))};
-  f->EmitCode(code, sizeof(code), nullptr, 0);
+  f->EmitCode(code, sizeof(code));
   WasmModuleWriter* writer = builder->Build(&zone);
   TestModule(writer->WriteTo(&zone), 11);
 }
@@ -151,10 +124,13 @@
 TEST(Run_WasmModule_CallMain_recursive) {
   v8::base::AccountingAllocator allocator;
   Zone zone(&allocator);
+  TestSignatures sigs;
+
   WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
   uint16_t f_index = builder->AddFunction();
   WasmFunctionBuilder* f = builder->FunctionAt(f_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
+
   uint16_t localIndex = f->AddLocal(kAstI32);
   f->Exported(1);
   byte code[] = {WASM_BLOCK(
@@ -165,7 +141,7 @@
                                                 WASM_INC_LOCAL(localIndex)),
                               WASM_BRV(1, WASM_CALL_FUNCTION0(0))),
                    WASM_BRV(0, WASM_I8(55))))};
-  f->EmitCode(code, sizeof(code), nullptr, 0);
+  f->EmitCode(code, sizeof(code));
   WasmModuleWriter* writer = builder->Build(&zone);
   TestModule(writer->WriteTo(&zone), 55);
 }
@@ -173,22 +149,24 @@
 TEST(Run_WasmModule_Global) {
   v8::base::AccountingAllocator allocator;
   Zone zone(&allocator);
+  TestSignatures sigs;
+
   WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
   uint32_t global1 = builder->AddGlobal(MachineType::Int32(), 0);
   uint32_t global2 = builder->AddGlobal(MachineType::Int32(), 0);
   uint16_t f1_index = builder->AddFunction();
   WasmFunctionBuilder* f = builder->FunctionAt(f1_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
   byte code1[] = {
       WASM_I32_ADD(WASM_LOAD_GLOBAL(global1), WASM_LOAD_GLOBAL(global2))};
   f->EmitCode(code1, sizeof(code1));
   uint16_t f2_index = builder->AddFunction();
   f = builder->FunctionAt(f2_index);
-  f->ReturnType(kAstI32);
+  f->SetSignature(sigs.i_v());
   f->Exported(1);
   byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)),
                   WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)),
-                  WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))};
+                  WASM_RETURN1(WASM_CALL_FUNCTION0(f1_index))};
   f->EmitCode(code2, sizeof(code2));
   WasmModuleWriter* writer = builder->Build(&zone);
   TestModule(writer->WriteTo(&zone), 97);