Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: Source/bindings/v8/custom/V8PromiseCustom.cpp

Issue 177773002: Support Promises instrumentation on backend. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address review comments + track Promise result Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
37 #include "bindings/v8/ScopedPersistent.h" 37 #include "bindings/v8/ScopedPersistent.h"
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/inspector/InspectorInstrumentation.h" 47 #include "core/inspector/InspectorInstrumentation.h"
aandrey 2014/02/26 16:11:30 remove
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
48 #include "core/inspector/InspectorPromiseInstrumentation.h"
48 #include "core/workers/WorkerGlobalScope.h" 49 #include "core/workers/WorkerGlobalScope.h"
49 #include "platform/Task.h" 50 #include "platform/Task.h"
50 #include "wtf/Deque.h" 51 #include "wtf/Deque.h"
51 #include "wtf/Functional.h" 52 #include "wtf/Functional.h"
52 #include "wtf/Noncopyable.h" 53 #include "wtf/Noncopyable.h"
53 #include "wtf/PassOwnPtr.h" 54 #include "wtf/PassOwnPtr.h"
54 55
55 namespace WebCore { 56 namespace WebCore {
56 57
57 namespace { 58 namespace {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 OwnPtr<Derived> derived = m_derivedStack.takeLast(); 384 OwnPtr<Derived> derived = m_derivedStack.takeLast();
384 updateDerived(derived->promise(isolate), derived->onFulfilled(isolate), derived->onRejected(isolate), derived->originator(isolate), isolate); 385 updateDerived(derived->promise(isolate), derived->onFulfilled(isolate), derived->onRejected(isolate), derived->originator(isolate), isolate);
385 } 386 }
386 } 387 }
387 388
388 void PromisePropagator::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8:: Value> value, v8::Isolate* isolate) 389 void PromisePropagator::setValue(v8::Handle<v8::Object> promise, v8::Handle<v8:: Value> value, v8::Isolate* isolate)
389 { 390 {
390 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); 391 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise);
391 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); 392 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected);
392 V8PromiseCustom::setState(internal, V8PromiseCustom::Fulfilled, value, isola te); 393 V8PromiseCustom::setState(internal, V8PromiseCustom::Fulfilled, value, isola te);
394 InspectorInstrumentation::setPromiseStateAndResult(currentExecutionContext(i solate), promise, value, V8PromiseCustom::Fulfilled);
aandrey 2014/02/26 16:11:30 move inside setState
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
393 propagateToDerived(promise, isolate); 395 propagateToDerived(promise, isolate);
394 } 396 }
395 397
396 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8: :Value> reason, v8::Isolate* isolate) 398 void PromisePropagator::setReason(v8::Handle<v8::Object> promise, v8::Handle<v8: :Value> reason, v8::Isolate* isolate)
397 { 399 {
398 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); 400 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise);
399 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected); 401 ASSERT(V8PromiseCustom::getState(internal) != V8PromiseCustom::Fulfilled && V8PromiseCustom::getState(internal) != V8PromiseCustom::Rejected);
400 V8PromiseCustom::setState(internal, V8PromiseCustom::Rejected, reason, isola te); 402 V8PromiseCustom::setState(internal, V8PromiseCustom::Rejected, reason, isola te);
403 InspectorInstrumentation::setPromiseStateAndResult(currentExecutionContext(i solate), promise, reason, V8PromiseCustom::Rejected);
aandrey 2014/02/26 16:11:30 ditto
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
401 propagateToDerived(promise, isolate); 404 propagateToDerived(promise, isolate);
402 } 405 }
403 406
404 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I solate* isolate) 407 void PromisePropagator::propagateToDerived(v8::Handle<v8::Object> promise, v8::I solate* isolate)
405 { 408 {
406 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); 409 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise);
407 ASSERT(V8PromiseCustom::getState(internal) == V8PromiseCustom::Fulfilled || V8PromiseCustom::getState(internal) == V8PromiseCustom::Rejected); 410 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>(); 411 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>(); 412 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>(); 413 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
464 } else { 467 } else {
465 updateDerivedFromValue(derivedPromise, onFulfilled, originatorValue, isolate); 468 updateDerivedFromValue(derivedPromise, onFulfilled, originatorValue, isolate);
466 } 469 }
467 } else { 470 } else {
468 updateDerivedFromReason(derivedPromise, onRejected, originatorValue, iso late); 471 updateDerivedFromReason(derivedPromise, onRejected, originatorValue, iso late);
469 } 472 }
470 } 473 }
471 474
472 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) 475 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)
473 { 476 {
477 InspectorInstrumentation::setPromiseParent(currentExecutionContext(isolate), derivedPromise, promise);
474 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); 478 v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise);
475 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); 479 V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal);
476 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte d) { 480 if (state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejecte d) {
477 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate) ; 481 updateDerived(derivedPromise, onFulfilled, onRejected, promise, isolate) ;
478 } else { 482 } else {
479 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate) ; 483 addToDerived(internal, derivedPromise, onFulfilled, onRejected, isolate) ;
480 } 484 }
481 } 485 }
482 486
483 } // namespace 487 } // namespace
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 632
629 // 633 //
630 // -- V8PromiseCustom -- 634 // -- V8PromiseCustom --
631 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate) 635 v8::Local<v8::Object> V8PromiseCustom::createPromise(v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate)
632 { 636 {
633 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate); 637 v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isol ate);
634 v8::Local<v8::Object> internal = internalTemplate->NewInstance(); 638 v8::Local<v8::Object> internal = internalTemplate->NewInstance();
635 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate); 639 v8::Local<v8::Object> promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::wrapperTypeInfo, 0, isolate);
636 640
637 clearDerived(internal, isolate); 641 clearDerived(internal, isolate);
642
643 InspectorInstrumentation::addPromise(currentExecutionContext(isolate), promi se, v8::Handle<v8::Object>());
644
638 setState(internal, Pending, v8::Undefined(isolate), isolate); 645 setState(internal, Pending, v8::Undefined(isolate), isolate);
646 InspectorInstrumentation::setPromiseStateAndResult(currentExecutionContext(i solate), promise, v8::Undefined(isolate), Pending);
aandrey 2014/02/26 16:11:30 remove
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
639 647
640 promise->SetInternalField(v8DOMWrapperObjectIndex, internal); 648 promise->SetInternalField(v8DOMWrapperObjectIndex, internal);
649
aandrey 2014/02/26 16:11:30 revert
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
641 return promise; 650 return promise;
642 } 651 }
643 652
644 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)
645 { 654 {
646 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex); 655 v8::Local<v8::Value> value = promise->GetInternalField(v8DOMWrapperObjectInd ex);
647 return value.As<v8::Object>(); 656 return value.As<v8::Object>();
648 } 657 }
649 658
650 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal) 659 V8PromiseCustom::PromiseState V8PromiseCustom::getState(v8::Handle<v8::Object> i nternal)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 if (isPromise(result, isolate)) { 702 if (isPromise(result, isolate)) {
694 v8::Local<v8::Object> valuePromise = result.As<v8::Object>(); 703 v8::Local<v8::Object> valuePromise = result.As<v8::Object>();
695 v8::Local<v8::Object> valueInternal = getInternal(valuePromise); 704 v8::Local<v8::Object> valueInternal = getInternal(valuePromise);
696 PromiseState valueState = getState(valueInternal); 705 PromiseState valueState = getState(valueInternal);
697 if (promise->SameValue(valuePromise)) { 706 if (promise->SameValue(valuePromise)) {
698 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);
699 setReason(promise, reason, isolate); 708 setReason(promise, reason, isolate);
700 } else if (valueState == Following) { 709 } else if (valueState == Following) {
701 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>();
702 setState(internal, Following, valuePromiseFollowing, isolate); 711 setState(internal, Following, valuePromiseFollowing, isolate);
712 InspectorInstrumentation::setPromiseStateAndResult(currentExecutionC ontext(isolate), promise, valuePromiseFollowing, Following);
aandrey 2014/02/26 16:11:30 move inside setState
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
703 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate); 713 addToDerived(getInternal(valuePromiseFollowing), promise, v8::Handle <v8::Function>(), v8::Handle<v8::Function>(), isolate);
704 } else if (valueState == Fulfilled) { 714 } else if (valueState == Fulfilled) {
705 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate); 715 setValue(promise, valueInternal->GetInternalField(InternalResultInde x), isolate);
706 } else if (valueState == Rejected) { 716 } else if (valueState == Rejected) {
707 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate); 717 setReason(promise, valueInternal->GetInternalField(InternalResultInd ex), isolate);
708 } else { 718 } else {
709 ASSERT(valueState == Pending); 719 ASSERT(valueState == Pending);
710 setState(internal, Following, valuePromise, isolate); 720 setState(internal, Following, valuePromise, isolate);
721 InspectorInstrumentation::setPromiseStateAndResult(currentExecutionC ontext(isolate), promise, valuePromise, Following);
aandrey 2014/02/26 16:11:30 move inside setState
Alexandra Mikhaylova 2014/02/28 13:52:05 Done.
711 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);
712 } 723 }
713 } else { 724 } else {
714 setValue(promise, result, isolate); 725 setValue(promise, result, isolate);
715 } 726 }
716 } 727 }
717 728
718 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)
719 { 730 {
720 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
807 818
808 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)
809 { 820 {
810 ASSERT(originatorState == Fulfilled || originatorState == Rejected); 821 ASSERT(originatorState == Fulfilled || originatorState == Rejected);
811 ExecutionContext* executionContext = currentExecutionContext(isolate); 822 ExecutionContext* executionContext = currentExecutionContext(isolate);
812 ASSERT(executionContext && executionContext->isContextThread()); 823 ASSERT(executionContext && executionContext->isContextThread());
813 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)));
814 } 825 }
815 826
816 } // namespace WebCore 827 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698