tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

JSDebugger.cpp (1308B)


      1 /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*-
      2 */
      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 "JSDebugger.h"
      8 #include "nsThreadUtils.h"
      9 #include "jsapi.h"
     10 #include "jsfriendapi.h"
     11 #include "js/Wrapper.h"
     12 #include "nsServiceManagerUtils.h"
     13 
     14 #define JSDEBUGGER_CONTRACTID "@mozilla.org/jsdebugger;1"
     15 
     16 #define JSDEBUGGER_CID \
     17  {0x0365cbd5, 0xd46e, 0x4e94, {0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63}}
     18 
     19 namespace mozilla::jsdebugger {
     20 
     21 NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger)
     22 
     23 JSDebugger::JSDebugger() = default;
     24 
     25 JSDebugger::~JSDebugger() = default;
     26 
     27 NS_IMETHODIMP
     28 JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx) {
     29  if (!global.isObject()) {
     30    return NS_ERROR_INVALID_ARG;
     31  }
     32 
     33  JS::Rooted<JSObject*> obj(cx, &global.toObject());
     34  obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
     35  if (!obj) {
     36    return NS_ERROR_FAILURE;
     37  }
     38 
     39  if (!JS_IsGlobalObject(obj)) {
     40    return NS_ERROR_INVALID_ARG;
     41  }
     42 
     43  JSAutoRealm ar(cx, obj);
     44  if (!JS_DefineDebuggerObject(cx, obj)) {
     45    return NS_ERROR_FAILURE;
     46  }
     47 
     48  return NS_OK;
     49 }
     50 
     51 }  // namespace mozilla::jsdebugger