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