Changeset 279937 in webkit


Ignore:
Timestamp:
Jul 14, 2021 8:11:53 PM (12 months ago)
Author:
Devin Rousso
Message:

Implement Array.prototype.findLast and Array.prototype.findLastIndex
https://bugs.webkit.org/show_bug.cgi?id=227939

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/typedarray-findLast.js: Added.

(keepEven):
(keepEvenAndChange):
(isBigEnoughAndException):

  • stress/typedarray-findLastIndex.js: Added.

(keepEven):
(keepEvenAndChange):
(isBigEnoughAndException):

Source/JavaScriptCore:

  • builtins/ArrayPrototype.js:

(findLast): Added.
(findLastIndex): Added.
(JSC::ArrayPrototype::finishCreation):

  • runtime/JSTypedArrayViewPrototype.cpp:
  • builtins/TypedArrayPrototype.js:

(findLast): Added.
(findLastIndex): Added.

  • runtime/ArrayPrototype.cpp:

(JSC::JSTypedArrayViewPrototype::finishCreation):

  • runtime/OptionsList.h:

Source/WebInspectorUI:

  • UserInterface/Models/NativeFunctionParameters.js:

LayoutTests:

  • js/array-findLast.html: Added.
  • js/array-findLast-expected.txt: Added.
  • js/script-tests/array-findLast.js: Added.

(passUndefined):
(passZero):
(passNull):
(passFalse):
(passEmptyString):
(passEven):
(passAfter5):
(toObject):
(findItemAddedDuringSearch):
(numberOfCallbacksInFindInArrayWithHoles):
(throwError):

  • js/array-findLastIndex.html: Added.
  • js/array-findLastIndex-expected.txt: Added.
  • js/script-tests/array-findLastIndex.js: Added.

(passUndefined):
(passZero):
(passNull):
(passFalse):
(passEmptyString):
(passEven):
(passAfter5):
(toObject):
(findItemAddedDuringSearch):
(numberOfCallbacksInFindIndexInArrayWithHoles):
(throwError):

