OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/wasm/encoder.h" | 8 #include "src/wasm/encoder.h" |
9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
10 #include "src/wasm/wasm-js.h" | |
11 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
12 #include "src/wasm/wasm-module.h" | 11 #include "src/wasm/wasm-module.h" |
13 #include "src/wasm/wasm-opcodes.h" | 12 #include "src/wasm/wasm-opcodes.h" |
14 | 13 |
15 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
16 #include "test/cctest/wasm/test-signatures.h" | 15 #include "test/cctest/wasm/test-signatures.h" |
17 #include "test/common/wasm/wasm-module-runner.h" | 16 #include "test/common/wasm/wasm-module-runner.h" |
18 | 17 |
19 using namespace v8::base; | 18 using namespace v8::base; |
20 using namespace v8::internal; | 19 using namespace v8::internal; |
21 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
22 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
23 | 22 |
24 namespace { | 23 namespace { |
24 static bool isolate_setup_for_module = false; | |
25 void TestModule(Zone* zone, WasmModuleBuilder* builder, | 25 void TestModule(Zone* zone, WasmModuleBuilder* builder, |
26 int32_t expected_result) { | 26 int32_t expected_result) { |
27 ZoneBuffer buffer(zone); | 27 ZoneBuffer buffer(zone); |
28 builder->WriteTo(buffer); | 28 builder->WriteTo(buffer); |
29 | 29 |
30 Isolate* isolate = CcTest::InitIsolateOnce(); | 30 Isolate* isolate = CcTest::InitIsolateOnce(); |
31 HandleScope scope(isolate); | 31 HandleScope scope(isolate); |
32 WasmJs::SetupIsolateForWasm(isolate); | 32 if (!isolate_setup_for_module) { |
Mircea Trofin
2016/09/16 07:13:01
This will only setup the first isolate.
gdeepti
2016/09/16 07:37:21
My understanding is that the isolate being returne
| |
33 testing::SetupIsolateForWasmModule(isolate); | |
34 isolate_setup_for_module = true; | |
35 } | |
33 int32_t result = testing::CompileAndRunWasmModule( | 36 int32_t result = testing::CompileAndRunWasmModule( |
34 isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin); | 37 isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin); |
35 CHECK_EQ(expected_result, result); | 38 CHECK_EQ(expected_result, result); |
36 } | 39 } |
37 | 40 |
38 void ExportAs(WasmFunctionBuilder* f, const char* name) { | 41 void ExportAs(WasmFunctionBuilder* f, const char* name) { |
39 f->SetExported(); | 42 f->SetExported(); |
40 f->SetName(name, static_cast<int>(strlen(name))); | 43 f->SetName(name, static_cast<int>(strlen(name))); |
41 } | 44 } |
42 | 45 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 ExportAs(f, kFunctionName); | 201 ExportAs(f, kFunctionName); |
199 | 202 |
200 ZoneBuffer buffer(&zone); | 203 ZoneBuffer buffer(&zone); |
201 builder->WriteTo(buffer); | 204 builder->WriteTo(buffer); |
202 | 205 |
203 Isolate* isolate = CcTest::InitIsolateOnce(); | 206 Isolate* isolate = CcTest::InitIsolateOnce(); |
204 ErrorThrower thrower(isolate, ""); | 207 ErrorThrower thrower(isolate, ""); |
205 v8::WasmCompiledModule::SerializedModule data; | 208 v8::WasmCompiledModule::SerializedModule data; |
206 { | 209 { |
207 HandleScope scope(isolate); | 210 HandleScope scope(isolate); |
208 WasmJs::SetupIsolateForWasm(isolate); | |
209 | 211 |
210 ModuleResult decoding_result = DecodeWasmModule( | 212 ModuleResult decoding_result = DecodeWasmModule( |
211 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin); | 213 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin); |
212 std::unique_ptr<const WasmModule> module(decoding_result.val); | 214 std::unique_ptr<const WasmModule> module(decoding_result.val); |
213 CHECK(!decoding_result.failed()); | 215 CHECK(!decoding_result.failed()); |
214 | 216 |
215 MaybeHandle<FixedArray> compiled_module = | 217 MaybeHandle<FixedArray> compiled_module = |
216 module->CompileFunctions(isolate, &thrower); | 218 module->CompileFunctions(isolate, &thrower); |
217 CHECK(!compiled_module.is_null()); | 219 CHECK(!compiled_module.is_null()); |
218 Handle<JSObject> module_obj = CreateCompiledModuleObject( | 220 Handle<JSObject> module_obj = CreateCompiledModuleObject( |
(...skipping 10 matching lines...) Expand all Loading... | |
229 create_params.array_buffer_allocator = | 231 create_params.array_buffer_allocator = |
230 CcTest::InitIsolateOnce()->array_buffer_allocator(); | 232 CcTest::InitIsolateOnce()->array_buffer_allocator(); |
231 | 233 |
232 v8::Isolate* v8_isolate = v8::Isolate::New(create_params); | 234 v8::Isolate* v8_isolate = v8::Isolate::New(create_params); |
233 { | 235 { |
234 v8::Isolate::Scope isolate_scope(v8_isolate); | 236 v8::Isolate::Scope isolate_scope(v8_isolate); |
235 v8::HandleScope new_scope(v8_isolate); | 237 v8::HandleScope new_scope(v8_isolate); |
236 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); | 238 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); |
237 new_ctx->Enter(); | 239 new_ctx->Enter(); |
238 isolate = reinterpret_cast<Isolate*>(v8_isolate); | 240 isolate = reinterpret_cast<Isolate*>(v8_isolate); |
239 WasmJs::SetupIsolateForWasm(isolate); | 241 testing::SetupIsolateForWasmModule(isolate); |
Mircea Trofin
2016/09/16 07:13:00
On line 240, we reassign isolate to the v8_isolate
gdeepti
2016/09/16 07:37:21
Can you elaborate what you mean by we won't initia
| |
240 | 242 |
241 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = | 243 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = |
242 v8::WasmCompiledModule::Deserialize(v8_isolate, data); | 244 v8::WasmCompiledModule::Deserialize(v8_isolate, data); |
243 v8::Local<v8::WasmCompiledModule> compiled_module; | 245 v8::Local<v8::WasmCompiledModule> compiled_module; |
244 CHECK(deserialized.ToLocal(&compiled_module)); | 246 CHECK(deserialized.ToLocal(&compiled_module)); |
245 Handle<JSObject> module_object = | 247 Handle<JSObject> module_object = |
246 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); | 248 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); |
247 Handle<JSObject> instance = | 249 Handle<JSObject> instance = |
248 WasmModule::Instantiate(isolate, module_object, | 250 WasmModule::Instantiate(isolate, module_object, |
249 Handle<JSReceiver>::null(), | 251 Handle<JSReceiver>::null(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 285 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
284 uint16_t f_index = builder->AddFunction(); | 286 uint16_t f_index = builder->AddFunction(); |
285 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 287 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
286 f->SetSignature(sigs.i_v()); | 288 f->SetSignature(sigs.i_v()); |
287 ExportAsMain(f); | 289 ExportAsMain(f); |
288 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), | 290 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), |
289 WASM_I32V(12))}; | 291 WASM_I32V(12))}; |
290 f->EmitCode(code, sizeof(code)); | 292 f->EmitCode(code, sizeof(code)); |
291 TestModule(&zone, builder, 12); | 293 TestModule(&zone, builder, 12); |
292 } | 294 } |
OLD | NEW |