⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268760 in webkit


Ignore:
Timestamp:
Oct 20, 2020, 2:23:53 PM (6 years ago)
Author:
Ross Kirsling
Message:

[JSC] Rename item() to at() and move it behind a flag
https://bugs.webkit.org/show_bug.cgi?id=217942

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/at-method.js: Renamed from JSTests/stress/item-method.js.
  • test262/config.yaml: Add skips until the feature is renamed.

Source/JavaScriptCore:

{Array, %TypedArray%}.prototype.item is official web-incompatible,
but it is expected to be renamed to at instead of being scrapped entirely:
https://github.com/tc39/proposal-item-method/issues/34

This patch performs the renaming, but does so behind a runtime flag since this has yet to achieve consensus.

  • builtins/ArrayPrototype.js:

(at):
(item): Deleted.

  • builtins/TypedArrayPrototype.js:

(at):
(item): Deleted.

  • runtime/ArrayPrototype.cpp:

(JSC::ArrayPrototype::finishCreation):

  • runtime/JSTypedArrayViewPrototype.cpp:

(JSC::JSTypedArrayViewPrototype::finishCreation):

  • runtime/OptionsList.h:

LayoutTests:

  • inspector/model/remote-object-get-properties-expected.txt:
  • js/array-unscopables-properties-expected.txt:
  • js/Object-getOwnPropertyNames-expected.txt:
  • js/script-tests/Object-getOwnPropertyNames.js:
  • js/script-tests/array-unscopables-properties.js:
