2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 #ifndef V8BindingMacros_h
32 #define V8BindingMacros_h
37 // TO*_RETURNTYPE[_ARGTYPE]...
38 // ...using _DEFAULT instead of _ANY..._ANY when returing a default value.
40 #define TONATIVE_EXCEPTION(type, var, value) \
45 if (UNLIKELY(block.HasCaught())) \
46 return block.ReThrow(); \
49 #define TONATIVE_VOID_INTERNAL(var, value) \
51 if (UNLIKELY(block.HasCaught())) \
54 #define TONATIVE_VOID(type, var, value) \
58 V8RethrowTryCatchScope rethrow(block); \
59 TONATIVE_VOID_INTERNAL(var, value); \
62 #define TONATIVE_DEFAULT(type, var, value, retVal) \
67 if (UNLIKELY(block.HasCaught())) { \
73 // We need to cancel the exception propergation when we return a rejected
75 #define TONATIVE_VOID_PROMISE_INTERNAL(var, value, info) \
77 if (UNLIKELY(block.HasCaught())) { \
78 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
83 #define TONATIVE_VOID_PROMISE(type, var, value, info) \
87 TONATIVE_VOID_PROMISE_INTERNAL(var, value, info); \
91 #define TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState) \
93 if (UNLIKELY(exceptionState.throwIfNeeded())) \
96 #define TONATIVE_VOID_EXCEPTIONSTATE(type, var, value, exceptionState) \
99 if (UNLIKELY(exceptionState.throwIfNeeded())) \
102 #define TONATIVE_DEFAULT_EXCEPTIONSTATE(type, var, value, exceptionState, retVal) \
103 type var = (value); \
104 if (UNLIKELY(exceptionState.throwIfNeeded())) \
107 // We need to cancel the exception propergation when we return a rejected
109 #define TONATIVE_VOID_EXCEPTIONSTATE_PROMISE_INTERNAL(var, value, exceptionState, info, scriptState) \
111 if (UNLIKELY(exceptionState.hadException())) { \
112 v8SetReturnValue(info, exceptionState.reject(scriptState).v8Value()); \
116 #define TONATIVE_VOID_EXCEPTIONSTATE_PROMISE(type, var, value, exceptionState, info, scriptState) \
118 TONATIVE_VOID_EXCEPTIONSTATE_PROMISE_INTERNAL(var, value, exceptionState, info, scriptState);
120 // type is an instance of class template V8StringResource<>,
121 // but Mode argument varies; using type (not Mode) for consistency
122 // with other macros and ease of code generation
123 #define TOSTRING_VOID(type, var, value) \
125 if (UNLIKELY(!var.prepare())) \
128 #define TOSTRING_VOID_INTERNAL(var, value) \
130 if (UNLIKELY(!var.prepare())) \
133 #define TOSTRING_DEFAULT(type, var, value, retVal) \
135 if (UNLIKELY(!var.prepare())) \
138 // We need to cancel the exception propagation when we return a rejected
140 #define TOSTRING_VOID_EXCEPTIONSTATE_PROMISE_INTERNAL(var, value, exceptionState, info, scriptState) \
142 if (UNLIKELY(!var.prepare(exceptionState))) { \
143 v8SetReturnValue(info, exceptionState.reject(scriptState).v8Value()); \
149 #endif // V8BindingMacros_h