2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-01-28 17:34:30 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/CallbackInterface.h"
|
|
|
|
#include "jsapi.h"
|
2021-07-13 14:52:43 +03:00
|
|
|
#include "js/CallAndConstruct.h" // JS::IsCallable
|
2018-09-05 12:25:42 +03:00
|
|
|
#include "js/CharacterEncoding.h"
|
2021-07-13 14:52:42 +03:00
|
|
|
#include "js/PropertyAndElement.h" // JS_GetProperty, JS_GetPropertyById
|
2013-01-28 17:34:30 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-06-17 21:07:03 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2013-01-28 17:34:30 +04:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2013-01-28 17:34:30 +04:00
|
|
|
|
2014-06-05 22:47:13 +04:00
|
|
|
bool CallbackInterface::GetCallableProperty(
|
2020-03-07 02:05:16 +03:00
|
|
|
BindingCallContext& cx, JS::Handle<jsid> aPropId,
|
2013-04-26 21:41:21 +04:00
|
|
|
JS::MutableHandle<JS::Value> aCallable) {
|
2020-05-21 17:09:02 +03:00
|
|
|
JS::Rooted<JSObject*> obj(cx, CallbackKnownNotGray());
|
|
|
|
if (!JS_GetPropertyById(cx, obj, aPropId, aCallable)) {
|
2013-01-28 17:34:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-25 15:13:28 +04:00
|
|
|
if (!aCallable.isObject() || !JS::IsCallable(&aCallable.toObject())) {
|
2022-02-10 12:13:17 +03:00
|
|
|
JS::RootedString propId(cx, aPropId.toString());
|
2018-09-05 16:05:03 +03:00
|
|
|
JS::UniqueChars propName = JS_EncodeStringToUTF8(cx, propId);
|
2018-09-05 12:25:42 +03:00
|
|
|
nsPrintfCString description("Property '%s'", propName.get());
|
2020-03-07 02:05:16 +03:00
|
|
|
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>(description.get());
|
2013-01-28 17:34:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|