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" | |
yhirano
2016/01/17 23:59:55
Not used?
domenic
2016/01/19 21:41:00
It turns out getExtrasExports returns a ScriptValu
| |
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 // These are utiltiies for calling functions added to the V8 extras binding obje ct. | |
111 | |
112 inline v8::MaybeLocal<v8::Value> v8CallExtraHelper(ScriptState* scriptState, con st char* name, size_t numArgs, v8::Local<v8::Value>* args) | |
113 { | |
114 v8::Isolate* isolate = scriptState->isolate(); | |
115 v8::Local<v8::Context> context = scriptState->context(); | |
116 v8::Local<v8::Value> undefined = v8::Undefined(isolate); | |
117 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name) .v8Value(); | |
118 v8::Local<v8::Function> function = functionValue.As<v8::Function>(); | |
119 return function->Call(context, undefined, numArgs, args); | |
haraken
2016/01/16 03:54:31
We want to unify all Function::Calls into V8Script
domenic
2016/01/19 21:41:00
Done; PTAL.
| |
120 } | |
121 | |
122 template <size_t N> | |
123 v8::MaybeLocal<v8::Value> v8CallExtra(ScriptState* scriptState, const char* name , v8::Local<v8::Value>(&args)[N]) | |
124 { | |
125 return v8CallExtraHelper(scriptState, name, N, args); | |
126 } | |
127 | |
128 template <size_t N> | |
129 v8::Local<v8::Value> v8CallExtraOrCrash(ScriptState* scriptState, const char* na me, v8::Local<v8::Value>(&args)[N]) | |
130 { | |
131 return v8CallOrCrash(v8CallExtraHelper(scriptState, name, N, args)); | |
132 } | |
133 | |
106 // The last "else" is to avoid dangling else problem. | 134 // The last "else" is to avoid dangling else problem. |
107 #define V8_CALL(outVariable, handle, methodCall, failureExpression) \ | 135 #define V8_CALL(outVariable, handle, methodCall, failureExpression) \ |
108 if (handle.IsEmpty() || !v8Call(handle->methodCall, outVariable)) { \ | 136 if (handle.IsEmpty() || !v8Call(handle->methodCall, outVariable)) { \ |
109 failureExpression; \ | 137 failureExpression; \ |
110 } else | 138 } else |
111 | 139 |
112 } // namespace blink | 140 } // namespace blink |
113 | 141 |
114 #endif // V8BindingMacros_h | 142 #endif // V8BindingMacros_h |
OLD | NEW |