Changeset 91224 in webkit


Ignore:
Timestamp:
Jul 18, 2011 5:25:49 PM (13 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=64678
Fix bugs in Object.prototype this handling.

Reviewed by Oliver Hunt.

Source/JavaScriptCore:

undefined/null this values should throw TypeErrors, not convert to the global object,
also, to toLocaleString should be calling the ToObject & invoking the object's toString
function, even for values that are already strings.

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncValueOf):
(JSC::objectProtoFuncHasOwnProperty):
(JSC::objectProtoFuncIsPrototypeOf):
(JSC::objectProtoFuncPropertyIsEnumerable):
(JSC::objectProtoFuncToLocaleString):
(JSC::objectProtoFuncToString):

LayoutTests:

  • fast/js/resources/js-test-pre.js:
    • Updated harness to not call Object.prototype.toString on undefined.
  • fast/js/eval-var-decl-expected.txt:
  • fast/js/object-prototype-properties-expected.txt: Added.
  • fast/js/object-prototype-properties.html: Added.
  • fast/js/object-prototype-toLocaleString-expected.txt
  • fast/js/script-tests/eval-var-decl.js:
    • Fix test case, calling hasProperty with undefined as the this value should throw.
  • fast/js/script-tests/object-prototype-properties.js: Added.
    • Place for test cases for Object.prototype properties; to being with, check that calling these methods on undefined throws!
  • fast/js/script-tests/object-prototype-toLocaleString.js:
    • Added test cases for correct behaviour when this is a string primitive.
  • sputnik/Conformance/11_Expressions/11.1_Primary_Expressions/11.1.1_The_this_Keyword/S11.1.1_A2-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.10_String.prototype.match/S15.5.4.10_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.11_String.prototype.replace/S15.5.4.11_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.12_String.prototype.search/S15.5.4.12_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.13_String.prototype.slice/S15.5.4.13_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.14_String.prototype.split/S15.5.4.14_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.15_String.prototype.substring/S15.5.4.15_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.4_String.prototype.charAt/S15.5.4.4_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.5_String.prototype.charCodeAt/S15.5.4.5_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.6_String.prototype.concat/S15.5.4.6_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.7_String.prototype.indexOf/S15.5.4.7_A1_T3-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.8_String.prototype.lastIndexOf/S15.5.4.8_A1_T3-expected.txt:
    • These test cases are all incorrect. (See https://bugs.ecmascript.org/show_bug.cgi?id=117). We were incorrectly passing 15.5.4.11_String.prototype.replace, this should fail, as the others do. All the other 15.5.4 tests were failing & are still failing, but now have a better error message. S11.1.1_A2 is also invalid, calling toString() passing undefined as this should throw.
Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91223 r91224  
     12011-07-18  Gavin Barraclough  <barraclough@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=64678
     4        Fix bugs in Object.prototype this handling.
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * fast/js/resources/js-test-pre.js:
     9            - Updated harness to not call Object.prototype.toString on undefined.
     10        * fast/js/eval-var-decl-expected.txt:
     11        * fast/js/object-prototype-properties-expected.txt: Added.
     12        * fast/js/object-prototype-properties.html: Added.
     13        * fast/js/object-prototype-toLocaleString-expected.txt
     14        * fast/js/script-tests/eval-var-decl.js:
     15            - Fix test case, calling hasProperty with undefined as the this value should throw.
     16        * fast/js/script-tests/object-prototype-properties.js: Added.
     17            - Place for test cases for Object.prototype properties; to being with, check that calling these methods on undefined throws!
     18        * fast/js/script-tests/object-prototype-toLocaleString.js:
     19            - Added test cases for correct behaviour when this is a string primitive.
     20        * sputnik/Conformance/11_Expressions/11.1_Primary_Expressions/11.1.1_The_this_Keyword/S11.1.1_A2-expected.txt:
     21        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.10_String.prototype.match/S15.5.4.10_A1_T3-expected.txt:
     22        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.11_String.prototype.replace/S15.5.4.11_A1_T3-expected.txt:
     23        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.12_String.prototype.search/S15.5.4.12_A1_T3-expected.txt:
     24        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.13_String.prototype.slice/S15.5.4.13_A1_T3-expected.txt:
     25        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.14_String.prototype.split/S15.5.4.14_A1_T3-expected.txt:
     26        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.15_String.prototype.substring/S15.5.4.15_A1_T3-expected.txt:
     27        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.4_String.prototype.charAt/S15.5.4.4_A1_T3-expected.txt:
     28        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.5_String.prototype.charCodeAt/S15.5.4.5_A1_T3-expected.txt:
     29        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.6_String.prototype.concat/S15.5.4.6_A1_T3-expected.txt:
     30        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.7_String.prototype.indexOf/S15.5.4.7_A1_T3-expected.txt:
     31        * sputnik/Conformance/15_Native_Objects/15.5_String/15.5.4/15.5.4.8_String.prototype.lastIndexOf/S15.5.4.8_A1_T3-expected.txt:
     32            - These test cases are all incorrect. (See https://bugs.ecmascript.org/show_bug.cgi?id=117).
     33              We were incorrectly passing 15.5.4.11_String.prototype.replace, this should fail, as the others do.
     34              All the other 15.5.4 tests were failing & are still failing, but now have a better error message.
     35              S11.1.1_A2 is also invalid, calling toString() passing undefined as this should throw.
     36
    1372011-07-18  Ryosuke Niwa  <rniwa@webkit.org>
    238
  • trunk/LayoutTests/fast/js/eval-var-decl-expected.txt

    r39534 r91224  
    44
    55
    6 PASS hasOwnProperty("foo") is true
    7 PASS hasOwnProperty("bar") is true
     6PASS this.hasOwnProperty("foo") is true
     7PASS this.hasOwnProperty("bar") is true
    88PASS firstEvalResult is true
    99PASS secondEvalResult is false
  • trunk/LayoutTests/fast/js/object-prototype-toLocaleString-expected.txt

    r12001 r91224  
    66PASS o.toLocaleString() is o.toString()
    77PASS o.toLocaleString() is "Dynamic toLocaleString()"
     8PASS Object.prototype.toLocaleString.call('Hello, world!') is "Hello, world!"
     9PASS Object.prototype.toLocaleString.call('Hello, world!') is "stringPrototypeToString"
    810PASS successfullyParsed is true
    911
  • trunk/LayoutTests/fast/js/resources/js-test-pre.js

    r70794 r91224  
    6666    if (typeof(_expected) == "number" && isNaN(_expected))
    6767        return typeof(_actual) == "number" && isNaN(_actual);
    68     if (Object.prototype.toString.call(_expected) == Object.prototype.toString.call([]))
     68    if (_expected && (Object.prototype.toString.call(_expected) == Object.prototype.toString.call([])))
    6969        return areArraysEqual(_actual, _expected);
    7070    return false;
  • trunk/LayoutTests/fast/js/script-tests/eval-var-decl.js

    r48651 r91224  
    33);
    44
    5 shouldBeTrue('hasOwnProperty("foo")');
     5shouldBeTrue('this.hasOwnProperty("foo")');
    66var foo = 3;
    77
    88delete bar;
    9 shouldBeTrue('hasOwnProperty("bar")');
     9shouldBeTrue('this.hasOwnProperty("bar")');
    1010var bar = 3;
    1111
    12 var firstEvalResult = eval('var result = hasOwnProperty("y"); var y = 3; result');
     12var firstEvalResult = eval('var result = this.hasOwnProperty("y"); var y = 3; result');
    1313shouldBeTrue("firstEvalResult");
    1414
    15 var secondEvalResult = eval('delete x; var result = hasOwnProperty("x"); var x = 3; result');
     15var secondEvalResult = eval('delete x; var result = this.hasOwnProperty("x"); var x = 3; result');
    1616shouldBeFalse("secondEvalResult");
    1717
  • trunk/LayoutTests/fast/js/script-tests/object-prototype-toLocaleString.js

    r48925 r91224  
    88shouldBe("o.toLocaleString()", '"Dynamic toLocaleString()"');
    99
     10shouldBe("Object.prototype.toLocaleString.call('Hello, world!')", '"Hello, world!"');
     11
     12var stringPrototypeToString = String.prototype.toString;
     13String.prototype.toString = (function(){ return "stringPrototypeToString"; });
     14shouldBe("Object.prototype.toLocaleString.call('Hello, world!')", '"stringPrototypeToString"');
     15String.prototype.toString = stringPrototypeToString;
     16
    1017var successfullyParsed = true;
  • trunk/Source/JavaScriptCore/ChangeLog

    r91218 r91224  
     12011-07-18  Gavin Barraclough  <barraclough@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=64678
     4        Fix bugs in Object.prototype this handling.
     5
     6        Reviewed by Oliver Hunt.
     7
     8        undefined/null this values should throw TypeErrors, not convert to the global object,
     9        also, to toLocaleString should be calling the ToObject & invoking the object's toString
     10        function, even for values that are already strings.
     11
     12        * runtime/ObjectPrototype.cpp:
     13        (JSC::objectProtoFuncValueOf):
     14        (JSC::objectProtoFuncHasOwnProperty):
     15        (JSC::objectProtoFuncIsPrototypeOf):
     16        (JSC::objectProtoFuncPropertyIsEnumerable):
     17        (JSC::objectProtoFuncToLocaleString):
     18        (JSC::objectProtoFuncToString):
     19
    1202011-07-18  Filip Pizlo  <fpizlo@apple.com>
    221
  • trunk/Source/JavaScriptCore/runtime/ObjectPrototype.cpp

    r86727 r91224  
    105105{
    106106    JSValue thisValue = exec->hostThisValue();
    107     return JSValue::encode(thisValue.toThisObject(exec));
     107    return JSValue::encode(thisValue.toObject(exec));
    108108}
    109109
     
    111111{
    112112    JSValue thisValue = exec->hostThisValue();
    113     return JSValue::encode(jsBoolean(thisValue.toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, exec->argument(0).toString(exec)))));
     113    return JSValue::encode(jsBoolean(thisValue.toObject(exec)->hasOwnProperty(exec, Identifier(exec, exec->argument(0).toString(exec)))));
    114114}
    115115
     
    117117{
    118118    JSValue thisValue = exec->hostThisValue();
    119     JSObject* thisObj = thisValue.toThisObject(exec);
     119    JSObject* thisObj = thisValue.toObject(exec);
    120120
    121121    if (!exec->argument(0).isObject())
     
    168168{
    169169    JSValue thisValue = exec->hostThisValue();
    170     return JSValue::encode(jsBoolean(thisValue.toThisObject(exec)->propertyIsEnumerable(exec, Identifier(exec, exec->argument(0).toString(exec)))));
    171 }
    172 
     170    return JSValue::encode(jsBoolean(thisValue.toObject(exec)->propertyIsEnumerable(exec, Identifier(exec, exec->argument(0).toString(exec)))));
     171}
     172
     173// 15.2.4.3 Object.prototype.toLocaleString()
    173174EncodedJSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState* exec)
    174175{
    175     JSValue thisValue = exec->hostThisValue();
    176     return JSValue::encode(thisValue.toThisJSString(exec));
     176    // 1. Let O be the result of calling ToObject passing the this value as the argument.
     177    JSObject* object = exec->hostThisValue().toObject(exec);
     178    if (exec->hadException())
     179        return JSValue::encode(jsUndefined());
     180
     181    // 2. Let toString be the result of calling the [[Get]] internal method of O passing "toString" as the argument.
     182    JSValue toString = object->get(exec, exec->propertyNames().toString);
     183
     184    // 3. If IsCallable(toString) is false, throw a TypeError exception.
     185    CallData callData;
     186    CallType callType = getCallData(toString, callData);
     187    if (callType == CallTypeNone)
     188        return JSValue::encode(jsUndefined());
     189
     190    // 4. Return the result of calling the [[Call]] internal method of toString passing O as the this value and no arguments.
     191    return JSValue::encode(call(exec, toString, callType, callData, object, exec->emptyList()));
    177192}
    178193
     
    180195{
    181196    JSValue thisValue = exec->hostThisValue();
    182     return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisValue.toThisObject(exec)->className(), "]"));
     197    return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisValue.toObject(exec)->className(), "]"));
    183198}
    184199
Note: See TracChangeset for help on using the changeset viewer.