Title: [273816] trunk
Revision
273816
Author
shvaikal...@gmail.com
Date
2021-03-03 08:37:24 -0800 (Wed, 03 Mar 2021)

Log Message

Add JSModuleNamespaceObject::deletePropertyByIndex() method
https://bugs.webkit.org/show_bug.cgi?id=222611

Reviewed by Yusuke Suzuki.

JSTests:

* modules/arbitrary-module-names-indexed.js: Added.
* modules/arbitrary-module-names/export-indexed.js: Added.

Source/_javascript_Core:

r270923 introduced arbitrary module namespace identifiers, enabling indexed identifiers
to be exported. While they were already handled by getOwnPropertySlotByIndex(), indexed
[[Delete]] override was absent, which prevented TypeError from being thrown.

This patch adds the missing method, aligning JSC with the spec [1].

[1]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-delete-p

* runtime/JSModuleNamespaceObject.cpp:
(JSC::JSModuleNamespaceObject::deleteProperty):
(JSC::JSModuleNamespaceObject::deletePropertyByIndex):
* runtime/JSModuleNamespaceObject.h:

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (273815 => 273816)


--- trunk/JSTests/ChangeLog	2021-03-03 16:34:03 UTC (rev 273815)
+++ trunk/JSTests/ChangeLog	2021-03-03 16:37:24 UTC (rev 273816)
@@ -1,3 +1,13 @@
+2021-03-03  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        Add JSModuleNamespaceObject::deletePropertyByIndex() method
+        https://bugs.webkit.org/show_bug.cgi?id=222611
+
+        Reviewed by Yusuke Suzuki.
+
+        * modules/arbitrary-module-names-indexed.js: Added.
+        * modules/arbitrary-module-names/export-indexed.js: Added.
+
 2021-03-02  Alexey Shvayka  <shvaikal...@gmail.com>
 
         TypedArray's [[DefineOwnProperty]] should throw in case of failure

Added: trunk/JSTests/modules/arbitrary-module-names/export-indexed.js (0 => 273816)


--- trunk/JSTests/modules/arbitrary-module-names/export-indexed.js	                        (rev 0)
+++ trunk/JSTests/modules/arbitrary-module-names/export-indexed.js	2021-03-03 16:37:24 UTC (rev 273816)
@@ -0,0 +1,6 @@
+var a = 0;
+var b = 1;
+export {
+    a as "0",
+    b as "1",
+};

Added: trunk/JSTests/modules/arbitrary-module-names-indexed.js (0 => 273816)


--- trunk/JSTests/modules/arbitrary-module-names-indexed.js	                        (rev 0)
+++ trunk/JSTests/modules/arbitrary-module-names-indexed.js	2021-03-03 16:37:24 UTC (rev 273816)
@@ -0,0 +1,22 @@
+import { shouldBe, shouldThrow } from "./resources/assert.js";
+import * as ns from "./arbitrary-module-names/export-indexed.js";
+
+(() => {
+    for (let i = 0; i < 1e5; i++) {
+        shouldBe(ns[0], 0);
+        shouldBe(Reflect.get(ns, 1), 1);
+        shouldBe(ns[2], undefined);
+
+        shouldThrow(() => { ns[0] = 1; }, `TypeError: Attempted to assign to readonly property.`);
+        shouldBe(Reflect.set(ns, 1, 1), false);
+        shouldThrow(() => { ns[2] = 2; }, `TypeError: Attempted to assign to readonly property.`);
+
+        shouldBe(0 in ns, true);
+        shouldBe(Reflect.has(ns, 1), true);
+        shouldBe(2 in ns, false);
+
+        shouldThrow(() => { delete ns[0]; }, `TypeError: Unable to delete property.`);
+        shouldBe(Reflect.deleteProperty(ns, 1), false);
+        shouldBe(delete ns[2], true);
+    }
+})();

Modified: trunk/Source/_javascript_Core/ChangeLog (273815 => 273816)


--- trunk/Source/_javascript_Core/ChangeLog	2021-03-03 16:34:03 UTC (rev 273815)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-03-03 16:37:24 UTC (rev 273816)
@@ -1,3 +1,23 @@
+2021-03-03  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        Add JSModuleNamespaceObject::deletePropertyByIndex() method
+        https://bugs.webkit.org/show_bug.cgi?id=222611
+
+        Reviewed by Yusuke Suzuki.
+
+        r270923 introduced arbitrary module namespace identifiers, enabling indexed identifiers
+        to be exported. While they were already handled by getOwnPropertySlotByIndex(), indexed
+        [[Delete]] override was absent, which prevented TypeError from being thrown.
+
+        This patch adds the missing method, aligning JSC with the spec [1].
+
+        [1]: https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-delete-p
+
+        * runtime/JSModuleNamespaceObject.cpp:
+        (JSC::JSModuleNamespaceObject::deleteProperty):
+        (JSC::JSModuleNamespaceObject::deletePropertyByIndex):
+        * runtime/JSModuleNamespaceObject.h:
+
 2021-03-03  Don Olmstead  <don.olmst...@sony.com>
 
         [CMake] _javascript_Core GLib headers should be copies

Modified: trunk/Source/_javascript_Core/runtime/JSModuleNamespaceObject.cpp (273815 => 273816)


--- trunk/Source/_javascript_Core/runtime/JSModuleNamespaceObject.cpp	2021-03-03 16:34:03 UTC (rev 273815)
+++ trunk/Source/_javascript_Core/runtime/JSModuleNamespaceObject.cpp	2021-03-03 16:37:24 UTC (rev 273816)
@@ -212,7 +212,7 @@
 
 bool JSModuleNamespaceObject::deleteProperty(JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName, DeletePropertySlot& slot)
 {
-    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-delete-p
+    // https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-delete-p
     JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);
     if (propertyName.isSymbol())
         return Base::deleteProperty(thisObject, globalObject, propertyName, slot);
@@ -220,6 +220,13 @@
     return !thisObject->m_exports.contains(propertyName.uid());
 }
 
+bool JSModuleNamespaceObject::deletePropertyByIndex(JSCell* cell, JSGlobalObject* globalObject, unsigned propertyName)
+{
+    VM& vm = globalObject->vm();
+    JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);
+    return !thisObject->m_exports.contains(Identifier::from(vm, propertyName).impl());
+}
+
 void JSModuleNamespaceObject::getOwnPropertyNames(JSObject* cell, JSGlobalObject* globalObject, PropertyNameArray& propertyNames, DontEnumPropertiesMode mode)
 {
     VM& vm = globalObject->vm();

Modified: trunk/Source/_javascript_Core/runtime/JSModuleNamespaceObject.h (273815 => 273816)


--- trunk/Source/_javascript_Core/runtime/JSModuleNamespaceObject.h	2021-03-03 16:34:03 UTC (rev 273815)
+++ trunk/Source/_javascript_Core/runtime/JSModuleNamespaceObject.h	2021-03-03 16:37:24 UTC (rev 273816)
@@ -57,6 +57,7 @@
     JS_EXPORT_PRIVATE static bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&);
     JS_EXPORT_PRIVATE static bool putByIndex(JSCell*, JSGlobalObject*, unsigned propertyName, JSValue, bool shouldThrow);
     JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&);
+    JS_EXPORT_PRIVATE static bool deletePropertyByIndex(JSCell*, JSGlobalObject*, unsigned propertyName);
     JS_EXPORT_PRIVATE static void getOwnPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArray&, DontEnumPropertiesMode);
     JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to