| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_UTILITY_H__ | |
| 6 #define V8_UTILITY_H__ | |
| 7 | |
| 8 #include "V8Utilities.h" | |
| 9 | |
| 10 // To break a cycle dependency during upstreaming this block of code, | |
| 11 // ifdefing it out based on this #define. | |
| 12 // | |
| 13 // TODO(ajwong): After https://bugs.webkit.org/show_bug.cgi?id=25595 | |
| 14 // lands and is rolled down into chromium, migrate all headaers to use | |
| 15 // the code in V8Utilities.h directly, and then, remove this code. | |
| 16 #ifndef V8UTILITIES_DEFINED | |
| 17 namespace WebCore { | |
| 18 | |
| 19 class AllowAllocation { | |
| 20 public: | |
| 21 inline AllowAllocation() { | |
| 22 m_prev = m_current; | |
| 23 m_current = true; | |
| 24 } | |
| 25 inline ~AllowAllocation() { | |
| 26 m_current = m_prev; | |
| 27 } | |
| 28 static bool m_current; | |
| 29 private: | |
| 30 bool m_prev; | |
| 31 }; | |
| 32 | |
| 33 class SafeAllocation { | |
| 34 public: | |
| 35 static inline v8::Local<v8::Object> NewInstance( | |
| 36 v8::Handle<v8::Function> fun); | |
| 37 static inline v8::Local<v8::Object> NewInstance( | |
| 38 v8::Handle<v8::ObjectTemplate> templ); | |
| 39 static inline v8::Local<v8::Object> NewInstance( | |
| 40 v8::Handle<v8::Function> fun, int argc, v8::Handle<v8::Value> argv[]); | |
| 41 }; | |
| 42 | |
| 43 v8::Local<v8::Object> SafeAllocation::NewInstance( | |
| 44 v8::Handle<v8::Function> fun) { | |
| 45 if (fun.IsEmpty()) | |
| 46 return v8::Local<v8::Object>(); | |
| 47 AllowAllocation allow; | |
| 48 return fun->NewInstance(); | |
| 49 } | |
| 50 | |
| 51 v8::Local<v8::Object> SafeAllocation::NewInstance( | |
| 52 v8::Handle<v8::ObjectTemplate> templ) { | |
| 53 if (templ.IsEmpty()) return v8::Local<v8::Object>(); | |
| 54 AllowAllocation allow; | |
| 55 return templ->NewInstance(); | |
| 56 } | |
| 57 | |
| 58 v8::Local<v8::Object> SafeAllocation::NewInstance( | |
| 59 v8::Handle<v8::Function> fun, int argc, v8::Handle<v8::Value> argv[]) { | |
| 60 if (fun.IsEmpty()) return v8::Local<v8::Object>(); | |
| 61 AllowAllocation allow; | |
| 62 return fun->NewInstance(argc, argv); | |
| 63 } | |
| 64 | |
| 65 } // namespace WebCore | |
| 66 #endif // V8UTILITIES_DEFINED | |
| 67 | |
| 68 #endif // V8_UTILITY_H__ | |
| OLD | NEW |