Title: [205131] trunk/Source/_javascript_Core
Revision
205131
Author
keith_mil...@apple.com
Date
2016-08-29 11:50:44 -0700 (Mon, 29 Aug 2016)

Log Message

Fix toStringName for Proxies and add support for normal instances
https://bugs.webkit.org/show_bug.cgi?id=161275

Reviewed by Saam Barati.

toStringName on proxies needs to follow the chain of proxies until it finds a non-proxy target.
Additionally, there are a couple of other classes that need to return "Object" for their
toStringName. Since this isn't tested by test262 I will propose a new test there.

* runtime/ClassInfo.h:
* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::toStringName):
* runtime/JSArrayBufferView.h:
* runtime/JSCell.cpp:
(JSC::JSCell::toStringName):
* runtime/JSCell.h:
* runtime/JSMap.cpp:
(JSC::JSMap::toStringName):
* runtime/JSMap.h:
* runtime/JSObject.cpp:
(JSC::JSObject::toStringName):
* runtime/JSObject.h:
* runtime/JSSet.cpp:
(JSC::JSSet::destroy):
(JSC::JSSet::toStringName):
* runtime/JSSet.h:
* runtime/JSWeakMap.cpp:
(JSC::JSWeakMap::toStringName):
* runtime/JSWeakMap.h:
* runtime/JSWeakSet.cpp:
(JSC::JSWeakSet::toStringName):
* runtime/JSWeakSet.h:
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncToString):
* runtime/ProxyObject.cpp:
(JSC::ProxyObject::toStringName):
* runtime/ProxyObject.h:
* runtime/SymbolObject.cpp:
(JSC::SymbolObject::toStringName):
* runtime/SymbolObject.h:
(JSC::SymbolObject::internalValue):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (205130 => 205131)


--- trunk/Source/_javascript_Core/ChangeLog	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-08-29 18:50:44 UTC (rev 205131)
@@ -1,3 +1,47 @@
+2016-08-29  Keith Miller  <keith_mil...@apple.com>
+
+        Fix toStringName for Proxies and add support for normal instances
+        https://bugs.webkit.org/show_bug.cgi?id=161275
+
+        Reviewed by Saam Barati.
+
+        toStringName on proxies needs to follow the chain of proxies until it finds a non-proxy target.
+        Additionally, there are a couple of other classes that need to return "Object" for their
+        toStringName. Since this isn't tested by test262 I will propose a new test there.
+
+        * runtime/ClassInfo.h:
+        * runtime/JSArrayBufferView.cpp:
+        (JSC::JSArrayBufferView::toStringName):
+        * runtime/JSArrayBufferView.h:
+        * runtime/JSCell.cpp:
+        (JSC::JSCell::toStringName):
+        * runtime/JSCell.h:
+        * runtime/JSMap.cpp:
+        (JSC::JSMap::toStringName):
+        * runtime/JSMap.h:
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::toStringName):
+        * runtime/JSObject.h:
+        * runtime/JSSet.cpp:
+        (JSC::JSSet::destroy):
+        (JSC::JSSet::toStringName):
+        * runtime/JSSet.h:
+        * runtime/JSWeakMap.cpp:
+        (JSC::JSWeakMap::toStringName):
+        * runtime/JSWeakMap.h:
+        * runtime/JSWeakSet.cpp:
+        (JSC::JSWeakSet::toStringName):
+        * runtime/JSWeakSet.h:
+        * runtime/ObjectPrototype.cpp:
+        (JSC::objectProtoFuncToString):
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::toStringName):
+        * runtime/ProxyObject.h:
+        * runtime/SymbolObject.cpp:
+        (JSC::SymbolObject::toStringName):
+        * runtime/SymbolObject.h:
+        (JSC::SymbolObject::internalValue):
+
 2016-08-29  Youenn Fablet  <you...@apple.com>
 
         [Fetch API] Response cloning should structureClone when teeing Response stream

Modified: trunk/Source/_javascript_Core/runtime/ClassInfo.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/ClassInfo.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/ClassInfo.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -91,8 +91,10 @@
 
     typedef String (*ClassNameFunctionPtr)(const JSObject*);
     ClassNameFunctionPtr className;
-    ClassNameFunctionPtr toStringName;
 
