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