| 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 27 matching lines...) Expand all Loading... |
| 38 #include "bindings/v8/ScriptFunctionCall.h" | 38 #include "bindings/v8/ScriptFunctionCall.h" |
| 39 #include "bindings/v8/ScriptState.h" | 39 #include "bindings/v8/ScriptState.h" |
| 40 #include "bindings/v8/V8Binding.h" | 40 #include "bindings/v8/V8Binding.h" |
| 41 #include "bindings/v8/V8PerIsolateData.h" | 41 #include "bindings/v8/V8PerIsolateData.h" |
| 42 #include "bindings/v8/V8ScriptRunner.h" | 42 #include "bindings/v8/V8ScriptRunner.h" |
| 43 #include "bindings/v8/WrapperTypeInfo.h" | 43 #include "bindings/v8/WrapperTypeInfo.h" |
| 44 #include "core/dom/Document.h" | 44 #include "core/dom/Document.h" |
| 45 #include "core/dom/ExecutionContextTask.h" | 45 #include "core/dom/ExecutionContextTask.h" |
| 46 #include "core/frame/DOMWindow.h" | 46 #include "core/frame/DOMWindow.h" |
| 47 #include "core/frame/UseCounter.h" | 47 #include "core/frame/UseCounter.h" |
| 48 #include "core/inspector/InspectorInstrumentation.h" | 48 #include "core/inspector/InspectorPromiseInstrumentation.h" |
| 49 #include "core/workers/WorkerGlobalScope.h" | 49 #include "core/workers/WorkerGlobalScope.h" |
| 50 #include "platform/Task.h" | 50 #include "platform/Task.h" |
| 51 #include "wtf/Deque.h" | 51 #include "wtf/Deque.h" |
| 52 #include "wtf/Functional.h" | 52 #include "wtf/Functional.h" |
| 53 #include "wtf/Noncopyable.h" | 53 #include "wtf/Noncopyable.h" |
| 54 #include "wtf/PassOwnPtr.h" | 54 #include "wtf/PassOwnPtr.h" |
| 55 | 55 |
| 56 namespace WebCore { | 56 namespace WebCore { |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 { | 378 { |
| 379 while (!m_derivedStack.isEmpty()) { | 379 while (!m_derivedStack.isEmpty()) { |
| 380 v8::HandleScope handleScope(isolate); | 380 v8::HandleScope handleScope(isolate); |
| 381 OwnPtr<Derived> derived = m_derivedStack.takeLast(); | 381 OwnPtr<Derived> derived = m_derivedStack.takeLast(); |
| 382 updateDerived(derived->promise(isolate), derived->onFulfilled(isolate),
derived->onRejected(isolate), derived->originator(isolate), isolate); | 382 updateDerived(derived->promise(isolate), derived->onFulfilled(isolate),
derived->onRejected(isolate), derived->originator(isolate), isolate); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 void PromisePropagator::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8::
Value> value, v8::Isolate* isolate) | 386 void PromisePropagator::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8::
Value> value, v8::Isolate* isolate) |
| 387 { | 387 { |
| 388 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 388 ASSERT(getState(V8PromiseCustom::getInternal(promise)) != V8PromiseCustom::F
ulfilled && getState(V8PromiseCustom::getInternal(promise)) != V8PromiseCustom::
Rejected); |
| 389 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled &&
V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); | 389 V8PromiseCustom::setState(promise, V8PromiseCustom::Fulfilled, value, isolat
e); |
| 390 V8PromiseCustom::setState(internal, V8PromiseCustom::Fulfilled, value, isola
te); | |
| 391 propagateToDerived(promise, isolate); | 390 propagateToDerived(promise, isolate); |
| 392 } | 391 } |
| 393 | 392 |
| 394 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Value> reason, v8::Isolate* isolate) | 393 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Value> reason, v8::Isolate* isolate) |
| 395 { | 394 { |
| 396 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 395 ASSERT(getState(V8PromiseCustom::getInternal(promise)) != V8PromiseCustom::F
ulfilled && getState(V8PromiseCustom::getInternal(promise)) != V8PromiseCustom::
Rejected); |
| 397 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled &&
V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); | 396 V8PromiseCustom::setState(promise, V8PromiseCustom::Rejected, reason, isolat
e); |
| 398 V8PromiseCustom::setState(internal, V8PromiseCustom::Rejected, reason, isola
te); | |
| 399 propagateToDerived(promise, isolate); | 397 propagateToDerived(promise, isolate); |
| 400 } | 398 } |
| 401 | 399 |
| 402 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I
solate* isolate) | 400 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I
solate* isolate) |
| 403 { | 401 { |
| 404 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 402 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
| 405 ASSERT(V8PromiseCustom::getState(internal) == V8PromiseCustom::Fulfilled ||
V8PromiseCustom::getState(internal) == V8PromiseCustom::Rejected); | 403 ASSERT(V8PromiseCustom::getState(internal) == V8PromiseCustom::Fulfilled ||
V8PromiseCustom::getState(internal) == V8PromiseCustom::Rejected); |
| 406 v8::Local<v8::Array> fulfillCallbacks = internal->GetInternalField(V8Promise
Custom::InternalFulfillCallbackIndex).As<v8::Array>(); | 404 v8::Local<v8::Array> fulfillCallbacks = internal->GetInternalField(V8Promise
Custom::InternalFulfillCallbackIndex).As<v8::Array>(); |
| 407 v8::Local<v8::Array> rejectCallbacks = internal->GetInternalField(V8PromiseC
ustom::InternalRejectCallbackIndex).As<v8::Array>(); | 405 v8::Local<v8::Array> rejectCallbacks = internal->GetInternalField(V8PromiseC
ustom::InternalRejectCallbackIndex).As<v8::Array>(); |
| 408 v8::Local<v8::Array> derivedPromises = internal->GetInternalField(V8PromiseC
ustom::InternalDerivedPromiseIndex).As<v8::Array>(); | 406 v8::Local<v8::Array> derivedPromises = internal->GetInternalField(V8PromiseC
ustom::InternalDerivedPromiseIndex).As<v8::Array>(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 467 |
| 470 void PromisePropagator::updateDerivedFromPromise(v8::Handle<v8::Object> derivedP
romise, v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Function> onRejecte
d, v8::Handle<v8::Object> promise, v8::Isolate* isolate) | 468 void PromisePropagator::updateDerivedFromPromise(v8::Handle<v8::Object> derivedP
romise, v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Function> onRejecte
d, v8::Handle<v8::Object> promise, v8::Isolate* isolate) |
| 471 { | 469 { |
| 472 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 470 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
| 473 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); | 471 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); |
| 474 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte
d) { | 472 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte
d) { |
| 475 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate)
; | 473 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate)
; |
| 476 } else { | 474 } else { |
| 477 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate)
; | 475 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate)
; |
| 478 } | 476 } |
| 477 InspectorInstrumentation::didUpdatePromiseParent(currentExecutionContext(iso
late), derivedPromise, promise); |
| 479 } | 478 } |
| 480 | 479 |
| 481 } // namespace | 480 } // namespace |
| 482 | 481 |
| 483 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) | 482 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
o) |
| 484 { | 483 { |
| 485 v8SetReturnValue(info, v8::Local<v8::Value>()); | 484 v8SetReturnValue(info, v8::Local<v8::Value>()); |
| 486 v8::Isolate* isolate = info.GetIsolate(); | 485 v8::Isolate* isolate = info.GetIsolate(); |
| 487 ExecutionContext* executionContext = callingExecutionContext(isolate); | 486 ExecutionContext* executionContext = callingExecutionContext(isolate); |
| 488 UseCounter::count(executionContext, UseCounter::PromiseConstructor); | 487 UseCounter::count(executionContext, UseCounter::PromiseConstructor); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 633 |
| 635 // | 634 // |
| 636 // -- V8PromiseCustom -- | 635 // -- V8PromiseCustom -- |
| 637 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea
tionContext, v8::Isolate* isolate) | 636 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea
tionContext, v8::Isolate* isolate) |
| 638 { | 637 { |
| 639 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol
ate); | 638 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol
ate); |
| 640 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); | 639 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); |
| 641 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext,
&V8Promise::wrapperTypeInfo, 0, isolate); | 640 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext,
&V8Promise::wrapperTypeInfo, 0, isolate); |
| 642 | 641 |
| 643 clearDerived(internal, isolate); | 642 clearDerived(internal, isolate); |
| 644 setState(internal, Pending, v8::Undefined(isolate), isolate); | 643 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); |
| 645 | 644 |
| 646 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); | 645 InspectorInstrumentation::didCreatePromise(currentExecutionContext(isolate),
promise); |
| 646 |
| 647 setState(promise, Pending, v8::Undefined(isolate), isolate); |
| 647 return promise; | 648 return promise; |
| 648 } | 649 } |
| 649 | 650 |
| 650 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis
e) | 651 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis
e) |
| 651 { | 652 { |
| 652 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd
ex); | 653 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd
ex); |
| 653 return value.As<v8::Object>(); | 654 return value.As<v8::Object>(); |
| 654 } | 655 } |
| 655 | 656 |
| 656 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i
nternal) | 657 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i
nternal) |
| 657 { | 658 { |
| 658 v8::Handle<v8::Value> value = internal->GetInternalField(V8PromiseCustom::In
ternalStateIndex); | 659 v8::Handle<v8::Value> value = internal->GetInternalField(V8PromiseCustom::In
ternalStateIndex); |
| 659 uint32_t number = toInt32(value); | 660 uint32_t number = toInt32(value); |
| 660 ASSERT(number == Pending || number == Fulfilled || number == Rejected || num
ber == Following); | 661 ASSERT(number == Pending || number == Fulfilled || number == Rejected || num
ber == Following); |
| 661 return static_cast<PromiseState>(number); | 662 return static_cast<PromiseState>(number); |
| 662 } | 663 } |
| 663 | 664 |
| 664 void V8PromiseCustom::setState(v8::Handle<v8::Object> internal, PromiseState sta
te, v8::Handle<v8::Value> value, v8::Isolate* isolate) | 665 void V8PromiseCustom::setState(v8::Handle<v8::Object> promise, PromiseState stat
e, v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| 665 { | 666 { |
| 666 ASSERT(!value.IsEmpty()); | 667 ASSERT(!value.IsEmpty()); |
| 667 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state
== Following); | 668 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state
== Following); |
| 669 v8::Local<v8::Object> internal = getInternal(promise); |
| 668 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta
te)); | 670 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta
te)); |
| 669 internal->SetInternalField(InternalResultIndex, value); | 671 internal->SetInternalField(InternalResultIndex, value); |
| 672 InspectorInstrumentation::didUpdatePromiseState(currentExecutionContext(isol
ate), promise, state, value); |
| 670 } | 673 } |
| 671 | 674 |
| 672 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate*
isolate) | 675 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate*
isolate) |
| 673 { | 676 { |
| 674 WrapperWorldType currentWorldType = worldType(isolate); | 677 WrapperWorldType currentWorldType = worldType(isolate); |
| 675 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP
romise); | 678 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP
romise); |
| 676 } | 679 } |
| 677 | 680 |
| 678 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm
ise, v8::Isolate* isolate) | 681 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm
ise, v8::Isolate* isolate) |
| 679 { | 682 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 698 | 701 |
| 699 if (isPromise(result, isolate)) { | 702 if (isPromise(result, isolate)) { |
| 700 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); | 703 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); |
| 701 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); | 704 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); |
| 702 PromiseState valueState = getState(valueInternal); | 705 PromiseState valueState = getState(valueInternal); |
| 703 if (promise->SameValue(valuePromise)) { | 706 if (promise->SameValue(valuePromise)) { |
| 704 v8::Local<v8::Value> reason = V8ThrowException::createTypeError("Res
olve a promise with itself", isolate); | 707 v8::Local<v8::Value> reason = V8ThrowException::createTypeError("Res
olve a promise with itself", isolate); |
| 705 setReason(promise, reason, isolate); | 708 setReason(promise, reason, isolate); |
| 706 } else if (valueState == Following) { | 709 } else if (valueState == Following) { |
| 707 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte
rnalField(InternalResultIndex).As<v8::Object>(); | 710 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte
rnalField(InternalResultIndex).As<v8::Object>(); |
| 708 setState(internal, Following, valuePromiseFollowing, isolate); | 711 setState(promise, Following, valuePromiseFollowing, isolate); |
| 709 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle
<v8::Function>(), v8::Handle<v8::Function>(), isolate); | 712 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle
<v8::Function>(), v8::Handle<v8::Function>(), isolate); |
| 710 } else if (valueState == Fulfilled) { | 713 } else if (valueState == Fulfilled) { |
| 711 setValue(promise, valueInternal->GetInternalField(InternalResultInde
x), isolate); | 714 setValue(promise, valueInternal->GetInternalField(InternalResultInde
x), isolate); |
| 712 } else if (valueState == Rejected) { | 715 } else if (valueState == Rejected) { |
| 713 setReason(promise, valueInternal->GetInternalField(InternalResultInd
ex), isolate); | 716 setReason(promise, valueInternal->GetInternalField(InternalResultInd
ex), isolate); |
| 714 } else { | 717 } else { |
| 715 ASSERT(valueState == Pending); | 718 ASSERT(valueState == Pending); |
| 716 setState(internal, Following, valuePromise, isolate); | 719 setState(promise, Following, valuePromise, isolate); |
| 717 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8:
:Handle<v8::Function>(), isolate); | 720 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8:
:Handle<v8::Function>(), isolate); |
| 718 } | 721 } |
| 719 } else { | 722 } else { |
| 720 setValue(promise, result, isolate); | 723 setValue(promise, result, isolate); |
| 721 } | 724 } |
| 722 } | 725 } |
| 723 | 726 |
| 724 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu
e> reason, v8::Isolate* isolate) | 727 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu
e> reason, v8::Isolate* isolate) |
| 725 { | 728 { |
| 726 v8::Local<v8::Object> internal = getInternal(promise); | 729 v8::Local<v8::Object> internal = getInternal(promise); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 816 |
| 814 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) |
| 815 { | 818 { |
| 816 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 819 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
| 817 ExecutionContext* executionContext = currentExecutionContext(isolate); | 820 ExecutionContext* executionContext = currentExecutionContext(isolate); |
| 818 ASSERT(executionContext && executionContext->isContextThread()); | 821 ASSERT(executionContext && executionContext->isContextThread()); |
| 819 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))); |
| 820 } | 823 } |
| 821 | 824 |
| 822 } // namespace WebCore | 825 } // namespace WebCore |
| OLD | NEW |