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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 table->set(static_cast<int>(i), *(*code_table)[index]); | 1622 table->set(static_cast<int>(i), *(*code_table)[index]); |
1623 } | 1623 } |
1624 } | 1624 } |
1625 | 1625 |
1626 int GetNumberOfFunctions(JSObject* wasm) { | 1626 int GetNumberOfFunctions(JSObject* wasm) { |
1627 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); | 1627 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); |
1628 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. | 1628 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. |
1629 return ByteArray::cast(func_names_obj)->get_int(0); | 1629 return ByteArray::cast(func_names_obj)->get_int(0); |
1630 } | 1630 } |
1631 | 1631 |
1632 Handle<JSObject> CreateCompiledModuleObject( | 1632 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, |
1633 Isolate* isolate, Handle<FixedArray> compiled_module) { | 1633 Handle<FixedArray> compiled_module, |
1634 Handle<JSFunction> module_cons( | 1634 ModuleOrigin origin) { |
1635 isolate->native_context()->wasm_module_constructor()); | 1635 Handle<JSObject> module_obj; |
1636 Handle<JSObject> module_obj = isolate->factory()->NewJSObject(module_cons); | 1636 if (origin == ModuleOrigin::kWasmOrigin) { |
| 1637 Handle<JSFunction> module_cons( |
| 1638 isolate->native_context()->wasm_module_constructor()); |
| 1639 module_obj = isolate->factory()->NewJSObject(module_cons); |
| 1640 } else { |
| 1641 DCHECK(origin == ModuleOrigin::kAsmJsOrigin); |
| 1642 Handle<Map> map = isolate->factory()->NewMap( |
| 1643 JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize); |
| 1644 module_obj = isolate->factory()->NewJSObjectFromMap(map, TENURED); |
| 1645 } |
1637 module_obj->SetInternalField(0, *compiled_module); | 1646 module_obj->SetInternalField(0, *compiled_module); |
1638 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); | 1647 if (origin == ModuleOrigin::kWasmOrigin) { |
1639 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); | 1648 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); |
| 1649 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); |
| 1650 } |
1640 return module_obj; | 1651 return module_obj; |
1641 } | 1652 } |
1642 | 1653 |
| 1654 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, |
| 1655 const byte* start, |
| 1656 const byte* end, |
| 1657 ErrorThrower* thrower, |
| 1658 ModuleOrigin origin) { |
| 1659 MaybeHandle<JSObject> nothing; |
| 1660 Zone zone(isolate->allocator()); |
| 1661 ModuleResult result = |
| 1662 DecodeWasmModule(isolate, &zone, start, end, false, origin); |
| 1663 std::unique_ptr<const WasmModule> decoded_module(result.val); |
| 1664 if (result.failed()) { |
| 1665 thrower->Failed("Wasm decoding failed", result); |
| 1666 return nothing; |
| 1667 } |
| 1668 MaybeHandle<FixedArray> compiled_module = |
| 1669 decoded_module->CompileFunctions(isolate, thrower); |
| 1670 if (compiled_module.is_null()) return nothing; |
| 1671 |
| 1672 return CreateCompiledModuleObject(isolate, compiled_module.ToHandleChecked(), |
| 1673 origin); |
| 1674 } |
| 1675 |
1643 namespace testing { | 1676 namespace testing { |
1644 | 1677 |
1645 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 1678 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
1646 const byte* module_end, bool asm_js) { | 1679 const byte* module_end, bool asm_js) { |
1647 HandleScope scope(isolate); | 1680 HandleScope scope(isolate); |
1648 Zone zone(isolate->allocator()); | 1681 Zone zone(isolate->allocator()); |
1649 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); | 1682 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); |
1650 | 1683 |
1651 // Decode the module, but don't verify function bodies, since we'll | 1684 // Decode the module, but don't verify function bodies, since we'll |
1652 // be compiling them anyway. | 1685 // be compiling them anyway. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 1754 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
1722 } | 1755 } |
1723 thrower->Error("WASM.compileRun() failed: Return value should be number"); | 1756 thrower->Error("WASM.compileRun() failed: Return value should be number"); |
1724 return -1; | 1757 return -1; |
1725 } | 1758 } |
1726 | 1759 |
1727 } // namespace testing | 1760 } // namespace testing |
1728 } // namespace wasm | 1761 } // namespace wasm |
1729 } // namespace internal | 1762 } // namespace internal |
1730 } // namespace v8 | 1763 } // namespace v8 |
OLD | NEW |