| 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 20 matching lines...) Expand all Loading... |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/v8/custom/V8PromiseCustom.h" | 32 #include "bindings/v8/custom/V8PromiseCustom.h" |
| 33 | 33 |
| 34 #include <v8.h> | 34 #include <v8.h> |
| 35 #include "V8Promise.h" | 35 #include "V8Promise.h" |
| 36 #include "bindings/v8/DOMRequestState.h" | 36 #include "bindings/v8/DOMRequestState.h" |
| 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/V8HiddenPropertyName.h" | |
| 42 #include "bindings/v8/V8PerIsolateData.h" | 41 #include "bindings/v8/V8PerIsolateData.h" |
| 43 #include "bindings/v8/V8ScriptRunner.h" | 42 #include "bindings/v8/V8ScriptRunner.h" |
| 44 #include "bindings/v8/WrapperTypeInfo.h" | 43 #include "bindings/v8/WrapperTypeInfo.h" |
| 45 #include "core/dom/Document.h" | 44 #include "core/dom/Document.h" |
| 46 #include "core/dom/ExecutionContextTask.h" | 45 #include "core/dom/ExecutionContextTask.h" |
| 47 #include "core/frame/DOMWindow.h" | 46 #include "core/frame/DOMWindow.h" |
| 48 #include "core/inspector/InspectorInstrumentation.h" | 47 #include "core/inspector/InspectorInstrumentation.h" |
| 49 #include "core/workers/WorkerGlobalScope.h" | 48 #include "core/workers/WorkerGlobalScope.h" |
| 50 #include "platform/Task.h" | 49 #include "platform/Task.h" |
| 51 #include "wtf/Deque.h" | 50 #include "wtf/Deque.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 { | 279 { |
| 281 TaskPerformScopeForInstrumentation performTaskScope(context, this); | 280 TaskPerformScopeForInstrumentation performTaskScope(context, this); |
| 282 | 281 |
| 283 ASSERT(context); | 282 ASSERT(context); |
| 284 if (context->activeDOMObjectsAreStopped()) | 283 if (context->activeDOMObjectsAreStopped()) |
| 285 return; | 284 return; |
| 286 | 285 |
| 287 DOMRequestState::Scope scope(m_requestState); | 286 DOMRequestState::Scope scope(m_requestState); |
| 288 v8::Isolate* isolate = m_requestState.isolate(); | 287 v8::Isolate* isolate = m_requestState.isolate(); |
| 289 v8::Local<v8::Object> originatorValueObject = m_originatorValueObject.newLoc
al(isolate); | 288 v8::Local<v8::Object> originatorValueObject = m_originatorValueObject.newLoc
al(isolate); |
| 290 v8::Local<v8::Value> coercedAlready = originatorValueObject->GetHiddenValue(
V8HiddenPropertyName::thenableHiddenPromise(isolate)); | 289 v8::Local<v8::Value> coercedAlready = getHiddenValue(isolate, originatorValu
eObject, "thenableHiddenPromise"); |
| 291 if (!coercedAlready.IsEmpty() && coercedAlready->IsObject()) { | 290 if (!coercedAlready.IsEmpty() && coercedAlready->IsObject()) { |
| 292 ASSERT(V8PromiseCustom::isPromise(coercedAlready.As<v8::Object>(), isola
te)); | 291 ASSERT(V8PromiseCustom::isPromise(coercedAlready.As<v8::Object>(), isola
te)); |
| 293 V8PromiseCustom::updateDerivedFromPromise(m_promise.newLocal(isolate), m
_onFulfilled.newLocal(isolate), m_onRejected.newLocal(isolate), coercedAlready.A
s<v8::Object>(), isolate); | 292 V8PromiseCustom::updateDerivedFromPromise(m_promise.newLocal(isolate), m
_onFulfilled.newLocal(isolate), m_onRejected.newLocal(isolate), coercedAlready.A
s<v8::Object>(), isolate); |
| 294 return; | 293 return; |
| 295 } | 294 } |
| 296 | 295 |
| 297 v8::Local<v8::Value> then; | 296 v8::Local<v8::Value> then; |
| 298 v8::TryCatch trycatch; | 297 v8::TryCatch trycatch; |
| 299 then = originatorValueObject->Get(v8AtomicString(isolate, "then")); | 298 then = originatorValueObject->Get(v8AtomicString(isolate, "then")); |
| 300 if (then.IsEmpty()) { | 299 if (then.IsEmpty()) { |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 ASSERT(!then.IsEmpty()); | 794 ASSERT(!then.IsEmpty()); |
| 796 v8::Local<v8::Object> promise = createPromise(v8::Handle<v8::Object>(), isol
ate); | 795 v8::Local<v8::Object> promise = createPromise(v8::Handle<v8::Object>(), isol
ate); |
| 797 v8::Handle<v8::Value> argv[] = { | 796 v8::Handle<v8::Value> argv[] = { |
| 798 createClosure(promiseResolveCallback, promise, isolate), | 797 createClosure(promiseResolveCallback, promise, isolate), |
| 799 createClosure(promiseRejectCallback, promise, isolate) | 798 createClosure(promiseRejectCallback, promise, isolate) |
| 800 }; | 799 }; |
| 801 v8::TryCatch trycatch; | 800 v8::TryCatch trycatch; |
| 802 if (V8ScriptRunner::callFunction(then, getExecutionContext(), thenable, WTF_
ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { | 801 if (V8ScriptRunner::callFunction(then, getExecutionContext(), thenable, WTF_
ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) { |
| 803 reject(promise, trycatch.Exception(), isolate); | 802 reject(promise, trycatch.Exception(), isolate); |
| 804 } | 803 } |
| 805 thenable->SetHiddenValue(V8HiddenPropertyName::thenableHiddenPromise(isolate
), promise); | 804 setHiddenValue(isolate, thenable, "thenableHiddenPromise", promise); |
| 806 return promise; | 805 return promise; |
| 807 } | 806 } |
| 808 | 807 |
| 809 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState
, v8::Isolate* isolate) | 808 void V8PromiseCustom::callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8:
:Function> handler, v8::Handle<v8::Value> argument, PromiseState originatorState
, v8::Isolate* isolate) |
| 810 { | 809 { |
| 811 ASSERT(originatorState == Fulfilled || originatorState == Rejected); | 810 ASSERT(originatorState == Fulfilled || originatorState == Rejected); |
| 812 ExecutionContext* executionContext = getExecutionContext(); | 811 ExecutionContext* executionContext = getExecutionContext(); |
| 813 ASSERT(executionContext && executionContext->isContextThread()); | 812 ASSERT(executionContext && executionContext->isContextThread()); |
| 814 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, originatorState, isolate, executionContext))); | 813 executionContext->postTask(adoptPtr(new CallHandlerTask(promise, handler, ar
gument, originatorState, isolate, executionContext))); |
| 815 } | 814 } |
| 816 | 815 |
| 817 } // namespace WebCore | 816 } // namespace WebCore |
| OLD | NEW |