| OLD | NEW |
| 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 Loading... |
| 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/v8/ScriptFunction.h" | 34 #include "bindings/v8/ScriptFunction.h" |
| 35 #include "bindings/v8/ScriptValue.h" | 35 #include "bindings/v8/ScriptValue.h" |
| 36 #include "bindings/v8/V8ThrowException.h" |
| 36 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 38 #include "wtf/text/WTFString.h" |
| 37 #include <v8.h> | 39 #include <v8.h> |
| 38 | 40 |
| 39 namespace WebCore { | 41 namespace WebCore { |
| 40 | 42 |
| 43 class ExceptionState; |
| 41 class ExecutionContext; | 44 class ExecutionContext; |
| 42 | 45 |
| 43 // ScriptPromise is the class for representing Promise values in C++ world. | 46 // ScriptPromise is the class for representing Promise values in C++ world. |
| 44 // ScriptPromise holds a Promise. | 47 // ScriptPromise holds a Promise. |
| 45 // So holding a ScriptPromise as a member variable in DOM object causes | 48 // So holding a ScriptPromise as a member variable in DOM object causes |
| 46 // memory leaks since it has a reference from C++ to V8. | 49 // memory leaks since it has a reference from C++ to V8. |
| 47 // | 50 // |
| 48 class ScriptPromise { | 51 class ScriptPromise { |
| 49 public: | 52 public: |
| 50 // Constructs an empty promise. | 53 // Constructs an empty promise. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 91 |
| 89 void clear() | 92 void clear() |
| 90 { | 93 { |
| 91 m_promise.clear(); | 94 m_promise.clear(); |
| 92 } | 95 } |
| 93 | 96 |
| 94 // Constructs and returns a ScriptPromise from |value|. | 97 // Constructs and returns a ScriptPromise from |value|. |
| 95 // if |value| is not a Promise object, returns a Promise object | 98 // if |value| is not a Promise object, returns a Promise object |
| 96 // resolved with |value|. | 99 // resolved with |value|. |
| 97 static ScriptPromise cast(const ScriptValue& /*value*/); | 100 static ScriptPromise cast(const ScriptValue& /*value*/); |
| 101 static ScriptPromise cast(v8::Handle<v8::Value>, v8::Isolate*); |
| 102 |
| 103 static ScriptPromise reject(const ScriptValue&); |
| 104 static ScriptPromise reject(v8::Handle<v8::Value>, v8::Isolate*); |
| 105 |
| 106 // static functions each of which returns a ScriptPromise rejected with |
| 107 // the given error. |
| 108 // They coresspond to functions in V8Binding.h, such as throwError, |
| 109 // throwTypeError, etc. |
| 110 static ScriptPromise rejectWithError(V8ErrorType, const String&, v8::Isolate
*); |
| 111 static ScriptPromise rejectWithError(v8::Handle<v8::Value>, v8::Isolate*); |
| 112 static ScriptPromise rejectWithTypeError(const String&, v8::Isolate*); |
| 113 static ScriptPromise rejectWithArityTypeErrorForMethod( |
| 114 const char* method, const char* type, unsigned expected, unsigned provid
edLeastNumMandatoryParams, v8::Isolate*); |
| 115 static ScriptPromise rejectWithArityTypeErrorForConstructor( |
| 116 const char* type, unsigned expected, unsigned providedLeastNumMandatoryP
arams, v8::Isolate*); |
| 117 static ScriptPromise rejectWithArityTypeError(ExceptionState&, unsigned expe
cted, unsigned providedLeastNumMandatoryParams); |
| 98 | 118 |
| 99 private: | 119 private: |
| 100 ScriptValue m_promise; | 120 ScriptValue m_promise; |
| 101 }; | 121 }; |
| 102 | 122 |
| 103 } // namespace WebCore | 123 } // namespace WebCore |
| 104 | 124 |
| 105 | 125 |
| 106 #endif // ScriptPromise_h | 126 #endif // ScriptPromise_h |
| OLD | NEW |