+    typedef String (*ToStringNameFunctionPtr)(const JSObject*, ExecState*);
+    ToStringNameFunctionPtr toStringName;
+
     typedef bool (*CustomHasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue);
     CustomHasInstanceFunctionPtr customHasInstance;
 

Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -36,6 +36,11 @@
     "ArrayBufferView", &Base::s_info, 0, CREATE_METHOD_TABLE(JSArrayBufferView)
 };
 
+String JSArrayBufferView::toStringName(const JSObject*, ExecState*)
+{
+    return ASCIILiteral("Object");
+}
+
 JSArrayBufferView::ConstructionContext::ConstructionContext(
     VM& vm, Structure* structure, uint32_t length, uint32_t elementSize,
     InitializationMode mode)

Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -179,6 +179,8 @@
 
     ArrayBuffer* existingBufferInButterfly();
 
+    static String toStringName(const JSObject*, ExecState*);
+
     CopyBarrier<char> m_vector; // this is really a void*, but void would not work here.
     uint32_t m_length;
     TypedArrayMode m_mode;

Modified: trunk/Source/_javascript_Core/runtime/JSCell.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSCell.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSCell.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -222,7 +222,7 @@
     return String();
 }
 
-String JSCell::toStringName(const JSObject*)
+String JSCell::toStringName(const JSObject*, ExecState*)
 {
     RELEASE_ASSERT_NOT_REACHED();
     return String();

Modified: trunk/Source/_javascript_Core/runtime/JSCell.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSCell.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSCell.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -212,7 +212,7 @@
     static NO_RETURN_DUE_TO_CRASH JSValue getPrototype(JSObject*, ExecState*);
 
     static String className(const JSObject*);
-    static String toStringName(const JSObject*);
+    static String toStringName(const JSObject*, ExecState*);
     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/JSMap.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSMap.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSMap.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -50,6 +50,11 @@
     return Base::estimatedSize(cell) + mapDataSize;
 }
 
+String JSMap::toStringName(const JSObject*, ExecState*)
+{
+    return ASCIILiteral("Object");
+}
+
 void JSMap::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     Base::visitChildren(cell, visitor);

Modified: trunk/Source/_javascript_Core/runtime/JSMap.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSMap.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSMap.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -125,6 +125,7 @@
     static size_t estimatedSize(JSCell*);
     static void visitChildren(JSCell*, SlotVisitor&);
     static void copyBackingStore(JSCell*, CopyVisitor&, CopyToken);
+    static String toStringName(const JSObject*, ExecState*);
 
     MapData m_mapData;
 };

Modified: trunk/Source/_javascript_Core/runtime/JSObject.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -308,7 +308,7 @@
     return info->className;
 }
 
-String JSObject::toStringName(const JSObject* object)
+String JSObject::toStringName(const JSObject* object, ExecState*)
 {
     const ClassInfo* info = object->classInfo();
     ASSERT(info);

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -113,7 +113,7 @@
     // 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*);
+    JS_EXPORT_PRIVATE static String toStringName(const JSObject*, ExecState*);
 
     // This is the fully virtual [[GetPrototypeOf]] internal function defined
     // in the ECMAScript 6 specification. Use this when doing a [[GetPrototypeOf]] 

Modified: trunk/Source/_javascript_Core/runtime/JSSet.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSSet.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSSet.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -43,6 +43,11 @@
     thisObject->JSSet::~JSSet();
 }
 
+String JSSet::toStringName(const JSObject*, ExecState*)
+{
+    return ASCIILiteral("Object");
+}
+
 size_t JSSet::estimatedSize(JSCell* cell)
 {
     JSSet* thisObject = jsCast<JSSet*>(cell);

Modified: trunk/Source/_javascript_Core/runtime/JSSet.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSSet.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSSet.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -120,6 +120,7 @@
     static size_t estimatedSize(JSCell*);
     static void visitChildren(JSCell*, SlotVisitor&);
     static void copyBackingStore(JSCell*, CopyVisitor&, CopyToken);
+    static String toStringName(const JSObject*, ExecState*);
 
     SetData m_setData;
 };

Modified: trunk/Source/_javascript_Core/runtime/JSWeakMap.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSWeakMap.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSWeakMap.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -49,4 +49,9 @@
     visitor.append(&thisObj->m_weakMapData);
 }
 
+String JSWeakMap::toStringName(const JSObject*, ExecState*)
+{
+    return ASCIILiteral("Object");
 }
+
+}

Modified: trunk/Source/_javascript_Core/runtime/JSWeakMap.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSWeakMap.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSWeakMap.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -72,6 +72,7 @@
 
     void finishCreation(VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
+    static String toStringName(const JSObject*, ExecState*);
 
     WriteBarrier<WeakMapData> m_weakMapData;
 };

Modified: trunk/Source/_javascript_Core/runtime/JSWeakSet.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSWeakSet.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSWeakSet.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -49,4 +49,9 @@
     visitor.append(&thisObj->m_weakMapData);
 }
 
+String JSWeakSet::toStringName(const JSC::JSObject*, ExecState*)
+{
+    return ASCIILiteral("Object");
 }
+
+}

Modified: trunk/Source/_javascript_Core/runtime/JSWeakSet.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/JSWeakSet.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/JSWeakSet.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -72,6 +72,7 @@
 
     void finishCreation(VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
+    static String toStringName(const JSObject*, ExecState*);
 
     WriteBarrier<WeakMapData> m_weakMapData;
 };

Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -298,7 +298,10 @@
             }
         }
 
-        String newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->toStringName(thisObject), "]");
+        String tag = thisObject->methodTable(exec->vm())->toStringName(thisObject, exec);
+        if (vm.exception())
+            return JSValue();
+        String newString = WTF::tryMakeString("[object ", WTFMove(tag), "]");
         if (!newString)
             return throwOutOfMemoryError(exec);
 

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "ProxyObject.h"
 
+#include "ArrayConstructor.h"
 #include "Error.h"
 #include "IdentifierInlines.h"
 #include "JSCJSValueInlines.h"
@@ -49,11 +50,19 @@
 {
 }
 
-String ProxyObject::toStringName(const JSObject* object)
+String ProxyObject::toStringName(const JSObject* object, ExecState* exec)
 {
-    const JSObject* target = jsCast<const ProxyObject*>(object)->target();
-    if (isJSArray(target))
-        return target->classInfo()->methodTable.className(target);
+    VM& vm = exec->vm();
+    const ProxyObject* proxy = jsCast<const ProxyObject*>(object);
+    while (proxy) {
+        const JSObject* target = proxy->target();
+        if (isArray(exec, target))
+            return target->classInfo()->methodTable.toStringName(target, exec);
+        if (vm.exception())
+            break;
+
+        proxy = jsDynamicCast<const ProxyObject*>(target);
+    }
     return ASCIILiteral("Object");
 }
 

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -75,7 +75,7 @@
     void finishCreation(VM&, ExecState*, JSValue target, JSValue handler);
     static Structure* structureForTarget(JSGlobalObject*, JSValue target);
 
-    static String toStringName(const JSObject*);
+    static String toStringName(const JSObject*, ExecState*);
     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
     static CallType getCallData(JSCell*, CallData&);

Modified: trunk/Source/_javascript_Core/runtime/SymbolObject.cpp (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/SymbolObject.cpp	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/SymbolObject.cpp	2016-08-29 18:50:44 UTC (rev 205131)
@@ -47,6 +47,11 @@
     setInternalValue(vm, symbol);
 }
 
+String SymbolObject::toStringName(const JSObject*, ExecState*)
+{
+    return ASCIILiteral("Object");
+}
+
 JSValue SymbolObject::defaultValue(const JSObject* object, ExecState*, PreferredPrimitiveType)
 {
     const SymbolObject* symbolObject = jsCast<const SymbolObject*>(object);

Modified: trunk/Source/_javascript_Core/runtime/SymbolObject.h (205130 => 205131)


--- trunk/Source/_javascript_Core/runtime/SymbolObject.h	2016-08-29 18:50:00 UTC (rev 205130)
+++ trunk/Source/_javascript_Core/runtime/SymbolObject.h	2016-08-29 18:50:44 UTC (rev 205131)
@@ -48,7 +48,7 @@
 
     DECLARE_EXPORT_INFO;
 
-    Symbol* internalValue() const { return asSymbol(JSWrapperObject::internalValue());}
+    Symbol* internalValue() const { return asSymbol(JSWrapperObject::internalValue()); }
 
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
     {
@@ -57,6 +57,8 @@
 
     static JSValue defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType);
 
+    static String toStringName(const JSObject*, ExecState*);
+
 protected:
     JS_EXPORT_PRIVATE void finishCreation(VM&, Symbol*);
     JS_EXPORT_PRIVATE SymbolObject(VM&, Structure*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to