// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_UTILITY_H__ #define V8_UTILITY_H__ namespace WebCore { class AllowAllocation { public: inline AllowAllocation() { m_prev = m_current; m_current = true; } inline ~AllowAllocation() { m_current = m_prev; } static bool m_current; private: bool m_prev; }; class SafeAllocation { public: static inline v8::Local NewInstance( v8::Handle fun); static inline v8::Local NewInstance( v8::Handle templ); static inline v8::Local NewInstance( v8::Handle fun, int argc, v8::Handle argv[]); }; v8::Local SafeAllocation::NewInstance( v8::Handle fun) { if (fun.IsEmpty()) return v8::Local(); AllowAllocation allow; return fun->NewInstance(); } v8::Local SafeAllocation::NewInstance( v8::Handle templ) { if (templ.IsEmpty()) return v8::Local(); AllowAllocation allow; return templ->NewInstance(); } v8::Local SafeAllocation::NewInstance( v8::Handle fun, int argc, v8::Handle argv[]) { if (fun.IsEmpty()) return v8::Local(); AllowAllocation allow; return fun->NewInstance(argc, argv); } } // namespace WebCore #endif // V8_UTILITY_H__