Location:
trunk
Files:
8 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r279923 r279937  
     12021-07-14  Devin Rousso  <drousso@apple.com>
     2
     3        Implement Array.prototype.findLast and Array.prototype.findLastIndex
     4        https://bugs.webkit.org/show_bug.cgi?id=227939
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/typedarray-findLast.js: Added.
     9        (keepEven):
     10        (keepEvenAndChange):
     11        (isBigEnoughAndException):
     12
     13        * stress/typedarray-findLastIndex.js: Added.
     14        (keepEven):
     15        (keepEvenAndChange):
     16        (isBigEnoughAndException):
     17
    1182021-07-14  Keith Miller  <keith_miller@apple.com>
    219
  • trunk/LayoutTests/ChangeLog

    r279936 r279937  
     12021-07-14  Devin Rousso  <drousso@apple.com>
     2
     3        Implement Array.prototype.findLast and Array.prototype.findLastIndex
     4        https://bugs.webkit.org/show_bug.cgi?id=227939
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * js/array-findLast.html: Added.
     9        * js/array-findLast-expected.txt: Added.
     10        * js/script-tests/array-findLast.js: Added.
     11        (passUndefined):
     12        (passZero):
     13        (passNull):
     14        (passFalse):
     15        (passEmptyString):
     16        (passEven):
     17        (passAfter5):
     18        (toObject):
     19        (findItemAddedDuringSearch):
     20        (numberOfCallbacksInFindInArrayWithHoles):
     21        (throwError):
     22
     23        * js/array-findLastIndex.html: Added.
     24        * js/array-findLastIndex-expected.txt: Added.
     25        * js/script-tests/array-findLastIndex.js: Added.
     26        (passUndefined):
     27        (passZero):
     28        (passNull):
     29        (passFalse):
     30        (passEmptyString):
     31        (passEven):
     32        (passAfter5):
     33        (toObject):
     34        (findItemAddedDuringSearch):
     35        (numberOfCallbacksInFindIndexInArrayWithHoles):
     36        (throwError):
     37
    1382021-07-14  Eric Hutchison  <ehutchison@apple.com>
    239
  • trunk/Source/JavaScriptCore/ChangeLog

    r279927 r279937  
     12021-07-14  Devin Rousso  <drousso@apple.com>
     2
     3        Implement Array.prototype.findLast and Array.prototype.findLastIndex
     4        https://bugs.webkit.org/show_bug.cgi?id=227939
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * builtins/ArrayPrototype.js:
     9        (findLast): Added.
     10        (findLastIndex): Added.
     11        (JSC::ArrayPrototype::finishCreation):
     12        * runtime/JSTypedArrayViewPrototype.cpp:
     13
     14        * builtins/TypedArrayPrototype.js:
     15        (findLast): Added.
     16        (findLastIndex): Added.
     17        * runtime/ArrayPrototype.cpp:
     18        (JSC::JSTypedArrayViewPrototype::finishCreation):
     19
     20        * runtime/OptionsList.h:
     21
    1222021-07-14  Michael Saboff  <msaboff@apple.com>
    223
  • trunk/Source/JavaScriptCore/builtins/ArrayPrototype.js

    r273617 r279937  
    255255}
    256256
     257function findLast(callback /*, thisArg */)
     258{
     259    "use strict";
     260
     261    var array = @toObject(this, "Array.prototype.findLast requires that |this| not be null or undefined");
     262    var length = @toLength(array.length);
     263
     264    if (!@isCallable(callback))
     265        @throwTypeError("Array.prototype.findLast callback must be a function");
     266
     267    var thisArg = @argument(1);
     268    for (var i = length - 1; i >= 0; i--) {
     269        var element = array[i];
     270        if (callback.@call(thisArg, element, i, array))
     271            return element;
     272    }
     273    return @undefined;
     274}
     275
    257276function findIndex(callback /*, thisArg */)
    258277{
     
    267286    var thisArg = @argument(1);
    268287    for (var i = 0; i < length; i++) {
     288        if (callback.@call(thisArg, array[i], i, array))
     289            return i;
     290    }
     291    return -1;
     292}
     293
     294function findLastIndex(callback /*, thisArg */)
     295{
     296    "use strict";
     297
     298    var array = @toObject(this, "Array.prototype.findLastIndex requires that |this| not be null or undefined");
     299    var length = @toLength(array.length);
     300
     301    if (!@isCallable(callback))
     302        @throwTypeError("Array.prototype.findLastIndex callback must be a function");
     303
     304    var thisArg = @argument(1);
     305    for (var i = length - 1; i >= 0; i--) {
    269306        if (callback.@call(thisArg, array[i], i, array))
    270307            return i;
  • trunk/Source/JavaScriptCore/builtins/TypedArrayPrototype.js

    r276612 r279937  
    8787}
    8888
     89function findLast(callback /* [, thisArg] */)
     90{
     91    "use strict";
     92    var length = @typedArrayLength(this);
     93    var thisArg = @argument(1);
     94
     95    if (!@isCallable(callback))
     96        @throwTypeError("TypedArray.prototype.findLast callback must be a function");
     97
     98    for (var i = length - 1; i >= 0; i--) {
     99        var element = this[i];
     100        if (callback.@call(thisArg, element, i, this))
     101            return element;
     102    }
     103    return @undefined;
     104}
     105
    89106function findIndex(callback /* [, thisArg] */)
    90107{
     
    97114
    98115    for (var i = 0; i < length; i++) {
     116        if (callback.@call(thisArg, this[i], i, this))
     117            return i;
     118    }
     119    return -1;
     120}
     121
     122function findLastIndex(callback /* [, thisArg] */)
     123{
     124    "use strict";
     125    var length = @typedArrayLength(this);
     126    var thisArg = @argument(1);
     127
     128    if (!@isCallable(callback))
     129        @throwTypeError("TypedArray.prototype.findLastIndex callback must be a function");
     130
     131    for (var i = length - 1; i >= 0; i--) {
    99132        if (callback.@call(thisArg, this[i], i, this))
    100133            return i;
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r278338 r279937  
    109109    JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().entriesPublicName(), arrayProtoFuncEntries, static_cast<unsigned>(PropertyAttribute::DontEnum), 0, ArrayEntriesIntrinsic);
    110110    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().findPublicName(), arrayPrototypeFindCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     111    if (Options::useArrayFindLastMethod())
     112        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().findLastPublicName(), arrayPrototypeFindLastCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    111113    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().findIndexPublicName(), arrayPrototypeFindIndexCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     114    if (Options::useArrayFindLastMethod())
     115        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().findLastIndexPublicName(), arrayPrototypeFindLastIndexCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    112116    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().includesPublicName(), arrayPrototypeIncludesCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    113117    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().copyWithinPublicName(), arrayPrototypeCopyWithinCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     
    135139        &vm.propertyNames->builtinNames().valuesPublicName()
    136140    };
     141    if (Options::useArrayFindLastMethod()) {
     142        unscopables->putDirect(vm, vm.propertyNames->builtinNames().findLastPublicName(), jsBoolean(true));
     143        unscopables->putDirect(vm, vm.propertyNames->builtinNames().findLastIndexPublicName(), jsBoolean(true));
     144    }
    137145    if (Options::useAtMethod())
    138146        unscopables->putDirect(vm, vm.propertyNames->builtinNames().atPublicName(), jsBoolean(true));
  • trunk/Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp

    r276719 r279937  
    454454    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().fillPublicName(), typedArrayViewProtoFuncFill, static_cast<unsigned>(PropertyAttribute::DontEnum), 1);
    455455    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("find", typedArrayPrototypeFindCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     456    if (Options::useArrayFindLastMethod())
     457        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().findLastPublicName(), typedArrayPrototypeFindLastCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    456458    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("findIndex", typedArrayPrototypeFindIndexCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
     459    if (Options::useArrayFindLastMethod())
     460        JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().findLastIndexPublicName(), typedArrayPrototypeFindLastIndexCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    457461    JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->forEach, typedArrayPrototypeForEachCodeGenerator, static_cast<unsigned>(PropertyAttribute::DontEnum));
    458462    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("indexOf", typedArrayViewProtoFuncIndexOf, static_cast<unsigned>(PropertyAttribute::DontEnum), 1);
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r279630 r279937  
    551551    v(Bool, useDataICSharing, false, Normal, nullptr) \
    552552    v(Bool, useTemporal, false, Normal, "Expose the Temporal object.") \
     553    v(Bool, useArrayFindLastMethod, false, Normal, "Expose the findLast() and findLastIndex() methods on Array and %TypedArray%.") \
    553554
    554555
  • trunk/Source/WebInspectorUI/ChangeLog

    r279862 r279937  
     12021-07-14  Devin Rousso  <drousso@apple.com>
     2
     3        Implement Array.prototype.findLast and Array.prototype.findLastIndex
     4        https://bugs.webkit.org/show_bug.cgi?id=227939
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * UserInterface/Models/NativeFunctionParameters.js:
     9
    1102021-07-12  Patrick Angle  <pangle@apple.com>
    211
  • trunk/Source/WebInspectorUI/UserInterface/Models/NativeFunctionParameters.js

    r277547 r279937  
    250250        find: "callback, [thisArg]",
    251251        findIndex: "callback, [thisArg]",
     252        findLast: "callback, [thisArg]",
     253        findLastIndex: "callback, [thisArg]",
    252254        forEach: "callback, [thisArg]",
    253255        includes: "searchValue, [startIndex=0]",
Note: See TracChangeset for help on using the changeset viewer.