| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 min_mem_size_log2(0), | 276 min_mem_size_log2(0), |
| 277 max_mem_size_log2(0), | 277 max_mem_size_log2(0), |
| 278 mem_export(false), | 278 mem_export(false), |
| 279 mem_external(false), | 279 mem_external(false), |
| 280 start_function_index(-1), | 280 start_function_index(-1), |
| 281 globals(nullptr), | 281 globals(nullptr), |
| 282 signatures(nullptr), | 282 signatures(nullptr), |
| 283 functions(nullptr), | 283 functions(nullptr), |
| 284 data_segments(nullptr), | 284 data_segments(nullptr), |
| 285 function_table(nullptr), | 285 function_table(nullptr), |
| 286 import_table(nullptr) {} | 286 import_table(nullptr), |
| 287 export_table(nullptr) {} |
| 287 | 288 |
| 288 WasmModule::~WasmModule() { | 289 WasmModule::~WasmModule() { |
| 289 if (globals) delete globals; | 290 if (globals) delete globals; |
| 290 if (signatures) delete signatures; | 291 if (signatures) delete signatures; |
| 291 if (functions) delete functions; | 292 if (functions) delete functions; |
| 292 if (data_segments) delete data_segments; | 293 if (data_segments) delete data_segments; |
| 293 if (function_table) delete function_table; | 294 if (function_table) delete function_table; |
| 294 if (import_table) delete import_table; | 295 if (import_table) delete import_table; |
| 296 if (export_table) delete export_table; |
| 295 } | 297 } |
| 296 | 298 |
| 297 static MaybeHandle<JSFunction> LookupFunction(ErrorThrower& thrower, | 299 static MaybeHandle<JSFunction> LookupFunction(ErrorThrower& thrower, |
| 298 Handle<JSObject> ffi, | 300 Handle<JSObject> ffi, |
| 299 uint32_t index, | 301 uint32_t index, |
| 300 Handle<String> name, | 302 Handle<String> name, |
| 301 const char* cstr) { | 303 const char* cstr) { |
| 302 if (!ffi.is_null()) { | 304 if (!ffi.is_null()) { |
| 303 MaybeHandle<Object> result = Object::GetProperty(ffi, name); | 305 MaybeHandle<Object> result = Object::GetProperty(ffi, name); |
| 304 if (!result.is_null()) { | 306 if (!result.is_null()) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 JSObject::AddProperty(instance.js_object, name, function, READ_ONLY); | 450 JSObject::AddProperty(instance.js_object, name, function, READ_ONLY); |
| 449 } | 451 } |
| 450 index++; | 452 index++; |
| 451 } | 453 } |
| 452 | 454 |
| 453 // Second pass: patch all direct call sites. | 455 // Second pass: patch all direct call sites. |
| 454 linker.Link(instance.function_table, this->function_table); | 456 linker.Link(instance.function_table, this->function_table); |
| 455 instance.js_object->SetInternalField(kWasmModuleFunctionTable, | 457 instance.js_object->SetInternalField(kWasmModuleFunctionTable, |
| 456 Smi::FromInt(0)); | 458 Smi::FromInt(0)); |
| 457 | 459 |
| 460 //------------------------------------------------------------------------- |
| 461 // Create and populate the exports object. |
| 462 //------------------------------------------------------------------------- |
| 463 if (export_table->size() > 0) { |
| 464 index = 0; |
| 465 // Create the "exports" object. |
| 466 Handle<JSFunction> object_function = Handle<JSFunction>( |
| 467 isolate->native_context()->object_function(), isolate); |
| 468 Handle<JSObject> exports_object = |
| 469 factory->NewJSObject(object_function, TENURED); |
| 470 Handle<String> exports_name = factory->InternalizeUtf8String("exports"); |
| 471 JSObject::AddProperty(instance.js_object, exports_name, exports_object, |
| 472 READ_ONLY); |
| 473 |
| 474 // Compile wrappers and add them to the exports object. |
| 475 for (const WasmExport& exp : *export_table) { |
| 476 if (thrower.error()) break; |
| 477 const char* cstr = GetName(exp.name_offset); |
| 478 Handle<String> name = factory->InternalizeUtf8String(cstr); |
| 479 Handle<Code> code = linker.GetFunctionCode(exp.func_index); |
| 480 Handle<JSFunction> function = compiler::CompileJSToWasmWrapper( |
| 481 isolate, &module_env, name, code, instance.js_object, exp.func_index); |
| 482 JSObject::AddProperty(exports_object, name, function, READ_ONLY); |
| 483 } |
| 484 } |
| 485 |
| 458 // Run the start function if one was specified. | 486 // Run the start function if one was specified. |
| 459 if (this->start_function_index >= 0) { | 487 if (this->start_function_index >= 0) { |
| 460 HandleScope scope(isolate); | 488 HandleScope scope(isolate); |
| 461 uint32_t index = static_cast<uint32_t>(this->start_function_index); | 489 uint32_t index = static_cast<uint32_t>(this->start_function_index); |
| 462 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); | 490 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); |
| 463 Handle<Code> code = linker.GetFunctionCode(index); | 491 Handle<Code> code = linker.GetFunctionCode(index); |
| 464 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( | 492 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( |
| 465 isolate, &module_env, name, code, instance.js_object, index); | 493 isolate, &module_env, name, code, instance.js_object, index); |
| 466 | 494 |
| 467 // Call the JS function. | 495 // Call the JS function. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 } | 632 } |
| 605 if (result->IsHeapNumber()) { | 633 if (result->IsHeapNumber()) { |
| 606 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 634 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
| 607 } | 635 } |
| 608 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 636 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
| 609 return -1; | 637 return -1; |
| 610 } | 638 } |
| 611 } // namespace wasm | 639 } // namespace wasm |
| 612 } // namespace internal | 640 } // namespace internal |
| 613 } // namespace v8 | 641 } // namespace v8 |
| OLD | NEW |