1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 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 13 * distribution. 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. 17 * 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. 29 */ 30 31 #ifndef V8BindingMacros_h 32 #define V8BindingMacros_h 33 34 namespace WebCore { 35 36 // Naming scheme: 37 // TO*_RETURNTYPE[_ARGTYPE]... 38 // ...using _DEFAULT instead of _ANY..._ANY when returing a default value. 39 40 #define TONATIVE_EXCEPTION(type, var, value) \ 41 type var; \ 42 { \ 43 v8::TryCatch block; \ 44 var = (value); \ 45 if (UNLIKELY(block.HasCaught())) \ 46 return block.ReThrow(); \ 47 } 48 49 #define TONATIVE_VOID_INTERNAL(var, value) \ 50 var = (value); \ 51 if (UNLIKELY(block.HasCaught())) \ 52 return; 53 54 #define TONATIVE_VOID(type, var, value) \ 55 type var; \ 56 { \ 57 v8::TryCatch block; \ 58 V8RethrowTryCatchScope rethrow(block); \ 59 TONATIVE_VOID_INTERNAL(var, value); \ 60 } 61 62 #define TONATIVE_DEFAULT(type, var, value, retVal) \ 63 type var; \ 64 { \ 65 v8::TryCatch block; \ 66 var = (value); \ 67 if (UNLIKELY(block.HasCaught())) { \ 68 block.ReThrow(); \ 69 return retVal; \ 70 } \ 71 } 72 73 #define TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState) \ 74 var = (value); \ 75 if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \ 76 return; \ 77 78 #define TONATIVE_VOID_EXCEPTIONSTATE(type, var, value, exceptionState) \ 79 type var; \ 80 { \ 81 v8::TryCatch block; \ 82 V8RethrowTryCatchScope rethrow(block); \ 83 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState); \ 84 } 85 86 #define TONATIVE_DEFAULT_EXCEPTIONSTATE(type, var, value, exceptionState, retVal) \ 87 type var; \ 88 { \ 89 v8::TryCatch block; \ 90 V8RethrowTryCatchScope rethrow(block); \ 91 var = (value); \ 92 if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \ 93 return retVal; \ 94 } 95 96 // type is an instance of class template V8StringResource<>, 97 // but Mode argument varies; using type (not Mode) for consistency 98 // with other macros and ease of code generation 99 #define TOSTRING_VOID(type, var, value) \ 100 type var(value); \ 101 if (UNLIKELY(!var.prepare())) \ 102 return; 103 104 #define TOSTRING_VOID_INTERNAL(var, value) \ 105 var = (value); \ 106 if (UNLIKELY(!var.prepare())) \ 107 return; 108 109 #define TOSTRING_DEFAULT(type, var, value, retVal) \ 110 type var(value); \ 111 if (UNLIKELY(!var.prepare())) \ 112 return retVal; 113 114 } // namespace WebCore 115 116 #endif // V8BindingMacros_h 117