Chromium Code Reviews| 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 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
|
aandrey
2014/02/28 16:08:13
move inside ASSERT:
ASSERT(V8PromiseCustom::getSt
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 389 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); | 389 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); |
| 390 V8PromiseCustom::setState(internal, V8PromiseCustom::Fulfilled, value, isola te); | 390 V8PromiseCustom::setState(promise, V8PromiseCustom::Fulfilled, value, isolat e); |
| 391 propagateToDerived(promise, isolate); | 391 propagateToDerived(promise, isolate); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8: :Value> reason, v8::Isolate* isolate) | 394 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8: :Value> reason, v8::Isolate* isolate) |
| 395 { | 395 { |
| 396 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 396 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
|
aandrey
2014/02/28 16:08:13
ditto
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 397 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); | 397 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); |
| 398 V8PromiseCustom::setState(internal, V8PromiseCustom::Rejected, reason, isola te); | 398 V8PromiseCustom::setState(promise, V8PromiseCustom::Rejected, reason, isolat e); |
| 399 propagateToDerived(promise, isolate); | 399 propagateToDerived(promise, isolate); |
| 400 } | 400 } |
| 401 | 401 |
| 402 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I solate* isolate) | 402 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I solate* isolate) |
| 403 { | 403 { |
| 404 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 404 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
| 405 ASSERT(V8PromiseCustom::getState(internal) == V8PromiseCustom::Fulfilled || V8PromiseCustom::getState(internal) == V8PromiseCustom::Rejected); | 405 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>(); | 406 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>(); | 407 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>(); | 408 v8::Local<v8::Array> derivedPromises = internal->GetInternalField(V8PromiseC ustom::InternalDerivedPromiseIndex).As<v8::Array>(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 } else { | 462 } else { |
| 463 updateDerivedFromValue(derivedPromise, onFulfilled, originatorValue, isolate); | 463 updateDerivedFromValue(derivedPromise, onFulfilled, originatorValue, isolate); |
| 464 } | 464 } |
| 465 } else { | 465 } else { |
| 466 updateDerivedFromReason(derivedPromise, onRejected, originatorValue, iso late); | 466 updateDerivedFromReason(derivedPromise, onRejected, originatorValue, iso late); |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 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) | 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) |
| 471 { | 471 { |
| 472 InspectorInstrumentation::didUpdatePromiseParent(currentExecutionContext(iso late), derivedPromise, promise); | |
|
aandrey
2014/02/28 16:08:13
move to the end of this func
Alexandra Mikhaylova
2014/03/03 14:04:25
Done.
| |
| 472 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); | 473 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
| 473 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); | 474 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); |
| 474 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte d) { | 475 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte d) { |
| 475 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate) ; | 476 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate) ; |
| 476 } else { | 477 } else { |
| 477 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate) ; | 478 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate) ; |
| 478 } | 479 } |
| 479 } | 480 } |
| 480 | 481 |
| 481 } // namespace | 482 } // namespace |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 | 635 |
| 635 // | 636 // |
| 636 // -- V8PromiseCustom -- | 637 // -- V8PromiseCustom -- |
| 637 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) | 638 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) |
| 638 { | 639 { |
| 639 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); | 640 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); |
| 640 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); | 641 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); |
| 641 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); | 642 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); |
| 642 | 643 |
| 643 clearDerived(internal, isolate); | 644 clearDerived(internal, isolate); |
| 644 setState(internal, Pending, v8::Undefined(isolate), isolate); | 645 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); |
| 645 | 646 |
| 646 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); | 647 InspectorInstrumentation::didCreatePromise(currentExecutionContext(isolate), promise, v8::Handle<v8::Object>()); |
|
aandrey
2014/02/28 16:08:13
remove dummy v8::Handle<v8::Object>() argument
Alexandra Mikhaylova
2014/03/03 14:04:25
Removed promise parent argument in didCreatePromis
| |
| 648 | |
| 649 setState(promise, Pending, v8::Undefined(isolate), isolate); | |
| 647 return promise; | 650 return promise; |
| 648 } | 651 } |
| 649 | 652 |
| 650 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) | 653 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) |
| 651 { | 654 { |
| 652 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); | 655 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); |
| 653 return value.As<v8::Object>(); | 656 return value.As<v8::Object>(); |
| 654 } | 657 } |
| 655 | 658 |
| 656 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) | 659 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) |
| 657 { | 660 { |
| 658 v8::Handle<v8::Value> value = internal->GetInternalField(V8PromiseCustom::In ternalStateIndex); | 661 v8::Handle<v8::Value> value = internal->GetInternalField(V8PromiseCustom::In ternalStateIndex); |
| 659 uint32_t number = toInt32(value); | 662 uint32_t number = toInt32(value); |
| 660 ASSERT(number == Pending || number == Fulfilled || number == Rejected || num ber == Following); | 663 ASSERT(number == Pending || number == Fulfilled || number == Rejected || num ber == Following); |
| 661 return static_cast<PromiseState>(number); | 664 return static_cast<PromiseState>(number); |
| 662 } | 665 } |
| 663 | 666 |
| 664 void V8PromiseCustom::setState(v8::Handle<v8::Object> internal, PromiseState sta te, v8::Handle<v8::Value> value, v8::Isolate* isolate) | 667 void V8PromiseCustom::setState(v8::Handle<v8::Object> promise, PromiseState stat e, v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| 665 { | 668 { |
| 666 ASSERT(!value.IsEmpty()); | 669 ASSERT(!value.IsEmpty()); |
| 667 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state == Following); | 670 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state == Following); |
| 671 v8::Local<v8::Object> internal = getInternal(promise); | |
| 668 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta te)); | 672 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta te)); |
| 669 internal->SetInternalField(InternalResultIndex, value); | 673 internal->SetInternalField(InternalResultIndex, value); |
| 674 InspectorInstrumentation::didUpdatePromiseState(currentExecutionContext(isol ate), promise, state, value); | |
| 670 } | 675 } |
| 671 | 676 |
| 672 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate* isolate) | 677 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate* isolate) |
| 673 { | 678 { |
| 674 WrapperWorldType currentWorldType = worldType(isolate); | 679 WrapperWorldType currentWorldType = worldType(isolate); |
| 675 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP romise); | 680 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP romise); |
| 676 } | 681 } |
| 677 | 682 |
| 678 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm ise, v8::Isolate* isolate) | 683 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm ise, v8::Isolate* isolate) |
| 679 { | 684 { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 698 | 703 |
| 699 if (isPromise(result, isolate)) { | 704 if (isPromise(result, isolate)) { |
| 700 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); | 705 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); |
| 701 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); | 706 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); |
| 702 PromiseState valueState = getState(valueInternal); | 707 PromiseState valueState = getState(valueInternal); |
| 703 if (promise->SameValue(valuePromise)) { | 708 if (promise->SameValue(valuePromise)) { |
| 704 v8::Local<v8::Value> reason = V8ThrowException::createTypeError("Res olve a promise with itself", isolate); | 709 v8::Local<v8::Value> reason = V8ThrowException::createTypeError("Res olve a promise with itself", isolate); |
| 705 setReason(promise, reason, isolate); | 710 setReason(promise, reason, isolate); |
| 706 } else if (valueState == Following) { | 711 } else if (valueState == Following) { |
| 707 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte rnalField(InternalResultIndex).As<v8::Object>(); | 712 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte rnalField(InternalResultIndex).As<v8::Object>(); |
| 708 setState(internal, Following, valuePromiseFollowing, isolate); | 713 setState(promise, Following, valuePromiseFollowing, isolate); |
| 709 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); | 714 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); |
| 710 } else if (valueState == Fulfilled) { | 715 } else if (valueState == Fulfilled) { |
| 711 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); | 716 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); |
| 712 } else if (valueState == Rejected) { | 717 } else if (valueState == Rejected) { |
| 713 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); | 718 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); |
| 714 } else { | 719 } else { |
| 715 ASSERT(valueState == Pending); | 720 ASSERT(valueState == Pending); |
| 716 setState(internal, Following, valuePromise, isolate); | 721 setState(promise, Following, valuePromise, isolate); |
| 717 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8: :Handle<v8::Function>(), isolate); | 722 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8: :Handle<v8::Function>(), isolate); |
| 718 } | 723 } |
| 719 } else { | 724 } else { |
| 720 setValue(promise, result, isolate); | 725 setValue(promise, result, isolate); |
| 721 } | 726 } |
| 722 } | 727 } |
| 723 | 728 |
| 724 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu e> reason, v8::Isolate* isolate) | 729 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu e> reason, v8::Isolate* isolate) |
| 725 { | 730 { |
| 726 v8::Local<v8::Object> internal = getInternal(promise); | 731 v8::Local<v8::Object> internal = getInternal(promise); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 | 818 |
| 814 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) | 819 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) |
| 815 { | 820 { |
| 816 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 821 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
| 817 ExecutionContext* executionContext = currentExecutionContext(isolate); | 822 ExecutionContext* executionContext = currentExecutionContext(isolate); |
| 818 ASSERT(executionContext && executionContext->isContextThread()); | 823 ASSERT(executionContext && executionContext->isContextThread()); |
| 819 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); | 824 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); |
| 820 } | 825 } |
| 821 | 826 |
| 822 } // namespace WebCore | 827 } // namespace WebCore |
| OLD | NEW |