Location:
trunk
Files:
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r268710 r268760  
     12020-10-20  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [JSC] Rename item() to at() and move it behind a flag
     4        https://bugs.webkit.org/show_bug.cgi?id=217942
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/at-method.js: Renamed from JSTests/stress/item-method.js.
     9        * test262/config.yaml: Add skips until the feature is renamed.
     10
    1112020-10-19  Alexey Shvayka  <shvaikalesh@gmail.com>
    212
  • trunk/JSTests/stress/at-method.js

    r268759 r268760  
     1//@ requireOptions("--useAtMethod=1")
     2
    13function shouldBe(actual, expected) {
    24    if (actual !== expected)
     
    1618}
    1719
    18 shouldBe(Array.prototype.item.length, 1);
    19 shouldThrowTypeError(() => Array.prototype.item.call(undefined));
    20 shouldThrowTypeError(() => Array.prototype.item.call(null));
     20shouldBe(Array.prototype.at.length, 1);
     21shouldThrowTypeError(() => Array.prototype.at.call(undefined));
     22shouldThrowTypeError(() => Array.prototype.at.call(null));
    2123
    2224const array = [42, 'b', true];
    2325// intentionally go one too far to ensure that we get undefined instead of wrapping
    2426for (let i = 0; i <= array.length; i++) {
    25   shouldBe(array.item(i), array[i]);
    26   shouldBe(array.item(-i - 1), array[array.length - i - 1]);
     27  shouldBe(array.at(i), array[i]);
     28  shouldBe(array.at(-i - 1), array[array.length - i - 1]);
    2729}
    28 shouldBe(array.item(), array[0]);
    29 shouldBe(array.item(null), array[0]);
    30 shouldBe(array.item({ valueOf: () => -1 }), array[array.length - 1]);
     30shouldBe(array.at(), array[0]);
     31shouldBe(array.at(null), array[0]);
     32shouldBe(array.at({ valueOf: () => -1 }), array[array.length - 1]);
    3133
    3234const weirdArrayLike = { length: 1, get '0'() { return 3; }, get '1'() { throw 'oops'; } };
    33 shouldBe(Array.prototype.item.call(weirdArrayLike, 0), 3);
    34 shouldBe(Array.prototype.item.call(weirdArrayLike, 1), undefined);
     35shouldBe(Array.prototype.at.call(weirdArrayLike, 0), 3);
     36shouldBe(Array.prototype.at.call(weirdArrayLike, 1), undefined);
    3537
    3638for (const TA of [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array]) {
    37   shouldBe(TA.prototype.item.length, 1);
    38   shouldThrowTypeError(() => TA.prototype.item.call([]));
     39  shouldBe(TA.prototype.at.length, 1);
     40  shouldThrowTypeError(() => TA.prototype.at.call([]));
    3941
    4042  const ta = [1, 2, 3];
    4143  // intentionally go one too far to ensure that we get undefined instead of wrapping
    4244  for (let i = 0; i <= ta.length; i++) {
    43     shouldBe(ta.item(i), ta[i]);
    44     shouldBe(ta.item(-i - 1), ta[ta.length - i - 1]);
     45    shouldBe(ta.at(i), ta[i]);
     46    shouldBe(ta.at(-i - 1), ta[ta.length - i - 1]);
    4547  }
    46   shouldBe(ta.item(), ta[0]);
    47   shouldBe(ta.item(null), ta[0]);
    48   shouldBe(ta.item({ valueOf: () => -1 }), ta[ta.length - 1]);
     48  shouldBe(ta.at(), ta[0]);
     49  shouldBe(ta.at(null), ta[0]);
     50  shouldBe(ta.at({ valueOf: () => -1 }), ta[ta.length - 1]);
    4951}
  • trunk/JSTests/stress/unscopables.js

    r267912 r268760  
     1//@ requireOptions("--useAtMethod=1")
     2
    13function test(actual, expected) {
    24    if (actual !== expected)
     
    1012    test(typeof unscopables, "object");
    1113    test(unscopables.__proto__, undefined);
    12     test(String(Object.keys(unscopables).sort()), "copyWithin,entries,fill,find,findIndex,flat,flatMap,includes,item,keys,values");
     14    test(String(Object.keys(unscopables).sort()), "at,copyWithin,entries,fill,find,findIndex,flat,flatMap,includes,keys,values");
    1315}());
    1416
  • trunk/JSTests/test262/config.yaml

    r268501 r268760  
    2727    - top-level-await
    2828    - Intl.ListFormat
     29
     30    # remove once it's been renamed in test262
     31    - Array.prototype.item
     32    - TypedArray.prototype.item
    2933
    3034    # remove once it's no longer in test262
  • trunk/LayoutTests/ChangeLog

    r268759 r268760  
     12020-10-20  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [JSC] Rename item() to at() and move it behind a flag
     4        https://bugs.webkit.org/show_bug.cgi?id=217942
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * inspector/model/remote-object-get-properties-expected.txt:
     9        * js/array-unscopables-properties-expected.txt:
     10        * js/Object-getOwnPropertyNames-expected.txt:
     11        * js/script-tests/Object-getOwnPropertyNames.js:
     12        * js/script-tests/array-unscopables-properties.js:
     13
    1142020-10-20  Diego Pino Garcia  <dpino@igalia.com>
    215
  • trunk/LayoutTests/inspector/model/remote-object-get-properties-expected.txt

    r267814 r268760  
    8686    includes
    8787    copyWithin
    88     item
    8988    constructor
    9089    Symbol(Symbol.iterator)
     
    140139    includes
    141140    copyWithin
    142     item
    143141    constructor
    144142    Symbol(Symbol.iterator)
     
    179177    includes
    180178    copyWithin
    181     item
    182179    constructor
    183180    Symbol(Symbol.iterator)
     
    218215    includes
    219216    copyWithin
    220     item
    221217    constructor
    222218    Symbol(Symbol.iterator)
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r268165 r268760  
    4848PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'arguments', 'bind', 'call', 'caller', 'constructor', 'length', 'name', 'toString']
    4949PASS getSortedOwnPropertyNames(Array) is ['from', 'isArray', 'length', 'name', 'of', 'prototype']
    50 PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'item', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']
     50PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']
    5151PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'fromCodePoint', 'length', 'name', 'prototype', 'raw']
    5252PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'replaceAll', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimEnd', 'trimLeft', 'trimRight', 'trimStart', 'valueOf']
  • trunk/LayoutTests/js/array-unscopables-properties-expected.txt

    r267912 r268760  
    4343PASS Object.getOwnPropertyDescriptor(Array.prototype[Symbol.unscopables], "includes").enumerable is true
    4444PASS Object.getOwnPropertyDescriptor(Array.prototype[Symbol.unscopables], "includes").configurable is true
    45 PASS Array.prototype[Symbol.unscopables]["item"] is true
    46 PASS Object.getOwnPropertyDescriptor(Array.prototype[Symbol.unscopables], "item").writable is true
    47 PASS Object.getOwnPropertyDescriptor(Array.prototype[Symbol.unscopables], "item").enumerable is true
    48 PASS Object.getOwnPropertyDescriptor(Array.prototype[Symbol.unscopables], "item").configurable is true
    4945PASS Array.prototype[Symbol.unscopables]["keys"] is true
    5046PASS Object.getOwnPropertyDescriptor(Array.prototype[Symbol.unscopables], "keys").writable is true
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r268165 r268760  
    5757    "Function.prototype": "['apply', 'arguments', 'bind', 'call', 'caller', 'constructor', 'length', 'name', 'toString']",
    5858    "Array": "['from', 'isArray', 'length', 'name', 'of', 'prototype']",
    59     "Array.prototype": "['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'item', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']",
     59    "Array.prototype": "['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']",
    6060    "String": "['fromCharCode', 'fromCodePoint', 'length', 'name', 'prototype', 'raw']",
    6161    "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'matchAll', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'replaceAll', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimEnd', 'trimLeft', 'trimRight', 'trimStart', 'valueOf']",
  • trunk/LayoutTests/js/script-tests/array-unscopables-properties.js

    r267912 r268760  
    1616    "flatMap",
    1717    "includes",
    18     "item",
    1918    "keys",
    2019    "values"
  • trunk/Source/JavaScriptCore/ChangeLog

    r268716 r268760  
     12020-10-20  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [JSC] Rename item() to at() and move it behind a flag
     4        https://bugs.webkit.org/show_bug.cgi?id=217942
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        {Array, %TypedArray%}.prototype.item is official web-incompatible,
     9        but it is expected to be renamed to `at` instead of being scrapped entirely:
     10        https://github.com/tc39/proposal-item-method/issues/34
     11
     12        This patch performs the renaming, but does so behind a runtime flag since this has yet to achieve consensus.
     13
     14        * builtins/ArrayPrototype.js:
     15        (at):
     16        (item): Deleted.
     17        * builtins/TypedArrayPrototype.js:
     18        (at):
     19        (item): Deleted.
     20        * runtime/ArrayPrototype.cpp:
     21        (JSC::ArrayPrototype::finishCreation):
     22        * runtime/JSTypedArrayViewPrototype.cpp:
     23        (JSC::JSTypedArrayViewPrototype::finishCreation):
     24        * runtime/OptionsList.h:
     25
    1262020-10-20  Philippe Normand  <pnormand@igalia.com> and Pavel Feldman <pavel.feldman@gmail.com>
    227
  • trunk/Source/JavaScriptCore/builtins/ArrayPrototype.js

    r268715 r268760  
    688688}
    689689
    690 function item(index)
    691 {
    692     "use strict";
    693 
    694     var array = @toObject(this, "Array.prototype.item requires that |this| not be null or undefined");
     690function at(index)
     691{
     692    "use strict";
     693
     694    var array = @toObject(this, "Array.prototype.at requires that |this| not be null or undefined");
    695695    var length = @toLength(array.length);
    696696
  • trunk/Source/JavaScriptCore/builtins/TypedArrayPrototype.js

    r268715 r268760  
    386386}
    387387
    388 function item(index)
     388function at(index)
    389389{
    390390    "use strict";
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r268489 r268760  
    111111    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().includesPublicName(), arrayPrototypeIncludesCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    112112    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().copyWithinPublicName(), arrayPrototypeCopyWithinCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    113     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().itemPublicName(), arrayPrototypeItemCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     113
     114    if (Options::useAtMethod())
     115        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().atPublicName(), arrayPrototypeAtCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    114116
    115117    putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().entriesPrivateName(), getDirect(vm, vm.propertyNames->builtinNames().entriesPublicName()), static_cast<unsigned>(PropertyAttribute::ReadOnly));
     
    129131        &vm.propertyNames->builtinNames().flatMapPublicName(),
    130132        &vm.propertyNames->builtinNames().includesPublicName(),
    131         &vm.propertyNames->builtinNames().itemPublicName(),
    132133        &vm.propertyNames->builtinNames().keysPublicName(),
    133134        &vm.propertyNames->builtinNames().valuesPublicName()
    134135    };
     136    if (Options::useAtMethod())
     137        unscopables->putDirect(vm, vm.propertyNames->builtinNames().atPublicName(), jsBoolean(true));
    135138    for (const auto* unscopableName : unscopableNames)
    136139        unscopables->putDirect(vm, *unscopableName, jsBoolean(true));
  • trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp

    r267814 r268760  
    376376    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->subarray, typedArrayPrototypeSubarrayCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    377377    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->toLocaleString, typedArrayPrototypeToLocaleStringCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    378     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().itemPublicName(), typedArrayPrototypeItemCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     378
     379    if (Options::useAtMethod())
     380        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().atPublicName(), typedArrayPrototypeAtCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    379381
    380382    JSFunction* toStringTagFunction = JSFunction::create(vm, globalObject, 0, "get [Symbol.toStringTag]"_s, typedArrayViewProtoGetterFuncToStringTag, NoIntrinsic);
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r268284 r268760  
    492492    v(Bool, useWeakRefs, true, Normal, "Expose the WeakRef constructor.") \
    493493    v(Bool, useIntlDateTimeFormatDayPeriod, true, Normal, "Expose the Intl.DateTimeFormat dayPeriod feature.") \
     494    v(Bool, useAtMethod, false, Normal, "Expose the at() method on Array and %TypedArray%.") \
    494495    v(Bool, useArrayAllocationProfiling, true, Normal, "If true, we will use our normal array allocation profiling. If false, the allocation profile will always claim to be undecided.") \
    495496    v(Bool, forcePolyProto, false, Normal, "If true, create_this will always create an object with a poly proto structure.") \
Note: See TracChangeset for help on using the changeset viewer.