OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 V8BindingMacros_h | 31 #ifndef V8BindingMacros_h |
32 #define V8BindingMacros_h | 32 #define V8BindingMacros_h |
33 | 33 |
| 34 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/ScriptValue.h" |
| 36 #include <v8.h> |
| 37 |
34 namespace blink { | 38 namespace blink { |
35 | 39 |
36 // type is an instance of class template V8StringResource<>, | 40 // type is an instance of class template V8StringResource<>, |
37 // but Mode argument varies; using type (not Mode) for consistency | 41 // but Mode argument varies; using type (not Mode) for consistency |
38 // with other macros and ease of code generation | 42 // with other macros and ease of code generation |
39 #define TOSTRING_VOID(type, var, value) \ | 43 #define TOSTRING_VOID(type, var, value) \ |
40 type var(value); \ | 44 type var(value); \ |
41 if (UNLIKELY(!var.prepare())) \ | 45 if (UNLIKELY(!var.prepare())) \ |
42 return; | 46 return; |
43 | 47 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 { | 100 { |
97 return maybe.FromJust(); | 101 return maybe.FromJust(); |
98 } | 102 } |
99 | 103 |
100 template <typename T> | 104 template <typename T> |
101 inline v8::Local<T> v8CallOrCrash(v8::MaybeLocal<T> maybeLocal) | 105 inline v8::Local<T> v8CallOrCrash(v8::MaybeLocal<T> maybeLocal) |
102 { | 106 { |
103 return maybeLocal.ToLocalChecked(); | 107 return maybeLocal.ToLocalChecked(); |
104 } | 108 } |
105 | 109 |
| 110 v8::MaybeLocal<v8::Value> v8CallExtra(ScriptState* scriptState, const char* name
, size_t numArgs, v8::Local<v8::Value>* args) |
| 111 { |
| 112 v8::Isolate* isolate = scriptState->isolate(); |
| 113 v8::Local<v8::Context> context = scriptState->context(); |
| 114 v8::Local<v8::Value> undefined = v8::Undefined(isolate); |
| 115 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name)
.v8Value(); |
| 116 v8::Local<v8::Function> function = functionValue.As<v8::Function>(); |
| 117 return function->Call(context, undefined, numArgs, args); |
| 118 } |
| 119 |
| 120 template <size_t N> |
| 121 v8::MaybeLocal<v8::Value> v8CallExtra(ScriptState* scriptState, const char* name
, v8::Local<v8::Value>(&args)[N]) |
| 122 { |
| 123 return v8CallExtra(scriptState, name, N, args); |
| 124 } |
| 125 |
| 126 template <size_t N> |
| 127 v8::Local<v8::Value> v8CallExtraOrCrash(ScriptState* scriptState, const char* na
me, v8::Local<v8::Value>(&args)[N]) |
| 128 { |
| 129 return v8CallOrCrash(v8CallExtra(scriptState, name, N, args)); |
| 130 } |
| 131 |
106 // The last "else" is to avoid dangling else problem. | 132 // The last "else" is to avoid dangling else problem. |
107 #define V8_CALL(outVariable, handle, methodCall, failureExpression)
\ | 133 #define V8_CALL(outVariable, handle, methodCall, failureExpression)
\ |
108 if (handle.IsEmpty() || !v8Call(handle->methodCall, outVariable)) { \ | 134 if (handle.IsEmpty() || !v8Call(handle->methodCall, outVariable)) { \ |
109 failureExpression;
\ | 135 failureExpression;
\ |
110 } else | 136 } else |
111 | 137 |
112 } // namespace blink | 138 } // namespace blink |
113 | 139 |
114 #endif // V8BindingMacros_h | 140 #endif // V8BindingMacros_h |
OLD | NEW |