Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/ductwork/debugger/JSDebugger.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*-  Mode: C++; tab-width: 2; 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
6
#include "JSDebugger.h"
7
#include "nsIXPConnect.h"
8
#include "nsThreadUtils.h"
9
#include "jsapi.h"
10
#include "jsfriendapi.h"
11
#include "js/Wrapper.h"
12
#include "mozilla/ModuleUtils.h"
13
#include "nsServiceManagerUtils.h"
14
#include "nsMemory.h"
15
16
#define JSDEBUGGER_CONTRACTID \
17
  "@mozilla.org/jsdebugger;1"
18
19
#define JSDEBUGGER_CID \
20
{ 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } }
21
22
namespace mozilla {
23
namespace jsdebugger {
24
25
NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger)
26
27
NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger)
28
29
JSDebugger::JSDebugger()
30
0
{
31
0
}
32
33
JSDebugger::~JSDebugger()
34
0
{
35
0
}
36
37
NS_IMETHODIMP
38
JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx)
39
0
{
40
0
  if (!global.isObject()) {
41
0
    return NS_ERROR_INVALID_ARG;
42
0
  }
43
0
44
0
  JS::RootedObject obj(cx, &global.toObject());
45
0
  obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
46
0
  if (!obj) {
47
0
    return NS_ERROR_FAILURE;
48
0
  }
49
0
50
0
  if (!JS_IsGlobalObject(obj)) {
51
0
    return NS_ERROR_INVALID_ARG;
52
0
  }
53
0
54
0
  JSAutoRealm ar(cx, obj);
55
0
  if (!JS_DefineDebuggerObject(cx, obj)) {
56
0
    return NS_ERROR_FAILURE;
57
0
  }
58
0
59
0
  if (recordreplay::IsRecordingOrReplaying() || recordreplay::IsMiddleman()) {
60
0
    if (!recordreplay::DefineRecordReplayControlObject(cx, obj)) {
61
0
      return NS_ERROR_FAILURE;
62
0
    }
63
0
  } else {
64
0
    // Define an empty RecordReplayControl object, to avoid reference errors in
65
0
    // scripts that run in normal processes. DefineRecordReplayControlObject
66
0
    // can't be called in normal processes.
67
0
    JS::RootedObject staticObject(cx, JS_NewObject(cx, nullptr));
68
0
    if (!staticObject || !JS_DefineProperty(cx, obj, "RecordReplayControl", staticObject, 0)) {
69
0
      return NS_ERROR_FAILURE;
70
0
    }
71
0
  }
72
0
73
0
  return NS_OK;
74
0
}
75
76
} // namespace jsdebugger
77
} // namespace mozilla
78
79
NS_DEFINE_NAMED_CID(JSDEBUGGER_CID);
80
81
static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = {
82
  { &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor },
83
  { nullptr }
84
};
85
86
static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = {
87
  { JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID },
88
  { nullptr }
89
};
90
91
static const mozilla::Module kJSDebuggerModule = {
92
  mozilla::Module::kVersion,
93
  kJSDebuggerCIDs,
94
  kJSDebuggerContracts
95
};
96
97
NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule;