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

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

Issue 232563003: API functions returning Promises should not throw exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « Source/bindings/core/v8/ExceptionState.cpp ('k') | Source/bindings/core/v8/ScriptPromise.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef ScriptPromise_h 31 #ifndef ScriptPromise_h
32 #define ScriptPromise_h 32 #define ScriptPromise_h
33 33
34 #include "bindings/core/v8/ScriptFunction.h" 34 #include "bindings/core/v8/ScriptFunction.h"
35 #include "bindings/core/v8/ScriptValue.h" 35 #include "bindings/core/v8/ScriptValue.h"
36 #include "bindings/core/v8/V8ThrowException.h"
37 #include "core/dom/ExceptionCode.h"
36 #include "platform/heap/Handle.h" 38 #include "platform/heap/Handle.h"
37 #include "wtf/PassOwnPtr.h" 39 #include "wtf/PassOwnPtr.h"
38 #include "wtf/PassRefPtr.h" 40 #include "wtf/PassRefPtr.h"
41 #include "wtf/text/WTFString.h"
39 #include <v8.h> 42 #include <v8.h>
40 43
41 namespace blink { 44 namespace blink {
42 45
43 class DOMException; 46 class DOMException;
47 class ExceptionState;
44 48
45 // ScriptPromise is the class for representing Promise values in C++ world. 49 // ScriptPromise is the class for representing Promise values in C++ world.
46 // ScriptPromise holds a Promise. 50 // ScriptPromise holds a Promise.
47 // So holding a ScriptPromise as a member variable in DOM object causes 51 // So holding a ScriptPromise as a member variable in DOM object causes
48 // memory leaks since it has a reference from C++ to V8. 52 // memory leaks since it has a reference from C++ to V8.
49 // 53 //
50 class ScriptPromise FINAL { 54 class ScriptPromise FINAL {
51 public: 55 public:
52 // Constructs an empty promise. 56 // Constructs an empty promise.
53 ScriptPromise() { } 57 ScriptPromise() { }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // resolved with |value|. 112 // resolved with |value|.
109 // Returns |value| itself if it is a Promise. 113 // Returns |value| itself if it is a Promise.
110 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/); 114 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/);
111 static ScriptPromise cast(ScriptState*, v8::Handle<v8::Value> /*value*/); 115 static ScriptPromise cast(ScriptState*, v8::Handle<v8::Value> /*value*/);
112 116
113 static ScriptPromise reject(ScriptState*, const ScriptValue&); 117 static ScriptPromise reject(ScriptState*, const ScriptValue&);
114 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>); 118 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>);
115 119
116 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtrWillBeRa wPtr<DOMException>); 120 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtrWillBeRa wPtr<DOMException>);
117 121
122 // static functions each of which returns a ScriptPromise rejected with
123 // the given error.
124 // They coresspond to functions in V8Binding.h, such as throwError,
125 // throwTypeError, etc.
126 // FIXME: Remove these functions.
127 static ScriptPromise rejectWithTypeError(ScriptState*, const String&);
128 static ScriptPromise rejectWithArityTypeErrorForMethod(ScriptState*, const c har* method, const char* type, const char* valid, unsigned provided);
129 static ScriptPromise rejectWithArityTypeErrorForConstructor(ScriptState*, co nst char* type, const char* valid, unsigned provided);
130 static ScriptPromise rejectWithArityTypeError(ScriptState*, ExceptionState&, const char* valid, unsigned provided);
131 static ScriptPromise rejectWithMinimumArityTypeErrorForMethod(
132 ScriptState*, const char* method, const char* type, unsigned expected, u nsigned providedLeastNumMandatoryParams);
133 static ScriptPromise rejectWithMinimumArityTypeErrorForConstructor(
134 ScriptState*, const char* type, unsigned expected, unsigned providedLeas tNumMandatoryParams);
135 static ScriptPromise rejectWithMinimumArityTypeError(ScriptState*, Exception State&, unsigned expected, unsigned providedLeastNumMandatoryParams);
136
137 static v8::Local<v8::Promise> rejectRaw(v8::Isolate*, v8::Handle<v8::Value>) ;
138
118 // This is a utility class intended to be used internally. 139 // This is a utility class intended to be used internally.
119 // ScriptPromiseResolver is for general purpose. 140 // ScriptPromiseResolver is for general purpose.
120 class InternalResolver FINAL { 141 class InternalResolver FINAL {
121 public: 142 public:
122 explicit InternalResolver(ScriptState*); 143 explicit InternalResolver(ScriptState*);
123 v8::Local<v8::Promise> v8Promise() const; 144 v8::Local<v8::Promise> v8Promise() const;
124 ScriptPromise promise() const; 145 ScriptPromise promise() const;
125 void resolve(v8::Local<v8::Value>); 146 void resolve(v8::Local<v8::Value>);
126 void reject(v8::Local<v8::Value>); 147 void reject(v8::Local<v8::Value>);
127 void clear() { m_resolver.clear(); } 148 void clear() { m_resolver.clear(); }
128 149
129 private: 150 private:
130 ScriptValue m_resolver; 151 ScriptValue m_resolver;
131 }; 152 };
132 153
133 private: 154 private:
134 RefPtr<ScriptState> m_scriptState; 155 RefPtr<ScriptState> m_scriptState;
135 ScriptValue m_promise; 156 ScriptValue m_promise;
136 }; 157 };
137 158
138 } // namespace blink 159 } // namespace blink
139 160
140 161
141 #endif // ScriptPromise_h 162 #endif // ScriptPromise_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ExceptionState.cpp ('k') | Source/bindings/core/v8/ScriptPromise.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698