summaryrefslogtreecommitdiff
path: root/components/reflect
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2021-11-14 01:30:12 -0500
committerMatt A. Tobin <email@mattatobin.com>2021-11-14 01:30:12 -0500
commit43fa0a71c814e902165782680f2f9705e3c234c9 (patch)
tree0ab3c66e8432febc00c18c036706c7ff43c11799 /components/reflect
parent2fccdffac3075ee72087f9ee153204b02c7d931a (diff)
downloadaura-central-43fa0a71c814e902165782680f2f9705e3c234c9.tar.gz
Issue %3005 - Move toolkit/components to components/
Diffstat (limited to 'components/reflect')
-rw-r--r--components/reflect/moz.build14
-rw-r--r--components/reflect/reflect.cpp77
-rw-r--r--components/reflect/reflect.h30
-rw-r--r--components/reflect/reflect.jsm24
4 files changed, 145 insertions, 0 deletions
diff --git a/components/reflect/moz.build b/components/reflect/moz.build
new file mode 100644
index 000000000..9a3f27116
--- /dev/null
+++ b/components/reflect/moz.build
@@ -0,0 +1,14 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# 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/.
+
+SOURCES += [
+ 'reflect.cpp',
+]
+
+EXTRA_JS_MODULES += [
+ 'reflect.jsm',
+]
+
+FINAL_LIBRARY = 'xul'
diff --git a/components/reflect/reflect.cpp b/components/reflect/reflect.cpp
new file mode 100644
index 000000000..cd46baf7c
--- /dev/null
+++ b/components/reflect/reflect.cpp
@@ -0,0 +1,77 @@
+/* -*- 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()
+{
+}
+
+Module::~Module()
+{
+}
+
+#define XPC_MAP_CLASSNAME Module
+#define XPC_MAP_QUOTED_CLASSNAME "Module"
+#define XPC_MAP_WANT_CALL
+#define XPC_MAP_FLAGS nsIXPCScriptable::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;
diff --git a/components/reflect/reflect.h b/components/reflect/reflect.h
new file mode 100644
index 000000000..6f5237104
--- /dev/null
+++ b/components/reflect/reflect.h
@@ -0,0 +1,30 @@
+/* -*- 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/. */
+
+#ifndef COMPONENTS_REFLECT_H
+#define COMPONENTS_REFLECT_H
+
+#include "nsIXPCScriptable.h"
+#include "mozilla/Attributes.h"
+
+namespace mozilla {
+namespace reflect {
+
+class Module final : public nsIXPCScriptable
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCSCRIPTABLE
+
+ Module();
+
+private:
+ ~Module();
+};
+
+} // namespace reflect
+} // namespace mozilla
+
+#endif
diff --git a/components/reflect/reflect.jsm b/components/reflect/reflect.jsm
new file mode 100644
index 000000000..fd1729dd9
--- /dev/null
+++ b/components/reflect/reflect.jsm
@@ -0,0 +1,24 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+this.EXPORTED_SYMBOLS = [ "Reflect" ];
+
+/*
+ * This is the js module for Reflect. Import it like so:
+ * Components.utils.import("resource://gre/modules/reflect.jsm");
+ *
+ * This will create a 'Reflect' object, which provides an interface to the
+ * SpiderMonkey parser API.
+ *
+ * For documentation on the API, see:
+ * https://developer.mozilla.org/en/SpiderMonkey/Parser_API
+ *
+ */
+
+
+// Initialize the ctypes object. You do not need to do this yourself.
+const init = Components.classes["@mozilla.org/jsreflect;1"].createInstance();
+init();
+this.Reflect = Reflect;