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/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2597 MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate( | 2597 MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate( |
2598 isolate, &thrower, module_object, imports, Handle<JSArrayBuffer>::null()); | 2598 isolate, &thrower, module_object, imports, Handle<JSArrayBuffer>::null()); |
2599 if (thrower.error()) { | 2599 if (thrower.error()) { |
2600 RejectPromise(isolate, handle(isolate->context()), &thrower, promise); | 2600 RejectPromise(isolate, handle(isolate->context()), &thrower, promise); |
2601 return; | 2601 return; |
2602 } | 2602 } |
2603 ResolvePromise(isolate, handle(isolate->context()), promise, | 2603 ResolvePromise(isolate, handle(isolate->context()), promise, |
2604 instance_object.ToHandleChecked()); | 2604 instance_object.ToHandleChecked()); |
2605 } | 2605 } |
2606 | 2606 |
2607 void wasm::AsyncCompileAndInstantiate(Isolate* isolate, | |
2608 Handle<JSPromise> promise, | |
2609 const ModuleWireBytes& bytes, | |
2610 MaybeHandle<JSReceiver> imports) { | |
2611 ErrorThrower thrower(isolate, nullptr); | |
2612 | |
2613 // Compile the module. | |
2614 MaybeHandle<WasmModuleObject> module_object = | |
2615 SyncCompile(isolate, &thrower, bytes); | |
2616 if (thrower.error()) { | |
2617 RejectPromise(isolate, handle(isolate->context()), &thrower, promise); | |
2618 return; | |
2619 } | |
2620 Handle<WasmModuleObject> module = module_object.ToHandleChecked(); | |
2621 | |
2622 // Instantiate the module. | |
2623 MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate( | |
2624 isolate, &thrower, module, imports, Handle<JSArrayBuffer>::null()); | |
2625 if (thrower.error()) { | |
2626 RejectPromise(isolate, handle(isolate->context()), &thrower, promise); | |
2627 return; | |
2628 } | |
2629 | |
2630 Handle<JSFunction> object_function = | |
2631 Handle<JSFunction>(isolate->native_context()->object_function(), isolate); | |
2632 Handle<JSObject> ret = | |
2633 isolate->factory()->NewJSObject(object_function, TENURED); | |
2634 Handle<String> module_property_name = | |
2635 isolate->factory()->InternalizeUtf8String("module"); | |
2636 Handle<String> instance_property_name = | |
2637 isolate->factory()->InternalizeUtf8String("instance"); | |
2638 JSObject::AddProperty(ret, module_property_name, module, NONE); | |
2639 JSObject::AddProperty(ret, instance_property_name, | |
2640 instance_object.ToHandleChecked(), NONE); | |
2641 | |
2642 ResolvePromise(isolate, handle(isolate->context()), promise, ret); | |
2643 } | |
2644 | |
2645 // Encapsulates all the state and steps of an asynchronous compilation. | 2607 // Encapsulates all the state and steps of an asynchronous compilation. |
2646 // An asynchronous compile job consists of a number of tasks that are executed | 2608 // An asynchronous compile job consists of a number of tasks that are executed |
2647 // as foreground and background tasks. Any phase that touches the V8 heap or | 2609 // as foreground and background tasks. Any phase that touches the V8 heap or |
2648 // allocates on the V8 heap (e.g. creating the module object) must be a | 2610 // allocates on the V8 heap (e.g. creating the module object) must be a |
2649 // foreground task. All other tasks (e.g. decoding and validating, the majority | 2611 // foreground task. All other tasks (e.g. decoding and validating, the majority |
2650 // of the work of compilation) can be background tasks. | 2612 // of the work of compilation) can be background tasks. |
2651 // TODO(wasm): factor out common parts of this with the synchronous pipeline. | 2613 // TODO(wasm): factor out common parts of this with the synchronous pipeline. |
2652 // | 2614 // |
2653 // Note: In predictable mode, DoSync and DoAsync execute the referenced function | 2615 // Note: In predictable mode, DoSync and DoAsync execute the referenced function |
2654 // immediately before returning. Thus we handle the predictable mode specially, | 2616 // immediately before returning. Thus we handle the predictable mode specially, |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3307 callee_compiled->instruction_start()); | 3269 callee_compiled->instruction_start()); |
3308 } | 3270 } |
3309 DCHECK_EQ(non_compiled_functions.size(), idx); | 3271 DCHECK_EQ(non_compiled_functions.size(), idx); |
3310 } | 3272 } |
3311 | 3273 |
3312 Code* ret = | 3274 Code* ret = |
3313 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3275 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
3314 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3276 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
3315 return handle(ret, isolate); | 3277 return handle(ret, isolate); |
3316 } | 3278 } |
OLD | NEW |