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

Changeset 267603 in webkit


Ignore:
Timestamp:
Sep 25, 2020, 3:54:55 PM (6 years ago)
Author:
Ross Kirsling
Message:

%TypedArray%.{from, of} no longer perform AllocateTypedArray
https://bugs.webkit.org/show_bug.cgi?id=216991

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/typedarray-of.js:

Fix test.

  • test262/expectations.yaml:

Mark twelve test cases as passing.

Source/JavaScriptCore:

Back in ES2015, %TypedArray%.of and %TypedArray%.from appear to have been based on the abstract operation
AllocateTypedArray, which involved crawling the prototype chain to find the appropriate constructor and
only permitted this to be a (derived) typed array.

This appears to have gone away as of ES2016 -- we simply expect this to be a constructor and verify that it
produced a typed array (of sufficient length).

  • builtins/BuiltinNames.h:
  • builtins/TypedArrayConstructor.js:

(of):
(from):
(allocateInt8Array): Deleted.
(allocateInt16Array): Deleted.
(allocateInt32Array): Deleted.
(allocateUint32Array): Deleted.
(allocateUint16Array): Deleted.
(allocateUint8Array): Deleted.
(allocateUint8ClampedArray): Deleted.
(allocateFloat32Array): Deleted.
(allocateFloat64Array): Deleted.

  • runtime/JSGenericTypedArrayViewConstructor.h:
  • runtime/JSGenericTypedArrayViewConstructorInlines.h:

