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 ASSERT(V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise)) != V 8PromiseCustom::Fulfilled && V8PromiseCustom::getState(V8PromiseCustom::getInter nal(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(V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise)) != V 8PromiseCustom::Fulfilled && V8PromiseCustom::getState(V8PromiseCustom::getInter nal(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 ExecutionContext* context = currentExecutionContext(isolate); | |
| 478 if (InspectorInstrumentation::isPromiseTrackerEnabled(context)) { | |
| 479 ScriptState* scriptState = ScriptState::forContext(isolate->GetCurrentCo ntext()); | |
| 480 InspectorInstrumentation::didUpdatePromiseParent(context, ScriptObject(s criptState, derivedPromise), ScriptObject(scriptState, promise)); | |
| 481 } | |
| 479 } | 482 } |
| 480 | 483 |
| 481 } // namespace | 484 } // namespace |
| 482 | 485 |
| 483 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf o) | 486 void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf o) |
| 484 { | 487 { |
| 485 v8SetReturnValue(info, v8::Local<v8::Value>()); | 488 v8SetReturnValue(info, v8::Local<v8::Value>()); |
| 486 v8::Isolate* isolate = info.GetIsolate(); | 489 v8::Isolate* isolate = info.GetIsolate(); |
| 487 ExecutionContext* executionContext = callingExecutionContext(isolate); | 490 ExecutionContext* executionContext = callingExecutionContext(isolate); |
| 488 UseCounter::count(executionContext, UseCounter::PromiseConstructor); | 491 UseCounter::count(executionContext, UseCounter::PromiseConstructor); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 | 637 |
| 635 // | 638 // |
| 636 // -- V8PromiseCustom -- | 639 // -- V8PromiseCustom -- |
| 637 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) | 640 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) |
| 638 { | 641 { |
| 639 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); | 642 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); |
| 640 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); | 643 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); |
| 641 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); | 644 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); |
| 642 | 645 |
| 643 clearDerived(internal, isolate); | 646 clearDerived(internal, isolate); |
| 644 setState(internal, Pending, v8::Undefined(isolate), isolate); | 647 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); |
| 645 | 648 |
| 646 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); | 649 ExecutionContext* context = currentExecutionContext(isolate); |
| 650 if (InspectorInstrumentation::isPromiseTrackerEnabled(context)) | |
| 651 InspectorInstrumentation::didCreatePromise(context, ScriptObject(ScriptS tate::forContext(isolate->GetCurrentContext()), promise)); | |
| 652 | |
| 653 setState(promise, Pending, v8::Undefined(isolate), isolate); | |
| 647 return promise; | 654 return promise; |
| 648 } | 655 } |
| 649 | 656 |
| 650 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) | 657 v8::Local<v8::Object> V8PromiseCustom::getInternal(v8::Handle<v8::Object> promis e) |
| 651 { | 658 { |
| 652 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); | 659 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); |
| 653 return value.As<v8::Object>(); | 660 return value.As<v8::Object>(); |
| 654 } | 661 } |
| 655 | 662 |
| 656 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) | 663 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) |
| 657 { | 664 { |
| 658 v8::Handle<v8::Value> value = internal->GetInternalField(V8PromiseCustom::In ternalStateIndex); | 665 v8::Handle<v8::Value> value = internal->GetInternalField(V8PromiseCustom::In ternalStateIndex); |
| 659 uint32_t number = toInt32(value); | 666 uint32_t number = toInt32(value); |
| 660 ASSERT(number == Pending || number == Fulfilled || number == Rejected || num ber == Following); | 667 ASSERT(number == Pending || number == Fulfilled || number == Rejected || num ber == Following); |
| 661 return static_cast<PromiseState>(number); | 668 return static_cast<PromiseState>(number); |
| 662 } | 669 } |
| 663 | 670 |
| 664 void V8PromiseCustom::setState(v8::Handle<v8::Object> internal, PromiseState sta te, v8::Handle<v8::Value> value, v8::Isolate* isolate) | 671 void V8PromiseCustom::setState(v8::Handle<v8::Object> promise, PromiseState stat e, v8::Handle<v8::Value> value, v8::Isolate* isolate) |
|
yhirano
2014/03/13 01:43:00
I don't like the subtle difference of the paramete
yhirano
2014/03/13 01:43:00
Is it possible to delete V8PromiseCustom::setState
Alexandra Mikhaylova
2014/03/13 13:22:51
Thanks, fixed it.
| |
| 665 { | 672 { |
| 666 ASSERT(!value.IsEmpty()); | 673 ASSERT(!value.IsEmpty()); |
| 667 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state == Following); | 674 ASSERT(state == Pending || state == Fulfilled || state == Rejected || state == Following); |
| 675 v8::Local<v8::Object> internal = getInternal(promise); | |
| 668 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta te)); | 676 internal->SetInternalField(InternalStateIndex, v8::Integer::New(isolate, sta te)); |
| 669 internal->SetInternalField(InternalResultIndex, value); | 677 internal->SetInternalField(InternalResultIndex, value); |
| 678 ExecutionContext* context = currentExecutionContext(isolate); | |
| 679 if (InspectorInstrumentation::isPromiseTrackerEnabled(context)) | |
| 680 InspectorInstrumentation::didUpdatePromiseState(context, ScriptObject(Sc riptState::forContext(isolate->GetCurrentContext()), promise), state, ScriptValu e(value, isolate)); | |
| 670 } | 681 } |
| 671 | 682 |
| 672 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate* isolate) | 683 bool V8PromiseCustom::isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate* isolate) |
| 673 { | 684 { |
| 674 WrapperWorldType currentWorldType = worldType(isolate); | 685 WrapperWorldType currentWorldType = worldType(isolate); |
| 675 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP romise); | 686 return V8Promise::domTemplate(isolate, currentWorldType)->HasInstance(maybeP romise); |
| 676 } | 687 } |
| 677 | 688 |
| 678 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm ise, v8::Isolate* isolate) | 689 v8::Local<v8::Object> V8PromiseCustom::toPromise(v8::Handle<v8::Value> maybeProm ise, v8::Isolate* isolate) |
| 679 { | 690 { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 698 | 709 |
| 699 if (isPromise(result, isolate)) { | 710 if (isPromise(result, isolate)) { |
| 700 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); | 711 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); |
| 701 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); | 712 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); |
| 702 PromiseState valueState = getState(valueInternal); | 713 PromiseState valueState = getState(valueInternal); |
| 703 if (promise->SameValue(valuePromise)) { | 714 if (promise->SameValue(valuePromise)) { |
| 704 v8::Local<v8::Value> reason = V8ThrowException::createTypeError("Res olve a promise with itself", isolate); | 715 v8::Local<v8::Value> reason = V8ThrowException::createTypeError("Res olve a promise with itself", isolate); |
| 705 setReason(promise, reason, isolate); | 716 setReason(promise, reason, isolate); |
| 706 } else if (valueState == Following) { | 717 } else if (valueState == Following) { |
| 707 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte rnalField(InternalResultIndex).As<v8::Object>(); | 718 v8::Local<v8::Object> valuePromiseFollowing = valueInternal->GetInte rnalField(InternalResultIndex).As<v8::Object>(); |
| 708 setState(internal, Following, valuePromiseFollowing, isolate); | 719 setState(promise, Following, valuePromiseFollowing, isolate); |
| 709 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); | 720 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); |
| 710 } else if (valueState == Fulfilled) { | 721 } else if (valueState == Fulfilled) { |
| 711 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); | 722 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); |
| 712 } else if (valueState == Rejected) { | 723 } else if (valueState == Rejected) { |
| 713 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); | 724 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); |
| 714 } else { | 725 } else { |
| 715 ASSERT(valueState == Pending); | 726 ASSERT(valueState == Pending); |
| 716 setState(internal, Following, valuePromise, isolate); | 727 setState(promise, Following, valuePromise, isolate); |
| 717 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8: :Handle<v8::Function>(), isolate); | 728 addToDerived(valueInternal, promise, v8::Handle<v8::Function>(), v8: :Handle<v8::Function>(), isolate); |
| 718 } | 729 } |
| 719 } else { | 730 } else { |
| 720 setValue(promise, result, isolate); | 731 setValue(promise, result, isolate); |
| 721 } | 732 } |
| 722 } | 733 } |
| 723 | 734 |
| 724 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu e> reason, v8::Isolate* isolate) | 735 void V8PromiseCustom::reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Valu e> reason, v8::Isolate* isolate) |
| 725 { | 736 { |
| 726 v8::Local<v8::Object> internal = getInternal(promise); | 737 v8::Local<v8::Object> internal = getInternal(promise); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 | 824 |
| 814 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) | 825 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8: :Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState , v8::Isolate* isolate) |
| 815 { | 826 { |
| 816 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 827 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
| 817 ExecutionContext* executionContext = currentExecutionContext(isolate); | 828 ExecutionContext* executionContext = currentExecutionContext(isolate); |
| 818 ASSERT(executionContext && executionContext->isContextThread()); | 829 ASSERT(executionContext && executionContext->isContextThread()); |
| 819 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); | 830 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar gument, originatorState, isolate, executionContext))); |
| 820 } | 831 } |
| 821 | 832 |
| 822 } // namespace WebCore | 833 } // namespace WebCore |
| OLD | NEW |