michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/CallbackInterface.h" michael@0: #include "jsapi.h" michael@0: #include "mozilla/dom/BindingUtils.h" michael@0: #include "nsPrintfCString.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: bool michael@0: CallbackInterface::GetCallableProperty(JSContext* cx, const char* aPropName, michael@0: JS::MutableHandle aCallable) michael@0: { michael@0: if (!JS_GetProperty(cx, CallbackPreserveColor(), aPropName, aCallable)) { michael@0: return false; michael@0: } michael@0: if (!aCallable.isObject() || michael@0: !JS_ObjectIsCallable(cx, &aCallable.toObject())) { michael@0: nsPrintfCString description("Property '%s'", aPropName); michael@0: ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get()); michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla