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

Changeset 267549 in webkit


Ignore:
Timestamp:
Sep 24, 2020, 3:05:31 PM (6 years ago)
Author:
Ross Kirsling
Message:

JSTests:
%TypedArray%.prototype.{map, filter} should perform TypedArraySpeciesCreate correctly
https://bugs.webkit.org/show_bug.cgi?id=216938

Reviewed by Yusuke Suzuki.

  • stress/typedarray-slice.js:

Fix test.

  • test262/expectations.yaml:

Mark ten test cases as passing.

Source/JavaScriptCore:
%TypedArray% methods should perform TypedArraySpeciesCreate correctly
https://bugs.webkit.org/show_bug.cgi?id=216938

Reviewed by Yusuke Suzuki.

map, filter, and slice are obliged to throw when:

  1. this.constructor is defined but not an object
  2. the species constructor produces a valid typed array which is shorter than the expected length
  • builtins/TypedArrayPrototype.js:

(map):
(filter):

  • runtime/JSGenericTypedArrayViewPrototypeFunctions.h:

(JSC::genericTypedArrayViewProtoFuncSlice):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r267522 r267549  
     12020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        %TypedArray%.prototype.{map, filter} should perform TypedArraySpeciesCreate correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=216938
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/typedarray-slice.js:
     9        Fix test.
     10
     11        * test262/expectations.yaml:
     12        Mark ten test cases as passing.
     13
    1142020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
    215
  • trunk/JSTests/stress/typedarray-slice.js

    r264304 r267549  
    115115function testSpeciesWithSameBuffer(unused, constructor) {
    116116    return typedArrays.every(function(speciesConstructor) {
     117        // This test is not valid for all type pairs.
     118        if (constructor.BYTES_PER_ELEMENT < speciesConstructor.BYTES_PER_ELEMENT)
     119            return true;
     120
    117121        constructor[Symbol.species] = function() { return new speciesConstructor(buffer); };
    118122        let array = new constructor(buffer);
  • trunk/JSTests/test262/expectations.yaml

    r267522 r267549  
    12461246test/built-ins/ThrowTypeError/unique-per-realm-non-simple.js:
    12471247  default: 'Test262Error: callee.get Expected SameValue(«function () {'
    1248 test/built-ins/TypedArray/prototype/filter/speciesctor-get-ctor-returns-throws.js:
    1249   default: 'Test262Error: 42 Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1250   strict mode: 'Test262Error: 42 Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1251 test/built-ins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws.js:
    1252   default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1253   strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1254 test/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-returns-throws.js:
    1255   default: 'Test262Error: 42 Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1256   strict mode: 'Test262Error: 42 Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1257 test/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws.js:
    1258   default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1259   strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    12601248test/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js:
    12611249  default: 'TypeError: Underlying ArrayBuffer has been detached from the view (Testing with Float64Array.)'
     
    12641252  default: 'TypeError: Underlying ArrayBuffer has been detached from the view (Testing with Float64Array.)'
    12651253  strict mode: 'TypeError: Underlying ArrayBuffer has been detached from the view (Testing with Float64Array.)'
    1266 test/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws.js:
    1267   default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1268   strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    12691254test/built-ins/TypedArray/prototype/sort/comparefn-nonfunction-call-throws.js:
    12701255  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
  • trunk/Source/JavaScriptCore/ChangeLog

    r267538 r267549  
     12020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        %TypedArray% methods should perform TypedArraySpeciesCreate correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=216938
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        map, filter, and slice are obliged to throw when:
     9        1. this.constructor is defined but not an object
     10        2. the species constructor produces a valid typed array which is shorter than the expected length
     11
     12        * builtins/TypedArrayPrototype.js:
     13        (map):
     14        (filter):
     15        * runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
     16        (JSC::genericTypedArrayViewProtoFuncSlice):
     17
    1182020-09-24  Basuke Suzuki  <basuke.suzuki@sony.com>
    219
  • trunk/Source/JavaScriptCore/builtins/TypedArrayPrototype.js

    r267522 r267549  
    312312    var thisArg = @argument(1);
    313313
    314     // Do species construction
    315     var constructor = this.constructor;
    316     var result;
    317     if (constructor === @undefined)
    318         result = new (@typedArrayGetOriginalConstructor(this))(length);
    319     else {
    320         var speciesConstructor = constructor.@@species;
    321         if (@isUndefinedOrNull(speciesConstructor))
    322             result = new (@typedArrayGetOriginalConstructor(this))(length);
    323         else {
    324             result = new speciesConstructor(length);
    325             // typedArrayLength throws if it doesn't get a view.
    326             @typedArrayLength(result);
    327         }
    328     }
     314    var constructor = @typedArraySpeciesConstructor(this);
     315    var result = new constructor(length);
     316    if (@typedArrayLength(result) < length)
     317        @throwTypeError("TypedArray.prototype.map constructed typed array of insufficient length");
    329318
    330319    for (var i = 0; i < length; i++) {
     
    352341            kept.@push(value);
    353342    }
    354 
    355     var constructor = this.constructor;
    356     var result;
    357     var resultLength = kept.length;
    358     if (constructor === @undefined)
    359         result = new (@typedArrayGetOriginalConstructor(this))(resultLength);
    360     else {
    361         var speciesConstructor = constructor.@@species;
    362         if (@isUndefinedOrNull(speciesConstructor))
    363             result = new (@typedArrayGetOriginalConstructor(this))(resultLength);
    364         else {
    365             result = new speciesConstructor(resultLength);
    366             // typedArrayLength throws if it doesn't get a view.
    367             @typedArrayLength(result);
    368         }
    369     }
    370 
    371     for (var i = 0; i < kept.length; i++)
     343    var length = kept.length;
     344
     345    var constructor = @typedArraySpeciesConstructor(this);
     346    var result = new constructor(length);
     347    if (@typedArrayLength(result) < length)
     348        @throwTypeError("TypedArray.prototype.filter constructed typed array of insufficient length");
     349
     350    for (var i = 0; i < length; i++)
    372351        result[i] = kept[i];
    373352
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h

    r263944 r267549  
    465465
    466466    // The species constructor may return an array with any arbitrary length.
    467     length = std::min(length, result->length());
     467    if (result->length() < length)
     468        return throwVMTypeError(globalObject, scope, "TypedArray.prototype.slice constructed typed array of insufficient length"_s);
     469
    468470    switch (result->classInfo(vm)->typedArrayStorageType) {
    469471    case TypeInt8:
Note: See TracChangeset for help on using the changeset viewer.