Changeset 205023 in webkit


Ignore:
Timestamp:
Aug 26, 2016 10:05:21 AM (8 years ago)
Author:
keith_miller@apple.com
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:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/test262.yaml

    r204851 r205023  
    1948119481  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
    1948219482- path: test262/test/built-ins/JSON/stringify/value-proxy.js
    19483   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
     19483  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
    1948419484- path: test262/test/built-ins/JSON/stringify/value-proxy.js
    19485   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
     19485  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
    1948619486- path: test262/test/built-ins/Map/Symbol.species/length.js
    1948719487  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/propertyHelper.js"], []
     
    2297522975  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
    2297622976- path: test262/test/built-ins/Object/create/15.2.3.5-4-14.js
    22977   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
     22977  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
    2297822978- path: test262/test/built-ins/Object/create/15.2.3.5-4-14.js
    22979   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
     22979  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
    2298022980- path: test262/test/built-ins/Object/create/15.2.3.5-4-140.js
    2298122981  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
     
    2374723747  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
    2374823748- path: test262/test/built-ins/Object/create/15.2.3.5-4-37.js
    23749   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
     23749  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
    2375023750- path: test262/test/built-ins/Object/create/15.2.3.5-4-37.js
    23751   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
     23751  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
    2375223752- path: test262/test/built-ins/Object/create/15.2.3.5-4-38.js
    2375323753  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
     
    3433134331  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
    3433234332- path: test262/test/built-ins/Object/prototype/toString/proxy.js
    34333   cmd: runTest262 :fail, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
     34333  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
    3433434334- path: test262/test/built-ins/Object/prototype/toString/proxy.js
    34335   cmd: runTest262 :fail, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
     34335  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
    3433634336- path: test262/test/built-ins/Object/prototype/toString/symbol-tag-non-str.js
    3433734337  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
     
    7310773107  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
    7310873108- path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js
    73109   cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
     73109  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
    7311073110- path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js
    73111   cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
     73111  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
    7311273112- path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals.js
    73113   cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
     73113  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
    7311473114- path: test262/test/language/statements/class/definition/early-errors-class-method-await-in-formals.js
    73115   cmd: runTest262 :fail, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
     73115  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
    7311673116- path: test262/test/language/statements/class/definition/early-errors-class-method-body-contains-super-call.js
    7311773117  cmd: runTest262 :normal, "SyntaxError", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
  • trunk/Source/JavaScriptCore/ChangeLog

    r205021 r205023  
     12016-08-25  Keith Miller  <keith_miller@apple.com>
     2
     3        toString called on proxies returns incorrect tag
     4        https://bugs.webkit.org/show_bug.cgi?id=161111
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        This patch adds a new Method table function toStringName. This function
     9        is used by Object.prototype.toString to create the string tag that it
     10        inserts. Right now it only changes the stringification of proxy objects.
     11        In future patches I plan to make it work for other classes of objects as
     12        well.
     13
     14        * runtime/ClassInfo.h:
     15        * runtime/JSCell.cpp:
     16        (JSC::JSCell::toStringName):
     17        * runtime/JSCell.h:
     18        * runtime/JSObject.cpp:
     19        (JSC::JSObject::toStringName):
     20        * runtime/JSObject.h:
     21        * runtime/ObjectPrototype.cpp:
     22        (JSC::objectProtoFuncToString):
     23        * runtime/ProxyObject.cpp:
     24        (JSC::ProxyObject::toStringName):
     25        * runtime/ProxyObject.h:
     26
    1272016-08-26  Csaba Osztrogonác  <ossy@webkit.org>
    228
  • trunk/Source/JavaScriptCore/runtime/ClassInfo.h

    r201853 r205023  
    9292    typedef String (*ClassNameFunctionPtr)(const JSObject*);
    9393    ClassNameFunctionPtr className;
     94    ClassNameFunctionPtr toStringName;
    9495
    9596    typedef bool (*CustomHasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue);
     
    167168        &ClassName::getGenericPropertyNames, \
    168169        &ClassName::className, \
     170        &ClassName::toStringName, \
    169171        &ClassName::customHasInstance, \
    170172        &ClassName::defineOwnProperty, \
  • trunk/Source/JavaScriptCore/runtime/JSCell.cpp

    r204912 r205023  
    223223}
    224224
     225String JSCell::toStringName(const JSObject*)
     226{
     227    RELEASE_ASSERT_NOT_REACHED();
     228    return String();
     229}
     230
    225231const char* JSCell::className() const
    226232{
  • trunk/Source/JavaScriptCore/runtime/JSCell.h

    r204912 r205023  
    213213
    214214    static String className(const JSObject*);
     215    static String toStringName(const JSObject*);
    215216    JS_EXPORT_PRIVATE static bool customHasInstance(JSObject*, ExecState*, JSValue);
    216217    static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r204912 r205023  
    307307    ASSERT(info);
    308308    return info->className;
     309}
     310
     311String JSObject::toStringName(const JSObject* object)
     312{
     313    const ClassInfo* info = object->classInfo();
     314    ASSERT(info);
     315    return info->methodTable.className(object);
    309316}
    310317
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r204912 r205023  
    109109    JS_EXPORT_PRIVATE static String className(const JSObject*);
    110110    JS_EXPORT_PRIVATE static String calculatedClassName(JSObject*);
     111
     112    // This function is what Object.prototype.toString() will use to get the name of
     113    // an object when using Symbol.toStringTag fails. For the most part there is no
     114    // difference between this and className(). The main use case is for new JS language
     115    // objects to set the default tag to "Object".
     116    JS_EXPORT_PRIVATE static String toStringName(const JSObject*);
    111117
    112118    // This is the fully virtual [[GetPrototypeOf]] internal function defined
  • trunk/Source/JavaScriptCore/runtime/ObjectPrototype.cpp

    r202890 r205023  
    299299        }
    300300
    301         String newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->className(thisObject), "]");
     301        String newString = WTF::tryMakeString("[object ", thisObject->methodTable(exec->vm())->toStringName(thisObject), "]");
    302302        if (!newString)
    303303            return throwOutOfMemoryError(exec);
  • trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp

    r204912 r205023  
    5050}
    5151
     52String ProxyObject::toStringName(const JSObject* object)
     53{
     54    const JSObject* target = jsCast<const ProxyObject*>(object)->target();
     55    if (isJSArray(target))
     56        return target->classInfo()->methodTable.className(target);
     57    return ASCIILiteral("Object");
     58}
     59
    5260Structure* ProxyObject::structureForTarget(JSGlobalObject* globalObject, JSValue target)
    5361{
  • trunk/Source/JavaScriptCore/runtime/ProxyObject.h

    r201703 r205023  
    7676    static Structure* structureForTarget(JSGlobalObject*, JSValue target);
    7777
     78    static String toStringName(const JSObject*);
    7879    static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
    7980    static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
Note: See TracChangeset for help on using the changeset viewer.