Changeset 270005 in webkit


Ignore:
Timestamp:
Nov 18, 2020 6:32:56 PM (3 years ago)
Author:
Ross Kirsling
Message:

[JSC] Reinstate String#at
https://bugs.webkit.org/show_bug.cgi?id=219124

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/at-method.js: Re-add tests.
  • test262/config.yaml: Re-enable feature.
  • test262/expectations.yaml:

"at/prop-desc.js" failures are due to a typo; will be fixed in https://github.com/tc39/test262/pull/2908.

Source/JavaScriptCore:

At this week's TC39 meeting, consensus was achieved on renaming item() *and* keeping it for strings too.
Accordingly, this patch reinstates String.prototype.at behind the existing useAtMethod runtime option.

  • builtins/StringPrototype.js:

(at):

  • runtime/StringPrototype.cpp:

(JSC::StringPrototype::finishCreation):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r269998 r270005  
     12020-11-18  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [JSC] Reinstate String#at
     4        https://bugs.webkit.org/show_bug.cgi?id=219124
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/at-method.js: Re-add tests.
     9        * test262/config.yaml: Re-enable feature.
     10        * test262/expectations.yaml:
     11        "at/prop-desc.js" failures are due to a typo; will be fixed in https://github.com/tc39/test262/pull/2908.
     12
    1132020-11-17  Yusuke Suzuki  <ysuzuki@apple.com>
    214
  • trunk/JSTests/stress/at-method.js

    r268760 r270005  
    5050  shouldBe(ta.at({ valueOf: () => -1 }), ta[ta.length - 1]);
    5151}
     52
     53shouldBe(String.prototype.at.length, 1); 
     54shouldThrowTypeError(() => String.prototype.at.call(undefined)); 
     55shouldThrowTypeError(() => String.prototype.at.call(null));
     56
     57const string = 'abc';
     58// intentionally go one too far to ensure that we get undefined instead of wrapping
     59for (let i = 0; i <= string.length; i++) { 
     60  shouldBe(string.at(i), string[i]); 
     61  shouldBe(string.at(-i - 1), string[string.length - i - 1]);
     62}
     63shouldBe(string.at(), string[0]);
     64shouldBe(string.at(null), string[0]);
     65shouldBe(string.at({ valueOf: () => -1 }), string[string.length - 1]); 
     66
     67const emojiPseudoString = { toString: () => '😅' }; 
     68shouldBe(String.prototype.at.call(emojiPseudoString, 0), '\u{d83d}');
     69shouldBe(String.prototype.at.call(emojiPseudoString, -1), '\u{de05}');
  • trunk/JSTests/test262/config.yaml

    r269986 r270005  
    1111  Array.prototype.at: useAtMethod
    1212  TypedArray.prototype.at: useAtMethod
     13  String.prototype.at: useAtMethod
    1314skip:
    1415  features:
     
    2829    - top-level-await
    2930    - Intl.ListFormat
    30 
    31     - String.prototype.at
    3231  paths:
    3332    - test/built-ins/DataView/prototype/getBigInt64
  • trunk/JSTests/test262/expectations.yaml

    r269986 r270005  
    824824  default: 'SyntaxError: Invalid regular expression: number too large in {} quantifier'
    825825  strict mode: 'SyntaxError: Invalid regular expression: number too large in {} quantifier'
     826test/built-ins/String/prototype/at/prop-desc.js:
     827  default: 'Test262Error: descriptor should be writable'
     828  strict mode: 'Test262Error: descriptor should be writable'
    826829test/built-ins/TypedArray/prototype/at/prop-desc.js:
    827830  default: 'Test262Error: descriptor should be writable'
  • trunk/Source/JavaScriptCore/ChangeLog

    r269998 r270005  
     12020-11-18  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [JSC] Reinstate String#at
     4        https://bugs.webkit.org/show_bug.cgi?id=219124
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        At this week's TC39 meeting, consensus was achieved on renaming item() *and* keeping it for strings too.
     9        Accordingly, this patch reinstates String.prototype.at behind the existing useAtMethod runtime option.
     10
     11        * builtins/StringPrototype.js:
     12        (at):
     13        * runtime/StringPrototype.cpp:
     14        (JSC::StringPrototype::finishCreation):
     15
    1162020-11-17  Yusuke Suzuki  <ysuzuki@apple.com>
    217
  • trunk/Source/JavaScriptCore/builtins/StringPrototype.js

    r268165 r270005  
    341341}
    342342
     343// FIXME: This is extremely similar to charAt, so we should optimize it accordingly.   
     344//        https://bugs.webkit.org/show_bug.cgi?id=217139   
     345function at(index)   
     346{   
     347    "use strict";   
     348
     349    if (@isUndefinedOrNull(this))   
     350        @throwTypeError("String.prototype.at requires that |this| not be null or undefined");
     351
     352    var string = @toString(this);   
     353    var length = string.length;
     354
     355    var k = @toInteger(index); 
     356    if (k < 0) 
     357        k += length;   
     358
     359    return (k >= 0 && k < length) ? string[k] : @undefined;
     360}
     361
    343362@globalPrivate
    344363function createHTML(func, string, tag, attribute, value)
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r268990 r270005  
    151151    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("normalize", stringProtoFuncNormalize, static_cast<unsigned>(PropertyAttribute::DontEnum), 0);
    152152    JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().charCodeAtPrivateName(), stringProtoFuncCharCodeAt, static_cast<unsigned>(PropertyAttribute::DontEnum), 1, CharCodeAtIntrinsic);
     153
     154    if (Options::useAtMethod())
     155        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().atPublicName(), stringPrototypeAtCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    153156
    154157    JSFunction* trimStartFunction = JSFunction::create(vm, globalObject, 0, "trimStart"_s, stringProtoFuncTrimStart, NoIntrinsic);
Note: See TracChangeset for help on using the changeset viewer.