Changeset 273750 in webkit


Ignore:
Timestamp:
Mar 2, 2021 12:00:31 PM (17 months ago)
Author:
Alexey Shvayka
Message:

TypedArray's DefineOwnProperty? should throw in case of failure
https://bugs.webkit.org/show_bug.cgi?id=220492

Reviewed by Darin Adler.

JSTests:

  • stress/array-species-config-array-constructor.js:
  • stress/put-direct-index-broken-2.js:

Update assertions, which are most certainly incorrect, partly aligning JSC with V8.

  • stress/typedarray-access-monomorphic-neutered.js:
  • stress/typedarray-access-neutered.js:
  • stress/typedarray-defineOwnProperty-error.js: Added.
  • test262/expectations.yaml:

Incorrect tests are being updated at https://github.com/tc39/test262/pull/2958.

Source/JavaScriptCore:

While web reality [1] requires failures of the most TypeArray internal methods to be
silent, DefineOwnProperty? can fail loudly if called via Object.defineProperty.

With this patch, TypeError is thrown for detached buffer, out-of-bounds index, and
non-index canonical numeric string key. Aligns JSC with the spec [2], V8, and SM.

[1]: https://github.com/tc39/ecma262/pull/2164
[2]: https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects-defineownproperty-p-desc (step 3.b)

  • runtime/JSGenericTypedArrayViewInlines.h:

(JSC::JSGenericTypedArrayView<Adaptor>::defineOwnProperty):

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r273717 r273750  
     12021-03-02  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        TypedArray's [[DefineOwnProperty]] should throw in case of failure
     4        https://bugs.webkit.org/show_bug.cgi?id=220492
     5
     6        Reviewed by Darin Adler.
     7
     8        * stress/array-species-config-array-constructor.js:
     9        * stress/put-direct-index-broken-2.js:
     10        Update assertions, which are most certainly incorrect, partly aligning JSC with V8.
     11
     12        * stress/typedarray-access-monomorphic-neutered.js:
     13        * stress/typedarray-access-neutered.js:
     14        * stress/typedarray-defineOwnProperty-error.js: Added.
     15        * test262/expectations.yaml:
     16        Incorrect tests are being updated at https://github.com/tc39/test262/pull/2958.
     17
    1182021-03-01  Yusuke Suzuki  <ysuzuki@apple.com>
    219
  • trunk/JSTests/stress/array-species-config-array-constructor.js

    r268640 r273750  
    3232
    3333function test() {
    34     foo.concat([1]);
     34    shouldThrow(() => {
     35        foo.concat([1]);
     36    }, "TypeError: Attempting to store out-of-bounds property on a typed array at index: 0");
    3537    foo = [1,2,3,4];
    3638    foo.slice(0);
  • trunk/JSTests/stress/put-direct-index-broken-2.js

    r268640 r273750  
    5757        err = e;
    5858    }
    59     assert(!err);
     59    assert(err.toString() == "TypeError: Attempting to store out-of-bounds property on a typed array at index: 0");
    6060});
    6161
  • trunk/JSTests/stress/typedarray-access-monomorphic-neutered.js

    r268640 r273750  
    2121    testNoException("array[0] = 1", array);
    2222    testNoException("array[i] = 1", array);
    23     testNoException("Object.defineProperty(array, 0, { value: 1, writable: true, configurable: true, enumerable: true })", array);
    2423}
    2524
     
    4140    testFTLNoException("array[0] = 1", array, failArray);
    4241    testFTLNoException("array[i] = 1", array, failArray);
    43     testFTLNoException("Object.defineProperty(array, 0, { value: 1, writable: true, configurable: true, enumerable: true })", array, failArray);
    4442}
  • trunk/JSTests/stress/typedarray-access-neutered.js

    r268640 r273750  
    1717    testNoException((array) => Object.getOwnPropertyDescriptor(array, 0), i);
    1818    testNoException((array) => array[0] = 1, i);
    19     testNoException((array) => Object.defineProperty(array, 0, { value: 1, writable: true, configurable: true, enumerable: true }), i)
    2019}
  • trunk/JSTests/test262/expectations.yaml

    r273661 r273750  
    827827  default: 'SyntaxError: Invalid regular expression: number too large in {} quantifier'
    828828  strict mode: 'SyntaxError: Invalid regular expression: number too large in {} quantifier'
     829test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js:
     830  default: 'Test262Error: Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42n;}}}) must return false Expected SameValue(«true», «false») to be true (Testing with BigInt64Array.)'
     831  strict mode: 'Test262Error: Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42n;}}}) must return false Expected SameValue(«true», «false») to be true (Testing with BigInt64Array.)'
     832test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js:
     833  default: 'Test262Error: Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42;}}} ) must return false Expected SameValue(«true», «false») to be true (Testing with Float64Array.)'
     834  strict mode: 'Test262Error: Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42;}}} ) must return false Expected SameValue(«true», «false») to be true (Testing with Float64Array.)'
    829835test/intl402/DateTimeFormat/prototype/formatRange/en-US.js:
    830836  default: 'Test262Error: Expected SameValue(«1/3/2019 – 1/5/2019», «1/3/2019 – 1/5/2019») to be true'
  • trunk/Source/JavaScriptCore/ChangeLog

    r273718 r273750  
     12021-03-02  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        TypedArray's [[DefineOwnProperty]] should throw in case of failure
     4        https://bugs.webkit.org/show_bug.cgi?id=220492
     5
     6        Reviewed by Darin Adler.
     7
     8        While web reality [1] requires failures of the most TypeArray internal methods to be
     9        silent, [[DefineOwnProperty]] can fail loudly if called via Object.defineProperty.
     10
     11        With this patch, TypeError is thrown for detached buffer, out-of-bounds index, and
     12        non-index canonical numeric string key. Aligns JSC with the spec [2], V8, and SM.
     13
     14        [1]: https://github.com/tc39/ecma262/pull/2164
     15        [2]: https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects-defineownproperty-p-desc (step 3.b)
     16
     17        * runtime/JSGenericTypedArrayViewInlines.h:
     18        (JSC::JSGenericTypedArrayView<Adaptor>::defineOwnProperty):
     19
    1202021-03-01  Keith Miller  <keith_miller@apple.com>
    221
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h

    r273138 r273750  
    404404        };
    405405
    406         if (index.value() >= thisObject->m_length)
    407             return false;
     406        if (thisObject->isDetached())
     407            return typeError(globalObject, scope, shouldThrow, typedArrayBufferHasBeenDetachedErrorMessage);
     408
     409        if (!thisObject->inBounds(index.value()))
     410            return throwTypeErrorIfNeeded("Attempting to store out-of-bounds property on a typed array at index: ");
    408411
    409412        if (descriptor.isAccessorDescriptor())
     
    419422            return throwTypeErrorIfNeeded("Attempting to store non-writable property on a typed array at index: ");
    420423
     424        scope.release();
    421425        if (descriptor.value())
    422             RELEASE_AND_RETURN(scope, thisObject->setIndex(globalObject, index.value(), descriptor.value()));
     426            thisObject->setIndex(globalObject, index.value(), descriptor.value());
    423427
    424428        return true;
     
    426430
    427431    if (isCanonicalNumericIndexString(propertyName))
    428         return false;
     432        return typeError(globalObject, scope, shouldThrow, "Attempting to store canonical numeric string property on a typed array"_s);
    429433
    430434    RELEASE_AND_RETURN(scope, Base::defineOwnProperty(thisObject, globalObject, propertyName, descriptor, shouldThrow));
Note: See TracChangeset for help on using the changeset viewer.