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

Side by Side Diff: Source/bindings/core/v8/ScriptPromisePropertyBase.h

Issue 361863003: Add a helper for implementing Promise-valued properties. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More feedback. Keeping separate header file for now. Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(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 ScriptPromisePropertyBase_h
6 #define ScriptPromisePropertyBase_h
7
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/RefCounted.h"
13 #include <v8.h>
14
15 namespace WebCore {
16
17 class ExecutionContext;
18
19 class ScriptPromisePropertyBase : public ContextLifecycleObserver, public RefCou nted<ScriptPromisePropertyBase> {
20 public:
21 virtual ~ScriptPromisePropertyBase();
22
23 enum Name {
24 #define P(Name) Name
25 SCRIPT_PROMISE_PROPERTIES(P)
26 #undef P
27 };
28
29 enum State {
30 Pending,
31 Resolved,
32 Rejected,
33 };
34 State state() const { return m_state; }
35
36 ScriptPromise promise(DOMWrapperWorld&);
37
38 protected:
39 ScriptPromisePropertyBase(ExecutionContext*, Name);
40
41 void resolveOrReject(State targetState);
42
43 // ScriptPromiseProperty overrides these to wrap the holder,
44 // rejected value and resolved value. The
45 // ScriptPromisePropertyBase caller will enter the V8Context for
46 // the property's execution context and the world it is
47 // creating/settling promises in; the implementation should use
48 // this context.
49 virtual v8::Handle<v8::Object> holder(v8::Handle<v8::Object> creationContext , v8::Isolate*) = 0;
50 virtual v8::Handle<v8::Value> resolvedValue(v8::Handle<v8::Object> creationC ontext, v8::Isolate*) = 0;
51 virtual v8::Handle<v8::Value> rejectedValue(v8::Handle<v8::Object> creationC ontext, v8::Isolate*) = 0;
52
53 private:
54 void resolveOrRejectInternal(v8::Handle<v8::Promise::Resolver>);
55
56 v8::Handle<v8::String> promiseName();
57 v8::Handle<v8::String> resolverName();
58
59 v8::Isolate* m_isolate;
60 Name m_name;
61 State m_state;
62
63 // FIXME: When isolated worlds are supported replace this with a
64 // set of wrappers.
65 ScopedPersistent<v8::Object> m_mainWorldWrapper;
66 };
67
68 } // namespace WebCore
69
70 #endif // ScriptPromisePropertyBase_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptPromiseProperty.h ('k') | Source/bindings/core/v8/ScriptPromisePropertyBase.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698