Title: [249538] trunk
Revision
249538
Author
[email protected]
Date
2019-09-05 11:47:55 -0700 (Thu, 05 Sep 2019)

Log Message

LazyClassStructure::setConstructor should not store the constructor to the global object
https://bugs.webkit.org/show_bug.cgi?id=201484
<rdar://problem/50400451>

Reviewed by Yusuke Suzuki.

JSTests:

* stress/web-assembly-constructors-should-not-override-global-object-property.js: Added.

Source/_javascript_Core:

LazyClassStructure::setConstructor sets the constructor as a property of the global object.
This became a problem when it started being used for WebAssembly constructors, such as Module
and Instance, since they are properties of the WebAssembly object, not the global object. That
resulted in properties of the global object replaced whenever a lazy WebAssembly constructor
was first accessed. e.g.

globalThis.Module = x;
WebAssembly.Module;
globalThis.Module === WebAssembly.Module;

* runtime/LazyClassStructure.cpp:
(JSC::LazyClassStructure::Initializer::setConstructor):
* runtime/LazyClassStructure.h:
* runtime/Lookup.h:
(JSC::reifyStaticProperty):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (249537 => 249538)


--- trunk/JSTests/ChangeLog	2019-09-05 18:29:13 UTC (rev 249537)
+++ trunk/JSTests/ChangeLog	2019-09-05 18:47:55 UTC (rev 249538)
@@ -1,3 +1,13 @@
+2019-09-05  Tadeu Zagallo  <[email protected]>
+
+        LazyClassStructure::setConstructor should not store the constructor to the global object
+        https://bugs.webkit.org/show_bug.cgi?id=201484
+        <rdar://problem/50400451>
+
+        Reviewed by Yusuke Suzuki.
+
+        * stress/web-assembly-constructors-should-not-override-global-object-property.js: Added.
+
 2019-09-05  Yusuke Suzuki  <[email protected]>
 
         [JSC] Do not use FTLOutput::weakPointer directly

Added: trunk/JSTests/stress/web-assembly-constructors-should-not-override-global-object-property.js (0 => 249538)


--- trunk/JSTests/stress/web-assembly-constructors-should-not-override-global-object-property.js	                        (rev 0)
+++ trunk/JSTests/stress/web-assembly-constructors-should-not-override-global-object-property.js	2019-09-05 18:47:55 UTC (rev 249538)
@@ -0,0 +1,4 @@
+var originalModule = this.Module = {};
+WebAssembly.Module;
+if (Module !== originalModule)
+    throw new Error('Global property `Module` was overwritten!');

Modified: trunk/Source/_javascript_Core/ChangeLog (249537 => 249538)


--- trunk/Source/_javascript_Core/ChangeLog	2019-09-05 18:29:13 UTC (rev 249537)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-09-05 18:47:55 UTC (rev 249538)
@@ -1,3 +1,27 @@
+2019-09-05  Tadeu Zagallo  <[email protected]>
+
+        LazyClassStructure::setConstructor should not store the constructor to the global object
+        https://bugs.webkit.org/show_bug.cgi?id=201484
+        <rdar://problem/50400451>
+
+        Reviewed by Yusuke Suzuki.
+
+        LazyClassStructure::setConstructor sets the constructor as a property of the global object.
+        This became a problem when it started being used for WebAssembly constructors, such as Module
+        and Instance, since they are properties of the WebAssembly object, not the global object. That
+        resulted in properties of the global object replaced whenever a lazy WebAssembly constructor
+        was first accessed. e.g.
+
+        globalThis.Module = x;
+        WebAssembly.Module;
+        globalThis.Module === WebAssembly.Module;
+
+        * runtime/LazyClassStructure.cpp:
+        (JSC::LazyClassStructure::Initializer::setConstructor):
+        * runtime/LazyClassStructure.h:
+        * runtime/Lookup.h:
+        (JSC::reifyStaticProperty):
+
 2019-09-05  Yusuke Suzuki  <[email protected]>
 
         [JSC] Do not use FTLOutput::weakPointer directly

Modified: trunk/Source/_javascript_Core/runtime/LazyClassStructure.cpp (249537 => 249538)


--- trunk/Source/_javascript_Core/runtime/LazyClassStructure.cpp	2019-09-05 18:29:13 UTC (rev 249537)
+++ trunk/Source/_javascript_Core/runtime/LazyClassStructure.cpp	2019-09-05 18:47:55 UTC (rev 249538)
@@ -60,7 +60,7 @@
         prototype = structure->storedPrototypeObject();
 }
 
-void LazyClassStructure::Initializer::setConstructor(PropertyName propertyName, JSObject* constructor)
+void LazyClassStructure::Initializer::setConstructor(JSObject* constructor)
 {
     RELEASE_ASSERT(structure);
     RELEASE_ASSERT(prototype);
@@ -69,24 +69,9 @@
     this->constructor = constructor;
 
     prototype->putDirectWithoutTransition(vm, vm.propertyNames->constructor, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
-    if (!propertyName.isNull())
-        global->putDirect(vm, propertyName, constructor, static_cast<unsigned>(PropertyAttribute::DontEnum));
     classStructure.m_constructor.set(vm, global, constructor);
 }
 
-void LazyClassStructure::Initializer::setConstructor(JSObject* constructor)
-{
-    String name;
-    if (InternalFunction* internalFunction = jsDynamicCast<InternalFunction*>(vm, constructor))
-        name = internalFunction->name();
-    else if (JSFunction* function = jsDynamicCast<JSFunction*>(vm, constructor))
-        name = function->name(vm);
-    else
-        RELEASE_ASSERT_NOT_REACHED();
-    
-    setConstructor(Identifier::fromString(vm, name), constructor);
-}
-
 void LazyClassStructure::visit(SlotVisitor& visitor)
 {
     m_structure.visit(visitor);

Modified: trunk/Source/_javascript_Core/runtime/LazyClassStructure.h (249537 => 249538)


--- trunk/Source/_javascript_Core/runtime/LazyClassStructure.h	2019-09-05 18:29:13 UTC (rev 249537)
+++ trunk/Source/_javascript_Core/runtime/LazyClassStructure.h	2019-09-05 18:47:55 UTC (rev 249538)
@@ -49,12 +49,6 @@
         
         // Call this last. It's expected that the constructor is initialized to point to the
         // prototype already. This will automatically set prototype.constructor=constructor.
-        // This will also stuff the constructor into the global object at the given property.
-        // Note that the variant that does not take a property name attempts to deduce it by
-        // casting constructor to either JSFunction or InternalFunction. Also, you can pass
-        // nullptr for the property name, in which case we don't assign the property to the
-        // global object.
-        void setConstructor(PropertyName, JSObject* constructor);
         void setConstructor(JSObject* constructor);
         
         VM& vm;

Modified: trunk/Source/_javascript_Core/runtime/Lookup.h (249537 => 249538)


--- trunk/Source/_javascript_Core/runtime/Lookup.h	2019-09-05 18:29:13 UTC (rev 249537)
+++ trunk/Source/_javascript_Core/runtime/Lookup.h	2019-09-05 18:47:55 UTC (rev 249538)
@@ -361,9 +361,10 @@
     }
     
     if (value.attributes() & PropertyAttribute::ClassStructure) {
-        LazyClassStructure* structure = bitwise_cast<LazyClassStructure*>(
+        LazyClassStructure* lazyStructure = bitwise_cast<LazyClassStructure*>(
             bitwise_cast<char*>(&thisObj) + value.lazyClassStructureOffset());
-        structure->get(jsCast<JSGlobalObject*>(&thisObj));
+        JSObject* constructor = lazyStructure->constructor(jsCast<JSGlobalObject*>(&thisObj));
+        thisObj.putDirect(vm, propertyName, constructor, attributesForStructure(value.attributes()));
         return;
     }
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to