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

Side by Side Diff: sky/engine/bindings/core/v8/ScriptPromise.h

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISE_H_
32 #define SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISE_H_
33
34 #include "sky/engine/bindings/core/v8/ScriptValue.h"
35 #include "sky/engine/bindings/core/v8/V8ThrowException.h"
36 #include "sky/engine/core/dom/ExceptionCode.h"
37 #include "sky/engine/wtf/PassRefPtr.h"
38 #include "sky/engine/wtf/text/WTFString.h"
39 #include "v8/include/v8.h"
40
41 namespace blink {
42
43 class DOMException;
44 class ExceptionState;
45
46 // ScriptPromise is the class for representing Promise values in C++ world.
47 // ScriptPromise holds a Promise.
48 // So holding a ScriptPromise as a member variable in DOM object causes
49 // memory leaks since it has a reference from C++ to V8.
50 //
51 class ScriptPromise final {
52 public:
53 // Constructs an empty promise.
54 ScriptPromise() { }
55
56 // Constructs a ScriptPromise from |promise|.
57 // If |promise| is not a Promise object, throws a v8 TypeError.
58 ScriptPromise(ScriptState*, v8::Handle<v8::Value> promise);
59
60 ScriptPromise then(v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Func tion> onRejected = v8::Handle<v8::Function>());
61
62 bool isObject() const
63 {
64 return m_promise.isObject();
65 }
66
67 bool isNull() const
68 {
69 return m_promise.isNull();
70 }
71
72 bool isUndefinedOrNull() const
73 {
74 return m_promise.isUndefined() || m_promise.isNull();
75 }
76
77 v8::Handle<v8::Value> v8Value() const
78 {
79 return m_promise.v8Value();
80 }
81
82 v8::Isolate* isolate() const
83 {
84 return m_promise.isolate();
85 }
86
87 bool isEmpty() const
88 {
89 return m_promise.isEmpty();
90 }
91
92 void clear()
93 {
94 m_promise.clear();
95 }
96
97 bool operator==(const ScriptPromise& value) const
98 {
99 return m_promise == value.m_promise;
100 }
101
102 bool operator!=(const ScriptPromise& value) const
103 {
104 return !operator==(value);
105 }
106
107 // Constructs and returns a ScriptPromise from |value|.
108 // if |value| is not a Promise object, returns a Promise object
109 // resolved with |value|.
110 // Returns |value| itself if it is a Promise.
111 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/);
112 static ScriptPromise cast(ScriptState*, v8::Handle<v8::Value> /*value*/);
113
114 static ScriptPromise reject(ScriptState*, const ScriptValue&);
115 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>);
116
117 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtr<DOMExce ption>);
118
119 static v8::Local<v8::Promise> rejectRaw(v8::Isolate*, v8::Handle<v8::Value>) ;
120
121 // This is a utility class intended to be used internally.
122 // ScriptPromiseResolver is for general purpose.
123 class InternalResolver final {
124 public:
125 explicit InternalResolver(ScriptState*);
126 v8::Local<v8::Promise> v8Promise() const;
127 ScriptPromise promise() const;
128 void resolve(v8::Local<v8::Value>);
129 void reject(v8::Local<v8::Value>);
130 void clear() { m_resolver.clear(); }
131
132 private:
133 ScriptValue m_resolver;
134 };
135
136 private:
137 RefPtr<ScriptState> m_scriptState;
138 ScriptValue m_promise;
139 };
140
141 } // namespace blink
142
143
144 #endif // SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISE_H_
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/ScriptProfiler.cpp ('k') | sky/engine/bindings/core/v8/ScriptPromise.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698