| 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 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
| 6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); | 488 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); |
| 489 | 489 |
| 490 // Return the number of functions in the given wasm object. | 490 // Return the number of functions in the given wasm object. |
| 491 int GetNumberOfFunctions(Handle<JSObject> wasm); | 491 int GetNumberOfFunctions(Handle<JSObject> wasm); |
| 492 | 492 |
| 493 // Create and export JSFunction | 493 // Create and export JSFunction |
| 494 Handle<JSFunction> WrapExportCodeAsJSFunction(Isolate* isolate, | 494 Handle<JSFunction> WrapExportCodeAsJSFunction(Isolate* isolate, |
| 495 Handle<Code> export_code, | 495 Handle<Code> export_code, |
| 496 Handle<String> name, int arity, | 496 Handle<String> name, int arity, |
| 497 MaybeHandle<ByteArray> signature, | 497 MaybeHandle<ByteArray> signature, |
| 498 Handle<JSObject> module_instance); | 498 Handle<JSObject> instance); |
| 499 | 499 |
| 500 // Check whether the given object is a wasm object. | 500 // Check whether the given object is a wasm object. |
| 501 // This checks the number and type of internal fields, so it's not 100 percent | 501 // This checks the number and type of internal fields, so it's not 100 percent |
| 502 // secure. If it turns out that we need more complete checks, we could add a | 502 // secure. If it turns out that we need more complete checks, we could add a |
| 503 // special marker as internal field, which will definitely never occur anywhere | 503 // special marker as internal field, which will definitely never occur anywhere |
| 504 // else. | 504 // else. |
| 505 bool IsWasmObject(Object* object); | 505 bool IsWasmInstance(Object* object); |
| 506 | 506 |
| 507 // Return the compiled module object for this wasm object. | 507 // Return the compiled module object for this wasm object. |
| 508 WasmCompiledModule* GetCompiledModule(JSObject* wasm); | 508 WasmCompiledModule* GetCompiledModule(JSObject* instance); |
| 509 | 509 |
| 510 // Check whether the wasm module was generated from asm.js code. | 510 // Check whether the wasm module was generated from asm.js code. |
| 511 bool WasmIsAsmJs(Object* wasm, Isolate* isolate); | 511 bool WasmIsAsmJs(Object* instance, Isolate* isolate); |
| 512 | 512 |
| 513 // Get the script for the asm.js origin of the wasm module. | 513 // Get the script for the asm.js origin of the wasm module. |
| 514 Handle<Script> GetAsmWasmScript(Handle<JSObject> wasm); | 514 Handle<Script> GetAsmWasmScript(Handle<JSObject> instance); |
| 515 | 515 |
| 516 // Get the asm.js source position for the given byte offset in the given | 516 // Get the asm.js source position for the given byte offset in the given |
| 517 // function. | 517 // function. |
| 518 int GetAsmWasmSourcePosition(Handle<JSObject> wasm, int func_index, | 518 int GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, |
| 519 int byte_offset); | 519 int byte_offset); |
| 520 | 520 |
| 521 // Constructs a single function table as a FixedArray of double size, | 521 // Constructs a single function table as a FixedArray of double size, |
| 522 // populating it with function signature indices and function indices. | 522 // populating it with function signature indices and function indices. |
| 523 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, | 523 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, |
| 524 const WasmModule* module); | 524 const WasmModule* module); |
| 525 | 525 |
| 526 // Populates a function table by replacing function indices with handles to | 526 // Populates a function table by replacing function indices with handles to |
| 527 // the compiled code. | 527 // the compiled code. |
| 528 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, | 528 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, |
| 529 const std::vector<Handle<Code>>* code_table); | 529 const std::vector<Handle<Code>>* code_table); |
| 530 | 530 |
| 531 Handle<JSObject> CreateCompiledModuleObject( | 531 Handle<JSObject> CreateCompiledModuleObject( |
| 532 Isolate* isolate, Handle<WasmCompiledModule> compiled_module, | 532 Isolate* isolate, Handle<WasmCompiledModule> compiled_module, |
| 533 ModuleOrigin origin); | 533 ModuleOrigin origin); |
| 534 | 534 |
| 535 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( | 535 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( |
| 536 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, | 536 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
| 537 ModuleOrigin origin, Handle<Script> asm_js_script, | 537 ModuleOrigin origin, Handle<Script> asm_js_script, |
| 538 const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); | 538 const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); |
| 539 | 539 |
| 540 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, | 540 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, |
| 541 const byte* end, | 541 const byte* end, |
| 542 ErrorThrower* thrower, | 542 ErrorThrower* thrower, |
| 543 ModuleOrigin origin); | 543 ModuleOrigin origin); |
| 544 | 544 |
| 545 // Get the number of imported functions for a WASM instance. | 545 // Get the number of imported functions for a WASM instance. |
| 546 int GetNumImportedFunctions(Handle<JSObject> wasm_object); | 546 int GetNumImportedFunctions(Handle<JSObject> instance); |
| 547 | 547 |
| 548 // Assumed to be called with a code object associated to a wasm module instance. | 548 // Assumed to be called with a code object associated to a wasm module instance. |
| 549 // Intended to be called from runtime functions. | 549 // Intended to be called from runtime functions. |
| 550 // Returns nullptr on failing to get owning instance. | 550 // Returns nullptr on failing to get owning instance. |
| 551 Object* GetOwningWasmInstance(Code* code); | 551 Object* GetOwningWasmInstance(Code* code); |
| 552 | 552 |
| 553 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 553 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
| 554 Handle<JSObject> instance); | 554 Handle<JSObject> instance); |
| 555 | 555 |
| 556 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); | 556 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); |
| 557 | 557 |
| 558 int32_t GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, | 558 int32_t GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, |
| 559 uint32_t pages); | 559 uint32_t pages); |
| 560 | 560 |
| 561 namespace testing { | 561 namespace testing { |
| 562 | 562 |
| 563 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, | 563 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, |
| 564 int instance_count); | 564 int instance_count); |
| 565 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 565 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
| 566 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 566 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| 567 | 567 |
| 568 } // namespace testing | 568 } // namespace testing |
| 569 } // namespace wasm | 569 } // namespace wasm |
| 570 } // namespace internal | 570 } // namespace internal |
| 571 } // namespace v8 | 571 } // namespace v8 |
| 572 | 572 |
| 573 #endif // V8_WASM_MODULE_H_ | 573 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |