Chromium Code Reviews| 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 "bindings/core/v8/V8ScriptRunner.h" | |
|
haraken
2016/01/19 21:49:48
Hmm, V8BindingMacros.h is intended to be a collect
| |
| 37 #include <v8.h> | |
| 38 | |
| 34 namespace blink { | 39 namespace blink { |
| 35 | 40 |
| 36 // type is an instance of class template V8StringResource<>, | 41 // type is an instance of class template V8StringResource<>, |
| 37 // but Mode argument varies; using type (not Mode) for consistency | 42 // but Mode argument varies; using type (not Mode) for consistency |
| 38 // with other macros and ease of code generation | 43 // with other macros and ease of code generation |
| 39 #define TOSTRING_VOID(type, var, value) \ | 44 #define TOSTRING_VOID(type, var, value) \ |
| 40 type var(value); \ | 45 type var(value); \ |
| 41 if (UNLIKELY(!var.prepare())) \ | 46 if (UNLIKELY(!var.prepare())) \ |
| 42 return; | 47 return; |
| 43 | 48 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 { | 101 { |
| 97 return maybe.FromJust(); | 102 return maybe.FromJust(); |
| 98 } | 103 } |
| 99 | 104 |
| 100 template <typename T> | 105 template <typename T> |
| 101 inline v8::Local<T> v8CallOrCrash(v8::MaybeLocal<T> maybeLocal) | 106 inline v8::Local<T> v8CallOrCrash(v8::MaybeLocal<T> maybeLocal) |
| 102 { | 107 { |
| 103 return maybeLocal.ToLocalChecked(); | 108 return maybeLocal.ToLocalChecked(); |
| 104 } | 109 } |
| 105 | 110 |
| 111 // These are utiltiies for calling functions added to the V8 extras binding obje ct. | |
| 112 | |
| 113 inline v8::MaybeLocal<v8::Value> v8CallExtraHelper(ScriptState* scriptState, con st char* name, size_t numArgs, v8::Local<v8::Value>* args) | |
| 114 { | |
| 115 v8::Isolate* isolate = scriptState->isolate(); | |
| 116 ExecutionContext* ec = scriptState->executionContext(); | |
| 117 v8::Local<v8::Value> undefined = v8::Undefined(isolate); | |
| 118 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name) .v8Value(); | |
| 119 v8::Local<v8::Function> function = functionValue.As<v8::Function>(); | |
| 120 return V8ScriptRunner::callFunction(function, ec, undefined, numArgs, args, isolate); | |
| 121 } | |
| 122 | |
| 123 template <size_t N> | |
| 124 v8::MaybeLocal<v8::Value> v8CallExtra(ScriptState* scriptState, const char* name , v8::Local<v8::Value>(&args)[N]) | |
| 125 { | |
| 126 return v8CallExtraHelper(scriptState, name, N, args); | |
| 127 } | |
| 128 | |
| 129 template <size_t N> | |
| 130 v8::Local<v8::Value> v8CallExtraOrCrash(ScriptState* scriptState, const char* na me, v8::Local<v8::Value>(&args)[N]) | |
| 131 { | |
| 132 return v8CallOrCrash(v8CallExtraHelper(scriptState, name, N, args)); | |
| 133 } | |
| 134 | |
| 106 // The last "else" is to avoid dangling else problem. | 135 // The last "else" is to avoid dangling else problem. |
| 107 #define V8_CALL(outVariable, handle, methodCall, failureExpression) \ | 136 #define V8_CALL(outVariable, handle, methodCall, failureExpression) \ |
| 108 if (handle.IsEmpty() || !v8Call(handle->methodCall, outVariable)) { \ | 137 if (handle.IsEmpty() || !v8Call(handle->methodCall, outVariable)) { \ |
| 109 failureExpression; \ | 138 failureExpression; \ |
| 110 } else | 139 } else |
| 111 | 140 |
| 112 } // namespace blink | 141 } // namespace blink |
| 113 | 142 |
| 114 #endif // V8BindingMacros_h | 143 #endif // V8BindingMacros_h |
| OLD | NEW |