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.
5 #ifndef ScriptPromisePropertyBase_h
6 #define ScriptPromisePropertyBase_h
8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseProperties.h"
11 #include "core/dom/ContextLifecycleObserver.h"
12 #include "wtf/OwnPtr.h"
13 #include "wtf/RefCounted.h"
14 #include "wtf/Vector.h"
19 class DOMWrapperWorld;
20 class ExecutionContext;
23 class ScriptPromisePropertyBase : public GarbageCollectedFinalized<ScriptPromisePropertyBase>, public ContextLifecycleObserver {
25 virtual ~ScriptPromisePropertyBase();
29 SCRIPT_PROMISE_PROPERTIES(P)
38 State state() const { return m_state; }
40 ScriptPromise promise(DOMWrapperWorld&);
42 virtual void trace(Visitor*) { }
45 ScriptPromisePropertyBase(ExecutionContext*, Name);
47 void resolveOrReject(State targetState);
49 // ScriptPromiseProperty overrides these to wrap the holder,
50 // rejected value and resolved value. The
51 // ScriptPromisePropertyBase caller will enter the V8Context for
52 // the property's execution context and the world it is
53 // creating/settling promises in; the implementation should use
55 virtual v8::Handle<v8::Object> holder(v8::Handle<v8::Object> creationContext, v8::Isolate*) = 0;
56 virtual v8::Handle<v8::Value> resolvedValue(v8::Isolate*, v8::Handle<v8::Object> creationContext) = 0;
57 virtual v8::Handle<v8::Value> rejectedValue(v8::Isolate*, v8::Handle<v8::Object> creationContext) = 0;
62 typedef Vector<OwnPtr<ScopedPersistent<v8::Object> > > WeakPersistentSet;
64 void resolveOrRejectInternal(v8::Handle<v8::Promise::Resolver>);
65 v8::Local<v8::Object> ensureHolderWrapper(ScriptState*);
68 v8::Handle<v8::String> promiseName();
69 v8::Handle<v8::String> resolverName();
71 v8::Isolate* m_isolate;
75 WeakPersistentSet m_wrappers;
80 #endif // ScriptPromisePropertyBase_h