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

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
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"
36 #include "platform/heap/Handle.h" 37 #include "platform/heap/Handle.h"
37 #include "wtf/PassOwnPtr.h" 38 #include "wtf/PassOwnPtr.h"
38 #include "wtf/PassRefPtr.h" 39 #include "wtf/PassRefPtr.h"
40 #include "wtf/text/WTFString.h"
39 #include <v8.h> 41 #include <v8.h>
40 42
41 namespace blink { 43 namespace blink {
42 44
43 class DOMException; 45 class DOMException;
46 class ExceptionState;
44 47
45 // ScriptPromise is the class for representing Promise values in C++ world. 48 // ScriptPromise is the class for representing Promise values in C++ world.
46 // ScriptPromise holds a Promise. 49 // ScriptPromise holds a Promise.
47 // So holding a ScriptPromise as a member variable in DOM object causes 50 // So holding a ScriptPromise as a member variable in DOM object causes
48 // memory leaks since it has a reference from C++ to V8. 51 // memory leaks since it has a reference from C++ to V8.
49 // 52 //
50 class ScriptPromise FINAL { 53 class ScriptPromise FINAL {
51 public: 54 public:
52 // Constructs an empty promise. 55 // Constructs an empty promise.
53 ScriptPromise() { } 56 ScriptPromise() { }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // resolved with |value|. 111 // resolved with |value|.
109 // Returns |value| itself if it is a Promise. 112 // Returns |value| itself if it is a Promise.
110 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/); 113 static ScriptPromise cast(ScriptState*, const ScriptValue& /*value*/);
111 static ScriptPromise cast(ScriptState*, v8::Handle<v8::Value> /*value*/); 114 static ScriptPromise cast(ScriptState*, v8::Handle<v8::Value> /*value*/);
112 115
113 static ScriptPromise reject(ScriptState*, const ScriptValue&); 116 static ScriptPromise reject(ScriptState*, const ScriptValue&);
114 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>); 117 static ScriptPromise reject(ScriptState*, v8::Handle<v8::Value>);
115 118
116 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtrWillBeRa wPtr<DOMException>); 119 static ScriptPromise rejectWithDOMException(ScriptState*, PassRefPtrWillBeRa wPtr<DOMException>);
117 120
121 // static functions each of which returns a ScriptPromise rejected with
haraken 2014/08/01 17:04:24 Add a FIXME to remove these functions.
yhirano 2014/08/04 01:42:08 Done.
122 // the given error.
123 // They coresspond to functions in V8Binding.h, such as throwError,
124 // throwTypeError, etc.
125 static ScriptPromise rejectWithError(ScriptState*, V8ErrorType, const String &);
126 static ScriptPromise rejectWithTypeError(ScriptState*, const String&);
127 static ScriptPromise rejectWithArityTypeErrorForMethod(ScriptState*, const c har* method, const char* type, const char* valid, unsigned provided);
128 static ScriptPromise rejectWithArityTypeErrorForConstructor(ScriptState*, co nst char* type, const char* valid, unsigned provided);
129 static ScriptPromise rejectWithArityTypeError(ScriptState*, ExceptionState&, const char* valid, unsigned provided);
130 static ScriptPromise rejectWithMinimumArityTypeErrorForMethod(
131 ScriptState*, const char* method, const char* type, unsigned expected, u nsigned providedLeastNumMandatoryParams);
132 static ScriptPromise rejectWithMinimumArityTypeErrorForConstructor(
133 ScriptState*, const char* type, unsigned expected, unsigned providedLeas tNumMandatoryParams);
134 static ScriptPromise rejectWithMinimumArityTypeError(ScriptState*, Exception State&, unsigned expected, unsigned providedLeastNumMandatoryParams);
135
136 static v8::Local<v8::Promise> rejectRaw(v8::Isolate*, v8::Handle<v8::Value>) ;
137
118 // This is a utility class intended to be used internally. 138 // This is a utility class intended to be used internally.
119 // ScriptPromiseResolver is for general purpose. 139 // ScriptPromiseResolver is for general purpose.
120 class InternalResolver FINAL { 140 class InternalResolver FINAL {
121 public: 141 public:
122 explicit InternalResolver(ScriptState*); 142 explicit InternalResolver(ScriptState*);
123 v8::Local<v8::Promise> v8Promise() const; 143 v8::Local<v8::Promise> v8Promise() const;
124 ScriptPromise promise() const; 144 ScriptPromise promise() const;
125 void resolve(v8::Local<v8::Value>); 145 void resolve(v8::Local<v8::Value>);
126 void reject(v8::Local<v8::Value>); 146 void reject(v8::Local<v8::Value>);
127 void clear() { m_resolver.clear(); } 147 void clear() { m_resolver.clear(); }
128 148
129 private: 149 private:
130 ScriptValue m_resolver; 150 ScriptValue m_resolver;
131 }; 151 };
132 152
133 private: 153 private:
134 RefPtr<ScriptState> m_scriptState; 154 RefPtr<ScriptState> m_scriptState;
135 ScriptValue m_promise; 155 ScriptValue m_promise;
136 }; 156 };
137 157
138 } // namespace blink 158 } // namespace blink
139 159
140 160
141 #endif // ScriptPromise_h 161 #endif // ScriptPromise_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698