(JSC::JSGenericTypedArrayViewConstructor<ViewClass>::finishCreation):
(JSC::JSGenericTypedArrayViewConstructor<ViewClass>::create):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r267564 r267603  
     12020-09-25  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        %TypedArray%.{from, of} no longer perform AllocateTypedArray
     4        https://bugs.webkit.org/show_bug.cgi?id=216991
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/typedarray-of.js:
     9        Fix test.
     10
     11        * test262/expectations.yaml:
     12        Mark twelve test cases as passing.
     13
    1142020-09-25  Alexey Shvayka  <shvaikalesh@gmail.com>
    215
  • trunk/JSTests/stress/typedarray-of.js

    r264304 r267603  
    1515shouldBeTrue("testConstructorFunction('of', '(1,2,3)', [1,2,3])");
    1616
    17 shouldThrow("testConstructorFunction('of', '.call(false)', false)", "'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor'");
    18 shouldThrow("testConstructorFunction('of', '.call({})', false)", "'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor'");
    19 shouldThrow("testConstructorFunction('of', '.call([])', false)", "'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor'");
     17shouldThrow("testConstructorFunction('of', '.call(false)', false)", "'TypeError: TypedArray.of requires |this| to be a constructor'");
     18shouldThrow("testConstructorFunction('of', '.call({})', false)", "'TypeError: TypedArray.of requires |this| to be a constructor'");
     19shouldThrow("testConstructorFunction('of', '.call([])', false)", "'TypeError: TypedArray.of requires |this| to be a constructor'");
    2020
    2121finishJSTest();
  • trunk/JSTests/test262/expectations.yaml

    r267559 r267603  
    13121312  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    13131313  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1314 test/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-instance.js:
    1315   default: 'TypeError: TypedArray.from requires its this argument subclass a TypedArray constructor (Testing with Float64Array.)'
    1316   strict mode: 'TypeError: TypedArray.from requires its this argument subclass a TypedArray constructor (Testing with Float64Array.)'
    1317 test/built-ins/TypedArrayConstructors/from/custom-ctor.js:
    1318   default: 'Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)'
    1319   strict mode: 'Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)'
    1320 test/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js:
    1321   default: 'TypeError: TypedArray.from requires its this argument subclass a TypedArray constructor (Testing with Float64Array.)'
    1322   strict mode: 'TypeError: TypedArray.from requires its this argument subclass a TypedArray constructor (Testing with Float64Array.)'
    13231314test/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js:
    13241315  default: 'Test262Error: interrupted source iteration Expected SameValue(«1», «[object Object]») to be true (Testing with Float64Array.)'
     
    13691360  default: 'Test262Error: ToNumber runs before ToInteger(index) Expected a Test262Error to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    13701361  strict mode: 'Test262Error: ToNumber runs before ToInteger(index) Expected a Test262Error to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1371 test/built-ins/TypedArrayConstructors/of/custom-ctor-returns-other-instance.js:
    1372   default: 'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor (Testing with Float64Array.)'
    1373   strict mode: 'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor (Testing with Float64Array.)'
    1374 test/built-ins/TypedArrayConstructors/of/custom-ctor.js:
    1375   default: 'Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)'
    1376   strict mode: 'Test262Error: Expected a Test262Error but got a TypeError (Testing with Float64Array.)'
    1377 test/built-ins/TypedArrayConstructors/of/new-instance-using-custom-ctor.js:
    1378   default: 'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor (Testing with Float64Array.)'
    1379   strict mode: 'TypeError: TypedArray.of requires its this argument to subclass a TypedArray constructor (Testing with Float64Array.)'
    13801362test/intl402/DateTimeFormat/prototype/formatRange/en-US.js:
    13811363  default: 'Test262Error: Expected SameValue(«1/3/2019 – 1/5/2019», «1/3/2019 – 1/5/2019») to be true'
  • trunk/Source/JavaScriptCore/ChangeLog

    r267594 r267603  
     12020-09-25  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        %TypedArray%.{from, of} no longer perform AllocateTypedArray
     4        https://bugs.webkit.org/show_bug.cgi?id=216991
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Back in ES2015, %TypedArray%.of and %TypedArray%.from appear to have been based on the abstract operation
     9        AllocateTypedArray, which involved crawling the prototype chain to find the appropriate constructor and
     10        only permitted `this` to be a (derived) typed array.
     11
     12        This appears to have gone away as of ES2016 -- we simply expect `this` to be a constructor and verify that it
     13        produced a typed array (of sufficient length).
     14
     15        * builtins/BuiltinNames.h:
     16        * builtins/TypedArrayConstructor.js:
     17        (of):
     18        (from):
     19        (allocateInt8Array): Deleted.
     20        (allocateInt16Array): Deleted.
     21        (allocateInt32Array): Deleted.
     22        (allocateUint32Array): Deleted.
     23        (allocateUint16Array): Deleted.
     24        (allocateUint8Array): Deleted.
     25        (allocateUint8ClampedArray): Deleted.
     26        (allocateFloat32Array): Deleted.
     27        (allocateFloat64Array): Deleted.
     28        * runtime/JSGenericTypedArrayViewConstructor.h:
     29        * runtime/JSGenericTypedArrayViewConstructorInlines.h:
     30        (JSC::JSGenericTypedArrayViewConstructor<ViewClass>::finishCreation):
     31        (JSC::JSGenericTypedArrayViewConstructor<ViewClass>::create):
     32        * runtime/JSGlobalObject.cpp:
     33        (JSC::JSGlobalObject::init):
     34
    1352020-09-25  Yusuke Suzuki  <ysuzuki@apple.com>
    236
  • trunk/Source/JavaScriptCore/builtins/BuiltinNames.h

    r267519 r267603  
    9191    macro(set) \
    9292    macro(shift) \
    93     macro(allocateTypedArray) \
    9493    macro(Int8Array) \
    9594    macro(Int16Array) \
  • trunk/Source/JavaScriptCore/builtins/TypedArrayConstructor.js

    r265907 r267603  
    2424 */
    2525
    26 // According to the spec we are supposed to crawl the prototype chain looking
    27 // for the a TypedArray constructor. The way we implement this is with a
    28 // private function, @alloctateTypedArray, on each of the prototypes.
    29 // This enables us to optimize this lookup in the inline cache.
    30 
    3126function of(/* items... */)
    3227{
    3328    "use strict";
    3429    var len = arguments.length;
    35     var constructFunction = @getByIdDirectPrivate(this, "allocateTypedArray");
    36     if (constructFunction === @undefined)
    37         @throwTypeError("TypedArray.of requires its this argument to subclass a TypedArray constructor");
    3830
    39     var result = constructFunction(len);
     31    if (!@isConstructor(this))
     32        @throwTypeError("TypedArray.of requires |this| to be a constructor");
     33
     34    var result = new this(len);
     35    if (@typedArrayLength(result) < len)
     36        @throwTypeError("TypedArray.of constructed typed array of insufficient length");
    4037
    4138    for (var i = 0; i < len; i++)
     
    4946    "use strict";
    5047
     48    if (!@isConstructor(this))
     49        @throwTypeError("TypedArray.from requires |this| to be a constructor");
     50
    5151    var mapFn = @argument(1);
    52 
    5352    var thisArg;
    54 
    5553    if (mapFn !== @undefined) {
    5654        if (!@isCallable(mapFn))
     
    8684        }
    8785
    88         var constructFunction = @getByIdDirectPrivate(this, "allocateTypedArray");
    89         if (constructFunction === @undefined)
    90             @throwTypeError("TypedArray.from requires its this argument subclass a TypedArray constructor");
    91 
    92         var result = constructFunction(k);
     86        var result = new this(k);
     87        if (@typedArrayLength(result) < k)
     88            @throwTypeError("TypedArray.from constructed typed array of insufficient length");
    9389
    9490        for (var i = 0; i < k; i++)
    9591            result[i] = accumulator[i];
    96 
    9792
    9893        return result;
     
    10196    var arrayLikeLength = @toLength(arrayLike.length);
    10297
    103     var constructFunction = @getByIdDirectPrivate(this, "allocateTypedArray");
    104     if (constructFunction === @undefined)
    105         @throwTypeError("this does not subclass a TypedArray constructor");
    106 
    107     var result = constructFunction(arrayLikeLength);
     98    var result = new this(arrayLikeLength);
     99    if (@typedArrayLength(result) < arrayLikeLength)
     100        @throwTypeError("TypedArray.from constructed typed array of insufficient length");
    108101
    109102    var k = 0;
     
    119112    return result;
    120113}
    121 
    122 function allocateInt8Array(length)
    123 {
    124     return new @Int8Array(length);
    125 }
    126 
    127 function allocateInt16Array(length)
    128 {
    129     return new @Int16Array(length);   
    130 }
    131 
    132 function allocateInt32Array(length)
    133 {
    134     return new @Int32Array(length);   
    135 }
    136 
    137 function allocateUint32Array(length)
    138 {
    139     return new @Uint32Array(length);
    140 }
    141 
    142 function allocateUint16Array(length)
    143 {
    144     return new @Uint16Array(length);   
    145 }
    146 
    147 function allocateUint8Array(length)
    148 {
    149     return new @Uint8Array(length);   
    150 }
    151 
    152 function allocateUint8ClampedArray(length)
    153 {
    154     return new @Uint8ClampedArray(length);
    155 }
    156 
    157 function allocateFloat32Array(length)
    158 {
    159     return new @Float32Array(length);
    160 }
    161 
    162 function allocateFloat64Array(length)
    163 {
    164     return new @Float64Array(length);
    165 }
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h

    r267594 r267603  
    5858
    5959    static JSGenericTypedArrayViewConstructor* create(
    60         VM&, JSGlobalObject*, Structure*, JSObject* prototype, const String& name, FunctionExecutable* privateAllocator);
     60        VM&, JSGlobalObject*, Structure*, JSObject* prototype, const String& name);
    6161
    6262    // FIXME: We should fix the warnings for extern-template in JSObject template classes: https://bugs.webkit.org/show_bug.cgi?id=161979
     
    127127private:
    128128    JSGenericTypedArrayViewConstructor(VM&, Structure*);
    129     void finishCreation(VM&, JSGlobalObject*, JSObject* prototype, const String& name, FunctionExecutable* privateAllocator);
     129    void finishCreation(VM&, JSGlobalObject*, JSObject* prototype, const String& name);
    130130};
    131131
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructorInlines.h

    r267594 r267603  
    4545
    4646template<typename ViewClass>
    47 void JSGenericTypedArrayViewConstructor<ViewClass>::finishCreation(VM& vm, JSGlobalObject* globalObject, JSObject* prototype, const String& name, FunctionExecutable* privateAllocator)
     47void JSGenericTypedArrayViewConstructor<ViewClass>::finishCreation(VM& vm, JSGlobalObject*, JSObject* prototype, const String& name)
    4848{
    4949    Base::finishCreation(vm, ViewClass::TypedArrayStorageType == TypeDataView ? 1 : 3, name, PropertyAdditionMode::WithoutStructureTransition);
    5050    putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
    5151    putDirectWithoutTransition(vm, vm.propertyNames->BYTES_PER_ELEMENT, jsNumber(ViewClass::elementSize), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly | PropertyAttribute::DontDelete);
    52 
    53     if (privateAllocator)
    54         putDirectBuiltinFunction(vm, globalObject, vm.propertyNames->builtinNames().allocateTypedArrayPrivateName(), privateAllocator, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
    5552}
    5653
     
    5956JSGenericTypedArrayViewConstructor<ViewClass>::create(
    6057    VM& vm, JSGlobalObject* globalObject, Structure* structure, JSObject* prototype,
    61     const String& name, FunctionExecutable* privateAllocator)
     58    const String& name)
    6259{
    6360    JSGenericTypedArrayViewConstructor* result =
    6461        new (NotNull, allocateCell<JSGenericTypedArrayViewConstructor>(vm.heap))
    6562        JSGenericTypedArrayViewConstructor(vm, structure);
    66     result->finishCreation(vm, globalObject, prototype, name, privateAllocator);
     63    result->finishCreation(vm, globalObject, prototype, name);
    6764    return result;
    6865}
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r267594 r267603  
    707707            init.setPrototype(JS ## type ## ArrayPrototype::create(init.vm, init.global, JS ## type ## ArrayPrototype::createStructure(init.vm, init.global, init.global->m_typedArrayProto.get(init.global)))); \
    708708            init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \
    709             init.setConstructor(JS ## type ## ArrayConstructor::create(init.vm, init.global, JS ## type ## ArrayConstructor::createStructure(init.vm, init.global, init.global->m_typedArraySuperConstructor.get(init.global)), init.prototype, #type "Array"_s, typedArrayConstructorAllocate ## type ## ArrayCodeGenerator(init.vm))); \
     709            init.setConstructor(JS ## type ## ArrayConstructor::create(init.vm, init.global, JS ## type ## ArrayConstructor::createStructure(init.vm, init.global, init.global->m_typedArraySuperConstructor.get(init.global)), init.prototype, #type "Array"_s)); \
    710710            init.global->putDirect(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast<unsigned>(PropertyAttribute::DontEnum)); \
    711711        });
     
    717717            init.setPrototype(JSDataViewPrototype::create(init.vm, JSDataViewPrototype::createStructure(init.vm, init.global, init.global->m_objectPrototype.get())));
    718718            init.setStructure(JSDataView::createStructure(init.vm, init.global, init.prototype));
    719             init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, "DataView"_s, nullptr));
     719            init.setConstructor(JSDataViewConstructor::create(init.vm, init.global, JSDataViewConstructor::createStructure(init.vm, init.global, init.global->m_functionPrototype.get()), init.prototype, "DataView"_s));
    720720        });
    721721   
Note: See TracChangeset for help on using the changeset viewer.