Bug 1780517 - Part 3: Do not define undefined in self-hosted intrinsic. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Thu, 21 Jul 2022 14:23:07 +0000
changeset 624760 1300bb7f770b9b55b11b6d9f451f9b2168542cb0
parent 624759 28d512ea39d561a96dc2c77eaf92bf6ff93ab05b
child 624761 d6b5fc5037233a7ac896ca0ba56207b1307ef220
push id40013
push userapavel@mozilla.com
push dateThu, 21 Jul 2022 21:40:08 +0000
treeherdermozilla-central@675d5c0e4d1d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1780517
milestone104.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 1780517 - Part 3: Do not define undefined in self-hosted intrinsic. r=jandem Depends on D152390 Differential Revision: https://phabricator.services.mozilla.com/D152392
js/src/vm/GlobalObject.cpp
js/src/vm/GlobalObject.h
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -838,23 +838,16 @@ bool GlobalObject::addToVarNames(JSConte
 bool GlobalObject::createIntrinsicsHolder(JSContext* cx,
                                           Handle<GlobalObject*> global) {
   Rooted<NativeObject*> intrinsicsHolder(
       cx, NewPlainObjectWithProto(cx, nullptr, TenuredObject));
   if (!intrinsicsHolder) {
     return false;
   }
 
-  // Define a top-level property 'undefined' with the undefined value.
-  if (!DefineDataProperty(cx, intrinsicsHolder, cx->names().undefined,
-                          UndefinedHandleValue,
-                          JSPROP_PERMANENT | JSPROP_READONLY)) {
-    return false;
-  }
-
   // Install the intrinsics holder on the global.
   global->data().intrinsicsHolder.init(intrinsicsHolder);
   return true;
 }
 
 /* static */
 bool GlobalObject::getSelfHostedFunction(JSContext* cx,
                                          Handle<GlobalObject*> global,
--- a/js/src/vm/GlobalObject.h
+++ b/js/src/vm/GlobalObject.h
@@ -915,16 +915,19 @@ class GlobalObject : public NativeObject
     }
 
     return false;
   }
 
   static bool getIntrinsicValue(JSContext* cx, Handle<GlobalObject*> global,
                                 Handle<PropertyName*> name,
                                 MutableHandleValue value) {
+    // `undefined` in self-hosted JS code should be emitted as JSOp::Undefined.
+    MOZ_ASSERT(name != cx->names().undefined);
+
     if (global->maybeGetIntrinsicValue(name, value.address(), cx)) {
       return true;
     }
     return getIntrinsicValueSlow(cx, global, name, value);
   }
 
   static bool getIntrinsicValueSlow(JSContext* cx, Handle<GlobalObject*> global,
                                     Handle<PropertyName*> name,