| 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 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2086 | 2086 |
| 2087 int GetNumberOfFunctions(Handle<JSObject> wasm) { | 2087 int GetNumberOfFunctions(Handle<JSObject> wasm) { |
| 2088 DCHECK(IsWasmObject(*wasm)); | 2088 DCHECK(IsWasmObject(*wasm)); |
| 2089 WasmCompiledModule* compiled_module = | 2089 WasmCompiledModule* compiled_module = |
| 2090 WasmCompiledModule::cast(wasm->GetInternalField(kWasmCompiledModule)); | 2090 WasmCompiledModule::cast(wasm->GetInternalField(kWasmCompiledModule)); |
| 2091 ByteArray* func_names_arr = compiled_module->ptr_to_function_names(); | 2091 ByteArray* func_names_arr = compiled_module->ptr_to_function_names(); |
| 2092 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. | 2092 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. |
| 2093 return func_names_arr->get_int(0); | 2093 return func_names_arr->get_int(0); |
| 2094 } | 2094 } |
| 2095 | 2095 |
| 2096 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, | 2096 Handle<JSObject> CreateCompiledModuleObject( |
| 2097 Handle<FixedArray> compiled_module, | 2097 Isolate* isolate, Handle<WasmCompiledModule> compiled_module, |
| 2098 ModuleOrigin origin) { | 2098 ModuleOrigin origin) { |
| 2099 Handle<JSObject> module_obj; | 2099 Handle<JSObject> module_obj; |
| 2100 if (origin == ModuleOrigin::kWasmOrigin) { | 2100 if (origin == ModuleOrigin::kWasmOrigin) { |
| 2101 Handle<JSFunction> module_cons( | 2101 Handle<JSFunction> module_cons( |
| 2102 isolate->native_context()->wasm_module_constructor()); | 2102 isolate->native_context()->wasm_module_constructor()); |
| 2103 module_obj = isolate->factory()->NewJSObject(module_cons); | 2103 module_obj = isolate->factory()->NewJSObject(module_cons); |
| 2104 } else { | 2104 } else { |
| 2105 DCHECK(origin == ModuleOrigin::kAsmJsOrigin); | 2105 DCHECK(origin == ModuleOrigin::kAsmJsOrigin); |
| 2106 Handle<Map> map = isolate->factory()->NewMap( | 2106 Handle<Map> map = isolate->factory()->NewMap( |
| 2107 JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize); | 2107 JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize); |
| 2108 module_obj = isolate->factory()->NewJSObjectFromMap(map, TENURED); | 2108 module_obj = isolate->factory()->NewJSObjectFromMap(map, TENURED); |
| 2109 } | 2109 } |
| 2110 module_obj->SetInternalField(0, *compiled_module); | 2110 module_obj->SetInternalField(0, *compiled_module); |
| 2111 if (origin == ModuleOrigin::kWasmOrigin) { | 2111 if (origin == ModuleOrigin::kWasmOrigin) { |
| 2112 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); | 2112 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); |
| 2113 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); | 2113 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); |
| 2114 } | 2114 } |
| 2115 Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj); | 2115 Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj); |
| 2116 WasmCompiledModule::cast(*compiled_module) | 2116 compiled_module->set_weak_module_object(link_to_module); |
| 2117 ->set_weak_module_object(link_to_module); | |
| 2118 return module_obj; | 2117 return module_obj; |
| 2119 } | 2118 } |
| 2120 | 2119 |
| 2121 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, | 2120 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, |
| 2122 const byte* start, | 2121 const byte* start, |
| 2123 const byte* end, | 2122 const byte* end, |
| 2124 ErrorThrower* thrower, | 2123 ErrorThrower* thrower, |
| 2125 ModuleOrigin origin) { | 2124 ModuleOrigin origin) { |
| 2126 MaybeHandle<JSObject> nothing; | 2125 MaybeHandle<JSObject> nothing; |
| 2127 Zone zone(isolate->allocator()); | 2126 Zone zone(isolate->allocator()); |
| 2128 ModuleResult result = | 2127 ModuleResult result = |
| 2129 DecodeWasmModule(isolate, &zone, start, end, false, origin); | 2128 DecodeWasmModule(isolate, &zone, start, end, false, origin); |
| 2130 std::unique_ptr<const WasmModule> decoded_module(result.val); | 2129 std::unique_ptr<const WasmModule> decoded_module(result.val); |
| 2131 if (result.failed()) { | 2130 if (result.failed()) { |
| 2132 thrower->Failed("Wasm decoding failed", result); | 2131 thrower->Failed("Wasm decoding failed", result); |
| 2133 return nothing; | 2132 return nothing; |
| 2134 } | 2133 } |
| 2135 MaybeHandle<FixedArray> compiled_module = | 2134 MaybeHandle<WasmCompiledModule> compiled_module = |
| 2136 decoded_module->CompileFunctions(isolate, thrower); | 2135 decoded_module->CompileFunctions(isolate, thrower); |
| 2137 if (compiled_module.is_null()) return nothing; | 2136 if (compiled_module.is_null()) return nothing; |
| 2138 | 2137 |
| 2139 return CreateCompiledModuleObject(isolate, compiled_module.ToHandleChecked(), | 2138 return CreateCompiledModuleObject(isolate, compiled_module.ToHandleChecked(), |
| 2140 origin); | 2139 origin); |
| 2141 } | 2140 } |
| 2142 | 2141 |
| 2143 bool ValidateModuleBytes(Isolate* isolate, const byte* start, const byte* end, | 2142 bool ValidateModuleBytes(Isolate* isolate, const byte* start, const byte* end, |
| 2144 ErrorThrower* thrower, ModuleOrigin origin) { | 2143 ErrorThrower* thrower, ModuleOrigin origin) { |
| 2145 Zone zone(isolate->allocator()); | 2144 Zone zone(isolate->allocator()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2277 WasmCompiledModule* compiled_module = | 2276 WasmCompiledModule* compiled_module = |
| 2278 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule)); | 2277 WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule)); |
| 2279 CHECK(compiled_module->has_weak_module_object()); | 2278 CHECK(compiled_module->has_weak_module_object()); |
| 2280 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); | 2279 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); |
| 2281 } | 2280 } |
| 2282 | 2281 |
| 2283 } // namespace testing | 2282 } // namespace testing |
| 2284 } // namespace wasm | 2283 } // namespace wasm |
| 2285 } // namespace internal | 2284 } // namespace internal |
| 2286 } // namespace v8 | 2285 } // namespace v8 |
| OLD | NEW |