summaryrefslogtreecommitdiff
path: root/components/perf
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-02-12 17:47:03 +0000
committerMatt A. Tobin <email@mattatobin.com>2022-02-12 14:23:18 -0600
commitf66babd8b8368ada3e5aa29cdef1c77291ee4ddd (patch)
treee3842e2a6bf19090185f9c475b3846e1bb79ac97 /components/perf
downloadGRE-f66babd8b8368ada3e5aa29cdef1c77291ee4ddd.tar.gz
Create the Goanna Runtime Environment
Diffstat (limited to 'components/perf')
-rw-r--r--components/perf/.eslintrc.js7
-rw-r--r--components/perf/PerfMeasurement.cpp120
-rw-r--r--components/perf/PerfMeasurement.h30
-rw-r--r--components/perf/PerfMeasurement.jsm19
-rw-r--r--components/perf/moz.build18
5 files changed, 194 insertions, 0 deletions
diff --git a/components/perf/.eslintrc.js b/components/perf/.eslintrc.js
new file mode 100644
index 000000000..4e6d4bcf0
--- /dev/null
+++ b/components/perf/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "../../../testing/mochitest/chrome.eslintrc.js"
+ ]
+};
diff --git a/components/perf/PerfMeasurement.cpp b/components/perf/PerfMeasurement.cpp
new file mode 100644
index 000000000..1b211b79c
--- /dev/null
+++ b/components/perf/PerfMeasurement.cpp
@@ -0,0 +1,120 @@
+/* -*- 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 "PerfMeasurement.h"
+#include "jsperf.h"
+#include "mozilla/ModuleUtils.h"
+#include "nsMemory.h"
+#include "mozilla/Preferences.h"
+#include "mozJSComponentLoader.h"
+#include "nsZipArchive.h"
+#include "xpc_make_class.h"
+
+#define JSPERF_CONTRACTID \
+ "@mozilla.org/jsperf;1"
+
+#define JSPERF_CID \
+{ 0x421c38e6, 0xaee0, 0x4509, \
+ { 0xa0, 0x25, 0x13, 0x0f, 0x43, 0x78, 0x03, 0x5a } }
+
+namespace mozilla {
+namespace jsperf {
+
+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"
+
+static bool
+SealObjectAndPrototype(JSContext* cx, JS::Handle<JSObject *> parent, const char* name)
+{
+ JS::Rooted<JS::Value> prop(cx);
+ if (!JS_GetProperty(cx, parent, name, &prop))
+ return false;
+
+ if (prop.isUndefined()) {
+ // Pretend we sealed the object.
+ return true;
+ }
+
+ JS::Rooted<JSObject*> obj(cx, prop.toObjectOrNull());
+ if (!JS_GetProperty(cx, obj, "prototype", &prop))
+ return false;
+
+ JS::Rooted<JSObject*> prototype(cx, prop.toObjectOrNull());
+ return JS_FreezeObject(cx, obj) && JS_FreezeObject(cx, prototype);
+}
+
+static bool
+InitAndSealPerfMeasurementClass(JSContext* cx, JS::Handle<JSObject*> global)
+{
+ // Init the PerfMeasurement class
+ if (!JS::RegisterPerfMeasurement(cx, global))
+ return false;
+
+ // Seal up Object, Function, and Array and their prototypes. (This single
+ // object instance is shared amongst everyone who imports the jsperf module.)
+ if (!SealObjectAndPrototype(cx, global, "Object") ||
+ !SealObjectAndPrototype(cx, global, "Function") ||
+ !SealObjectAndPrototype(cx, global, "Array"))
+ return false;
+
+ // Finally, seal the global object, for good measure. (But not recursively;
+ // this breaks things.)
+ return JS_FreezeObject(cx, global);
+}
+
+NS_IMETHODIMP
+Module::Call(nsIXPConnectWrappedNative* wrapper,
+ JSContext* cx,
+ JSObject* obj,
+ const JS::CallArgs& args,
+ bool* _retval)
+{
+
+ mozJSComponentLoader* loader = mozJSComponentLoader::Get();
+ JS::Rooted<JSObject*> targetObj(cx);
+ nsresult rv = loader->FindTargetObject(cx, &targetObj);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ *_retval = InitAndSealPerfMeasurementClass(cx, targetObj);
+ return NS_OK;
+}
+
+} // namespace jsperf
+} // namespace mozilla
+
+NS_DEFINE_NAMED_CID(JSPERF_CID);
+
+static const mozilla::Module::CIDEntry kPerfCIDs[] = {
+ { &kJSPERF_CID, false, nullptr, mozilla::jsperf::ModuleConstructor },
+ { nullptr }
+};
+
+static const mozilla::Module::ContractIDEntry kPerfContracts[] = {
+ { JSPERF_CONTRACTID, &kJSPERF_CID },
+ { nullptr }
+};
+
+static const mozilla::Module kPerfModule = {
+ mozilla::Module::kVersion,
+ kPerfCIDs,
+ kPerfContracts
+};
+
+NSMODULE_DEFN(jsperf) = &kPerfModule;
diff --git a/components/perf/PerfMeasurement.h b/components/perf/PerfMeasurement.h
new file mode 100644
index 000000000..b158d1685
--- /dev/null
+++ b/components/perf/PerfMeasurement.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_PERFMEASUREMENT_H
+#define COMPONENTS_PERFMEASUREMENT_H
+
+#include "nsIXPCScriptable.h"
+#include "mozilla/Attributes.h"
+
+namespace mozilla {
+namespace jsperf {
+
+class Module final : public nsIXPCScriptable
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCSCRIPTABLE
+
+ Module();
+
+private:
+ ~Module();
+};
+
+} // namespace jsperf
+} // namespace mozilla
+
+#endif
diff --git a/components/perf/PerfMeasurement.jsm b/components/perf/PerfMeasurement.jsm
new file mode 100644
index 000000000..29a221c6f
--- /dev/null
+++ b/components/perf/PerfMeasurement.jsm
@@ -0,0 +1,19 @@
+/* -*- 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 = [ "PerfMeasurement" ];
+
+/*
+ * This is the js module for jsperf. Import it like so:
+ * Components.utils.import("resource://gre/modules/PerfMeasurement.jsm");
+ *
+ * This will create a 'PerfMeasurement' class. Instances of this class can
+ * be used to benchmark browser operations.
+ *
+ * For documentation on the API, see js/src/perf/jsperf.h.
+ *
+ */
+
+Components.classes["@mozilla.org/jsperf;1"].createInstance()();
diff --git a/components/perf/moz.build b/components/perf/moz.build
new file mode 100644
index 000000000..099a1c4eb
--- /dev/null
+++ b/components/perf/moz.build
@@ -0,0 +1,18 @@
+# -*- 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 += [
+ 'PerfMeasurement.cpp',
+]
+
+EXTRA_JS_MODULES += [
+ 'PerfMeasurement.jsm',
+]
+
+FINAL_LIBRARY = 'xul'
+
+LOCAL_INCLUDES += [
+ '/js/xpconnect/loader',
+]