Title: [205023] trunk
Revision
205023
Author
[email protected]
Date
2016-08-26 10:05:21 -0700 (Fri, 26 Aug 2016)

Log Message

toString called on proxies returns incorrect tag
https://bugs.webkit.org/show_bug.cgi?id=161111

Reviewed by Benjamin Poulain.

This patch adds a new Method table function toStringName. This function
is used by Object.prototype.toString to create the string tag that it
inserts. Right now it only changes the stringification of proxy objects.
In future patches I plan to make it work for other classes of objects as
well.

* runtime/ClassInfo.h:
* runtime/JSCell.cpp:
(JSC::JSCell::toStringName):
* runtime/JSCell.h:
* runtime/JSObject.cpp:
(JSC::JSObject::toStringName):
* runtime/JSObject.h:
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncToString):
* runtime/ProxyObject.cpp:
(JSC::ProxyObject::toStringName):
* runtime/ProxyObject.h:

Modified Paths

Diff

Modified: trunk/JSTests/test262.yaml (205022 => 205023)


--- trunk/JSTests/test262.yaml	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/JSTests/test262.yaml	2016-08-26 17:05:21 UTC (rev 205023)
@@ -19480,9 +19480,9 @@
 - path: test262/test/built-ins/JSON/stringify/value-proxy-revoked.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/JSON/stringify/value-proxy.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/JSON/stringify/value-proxy.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Map/Symbol.species/length.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/propertyHelper.js"], []
 - path: test262/test/built-ins/Map/Symbol.species/length.js
@@ -22974,9 +22974,9 @@
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-139.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-14.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-14.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-140.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-140.js
@@ -23746,9 +23746,9 @@
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-36.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-37.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-37.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-38.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Object/create/15.2.3.5-4-38.js
@@ -34330,9 +34330,9 @@
 - path: test262/test/built-ins/Object/prototype/toString/proxy-revoked.js
   cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Object/prototype/toString/proxy.js
-  cmd: runTest262 :fail, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Object/prototype/toString/proxy.js
-  cmd: runTest262 :fail, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Object/prototype/toString/symbol-tag-non-str.js
   cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Object/prototype/toString/symbol-tag-non-str.js
@@ -73106,13 +73106,13 @@
 - path: test262/test/language/statements/class/definition/early-errors-class-method-arguments-in-formal-parameters.js
   cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js
-  cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js
-  cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals.js
-  cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals.js
-  cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/language/statements/class/definition/early-errors-class-method-body-contains-super-call.js
   cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/language/statements/class/definition/early-errors-class-method-body-contains-super-call.js

Modified: trunk/Source/_javascript_Core/ChangeLog (205022 => 205023)


--- trunk/Source/_javascript_Core/ChangeLog	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-08-26 17:05:21 UTC (rev 205023)
@@ -1,3 +1,29 @@
+2016-08-25  Keith Miller  <[email protected]>
+
+        toString called on proxies returns incorrect tag
+        https://bugs.webkit.org/show_bug.cgi?id=161111
+
+        Reviewed by Benjamin Poulain.
+
+        This patch adds a new Method table function toStringName. This function
+        is used by Object.prototype.toString to create the string tag that it
+        inserts. Right now it only changes the stringification of proxy objects.
+        In future patches I plan to make it work for other classes of objects as
+        well.
+
+        * runtime/ClassInfo.h:
+        * runtime/JSCell.cpp:
+        (JSC::JSCell::toStringName):
+        * runtime/JSCell.h:
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::toStringName):
+        * runtime/JSObject.h:
+        * runtime/ObjectPrototype.cpp:
+        (JSC::objectProtoFuncToString):
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::toStringName):
+        * runtime/ProxyObject.h:
+
 2016-08-26  Csaba Osztrogonác  <[email protected]>
 
         Fix the ENABLE(WEBASSEMBLY) build on Linux

