1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/CallbackInterface.h"
9 #include "js/CharacterEncoding.h"
10 #include "mozilla/dom/BindingUtils.h"
11 #include "nsPrintfCString.h"
13 namespace mozilla::dom
{
15 bool CallbackInterface::GetCallableProperty(
16 BindingCallContext
& cx
, JS::Handle
<jsid
> aPropId
,
17 JS::MutableHandle
<JS::Value
> aCallable
) {
18 JS::Rooted
<JSObject
*> obj(cx
, CallbackKnownNotGray());
19 if (!JS_GetPropertyById(cx
, obj
, aPropId
, aCallable
)) {
22 if (!aCallable
.isObject() || !JS::IsCallable(&aCallable
.toObject())) {
23 JS::RootedString
propId(cx
, JSID_TO_STRING(aPropId
));
24 JS::UniqueChars propName
= JS_EncodeStringToUTF8(cx
, propId
);
25 nsPrintfCString
description("Property '%s'", propName
.get());
26 cx
.ThrowErrorMessage
<MSG_NOT_CALLABLE
>(description
.get());
33 } // namespace mozilla::dom