From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../internals/DefineOwnProperty/BigInt/browser.js | 0 .../DefineOwnProperty/BigInt/desc-value-throws.js | 54 ++ .../BigInt/detached-buffer-throws-realm.js | 54 ++ .../BigInt/detached-buffer-throws.js | 50 ++ .../DefineOwnProperty/BigInt/detached-buffer.js | 122 ++++ .../BigInt/key-is-greater-than-last-index.js | 49 ++ .../BigInt/key-is-lower-than-zero.js | 36 ++ .../DefineOwnProperty/BigInt/key-is-minus-zero.js | 38 ++ .../BigInt/key-is-not-canonical-index.js | 100 +++ .../DefineOwnProperty/BigInt/key-is-not-integer.js | 126 ++++ .../BigInt/key-is-not-numeric-index-throws.js | 47 ++ .../BigInt/key-is-not-numeric-index.js | 54 ++ .../key-is-numericindex-accessor-desc-throws.js | 46 ++ .../BigInt/key-is-numericindex-accessor-desc.js | 60 ++ .../key-is-numericindex-desc-configurable.js | 38 ++ ...is-numericindex-desc-not-configurable-throws.js | 41 ++ ...y-is-numericindex-desc-not-enumerable-throws.js | 41 ++ .../key-is-numericindex-desc-not-enumerable.js | 37 ++ ...key-is-numericindex-desc-not-writable-throws.js | 41 ++ .../key-is-numericindex-desc-not-writable.js | 37 ++ .../BigInt/key-is-numericindex.js | 40 ++ .../DefineOwnProperty/BigInt/key-is-symbol.js | 56 ++ .../BigInt/non-extensible-new-key.js | 46 ++ .../BigInt/non-extensible-redefine-key.js | 59 ++ .../DefineOwnProperty/BigInt/set-value.js | 57 ++ .../internals/DefineOwnProperty/BigInt/shell.js | 42 ++ .../BigInt/this-is-not-extensible.js | 33 + .../BigInt/tonumber-value-detached-buffer.js | 61 ++ .../internals/DefineOwnProperty/browser.js | 0 .../conversion-operation-consistent-nan.js | 100 +++ .../DefineOwnProperty/conversion-operation.js | 65 ++ .../DefineOwnProperty/desc-value-throws.js | 52 ++ .../detached-buffer-throws-realm.js | 54 ++ .../DefineOwnProperty/detached-buffer-throws.js | 50 ++ .../internals/DefineOwnProperty/detached-buffer.js | 143 +++++ .../key-is-greater-than-last-index.js | 49 ++ .../DefineOwnProperty/key-is-lower-than-zero.js | 36 ++ .../DefineOwnProperty/key-is-minus-zero.js | 38 ++ .../key-is-not-canonical-index.js | 100 +++ .../DefineOwnProperty/key-is-not-integer.js | 126 ++++ .../key-is-not-numeric-index-throws.js | 47 ++ .../DefineOwnProperty/key-is-not-numeric-index.js | 54 ++ .../key-is-numericindex-accessor-desc-throws.js | 46 ++ .../key-is-numericindex-accessor-desc.js | 60 ++ .../key-is-numericindex-desc-configurable.js | 38 ++ ...is-numericindex-desc-not-configurable-throws.js | 41 ++ ...y-is-numericindex-desc-not-enumerable-throws.js | 41 ++ .../key-is-numericindex-desc-not-enumerable.js | 37 ++ ...key-is-numericindex-desc-not-writable-throws.js | 41 ++ .../key-is-numericindex-desc-not-writable.js | 37 ++ .../DefineOwnProperty/key-is-numericindex.js | 47 ++ .../internals/DefineOwnProperty/key-is-symbol.js | 56 ++ .../DefineOwnProperty/non-extensible-new-key.js | 46 ++ .../non-extensible-redefine-key.js | 59 ++ .../internals/DefineOwnProperty/set-value.js | 57 ++ .../internals/DefineOwnProperty/shell.js | 694 +++++++++++++++++++++ .../DefineOwnProperty/this-is-not-extensible.js | 33 + .../tonumber-value-detached-buffer.js | 64 ++ .../internals/Delete/BigInt/browser.js | 0 .../detached-buffer-key-is-not-numeric-index.js | 34 + .../Delete/BigInt/detached-buffer-key-is-symbol.js | 30 + .../Delete/BigInt/detached-buffer-realm.js | 35 ++ .../internals/Delete/BigInt/detached-buffer.js | 33 + .../Delete/BigInt/indexed-value-ab-non-strict.js | 46 ++ .../BigInt/indexed-value-ab-strict-strict.js | 55 ++ .../Delete/BigInt/indexed-value-sab-non-strict.js | 35 ++ .../BigInt/indexed-value-sab-strict-strict.js | 44 ++ .../Delete/BigInt/infinity-detached-buffer.js | 35 ++ .../key-is-not-canonical-index-non-strict.js | 69 ++ .../key-is-not-canonical-index-strict-strict.js | 69 ++ .../BigInt/key-is-not-minus-zero-non-strict.js | 46 ++ .../BigInt/key-is-not-minus-zero-strict-strict.js | 49 ++ .../BigInt/key-is-not-numeric-index-get-throws.js | 40 ++ .../BigInt/key-is-not-numeric-index-non-strict.js | 46 ++ .../key-is-not-numeric-index-strict-strict.js | 50 ++ .../BigInt/key-is-out-of-bounds-non-strict.js | 49 ++ .../BigInt/key-is-out-of-bounds-strict-strict.js | 57 ++ .../internals/Delete/BigInt/key-is-symbol.js | 33 + .../internals/Delete/BigInt/shell.js | 42 ++ .../internals/Delete/browser.js | 0 .../detached-buffer-key-is-not-numeric-index.js | 36 ++ .../Delete/detached-buffer-key-is-symbol.js | 30 + .../internals/Delete/detached-buffer-realm.js | 35 ++ .../internals/Delete/detached-buffer.js | 33 + .../Delete/indexed-value-ab-non-strict.js | 46 ++ .../Delete/indexed-value-ab-strict-strict.js | 55 ++ .../Delete/indexed-value-sab-non-strict.js | 35 ++ .../Delete/indexed-value-sab-strict-strict.js | 44 ++ .../internals/Delete/infinity-detached-buffer.js | 35 ++ .../key-is-not-canonical-index-non-strict.js | 69 ++ .../key-is-not-canonical-index-strict-strict.js | 69 ++ .../internals/Delete/key-is-not-integer.js | 44 ++ .../Delete/key-is-not-minus-zero-non-strict.js | 46 ++ .../Delete/key-is-not-minus-zero-strict-strict.js | 49 ++ .../Delete/key-is-not-numeric-index-get-throws.js | 40 ++ .../Delete/key-is-not-numeric-index-non-strict.js | 46 ++ .../key-is-not-numeric-index-strict-strict.js | 50 ++ .../Delete/key-is-out-of-bounds-non-strict.js | 49 ++ .../Delete/key-is-out-of-bounds-strict-strict.js | 57 ++ .../internals/Delete/key-is-symbol.js | 33 + .../internals/Delete/shell.js | 179 ++++++ .../internals/Get/BigInt/browser.js | 0 .../detached-buffer-key-is-not-numeric-index.js | 30 + .../Get/BigInt/detached-buffer-key-is-symbol.js | 30 + .../internals/Get/BigInt/detached-buffer-realm.js | 38 ++ .../internals/Get/BigInt/detached-buffer.js | 38 ++ .../internals/Get/BigInt/indexed-value-sab.js | 31 + .../internals/Get/BigInt/indexed-value.js | 36 ++ .../Get/BigInt/infinity-detached-buffer.js | 40 ++ .../Get/BigInt/key-is-not-canonical-index.js | 63 ++ .../internals/Get/BigInt/key-is-not-integer.js | 39 ++ .../internals/Get/BigInt/key-is-not-minus-zero.js | 39 ++ .../BigInt/key-is-not-numeric-index-get-throws.js | 40 ++ .../Get/BigInt/key-is-not-numeric-index.js | 41 ++ .../internals/Get/BigInt/key-is-out-of-bounds.js | 45 ++ .../internals/Get/BigInt/key-is-symbol.js | 42 ++ .../internals/Get/BigInt/shell.js | 42 ++ .../internals/Get/browser.js | 0 .../detached-buffer-key-is-not-numeric-index.js | 30 + .../internals/Get/detached-buffer-key-is-symbol.js | 30 + .../internals/Get/detached-buffer-realm.js | 38 ++ .../internals/Get/detached-buffer.js | 38 ++ .../internals/Get/indexed-value-sab.js | 31 + .../internals/Get/indexed-value.js | 36 ++ .../internals/Get/infinity-detached-buffer.js | 41 ++ .../internals/Get/key-is-not-canonical-index.js | 63 ++ .../internals/Get/key-is-not-integer.js | 39 ++ .../internals/Get/key-is-not-minus-zero.js | 39 ++ .../Get/key-is-not-numeric-index-get-throws.js | 40 ++ .../internals/Get/key-is-not-numeric-index.js | 41 ++ .../internals/Get/key-is-out-of-bounds.js | 45 ++ .../internals/Get/key-is-symbol.js | 42 ++ .../TypedArrayConstructors/internals/Get/shell.js | 179 ++++++ .../internals/GetOwnProperty/BigInt/browser.js | 0 .../BigInt/detached-buffer-key-is-not-number.js | 40 ++ .../BigInt/detached-buffer-key-is-symbol.js | 33 + .../GetOwnProperty/BigInt/detached-buffer-realm.js | 43 ++ .../GetOwnProperty/BigInt/detached-buffer.js | 38 ++ .../BigInt/enumerate-detached-buffer.js | 44 ++ .../GetOwnProperty/BigInt/index-prop-desc.js | 38 ++ .../GetOwnProperty/BigInt/key-is-minus-zero.js | 39 ++ .../BigInt/key-is-not-canonical-index.js | 50 ++ .../GetOwnProperty/BigInt/key-is-not-integer.js | 33 + .../BigInt/key-is-not-numeric-index.js | 40 ++ .../GetOwnProperty/BigInt/key-is-out-of-bounds.js | 36 ++ .../GetOwnProperty/BigInt/key-is-symbol.js | 33 + .../internals/GetOwnProperty/BigInt/shell.js | 42 ++ .../internals/GetOwnProperty/browser.js | 0 .../detached-buffer-key-is-not-number.js | 40 ++ .../detached-buffer-key-is-symbol.js | 33 + .../GetOwnProperty/detached-buffer-realm.js | 43 ++ .../internals/GetOwnProperty/detached-buffer.js | 38 ++ .../GetOwnProperty/enumerate-detached-buffer.js | 44 ++ .../internals/GetOwnProperty/index-prop-desc.js | 40 ++ .../internals/GetOwnProperty/key-is-minus-zero.js | 39 ++ .../GetOwnProperty/key-is-not-canonical-index.js | 50 ++ .../internals/GetOwnProperty/key-is-not-integer.js | 33 + .../GetOwnProperty/key-is-not-numeric-index.js | 40 ++ .../GetOwnProperty/key-is-out-of-bounds.js | 36 ++ .../internals/GetOwnProperty/key-is-symbol.js | 33 + .../internals/GetOwnProperty/shell.js | 179 ++++++ .../abrupt-from-ordinary-has-parent-hasproperty.js | 65 ++ .../internals/HasProperty/BigInt/browser.js | 0 .../BigInt/detached-buffer-key-is-not-number.js | 31 + .../BigInt/detached-buffer-key-is-symbol.js | 33 + .../HasProperty/BigInt/detached-buffer-realm.js | 33 + .../HasProperty/BigInt/detached-buffer.js | 29 + .../internals/HasProperty/BigInt/indexed-value.js | 28 + .../BigInt/infinity-with-detached-buffer.js | 48 ++ .../HasProperty/BigInt/inherited-property.js | 37 ++ .../BigInt/key-is-greater-than-last-index.js | 29 + .../HasProperty/BigInt/key-is-lower-than-zero.js | 30 + .../HasProperty/BigInt/key-is-minus-zero.js | 30 + .../BigInt/key-is-not-canonical-index.js | 55 ++ .../HasProperty/BigInt/key-is-not-integer.js | 32 + .../HasProperty/BigInt/key-is-not-numeric-index.js | 31 + .../internals/HasProperty/BigInt/key-is-symbol.js | 30 + .../internals/HasProperty/BigInt/shell.js | 42 ++ .../abrupt-from-ordinary-has-parent-hasproperty.js | 65 ++ .../internals/HasProperty/browser.js | 0 .../detached-buffer-key-is-not-number.js | 31 + .../HasProperty/detached-buffer-key-is-symbol.js | 33 + .../internals/HasProperty/detached-buffer-realm.js | 32 + .../internals/HasProperty/detached-buffer.js | 29 + .../internals/HasProperty/indexed-value.js | 30 + .../HasProperty/infinity-with-detached-buffer.js | 52 ++ .../internals/HasProperty/inherited-property.js | 37 ++ .../HasProperty/key-is-greater-than-last-index.js | 29 + .../HasProperty/key-is-lower-than-zero.js | 30 + .../internals/HasProperty/key-is-minus-zero.js | 30 + .../HasProperty/key-is-not-canonical-index.js | 55 ++ .../internals/HasProperty/key-is-not-integer.js | 32 + .../HasProperty/key-is-not-numeric-index.js | 31 + .../internals/HasProperty/key-is-symbol.js | 30 + .../HasProperty/resizable-array-buffer-auto.js | 64 ++ .../HasProperty/resizable-array-buffer-fixed.js | 57 ++ .../internals/HasProperty/shell.js | 179 ++++++ .../internals/OwnPropertyKeys/BigInt/browser.js | 0 .../integer-indexes-and-string-and-symbol-keys-.js | 50 ++ .../BigInt/integer-indexes-and-string-keys.js | 43 ++ .../OwnPropertyKeys/BigInt/integer-indexes.js | 38 ++ .../OwnPropertyKeys/BigInt/not-enumerable-keys.js | 37 ++ .../internals/OwnPropertyKeys/BigInt/shell.js | 42 ++ .../internals/OwnPropertyKeys/browser.js | 0 .../integer-indexes-and-string-and-symbol-keys-.js | 50 ++ .../integer-indexes-and-string-keys.js | 43 ++ .../integer-indexes-resizable-array-buffer-auto.js | 70 +++ ...integer-indexes-resizable-array-buffer-fixed.js | 61 ++ .../internals/OwnPropertyKeys/integer-indexes.js | 38 ++ .../OwnPropertyKeys/not-enumerable-keys.js | 37 ++ .../internals/OwnPropertyKeys/shell.js | 161 +++++ .../internals/Set/BigInt/bigint-tobigint64.js | 102 +++ .../internals/Set/BigInt/bigint-tobiguint64.js | 104 +++ .../internals/Set/BigInt/boolean-tobigint.js | 61 ++ .../internals/Set/BigInt/browser.js | 0 .../detached-buffer-key-is-not-numeric-index.js | 32 + .../Set/BigInt/detached-buffer-key-is-symbol.js | 32 + .../internals/Set/BigInt/detached-buffer-realm.js | 41 ++ .../internals/Set/BigInt/detached-buffer.js | 56 ++ .../internals/Set/BigInt/indexed-value.js | 40 ++ .../internals/Set/BigInt/key-is-minus-zero.js | 26 + .../Set/BigInt/key-is-not-canonical-index.js | 51 ++ .../internals/Set/BigInt/key-is-not-integer.js | 35 ++ .../BigInt/key-is-not-numeric-index-set-throws.js | 42 ++ .../Set/BigInt/key-is-not-numeric-index.js | 47 ++ .../internals/Set/BigInt/key-is-out-of-bounds.js | 37 ++ .../internals/Set/BigInt/key-is-symbol.js | 53 ++ .../internals/Set/BigInt/null-tobigint.js | 63 ++ .../internals/Set/BigInt/number-tobigint.js | 87 +++ .../internals/Set/BigInt/shell.js | 42 ++ .../internals/Set/BigInt/string-nan-tobigint.js | 67 ++ .../internals/Set/BigInt/string-tobigint.js | 87 +++ .../internals/Set/BigInt/symbol-tobigint.js | 65 ++ .../Set/BigInt/tonumber-value-detached-buffer.js | 40 ++ .../internals/Set/BigInt/tonumber-value-throws.js | 62 ++ .../internals/Set/BigInt/undefined-tobigint.js | 64 ++ .../internals/Set/bigint-tonumber.js | 61 ++ .../internals/Set/browser.js | 0 .../Set/conversion-operation-consistent-nan.js | 107 ++++ .../internals/Set/conversion-operation.js | 63 ++ .../detached-buffer-key-is-not-numeric-index.js | 32 + .../internals/Set/detached-buffer-key-is-symbol.js | 32 + .../internals/Set/detached-buffer-realm.js | 41 ++ .../internals/Set/detached-buffer.js | 57 ++ .../internals/Set/indexed-value.js | 55 ++ .../internals/Set/key-is-minus-zero.js | 29 + .../internals/Set/key-is-not-canonical-index.js | 60 ++ .../internals/Set/key-is-not-integer.js | 36 ++ .../Set/key-is-not-numeric-index-set-throws.js | 42 ++ .../internals/Set/key-is-not-numeric-index.js | 49 ++ .../internals/Set/key-is-out-of-bounds.js | 34 + .../internals/Set/key-is-symbol.js | 50 ++ .../TypedArrayConstructors/internals/Set/shell.js | 694 +++++++++++++++++++++ .../Set/tonumber-value-detached-buffer.js | 52 ++ .../internals/Set/tonumber-value-throws.js | 63 ++ .../TypedArrayConstructors/internals/browser.js | 0 .../TypedArrayConstructors/internals/shell.js | 0 257 files changed, 13228 insertions(+) create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/infinity-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArrayConstructors/internals/shell.js (limited to 'js/src/tests/test262/built-ins/TypedArrayConstructors/internals') diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.js new file mode 100644 index 0000000000..687ae5e5ef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Return abrupt from the evaluation of ToNumber(desc.value) +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.throws(Test262Error, function() { + Object.defineProperty(sample, "0", {value: obj}); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.js new file mode 100644 index 0000000000..2a17145caf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid descriptor & canonical numeric string if buffer is detached. + (honoring the Realm of the current execution context) +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA([0n]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js new file mode 100644 index 0000000000..747595e86b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js @@ -0,0 +1,50 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid descriptor & canonical numeric string if buffer is detached. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 0000000000..b857d4c3a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js @@ -0,0 +1,122 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if this has valid numeric index and a detached buffer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +var desc = { + value: 0n, + configurable: false, + enumerable: true, + writable: true +}; + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.defineProperty(sample, '0', desc), + false, + 'Reflect.defineProperty(sample, "0", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '-1', desc), + false, + 'Reflect.defineProperty(sample, "-1", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '1.1', desc), + false, + 'Reflect.defineProperty(sample, "1.1", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '-0', desc), + false, + 'Reflect.defineProperty(sample, "-0", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue(Reflect.defineProperty(sample, '2', { + configurable: true, + enumerable: true, + writable: true, + value: obj + }), false, 'Reflect.defineProperty(sample, "2", {configurable: true, enumerable: true, writable: true, value: obj}) must return false'); + + assert.sameValue(Reflect.defineProperty(sample, '3', { + configurable: false, + enumerable: false, + writable: true, + value: obj + }), false, 'Reflect.defineProperty(sample, "3", {configurable: false, enumerable: false, writable: true, value: obj}) must return false'); + + assert.sameValue(Reflect.defineProperty(sample, '4', { + writable: false, + configurable: false, + enumerable: true, + value: obj + }), false, 'Reflect.defineProperty(sample, "4", {writable: false, configurable: false, enumerable: true, value: obj}) must return false'); + + assert.sameValue( + Reflect.defineProperty(sample, '42', desc), + false, + 'Reflect.defineProperty(sample, "42", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '43', desc), + false, + 'Reflect.defineProperty(sample, "43", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue(Reflect.defineProperty(sample, '5', { + get: function() {} + }), false, 'Reflect.defineProperty(sample, "5", {get: function() {}}) must return false'); + + assert.sameValue(Reflect.defineProperty(sample, '6', { + configurable: false, + enumerable: true, + writable: true + }), false, 'Reflect.defineProperty(sample, "6", {configurable: false, enumerable: true, writable: true}) must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..08799367b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is >= [[ArrayLength]] +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + ... + v. Let length be the value of O's [[ArrayLength]] internal slot. + vi. If intIndex ≥ length, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex == length" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex > length" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 0000000000..b7e490c51d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is < 0 +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + iv. If intIndex < 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-1" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..5dadc628c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is "-0" +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ii. Let intIndex be numericIndex. + iii. If intIndex = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "defineProperty returns false" + ); + assert.sameValue(sample[0], 0n, "does not change the value for [0]"); + assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..7fdad5a989 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,100 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Sets an ordinary property value if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +var fnset = function() {}; +var fnget = function() {}; + +var acDesc = { + get: fnget, + set: fnset, + enumerable: true, + configurable: false +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var dataDesc = { + value: 42n, + writable: true, + configurable: true + }; + + var sample1 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample1, key, dataDesc), + true, + "return true after defining data property [" + key + "]" + ); + + assert.sameValue(sample1[key], 42n, "value is set to [" + key + "]"); + verifyNotEnumerable(sample1, key); + verifyWritable(sample1, key); + verifyConfigurable(sample1, key); + + assert.sameValue(sample1[0], undefined, "no value is set on sample1[0]"); + assert.sameValue(sample1.length, 0, "length is still 0"); + + var sample2 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample2, key, acDesc), + true, + "return true after defining accessors property [" + key + "]" + ); + + var desc = Object.getOwnPropertyDescriptor(sample2, key); + verifyEnumerable(sample2, key); + assert.sameValue(desc.get, fnget, "accessor's get [" + key + "]"); + assert.sameValue(desc.set, fnset, "accessor's set [" + key + "]"); + verifyNotConfigurable(sample2, key); + + assert.sameValue(sample2[0], undefined,"no value is set on sample2[0]"); + assert.sameValue(sample2.length, 0, "length is still 0"); + + var sample3 = new TA(); + Object.preventExtensions(sample3); + + assert.sameValue( + Reflect.defineProperty(sample3, key, dataDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample3, key), undefined); + + var sample4 = new TA(); + Object.preventExtensions(sample4); + + assert.sameValue( + Reflect.defineProperty(sample4, key, acDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample4, key), undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..c0c53679d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,126 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is not an integer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0.1", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.1" + ); + assert.sameValue(sample[0], 0n, "'0.1' - does not change the value for [0]"); + assert.sameValue( + sample["0.1"], + undefined, + "'0.1' - does not define a value for ['0.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "0.000001", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.000001" + ); + assert.sameValue( + sample[0], 0n, + "'0.000001' - does not change the value for [0]" + ); + assert.sameValue( + sample["0.000001"], + undefined, + "'0.000001' - does not define a value for ['0.000001']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "1.1" + ); + assert.sameValue(sample[1], 0n, "'1.1' - does not change the value for [1]"); + assert.sameValue( + sample["1.1"], + undefined, + "'1.1' - does not define a value for ['1.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "Infinity", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "Infinity" + ); + assert.sameValue( + sample[0], 0n, + "'Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0n, + "'Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["Infinity"], + undefined, + "'Infinity' - does not define a value for ['Infinity']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-Infinity", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-Infinity" + ); + assert.sameValue( + sample[0], 0n, + "'-Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0n, + "'-Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["-Infinity"], + undefined, + "'-Infinity' - does not define a value for ['-Infinity']" + ); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js new file mode 100644 index 0000000000..272c7e74f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid descriptor & canonical numeric string that is invalid index. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 3. If ! IsIntegralNumber(index) is false, return false. + 4. If index is -0𝔽, return false. + 5. If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return false. +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..c2d3b19e17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "return true after defining property" + ); + + assert.sameValue(sample.foo, 42); + verifyNotWritable(sample, "foo"); + verifyNotConfigurable(sample, "foo"); + verifyNotEnumerable(sample, "foo"); + + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyConfigurable(sample, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js new file mode 100644 index 0000000000..6093419b97 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & accessor descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iv. If IsAccessorDescriptor(Desc) is true, return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42n; }, + }); + }, "get accessor"); + assert.sameValue(sample[0], 0n, "get accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + set: function(_v) {}, + }); + }, "set accessor"); + assert.sameValue(sample[0], 0n, "set accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42n; }, + set: function(_v) {}, + }); + }, "get and set accessors"); + assert.sameValue(sample[0], 0n, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js new file mode 100644 index 0000000000..073c905f19 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Descriptor is an + AccessorDescriptor +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + vii. If IsAccessorDescriptor(Desc) is true, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get accessor" + ); + assert.sameValue(sample[0], 0n, "get accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + enumerable: true + }), + false, + "set accessor" + ); + assert.sameValue(sample[0], 0n, "set accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get and set accessors" + ); + assert.sameValue(sample[0], 0n, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js new file mode 100644 index 0000000000..02fbb4e786 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns true if key is a numeric index and Desc.[[Configurable]] is true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42n, + configurable: true, + enumerable: true, + writable: true + }), + true, + "defineProperty's result" + ); + assert.sameValue(sample[0], 42n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js new file mode 100644 index 0000000000..970f59f008 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & non-configurable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + ii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false. +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + configurable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42n, + writable: true, + enumerable: true, + configurable: false, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js new file mode 100644 index 0000000000..a8878645dd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & non-enumerable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + enumerable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42n, + writable: true, + enumerable: false, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js new file mode 100644 index 0000000000..104cf33d0f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Enumerable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ix. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is + false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42n, + configurable: false, + enumerable: false, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js new file mode 100644 index 0000000000..6ddf3303df --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & non-writable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + v. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + writable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42n, + writable: false, + enumerable: true, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js new file mode 100644 index 0000000000..48adf6678e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Writable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, + return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42n, + configurable: false, + enumerable: true, + writable: false + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.js new file mode 100644 index 0000000000..aaadd22433 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns true after setting a valid numeric index key +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 42n]); + + assert.sameValue(Reflect.defineProperty(sample, '0', { + value: 8n, + configurable: true, + enumerable: true, + writable: true + }), true, 'Reflect.defineProperty(sample, "0", {value: 8n, configurable: true, enumerable: true, writable: true}) must return true'); + + assert.sameValue(sample[0], 8n, 'The value of sample[0] is 8n'); + var desc = Object.getOwnPropertyDescriptor(sample, '0'); + assert.sameValue(desc.value, 8n, 'The value of desc.value is 8n'); + assert.sameValue(desc.configurable, true, 'The value of desc.configurable is true'); + assert.sameValue(desc.enumerable, true, 'The value of desc.enumerable is true'); + assert.sameValue(desc.writable, true, 'The value of desc.writable is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..ec5fed280c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Define an ordinary property value if key is a Symbol +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + var s1 = Symbol("foo"); + assert.sameValue( + Reflect.defineProperty(sample, s1, { + value: 42, + configurable: true + }), + true, + "return true after defining property" + ); + + assert.sameValue(sample[s1], 42); + verifyNotWritable(sample, s1); + verifyNotEnumerable(sample, s1); + verifyConfigurable(sample, s1); + + var s2 = Symbol("bar"); + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, s2, { + get: fnget, + set: fnset, + enumerable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, s2); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + assert.sameValue(desc.enumerable, true); + verifyNotConfigurable(sample, s2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js new file mode 100644 index 0000000000..0f6624e723 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Can't define a new non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + false, + "return false on a non-extensible object - data descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "foo"), undefined); + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: function() {}, + set: function() {}, + enumerable: false, + configurable: true + }), + false, + "return false on a non-extensible object - accessor descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "bar"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js new file mode 100644 index 0000000000..6db2aa90ca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Redefine a non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + sample.foo = true; + sample.bar = true; + + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "data descriptor" + ); + + assert.sameValue(sample.foo, 42); + verifyEnumerable(sample, "foo"); + verifyWritable(sample, "foo"); + verifyConfigurable(sample, "foo"); + + var fnget = function() {}; + var fnset = function() {}; + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: false + }), + true, + "accessor descriptor" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyNotConfigurable(sample, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.js new file mode 100644 index 0000000000..6998041783 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Set the value and return true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 0n]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", {value: 1n}), + true, + "set value for sample[0] returns true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1", {value: 2n}), + true, + "set value for sample[1] returns true" + ); + + assert.sameValue(sample[0], 1n, "sample[0]"); + assert.sameValue(sample[1], 2n, "sample[1]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js new file mode 100644 index 0000000000..f3e20f5bea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false for non-numeric index property value if `this` is not extensible +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.preventExtensions(sample); + + assert.sameValue(Reflect.defineProperty(sample, "foo", {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, "foo"), undefined); + + var s = Symbol("1"); + assert.sameValue(Reflect.defineProperty(sample, s, {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, s), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..c10b7a5579 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,61 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Defining a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, should return + true and not modify the typed array. +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA([17n]); + + var desc = { + value: { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42n; + } + } + }; + + assert.sameValue( + Reflect.defineProperty(ta, 0, desc), + true, + 'Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42n;}}}) must return true' + ); + + assert.sameValue(ta[0], undefined, 'The value of ta[0] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js new file mode 100644 index 0000000000..12b8eb5042 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js @@ -0,0 +1,100 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: Consistent canonicalization of NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[DefineOwnProperty]] ( P, Desc) + + ... + 3. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + #sec-integerindexedelementset + IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. + ... + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(FA) { + var precision = floatTypedArrayConstructorPrecision(FA); + var samples = new FA(1); + var controls, idx, aNaN; + + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx]; + controls = new FA([aNaN, aNaN, aNaN]); + + Object.defineProperty(samples, "0", { value: aNaN }); + + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `samples (index=${idx}) produces a valid NaN (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `controls (index=${idx}) produces a valid NaN (${precision} precision)` + ); + } + } +}, floatArrayConstructors); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js new file mode 100644 index 0000000000..9cb1a271c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Verify conversion after defining value +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + + ... + 3. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testTypedArray.js] +features: [TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + Object.defineProperty(sample, "0", {value: value}); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.js new file mode 100644 index 0000000000..987400e098 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Return abrupt from the evaluation of ToNumber(desc.value) +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.throws(Test262Error, function() { + Object.defineProperty(sample, "0", {value: obj}); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.js new file mode 100644 index 0000000000..e0bc4aa960 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid descriptor & canonical numeric string if buffer is detached. + (honoring the Realm of the current execution context) +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA([0]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js new file mode 100644 index 0000000000..0508818e9d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js @@ -0,0 +1,50 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid descriptor & canonical numeric string if buffer is detached. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js new file mode 100644 index 0000000000..5bca5e6893 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js @@ -0,0 +1,143 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if this has valid numeric index and a detached buffer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +var desc = { + value: 0, + configurable: false, + enumerable: true, + writable: true +}; + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.defineProperty(sample, "0", desc), + false, + 'Reflect.defineProperty(sample, "0", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", desc), + false, + 'Reflect.defineProperty(sample, "-1", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", desc), + false, + 'Reflect.defineProperty(sample, "1.1", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", desc), + false, + 'Reflect.defineProperty(sample, "-0", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + configurable: true, + enumerable: true, + writable: true, + value: obj + }), + false, + 'Reflect.defineProperty(sample, "2", {configurable: true, enumerable: true, writable: true, value: obj}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + configurable: false, + enumerable: false, + writable: true, + value: obj + }), + false, + 'Reflect.defineProperty(sample, "3", {configurable: false, enumerable: false, writable: true, value: obj}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "4", { + writable: false, + configurable: false, + enumerable: true, + value: obj + }), + false, + 'Reflect.defineProperty("new TA(42)", "4", {writable: false, configurable: false, enumerable: true, value: obj}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "42", desc), + false, + 'Reflect.defineProperty(sample, "42", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "43", desc), + false, + 'Reflect.defineProperty(sample, "43", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "5", { + get: function() {} + }), + false, + 'Reflect.defineProperty(sample, "5", {get: function() {}}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "6", { + configurable: false, + enumerable: true, + writable: true + }), + false, + 'Reflect.defineProperty(sample, "6", {configurable: false, enumerable: true, writable: true}) must return false' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..ad49623d94 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is >= [[ArrayLength]] +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + ... + v. Let length be the value of O's [[ArrayLength]] internal slot. + vi. If intIndex ≥ length, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex == length" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex > length" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-zero.js new file mode 100644 index 0000000000..bafcc4e84f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-zero.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is < 0 +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + iv. If intIndex < 0, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-1" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.js new file mode 100644 index 0000000000..970eb231eb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is "-0" +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ii. Let intIndex be numericIndex. + iii. If intIndex = -0, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "defineProperty returns false" + ); + assert.sameValue(sample[0], 0, "does not change the value for [0]"); + assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js new file mode 100644 index 0000000000..c667f7ac46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js @@ -0,0 +1,100 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Sets an ordinary property value if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testTypedArray.js, propertyHelper.js] +features: [Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +var dataDesc = { + value: 42, + writable: true, + configurable: true +}; + +var fnset = function() {}; +var fnget = function() {}; + +var acDesc = { + get: fnget, + set: fnset, + enumerable: true, + configurable: false +}; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample1 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample1, key, dataDesc), + true, + "return true after defining data property [" + key + "]" + ); + + assert.sameValue(sample1[key], 42, "value is set to [" + key + "]"); + verifyNotEnumerable(sample1, key); + verifyWritable(sample1, key); + verifyConfigurable(sample1, key); + + assert.sameValue(sample1[0], undefined, "no value is set on sample1[0]"); + assert.sameValue(sample1.length, 0, "length is still 0"); + + var sample2 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample2, key, acDesc), + true, + "return true after defining accessors property [" + key + "]" + ); + + var desc = Object.getOwnPropertyDescriptor(sample2, key); + verifyEnumerable(sample2, key); + assert.sameValue(desc.get, fnget, "accessor's get [" + key + "]"); + assert.sameValue(desc.set, fnset, "accessor's set [" + key + "]"); + verifyNotConfigurable(sample2, key); + + assert.sameValue(sample2[0], undefined,"no value is set on sample2[0]"); + assert.sameValue(sample2.length, 0, "length is still 0"); + + var sample3 = new TA(); + Object.preventExtensions(sample3); + + assert.sameValue( + Reflect.defineProperty(sample3, key, dataDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample3, key), undefined); + + var sample4 = new TA(); + Object.preventExtensions(sample4); + + assert.sameValue( + Reflect.defineProperty(sample4, key, acDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample4, key), undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js new file mode 100644 index 0000000000..7b1c6c9206 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js @@ -0,0 +1,126 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is not an integer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0.1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.1" + ); + assert.sameValue(sample[0], 0, "'0.1' - does not change the value for [0]"); + assert.sameValue( + sample["0.1"], + undefined, + "'0.1' - does not define a value for ['0.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "0.000001", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.000001" + ); + assert.sameValue( + sample[0], 0, + "'0.000001' - does not change the value for [0]" + ); + assert.sameValue( + sample["0.000001"], + undefined, + "'0.000001' - does not define a value for ['0.000001']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "1.1" + ); + assert.sameValue(sample[1], 0, "'1.1' - does not change the value for [1]"); + assert.sameValue( + sample["1.1"], + undefined, + "'1.1' - does not define a value for ['1.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "Infinity", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "Infinity" + ); + assert.sameValue( + sample[0], 0, + "'Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0, + "'Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["Infinity"], + undefined, + "'Infinity' - does not define a value for ['Infinity']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-Infinity", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-Infinity" + ); + assert.sameValue( + sample[0], 0, + "'-Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0, + "'-Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["-Infinity"], + undefined, + "'-Infinity' - does not define a value for ['-Infinity']" + ); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js new file mode 100644 index 0000000000..5dbb162ef3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid descriptor & canonical numeric string that is invalid index. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 3. If ! IsIntegralNumber(index) is false, return false. + 4. If index is -0𝔽, return false. + 5. If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return false. +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.js new file mode 100644 index 0000000000..33b460ede6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testTypedArray.js, propertyHelper.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "return true after defining property" + ); + + assert.sameValue(sample.foo, 42); + verifyNotWritable(sample, "foo"); + verifyNotConfigurable(sample, "foo"); + verifyNotEnumerable(sample, "foo"); + + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyConfigurable(sample, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js new file mode 100644 index 0000000000..c794dd233d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & accessor descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iv. If IsAccessorDescriptor(Desc) is true, return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42; }, + }); + }, "get accessor"); + assert.sameValue(sample[0], 0, "get accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + set: function(_v) {}, + }); + }, "set accessor"); + assert.sameValue(sample[0], 0, "set accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42; }, + set: function(_v) {}, + }); + }, "get and set accessors"); + assert.sameValue(sample[0], 0, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js new file mode 100644 index 0000000000..b382b1fcea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Descriptor is an + AccessorDescriptor +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + vii. If IsAccessorDescriptor(Desc) is true, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get accessor" + ); + assert.sameValue(sample[0], 0, "get accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + enumerable: true + }), + false, + "set accessor" + ); + assert.sameValue(sample[0], 0, "set accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get and set accessors" + ); + assert.sameValue(sample[0], 0, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js new file mode 100644 index 0000000000..3e6defb841 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns true if key is a numeric index and Desc.[[Configurable]] is true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: true, + enumerable: true, + writable: true + }), + true, + "defineProperty's result" + ); + assert.sameValue(sample[0], 42, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js new file mode 100644 index 0000000000..12c0ea92de --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & non-configurable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + ii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false. +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + configurable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42, + writable: true, + enumerable: true, + configurable: false, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js new file mode 100644 index 0000000000..3e09508c43 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & non-enumerable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + enumerable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42, + writable: true, + enumerable: false, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js new file mode 100644 index 0000000000..1c8ab48205 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Enumerable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ix. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is + false, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: false, + enumerable: false, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js new file mode 100644 index 0000000000..99c5579ee8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws TypeError for valid index & non-writable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + v. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + writable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42, + writable: false, + enumerable: true, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js new file mode 100644 index 0000000000..25d78bf869 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Writable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, + return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: false, + enumerable: true, + writable: false + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.js new file mode 100644 index 0000000000..0b45de3189 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns true after setting a valid numeric index key +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + If IsAccessorDescriptor(Desc) is true, return false. + If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false. + If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. + If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false. + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 42]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 8, + configurable: true, + enumerable: true, + writable: true + }), + true + ); + + assert.sameValue(sample[0], 8, "property value was set"); + let descriptor0 = Object.getOwnPropertyDescriptor(sample, "0"); + assert.sameValue(descriptor0.value, 8); + assert.sameValue(descriptor0.configurable, true); + assert.sameValue(descriptor0.enumerable, true); + assert.sameValue(descriptor0.writable, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.js new file mode 100644 index 0000000000..867f69e9d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Define an ordinary property value if key is a Symbol +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testTypedArray.js, propertyHelper.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + var s1 = Symbol("foo"); + assert.sameValue( + Reflect.defineProperty(sample, s1, { + value: 42, + configurable: true + }), + true, + "return true after defining property" + ); + + assert.sameValue(sample[s1], 42); + verifyNotWritable(sample, s1); + verifyNotEnumerable(sample, s1); + verifyConfigurable(sample, s1); + + var s2 = Symbol("bar"); + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, s2, { + get: fnget, + set: fnset, + enumerable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, s2); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + assert.sameValue(desc.enumerable, true); + verifyNotConfigurable(sample, s2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.js new file mode 100644 index 0000000000..51a824d248 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Can't define a new non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + false, + "return false on a non-extensible object - data descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "foo"), undefined); + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: function() {}, + set: function() {}, + enumerable: false, + configurable: true + }), + false, + "return false on a non-extensible object - accessor descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "bar"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.js new file mode 100644 index 0000000000..00e67d6fd6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Redefine a non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testTypedArray.js, propertyHelper.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + sample.foo = true; + sample.bar = true; + + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "data descriptor" + ); + + assert.sameValue(sample.foo, 42); + verifyEnumerable(sample, "foo"); + verifyWritable(sample, "foo"); + verifyConfigurable(sample, "foo"); + + var fnget = function() {}; + var fnset = function() {}; + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: false + }), + true, + "accessor descriptor" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyNotConfigurable(sample, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.js new file mode 100644 index 0000000000..2b81f9777f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Set the value and return true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 0]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", {value: 1}), + true, + "set value for sample[0] returns true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1", {value: 2}), + true, + "set value for sample[1] returns true" + ); + + assert.sameValue(sample[0], 1, "sample[0]"); + assert.sameValue(sample[1], 2, "sample[1]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js new file mode 100644 index 0000000000..c32f046213 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js @@ -0,0 +1,694 @@ +// GENERATED, DO NOT EDIT +// file: byteConversionValues.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float16: [ + 127, // 127 + 128, // 128 + 32768, // 32767 + 32768, // 32768 + Infinity, // 2147483647 + Infinity, // 2147483648 + 255, // 255 + 256, // 256 + Infinity, // 65535 + Infinity, // 65536 + Infinity, // 4294967295 + Infinity, // 4294967296 + Infinity, // 9007199254740991 + Infinity, // 9007199254740992 + 1.099609375, // 1.1 + 0.0999755859375, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.60009765625, // 0.6 + 0.7001953125, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.0999755859375, // -0.1 + -1.099609375, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32768, // -32767 + -32768, // -32768 + -Infinity, // -2147483647 + -Infinity, // -2147483648 + -255, // -255 + -256, // -256 + -Infinity, // -65535 + -Infinity, // -65536 + -Infinity, // -4294967295 + -Infinity, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; + +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.js new file mode 100644 index 0000000000..466959ed64 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false for non-numeric index property value if `this` is not extensible +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testTypedArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + Object.preventExtensions(sample); + + assert.sameValue(Reflect.defineProperty(sample, "foo", {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, "foo"), undefined); + + var s = Symbol("1"); + assert.sameValue(Reflect.defineProperty(sample, s, {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, s), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..62b51f8945 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js @@ -0,0 +1,64 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Defining a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, should + return true and not modify the typed array. +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta = new TA([17]); + + var desc = + { + value: { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42; + } + } + }; + + assert.sameValue( + Reflect.defineProperty(ta, 0, desc), + true, + 'Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42;}}} ) must return true' + ); + assert.sameValue(ta[0], undefined, 'The value of ta[0] is expected to equal `undefined`'); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..c39af7873f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... + Return ? OrdinaryDelete(O, P) +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + sample.string = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.string, true, 'The value of `delete sample.string` is true'); + assert.sameValue(delete sample.undef, true, 'The value of `delete sample.undef` is true'); + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..ed0dddfd7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Calls OrdinaryDelete when key is a Symbol. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + let s = Symbol("1"); + + sample[s] = 1; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..05cc9e7246 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached + (honoring the Realm of the current execution context) +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js new file mode 100644 index 0000000000..2879b0cc8f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); + assert.sameValue(delete sample["1.1"], true, 'The value of `delete sample["1.1"]` is true'); + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample["2"], true, 'The value of `delete sample["2"]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js new file mode 100644 index 0000000000..f42faf11d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample[1]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js new file mode 100644 index 0000000000..b54d66cca8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js @@ -0,0 +1,55 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample["1"]; + }, '`delete sample["1"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js new file mode 100644 index 0000000000..0f63640193 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index, with SharedArrayBuffer +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample["1"]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js new file mode 100644 index 0000000000..6677f96548 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Throws TypeError exception in strict mode. +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.throws(TypeError, () => { + delete sample["0"]; + }); + assert.throws(TypeError, () => { + delete sample[0]; + }); + assert.throws(TypeError, () => { + delete sample["1"]; + }); + assert.throws(TypeError, () => { + delete sample[1]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js new file mode 100644 index 0000000000..0600fa230f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string. Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] ( P, Receiver ) + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + CanonicalNumericIndexString ( argument ) + ... + Let n be ! ToNumber(argument). + If SameValue(! ToString(n), argument) is false, return undefined. + Return n. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.Infinity, true, 'The value of `delete sample.Infinity` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js new file mode 100644 index 0000000000..dbe5370153 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.sameValue( + delete sample[key], false, + 'The value of `delete sample[key]` is false' + ); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js new file mode 100644 index 0000000000..4435c4ac17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js @@ -0,0 +1,69 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.throws(TypeError, () => { + delete sample[key]; + }, '`delete sample[key]` throws TypeError'); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js new file mode 100644 index 0000000000..319764e862 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample[-0], false, 'The value of `delete sample[-0]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js new file mode 100644 index 0000000000..c0e42e745e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js @@ -0,0 +1,49 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.throws(TypeError, () => { + delete sample[-0]; + }, '`delete sample[-0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..2cd35158c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + + Object.defineProperty(sample, "foo", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, () => { + sample.foo; + }, '`sample.foo` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js new file mode 100644 index 0000000000..29c468caa7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.sameValue(delete sample.bar, false, 'The value of `delete sample.bar` is false'); + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js new file mode 100644 index 0000000000..2a9f7171e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js @@ -0,0 +1,50 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.throws(TypeError, () => { + delete sample.bar; + }, '`delete sample.bar` throws TypeError'); + + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js new file mode 100644 index 0000000000..ee352b1a40 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js new file mode 100644 index 0000000000..8d67ba003f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js @@ -0,0 +1,57 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..9d642c8c6b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is a Symbol +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + let s = Symbol("1"); + + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); + + sample[s] = ""; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..f204b58813 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,36 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... + Return ? OrdinaryDelete(O, P) +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + let key = "key"; + sample.string = key; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.string, true, 'The value of `delete sample.string` is true'); + assert.sameValue(delete sample.undef, true, 'The value of `delete sample.undef` is true'); + assert.sameValue(delete sample[key], true, 'The value of `delete sample.string` is true'); + assert.sameValue(delete sample["undef"], true, 'The value of `delete sample.undef` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..ed0dddfd7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Calls OrdinaryDelete when key is a Symbol. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + let s = Symbol("1"); + + sample[s] = 1; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js new file mode 100644 index 0000000000..05cc9e7246 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached + (honoring the Realm of the current execution context) +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js new file mode 100644 index 0000000000..d55e8b15ee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); + assert.sameValue(delete sample["1.1"], true, 'The value of `delete sample["1.1"]` is true'); + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample["2"], true, 'The value of `delete sample["2"]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js new file mode 100644 index 0000000000..ac273ff0a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample[1]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js new file mode 100644 index 0000000000..5ac3219bba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js @@ -0,0 +1,55 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample["1"]; + }, '`delete sample["1"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js new file mode 100644 index 0000000000..0f63640193 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index, with SharedArrayBuffer +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample["1"]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js new file mode 100644 index 0000000000..6677f96548 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Throws TypeError exception in strict mode. +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.throws(TypeError, () => { + delete sample["0"]; + }); + assert.throws(TypeError, () => { + delete sample[0]; + }); + assert.throws(TypeError, () => { + delete sample["1"]; + }); + assert.throws(TypeError, () => { + delete sample[1]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js new file mode 100644 index 0000000000..735673dcc1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string. Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] ( P, Receiver ) + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + CanonicalNumericIndexString ( argument ) + ... + Let n be ! ToNumber(argument). + If SameValue(! ToString(n), argument) is false, return undefined. + Return n. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.Infinity, true, 'The value of `delete sample.Infinity` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js new file mode 100644 index 0000000000..9cd26b2c46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.sameValue( + delete sample[key], false, + 'The value of `delete sample[key]` is false' + ); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js new file mode 100644 index 0000000000..acd52c7cce --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js @@ -0,0 +1,69 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.throws(TypeError, () => { + delete sample[key]; + }, '`delete sample[key]` throws TypeError'); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js new file mode 100644 index 0000000000..d8862bd99b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "1.1", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["1.1"], true, 'The value of `delete sample["1.1"]` is true'); + assert.sameValue(delete sample[1.1], true, 'The value of `delete sample[1.1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js new file mode 100644 index 0000000000..8a60a14c4c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample[-0], false, 'The value of `delete sample[-0]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js new file mode 100644 index 0000000000..33bae05317 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js @@ -0,0 +1,49 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.throws(TypeError, () => { + delete sample[-0]; + }, '`delete sample[-0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..5035a5d733 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + + Object.defineProperty(sample, "foo", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, () => { + sample.foo; + }, '`sample.foo` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js new file mode 100644 index 0000000000..2b9d9a378e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.sameValue(delete sample.bar, false, 'The value of `delete sample.bar` is false'); + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js new file mode 100644 index 0000000000..af6397a576 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js @@ -0,0 +1,50 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.throws(TypeError, () => { + delete sample.bar; + }, '`delete sample.bar` throws TypeError'); + + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js new file mode 100644 index 0000000000..63130f39a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js new file mode 100644 index 0000000000..c668f681c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js @@ -0,0 +1,57 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js new file mode 100644 index 0000000000..6e25155282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is a Symbol +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + let s = Symbol("1"); + + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); + + sample[s] = ""; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js new file mode 100644 index 0000000000..7b3c9f20d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js @@ -0,0 +1,179 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..e8296d36f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + sample.foo = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.undef, undefined); + assert.sameValue(sample.foo, "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..a0316ccb2f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("1"); + + assert.sameValue(sample[s], undefined); + + sample[s] = "test262"; + assert.sameValue(sample[s], "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..f979db1546 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns undefined if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.js new file mode 100644 index 0000000000..b7ee084085 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns undefined if key has a numeric index and object has a detached buffer +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); + assert.sameValue(sample["1.1"], undefined, 'The value of sample["1.1"] is expected to equal `undefined`'); + assert.sameValue(sample["-0"], undefined, 'The value of sample["-0"] is expected to equal `undefined`'); + assert.sameValue(sample["-1"], undefined, 'The value of sample["-1"] is expected to equal `undefined`'); + assert.sameValue(sample["1"], undefined, 'The value of sample["1"] is expected to equal `undefined`'); + assert.sameValue(sample["2"], undefined, 'The value of sample["2"] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js new file mode 100644 index 0000000000..c3eac9165f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js @@ -0,0 +1,31 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index, with SharedArrayBuffer +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray, SharedArrayBuffer] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + var sample = new TA(sab); + sample.set([42n, 1n]); + + assert.sameValue(sample["0"], 42n); + assert.sameValue(sample["1"], 1n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.js new file mode 100644 index 0000000000..4c54b6f3d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 1n]); + + assert.sameValue(sample["0"], 42n); + assert.sameValue(sample["1"], 1n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/infinity-detached-buffer.js new file mode 100644 index 0000000000..b1c9e74b09 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/infinity-detached-buffer.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.4 [[Get]] ( P, Receiver ) + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.Infinity, undefined, 'The value of sample.Infinity is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..115b604b18 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrdinaryGet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(); + + assert.sameValue( + sample[key], undefined, + "return undefined for inexistent properties [" + key + "]" + ); + + TypedArray.prototype[key] = "test262"; + + assert.sameValue( + sample[key], + "test262", + "return value from inherited key [" + key + "]" + ); + + sample[key] = "bar"; + assert.sameValue( + sample[key], "bar", + "return value from own key [" + key + "]" + ); + + Object.defineProperty(sample, key, { + get: function() { return "baz"; } + }); + + assert.sameValue( + sample[key], "baz", + "return value from get accessor [" + key + "]" + ); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..251231fc65 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is not an integer. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "1.1", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(sample["1.1"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.js new file mode 100644 index 0000000000..99d6d4f7af --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is -0. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "-0", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(sample["-0"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..9073ee159a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns abrupt from OrdinaryGet when key is not a numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). + + 9.1.8.1 OrdinaryGet (O, P, Receiver) + + ... + 8. Return ? Call(getter, Receiver). + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..7d4e873e52 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrdinaryGet if key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +TypedArray.prototype.baz = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + sample.foo, undefined, + "return undefined for inexistent properties" + ); + + sample.foo = "bar"; + assert.sameValue(sample.foo, "bar", "return value"); + + Object.defineProperty(sample, "bar", { + get: function() { return "baz"; } + }); + assert.sameValue(sample.bar, "baz", "return value from get accessor"); + + assert.sameValue(sample.baz, "test262", "return value from inherited key"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..30ccf64286 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index < 0 or index ≥ [[ArrayLength]]. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "-1", throwDesc); +Object.defineProperty(proto, "2", throwDesc); +Object.defineProperty(proto, "3", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(sample["-1"], undefined); + assert.sameValue(sample["2"], undefined); + assert.sameValue(sample["3"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..0ef9bee129 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrdinaryGet if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, TypedArray] +---*/ + +var parentKey = Symbol("2"); +TypedArray.prototype[parentKey] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + var s1 = Symbol("1"); + + assert.sameValue( + sample[s1], undefined, + "return undefined if not property is present" + ); + + sample[s1] = "foo"; + assert.sameValue(sample[s1], "foo", "return value"); + + Object.defineProperty(sample, s1, { + get: function() { return "bar"; } + }); + assert.sameValue(sample[s1], "bar", "return value from get accessor"); + + assert.sameValue(sample[parentKey], "test262", "value from parent key"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..85a5dd2845 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + sample.foo = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.undef, undefined); + assert.sameValue(sample.foo, "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..5d7d4fcb48 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("1"); + + assert.sameValue(sample[s], undefined); + + sample[s] = "test262"; + assert.sameValue(sample[s], "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.js new file mode 100644 index 0000000000..5c54ccfa2f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns undefined if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.js new file mode 100644 index 0000000000..ca6783aa51 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns undefined if key has a numeric index and object has a detached buffer +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); + assert.sameValue(sample["1.1"], undefined, 'The value of sample["1.1"] is expected to equal `undefined`'); + assert.sameValue(sample["-0"], undefined, 'The value of sample["-0"] is expected to equal `undefined`'); + assert.sameValue(sample["-1"], undefined, 'The value of sample["-1"] is expected to equal `undefined`'); + assert.sameValue(sample["1"], undefined, 'The value of sample["1"] is expected to equal `undefined`'); + assert.sameValue(sample["2"], undefined, 'The value of sample["2"] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js new file mode 100644 index 0000000000..508254c872 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js @@ -0,0 +1,31 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index, with SharedArrayBuffer +includes: [testTypedArray.js] +features: [TypedArray, SharedArrayBuffer] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + var sample = new TA(sab); + sample.set([42, 1]); + + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.js new file mode 100644 index 0000000000..f99235ad50 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 1]); + + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js new file mode 100644 index 0000000000..64cf13940d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.4 [[Get]] ( P, Receiver ) + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.Infinity, undefined, 'The value of sample.Infinity is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.js new file mode 100644 index 0000000000..985516626b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrdinaryGet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(); + + assert.sameValue( + sample[key], undefined, + "return undefined for inexistent properties [" + key + "]" + ); + + TypedArray.prototype[key] = "test262"; + + assert.sameValue( + sample[key], + "test262", + "return value from inherited key [" + key + "]" + ); + + sample[key] = "bar"; + assert.sameValue( + sample[key], "bar", + "return value from own key [" + key + "]" + ); + + Object.defineProperty(sample, key, { + get: function() { return "baz"; } + }); + + assert.sameValue( + sample[key], "baz", + "return value from get accessor [" + key + "]" + ); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.js new file mode 100644 index 0000000000..3059457150 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is not an integer. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "1.1", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(sample["1.1"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.js new file mode 100644 index 0000000000..2810260d97 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is -0. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "-0", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(sample["-0"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..12ad42d27c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns abrupt from OrdinaryGet when key is not a numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). + + 9.1.8.1 OrdinaryGet (O, P, Receiver) + + ... + 8. Return ? Call(getter, Receiver). + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.js new file mode 100644 index 0000000000..928add152b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrdinaryGet if key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +TypedArray.prototype.baz = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue( + sample.foo, undefined, + "return undefined for inexistent properties" + ); + + sample.foo = "bar"; + assert.sameValue(sample.foo, "bar", "return value"); + + Object.defineProperty(sample, "bar", { + get: function() { return "baz"; } + }); + assert.sameValue(sample.bar, "baz", "return value from get accessor"); + + assert.sameValue(sample.baz, "test262", "return value from inherited key"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.js new file mode 100644 index 0000000000..b8534bf612 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index < 0 or index ≥ [[ArrayLength]]. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "-1", throwDesc); +Object.defineProperty(proto, "2", throwDesc); +Object.defineProperty(proto, "3", throwDesc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(sample["-1"], undefined); + assert.sameValue(sample["2"], undefined); + assert.sameValue(sample["3"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.js new file mode 100644 index 0000000000..c0dcf29c51 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrdinaryGet if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +var parentKey = Symbol("2"); +TypedArray.prototype[parentKey] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + var s1 = Symbol("1"); + + assert.sameValue( + sample[s1], undefined, + "return undefined if not property is present" + ); + + sample[s1] = "foo"; + assert.sameValue(sample[s1], "foo", "return value"); + + Object.defineProperty(sample, s1, { + get: function() { return "bar"; } + }); + assert.sameValue(sample[s1], "bar", "return value from get accessor"); + + assert.sameValue(sample[parentKey], "test262", "value from parent key"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js new file mode 100644 index 0000000000..7b3c9f20d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js @@ -0,0 +1,179 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..fa599e0e98 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..51c9edc2d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..bb170e21ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returned undefined if this has a detached buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ! IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor("new OtherTA(1)", 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 0000000000..89c1fbecbd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined if this has a detached buffer +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ! IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor(sample, 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js new file mode 100644 index 0000000000..caaf1aeeee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Test for-in enumeration with detached buffer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ! IntegerIndexedElementGet(O, numericIndex). + ... + + IntegerIndexedElementGet ( O, index ) + ... + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... + + 13.7.5.15 EnumerateObjectProperties (O) + ... + EnumerateObjectProperties must obtain the own property keys of the + target object by calling its [[OwnPropertyKeys]] internal method. + Property attributes of the target object must be obtained by + calling its [[GetOwnProperty]] internal method. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + let counter = 0; + for (var key in sample) { + counter++; + } + assert.sameValue(counter, 0, 'The value of `counter` is 0'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.js new file mode 100644 index 0000000000..1b5eaf1399 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns a descriptor object from an index property +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. Return a PropertyDescriptor{[[Value]]: value, [[Writable]]: true, + [[Enumerable]]: true, [[Configurable]]: true}. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + let descriptor0 = Object.getOwnPropertyDescriptor(sample, "0"); + let descriptor1 = Object.getOwnPropertyDescriptor(sample, "1"); + + assert.sameValue(descriptor0.value, 42n); + assert.sameValue(descriptor0.configurable, true); + assert.sameValue(descriptor0.enumerable, true); + assert.sameValue(descriptor0.writable, true); + + assert.sameValue(descriptor1.value, 43n); + assert.sameValue(descriptor1.configurable, true); + assert.sameValue(descriptor1.enumerable, true); + assert.sameValue(descriptor1.writable, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..473501b28e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is -0. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + + ... + 2. If argument is "-0", return -0. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + // -0 as a number value is converted to "0" before calling [[GetOwnProperty]] + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..1c613c4538 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if numeric key is not a + CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key), + undefined, + "undefined property [" + key + "]" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, key, {value: "bar"}); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key).value, + "bar", + "return value from a ordinary property key [" + key + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..bfccde6239 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not an integer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..db2cef9856 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..de31a8d0bc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not a valid index number. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-42"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "42"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..d6570d764a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..59696d38ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..38d405b94b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.js new file mode 100644 index 0000000000..dfb0d554f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returned undefined if this has a detached buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ! IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor(sample, 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.js new file mode 100644 index 0000000000..c1a7151ae0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined if this has a detached buffer +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ! IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor(sample, 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js new file mode 100644 index 0000000000..8611cfb434 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Test for-in enumeration with detached buffer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ! IntegerIndexedElementGet(O, numericIndex). + ... + + IntegerIndexedElementGet ( O, index ) + ... + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... + + 13.7.5.15 EnumerateObjectProperties (O) + ... + EnumerateObjectProperties must obtain the own property keys of the + target object by calling its [[OwnPropertyKeys]] internal method. + Property attributes of the target object must be obtained by + calling its [[GetOwnProperty]] internal method. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + let count = 0; + for (var key in sample) { + count++; + } + assert.sameValue(count, 0, 'The value of `count` is 0'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js new file mode 100644 index 0000000000..4238cd9e66 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns a descriptor object from an index property +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. Return a PropertyDescriptor{[[Value]]: value, [[Writable]]: true, + [[Enumerable]]: true, [[Configurable]]: true}. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + let descriptor0 = Object.getOwnPropertyDescriptor(sample, "0"); + let descriptor1 = Object.getOwnPropertyDescriptor(sample, "1"); + + assert.sameValue(descriptor0.value, 42); + assert.sameValue(descriptor0.configurable, true); + assert.sameValue(descriptor0.enumerable, true); + assert.sameValue(descriptor0.writable, true); + + assert.sameValue(descriptor1.value, 43); + assert.sameValue(descriptor1.configurable, true); + assert.sameValue(descriptor1.enumerable, true); + assert.sameValue(descriptor1.writable, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.js new file mode 100644 index 0000000000..752f3f6204 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is -0. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + + ... + 2. If argument is "-0", return -0. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + // -0 as a number value is converted to "0" before calling [[GetOwnProperty]] + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.js new file mode 100644 index 0000000000..c9fa3e8b54 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if numeric key is not a + CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42, 43]); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key), + undefined, + "undefined property [" + key + "]" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, key, {value: "bar"}); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key).value, + "bar", + "return value from a ordinary property key [" + key + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.js new file mode 100644 index 0000000000..297e1b14a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not an integer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.js new file mode 100644 index 0000000000..0f78950189 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.js new file mode 100644 index 0000000000..c4cda461fb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not a valid index number. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-42"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "42"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-symbol.js new file mode 100644 index 0000000000..d686d07edb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js new file mode 100644 index 0000000000..7b3c9f20d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js @@ -0,0 +1,179 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 0000000000..fcec3e4db7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return abrupt from OrdinaryHasProperty parent's [[HasProperty]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... + + 9.1.7.1 OrdinaryHasProperty (O, P) + + ... + 2. Let hasOwn be ? O.[[GetOwnProperty]](P). + 3. If hasOwn is not undefined, return true. + 4. Let parent be ? O.[[GetPrototypeOf]](). + 5. If parent is not null, then + a. Return ? parent.[[HasProperty]](P). + 6. Return false. +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, Proxy, TypedArray] +---*/ + +var handler = { + has: function() { + throw new Test262Error(); + } +}; + +var proxy = new Proxy(TypedArray.prototype, handler); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.setPrototypeOf(sample, proxy); + + assert.sameValue( + Reflect.has(sample, 0), true, + 'Reflect.has(sample, 0) must return true' + ); + assert.sameValue( + Reflect.has(sample, 1), false, + 'Reflect.has(sample, 1) must return false' + ); + + assert.throws(Test262Error, function() { + Reflect.has(sample, "foo"); + }, '`Reflect.has(sample, "foo")` throws Test262Error'); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue( + Reflect.has(sample, "foo"), + true, + 'Reflect.has(sample, "foo") must return true' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..011a63acd1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a + CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + Object.defineProperty(sample, "bar", { value: 42 }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "foo"), false); + assert.sameValue(Reflect.has(sample, "bar"), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..e24e8e58ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("foo"); +var s2 = Symbol("bar"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + Object.defineProperty(sample, s1, { value: "baz" }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, s1), true); + assert.sameValue(Reflect.has(sample, s2), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..298c79428b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-realm.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Returns false if this has a detached buffer (honoring the Realm of the + current execution context) +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, '0'), false, 'Reflect.has(sample, "0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.js new file mode 100644 index 0000000000..7e58bd2473 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Returns false if this has a detached buffer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "0"), false, 'Reflect.has(sample, "0") must return false'); + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); + assert.sameValue(Reflect.has(sample, "1.1"), false, 'Reflect.has(sample, "1.1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.js new file mode 100644 index 0000000000..6773bd1487 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return true for indexed properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + iv. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + assert.sameValue(Reflect.has(sample, 0), true, 'Reflect.has(sample, 0) must return true'); + assert.sameValue(Reflect.has(sample, 1), true, 'Reflect.has(sample, 1) must return true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js new file mode 100644 index 0000000000..80a9f396cf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js @@ -0,0 +1,48 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.2 [[HasProperty]]( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + +flags: [noStrict] +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + + let n = { + valueOf() { + counter++; + return 9n; + } + }; + + assert.sameValue(counter, 0, 'The value of `counter` is 0'); + let ta = new TA([n]); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + $DETACHBUFFER(ta.buffer); + + with (ta) { + Infinity; + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.js new file mode 100644 index 0000000000..d2ec511afd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Find inherited properties if property is not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +TypedArray.prototype.foo = 42; +TypedArray.prototype[42] = true; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + TA.prototype.bar = 42; + + assert.sameValue(Reflect.has(sample, "subarray"), true, "subarray"); + assert.sameValue(Reflect.has(sample, "foo"), true, "foo"); + assert.sameValue(Reflect.has(sample, "bar"), true, "bar"); + assert.sameValue(Reflect.has(sample, "baz"), false, "baz"); + + assert.sameValue(Reflect.has(sample, "42"), false, "42"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..3c51c7f6df --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-index.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is >= this's [[ArrayLength]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[1] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1"), false, 'Reflect.has(sample, "1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 0000000000..e445238631 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-zero.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is < 0 +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[-1] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-1"), false, 'Reflect.has(sample, "-1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..f8e938299b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-minus-zero.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is "-0" +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["-0"] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..828aa9b570 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from numeric keys that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(1); + + assert.sameValue( + Reflect.has(sample, key), false, + "returns false without key [" + key + "]" + ); + + TypedArray.prototype[key] = 42; + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with inherited key [" + key + "]" + ); + + delete TypedArray.prototype[key]; + + Object.defineProperty(sample, key, {value: 42n}); + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with own key [" + key + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..196ad49ef3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is not an integer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If IsInteger(numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["1.1"] = "test262"; +TypedArray.prototype["0.000001"] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1.1"), false, "1.1"); + assert.sameValue(Reflect.has(sample, "0.000001"), false, "0.000001"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..e29503e510 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from properties that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "foo"), false); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue(Reflect.has(sample, "foo"), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..d86caa85b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from Symbol properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("foo"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, s), false); + + Object.defineProperty(sample, s, { value: 42 }); + + assert.sameValue(Reflect.has(sample, s), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 0000000000..3513862b71 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return abrupt from OrdinaryHasProperty parent's [[HasProperty]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... + + 9.1.7.1 OrdinaryHasProperty (O, P) + + ... + 2. Let hasOwn be ? O.[[GetOwnProperty]](P). + 3. If hasOwn is not undefined, return true. + 4. Let parent be ? O.[[GetPrototypeOf]](). + 5. If parent is not null, then + a. Return ? parent.[[HasProperty]](P). + 6. Return false. +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, Proxy, TypedArray] +---*/ + +var handler = { + has: function() { + throw new Test262Error(); + } +}; + +var proxy = new Proxy(TypedArray.prototype, handler); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.setPrototypeOf(sample, proxy); + + assert.sameValue( + Reflect.has(sample, 0), true, + 'Reflect.has(sample, 0) must return true' + ); + assert.sameValue( + Reflect.has(sample, 1), false, + 'Reflect.has(sample, 1) must return false' + ); + + assert.throws(Test262Error, function() { + Reflect.has(sample, "foo"); + }, '`Reflect.has(sample, "foo")` throws Test262Error'); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue( + Reflect.has(sample, "foo"), + true, + 'Reflect.has(sample, "foo") must return true' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..3a8d2511e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a + CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + Object.defineProperty(sample, "bar", { value: 42 }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "foo"), false); + assert.sameValue(Reflect.has(sample, "bar"), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..80810d3d8c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("foo"); +var s2 = Symbol("bar"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + Object.defineProperty(sample, s1, { value: "baz" }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, s1), true); + assert.sameValue(Reflect.has(sample, s2), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js new file mode 100644 index 0000000000..d9be7d2e18 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Returns false if this has a detached buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, '0'), false, 'Reflect.has(sample, "0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.js new file mode 100644 index 0000000000..80f3d2aaf3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if this has a detached buffer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "0"), false, 'Reflect.has(sample, "0") must return false'); + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); + assert.sameValue(Reflect.has(sample, "1.1"), false, 'Reflect.has(sample, "1.1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.js new file mode 100644 index 0000000000..3cb63c33ba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return true for indexed properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + iv. Return true. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(Reflect.has(sample, 0), true, 'Reflect.has("new TA([42, 43])", 0) must return true'); + assert.sameValue(Reflect.has(sample, 1), true, 'Reflect.has("new TA([42, 43])", 1) must return true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js new file mode 100644 index 0000000000..b71d009764 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js @@ -0,0 +1,52 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.2 [[HasProperty]]( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + +flags: [noStrict] +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let n = { + valueOf() { + counter++; + return 9; + } + }; + + assert.sameValue(counter, 0, 'The value of `counter` is 0'); + + let ta = new TA([n]); + + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + $DETACHBUFFER(ta.buffer); + + with (ta) { + Infinity; + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.js new file mode 100644 index 0000000000..eb736978dc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Find inherited properties if property is not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +TypedArray.prototype.foo = 42; +TypedArray.prototype[42] = true; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + TA.prototype.bar = 42; + + assert.sameValue(Reflect.has(sample, "subarray"), true, "subarray"); + assert.sameValue(Reflect.has(sample, "foo"), true, "foo"); + assert.sameValue(Reflect.has(sample, "bar"), true, "bar"); + assert.sameValue(Reflect.has(sample, "baz"), false, "baz"); + + assert.sameValue(Reflect.has(sample, "42"), false, "42"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..1c930e4005 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-index.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is >= this's [[ArrayLength]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[1] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1"), false, 'Reflect.has(sample, "1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-zero.js new file mode 100644 index 0000000000..3cbe081f30 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-zero.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is < 0 +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[-1] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-1"), false, 'Reflect.has(sample, "-1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-minus-zero.js new file mode 100644 index 0000000000..870cc9a039 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-minus-zero.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is "-0" +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["-0"] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.js new file mode 100644 index 0000000000..4207b866e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from numeric keys that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(1); + + assert.sameValue( + Reflect.has(sample, key), false, + "returns false without key [" + key + "]" + ); + + TypedArray.prototype[key] = 42; + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with inherited key [" + key + "]" + ); + + delete TypedArray.prototype[key]; + + Object.defineProperty(sample, key, {value: 42}); + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with own key [" + key + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.js new file mode 100644 index 0000000000..3b9b39bae2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is not an integer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If IsInteger(numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["1.1"] = "test262"; +TypedArray.prototype["0.000001"] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1.1"), false, "1.1"); + assert.sameValue(Reflect.has(sample, "0.000001"), false, "0.000001"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.js new file mode 100644 index 0000000000..acb5905ae0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from properties that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "foo"), false); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue(Reflect.has(sample, "foo"), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-symbol.js new file mode 100644 index 0000000000..915af90334 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from Symbol properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testTypedArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("foo"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, s), false); + + Object.defineProperty(sample, s, { value: 42 }); + + assert.sameValue(Reflect.has(sample, s), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js new file mode 100644 index 0000000000..5e1a504d5e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js @@ -0,0 +1,64 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: returned keys reflect resized ArrayBuffer for a dynamically-sized TypedArray +includes: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +function inspect(array) { + return [ + Reflect.has(array, 0), + Reflect.has(array, 1), + Reflect.has(array, 2), + Reflect.has(array, 3), + Reflect.has(array, 4) + ].join(","); +} + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = "true,true,true,false,false"; + + assert.sameValue(inspect(array), expected, "initial"); + + try { + ab.resize(BPE * 5); + expected = "true,true,true,true,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = "true,true,false,false,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following shrink (within bounds)"); + + try { + ab.resize(BPE); + expected = "false,false,false,false,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following shrink (on boundary)"); + + try { + ab.resize(0); + expected = "false,false,false,false,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following shrink (out of bounds)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..59c5b5ac4c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js @@ -0,0 +1,57 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: returned keys reflect resized ArrayBuffer for a fixed-sized TypedArray +includes: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +function inspect(array) { + return [ + Reflect.has(array, 0), + Reflect.has(array, 1), + Reflect.has(array, 2), + Reflect.has(array, 3), + Reflect.has(array, 4) + ].join(","); +} + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(inspect(array), "true,true,false,false,false", "initial"); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(inspect(array), "true,true,false,false,false", "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(inspect(array), "true,true,false,false,false", "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 2); + expected = "false,false,false,false,false"; + } catch (_) { + expected = "true,true,false,false,false"; + } + + assert.sameValue(inspect(array), expected, "following shrink (out of bounds)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js new file mode 100644 index 0000000000..7b3c9f20d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js @@ -0,0 +1,179 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js new file mode 100644 index 0000000000..4aa72e5416 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA([42n, 42n, 42n]); + sample1[s1] = 42; + sample1[s2] = 42; + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262", s1, s2]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2[s1] = 42; + sample2[s2] = 42; + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262", s1, s2]), + "result2" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js new file mode 100644 index 0000000000..5867283bf8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA([42n, 42n, 42n]); + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262"]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262"]), + "result2" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.js new file mode 100644 index 0000000000..596d2d59a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA([42n, 42n, 42n]); + var result1 = Reflect.ownKeys(sample1); + assert(compareArray(result1, ["0", "1", "2"]), "result1"); + + var sample2 = new TA(4); + var result2 = Reflect.ownKeys(sample2); + assert(compareArray(result2, ["0", "1", "2", "3"]), "result2"); + + var sample3 = new TA(4).subarray(2); + var result3 = Reflect.ownKeys(sample3); + assert(compareArray(result3, ["0", "1"]), "result3"); + + var sample4 = new TA(); + var result4 = Reflect.ownKeys(sample4); + assert(compareArray(result4, []), "result4"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js new file mode 100644 index 0000000000..06439e1441 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + List not-enumerable own keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + Object.defineProperty(sample, s, { + value: 42, + enumerable: false + }); + Object.defineProperty(sample, "test262", { + value: 42, + enumerable: false + }); + var result = Reflect.ownKeys(sample); + assert(compareArray(result, ["test262", s])); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js new file mode 100644 index 0000000000..ebf707791b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testTypedArray.js, compareArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([42, 42, 42]); + sample1[s1] = 42; + sample1[s2] = 42; + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262", s1, s2]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2[s1] = 42; + sample2[s2] = 42; + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262", s1, s2]), + "result2" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js new file mode 100644 index 0000000000..00532ce8b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testTypedArray.js, compareArray.js] +features: [Reflect, TypedArray] +---*/ + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([42, 42, 42]); + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262"]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262"]), + "result2" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js new file mode 100644 index 0000000000..83995def30 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js @@ -0,0 +1,70 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: returned keys reflect resized ArrayBuffer for a dynamically-sized TypedArray +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let getBufferByteLength be ! + MakeIdempotentArrayBufferByteLengthGetter(SeqCst). + 4. Let len be IntegerIndexedObjectLength(O, getBufferByteLength). + 5. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = "0,1,2"; + + assert.sameValue(Reflect.ownKeys(array).join(","), expected, "initial"); + + try { + ab.resize(BPE * 5); + expected = "0,1,2,3"; + } catch (_) {} + + assert.sameValue(Reflect.ownKeys(array).join(","), expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = "0,1"; + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (within bounds)" + ); + + try { + ab.resize(BPE); + expected = ""; + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (on boundary)" + ); + + try { + ab.resize(0); + expected = ""; + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (out of bounds)" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..b6faa1f4ba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js @@ -0,0 +1,61 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: returned keys reflect resized ArrayBuffer for a fixed-sized TypedArray +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let getBufferByteLength be ! + MakeIdempotentArrayBufferByteLengthGetter(SeqCst). + 4. Let len be IntegerIndexedObjectLength(O, getBufferByteLength). + 5. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(Reflect.ownKeys(array).join(","), "0,1", "initial"); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(Reflect.ownKeys(array).join(","), "0,1", "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), "0,1", "following shrink (within bounds)" + ); + + var expected; + try { + ab.resize(BPE * 2); + expected = ""; + } catch (_) { + expected = "0,1"; + } + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (out of bounds)" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.js new file mode 100644 index 0000000000..b731decd95 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testTypedArray.js, compareArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([42, 42, 42]); + var result1 = Reflect.ownKeys(sample1); + assert(compareArray(result1, ["0", "1", "2"]), "result1"); + + var sample2 = new TA(4); + var result2 = Reflect.ownKeys(sample2); + assert(compareArray(result2, ["0", "1", "2", "3"]), "result2"); + + var sample3 = new TA(4).subarray(2); + var result3 = Reflect.ownKeys(sample3); + assert(compareArray(result3, ["0", "1"]), "result3"); + + var sample4 = new TA(); + var result4 = Reflect.ownKeys(sample4); + assert(compareArray(result4, []), "result4"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.js new file mode 100644 index 0000000000..9c78932877 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: > + List not-enumerable own keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testTypedArray.js, compareArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + Object.defineProperty(sample, s, { + value: 42, + enumerable: false + }); + Object.defineProperty(sample, "test262", { + value: 42, + enumerable: false + }); + var result = Reflect.ownKeys(sample); + assert(compareArray(result, ["test262", s])); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js new file mode 100644 index 0000000000..05fecd6ef1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js @@ -0,0 +1,161 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js new file mode 100644 index 0000000000..fac2234818 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js @@ -0,0 +1,102 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of BigInts +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered"). + 17. Return true. + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigInt64 + Conversion Operation: ToBigInt64 + + ToBigInt64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. If int64bit ≥ 2^63, return int64bit - 2^64; otherwise return int64bit. + +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +// 2n ** 64n + 2n +// 2n ** 63n + 2n +// -(2n ** 63n) - 2n +// -(2n ** 64n) - 2n +// 2n - 2n ** 63n +// 2n ** 63n - 2 +var vals = [ + 18446744073709551618n, + 9223372036854775810n, + 2n, + 0n, + -2n, + -9223372036854775810n, + -18446744073709551618n +]; + +var typedArray = new BigInt64Array(1); +typedArray[0] = vals[0]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[1]; +assert.sameValue(typedArray[0], -9223372036854775806n, 'The value of typedArray[0] is -9223372036854775806n'); +typedArray[0] = vals[2]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[3]; +assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); +typedArray[0] = vals[4]; +assert.sameValue(typedArray[0], -2n, 'The value of typedArray[0] is -2n'); +typedArray[0] = vals[5]; +assert.sameValue(typedArray[0], 9223372036854775806n, 'The value of typedArray[0] is 9223372036854775806n'); +typedArray[0] = vals[6]; +assert.sameValue(typedArray[0], -2n, 'The value of typedArray[0] is -2n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js new file mode 100644 index 0000000000..d1b8b9067e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js @@ -0,0 +1,104 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of BigInts +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered"). + 17. Return true. + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigUint64 + Conversion Operation: ToBigUint64 + + ToBigUint64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. Return int64bit. + +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +// 2n ** 64n + 2n +// 2n ** 63n + 2n +// -(2n ** 63n) - 2n +// -(2n ** 64n) - 2n +// 2n ** 63n + 2n +// 2n ** 64n - 2n +// 2n ** 63n - 2n +// 2n ** 64n - 2n +var vals = [ + 18446744073709551618n, + 9223372036854775810n, + 2n, + 0n, + -2n, + -9223372036854775810n, + -18446744073709551618n +]; + +var typedArray = new BigUint64Array(1); +typedArray[0] = vals[0]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[1]; +assert.sameValue(typedArray[0], 9223372036854775810n, 'The value of typedArray[0] is 9223372036854775810n'); +typedArray[0] = vals[2]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[3]; +assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); +typedArray[0] = vals[4]; +assert.sameValue(typedArray[0], 18446744073709551614n, 'The value of typedArray[0] is 18446744073709551614n'); +typedArray[0] = vals[5]; +assert.sameValue(typedArray[0], 9223372036854775806n, 'The value of typedArray[0] is 9223372036854775806n'); +typedArray[0] = vals[6]; +assert.sameValue(typedArray[0], 18446744073709551614n, 'The value of typedArray[0] is 18446744073709551614n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js new file mode 100644 index 0000000000..e41c023d36 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for assigning Booleans to BigInt TypedArray +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Boolean + Result: Return 1n if prim is true and 0n if prim is false. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray[0] = false; + typedArray[1] = true; + assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); + assert.sameValue(typedArray[1], 1n, 'The value of typedArray[1] is 1n'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..27d868a915 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, 'foo', 'test262'), + true, + 'Reflect.set(sample, "foo", "test262") must return true' + ); + + assert.sameValue(sample.foo, 'test262', 'The value of sample.foo is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..5a34f8f6d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, Reflect, TypedArray] +---*/ +var s = Symbol('1'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, s, 'test262'), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "test262") must return true' + ); + + assert.sameValue(sample[s], 'test262', 'The value of sample[s] is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..ed67be5eaa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; +testWithBigIntTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + $DETACHBUFFER(sample.buffer); + sample[0] = 1n; + assert.sameValue(sample[0], undefined, '`sample[0]` is undefined'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js new file mode 100644 index 0000000000..d4b7ea8ba3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false when setting the value of any CanonicalNumericIndexString if buffer is detached. +info: | + [[Set]] ( P, V, Receiver) + + ... + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n]); + $DETACHBUFFER(sample.buffer); + sample[0] = 1n; + assert.sameValue(sample[0], undefined, '`sample[0] = 1n` is undefined'); + sample['1.1'] = 1n; + assert.sameValue(sample['1.1'], undefined, '`sample["1.1"] = 1n` is undefined'); + sample['-0'] = 1n; + assert.sameValue(sample['-0'], undefined, '`sample["-0"] = 1n` is undefined'); + sample['-1'] = 1n; + assert.sameValue(sample['-1'], undefined, '`sample["-1"] = 1n` is undefined'); + sample['1'] = 1n; + assert.sameValue(sample['1'], undefined, '`sample["1"] = 1n` is undefined'); + sample['2'] = 1n; + assert.sameValue(sample['2'], undefined, '`sample["2"] = 1n` is undefined'); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample["0"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js new file mode 100644 index 0000000000..60d0b4b736 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +let proto = TypedArray.prototype; +let throwDesc = { + set: function() { + throw new Test262Error('OrdinarySet was called!'); + } +}; + +Object.defineProperty(proto, '0', throwDesc); +Object.defineProperty(proto, '1', throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(2); + assert.sameValue(Reflect.set(sample, '0', 1n), true, 'Reflect.set(sample, "0", 1n) must return true'); + assert.sameValue(sample[0], 1n, 'The value of sample[0] is 1n'); + assert.sameValue(Reflect.set(sample, '1', 42n), true, 'Reflect.set(sample, "1", 42n) must return true'); + assert.sameValue(sample[1], 42n, 'The value of sample[1] is 42n'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..a8027b8002 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true, even if index is -0 +info: | + [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '-0', 1n), true, 'Reflect.set("new TA([42n])", "-0", 1n) must return true'); + assert.sameValue(sample.hasOwnProperty('-0'), false, 'sample.hasOwnProperty("-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..380c18c935 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +var keys = ['1.0', '+1', '1000000000000000000000', '0.0000001']; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, key, 'ecma262'), + true, + 'Reflect.set("new TA([42n])", key, "ecma262") must return true' + ); + + assert.sameValue(sample[key], 'ecma262', 'The value of sample[key] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, key, 'es3000'), + true, + 'Reflect.set("new TA([42n])", key, "es3000") must return true' + ); + + assert.sameValue(sample[key], 'es3000', 'The value of sample[key] is "es3000"'); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + + assert.sameValue(Reflect.set(sample, key, 42), false, 'Reflect.set("new TA([42n])", key, 42) must return false'); + assert.sameValue(sample[key], undefined, 'The value of sample[key] is expected to equal `undefined`'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..cb8fa7a526 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true, even if index is not CanonicalNumericIndexString +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '1.1', 1n), true, 'Reflect.set("new TA([42n])", "1.1", 1n) must return true'); + + assert.sameValue( + Reflect.set(sample, '0.0001', 1n), + true, + 'Reflect.set("new TA([42n])", "0.0001", 1n) must return true' + ); + + assert.sameValue(sample.hasOwnProperty('1.1'), false, 'sample.hasOwnProperty("1.1") must return false'); + assert.sameValue(sample.hasOwnProperty('0.0001'), false, 'sample.hasOwnProperty("0.0001") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js new file mode 100644 index 0000000000..5b8dd12f01 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from OrdinarySet when key is not a numeric index +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). + + 9.1.9.1 OrdinarySet (O, P, V, Receiver) + + ... + 8. Perform ? Call(setter, Receiver, « V »). + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + set: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262 = 1; + }, '`sample.test262 = 1` throws Test262Error'); + + assert.sameValue(sample.test262, undefined, 'The value of sample.test262 is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..04f4deab89 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet if key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, 'test262', 'ecma262'), + true, + 'Reflect.set("new TA([42n])", "test262", "ecma262") must return true' + ); + + assert.sameValue(sample.test262, 'ecma262', 'The value of sample.test262 is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, 'test262', 'es3000'), + true, + 'Reflect.set("new TA([42n])", "test262", "es3000") must return true' + ); + + assert.sameValue(sample.test262, 'es3000', 'The value of sample.test262 is "es3000"'); + + Object.defineProperty(sample, 'foo', { + writable: false, + value: undefined + }); + + assert.sameValue(Reflect.set(sample, 'foo', 42), false, 'Reflect.set("new TA([42n])", "foo", 42) must return false'); + assert.sameValue(sample.foo, undefined, 'The value of sample.foo is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..5fe02832bd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true, even if index is out of bounds +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + 9.4.5.11 IntegerIndexedElementSet ( O, index, value ) + + ... + 8. Let length be the value of O's [[ArrayLength]] internal slot. + 9. If index < 0 or index ≥ length, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '-1', 1n), true, 'Reflect.set("new TA([42n])", "-1", 1n) must return false'); + assert.sameValue(Reflect.set(sample, '1', 1n), true, 'Reflect.set("new TA([42n])", "1", 1n) must return false'); + assert.sameValue(Reflect.set(sample, '2', 1n), true, 'Reflect.set("new TA([42n])", "2", 1n) must return false'); + assert.sameValue(sample.hasOwnProperty('-1'), false, 'sample.hasOwnProperty("-1") must return false'); + assert.sameValue(sample.hasOwnProperty('1'), false, 'sample.hasOwnProperty("1") must return false'); + assert.sameValue(sample.hasOwnProperty('2'), false, 'sample.hasOwnProperty("2") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..0fc2d9ec46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, Symbol, TypedArray] +---*/ +var s1 = Symbol('1'); +var s2 = Symbol('2'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, s1, 'ecma262'), + true, + 'Reflect.set("new TA([42n])", "Symbol(\\"1\\")", "ecma262") must return true' + ); + + assert.sameValue(sample[s1], 'ecma262', 'The value of sample[s1] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, s1, 'es3000'), + true, + 'Reflect.set("new TA([42n])", "Symbol(\\"1\\")", "es3000") must return true' + ); + + assert.sameValue(sample[s1], 'es3000', 'The value of sample[s1] is "es3000"'); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + 'Reflect.set("new TA([42n])", "Symbol(\\"2\\")", 42) must return false' + ); + + assert.sameValue(sample[s2], undefined, 'The value of sample[s2] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js new file mode 100644 index 0000000000..104c5a8509 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js @@ -0,0 +1,63 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on null +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Null + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = null; + }, '`typedArray[0] = null` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js new file mode 100644 index 0000000000..b7724a0aed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js @@ -0,0 +1,87 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on Number +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Number + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = 1; + }, '`typedArray[0] = 1` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = Math.pow(2, 63); + }, '`typedArray[0] = Math.pow(2, 63)` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = +0; + }, '`typedArray[0] = +0` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = -0; + }, '`typedArray[0] = -0` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = Infinity; + }, '`typedArray[0] = Infinity` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = -Infinity; + }, '`typedArray[0] = -Infinity` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = NaN; + }, '`typedArray[0] = NaN` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js new file mode 100644 index 0000000000..f0646cc025 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js @@ -0,0 +1,67 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt String, when StringToBigInt returns NaN +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(SyntaxError, function() { + typedArray[0] = "definately not a number"; + }, '`typedArray[0] = "definately not a number"` throws SyntaxError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js new file mode 100644 index 0000000000..ff5aa4145a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js @@ -0,0 +1,87 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of Strings, successful conversion +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + + StringToBigInt (argument) + Apply the algorithm in 3.1.3.1 with the following changes: + * Replace the StrUnsignedDecimalLiteral production with DecimalDigits to + not allow Infinity, decimal points, or exponents. + * If the MV is NaN, return NaN, otherwise return the BigInt which exactly + corresponds to the MV, rather than rounding to a Number. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + typedArray[0] = ''; + assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); + typedArray[0] = '1'; + assert.sameValue(typedArray[0], 1n, 'The value of typedArray[0] is 1n'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1n'; + }, '`typedArray[0] = "1n"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = 'Infinity'; + }, '`typedArray[0] = "Infinity"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1.1'; + }, '`typedArray[0] = "1.1"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1e7'; + }, '`typedArray[0] = "1e7"` throws SyntaxError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js new file mode 100644 index 0000000000..6b5618b568 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on Symbol +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Symbol + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray, Symbol] +---*/ + +var s = Symbol() + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1) + + assert.throws(TypeError, function() { + typedArray[0] = s; + }, '`typedArray[0] = s` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..974de14c4a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Setting a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, + will always return true. +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let ta = new TA(1); + let isDetached = false; + let result = Reflect.set(ta, 0, { + valueOf() { + $DETACHBUFFER(ta.buffer); + isDetached = true; + return 42n; + } + }); + + assert.sameValue(result, true); + assert.sameValue(ta[0], undefined); + assert.sameValue(isDetached, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js new file mode 100644 index 0000000000..665d19b195 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js @@ -0,0 +1,62 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from ToNumber(value) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n]); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample["0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['1.1'] = obj; + }, '`sample["1.1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['-0'] = obj; + }, '`sample["-0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['-1'] = obj; + }, '`sample["-1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['1'] = obj; + }, '`sample["1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['2'] = obj; + }, '`sample["2"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js new file mode 100644 index 0000000000..a2152d98f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js @@ -0,0 +1,64 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on undefined +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Undefined + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = undefined; + }, '`typedArray[0] = undefined` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js new file mode 100644 index 0000000000..d2355a13c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on BigInt +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + 6. Otherwise, let numValue be ? ToNumber(value). + ... + + ToNumber ( argument ) + The abstract operation ToNumber converts argument to a value of type Number + according to: + + Number Conversion + Argument Type: BigInt + Result: Throw a TypeError Exception + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = 1n; + }, '`typedArray[0] = 1n` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js new file mode 100644 index 0000000000..b97ef770e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js @@ -0,0 +1,107 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: Consistent canonicalization of NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. + ... + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(FA) { + var precision = floatTypedArrayConstructorPrecision(FA); + var samples = new FA(1); + var controls, idx, aNaN; + + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx]; + controls = new FA([aNaN, aNaN, aNaN]); + + samples[0] = aNaN; + + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `The result of \`(samples[i] !== samples[i])\` is true (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `The result of \`(controls[i] !== controls[i])\` is true (${precision} precision)` + ); + } + } +}, floatArrayConstructors); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js new file mode 100644 index 0000000000..786b0c4bec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Verify conversion after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample[0] = value; + + assert.sameValue(sample[0], expected, 'The value of sample[0] is expected to equal the value of expected'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..81a22ef437 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, "foo", "test262"), + true, + 'Reflect.set(sample, "foo", "test262") must return true' + ); + assert.sameValue(sample.foo, "test262", 'The value of sample.foo is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..183070c85b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, Reflect, TypedArray] +---*/ + +let s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, s, "test262"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "test262") must return true' + ); + assert.sameValue(sample[s], "test262", 'The value of sample[s] is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js new file mode 100644 index 0000000000..5e6269b2e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; +testWithTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + $DETACHBUFFER(sample.buffer); + sample[0] = 1; + assert.sameValue(sample[0], undefined, '`sample[0]` is undefined'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js new file mode 100644 index 0000000000..705b22dca5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if key has a numeric index and object has a detached buffer +info: | + [[Set]] ( P, V, Receiver) + + ... + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42]); + $DETACHBUFFER(sample.buffer); + sample[0] = 1; + + assert.sameValue(sample[0], undefined, '`sample[0] = 1` is undefined'); + sample['1.1'] = 1; + assert.sameValue(sample['1.1'], undefined, '`sample[\'1.1\'] = 1` is undefined'); + sample['-0'] = 1; + assert.sameValue(sample['-0'], undefined, '`sample[\'-0\'] = 1` is undefined'); + sample['-1'] = 1; + assert.sameValue(sample['-1'], undefined, '`sample[\'-1\'] = 1` is undefined'); + sample['1'] = 1; + assert.sameValue(sample['1'], undefined, '`sample[\'1\'] = 1` is undefined'); + sample['2'] = 1; + assert.sameValue(sample['2'], undefined, '`sample[\'2\'] = 1` is undefined'); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample[\'0\'] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js new file mode 100644 index 0000000000..66cf4571ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +let proto = TypedArray.prototype; +let throwDesc = { + set: function() { + throw new Test262Error('OrdinarySet was called!'); + } +}; + +Object.defineProperty(proto, '0', throwDesc); +Object.defineProperty(proto, '1', throwDesc); + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(2); + assert.sameValue(Reflect.set(sample, '0', 1), true, 'Reflect.set(sample, "0", 1) must return true'); + assert.sameValue(sample[0], 1, 'The value of sample[0] is 1'); + assert.sameValue(Reflect.set(sample, '1', 42), true, 'Reflect.set(sample, "1", 42) must return true'); + assert.sameValue(sample[1], 42, 'The value of sample[1] is 42'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js new file mode 100644 index 0000000000..c171aa1a3c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true, even if index is -0 +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "-0", 1), true, 'Reflect.set(sample, "-0", 1) must return true'); + assert.sameValue(sample.hasOwnProperty("-0"), false, 'sample.hasOwnProperty("-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js new file mode 100644 index 0000000000..72d1f7769a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, key, "ecma262"), + true, + 'Reflect.set(sample, key, "ecma262") must return true' + ); + assert.sameValue(sample[key], "ecma262", 'The value of sample[key] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, key, "es3000"), + true, + 'Reflect.set(sample, key, "es3000") must return true' + ); + assert.sameValue(sample[key], "es3000", 'The value of sample[key] is "es3000"'); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, key, 42), + false, + 'Reflect.set(sample, key, 42) must return false' + ); + assert.sameValue( + sample[key], undefined, 'The value of sample[key] is expected to equal `undefined`' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js new file mode 100644 index 0000000000..a13b9cfe79 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true, even if index is not CanonicalNumericIndexString +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "1.1", 1), true, 'Reflect.set(sample, "1.1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "0.0001", 1), true, 'Reflect.set(sample, "0.0001", 1) must return true'); + + assert.sameValue(sample.hasOwnProperty("1.1"), false, 'sample.hasOwnProperty("1.1") must return false'); + assert.sameValue( + sample.hasOwnProperty("0.0001"), + false, + 'sample.hasOwnProperty("0.0001") must return false' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js new file mode 100644 index 0000000000..13360bfa55 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from OrdinarySet when key is not a numeric index +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). + + 9.1.9.1 OrdinarySet (O, P, V, Receiver) + + ... + 8. Perform ? Call(setter, Receiver, « V »). + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + set: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262 = 1; + }, '`sample.test262 = 1` throws Test262Error'); + + assert.sameValue(sample.test262, undefined, 'The value of sample.test262 is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js new file mode 100644 index 0000000000..9db75bd292 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet if key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, "test262", "ecma262"), + true, + 'Reflect.set(sample, "test262", "ecma262") must return true' + ); + assert.sameValue(sample.test262, "ecma262", 'The value of sample.test262 is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, "test262", "es3000"), + true, + 'Reflect.set(sample, "test262", "es3000") must return true' + ); + assert.sameValue(sample.test262, "es3000", 'The value of sample.test262 is "es3000"'); + + Object.defineProperty(sample, "foo", { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, "foo", 42), + false, + 'Reflect.set(sample, "foo", 42) must return false' + ); + assert.sameValue(sample.foo, undefined, 'The value of sample.foo is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js new file mode 100644 index 0000000000..5470398b71 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true even if index is out of bounds +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "-1", 1), true, 'Reflect.set(sample, "-1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "1", 1), true, 'Reflect.set(sample, "1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "2", 1), true, 'Reflect.set(sample, "2", 1) must return true'); + + assert.sameValue(sample.hasOwnProperty("-1"), false, 'sample.hasOwnProperty("-1") must return false'); + assert.sameValue(sample.hasOwnProperty("1"), false, 'sample.hasOwnProperty("1") must return false'); + assert.sameValue(sample.hasOwnProperty("2"), false, 'sample.hasOwnProperty("2") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js new file mode 100644 index 0000000000..fe624e4725 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, s1, "ecma262"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "ecma262") must return true' + ); + assert.sameValue(sample[s1], "ecma262", 'The value of sample[s1] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, s1, "es3000"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "es3000") must return true' + ); + assert.sameValue(sample[s1], "es3000", 'The value of sample[s1] is "es3000"'); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + 'Reflect.set(sample, "Symbol(\\"2\\")", 42) must return false' + ); + assert.sameValue(sample[s2], undefined, 'The value of sample[s2] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js new file mode 100644 index 0000000000..c32f046213 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js @@ -0,0 +1,694 @@ +// GENERATED, DO NOT EDIT +// file: byteConversionValues.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float16: [ + 127, // 127 + 128, // 128 + 32768, // 32767 + 32768, // 32768 + Infinity, // 2147483647 + Infinity, // 2147483648 + 255, // 255 + 256, // 256 + Infinity, // 65535 + Infinity, // 65536 + Infinity, // 4294967295 + Infinity, // 4294967296 + Infinity, // 9007199254740991 + Infinity, // 9007199254740992 + 1.099609375, // 1.1 + 0.0999755859375, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.60009765625, // 0.6 + 0.7001953125, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.0999755859375, // -0.1 + -1.099609375, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32768, // -32767 + -32768, // -32768 + -Infinity, // -2147483647 + -Infinity, // -2147483648 + -255, // -255 + -256, // -256 + -Infinity, // -65535 + -Infinity, // -65536 + -Infinity, // -4294967295 + -Infinity, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; + +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..bdb3a74ae9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js @@ -0,0 +1,52 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Setting a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, will return true. +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + 9.4.5.11 IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let ta = new TA(1); + let result = Reflect.set(ta, 0, { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42; + } + }); + + assert.sameValue(result, true); + assert.sameValue(ta[0], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js new file mode 100644 index 0000000000..08f17de272 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from ToNumber(value) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42]); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, '`sample["0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["1.1"] = obj; + }, '`sample["1.1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["-0"] = obj; + }, '`sample["-0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["-1"] = obj; + }, '`sample["-1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["1"] = obj; + }, '`sample["1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["2"] = obj; + }, '`sample["2"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/shell.js new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3