Modified: trunk/Source/_javascript_Core/runtime/ClassInfo.h (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/ClassInfo.h	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/ClassInfo.h	2016-08-26 17:05:21 UTC (rev 205023)
@@ -91,6 +91,7 @@
 
     typedef String (*ClassNameFunctionPtr)(const JSObject*);
     ClassNameFunctionPtr className;
+    ClassNameFunctionPtr toStringName;
 
     typedef bool (*CustomHasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue);
     CustomHasInstanceFunctionPtr customHasInstance;
@@ -166,6 +167,7 @@
         &ClassName::getStructurePropertyNames, \
         &ClassName::getGenericPropertyNames, \
         &ClassName::className, \
+        &ClassName::toStringName, \
         &ClassName::customHasInstance, \
         &ClassName::defineOwnProperty, \
         &ClassName::slowDownAndWasteMemory, \

Modified: trunk/Source/_javascript_Core/runtime/JSCell.cpp (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/JSCell.cpp	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/JSCell.cpp	2016-08-26 17:05:21 UTC (rev 205023)
@@ -222,6 +222,12 @@
     return String();
 }
 
+String JSCell::toStringName(const JSObject*)
+{
+    RELEASE_ASSERT_NOT_REACHED();
+    return String();
+}
+
 const char* JSCell::className() const
 {
     return classInfo()->className;

Modified: trunk/Source/_javascript_Core/runtime/JSCell.h (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/JSCell.h	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/JSCell.h	2016-08-26 17:05:21 UTC (rev 205023)
@@ -212,6 +212,7 @@
     static NO_RETURN_DUE_TO_CRASH JSValue getPrototype(JSObject*, ExecState*);
 
     static String className(const JSObject*);
+    static String toStringName(const JSObject*);
     JS_EXPORT_PRIVATE static bool customHasInstance(JSObject*, ExecState*, JSValue);
     static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);

Modified: trunk/Source/_javascript_Core/runtime/JSObject.cpp (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-08-26 17:05:21 UTC (rev 205023)
@@ -308,6 +308,13 @@
     return info->className;
 }
 
+String JSObject::toStringName(const JSObject* object)
+{
+    const ClassInfo* info = object->classInfo();
+    ASSERT(info);
+    return info->methodTable.className(object);
+}
+
 String JSObject::calculatedClassName(JSObject* object)
 {
     String prototypeFunctionName;

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2016-08-26 17:05:21 UTC (rev 205023)
@@ -109,6 +109,12 @@
     JS_EXPORT_PRIVATE static String className(const JSObject*);
     JS_EXPORT_PRIVATE static String calculatedClassName(JSObject*);
 
+    // This function is what Object.prototype.toString() will use to get the name of
+    // an object when using Symbol.toStringTag fails. For the most part there is no
+    // difference between this and className(). The main use case is for new JS language
+    // objects to set the default tag to "Object".
+    JS_EXPORT_PRIVATE static String toStringName(const JSObject*);
+
     // This is the fully virtual [[GetPrototypeOf]] internal function defined
     // in the ECMAScript 6 specification. Use this when doing a [[GetPrototypeOf]] 
     // operation as dictated in the specification.

Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2016-08-26 17:05:21 UTC (rev 205023)
@@ -298,7 +298,7 @@
             }
         }
 
-        String newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->className(thisObject), "]");
+        String newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->toStringName(thisObject), "]");
         if (!newString)
             return throwOutOfMemoryError(exec);
 

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.cpp (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-08-26 17:05:21 UTC (rev 205023)
@@ -49,6 +49,14 @@
 {
 }
 
+String ProxyObject::toStringName(const JSObject* object)
+{
+    const JSObject* target = jsCast<const ProxyObject*>(object)->target();
+    if (isJSArray(target))
+        return target->classInfo()->methodTable.className(target);
+    return ASCIILiteral("Object");
+}
+
 Structure* ProxyObject::structureForTarget(JSGlobalObject* globalObject, JSValue target)
 {
     if (!target.isObject())

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.h (205022 => 205023)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.h	2016-08-26 17:02:37 UTC (rev 205022)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.h	2016-08-26 17:05:21 UTC (rev 205023)
@@ -75,6 +75,7 @@
     void finishCreation(VM&, ExecState*, JSValue target, JSValue handler);
     static Structure* structureForTarget(JSGlobalObject*, JSValue target);
 
+    static String toStringName(const JSObject*);
     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
     static CallType getCallData(JSCell*, CallData&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to