Bug 1771084 part 3 - Freeze builtins for the shared system global. r=mccr8,peterv
authorNika Layzell <nika@thelayzells.com>
Tue, 07 Jun 2022 19:44:59 +0000
changeset 619998 9bff6c2a2b5960a3ae4c813a60f1acb487b280cc
parent 619997 21b8a9b8b705145deb60e11ab97761d73dc62aed
child 619999 0e4c8788bb757864f7c8c388c54f6d50b053763e
push id39813
push usernfay@mozilla.com
push dateWed, 08 Jun 2022 03:52:13 +0000
treeherdermozilla-central@5a7069a5e368 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, peterv
bugs1771084
milestone103.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1771084 part 3 - Freeze builtins for the shared system global. r=mccr8,peterv Differential Revision: https://phabricator.services.mozilla.com/D147305
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/tests/browser/browser.ini
js/xpconnect/tests/browser/browser_freeze_builtins.js
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -596,17 +596,19 @@ mozJSComponentLoader::CollectReports(nsI
 }
 
 void mozJSComponentLoader::CreateLoaderGlobal(JSContext* aCx,
                                               const nsACString& aLocation,
                                               MutableHandleObject aGlobal) {
   auto backstagePass = MakeRefPtr<BackstagePass>();
   RealmOptions options;
 
-  options.creationOptions().setNewCompartmentInSystemZone();
+  options.creationOptions()
+      .setFreezeBuiltins(true)
+      .setNewCompartmentInSystemZone();
   xpc::SetPrefableRealmOptions(options);
 
   // Defer firing OnNewGlobalObject until after the __URI__ property has
   // been defined so the JS debugger can tell what module the global is
   // for
   RootedObject global(aCx);
   nsresult rv = xpc::InitClassesWithNewWrappedGlobal(
       aCx, static_cast<nsIGlobalObject*>(backstagePass),
--- a/js/xpconnect/tests/browser/browser.ini
+++ b/js/xpconnect/tests/browser/browser.ini
@@ -4,12 +4,13 @@ support-files =
   browser_deadObjectOnUnload.html
   browser_realm_key_object_prototype_top.html
   browser_realm_key_object_prototype_frame.html
   browser_realm_key_promise_top.html
   browser_realm_key_promise_frame.html
   browser_promise_userInteractionHandling.html
 [browser_dead_object.js]
 [browser_exception_leak.js]
+[browser_freeze_builtins.js]
 [browser_parent_process_hang_telemetry.js]
 [browser_realm_key_and_document_domain.js]
 [browser_promise_userInteractionHandling.js]
 [browser_import_mapped_jsm.js]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/browser/browser_freeze_builtins.js
@@ -0,0 +1,27 @@
+/* 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/.
+ */
+
+function checkCtor(global, name, description) {
+  ok(Object.isFrozen(global[name]), `${description} ${name} is frozen`);
+  ok(
+    Object.isSealed(global[name].prototype),
+    `${description} ${name}.prototype is sealed`
+  );
+
+  let descr = Object.getOwnPropertyDescriptor(global, name);
+  ok(!descr.configurable, `${description} ${name} should be non-configurable`);
+  ok(!descr.writable, `${description} ${name} should not be writable`);
+}
+
+function checkGlobal(global, description) {
+  checkCtor(global, "Object", description);
+  checkCtor(global, "Array", description);
+  checkCtor(global, "Function", description);
+}
+
+add_task(async function() {
+  let systemGlobal = Cu.getGlobalForObject(Services);
+  checkGlobal(systemGlobal, "system global");
+});