| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISEPROPERTYBASE_H_ | |
| 6 #define SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISEPROPERTYBASE_H_ | |
| 7 | |
| 8 #include "sky/engine/bindings/core/v8/ScopedPersistent.h" | |
| 9 #include "sky/engine/bindings/core/v8/ScriptPromise.h" | |
| 10 #include "sky/engine/bindings/core/v8/ScriptPromiseProperties.h" | |
| 11 #include "sky/engine/core/dom/ContextLifecycleObserver.h" | |
| 12 #include "sky/engine/wtf/OwnPtr.h" | |
| 13 #include "sky/engine/wtf/RefCounted.h" | |
| 14 #include "sky/engine/wtf/Vector.h" | |
| 15 #include "v8/include/v8.h" | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 class DOMWrapperWorld; | |
| 20 class ExecutionContext; | |
| 21 class ScriptState; | |
| 22 | |
| 23 class ScriptPromisePropertyBase : public ContextLifecycleObserver { | |
| 24 public: | |
| 25 virtual ~ScriptPromisePropertyBase(); | |
| 26 | |
| 27 enum Name { | |
| 28 #define P(Name) Name, | |
| 29 SCRIPT_PROMISE_PROPERTIES(P) | |
| 30 #undef P | |
| 31 }; | |
| 32 | |
| 33 enum State { | |
| 34 Pending, | |
| 35 Resolved, | |
| 36 Rejected, | |
| 37 }; | |
| 38 State state() const { return m_state; } | |
| 39 | |
| 40 ScriptPromise promise(DOMWrapperWorld&); | |
| 41 | |
| 42 protected: | |
| 43 ScriptPromisePropertyBase(ExecutionContext*, Name); | |
| 44 | |
| 45 void resolveOrReject(State targetState); | |
| 46 | |
| 47 // ScriptPromiseProperty overrides these to wrap the holder, | |
| 48 // rejected value and resolved value. The | |
| 49 // ScriptPromisePropertyBase caller will enter the V8Context for | |
| 50 // the property's execution context and the world it is | |
| 51 // creating/settling promises in; the implementation should use | |
| 52 // this context. | |
| 53 virtual v8::Handle<v8::Object> holder(v8::Handle<v8::Object> creationContext
, v8::Isolate*) = 0; | |
| 54 virtual v8::Handle<v8::Value> resolvedValue(v8::Handle<v8::Object> creationC
ontext, v8::Isolate*) = 0; | |
| 55 virtual v8::Handle<v8::Value> rejectedValue(v8::Handle<v8::Object> creationC
ontext, v8::Isolate*) = 0; | |
| 56 | |
| 57 void resetBase(); | |
| 58 | |
| 59 private: | |
| 60 typedef Vector<OwnPtr<ScopedPersistent<v8::Object> > > WeakPersistentSet; | |
| 61 | |
| 62 void resolveOrRejectInternal(v8::Handle<v8::Promise::Resolver>); | |
| 63 v8::Local<v8::Object> ensureHolderWrapper(ScriptState*); | |
| 64 void clearWrappers(); | |
| 65 | |
| 66 v8::Handle<v8::String> promiseName(); | |
| 67 v8::Handle<v8::String> resolverName(); | |
| 68 | |
| 69 v8::Isolate* m_isolate; | |
| 70 Name m_name; | |
| 71 State m_state; | |
| 72 | |
| 73 WeakPersistentSet m_wrappers; | |
| 74 }; | |
| 75 | |
| 76 } // namespace blink | |
| 77 | |
| 78 #endif // SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISEPROPERTYBASE_H_ | |
| OLD | NEW |