OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium 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 "bindings/modules/v8/wasm/WasmResponseExtensions.h" | 5 #include "bindings/modules/v8/wasm/WasmResponseExtensions.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if (!args[0]->IsPromise() && | 200 if (!args[0]->IsPromise() && |
201 !V8Response::hasInstance(args[0], args.GetIsolate())) | 201 !V8Response::hasInstance(args[0], args.GetIsolate())) |
202 return false; | 202 return false; |
203 | 203 |
204 v8::Isolate* isolate = args.GetIsolate(); | 204 v8::Isolate* isolate = args.GetIsolate(); |
205 ScriptState* script_state = ScriptState::ForReceiverObject(args); | 205 ScriptState* script_state = ScriptState::ForReceiverObject(args); |
206 | 206 |
207 v8::Local<v8::Function> compile_callback = | 207 v8::Local<v8::Function> compile_callback = |
208 v8::Function::New(isolate, CompileFromResponseCallback); | 208 v8::Function::New(isolate, CompileFromResponseCallback); |
209 | 209 |
210 ScriptPromiseResolver* script_promise_resolver = | |
211 ScriptPromiseResolver::Create(script_state); | |
212 // treat either case of parameter as | 210 // treat either case of parameter as |
213 // Promise.resolve(parameter) | 211 // Promise.resolve(parameter) |
214 // as per https://www.w3.org/2001/tag/doc/promises-guide#resolve-arguments | 212 // as per https://www.w3.org/2001/tag/doc/promises-guide#resolve-arguments |
215 | 213 |
216 // Ending with: | 214 // Ending with: |
217 // return Promise.resolve(parameter).then(compileCallback); | 215 // return Promise.resolve(parameter).then(compileCallback); |
218 ScriptPromise parameter_as_promise = script_promise_resolver->Promise(); | |
219 V8SetReturnValue(args, ScriptPromise::Cast(script_state, args[0]) | 216 V8SetReturnValue(args, ScriptPromise::Cast(script_state, args[0]) |
220 .Then(compile_callback) | 217 .Then(compile_callback) |
221 .V8Value()); | 218 .V8Value()); |
222 | 219 |
223 // resolve the first parameter promise. | |
224 script_promise_resolver->Resolve(ScriptValue::From(script_state, args[0])); | |
225 return true; | 220 return true; |
226 } | 221 } |
227 | 222 |
228 } // namespace | 223 } // namespace |
229 | 224 |
230 void WasmResponseExtensions::Initialize(v8::Isolate* isolate) { | 225 void WasmResponseExtensions::Initialize(v8::Isolate* isolate) { |
231 isolate->SetWasmCompileCallback(WasmCompileOverload); | 226 isolate->SetWasmCompileCallback(WasmCompileOverload); |
232 } | 227 } |
233 | 228 |
234 } // namespace blink | 229 } // namespace blink |
OLD | NEW |