Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/bindings/CallbackInterface.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "mozilla/dom/CallbackInterface.h"
8
#include "jsapi.h"
9
#include "js/CharacterEncoding.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "nsPrintfCString.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
bool
17
CallbackInterface::GetCallableProperty(JSContext* cx, JS::Handle<jsid> aPropId,
18
                                       JS::MutableHandle<JS::Value> aCallable)
19
0
{
20
0
  if (!JS_GetPropertyById(cx, CallbackKnownNotGray(), aPropId, aCallable)) {
21
0
    return false;
22
0
  }
23
0
  if (!aCallable.isObject() ||
24
0
      !JS::IsCallable(&aCallable.toObject())) {
25
0
    JS::RootedString propId(cx, JS_FORGET_STRING_FLATNESS(JSID_TO_FLAT_STRING(aPropId)));
26
0
    JS::UniqueChars propName = JS_EncodeStringToUTF8(cx, propId);
27
0
    nsPrintfCString description("Property '%s'", propName.get());
28
0
    ThrowErrorMessage(cx, MSG_NOT_CALLABLE, description.get());
29
0
    return false;
30
0
  }
31
0
32
0
  return true;
33
0
}
34
35
} // namespace dom
36
} // namespace mozilla