CallbackInterface.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/dom/CallbackInterface.h"
  6. #include "jsapi.h"
  7. #include "mozilla/dom/BindingUtils.h"
  8. #include "nsPrintfCString.h"
  9. namespace mozilla {
  10. namespace dom {
  11. bool
  12. CallbackInterface::GetCallableProperty(JSContext* cx, JS::Handle<jsid> aPropId,
  13. JS::MutableHandle<JS::Value> aCallable)
  14. {
  15. if (!JS_GetPropertyById(cx, CallbackKnownNotGray(), aPropId, aCallable)) {
  16. return false;
  17. }
  18. if (!aCallable.isObject() ||
  19. !JS::IsCallable(&aCallable.toObject())) {
  20. char* propName =
  21. JS_EncodeString(cx, JS_FORGET_STRING_FLATNESS(JSID_TO_FLAT_STRING(aPropId)));
  22. nsPrintfCString description("Property '%s'", propName);
  23. JS_free(cx, propName);
  24. ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
  25. return false;
  26. }
  27. return true;
  28. }
  29. } // namespace dom
  30. } // namespace mozilla