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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 OwnPtr<Derived> derived = m_derivedStack.takeLast(); | 383 OwnPtr<Derived> derived = m_derivedStack.takeLast(); |
384 updateDerived(derived->promise(isolate), derived->onFulfilled(isolate), derived->onRejected(isolate), derived->originator(isolate), isolate); | 384 updateDerived(derived->promise(isolate), derived->onFulfilled(isolate), derived->onRejected(isolate), derived->originator(isolate), isolate); |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 void PromisePropagator::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8:: Value> value, v8::Isolate* isolate) | 388 void PromisePropagator::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8:: Value> value, v8::Isolate* isolate) |
389 { | 389 { |
390 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 390 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
391 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); | 391 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); |
392 V8PromiseCustom::setState(internal, V8PromiseCustom::Fulfilled, value, isola te); | 392 V8PromiseCustom::setState(internal, V8PromiseCustom::Fulfilled, value, isola te); |
393 InspectorInstrumentation::updatePromiseState(currentExecutionContext(isolate ), promise, V8PromiseCustom::Fulfilled); | |
aandrey
2014/02/25 12:36:07
move inside V8PromiseCustom::setState
Alexandra Mikhaylova
2014/02/26 14:08:41
It seems that we can't move the instrumentation in
aandrey
2014/02/26 16:17:42
make V8PromiseCustom::setState accept a promise
Alexandra Mikhaylova
2014/02/28 13:52:05
Done.
| |
393 propagateToDerived(promise, isolate); | 394 propagateToDerived(promise, isolate); |
394 } | 395 } |
395 | 396 |
396 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8: :Value> reason, v8::Isolate* isolate) | 397 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8: :Value> reason, v8::Isolate* isolate) |
397 { | 398 { |
398 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 399 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
399 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); | 400 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); |
400 V8PromiseCustom::setState(internal, V8PromiseCustom::Rejected, reason, isola te); | 401 V8PromiseCustom::setState(internal, V8PromiseCustom::Rejected, reason, isola te); |
402 InspectorInstrumentation::updatePromiseState(currentExecutionContext(isolate ), promise, V8PromiseCustom::Rejected); | |
aandrey
2014/02/25 12:36:07
ditto
Alexandra Mikhaylova
2014/02/26 14:08:41
see above
| |
401 propagateToDerived(promise, isolate); | 403 propagateToDerived(promise, isolate); |
402 } | 404 } |
403 | 405 |
404 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I solate* isolate) | 406 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I solate* isolate) |
405 { | 407 { |
406 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 408 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
407 ASSERT(V8PromiseCustom::getState(internal) == V8PromiseCustom::Fulfilled || V8PromiseCustom::getState(internal) == V8PromiseCustom::Rejected); | 409 ASSERT(V8PromiseCustom::getState(internal) == V8PromiseCustom::Fulfilled || V8PromiseCustom::getState(internal) == V8PromiseCustom::Rejected); |
408 v8::Local<v8::Array> fulfillCallbacks = internal->GetInternalField(V8Promise Custom::InternalFulfillCallbackIndex).As<v8::Array>(); | 410 v8::Local<v8::Array> fulfillCallbacks = internal->GetInternalField(V8Promise Custom::InternalFulfillCallbackIndex).As<v8::Array>(); |
409 v8::Local<v8::Array> rejectCallbacks = internal->GetInternalField(V8PromiseC ustom::InternalRejectCallbackIndex).As<v8::Array>(); | 411 v8::Local<v8::Array> rejectCallbacks = internal->GetInternalField(V8PromiseC ustom::InternalRejectCallbackIndex).As<v8::Array>(); |
410 v8::Local<v8::Array> derivedPromises = internal->GetInternalField(V8PromiseC ustom::InternalDerivedPromiseIndex).As<v8::Array>(); | 412 v8::Local<v8::Array> derivedPromises = internal->GetInternalField(V8PromiseC ustom::InternalDerivedPromiseIndex).As<v8::Array>(); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) | 633 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) |
632 { | 634 { |
633 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); | 635 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); |
634 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); | 636 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); |
635 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); | 637 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); |
636 | 638 |
637 clearDerived(internal, isolate); | 639 clearDerived(internal, isolate); |
638 setState(internal, Pending, v8::Undefined(isolate), isolate); | 640 setState(internal, Pending, v8::Undefined(isolate), isolate); |
639 | 641 |
640 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); | 642 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); |
643 | |
644 InspectorInstrumentation::addPromise(currentExecutionContext(isolate), | |
aandrey
2014/02/25 12:36:07
one line
Alexandra Mikhaylova
2014/02/26 14:08:41
Done.
| |
645 promise, | |
646 v8::Handle<v8::Object>::Cast(v8::Null(i solate)), | |
aandrey
2014/02/25 12:36:07
v8::Handle<v8::Object>()
Alexandra Mikhaylova
2014/02/26 14:08:41
Done.
| |
647 Pending); | |
aandrey
2014/02/25 12:36:07
remove Pending, move up before setState()
Alexandra Mikhaylova
2014/02/26 14:08:41
Done.
| |
648 | |
641 return promise; | 649 return promise; |
642 } | 650 } |
643 | 651 |
644 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) | 652 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) |
645 { | 653 { |
646 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); | 654 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); |
647 return value.As<v8::Object>(); | 655 return value.As<v8::Object>(); |
648 } | 656 } |
649 | 657 |
650 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) | 658 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 } else if (valueState == Following) { | 708 } else if (valueState == Following) { |
701 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte rnalField(InternalResultIndex).As<v8::Object>(); | 709 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte rnalField(InternalResultIndex).As<v8::Object>(); |
702 setState(internal, Following, valuePromiseFollowing, isolate); | 710 setState(internal, Following, valuePromiseFollowing, isolate); |
703 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); | 711 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); |
704 } else if (valueState == Fulfilled) { | 712 } else if (valueState == Fulfilled) { |
705 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); | 713 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); |
706 } else if (valueState == Rejected) { | 714 } else if (valueState == Rejected) { |
707 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); | 715 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); |
708 } else { | 716 } else { |
709 ASSERT(valueState == Pending); | 717 ASSERT(valueState == Pending); |
710 setState(internal, Following, valuePromise, isolate); | 718 setState(internal, Following, valuePromise, isolate); // TODO: how c an we track the Following state? |
aandrey
2014/02/25 12:36:07
remove todo
Alexandra Mikhaylova
2014/02/26 14:08:41
Done.
| |
711 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8: :Handle<v8::Function>(), isolate); | 719 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8: :Handle<v8::Function>(), isolate); |
712 } | 720 } |
713 } else { | 721 } else { |
714 setValue(promise, result, isolate); | 722 setValue(promise, result, isolate); |
715 } | 723 } |
716 } | 724 } |
717 | 725 |
718 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu e> reason, v8::Isolate* isolate) | 726 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu e> reason, v8::Isolate* isolate) |
719 { | 727 { |
720 v8::Local<v8::Object> internal = getInternal(promise); | 728 v8::Local<v8::Object> internal = getInternal(promise); |
721 PromiseState state = getState(internal); | 729 PromiseState state = getState(internal); |
722 if (state != Pending) | 730 if (state != Pending) |
723 return; | 731 return; |
724 setReason(promise, reason, isolate); | 732 setReason(promise, reason, isolate); |
725 } | 733 } |
726 | 734 |
727 v8::Local<v8::Object> V8PromiseCustom::then(v8::Handle<v8::Object> promise, v8:: Handle<v8::Function> onFulfilled, v8::Handle<v8::Function> onRejected, v8::Isola te* isolate) | 735 v8::Local<v8::Object> V8PromiseCustom::then(v8::Handle<v8::Object> promise, v8:: Handle<v8::Function> onFulfilled, v8::Handle<v8::Function> onRejected, v8::Isola te* isolate) |
728 { | 736 { |
729 v8::Handle<v8::Object> internal = getInternal(promise); | 737 v8::Handle<v8::Object> internal = getInternal(promise); |
730 while (getState(internal) == Following) { | 738 while (getState(internal) == Following) { |
731 promise = internal->GetInternalField(InternalResultIndex).As<v8::Object> (); | 739 promise = internal->GetInternalField(InternalResultIndex).As<v8::Object> (); |
732 internal = getInternal(promise); | 740 internal = getInternal(promise); |
733 } | 741 } |
734 // FIXME: Currently we don't lookup "constructor" property since we limit | 742 // FIXME: Currently we don't lookup "constructor" property since we limit |
735 // the creation of the promise objects only from the Blink Promise | 743 // the creation of the promise objects only from the Blink Promise |
736 // constructor. | 744 // constructor. |
737 v8::Local<v8::Object> derivedPromise = createPromise(v8::Handle<v8::Object>( ), isolate); | 745 v8::Local<v8::Object> derivedPromise = createPromise(v8::Handle<v8::Object>( ), isolate); |
746 InspectorInstrumentation::updatePromiseParent(currentExecutionContext(isolat e), derivedPromise, promise); | |
aandrey
2014/02/25 12:36:07
move inside updateDerivedFromPromise()
Alexandra Mikhaylova
2014/02/26 14:08:41
Done.
| |
738 updateDerivedFromPromise(derivedPromise, onFulfilled, onRejected, promise, i solate); | 747 updateDerivedFromPromise(derivedPromise, onFulfilled, onRejected, promise, i solate); |
739 return derivedPromise; | 748 return derivedPromise; |
740 } | 749 } |
741 | 750 |
742 void V8PromiseCustom::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8::Va lue> value, v8::Isolate* isolate) | 751 void V8PromiseCustom::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8::Va lue> value, v8::Isolate* isolate) |
743 { | 752 { |
744 PromisePropagator propagator; | 753 PromisePropagator propagator; |
745 propagator.setValue(promise, value, isolate); | 754 propagator.setValue(promise, value, isolate); |
746 propagator.performPropagation(isolate); | 755 propagator.performPropagation(isolate); |
747 } | 756 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 | 816 |
808 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) | 817 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) |
809 { | 818 { |
810 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 819 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
811 ExecutionContext* executionContext = currentExecutionContext(isolate); | 820 ExecutionContext* executionContext = currentExecutionContext(isolate); |
812 ASSERT(executionContext && executionContext->isContextThread()); | 821 ASSERT(executionContext && executionContext->isContextThread()); |
813 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); | 822 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); |
814 } | 823 } |
815 | 824 |
816 } // namespace WebCore | 825 } // namespace WebCore |
OLD | NEW |