Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / v8 / custom / V8PromiseCustom.cpp
index be95b44..21f923d 100644 (file)
@@ -44,6 +44,7 @@
 #include "core/dom/Document.h"
 #include "core/dom/ExecutionContextTask.h"
 #include "core/frame/DOMWindow.h"
+#include "core/frame/UseCounter.h"
 #include "core/inspector/InspectorInstrumentation.h"
 #include "core/workers/WorkerGlobalScope.h"
 #include "platform/Task.h"
@@ -458,7 +459,7 @@ void PromisePropagator::updateDerived(v8::Handle<v8::Object> derivedPromise, v8:
     v8::Local<v8::Value> originatorValue = originatorInternal->GetInternalField(V8PromiseCustom::InternalResultIndex);
     if (originatorState == V8PromiseCustom::Fulfilled) {
         if (originatorValue->IsObject()) {
-            ExecutionContext* executionContext = getExecutionContext();
+            ExecutionContext* executionContext = currentExecutionContext(isolate);
             ASSERT(executionContext && executionContext->isContextThread());
             executionContext->postTask(adoptPtr(new UpdateDerivedTask(derivedPromise, onFulfilled, onRejected, originatorValue.As<v8::Object>(), isolate, executionContext)));
         } else {
@@ -486,6 +487,8 @@ void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
 {
     v8SetReturnValue(info, v8::Local<v8::Value>());
     v8::Isolate* isolate = info.GetIsolate();
+    ExecutionContext* executionContext = activeExecutionContext(isolate);
+    UseCounter::count(executionContext, UseCounter::PromiseConstructor);
     if (!info.Length() || !info[0]->IsFunction()) {
         throwTypeError("Promise constructor takes a function argument", isolate);
         return;
@@ -497,7 +500,7 @@ void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
         createClosure(promiseRejectCallback, promise, isolate)
     };
     v8::TryCatch trycatch;
-    if (V8ScriptRunner::callFunction(init, getExecutionContext(), v8::Undefined(isolate), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) {
+    if (V8ScriptRunner::callFunction(init, currentExecutionContext(isolate), v8::Undefined(isolate), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) {
         // An exception is thrown. Reject the promise if its resolved flag is unset.
         V8PromiseCustom::reject(promise, trycatch.Exception(), isolate);
     }
@@ -519,6 +522,8 @@ void V8Promise::thenMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info
 void V8Promise::castMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
 {
     v8::Isolate* isolate = info.GetIsolate();
+    ExecutionContext* executionContext = activeExecutionContext(isolate);
+    UseCounter::count(executionContext, UseCounter::PromiseCast);
     v8::Local<v8::Value> result = v8::Undefined(isolate);
     if (info.Length() > 0)
         result = info[0];
@@ -544,6 +549,8 @@ void V8Promise::catchMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& inf
 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
 {
     v8::Isolate* isolate = info.GetIsolate();
+    ExecutionContext* executionContext = activeExecutionContext(isolate);
+    UseCounter::count(executionContext, UseCounter::PromiseResolve);
     v8::Local<v8::Value> result = v8::Undefined(isolate);
     if (info.Length() > 0)
         result = info[0];
@@ -556,6 +563,8 @@ void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
 {
     v8::Isolate* isolate = info.GetIsolate();
+    ExecutionContext* executionContext = activeExecutionContext(isolate);
+    UseCounter::count(executionContext, UseCounter::PromiseReject);
     v8::Local<v8::Value> result = v8::Undefined(isolate);
     if (info.Length() > 0)
         result = info[0];
@@ -798,7 +807,7 @@ v8::Local<v8::Object> V8PromiseCustom::coerceThenable(v8::Handle<v8::Object> the
         createClosure(promiseRejectCallback, promise, isolate)
     };
     v8::TryCatch trycatch;
-    if (V8ScriptRunner::callFunction(then, getExecutionContext(), thenable, WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) {
+    if (V8ScriptRunner::callFunction(then, currentExecutionContext(isolate), thenable, WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) {
         reject(promise, trycatch.Exception(), isolate);
     }
     setHiddenValue(isolate, thenable, "thenableHiddenPromise", promise);
@@ -808,7 +817,7 @@ v8::Local<v8::Object> V8PromiseCustom::coerceThenable(v8::Handle<v8::Object> the
 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8::Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState, v8::Isolate* isolate)
 {
     ASSERT(originatorState == Fulfilled || originatorState == Rejected);
-    ExecutionContext* executionContext = getExecutionContext();
+    ExecutionContext* executionContext = currentExecutionContext(isolate);
     ASSERT(executionContext && executionContext->isContextThread());
     executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, argument, originatorState, isolate, executionContext)));
 }