From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- toolkit/components/perf/.eslintrc.js | 7 ++ toolkit/components/perf/PerfMeasurement.cpp | 120 ++++++++++++++++++++++++++++ toolkit/components/perf/PerfMeasurement.h | 30 +++++++ toolkit/components/perf/PerfMeasurement.jsm | 19 +++++ toolkit/components/perf/chrome.ini | 3 + toolkit/components/perf/moz.build | 21 +++++ toolkit/components/perf/test_pm.xul | 48 +++++++++++ 7 files changed, 248 insertions(+) create mode 100644 toolkit/components/perf/.eslintrc.js create mode 100644 toolkit/components/perf/PerfMeasurement.cpp create mode 100644 toolkit/components/perf/PerfMeasurement.h create mode 100644 toolkit/components/perf/PerfMeasurement.jsm create mode 100644 toolkit/components/perf/chrome.ini create mode 100644 toolkit/components/perf/moz.build create mode 100644 toolkit/components/perf/test_pm.xul (limited to 'toolkit/components/perf') diff --git a/toolkit/components/perf/.eslintrc.js b/toolkit/components/perf/.eslintrc.js new file mode 100644 index 000000000..4e6d4bcf0 --- /dev/null +++ b/toolkit/components/perf/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../testing/mochitest/chrome.eslintrc.js" + ] +}; diff --git a/toolkit/components/perf/PerfMeasurement.cpp b/toolkit/components/perf/PerfMeasurement.cpp new file mode 100644 index 000000000..1b211b79c --- /dev/null +++ b/toolkit/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 parent, const char* name) +{ + JS::Rooted prop(cx); + if (!JS_GetProperty(cx, parent, name, &prop)) + return false; + + if (prop.isUndefined()) { + // Pretend we sealed the object. + return true; + } + + JS::Rooted obj(cx, prop.toObjectOrNull()); + if (!JS_GetProperty(cx, obj, "prototype", &prop)) + return false; + + JS::Rooted prototype(cx, prop.toObjectOrNull()); + return JS_FreezeObject(cx, obj) && JS_FreezeObject(cx, prototype); +} + +static bool +InitAndSealPerfMeasurementClass(JSContext* cx, JS::Handle 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 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/toolkit/components/perf/PerfMeasurement.h b/toolkit/components/perf/PerfMeasurement.h new file mode 100644 index 000000000..b158d1685 --- /dev/null +++ b/toolkit/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/toolkit/components/perf/PerfMeasurement.jsm b/toolkit/components/perf/PerfMeasurement.jsm new file mode 100644 index 000000000..29a221c6f --- /dev/null +++ b/toolkit/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/toolkit/components/perf/chrome.ini b/toolkit/components/perf/chrome.ini new file mode 100644 index 000000000..eaa3c2401 --- /dev/null +++ b/toolkit/components/perf/chrome.ini @@ -0,0 +1,3 @@ +[DEFAULT] + +[test_pm.xul] diff --git a/toolkit/components/perf/moz.build b/toolkit/components/perf/moz.build new file mode 100644 index 000000000..d153244c5 --- /dev/null +++ b/toolkit/components/perf/moz.build @@ -0,0 +1,21 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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', +] + +MOCHITEST_CHROME_MANIFESTS += ['chrome.ini'] diff --git a/toolkit/components/perf/test_pm.xul b/toolkit/components/perf/test_pm.xul new file mode 100644 index 000000000..7dbf27b92 --- /dev/null +++ b/toolkit/components/perf/test_pm.xul @@ -0,0 +1,48 @@ + + + + + + + + +

+ +

+  
+  
-- cgit v1.2.3