| 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 "src/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
| 6 #include "src/objects.h" | 6 #include "src/objects.h" |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/simulator.h" | 9 #include "src/simulator.h" |
| 10 | 10 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 if (!instance->globals_start) { | 249 if (!instance->globals_start) { |
| 250 // Not enough space for backing store of globals. | 250 // Not enough space for backing store of globals. |
| 251 thrower->Error("Out of memory: wasm globals"); | 251 thrower->Error("Out of memory: wasm globals"); |
| 252 return false; | 252 return false; |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 return true; | 255 return true; |
| 256 } | 256 } |
| 257 } // namespace | 257 } // namespace |
| 258 | 258 |
| 259 | |
| 260 WasmModule::WasmModule() | 259 WasmModule::WasmModule() |
| 261 : globals(nullptr), | 260 : shared_isolate(nullptr), |
| 261 module_start(nullptr), |
| 262 module_end(nullptr), |
| 263 min_mem_size_log2(0), |
| 264 max_mem_size_log2(0), |
| 265 mem_export(false), |
| 266 mem_external(false), |
| 267 start_function_index(-1), |
| 268 globals(nullptr), |
| 262 signatures(nullptr), | 269 signatures(nullptr), |
| 263 functions(nullptr), | 270 functions(nullptr), |
| 264 data_segments(nullptr), | 271 data_segments(nullptr), |
| 265 function_table(nullptr) {} | 272 function_table(nullptr) {} |
| 266 | 273 |
| 267 | |
| 268 WasmModule::~WasmModule() { | 274 WasmModule::~WasmModule() { |
| 269 if (globals) delete globals; | 275 if (globals) delete globals; |
| 270 if (signatures) delete signatures; | 276 if (signatures) delete signatures; |
| 271 if (functions) delete functions; | 277 if (functions) delete functions; |
| 272 if (data_segments) delete data_segments; | 278 if (data_segments) delete data_segments; |
| 273 if (function_table) delete function_table; | 279 if (function_table) delete function_table; |
| 274 } | 280 } |
| 275 | 281 |
| 276 | 282 |
| 277 // Instantiates a wasm module as a JSObject. | 283 // Instantiates a wasm module as a JSObject. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // Exported functions are installed as read-only properties on the module. | 402 // Exported functions are installed as read-only properties on the module. |
| 397 JSObject::AddProperty(instance.js_object, name, function, READ_ONLY); | 403 JSObject::AddProperty(instance.js_object, name, function, READ_ONLY); |
| 398 } | 404 } |
| 399 index++; | 405 index++; |
| 400 } | 406 } |
| 401 | 407 |
| 402 // Second pass: patch all direct call sites. | 408 // Second pass: patch all direct call sites. |
| 403 linker.Link(instance.function_table, this->function_table); | 409 linker.Link(instance.function_table, this->function_table); |
| 404 instance.js_object->SetInternalField(kWasmModuleFunctionTable, | 410 instance.js_object->SetInternalField(kWasmModuleFunctionTable, |
| 405 Smi::FromInt(0)); | 411 Smi::FromInt(0)); |
| 412 |
| 413 // Run the start function if one was specified. |
| 414 if (this->start_function_index >= 0) { |
| 415 HandleScope scope(isolate); |
| 416 uint32_t index = static_cast<uint32_t>(this->start_function_index); |
| 417 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); |
| 418 Handle<Code> code = linker.GetFunctionCode(index); |
| 419 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( |
| 420 isolate, &module_env, name, code, instance.js_object, index); |
| 421 |
| 422 // Call the JS function. |
| 423 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); |
| 424 MaybeHandle<Object> retval = |
| 425 Execution::Call(isolate, jsfunc, undefined, 0, nullptr); |
| 426 |
| 427 if (retval.is_null()) { |
| 428 thrower.Error("WASM.instantiateModule(): start function failed"); |
| 429 } |
| 430 } |
| 406 return instance.js_object; | 431 return instance.js_object; |
| 407 } | 432 } |
| 408 | 433 |
| 409 | 434 |
| 410 Handle<Code> ModuleEnv::GetFunctionCode(uint32_t index) { | 435 Handle<Code> ModuleEnv::GetFunctionCode(uint32_t index) { |
| 411 DCHECK(IsValidFunction(index)); | 436 DCHECK(IsValidFunction(index)); |
| 412 if (linker) return linker->GetFunctionCode(index); | 437 if (linker) return linker->GetFunctionCode(index); |
| 413 if (instance && instance->function_code) { | 438 if (instance && instance->function_code) { |
| 414 return instance->function_code->at(index); | 439 return instance->function_code->at(index); |
| 415 } | 440 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 551 } |
| 527 if (result->IsHeapNumber()) { | 552 if (result->IsHeapNumber()) { |
| 528 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 553 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
| 529 } | 554 } |
| 530 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 555 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
| 531 return -1; | 556 return -1; |
| 532 } | 557 } |
| 533 } // namespace wasm | 558 } // namespace wasm |
| 534 } // namespace internal | 559 } // namespace internal |
| 535 } // namespace v8 | 560 } // namespace v8 |
| OLD | NEW |