toolkit/components/reflect/reflect.cpp
author Bill McCloskey <billm@mozilla.com>
Mon, 12 Jun 2017 12:34:10 -0700
changeset 364767 9846de3bd9545fb2c2b803a36af85568ccf2473b
parent 330600 538094a7900cdec31ad57faf9a6937104edce590
child 448735 04f0bbf40bf36957dc1f72a8aae9916df0e3222f
permissions -rw-r--r--
Bug 1372405 - Provide names for all runnables in the tree (r=froydnj) MozReview-Commit-ID: DKR6ROiHRS7

/* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* 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 "reflect.h"
#include "jsapi.h"
#include "mozilla/ModuleUtils.h"
#include "nsMemory.h"
#include "nsString.h"
#include "nsNativeCharsetUtils.h"
#include "xpc_make_class.h"

#define JSREFLECT_CONTRACTID \
  "@mozilla.org/jsreflect;1"

#define JSREFLECT_CID \
{ 0x1a817186, 0x357a, 0x47cd, { 0x8a, 0xea, 0x28, 0x50, 0xd6, 0x0e, 0x95, 0x9e } }

namespace mozilla {
namespace reflect {

NS_GENERIC_FACTORY_CONSTRUCTOR(Module)

NS_IMPL_ISUPPORTS(Module, nsIXPCScriptable)

Module::Module() = default;

Module::~Module() = default;

#define XPC_MAP_CLASSNAME Module
#define XPC_MAP_QUOTED_CLASSNAME "Module"
#define XPC_MAP_FLAGS XPC_SCRIPTABLE_WANT_CALL
#include "xpc_map_end.h"

NS_IMETHODIMP
Module::Call(nsIXPConnectWrappedNative* wrapper,
             JSContext* cx,
             JSObject* obj,
             const JS::CallArgs& args,
             bool* _retval)
{
  JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
  if (!global)
    return NS_ERROR_NOT_AVAILABLE;

  *_retval = JS_InitReflectParse(cx, global);
  return NS_OK;
}

} // namespace reflect
} // namespace mozilla

NS_DEFINE_NAMED_CID(JSREFLECT_CID);

static const mozilla::Module::CIDEntry kReflectCIDs[] = {
  { &kJSREFLECT_CID, false, nullptr, mozilla::reflect::ModuleConstructor },
  { nullptr }
};

static const mozilla::Module::ContractIDEntry kReflectContracts[] = {
  { JSREFLECT_CONTRACTID, &kJSREFLECT_CID },
  { nullptr }
};

static const mozilla::Module kReflectModule = {
  mozilla::Module::kVersion,
  kReflectCIDs,
  kReflectContracts
};

NSMODULE_DEFN(jsreflect) = &kReflectModule;