OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/v8/custom/V8PromiseCustom.h" | 32 #include "bindings/v8/custom/V8PromiseCustom.h" |
33 | 33 |
34 #include <v8.h> | |
35 #include "V8Promise.h" | 34 #include "V8Promise.h" |
36 #include "bindings/v8/DOMRequestState.h" | 35 #include "bindings/v8/DOMRequestState.h" |
37 #include "bindings/v8/ScopedPersistent.h" | 36 #include "bindings/v8/ScopedPersistent.h" |
38 #include "bindings/v8/ScriptFunctionCall.h" | 37 #include "bindings/v8/ScriptFunctionCall.h" |
39 #include "bindings/v8/ScriptState.h" | 38 #include "bindings/v8/ScriptState.h" |
40 #include "bindings/v8/V8Binding.h" | 39 #include "bindings/v8/V8Binding.h" |
41 #include "bindings/v8/V8PerIsolateData.h" | 40 #include "bindings/v8/V8PerIsolateData.h" |
42 #include "bindings/v8/V8ScriptRunner.h" | 41 #include "bindings/v8/V8ScriptRunner.h" |
43 #include "bindings/v8/WrapperTypeInfo.h" | 42 #include "bindings/v8/WrapperTypeInfo.h" |
44 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
45 #include "core/dom/ExecutionContextTask.h" | 44 #include "core/dom/ExecutionContextTask.h" |
46 #include "core/frame/DOMWindow.h" | 45 #include "core/frame/DOMWindow.h" |
47 #include "core/frame/UseCounter.h" | 46 #include "core/frame/UseCounter.h" |
48 #include "core/inspector/InspectorInstrumentation.h" | 47 #include "core/inspector/InspectorInstrumentation.h" |
49 #include "core/workers/WorkerGlobalScope.h" | 48 #include "core/workers/WorkerGlobalScope.h" |
50 #include "platform/Task.h" | 49 #include "platform/Task.h" |
51 #include "wtf/Deque.h" | 50 #include "wtf/Deque.h" |
52 #include "wtf/Functional.h" | 51 #include "wtf/Functional.h" |
53 #include "wtf/Noncopyable.h" | 52 #include "wtf/Noncopyable.h" |
54 #include "wtf/PassOwnPtr.h" | 53 #include "wtf/PassOwnPtr.h" |
54 #include <v8.h> | |
55 | |
56 #define RETURN_IF_EMPTY(handle, result) \ | |
haraken
2014/02/21 04:19:21
I don't know if this macro is worth adding. We nor
yhirano
2014/02/21 07:32:51
Done.
| |
57 if ((handle).IsEmpty()) { \ | |
58 return (result); \ | |
59 } | |
55 | 60 |
56 namespace WebCore { | 61 namespace WebCore { |
57 | 62 |
58 namespace { | 63 namespace { |
59 | 64 |
60 v8::Local<v8::ObjectTemplate> cachedObjectTemplate(void* domTemplateKey, int int ernalFieldCount, v8::Isolate* isolate) | 65 v8::Local<v8::ObjectTemplate> cachedObjectTemplate(void* domTemplateKey, int int ernalFieldCount, v8::Isolate* isolate) |
61 { | 66 { |
62 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 67 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
63 WrapperWorldType currentWorldType = worldType(isolate); | 68 WrapperWorldType currentWorldType = worldType(isolate); |
64 v8::Handle<v8::FunctionTemplate> functionDescriptor = data->existingDOMTempl ate(currentWorldType, domTemplateKey); | 69 v8::Handle<v8::FunctionTemplate> functionDescriptor = data->existingDOMTempl ate(currentWorldType, domTemplateKey); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 V8PromiseCustom::resolve(promise, results, isolate); | 139 V8PromiseCustom::resolve(promise, results, isolate); |
135 return; | 140 return; |
136 } | 141 } |
137 countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiv eIndex, v8::Integer::New(isolate, countdown->Value() - 1)); | 142 countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiv eIndex, v8::Integer::New(isolate, countdown->Value() - 1)); |
138 } | 143 } |
139 | 144 |
140 v8::Local<v8::Object> promiseAllEnvironment(v8::Handle<v8::Object> promise, v8:: Handle<v8::Object> countdownWrapper, int index, v8::Handle<v8::Array> results, v 8::Isolate* isolate) | 145 v8::Local<v8::Object> promiseAllEnvironment(v8::Handle<v8::Object> promise, v8:: Handle<v8::Object> countdownWrapper, int index, v8::Handle<v8::Array> results, v 8::Isolate* isolate) |
141 { | 146 { |
142 v8::Local<v8::ObjectTemplate> objectTemplate = promiseAllEnvironmentObjectTe mplate(isolate); | 147 v8::Local<v8::ObjectTemplate> objectTemplate = promiseAllEnvironmentObjectTe mplate(isolate); |
143 v8::Local<v8::Object> environment = objectTemplate->NewInstance(); | 148 v8::Local<v8::Object> environment = objectTemplate->NewInstance(); |
149 RETURN_IF_EMPTY(environment, v8::Local<v8::Object>()); | |
144 | 150 |
145 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentPromiseI ndex, promise); | 151 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentPromiseI ndex, promise); |
146 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentCountdow nIndex, countdownWrapper); | 152 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentCountdow nIndex, countdownWrapper); |
147 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentIndexInd ex, v8::Integer::New(isolate, index)); | 153 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentIndexInd ex, v8::Integer::New(isolate, index)); |
148 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentResultsI ndex, results); | 154 environment->SetInternalField(V8PromiseCustom::PromiseAllEnvironmentResultsI ndex, results); |
149 return environment; | 155 return environment; |
150 } | 156 } |
151 | 157 |
152 // Clear |internal|'s derived array. | 158 // Clear |internal|'s derived array. |
153 void clearDerived(v8::Handle<v8::Object> internal, v8::Isolate* isolate) | 159 void clearDerived(v8::Handle<v8::Object> internal, v8::Isolate* isolate) |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 { | 490 { |
485 v8SetReturnValue(info, v8::Local<v8::Value>()); | 491 v8SetReturnValue(info, v8::Local<v8::Value>()); |
486 v8::Isolate* isolate = info.GetIsolate(); | 492 v8::Isolate* isolate = info.GetIsolate(); |
487 ExecutionContext* executionContext = callingExecutionContext(isolate); | 493 ExecutionContext* executionContext = callingExecutionContext(isolate); |
488 UseCounter::count(executionContext, UseCounter::PromiseConstructor); | 494 UseCounter::count(executionContext, UseCounter::PromiseConstructor); |
489 if (!info.Length() || !info[0]->IsFunction()) { | 495 if (!info.Length() || !info[0]->IsFunction()) { |
490 throwTypeError("Promise constructor takes a function argument", isolate) ; | 496 throwTypeError("Promise constructor takes a function argument", isolate) ; |
491 return; | 497 return; |
492 } | 498 } |
493 v8::Local<v8::Function> init = info[0].As<v8::Function>(); | 499 v8::Local<v8::Function> init = info[0].As<v8::Function>(); |
494 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); | 500 V8TRYCATCH_VOID(v8::Local<v8::Object>, promise, V8PromiseCustom::createPromi se(info.Holder(), isolate)); |
495 v8::Handle<v8::Value> argv[] = { | 501 V8TRYCATCH_VOID(v8::Handle<v8::Value>, resolve, createClosure(promiseResolve Callback, promise, isolate)); |
496 createClosure(promiseResolveCallback, promise, isolate), | 502 V8TRYCATCH_VOID(v8::Handle<v8::Value>, reject, createClosure(promiseRejectCa llback, promise, isolate)); |
497 createClosure(promiseRejectCallback, promise, isolate) | 503 v8::Handle<v8::Value> argv[] = { resolve, reject }; |
498 }; | |
499 v8::TryCatch trycatch; | 504 v8::TryCatch trycatch; |
500 if (V8ScriptRunner::callFunction(init, currentExecutionContext(isolate), v8: :Undefined(isolate), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { | 505 if (V8ScriptRunner::callFunction(init, currentExecutionContext(isolate), v8: :Undefined(isolate), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { |
501 // An exception is thrown. Reject the promise if its resolved flag is un set. | 506 // An exception is thrown. Reject the promise if its resolved flag is un set. |
502 V8PromiseCustom::reject(promise, trycatch.Exception(), isolate); | 507 V8PromiseCustom::reject(promise, trycatch.Exception(), isolate); |
503 } | 508 } |
504 v8SetReturnValue(info, promise); | 509 v8SetReturnValue(info, promise); |
505 return; | 510 return; |
506 } | 511 } |
507 | 512 |
508 void V8Promise::thenMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info ) | 513 void V8Promise::thenMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info ) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 | 550 |
546 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo) | 551 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo) |
547 { | 552 { |
548 v8::Isolate* isolate = info.GetIsolate(); | 553 v8::Isolate* isolate = info.GetIsolate(); |
549 ExecutionContext* executionContext = callingExecutionContext(isolate); | 554 ExecutionContext* executionContext = callingExecutionContext(isolate); |
550 UseCounter::count(executionContext, UseCounter::PromiseResolve); | 555 UseCounter::count(executionContext, UseCounter::PromiseResolve); |
551 v8::Local<v8::Value> result = v8::Undefined(isolate); | 556 v8::Local<v8::Value> result = v8::Undefined(isolate); |
552 if (info.Length() > 0) | 557 if (info.Length() > 0) |
553 result = info[0]; | 558 result = info[0]; |
554 | 559 |
555 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); | 560 V8TRYCATCH_VOID(v8::Local<v8::Object>, promise, V8PromiseCustom::createPromi se(info.Holder(), isolate)); |
556 V8PromiseCustom::resolve(promise, result, isolate); | 561 V8PromiseCustom::resolve(promise, result, isolate); |
557 v8SetReturnValue(info, promise); | 562 v8SetReturnValue(info, promise); |
558 } | 563 } |
559 | 564 |
560 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in fo) | 565 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& in fo) |
561 { | 566 { |
562 v8::Isolate* isolate = info.GetIsolate(); | 567 v8::Isolate* isolate = info.GetIsolate(); |
563 ExecutionContext* executionContext = callingExecutionContext(isolate); | 568 ExecutionContext* executionContext = callingExecutionContext(isolate); |
564 UseCounter::count(executionContext, UseCounter::PromiseReject); | 569 UseCounter::count(executionContext, UseCounter::PromiseReject); |
565 v8::Local<v8::Value> result = v8::Undefined(isolate); | 570 v8::Local<v8::Value> result = v8::Undefined(isolate); |
566 if (info.Length() > 0) | 571 if (info.Length() > 0) |
567 result = info[0]; | 572 result = info[0]; |
568 | 573 |
569 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); | 574 V8TRYCATCH_VOID(v8::Local<v8::Object>, promise, V8PromiseCustom::createPromi se(info.Holder(), isolate)); |
570 V8PromiseCustom::reject(promise, result, isolate); | 575 V8PromiseCustom::reject(promise, result, isolate); |
571 v8SetReturnValue(info, promise); | 576 v8SetReturnValue(info, promise); |
572 } | 577 } |
573 | 578 |
574 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info ) | 579 void V8Promise::raceMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info ) |
575 { | 580 { |
576 v8::Isolate* isolate = info.GetIsolate(); | 581 v8::Isolate* isolate = info.GetIsolate(); |
577 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); | 582 V8TRYCATCH_VOID(v8::Local<v8::Object>, promise, V8PromiseCustom::createPromi se(info.Holder(), isolate)); |
578 | 583 |
579 if (!info.Length() || !info[0]->IsArray()) { | 584 if (!info.Length() || !info[0]->IsArray()) { |
580 v8SetReturnValue(info, promise); | 585 v8SetReturnValue(info, promise); |
581 return; | 586 return; |
582 } | 587 } |
583 | 588 |
584 // FIXME: Now we limit the iterable type to the Array type. | 589 // FIXME: Now we limit the iterable type to the Array type. |
585 v8::Local<v8::Array> iterable = info[0].As<v8::Array>(); | 590 v8::Local<v8::Array> iterable = info[0].As<v8::Array>(); |
586 v8::Local<v8::Function> onFulfilled = createClosure(promiseResolveCallback, promise, isolate); | 591 V8TRYCATCH_VOID(v8::Local<v8::Function>, onFulfilled, createClosure(promiseR esolveCallback, promise, isolate)); |
587 v8::Local<v8::Function> onRejected = createClosure(promiseRejectCallback, pr omise, isolate); | 592 V8TRYCATCH_VOID(v8::Local<v8::Function>, onRejected, createClosure(promiseRe jectCallback, promise, isolate)); |
588 | 593 |
589 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { | 594 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { |
590 // Array-holes should not be skipped by for-of iteration semantics. | 595 // Array-holes should not be skipped by for-of iteration semantics. |
591 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); | 596 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); |
592 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue , isolate); | 597 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue , isolate); |
593 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); | 598 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); |
594 } | 599 } |
595 v8SetReturnValue(info, promise); | 600 v8SetReturnValue(info, promise); |
596 } | 601 } |
597 | 602 |
598 void V8Promise::allMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 603 void V8Promise::allMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
599 { | 604 { |
600 v8::Isolate* isolate = info.GetIsolate(); | 605 v8::Isolate* isolate = info.GetIsolate(); |
601 v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(info.Holder() , isolate); | 606 V8TRYCATCH_VOID(v8::Local<v8::Object>, promise, V8PromiseCustom::createPromi se(info.Holder(), isolate)); |
602 v8::Local<v8::Array> results = v8::Array::New(info.GetIsolate()); | 607 v8::Local<v8::Array> results = v8::Array::New(info.GetIsolate()); |
603 | 608 |
604 if (!info.Length() || !info[0]->IsArray()) { | 609 if (!info.Length() || !info[0]->IsArray()) { |
605 V8PromiseCustom::resolve(promise, results, isolate); | 610 V8PromiseCustom::resolve(promise, results, isolate); |
606 v8SetReturnValue(info, promise); | 611 v8SetReturnValue(info, promise); |
607 return; | 612 return; |
608 } | 613 } |
609 | 614 |
610 // FIXME: Now we limit the iterable type to the Array type. | 615 // FIXME: Now we limit the iterable type to the Array type. |
611 v8::Local<v8::Array> iterable = info[0].As<v8::Array>(); | 616 v8::Local<v8::Array> iterable = info[0].As<v8::Array>(); |
612 | 617 |
613 if (!iterable->Length()) { | 618 if (!iterable->Length()) { |
614 V8PromiseCustom::resolve(promise, results, isolate); | 619 V8PromiseCustom::resolve(promise, results, isolate); |
615 v8SetReturnValue(info, promise); | 620 v8SetReturnValue(info, promise); |
616 return; | 621 return; |
617 } | 622 } |
618 | 623 |
619 v8::Local<v8::ObjectTemplate> objectTemplate = primitiveWrapperObjectTemplat e(isolate); | 624 v8::Local<v8::ObjectTemplate> objectTemplate = primitiveWrapperObjectTemplat e(isolate); |
620 v8::Local<v8::Object> countdownWrapper = objectTemplate->NewInstance(); | 625 V8TRYCATCH_VOID(v8::Local<v8::Object>, countdownWrapper, objectTemplate->New Instance()); |
621 countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiv eIndex, v8::Integer::New(isolate, iterable->Length())); | 626 countdownWrapper->SetInternalField(V8PromiseCustom::PrimitiveWrapperPrimitiv eIndex, v8::Integer::New(isolate, iterable->Length())); |
622 | 627 |
623 v8::Local<v8::Function> onRejected = createClosure(promiseRejectCallback, pr omise, isolate); | 628 V8TRYCATCH_VOID(v8::Local<v8::Function>, onRejected, createClosure(promiseRe jectCallback, promise, isolate)); |
624 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { | 629 for (unsigned i = 0, length = iterable->Length(); i < length; ++i) { |
625 // Array-holes should not be skipped by for-of iteration semantics. | 630 // Array-holes should not be skipped by for-of iteration semantics. |
626 v8::Local<v8::Object> environment = promiseAllEnvironment(promise, count downWrapper, i, results, isolate); | 631 V8TRYCATCH_VOID(v8::Local<v8::Object>, environment, promiseAllEnvironmen t(promise, countdownWrapper, i, results, isolate)); |
627 v8::Local<v8::Function> onFulfilled = createClosure(promiseAllFulfillCal lback, environment, isolate); | 632 V8TRYCATCH_VOID(v8::Local<v8::Function>, onFulfilled, createClosure(prom iseAllFulfillCallback, environment, isolate)); |
628 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); | 633 V8TRYCATCH_VOID(v8::Local<v8::Value>, nextValue, iterable->Get(i)); |
629 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue , isolate); | 634 v8::Local<v8::Object> nextPromise = V8PromiseCustom::toPromise(nextValue , isolate); |
630 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); | 635 V8PromiseCustom::then(nextPromise, onFulfilled, onRejected, isolate); |
631 } | 636 } |
632 v8SetReturnValue(info, promise); | 637 v8SetReturnValue(info, promise); |
633 } | 638 } |
634 | 639 |
635 // | 640 // |
636 // -- V8PromiseCustom -- | 641 // -- V8PromiseCustom -- |
637 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) | 642 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) |
638 { | 643 { |
639 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); | 644 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); |
640 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); | 645 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); |
646 RETURN_IF_EMPTY(internal, v8::Local<v8::Object>()); | |
641 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); | 647 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); |
642 | 648 |
643 clearDerived(internal, isolate); | 649 clearDerived(internal, isolate); |
644 setState(internal, Pending, v8::Undefined(isolate), isolate); | 650 setState(internal, Pending, v8::Undefined(isolate), isolate); |
645 | 651 |
646 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); | 652 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); |
647 return promise; | 653 return promise; |
648 } | 654 } |
649 | 655 |
650 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) | 656 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 PromisePropagator propagator; | 798 PromisePropagator propagator; |
793 propagator.updateDerivedFromPromise(derivedPromise, onFulfilled, onRejected, promise, isolate); | 799 propagator.updateDerivedFromPromise(derivedPromise, onFulfilled, onRejected, promise, isolate); |
794 propagator.performPropagation(isolate); | 800 propagator.performPropagation(isolate); |
795 } | 801 } |
796 | 802 |
797 v8::Local<v8::Object> V8PromiseCustom::coerceThenable(v8::Handle<v8::Object> the nable, v8::Handle<v8::Function> then, v8::Isolate* isolate) | 803 v8::Local<v8::Object> V8PromiseCustom::coerceThenable(v8::Handle<v8::Object> the nable, v8::Handle<v8::Function> then, v8::Isolate* isolate) |
798 { | 804 { |
799 ASSERT(!thenable.IsEmpty()); | 805 ASSERT(!thenable.IsEmpty()); |
800 ASSERT(!then.IsEmpty()); | 806 ASSERT(!then.IsEmpty()); |
801 v8::Local<v8::Object> promise = createPromise(v8::Handle<v8::Object>(), isol ate); | 807 v8::Local<v8::Object> promise = createPromise(v8::Handle<v8::Object>(), isol ate); |
802 v8::Handle<v8::Value> argv[] = { | 808 v8::Handle<v8::Value> onFulfilled = createClosure(promiseResolveCallback, pr omise, isolate); |
803 createClosure(promiseResolveCallback, promise, isolate), | 809 RETURN_IF_EMPTY(onFulfilled, v8::Local<v8::Object>()); |
804 createClosure(promiseRejectCallback, promise, isolate) | 810 v8::Handle<v8::Value> onRejected = createClosure(promiseRejectCallback, prom ise, isolate); |
805 }; | 811 RETURN_IF_EMPTY(onRejected, v8::Local<v8::Object>()); |
812 v8::Handle<v8::Value> argv[] = { onFulfilled, onRejected }; | |
813 | |
806 v8::TryCatch trycatch; | 814 v8::TryCatch trycatch; |
807 if (V8ScriptRunner::callFunction(then, currentExecutionContext(isolate), the nable, WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { | 815 if (V8ScriptRunner::callFunction(then, currentExecutionContext(isolate), the nable, WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { |
808 reject(promise, trycatch.Exception(), isolate); | 816 reject(promise, trycatch.Exception(), isolate); |
809 } | 817 } |
810 setHiddenValue(isolate, thenable, "thenableHiddenPromise", promise); | 818 setHiddenValue(isolate, thenable, "thenableHiddenPromise", promise); |
811 return promise; | 819 return promise; |
812 } | 820 } |
813 | 821 |
814 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) | 822 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) |
815 { | 823 { |
816 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 824 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
817 ExecutionContext* executionContext = currentExecutionContext(isolate); | 825 ExecutionContext* executionContext = currentExecutionContext(isolate); |
818 ASSERT(executionContext && executionContext->isContextThread()); | 826 ASSERT(executionContext && executionContext->isContextThread()); |
819 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); | 827 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); |
820 } | 828 } |
821 | 829 |
822 } // namespace WebCore | 830 } // namespace WebCore |
OLD | NEW |