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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 type var(value); \ | 71 type var(value); \ |
72 if (UNLIKELY(!var.prepare())) \ | 72 if (UNLIKELY(!var.prepare())) \ |
73 return; | 73 return; |
74 | 74 |
75 #define TOSTRING_DEFAULT(type, var, value, retVal) \ | 75 #define TOSTRING_DEFAULT(type, var, value, retVal) \ |
76 type var(value); \ | 76 type var(value); \ |
77 if (UNLIKELY(!var.prepare())) \ | 77 if (UNLIKELY(!var.prepare())) \ |
78 return retVal; | 78 return retVal; |
79 | 79 |
80 template <typename T> | 80 template <typename T> |
81 inline bool v8Call(v8::MaybeLocal<T> maybeLocal, v8::Local<T>& outVariable, v8::
TryCatch& tryCatch) | |
82 { | |
83 bool success = maybeLocal.ToLocal(&outVariable); | |
84 ASSERT(success || tryCatch.HasCaught()); | |
85 return success; | |
86 } | |
87 | |
88 template <typename T> | |
89 inline bool getValueFromMaybe(v8::Maybe<T> maybe, T& outVariable) | 81 inline bool getValueFromMaybe(v8::Maybe<T> maybe, T& outVariable) |
90 { | 82 { |
91 if (maybe.IsNothing()) | 83 if (maybe.IsNothing()) |
92 return false; | 84 return false; |
93 outVariable = maybe.FromJust(); | 85 outVariable = maybe.FromJust(); |
94 return true; | 86 return true; |
95 } | 87 } |
96 | 88 |
97 inline bool v8CallBoolean(v8::Maybe<bool> maybe) | 89 inline bool v8CallBoolean(v8::Maybe<bool> maybe) |
98 { | 90 { |
99 bool result; | 91 bool result; |
100 return getValueFromMaybe(maybe, result) && result; | 92 return getValueFromMaybe(maybe, result) && result; |
101 } | 93 } |
102 | 94 |
| 95 template <typename T> |
| 96 inline bool v8Call(v8::Maybe<T> maybe, T& outVariable, v8::TryCatch& tryCatch) |
| 97 { |
| 98 bool success = getValueFromMaybe(maybe, outVariable); |
| 99 ASSERT(success || tryCatch.HasCaught()); |
| 100 return success; |
| 101 } |
| 102 |
| 103 template <typename T> |
| 104 inline bool v8Call(v8::MaybeLocal<T> maybeLocal, v8::Local<T>& outVariable, v8::
TryCatch& tryCatch) |
| 105 { |
| 106 bool success = maybeLocal.ToLocal(&outVariable); |
| 107 ASSERT(success || tryCatch.HasCaught()); |
| 108 return success; |
| 109 } |
| 110 |
103 // The last "else" is to avoid dangling else problem. | 111 // The last "else" is to avoid dangling else problem. |
104 #define V8_CALL(outVariable, handle, methodCall, failureExpression)
\ | 112 #define V8_CALL(outVariable, handle, methodCall, failureExpression)
\ |
105 if (handle.IsEmpty() || !getValueFromMaybe(handle->methodCall, outVariable))
{ \ | 113 if (handle.IsEmpty() || !getValueFromMaybe(handle->methodCall, outVariable))
{ \ |
106 failureExpression;
\ | 114 failureExpression;
\ |
107 } else | 115 } else |
108 | 116 |
109 } // namespace blink | 117 } // namespace blink |
110 | 118 |
111 #endif // V8BindingMacros_h | 119 #endif // V8BindingMacros_h |
OLD | NEW |