From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/test262/built-ins/DataView/browser.js | 0 ...er-does-not-have-arraybuffer-data-throws-sab.js | 45 ++ ...buffer-does-not-have-arraybuffer-data-throws.js | 43 ++ .../built-ins/DataView/buffer-not-object-throws.js | 55 +++ .../built-ins/DataView/buffer-reference-sab.js | 28 ++ .../test262/built-ins/DataView/buffer-reference.js | 25 ++ .../DataView/byteoffset-is-negative-throws-sab.js | 31 ++ .../DataView/byteoffset-is-negative-throws.js | 28 ++ .../test262/built-ins/DataView/constructor.js | 13 + .../custom-proto-access-detaches-buffer.js | 38 ++ ...roto-access-resizes-buffer-invalid-by-length.js | 43 ++ ...roto-access-resizes-buffer-invalid-by-offset.js | 42 ++ ...-proto-access-resizes-buffer-valid-by-length.js | 35 ++ ...-proto-access-resizes-buffer-valid-by-offset.js | 38 ++ .../DataView/custom-proto-access-throws-sab.js | 48 ++ .../DataView/custom-proto-access-throws.js | 46 ++ ...ot-object-fallbacks-to-default-prototype-sab.js | 49 +++ ...if-not-object-fallbacks-to-default-prototype.js | 47 ++ .../DataView/custom-proto-if-object-is-used-sab.js | 50 +++ .../DataView/custom-proto-if-object-is-used.js | 48 ++ .../tests/test262/built-ins/DataView/dataview.js | 15 + .../defined-bytelength-and-byteoffset-sab.js | 63 +++ .../DataView/defined-bytelength-and-byteoffset.js | 60 +++ .../built-ins/DataView/defined-byteoffset-sab.js | 56 +++ .../defined-byteoffset-undefined-bytelength-sab.js | 59 +++ .../defined-byteoffset-undefined-bytelength.js | 56 +++ .../built-ins/DataView/defined-byteoffset.js | 53 +++ .../test262/built-ins/DataView/detached-buffer.js | 36 ++ .../DataView/excessive-bytelength-throws-sab.js | 58 +++ .../DataView/excessive-bytelength-throws.js | 55 +++ .../DataView/excessive-byteoffset-throws-sab.js | 31 ++ .../DataView/excessive-byteoffset-throws.js | 28 ++ .../test262/built-ins/DataView/extensibility.js | 17 + .../DataView/instance-extensibility-sab.js | 56 +++ .../built-ins/DataView/instance-extensibility.js | 53 +++ .../test262/built-ins/DataView/is-a-constructor.js | 26 ++ js/src/tests/test262/built-ins/DataView/length.js | 35 ++ js/src/tests/test262/built-ins/DataView/name.js | 17 + .../DataView/negative-bytelength-throws-sab.js | 49 +++ .../DataView/negative-bytelength-throws.js | 46 ++ .../DataView/negative-byteoffset-throws-sab.js | 38 ++ .../DataView/negative-byteoffset-throws.js | 35 ++ .../DataView/newtarget-undefined-throws-sab.js | 30 ++ .../DataView/newtarget-undefined-throws.js | 27 ++ .../DataView/proto-from-ctor-realm-sab.js | 35 ++ .../built-ins/DataView/proto-from-ctor-realm.js | 33 ++ js/src/tests/test262/built-ins/DataView/proto.js | 15 + .../tests/test262/built-ins/DataView/prototype.js | 21 + .../DataView/prototype/Symbol.toStringTag.js | 27 ++ .../built-ins/DataView/prototype/browser.js | 0 .../built-ins/DataView/prototype/buffer/browser.js | 0 .../DataView/prototype/buffer/detached-buffer.js | 22 + .../prototype/buffer/invoked-as-accessor.js | 22 + .../DataView/prototype/buffer/invoked-as-func.js | 25 ++ .../built-ins/DataView/prototype/buffer/length.js | 33 ++ .../built-ins/DataView/prototype/buffer/name.js | 29 ++ .../DataView/prototype/buffer/prop-desc.js | 25 ++ .../DataView/prototype/buffer/return-buffer-sab.js | 24 + .../DataView/prototype/buffer/return-buffer.js | 21 + .../built-ins/DataView/prototype/buffer/shell.js | 0 .../buffer/this-has-no-dataview-internal-sab.js | 44 ++ .../buffer/this-has-no-dataview-internal.js | 42 ++ .../prototype/buffer/this-is-not-object.js | 49 +++ .../DataView/prototype/byteLength/browser.js | 0 .../prototype/byteLength/detached-buffer.js | 25 ++ .../byteLength/instance-has-detached-buffer.js | 25 ++ .../prototype/byteLength/invoked-as-accessor.js | 22 + .../prototype/byteLength/invoked-as-func.js | 25 ++ .../DataView/prototype/byteLength/length.js | 33 ++ .../DataView/prototype/byteLength/name.js | 29 ++ .../DataView/prototype/byteLength/prop-desc.js | 27 ++ .../byteLength/resizable-array-buffer-auto.js | 57 +++ .../byteLength/resizable-array-buffer-fixed.js | 48 ++ .../prototype/byteLength/return-bytelength-sab.js | 31 ++ .../prototype/byteLength/return-bytelength.js | 28 ++ .../DataView/prototype/byteLength/shell.js | 0 .../this-has-no-dataview-internal-sab.js | 44 ++ .../byteLength/this-has-no-dataview-internal.js | 42 ++ .../prototype/byteLength/this-is-not-object.js | 49 +++ .../DataView/prototype/byteOffset/browser.js | 0 .../prototype/byteOffset/detached-buffer.js | 26 ++ .../prototype/byteOffset/invoked-as-accessor.js | 22 + .../prototype/byteOffset/invoked-as-func.js | 25 ++ .../DataView/prototype/byteOffset/length.js | 33 ++ .../DataView/prototype/byteOffset/name.js | 29 ++ .../DataView/prototype/byteOffset/prop-desc.js | 25 ++ .../byteOffset/resizable-array-buffer-auto.js | 54 +++ .../byteOffset/resizable-array-buffer-fixed.js | 48 ++ .../prototype/byteOffset/return-byteoffset-sab.js | 33 ++ .../prototype/byteOffset/return-byteoffset.js | 30 ++ .../DataView/prototype/byteOffset/shell.js | 0 .../this-has-no-dataview-internal-sab.js | 44 ++ .../byteOffset/this-has-no-dataview-internal.js | 42 ++ .../prototype/byteOffset/this-is-not-object.js | 49 +++ .../DataView/prototype/getBigInt64/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 38 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/getBigInt64/detached-buffer.js | 32 ++ .../prototype/getBigInt64/index-is-out-of-range.js | 77 ++++ .../DataView/prototype/getBigInt64/length.js | 34 ++ .../DataView/prototype/getBigInt64/name.js | 33 ++ .../getBigInt64/negative-byteoffset-throws.js | 32 ++ .../prototype/getBigInt64/not-a-constructor.js | 35 ++ .../prototype/getBigInt64/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 30 ++ .../return-abrupt-from-tonumber-byteoffset.js | 41 ++ .../getBigInt64/return-value-clean-arraybuffer.js | 50 +++ .../getBigInt64/return-values-custom-offset.js | 70 +++ .../prototype/getBigInt64/return-values.js | 71 +++ .../DataView/prototype/getBigInt64/shell.js | 0 .../getBigInt64/this-has-no-dataview-internal.js | 36 ++ .../prototype/getBigInt64/this-is-not-object.js | 39 ++ .../getBigInt64/to-boolean-littleendian.js | 69 +++ .../getBigInt64/toindex-byteoffset-errors.js | 109 +++++ .../getBigInt64/toindex-byteoffset-toprimitive.js | 190 ++++++++ .../toindex-byteoffset-wrapped-values.js | 135 ++++++ .../prototype/getBigInt64/toindex-byteoffset.js | 72 +++ .../DataView/prototype/getBigUint64/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 23 + ...detached-buffer-before-outofrange-byteoffset.js | 22 + .../prototype/getBigUint64/detached-buffer.js | 19 + .../getBigUint64/index-is-out-of-range.js | 61 +++ .../DataView/prototype/getBigUint64/length.js | 18 + .../DataView/prototype/getBigUint64/name.js | 18 + .../getBigUint64/negative-byteoffset-throws.js | 20 + .../prototype/getBigUint64/not-a-constructor.js | 35 ++ .../prototype/getBigUint64/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 18 + .../return-abrupt-from-tonumber-byteoffset.js | 29 ++ .../getBigUint64/return-value-clean-arraybuffer.js | 25 ++ .../getBigUint64/return-values-custom-offset.js | 45 ++ .../prototype/getBigUint64/return-values.js | 51 +++ .../DataView/prototype/getBigUint64/shell.js | 0 .../getBigUint64/this-has-no-dataview-internal.js | 23 + .../prototype/getBigUint64/this-is-not-object.js | 28 ++ .../getBigUint64/to-boolean-littleendian.js | 42 ++ .../getBigUint64/toindex-byteoffset-errors.js | 97 ++++ .../getBigUint64/toindex-byteoffset-toprimitive.js | 178 ++++++++ .../toindex-byteoffset-wrapped-values.js | 123 ++++++ .../prototype/getBigUint64/toindex-byteoffset.js | 60 +++ .../DataView/prototype/getFloat32/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/getFloat32/detached-buffer.js | 32 ++ .../prototype/getFloat32/index-is-out-of-range.js | 85 ++++ .../DataView/prototype/getFloat32/length.js | 32 ++ .../DataView/prototype/getFloat32/minus-zero.js | 42 ++ .../DataView/prototype/getFloat32/name.js | 28 ++ .../getFloat32/negative-byteoffset-throws.js | 33 ++ .../prototype/getFloat32/not-a-constructor.js | 35 ++ .../prototype/getFloat32/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../prototype/getFloat32/return-infinity.js | 46 ++ .../DataView/prototype/getFloat32/return-nan.js | 46 ++ .../getFloat32/return-value-clean-arraybuffer.js | 44 ++ .../getFloat32/return-values-custom-offset.js | 56 +++ .../DataView/prototype/getFloat32/return-values.js | 75 ++++ .../DataView/prototype/getFloat32/shell.js | 0 .../getFloat32/this-has-no-dataview-internal.js | 44 ++ .../prototype/getFloat32/this-is-not-object.js | 52 +++ .../getFloat32/to-boolean-littleendian.js | 52 +++ .../prototype/getFloat32/toindex-byteoffset.js | 66 +++ .../DataView/prototype/getFloat64/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/getFloat64/detached-buffer.js | 32 ++ .../prototype/getFloat64/index-is-out-of-range.js | 101 +++++ .../DataView/prototype/getFloat64/length.js | 32 ++ .../DataView/prototype/getFloat64/minus-zero.js | 46 ++ .../DataView/prototype/getFloat64/name.js | 28 ++ .../getFloat64/negative-byteoffset-throws.js | 33 ++ .../prototype/getFloat64/not-a-constructor.js | 35 ++ .../prototype/getFloat64/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../prototype/getFloat64/return-infinity.js | 54 +++ .../DataView/prototype/getFloat64/return-nan.js | 74 ++++ .../getFloat64/return-value-clean-arraybuffer.js | 44 ++ .../getFloat64/return-values-custom-offset.js | 61 +++ .../DataView/prototype/getFloat64/return-values.js | 71 +++ .../DataView/prototype/getFloat64/shell.js | 0 .../getFloat64/this-has-no-dataview-internal.js | 44 ++ .../prototype/getFloat64/this-is-not-object.js | 52 +++ .../getFloat64/to-boolean-littleendian.js | 56 +++ .../prototype/getFloat64/toindex-byteoffset.js | 70 +++ .../DataView/prototype/getInt16/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../DataView/prototype/getInt16/detached-buffer.js | 32 ++ .../prototype/getInt16/index-is-out-of-range.js | 77 ++++ .../DataView/prototype/getInt16/length.js | 32 ++ .../built-ins/DataView/prototype/getInt16/name.js | 28 ++ .../getInt16/negative-byteoffset-throws.js | 33 ++ .../prototype/getInt16/not-a-constructor.js | 35 ++ .../prototype/getInt16/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../getInt16/return-value-clean-arraybuffer.js | 44 ++ .../getInt16/return-values-custom-offset.js | 53 +++ .../DataView/prototype/getInt16/return-values.js | 59 +++ .../built-ins/DataView/prototype/getInt16/shell.js | 0 .../getInt16/this-has-no-dataview-internal.js | 44 ++ .../prototype/getInt16/this-is-not-object.js | 52 +++ .../prototype/getInt16/to-boolean-littleendian.js | 50 +++ .../prototype/getInt16/toindex-byteoffset.js | 63 +++ .../DataView/prototype/getInt32/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../DataView/prototype/getInt32/detached-buffer.js | 32 ++ .../getInt32/index-is-out-of-range-sab.js | 88 ++++ .../prototype/getInt32/index-is-out-of-range.js | 85 ++++ .../DataView/prototype/getInt32/length.js | 32 ++ .../built-ins/DataView/prototype/getInt32/name.js | 28 ++ .../getInt32/negative-byteoffset-throws-sab.js | 36 ++ .../getInt32/negative-byteoffset-throws.js | 33 ++ .../prototype/getInt32/not-a-constructor.js | 35 ++ .../prototype/getInt32/resizable-buffer.js | 44 ++ .../return-abrupt-from-tonumber-byteoffset-sab.js | 48 ++ ...n-abrupt-from-tonumber-byteoffset-symbol-sab.js | 34 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../getInt32/return-value-clean-arraybuffer-sab.js | 47 ++ .../getInt32/return-value-clean-arraybuffer.js | 44 ++ .../getInt32/return-values-custom-offset-sab.js | 61 +++ .../getInt32/return-values-custom-offset.js | 59 +++ .../prototype/getInt32/return-values-sab.js | 69 +++ .../DataView/prototype/getInt32/return-values.js | 67 +++ .../built-ins/DataView/prototype/getInt32/shell.js | 0 .../getInt32/this-has-no-dataview-internal-sab.js | 46 ++ .../getInt32/this-has-no-dataview-internal.js | 44 ++ .../prototype/getInt32/this-is-not-object.js | 52 +++ .../getInt32/to-boolean-littleendian-sab.js | 54 +++ .../prototype/getInt32/to-boolean-littleendian.js | 52 +++ .../prototype/getInt32/toindex-byteoffset-sab.js | 68 +++ .../prototype/getInt32/toindex-byteoffset.js | 66 +++ .../DataView/prototype/getInt8/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 38 ++ ...detached-buffer-before-outofrange-byteoffset.js | 36 ++ .../DataView/prototype/getInt8/detached-buffer.js | 31 ++ .../prototype/getInt8/index-is-out-of-range.js | 62 +++ .../built-ins/DataView/prototype/getInt8/length.js | 31 ++ .../built-ins/DataView/prototype/getInt8/name.js | 28 ++ .../getInt8/negative-byteoffset-throws.js | 32 ++ .../prototype/getInt8/not-a-constructor.js | 35 ++ .../DataView/prototype/getInt8/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 31 ++ .../return-abrupt-from-tonumber-byteoffset.js | 44 ++ .../getInt8/return-value-clean-arraybuffer.js | 37 ++ .../getInt8/return-values-custom-offset.js | 49 +++ .../DataView/prototype/getInt8/return-values.js | 43 ++ .../built-ins/DataView/prototype/getInt8/shell.js | 0 .../getInt8/this-has-no-dataview-internal.js | 43 ++ .../prototype/getInt8/this-is-not-object.js | 51 +++ .../prototype/getInt8/toindex-byteoffset.js | 61 +++ .../DataView/prototype/getUint16/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/getUint16/detached-buffer.js | 32 ++ .../prototype/getUint16/index-is-out-of-range.js | 77 ++++ .../DataView/prototype/getUint16/length.js | 32 ++ .../built-ins/DataView/prototype/getUint16/name.js | 28 ++ .../getUint16/negative-byteoffset-throws.js | 33 ++ .../prototype/getUint16/not-a-constructor.js | 35 ++ .../prototype/getUint16/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../getUint16/return-value-clean-arraybuffer.js | 44 ++ .../getUint16/return-values-custom-offset.js | 53 +++ .../DataView/prototype/getUint16/return-values.js | 59 +++ .../DataView/prototype/getUint16/shell.js | 0 .../getUint16/this-has-no-dataview-internal.js | 44 ++ .../prototype/getUint16/this-is-not-object.js | 52 +++ .../prototype/getUint16/to-boolean-littleendian.js | 50 +++ .../prototype/getUint16/toindex-byteoffset.js | 64 +++ .../DataView/prototype/getUint32/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/getUint32/detached-buffer.js | 32 ++ .../prototype/getUint32/index-is-out-of-range.js | 85 ++++ .../DataView/prototype/getUint32/length.js | 32 ++ .../built-ins/DataView/prototype/getUint32/name.js | 28 ++ .../getUint32/negative-byteoffset-throws.js | 33 ++ .../prototype/getUint32/not-a-constructor.js | 35 ++ .../prototype/getUint32/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../getUint32/return-value-clean-arraybuffer.js | 44 ++ .../getUint32/return-values-custom-offset.js | 59 +++ .../DataView/prototype/getUint32/return-values.js | 67 +++ .../DataView/prototype/getUint32/shell.js | 0 .../getUint32/this-has-no-dataview-internal.js | 44 ++ .../prototype/getUint32/this-is-not-object.js | 52 +++ .../prototype/getUint32/to-boolean-littleendian.js | 52 +++ .../prototype/getUint32/toindex-byteoffset.js | 65 +++ .../DataView/prototype/getUint8/browser.js | 0 .../detached-buffer-after-toindex-byteoffset.js | 38 ++ ...detached-buffer-before-outofrange-byteoffset.js | 36 ++ .../DataView/prototype/getUint8/detached-buffer.js | 31 ++ .../prototype/getUint8/index-is-out-of-range.js | 62 +++ .../DataView/prototype/getUint8/length.js | 31 ++ .../built-ins/DataView/prototype/getUint8/name.js | 28 ++ .../getUint8/negative-byteoffset-throws.js | 32 ++ .../prototype/getUint8/not-a-constructor.js | 35 ++ .../prototype/getUint8/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 31 ++ .../return-abrupt-from-tonumber-byteoffset.js | 44 ++ .../getUint8/return-value-clean-arraybuffer.js | 37 ++ .../getUint8/return-values-custom-offset.js | 49 +++ .../DataView/prototype/getUint8/return-values.js | 43 ++ .../built-ins/DataView/prototype/getUint8/shell.js | 0 .../getUint8/this-has-no-dataview-internal.js | 43 ++ .../prototype/getUint8/this-is-not-object.js | 51 +++ .../prototype/getUint8/toindex-byteoffset.js | 61 +++ .../DataView/prototype/setBigInt64/browser.js | 0 .../detached-buffer-after-bigint-value.js | 26 ++ .../detached-buffer-after-toindex-byteoffset.js | 25 ++ ...detached-buffer-before-outofrange-byteoffset.js | 23 + .../prototype/setBigInt64/detached-buffer.js | 20 + .../index-check-before-value-conversion.js | 36 ++ .../prototype/setBigInt64/index-is-out-of-range.js | 90 ++++ .../DataView/prototype/setBigInt64/length.js | 18 + .../DataView/prototype/setBigInt64/name.js | 18 + .../setBigInt64/negative-byteoffset-throws.js | 24 + .../DataView/prototype/setBigInt64/no-value-arg.js | 16 + .../prototype/setBigInt64/not-a-constructor.js | 35 ++ .../range-check-after-value-conversion.js | 27 ++ .../prototype/setBigInt64/resizable-buffer.js | 44 ++ .../return-abrupt-from-tobigint-value-symbol.js | 20 + .../return-abrupt-from-tobigint-value.js | 33 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 20 + .../return-abrupt-from-tonumber-byteoffset.js | 33 ++ .../setBigInt64/set-values-little-endian-order.js | 40 ++ .../setBigInt64/set-values-return-undefined.js | 45 ++ .../DataView/prototype/setBigInt64/shell.js | 0 .../setBigInt64/this-has-no-dataview-internal.js | 31 ++ .../prototype/setBigInt64/this-is-not-object.js | 41 ++ .../setBigInt64/to-boolean-littleendian.js | 36 ++ .../prototype/setBigInt64/toindex-byteoffset.js | 93 ++++ .../DataView/prototype/setBigUint64/browser.js | 0 .../prototype/setBigUint64/not-a-constructor.js | 35 ++ .../prototype/setBigUint64/resizable-buffer.js | 44 ++ .../DataView/prototype/setBigUint64/shell.js | 0 .../DataView/prototype/setFloat32/browser.js | 0 .../detached-buffer-after-number-value.js | 40 ++ .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/setFloat32/detached-buffer.js | 32 ++ .../index-check-before-value-conversion.js | 43 ++ .../prototype/setFloat32/index-is-out-of-range.js | 91 ++++ .../DataView/prototype/setFloat32/length.js | 32 ++ .../DataView/prototype/setFloat32/name.js | 28 ++ .../setFloat32/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setFloat32/no-value-arg.js | 48 ++ .../prototype/setFloat32/not-a-constructor.js | 35 ++ .../range-check-after-value-conversion.js | 41 ++ .../prototype/setFloat32/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../return-abrupt-from-tonumber-value-symbol.js | 32 ++ .../return-abrupt-from-tonumber-value.js | 45 ++ .../setFloat32/set-values-little-endian-order.js | 53 +++ .../setFloat32/set-values-return-undefined.js | 64 +++ .../DataView/prototype/setFloat32/shell.js | 0 .../setFloat32/this-has-no-dataview-internal.js | 44 ++ .../prototype/setFloat32/this-is-not-object.js | 52 +++ .../setFloat32/to-boolean-littleendian.js | 59 +++ .../prototype/setFloat32/toindex-byteoffset.js | 110 +++++ .../DataView/prototype/setFloat64/browser.js | 0 .../detached-buffer-after-number-value.js | 40 ++ .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/setFloat64/detached-buffer.js | 32 ++ .../index-check-before-value-conversion.js | 44 ++ .../prototype/setFloat64/index-is-out-of-range.js | 106 +++++ .../DataView/prototype/setFloat64/length.js | 32 ++ .../DataView/prototype/setFloat64/name.js | 28 ++ .../setFloat64/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setFloat64/no-value-arg.js | 47 ++ .../prototype/setFloat64/not-a-constructor.js | 35 ++ .../range-check-after-value-conversion.js | 41 ++ .../prototype/setFloat64/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../return-abrupt-from-tonumber-value-symbol.js | 32 ++ .../return-abrupt-from-tonumber-value.js | 45 ++ .../setFloat64/set-values-little-endian-order.js | 51 +++ .../setFloat64/set-values-return-undefined.js | 62 +++ .../DataView/prototype/setFloat64/shell.js | 0 .../setFloat64/this-has-no-dataview-internal.js | 44 ++ .../prototype/setFloat64/this-is-not-object.js | 52 +++ .../setFloat64/to-boolean-littleendian.js | 58 +++ .../prototype/setFloat64/toindex-byteoffset.js | 110 +++++ .../DataView/prototype/setInt16/browser.js | 0 .../setInt16/detached-buffer-after-number-value.js | 40 ++ .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../DataView/prototype/setInt16/detached-buffer.js | 32 ++ .../index-check-before-value-conversion.js | 44 ++ .../prototype/setInt16/index-is-out-of-range.js | 86 ++++ .../DataView/prototype/setInt16/length.js | 32 ++ .../built-ins/DataView/prototype/setInt16/name.js | 28 ++ .../setInt16/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setInt16/no-value-arg.js | 40 ++ .../prototype/setInt16/not-a-constructor.js | 35 ++ .../setInt16/range-check-after-value-conversion.js | 41 ++ .../prototype/setInt16/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../return-abrupt-from-tonumber-value-symbol.js | 32 ++ .../setInt16/return-abrupt-from-tonumber-value.js | 45 ++ .../setInt16/set-values-little-endian-order.js | 59 +++ .../setInt16/set-values-return-undefined.js | 54 +++ .../built-ins/DataView/prototype/setInt16/shell.js | 0 .../setInt16/this-has-no-dataview-internal.js | 44 ++ .../prototype/setInt16/this-is-not-object.js | 52 +++ .../prototype/setInt16/to-boolean-littleendian.js | 48 ++ .../prototype/setInt16/toindex-byteoffset.js | 110 +++++ .../DataView/prototype/setInt32/browser.js | 0 .../setInt32/detached-buffer-after-number-value.js | 40 ++ .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../DataView/prototype/setInt32/detached-buffer.js | 32 ++ .../index-check-before-value-conversion.js | 44 ++ .../prototype/setInt32/index-is-out-of-range.js | 91 ++++ .../DataView/prototype/setInt32/length.js | 32 ++ .../built-ins/DataView/prototype/setInt32/name.js | 28 ++ .../setInt32/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setInt32/no-value-arg.js | 40 ++ .../prototype/setInt32/not-a-constructor.js | 35 ++ .../setInt32/range-check-after-value-conversion.js | 41 ++ .../prototype/setInt32/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../return-abrupt-from-tonumber-value-symbol.js | 32 ++ .../setInt32/return-abrupt-from-tonumber-value.js | 45 ++ .../setInt32/set-values-little-endian-order.js | 59 +++ .../setInt32/set-values-return-undefined.js | 54 +++ .../built-ins/DataView/prototype/setInt32/shell.js | 0 .../setInt32/this-has-no-dataview-internal.js | 44 ++ .../prototype/setInt32/this-is-not-object.js | 52 +++ .../prototype/setInt32/to-boolean-littleendian.js | 48 ++ .../prototype/setInt32/toindex-byteoffset.js | 110 +++++ .../DataView/prototype/setInt8/browser.js | 0 .../setInt8/detached-buffer-after-number-value.js | 39 ++ .../detached-buffer-after-toindex-byteoffset.js | 38 ++ ...detached-buffer-before-outofrange-byteoffset.js | 36 ++ .../DataView/prototype/setInt8/detached-buffer.js | 31 ++ .../setInt8/index-check-before-value-conversion.js | 44 ++ .../prototype/setInt8/index-is-out-of-range.js | 64 +++ .../built-ins/DataView/prototype/setInt8/length.js | 31 ++ .../built-ins/DataView/prototype/setInt8/name.js | 28 ++ .../setInt8/negative-byteoffset-throws.js | 35 ++ .../DataView/prototype/setInt8/no-value-arg.js | 39 ++ .../prototype/setInt8/not-a-constructor.js | 35 ++ .../setInt8/range-check-after-value-conversion.js | 41 ++ .../DataView/prototype/setInt8/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 31 ++ .../return-abrupt-from-tonumber-byteoffset.js | 44 ++ .../return-abrupt-from-tonumber-value-symbol.js | 31 ++ .../setInt8/return-abrupt-from-tonumber-value.js | 44 ++ .../setInt8/set-values-return-undefined.js | 53 +++ .../built-ins/DataView/prototype/setInt8/shell.js | 0 .../setInt8/this-has-no-dataview-internal.js | 43 ++ .../prototype/setInt8/this-is-not-object.js | 51 +++ .../prototype/setInt8/toindex-byteoffset.js | 109 +++++ .../DataView/prototype/setUint16/browser.js | 0 .../detached-buffer-after-number-value.js | 40 ++ .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/setUint16/detached-buffer.js | 32 ++ .../index-check-before-value-conversion.js | 44 ++ .../prototype/setUint16/index-is-out-of-range.js | 86 ++++ .../DataView/prototype/setUint16/length.js | 32 ++ .../built-ins/DataView/prototype/setUint16/name.js | 28 ++ .../setUint16/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setUint16/no-value-arg.js | 40 ++ .../prototype/setUint16/not-a-constructor.js | 35 ++ .../range-check-after-value-conversion.js | 41 ++ .../prototype/setUint16/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../return-abrupt-from-tonumber-value-symbol.js | 32 ++ .../setUint16/return-abrupt-from-tonumber-value.js | 45 ++ .../setUint16/set-values-little-endian-order.js | 59 +++ .../setUint16/set-values-return-undefined.js | 54 +++ .../DataView/prototype/setUint16/shell.js | 0 .../setUint16/this-has-no-dataview-internal.js | 44 ++ .../prototype/setUint16/this-is-not-object.js | 52 +++ .../prototype/setUint16/to-boolean-littleendian.js | 48 ++ .../prototype/setUint16/toindex-byteoffset.js | 110 +++++ .../DataView/prototype/setUint32/browser.js | 0 .../detached-buffer-after-number-value.js | 40 ++ .../detached-buffer-after-toindex-byteoffset.js | 39 ++ ...detached-buffer-before-outofrange-byteoffset.js | 37 ++ .../prototype/setUint32/detached-buffer.js | 32 ++ .../index-check-before-value-conversion.js | 44 ++ .../prototype/setUint32/index-is-out-of-range.js | 91 ++++ .../DataView/prototype/setUint32/length.js | 32 ++ .../built-ins/DataView/prototype/setUint32/name.js | 28 ++ .../setUint32/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setUint32/no-value-arg.js | 40 ++ .../prototype/setUint32/not-a-constructor.js | 35 ++ .../range-check-after-value-conversion.js | 41 ++ .../prototype/setUint32/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 32 ++ .../return-abrupt-from-tonumber-byteoffset.js | 45 ++ .../return-abrupt-from-tonumber-value-symbol.js | 32 ++ .../setUint32/return-abrupt-from-tonumber-value.js | 45 ++ .../setUint32/set-values-little-endian-order.js | 59 +++ .../setUint32/set-values-return-undefined.js | 54 +++ .../DataView/prototype/setUint32/shell.js | 0 .../setUint32/this-has-no-dataview-internal.js | 44 ++ .../prototype/setUint32/this-is-not-object.js | 52 +++ .../prototype/setUint32/to-boolean-littleendian.js | 48 ++ .../prototype/setUint32/toindex-byteoffset.js | 110 +++++ .../DataView/prototype/setUint8/browser.js | 0 .../setUint8/detached-buffer-after-number-value.js | 39 ++ .../detached-buffer-after-toindex-byteoffset.js | 38 ++ ...detached-buffer-before-outofrange-byteoffset.js | 36 ++ .../DataView/prototype/setUint8/detached-buffer.js | 31 ++ .../index-check-before-value-conversion.js | 44 ++ .../prototype/setUint8/index-is-out-of-range.js | 64 +++ .../DataView/prototype/setUint8/length.js | 31 ++ .../built-ins/DataView/prototype/setUint8/name.js | 28 ++ .../setUint8/negative-byteoffset-throws.js | 36 ++ .../DataView/prototype/setUint8/no-value-arg.js | 40 ++ .../prototype/setUint8/not-a-constructor.js | 35 ++ .../setUint8/range-check-after-value-conversion.js | 41 ++ .../prototype/setUint8/resizable-buffer.js | 44 ++ ...eturn-abrupt-from-tonumber-byteoffset-symbol.js | 31 ++ .../return-abrupt-from-tonumber-byteoffset.js | 44 ++ .../return-abrupt-from-tonumber-value-symbol.js | 31 ++ .../setUint8/return-abrupt-from-tonumber-value.js | 44 ++ .../setUint8/set-values-return-undefined.js | 54 +++ .../built-ins/DataView/prototype/setUint8/shell.js | 0 .../setUint8/this-has-no-dataview-internal.js | 43 ++ .../prototype/setUint8/this-is-not-object.js | 51 +++ .../prototype/setUint8/toindex-byteoffset.js | 110 +++++ .../test262/built-ins/DataView/prototype/shell.js | 0 .../return-abrupt-tonumber-bytelength-sab.js | 44 ++ ...return-abrupt-tonumber-bytelength-symbol-sab.js | 29 ++ .../return-abrupt-tonumber-bytelength-symbol.js | 27 ++ .../DataView/return-abrupt-tonumber-bytelength.js | 41 ++ .../return-abrupt-tonumber-byteoffset-sab.js | 31 ++ ...return-abrupt-tonumber-byteoffset-symbol-sab.js | 26 ++ .../return-abrupt-tonumber-byteoffset-symbol.js | 24 + .../DataView/return-abrupt-tonumber-byteoffset.js | 28 ++ .../built-ins/DataView/return-instance-sab.js | 33 ++ .../test262/built-ins/DataView/return-instance.js | 30 ++ js/src/tests/test262/built-ins/DataView/shell.js | 490 +++++++++++++++++++++ .../built-ins/DataView/toindex-bytelength-sab.js | 98 +++++ .../built-ins/DataView/toindex-bytelength.js | 95 ++++ .../built-ins/DataView/toindex-byteoffset-sab.js | 96 ++++ .../built-ins/DataView/toindex-byteoffset.js | 93 ++++ 555 files changed, 22892 insertions(+) create mode 100644 js/src/tests/test262/built-ins/DataView/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/buffer-not-object-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/buffer-reference-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/buffer-reference.js create mode 100644 js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-detaches-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-length.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-length.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-access-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used.js create mode 100644 js/src/tests/test262/built-ins/DataView/dataview.js create mode 100644 js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/defined-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength.js create mode 100644 js/src/tests/test262/built-ins/DataView/defined-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/extensibility.js create mode 100644 js/src/tests/test262/built-ins/DataView/instance-extensibility-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/instance-extensibility.js create mode 100644 js/src/tests/test262/built-ins/DataView/is-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/negative-bytelength-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/negative-bytelength-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm.js create mode 100644 js/src/tests/test262/built-ins/DataView/proto.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/Symbol.toStringTag.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-accessor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-func.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/buffer/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/instance-has-detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-accessor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-func.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-func.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-errors.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-toprimitive.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-wrapped-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/minus-zero.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-infinity.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-nan.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat32/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/minus-zero.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-infinity.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-nan.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getFloat64/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt16/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getInt8/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint16/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint32/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-value-clean-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values-custom-offset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/getUint8/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat32/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setFloat64/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt16/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt32/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setInt8/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint16/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-little-endian-order.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/to-boolean-littleendian.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint32/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/browser.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-number-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-before-outofrange-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-check-before-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-is-out-of-range.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/length.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/name.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/negative-byteoffset-throws.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/no-value-arg.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/range-check-after-value-conversion.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/resizable-buffer.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/set-values-return-undefined.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-has-no-dataview-internal.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/setUint8/toindex-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/prototype/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-instance-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/return-instance.js create mode 100644 js/src/tests/test262/built-ins/DataView/shell.js create mode 100644 js/src/tests/test262/built-ins/DataView/toindex-bytelength-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/toindex-bytelength.js create mode 100644 js/src/tests/test262/built-ins/DataView/toindex-byteoffset-sab.js create mode 100644 js/src/tests/test262/built-ins/DataView/toindex-byteoffset.js (limited to 'js/src/tests/test262/built-ins/DataView') diff --git a/js/src/tests/test262/built-ins/DataView/browser.js b/js/src/tests/test262/built-ins/DataView/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js b/js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js new file mode 100644 index 0000000000..dbabc36b7e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js @@ -0,0 +1,45 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer does not have [[ArrayBufferData]] +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 2. If Type(buffer) is not Object, throw a TypeError exception. + 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a + TypeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("buffer should be verified before byteOffset"); + } +}; + +assert.throws(TypeError, function() { + new DataView({}, obj); +}, "{}"); + +assert.throws(TypeError, function() { + new DataView([], obj); +}, "[]"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + new DataView(ta, obj); +}, "typedArray instance"); + +var other = new DataView(new SharedArrayBuffer(1), 0); +assert.throws(TypeError, function() { + new DataView(other, obj); +}, "dataView instance"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.js b/js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.js new file mode 100644 index 0000000000..ef2b0a2cb1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer does not have [[ArrayBufferData]] +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 2. If Type(buffer) is not Object, throw a TypeError exception. + 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a + TypeError exception. + ... +features: [Int8Array] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("buffer should be verified before byteOffset"); + } +}; + +assert.throws(TypeError, function() { + new DataView({}, obj); +}, "{}"); + +assert.throws(TypeError, function() { + new DataView([], obj); +}, "[]"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + new DataView(ta, obj); +}, "typedArray instance"); + +var other = new DataView(new ArrayBuffer(1), 0); +assert.throws(TypeError, function() { + new DataView(other, obj); +}, "dataView instance"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/buffer-not-object-throws.js b/js/src/tests/test262/built-ins/DataView/buffer-not-object-throws.js new file mode 100644 index 0000000000..4c4bfcabfa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/buffer-not-object-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer is not Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. If Type(buffer) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("buffer should be verified before byteOffset"); + } +}; + +assert.throws(TypeError, function() { + new DataView(0, obj); +}, "0"); + +assert.throws(TypeError, function() { + new DataView(1, obj); +}, "1"); + +assert.throws(TypeError, function() { + new DataView("", obj); +}, "the empty string"); + +assert.throws(TypeError, function() { + new DataView("buffer", obj); +}, "string"); + +assert.throws(TypeError, function() { + new DataView(false, obj); +}, "false"); + +assert.throws(TypeError, function() { + new DataView(true, obj); +}, "true"); + +assert.throws(TypeError, function() { + new DataView(NaN, obj); +}, "NaN"); + +assert.throws(TypeError, function() { + new DataView(Symbol("1"), obj); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/buffer-reference-sab.js b/js/src/tests/test262/built-ins/DataView/buffer-reference-sab.js new file mode 100644 index 0000000000..7670ef27af --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/buffer-reference-sab.js @@ -0,0 +1,28 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Reuse buffer argument instead of making a new clone +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 14. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var dv1 = new DataView(buffer, 0); +var dv2 = new DataView(buffer, 0); + +assert.sameValue(dv1.buffer, buffer); +assert.sameValue(dv2.buffer, buffer); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/buffer-reference.js b/js/src/tests/test262/built-ins/DataView/buffer-reference.js new file mode 100644 index 0000000000..bc519b1da1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/buffer-reference.js @@ -0,0 +1,25 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + Reuse buffer argument instead of making a new clone +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 14. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... + 17. Return O. +---*/ + +var buffer = new ArrayBuffer(8); + +var dv1 = new DataView(buffer, 0); +var dv2 = new DataView(buffer, 0); + +assert.sameValue(dv1.buffer, buffer); +assert.sameValue(dv2.buffer, buffer); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws-sab.js b/js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws-sab.js new file mode 100644 index 0000000000..e034814868 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws-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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + 5. Let offset be ToInteger(numberOffset). + 6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var ab = new SharedArrayBuffer(42); + +assert.throws(RangeError, function() { + new DataView(ab, -1); +}, "-1"); + +assert.throws(RangeError, function() { + new DataView(ab, -Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws.js b/js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..a09cac8a7b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/byteoffset-is-negative-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + 5. Let offset be ToInteger(numberOffset). + 6. If numberOffset ≠ offset or offset < 0, throw a RangeError exception. + ... +---*/ + +var ab = new ArrayBuffer(42); + +assert.throws(RangeError, function() { + new DataView(ab, -1); +}, "-1"); + +assert.throws(RangeError, function() { + new DataView(ab, -Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/constructor.js b/js/src/tests/test262/built-ins/DataView/constructor.js new file mode 100644 index 0000000000..ee988da5c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/constructor.js @@ -0,0 +1,13 @@ +// 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-dataview-constructor +description: > + The DataView constructor is the %DataView% intrinsic object and the initial + value of the DataView property of the global object. +---*/ + +assert.sameValue(typeof DataView, "function", "`typeof DataView` is `'function'`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-detaches-buffer.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-detaches-buffer.js new file mode 100644 index 0000000000..cbd0628a9f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-detaches-buffer.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Jeff Walden +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + The `DataView` constructor shouldn't be able to return a `DataView` instance + backed by a detached `ArrayBuffer` when `OrdinaryCreateFromConstructor` + returns an instance so backed. +info: | + `OrdinaryCreateFromConstructor` has the potential to invoke user-defined code + that may detach the `ArrayBuffer` intended to underlie the fresh instance. + Verify that a final is-detached check is performed before the new instance is + returned. +includes: [detachArrayBuffer.js] +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +var called = false; +var byteOffset = { valueOf() { called = true; return 0; } }; + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + $DETACHBUFFER(buffer); + return DataView.prototype; + } +}); + +assert.throws(TypeError, function() { + Reflect.construct(DataView, [buffer, byteOffset], newTarget); +}); +assert.sameValue(called, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-length.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-length.js new file mode 100644 index 0000000000..7626720d2a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-length.js @@ -0,0 +1,43 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview-buffer-byteoffset-bytelength +description: > + The sum of the view's offset and byte length cannot exceed the underlying + buffer's byte length if it is modified during retrieval of the NewTarget's + prototype. +features: [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'); + +var buffer = new ArrayBuffer(3, {maxByteLength: 3}); +var expectedError; + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + try { + buffer.resize(2); + expectedError = RangeError; + } catch (error) { + expectedError = null; + } + } +}); +var error = null; + +try { + Reflect.construct(DataView, [buffer, 1, 2], newTarget); +} catch (caught) { + error = caught.constructor; +} + +assert.sameValue(error, expectedError); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-offset.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-offset.js new file mode 100644 index 0000000000..63cb6a2ef1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-invalid-by-offset.js @@ -0,0 +1,42 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview-buffer-byteoffset-bytelength +description: > + The view's offset cannot exceed the underlying buffer's byte length if it is + modified during retrieval of the NewTarget's prototype. +features: [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'); + +var buffer = new ArrayBuffer(3, {maxByteLength: 3}); +var expectedError; + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + try { + buffer.resize(1); + expectedError = RangeError; + } catch (error) { + expectedError = null; + } + } +}); +var error = null; + +try { + Reflect.construct(DataView, [buffer, 2], newTarget); +} catch (caught) { + error = caught.constructor; +} + +assert.sameValue(error, expectedError); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-length.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-length.js new file mode 100644 index 0000000000..3aacc841b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-length.js @@ -0,0 +1,35 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview-buffer-byteoffset-bytelength +description: > + The sum of the view's offset and byte length may equal the underlying + buffer's byte length if it is modified during retrieval of the NewTarget's + prototype. +features: [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'); + +var buffer = new ArrayBuffer(3, {maxByteLength: 3}); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + try { + buffer.resize(2); + } catch (error) {} + } +}); + +var result = Reflect.construct(DataView, [buffer, 1, 1], newTarget); + +assert.sameValue(result.constructor, DataView); +assert.sameValue(result.byteLength, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-offset.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-offset.js new file mode 100644 index 0000000000..ba6b7e9eaa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-resizes-buffer-valid-by-offset.js @@ -0,0 +1,38 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview-buffer-byteoffset-bytelength +description: > + The view's offset may equal the underlying buffer's byte length if it is + modified during retrieval of the NewTarget's prototype. +features: [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'); + +var buffer = new ArrayBuffer(3, {maxByteLength: 3}); +var expectedByteLength; + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, 'prototype', { + get: function() { + try { + buffer.resize(2); + expectedByteLength = 0; + } catch (error) { + expectedByteLength = 1; + } + } +}); + +var result = Reflect.construct(DataView, [buffer, 2], newTarget); + +assert.sameValue(result.constructor, DataView); +assert.sameValue(result.byteLength, expectedByteLength); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-throws-sab.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-throws-sab.js new file mode 100644 index 0000000000..9fc65a863f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-throws-sab.js @@ -0,0 +1,48 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from newTarget's custom constructor prototype +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect.construct, SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(DataView, [buffer, 0], newTarget); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/DataView/custom-proto-access-throws.js new file mode 100644 index 0000000000..b7ca8fb3b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-access-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from newTarget's custom constructor prototype +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(DataView, [buffer, 0], newTarget); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js b/js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js new file mode 100644 index 0000000000..0e7f424abf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js @@ -0,0 +1,49 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Use DataView.prototype if newTarget's prototype is not an Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct, SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.js b/js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.js new file mode 100644 index 0000000000..7c4d0530ec --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype.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-dataview-buffer-byteoffset-bytelength +description: > + Use DataView.prototype if newTarget's prototype is not an Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used-sab.js b/js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used-sab.js new file mode 100644 index 0000000000..ab9dc12ab5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used-sab.js @@ -0,0 +1,50 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Use newTarget's custom constructor prototype if Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct, SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, Object); +assert.sameValue(Object.getPrototypeOf(sample), proto); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used.js b/js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used.js new file mode 100644 index 0000000000..89fc8552cc --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/custom-proto-if-object-is-used.js @@ -0,0 +1,48 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + Use newTarget's custom constructor prototype if Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, Object); +assert.sameValue(Object.getPrototypeOf(sample), proto); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/dataview.js b/js/src/tests/test262/built-ins/DataView/dataview.js new file mode 100644 index 0000000000..24f1529052 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/dataview.js @@ -0,0 +1,15 @@ +// 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-dataview-constructor +description: > + The DataView Constructor +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, "DataView"); +verifyWritable(this, "DataView"); +verifyConfigurable(this, "DataView"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js new file mode 100644 index 0000000000..833c07b57e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js @@ -0,0 +1,63 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined length and offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(3); + +sample = new DataView(buffer, 1, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 3); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 1); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset.js b/js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset.js new file mode 100644 index 0000000000..a1a7edb7f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/defined-bytelength-and-byteoffset.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-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined length and offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(3); + +sample = new DataView(buffer, 1, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 3); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 1); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/defined-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/defined-byteoffset-sab.js new file mode 100644 index 0000000000..bc4feb3f16 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/defined-byteoffset-sab.js @@ -0,0 +1,56 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(4); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js b/js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js new file mode 100644 index 0000000000..7bde26ef05 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js @@ -0,0 +1,59 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined byteoffset and undefined bytelength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(4); + +sample = new DataView(buffer, 0, undefined); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, undefined); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2, undefined); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, undefined); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4, undefined); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength.js b/js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength.js new file mode 100644 index 0000000000..af63fed1da --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/defined-byteoffset-undefined-bytelength.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-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined byteoffset and undefined bytelength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(4); + +sample = new DataView(buffer, 0, undefined); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, undefined); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2, undefined); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, undefined); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4, undefined); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/defined-byteoffset.js b/js/src/tests/test262/built-ins/DataView/defined-byteoffset.js new file mode 100644 index 0000000000..afb7eb5243 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/defined-byteoffset.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-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +---*/ + +var sample; +var buffer = new ArrayBuffer(4); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/detached-buffer.js new file mode 100644 index 0000000000..c3145a849a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/detached-buffer.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var toNumberOffset = 0; +var obj = { + valueOf: function() { + toNumberOffset += 1; + return 0; + } +}; + +var ab = new ArrayBuffer(42); +$DETACHBUFFER(ab); + +assert.throws(TypeError, function() { + new DataView(ab, obj); +}, "throws if buffer is detached"); + +assert.sameValue(toNumberOffset, 1, "ToNumber(byteOffset) runs before"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws-sab.js b/js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws-sab.js new file mode 100644 index 0000000000..02a82ac4ff --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws-sab.js @@ -0,0 +1,58 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Throws RangeError if offset + viewByteLength > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + ... + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + b. If offset+viewByteLength > bufferByteLength, throw a RangeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(3); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, 4); +}, "offset: 0, length 4"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, 3); +}, "offset: 1, length: 3"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, 2); +}, "offset: 2, length: 2"); + +assert.throws(RangeError, function() { + new DataView(buffer, 3, 1); +}, "offset: 3, length: 1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, 0); +}, "offset: 4, length: 0"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -1); +}, "offset: 4, length: -1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -Infinity); +}, "offset: 4, length: -Infinity"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, Infinity); +}, "offset: 0, length: Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws.js b/js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws.js new file mode 100644 index 0000000000..60aaf4e948 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/excessive-bytelength-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws RangeError if offset + viewByteLength > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + ... + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + b. If offset+viewByteLength > bufferByteLength, throw a RangeError + exception. + ... +---*/ + +var buffer = new ArrayBuffer(3); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, 4); +}, "offset: 0, length 4"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, 3); +}, "offset: 1, length: 3"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, 2); +}, "offset: 2, length: 2"); + +assert.throws(RangeError, function() { + new DataView(buffer, 3, 1); +}, "offset: 3, length: 1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, 0); +}, "offset: 4, length: 0"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -1); +}, "offset: 4, length: -1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -Infinity); +}, "offset: 4, length: -Infinity"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, Infinity); +}, "offset: 0, length: Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws-sab.js b/js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws-sab.js new file mode 100644 index 0000000000..9cba155986 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws-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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if offset > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]] + internal slot. + 9. If offset > bufferByteLength, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var ab = new SharedArrayBuffer(1); + +assert.throws(RangeError, function() { + new DataView(ab, 2); +}, "2"); + +assert.throws(RangeError, function() { + new DataView(ab, Infinity); +}, "Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws.js new file mode 100644 index 0000000000..6e16e3fd6e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/excessive-byteoffset-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if offset > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]] + internal slot. + 9. If offset > bufferByteLength, throw a RangeError exception. + ... +---*/ + +var ab = new ArrayBuffer(1); + +assert.throws(RangeError, function() { + new DataView(ab, 2); +}, "2"); + +assert.throws(RangeError, function() { + new DataView(ab, Infinity); +}, "Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/extensibility.js b/js/src/tests/test262/built-ins/DataView/extensibility.js new file mode 100644 index 0000000000..68a11f58f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/extensibility.js @@ -0,0 +1,17 @@ +// 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-dataview-constructor +description: > + The DataView constructor is extensible +info: | + 17 ECMAScript Standard Built-in Objects + + Unless specified otherwise, the [[Extensible]] internal slot of a built-in + object initially has the value true. +---*/ + +assert.sameValue(Object.isExtensible(DataView), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/instance-extensibility-sab.js b/js/src/tests/test262/built-ins/DataView/instance-extensibility-sab.js new file mode 100644 index 0000000000..93db146895 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/instance-extensibility-sab.js @@ -0,0 +1,56 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + The new instance is extensible +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.12 ObjectCreate (proto [ , internalSlotsList ]) + + ... + 5. Set the [[Extensible]] internal slot of obj to true. + ... +features: [SharedArrayBuffer] +includes: [propertyHelper.js] +---*/ + +var buffer = new SharedArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert(Object.isExtensible(sample)); + +Object.defineProperty(sample, 'baz', {}); +assert(sample.hasOwnProperty('baz'), 'confirms extensibility adding a new property'); + +Object.defineProperty(sample, 'foo', { + value: 'bar', + writable: true, + configurable: true, + enumerable: false, +}); + +verifyProperty(sample, 'foo', { + value: 'bar', + writable: true, + configurable: true, + enumerable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/instance-extensibility.js b/js/src/tests/test262/built-ins/DataView/instance-extensibility.js new file mode 100644 index 0000000000..5c6f0b9486 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/instance-extensibility.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-dataview-buffer-byteoffset-bytelength +description: > + The new instance is extensible +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.12 ObjectCreate (proto [ , internalSlotsList ]) + + ... + 5. Set the [[Extensible]] internal slot of obj to true. + ... +includes: [propertyHelper.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert(Object.isExtensible(sample)); + +Object.defineProperty(sample, 'baz', {}); +assert(sample.hasOwnProperty('baz'), 'confirms extensibility adding a new property'); + +Object.defineProperty(sample, 'foo', { + value: 'bar', + writable: true, + configurable: true, + enumerable: false, +}); + +verifyProperty(sample, 'foo', { + value: 'bar', + writable: true, + configurable: true, + enumerable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/is-a-constructor.js b/js/src/tests/test262/built-ins/DataView/is-a-constructor.js new file mode 100644 index 0000000000..ecb887b65b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The DataView constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, DataView, ArrayBuffer] +---*/ + +assert.sameValue(isConstructor(DataView), true, 'isConstructor(DataView) must return true'); +new DataView(new ArrayBuffer(16)); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/length.js b/js/src/tests/test262/built-ins/DataView/length.js new file mode 100644 index 0000000000..c75e4916ab --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/length.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-dataview-constructor +description: > + The length property of DataView has the default value of 1 +info: | + DataView ( buffer [ , byteOffset [ , byteLength ] ] ) + + ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [DataView] +---*/ + +verifyProperty(DataView, "length", { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/name.js b/js/src/tests/test262/built-ins/DataView/name.js new file mode 100644 index 0000000000..2b1e1c74bd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/name.js @@ -0,0 +1,17 @@ +// 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-dataview-constructor +description: > + The name property of DataView is "DataView" +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.name, "DataView", "The value of `DataView.name` is `'DataView'`"); + +verifyNotEnumerable(DataView, "name"); +verifyNotWritable(DataView, "name"); +verifyConfigurable(DataView, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/negative-bytelength-throws-sab.js b/js/src/tests/test262/built-ins/DataView/negative-bytelength-throws-sab.js new file mode 100644 index 0000000000..67494e3c73 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/negative-bytelength-throws-sab.js @@ -0,0 +1,49 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteLength) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 9. Else, + a. Let viewByteLength be ? ToIndex(byteLength). + ... + + ToIndex ( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(2); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, -1); +}, "new DataView(buffer, 0, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, -Infinity); +}, "new DataView(buffer, 0, -Infinity);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, -1); +}, "new DataView(buffer, 1, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, -Infinity); +}, "new DataView(buffer, 2, -Infinity);"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/negative-bytelength-throws.js b/js/src/tests/test262/built-ins/DataView/negative-bytelength-throws.js new file mode 100644 index 0000000000..f5722562a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/negative-bytelength-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteLength) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 9. Else, + a. Let viewByteLength be ? ToIndex(byteLength). + ... + + ToIndex ( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +---*/ + +var buffer = new ArrayBuffer(2); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, -1); +}, "new DataView(buffer, 0, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, -Infinity); +}, "new DataView(buffer, 0, -Infinity);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, -1); +}, "new DataView(buffer, 1, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, -Infinity); +}, "new DataView(buffer, 2, -Infinity);"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws-sab.js b/js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws-sab.js new file mode 100644 index 0000000000..90281fde24 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws-sab.js @@ -0,0 +1,38 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let offset be ? ToIndex(byteOffset). + ... + + ToIndex ( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(2); + +assert.throws(RangeError, function() { + new DataView(buffer, -1); +}, "new DataView(buffer, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, -Infinity); +}, "new DataView(buffer, -Infinity);"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws.js new file mode 100644 index 0000000000..a55acae04c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/negative-byteoffset-throws.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-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let offset be ? ToIndex(byteOffset). + ... + + ToIndex ( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +---*/ + +var buffer = new ArrayBuffer(2); + +assert.throws(RangeError, function() { + new DataView(buffer, -1); +}, "new DataView(buffer, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, -Infinity); +}, "new DataView(buffer, -Infinity);"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws-sab.js b/js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws-sab.js new file mode 100644 index 0000000000..13bd57512b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws-sab.js @@ -0,0 +1,30 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("NewTarget should be verified before byteOffset"); + } +}; + +var buffer = new SharedArrayBuffer(1); + +assert.throws(TypeError, function() { + DataView(buffer, obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws.js b/js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws.js new file mode 100644 index 0000000000..21df2b8ab2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/newtarget-undefined-throws.js @@ -0,0 +1,27 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("NewTarget should be verified before byteOffset"); + } +}; + +var buffer = new ArrayBuffer(1); + +assert.throws(TypeError, function() { + DataView(buffer, obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm-sab.js b/js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm-sab.js new file mode 100644 index 0000000000..e8a412bd41 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm-sab.js @@ -0,0 +1,35 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, + "%DataViewPrototype%", « [[DataView]], [[ViewedArrayBuffer]], + [[ByteLength]], [[ByteOffset]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect, SharedArrayBuffer] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; +var buffer = new SharedArrayBuffer(0); + +var o = Reflect.construct(DataView, [buffer, 0], C); + +assert.sameValue(Object.getPrototypeOf(o), other.DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/DataView/proto-from-ctor-realm.js new file mode 100644 index 0000000000..6b9aff4a1f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/proto-from-ctor-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-dataview-buffer-byteoffset-bytelength +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, + "%DataViewPrototype%", « [[DataView]], [[ViewedArrayBuffer]], + [[ByteLength]], [[ByteOffset]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; +var buffer = new ArrayBuffer(0); + +var o = Reflect.construct(DataView, [buffer, 0], C); + +assert.sameValue(Object.getPrototypeOf(o), other.DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/proto.js b/js/src/tests/test262/built-ins/DataView/proto.js new file mode 100644 index 0000000000..d04d7077c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/proto.js @@ -0,0 +1,15 @@ +// 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-properties-of-the-dataview-constructor +description: > + The prototype of DataView is Function.prototype +info: | + The value of the [[Prototype]] internal slot of the DataView constructor is + the intrinsic object %FunctionPrototype%. +---*/ + +assert.sameValue(Object.getPrototypeOf(DataView), Function.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype.js b/js/src/tests/test262/built-ins/DataView/prototype.js new file mode 100644 index 0000000000..0728190dd6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype.js @@ -0,0 +1,21 @@ +// 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-dataview.prototype +description: > + The initial value of DataView.prototype is the DataView prototype object. +info: | + The initial value of DataView.prototype is the intrinsic object + %DataViewPrototype%. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(DataView, "prototype"); +verifyNotWritable(DataView, "prototype"); +verifyNotConfigurable(DataView, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/DataView/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..a6787061c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/Symbol.toStringTag.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-dataview.prototype-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "DataView". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue( + DataView.prototype[Symbol.toStringTag], + 'DataView', + 'The value of DataView.prototype[Symbol.toStringTag] is expected to be "DataView"' +); + +verifyNotEnumerable(DataView.prototype, Symbol.toStringTag); +verifyNotWritable(DataView.prototype, Symbol.toStringTag); +verifyConfigurable(DataView.prototype, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/detached-buffer.js new file mode 100644 index 0000000000..7b7466cc96 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/detached-buffer.js @@ -0,0 +1,22 @@ +// 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-get-dataview.prototype.buffer +description: The getter method does not throw with a detached buffer +info: | + 24.2.4.1 get DataView.prototype.buffer + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. Return buffer. +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(sample.buffer); +assert.sameValue(sample.buffer, buffer); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-accessor.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-accessor.js new file mode 100644 index 0000000000..555cf82f0a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-accessor.js @@ -0,0 +1,22 @@ +// 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-get-dataview.prototype.buffer +description: > + Requires this value to have a [[DataView]] internal slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + DataView.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-func.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-func.js new file mode 100644 index 0000000000..93a8692842 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/invoked-as-func.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.buffer +description: Throws a TypeError exception when invoked as a function +info: | + 24.2.4.1 get DataView.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, 'buffer' +).get; + +assert.throws(TypeError, function() { + getter(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/length.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/length.js new file mode 100644 index 0000000000..826ab9e259 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.buffer +description: > + get DataView.prototype.buffer.length is 0. +info: | + get DataView.prototype.buffer + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "buffer"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/name.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/name.js new file mode 100644 index 0000000000..6721b00274 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.buffer +description: > + get DataView.prototype.buffer + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor( + DataView.prototype, 'buffer' +); + +assert.sameValue( + descriptor.get.name, 'get buffer', + 'The value of `descriptor.get.name` is `"get buffer"`' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/prop-desc.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/prop-desc.js new file mode 100644 index 0000000000..37933bcb74 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/prop-desc.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.buffer +description: > + "buffer" property of DataView.prototype +info: | + DataView.prototype.buffer is an accessor property whose set accessor function + is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "buffer"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(DataView.prototype, "buffer"); +verifyConfigurable(DataView.prototype, "buffer"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer-sab.js new file mode 100644 index 0000000000..b6f207d781 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer-sab.js @@ -0,0 +1,24 @@ +// |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-get-dataview.prototype.buffer +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. Return buffer. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(1); +var dv = new DataView(buffer, 0); + +assert.sameValue(dv.buffer, buffer); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer.js new file mode 100644 index 0000000000..d11a590e5e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/return-buffer.js @@ -0,0 +1,21 @@ +// 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-get-dataview.prototype.buffer +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. Return buffer. +---*/ + +var buffer = new ArrayBuffer(1); +var dv = new DataView(buffer, 0); + +assert.sameValue(dv.buffer, buffer); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000..fde409511f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js @@ -0,0 +1,44 @@ +// |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-get-dataview.prototype.buffer +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..8aada64dda --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal.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-get-dataview.prototype.buffer +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-is-not-object.js new file mode 100644 index 0000000000..a8c917afc5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/buffer/this-is-not-object.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-get-dataview.prototype.buffer +description: Throws a TypeError exception when `this` is not Object +info: | + 24.2.4.1 get DataView.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/detached-buffer.js new file mode 100644 index 0000000000..33497518f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/detached-buffer.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.bytelength +description: Throws a TypeError if the instance has a detached buffer +info: | + get DataView.prototype.byteLength + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +let buffer = new ArrayBuffer(1); +let dv = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, () => { + dv.byteLength; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/instance-has-detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/instance-has-detached-buffer.js new file mode 100644 index 0000000000..bbb7598bc4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/instance-has-detached-buffer.js @@ -0,0 +1,25 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.bytelength +description: Throws a TypeError if the instance has a detached buffer +info: | + get DataView.prototype.byteLength + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +let buffer = new ArrayBuffer(1); +let dv = new DataView(buffer, 0); + +$DETACHBUFFER(dv.buffer); + +assert.throws(TypeError, () => { + dv.byteLength; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-accessor.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-accessor.js new file mode 100644 index 0000000000..b5b9074ac9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-accessor.js @@ -0,0 +1,22 @@ +// 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-get-dataview.prototype.bytelength +description: > + Requires this value to have a [[DataView]] internal slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + DataView.prototype.byteLength; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-func.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-func.js new file mode 100644 index 0000000000..48a1fe88d5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/invoked-as-func.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.bytelength +description: Throws a TypeError exception when invoked as a function +info: | + 24.2.4.2 get DataView.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, 'byteLength' +).get; + +assert.throws(TypeError, function() { + getter(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/length.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/length.js new file mode 100644 index 0000000000..85dd54adcf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.bytelength +description: > + get DataView.prototype.byteLength.length is 0. +info: | + get DataView.prototype.byteLength + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/name.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/name.js new file mode 100644 index 0000000000..b437bd7173 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.bytelength +description: > + get DataView.prototype.byteLength + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor( + DataView.prototype, 'byteLength' +); + +assert.sameValue( + descriptor.get.name, 'get byteLength', + 'The value of `descriptor.get.name` is `"get byteLength"`' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/prop-desc.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/prop-desc.js new file mode 100644 index 0000000000..f125e9f409 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/prop-desc.js @@ -0,0 +1,27 @@ +// 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-get-dataview.prototype.bytelength +description: > + "byteLength" property of DataView.prototype +info: | + 24.2.4.2 get DataView.prototype.byteLength + + DataView.prototype.byteLength is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(DataView.prototype, "byteLength"); +verifyConfigurable(DataView.prototype, "byteLength"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js new file mode 100644 index 0000000000..6ff801c6ef --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-auto.js @@ -0,0 +1,57 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-get-dataview.prototype.bytelength +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the dynamically-sized DataView instance +features: [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"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1); +var expected = 3; + +assert.sameValue(dataView.byteLength, expected); + +try { + ab.resize(5); + expected = 4; +} catch (_) {} + +assert.sameValue(dataView.byteLength, expected, "following grow"); + +try { + ab.resize(3); + expected = 2; +} catch (_) {} + +assert.sameValue(dataView.byteLength, expected, "following shrink (within bounds)"); + +try { + ab.resize(1); + expected = 0; +} catch (_) {} + +assert.sameValue(dataView.byteLength, expected, "following shrink (on boundary)"); + +try { + ab.resize(0); + expected = TypeError; +} catch (_) { + expected = Test262Error; +} + +assert.throws(expected, function() { + dataView.byteLength; + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..8b04f69af5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/resizable-array-buffer-fixed.js @@ -0,0 +1,48 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-get-dataview.prototype.bytelength +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the fixed-sized DataView instance +features: [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"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1, 2); + +assert.sameValue(dataView.byteLength, 2); + +try { + ab.resize(5); +} catch (_) {} + +assert.sameValue(dataView.byteLength, 2, "following grow"); + +try { + ab.resize(3); +} catch (_) {} + +assert.sameValue(dataView.byteLength, 2, "following shrink (within bounds)"); + +var expectedError; +try { + ab.resize(2); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + dataView.byteLength; + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength-sab.js new file mode 100644 index 0000000000..64f0ac4cba --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength-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-get-dataview.prototype.bytelength +description: > + Return value from [[ByteLength]] internal slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + ... + 7. Let size be the value of O's [[ByteLength]] internal slot. + 8. Return size. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); + +assert.sameValue(sample1.byteLength, 12); +assert.sameValue(sample2.byteLength, 8); +assert.sameValue(sample3.byteLength, 4); +assert.sameValue(sample4.byteLength, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength.js new file mode 100644 index 0000000000..91bee75b51 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/return-bytelength.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-get-dataview.prototype.bytelength +description: > + Return value from [[ByteLength]] internal slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + ... + 7. Let size be the value of O's [[ByteLength]] internal slot. + 8. Return size. +---*/ + +var buffer = new ArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); + +assert.sameValue(sample1.byteLength, 12); +assert.sameValue(sample2.byteLength, 8); +assert.sameValue(sample3.byteLength, 4); +assert.sameValue(sample4.byteLength, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000..57b138db7a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js @@ -0,0 +1,44 @@ +// |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-get-dataview.prototype.bytelength +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..6d9c243c79 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal.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-get-dataview.prototype.bytelength +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-is-not-object.js new file mode 100644 index 0000000000..b4c84f0878 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteLength/this-is-not-object.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-get-dataview.prototype.bytelength +description: Throws a TypeError exception when `this` is not Object +info: | + 24.2.4.2 get DataView.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/detached-buffer.js new file mode 100644 index 0000000000..c151c15d43 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/detached-buffer.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-get-dataview.prototype.byteoffset +description: Throws a TypeError if the instance has a detached buffer +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.byteOffset; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js new file mode 100644 index 0000000000..62736ba675 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-accessor.js @@ -0,0 +1,22 @@ +// 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-get-dataview.prototype.byteoffset +description: > + Requires this value to have a [[DataView]] internal slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + DataView.prototype.byteOffset; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-func.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-func.js new file mode 100644 index 0000000000..7ce651f30a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/invoked-as-func.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.byteoffset +description: Throws a TypeError exception when invoked as a function +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, 'byteOffset' +).get; + +assert.throws(TypeError, function() { + getter(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/length.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/length.js new file mode 100644 index 0000000000..6565d89280 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.byteoffset +description: > + get DataView.prototype.byteOffset.length is 0. +info: | + get DataView.prototype.byteOffset + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "byteOffset"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/name.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/name.js new file mode 100644 index 0000000000..e77dc91d09 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-dataview.prototype.byteoffset +description: > + get DataView.prototype.byteOffset + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor( + DataView.prototype, 'byteOffset' +); + +assert.sameValue( + descriptor.get.name, 'get byteOffset', + 'The value of `descriptor.get.name` is `"get byteOffset"`' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/prop-desc.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/prop-desc.js new file mode 100644 index 0000000000..a52f1fe7d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/prop-desc.js @@ -0,0 +1,25 @@ +// 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-get-dataview.prototype.byteoffset +description: > + "byteOffset" property of DataView.prototype +info: | + DataView.prototype.byteOffset is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(DataView.prototype, "byteOffset"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(DataView.prototype, "byteOffset"); +verifyConfigurable(DataView.prototype, "byteOffset"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js new file mode 100644 index 0000000000..49d07780bf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-auto.js @@ -0,0 +1,54 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-get-dataview.prototype.byteoffset +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the dynamically-sized DataView instance +features: [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"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1); + +assert.sameValue(dataView.byteOffset, 1); + +try { + ab.resize(5); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following grow"); + +try { + ab.resize(3); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following shrink (within bounds)"); + +try { + ab.resize(1); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following shrink (on boundary)"); + +var expectedError; +try { + ab.resize(0); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + dataView.byteOffset; + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..d9c04d8177 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/resizable-array-buffer-fixed.js @@ -0,0 +1,48 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-get-dataview.prototype.byteoffset +description: | + throws a TypeError if the underlying ArrayBuffer is resized beyond the + boundary of the fixed-sized DataView instance +features: [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"); + +var ab = new ArrayBuffer(4, {maxByteLength: 5}); +var dataView = new DataView(ab, 1, 2); + +assert.sameValue(dataView.byteOffset, 1); + +try { + ab.resize(5); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following grow"); + +try { + ab.resize(BPE * 3); +} catch (_) {} + +assert.sameValue(dataView.byteOffset, 1, "following shrink (within bounds)"); + +var expectedError; +try { + ab.resize(2); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + dataView.byteOffset; + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js new file mode 100644 index 0000000000..e0184f2a5b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js @@ -0,0 +1,33 @@ +// |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-get-dataview.prototype.byteoffset +description: > + Return value from [[ByteOffset]] internal slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + ... + 7. Let offset be the value of O's [[ByteOffset]] internal slot. + 8. Return offset. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); +var sample5 = new DataView(buffer, 0, 2); + +assert.sameValue(sample1.byteOffset, 0); +assert.sameValue(sample2.byteOffset, 4); +assert.sameValue(sample3.byteOffset, 6); +assert.sameValue(sample4.byteOffset, 12); +assert.sameValue(sample5.byteOffset, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset.js new file mode 100644 index 0000000000..b7f3c201a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/return-byteoffset.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-get-dataview.prototype.byteoffset +description: > + Return value from [[ByteOffset]] internal slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + ... + 7. Let offset be the value of O's [[ByteOffset]] internal slot. + 8. Return offset. +---*/ + +var buffer = new ArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); +var sample5 = new DataView(buffer, 0, 2); + +assert.sameValue(sample1.byteOffset, 0); +assert.sameValue(sample2.byteOffset, 4); +assert.sameValue(sample3.byteOffset, 6); +assert.sameValue(sample4.byteOffset, 12); +assert.sameValue(sample5.byteOffset, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000..792463509c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js @@ -0,0 +1,44 @@ +// |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-get-dataview.prototype.byteoffset +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..ad3f8d1503 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal.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-get-dataview.prototype.byteoffset +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-is-not-object.js new file mode 100644 index 0000000000..6a78b8f234 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/byteOffset/this-is-not-object.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-get-dataview.prototype.byteoffset +description: Throws a TypeError exception when `this` is not Object +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..d5d1a51f92 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-after-toindex-byteoffset.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, () => sample.getBigInt64(Infinity), + "DataView access at index Infinity should throw"); + +assert.throws(RangeError, () => sample.getBigInt64(-1), + "DataView access at index -1 should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..b74a9e54ea --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer-before-outofrange-byteoffset.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.8 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, () => sample.getBigInt64(13), + "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.js new file mode 100644 index 0000000000..697b6b181e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/detached-buffer.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Throws a TypeError if buffer is detached +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, () => sample.getBigInt64(0), + "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js new file mode 100644 index 0000000000..bd03fe7962 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/index-is-out-of-range.js @@ -0,0 +1,77 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, () => sample.getBigInt64(Infinity), + "DataView access at index Infinity should throw"); + +assert.throws(RangeError, () => sample.getBigInt64(13), "13 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(12), "12 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(11), "11 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(10), "10 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(9), "9 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(8), "8 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(7), "7 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(6), "6 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigInt64(5), "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, () => sample.getBigInt64(1), + "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, () => sample.getBigInt64(0), + "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, () => sample.getBigInt64(1), + "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, () => sample.getBigInt64(0), + "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, () => sample.getBigInt64(1), + "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, () => sample.getBigInt64(0), + "0 + 8 > 7 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.js new file mode 100644 index 0000000000..f45bdc5f25 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: DataView.prototype.getBigInt64.length property descriptor +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in + function object has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.getBigInt64, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js new file mode 100644 index 0000000000..9d6b4253aa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/name.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: DataView.prototype.getBigInt64.name property descriptor +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. Unless otherwise specified, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.getBigInt64, "name", { + value: "getBigInt64", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..7f15464f69 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/negative-byteoffset-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Throws a RangeError if getIndex < 0 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, () => sample.getBigInt64(-1), + "DataView access at index -1 should throw"); + +assert.throws(RangeError, () => sample.getBigInt64(-Infinity), + "DataView access at index -Infinity should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.js new file mode 100644 index 0000000000..20cb228a77 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getBigInt64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getBigInt64), + false, + 'isConstructor(DataView.prototype.getBigInt64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getBigInt64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getBigInt64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js new file mode 100644 index 0000000000..ac4b57792d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getbigint64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getBigInt64(0), 0n, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getBigInt64(0), 0n, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getBigInt64(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..c14c271245 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToNumber(requestIndex). + ... +features: [DataView, ArrayBuffer, Symbol, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, () => sample.getBigInt64(s)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..4ce2b32f1e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToNumber(requestIndex). + ... +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf() { + throw new Test262Error(); + } +}; +var bo2 = { + toString() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => sample.getBigInt64(bo1), "valueOf"); + +assert.throws(Test262Error, () => sample.getBigInt64(bo2), "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..2fabb4edce --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-value-clean-arraybuffer.js @@ -0,0 +1,50 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 12. Let bufferIndex be getIndex + viewOffset. + 13. Return GetValueFromBuffer(buffer, bufferIndex, type, false, + "Unordered", isLittleEndian). + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type, + isTypedArray, order [ , isLittleEndian ] ) + + ... + 9. Return RawBytesToNumber(type, rawValue, isLittleEndian). + + 24.1.1.5 RawBytesToNumber( type, rawBytes, isLittleEndian ) + + ... + 2. If isLittleEndian is false, reverse the order of the elements of rawBytes. + ... +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getBigInt64(0, true), 0n, "sample.getBigInt64(0, true)"); +assert.sameValue(sample.getBigInt64(1, true), 0n, "sample.getBigInt64(1, true)"); +assert.sameValue(sample.getBigInt64(2, true), 0n, "sample.getBigInt64(2, true)"); +assert.sameValue(sample.getBigInt64(3, true), 0n, "sample.getBigInt64(3, true)"); +assert.sameValue(sample.getBigInt64(4, true), 0n, "sample.getBigInt64(4, true)"); +assert.sameValue(sample.getBigInt64(0, false), 0n, "sample.getBigInt64(0, false)"); +assert.sameValue(sample.getBigInt64(1, false), 0n, "sample.getBigInt64(1, false)"); +assert.sameValue(sample.getBigInt64(2, false), 0n, "sample.getBigInt64(2, false)"); +assert.sameValue(sample.getBigInt64(3, false), 0n, "sample.getBigInt64(3, false)"); +assert.sameValue(sample.getBigInt64(4, false), 0n, "sample.getBigInt64(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js new file mode 100644 index 0000000000..aaefaca0ff --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values-custom-offset.js @@ -0,0 +1,70 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Return values from Buffer using a custom offset +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 12. Let bufferIndex be getIndex + viewOffset. + 13. Return GetValueFromBuffer(buffer, bufferIndex, type, false, + "Unordered", isLittleEndian). + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type, + isTypedArray, order [ , isLittleEndian ] ) + + ... + 9. Return RawBytesToNumber(type, rawValue, isLittleEndian). + + 24.1.1.5 RawBytesToNumber( type, rawBytes, isLittleEndian ) + + ... + 2. If isLittleEndian is false, reverse the order of the elements of rawBytes. + ... +features: [DataView, ArrayBuffer, DataView.prototype.setUint8, BigInt] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); +sample.setUint8(12, 0x80); +sample.setUint8(13, 0x7f); +sample.setUint8(14, 0xff); +sample.setUint8(15, 0x80); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getBigInt64(0, false), -0x7fff7ffe80fffefen, "0, false"); +assert.sameValue(sample.getBigInt64(1, false), 0x80017f00010280n, "1, false"); +assert.sameValue(sample.getBigInt64(2, false), -0x7ffe80fffefd7f81n, "2, false"); +assert.sameValue(sample.getBigInt64(3, false), 0x17f000102807fffn, "3, false"); +assert.sameValue(sample.getBigInt64(4, false), 0x7f000102807fff80n, "4, false"); + +assert.sameValue(sample.getBigInt64(0, true), 0x201007f01800080n, "0, true"); +assert.sameValue(sample.getBigInt64(1, true), -0x7ffdfeff80fe8000n, "1, true"); +assert.sameValue(sample.getBigInt64(2, true), 0x7f800201007f0180n, "2, true"); +assert.sameValue(sample.getBigInt64(3, true), -0x807ffdfeff80ffn, "3, true"); +assert.sameValue(sample.getBigInt64(4, true), -0x7f00807ffdfeff81n, "4, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js new file mode 100644 index 0000000000..3a86cee604 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/return-values.js @@ -0,0 +1,71 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Return values from Buffer +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView, ArrayBuffer, DataView.prototype.setUint8, BigInt] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); +sample.setUint8(12, 0x80); +sample.setUint8(13, 0x7f); +sample.setUint8(14, 0xff); +sample.setUint8(15, 0x80); + +assert.sameValue(sample.getBigInt64(0, false), 0x2702060280008001n, "0, false"); +assert.sameValue(sample.getBigInt64(1, false), 0x20602800080017fn, "1, false"); +assert.sameValue(sample.getBigInt64(2, false), 0x602800080017f00n, "2, false"); +assert.sameValue(sample.getBigInt64(3, false), 0x2800080017f0001n, "3, false"); +assert.sameValue(sample.getBigInt64(4, false), -0x7fff7ffe80fffefen, "4, false"); +assert.sameValue(sample.getBigInt64(5, false), 0x80017f00010280n, "5, false"); +assert.sameValue(sample.getBigInt64(6, false), -0x7ffe80fffefd7f81n, "6, false"); +assert.sameValue(sample.getBigInt64(7, false), 0x17f000102807fffn, "7, false"); +assert.sameValue(sample.getBigInt64(8, false), 0x7f000102807fff80n, "8, false"); + +assert.sameValue(sample.getBigInt64(0, true), 0x180008002060227n, "0, true"); +assert.sameValue(sample.getBigInt64(1, true), 0x7f01800080020602n, "1, true"); +assert.sameValue(sample.getBigInt64(2, true), 0x7f018000800206n, "2, true"); +assert.sameValue(sample.getBigInt64(3, true), 0x1007f0180008002n, "3, true"); +assert.sameValue(sample.getBigInt64(4, true), 0x201007f01800080n, "4, true"); +assert.sameValue(sample.getBigInt64(5, true), -0x7ffdfeff80fe8000n, "5, true"); +assert.sameValue(sample.getBigInt64(6, true), 0x7f800201007f0180n, "6, true"); +assert.sameValue(sample.getBigInt64(7, true), -0x807ffdfeff80ffn, "7, true"); +assert.sameValue(sample.getBigInt64(8, true), -0x7f00807ffdfeff81n, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..cc7dfd497e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-has-no-dataview-internal.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [DataView, ArrayBuffer, Int8Array, BigInt, arrow-function] +---*/ + +var getBigInt64 = DataView.prototype.getBigInt64; + +assert.throws(TypeError, () => getBigInt64.call({}), "{}"); + +assert.throws(TypeError, () => getBigInt64.call([]), "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, () => getBigInt64.call(ab), "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, () => getBigInt64.call(ta), "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-is-not-object.js new file mode 100644 index 0000000000..a4d2f6007b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/this-is-not-object.js @@ -0,0 +1,39 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbigint64 +description: Throws a TypeError if this is not Object +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [DataView, ArrayBuffer, Symbol, BigInt, arrow-function] +---*/ + +var getBigInt64 = DataView.prototype.getBigInt64; + +assert.throws(TypeError, () => getBigInt64.call(undefined), + "undefined"); + +assert.throws(TypeError, () => getBigInt64.call(null), "null"); + +assert.throws(TypeError, () => getBigInt64.call(1), "1"); + +assert.throws(TypeError, () => getBigInt64.call("string"), "string"); + +assert.throws(TypeError, () => getBigInt64.call(true), "true"); + +assert.throws(TypeError, () => getBigInt64.call(false), "false"); + +var s = Symbol("1"); +assert.throws(TypeError, () => getBigInt64.call(s), "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js new file mode 100644 index 0000000000..7c86c4fc38 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/to-boolean-littleendian.js @@ -0,0 +1,69 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Boolean littleEndian argument coerced in ToBoolean +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 5. Set isLittleEndian to ToBoolean(isLittleEndian). + ... + 12. Let bufferIndex be getIndex + viewOffset. + 13. Return GetValueFromBuffer(buffer, bufferIndex, type, false, + "Unordered", isLittleEndian). + + 24.1.1.6 GetValueFromBuffer ( arrayBuffer, byteIndex, type, + isTypedArray, order [ , isLittleEndian ] ) + + ... + 9. Return RawBytesToNumber(type, rawValue, isLittleEndian). + + 24.1.1.5 RawBytesToNumber( type, rawBytes, isLittleEndian ) + + ... + 2. If isLittleEndian is false, reverse the order of the elements of rawBytes. + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); +sample.setUint8(7, 0xff); +assert.sameValue(sample.getBigInt64(0), 0xffn, "no argument"); + +assert.sameValue(sample.getBigInt64(0, false), 0xffn); +assert.sameValue(sample.getBigInt64(0, true), -0x100000000000000n); +assert.sameValue(sample.getBigInt64(0, 0), 0xffn, "ToBoolean: 0 => false"); +assert.sameValue(sample.getBigInt64(0, -0), 0xffn, "ToBoolean: -0 => false"); +assert.sameValue(sample.getBigInt64(0, 1), -0x100000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, -1), -0x100000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, 0.1), -0x100000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, Infinity), -0x100000000000000n, + "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigInt64(0, NaN), 0xffn, "ToBoolean: NaN => false"); +assert.sameValue(sample.getBigInt64(0, undefined), 0xffn, "ToBoolean: undefined => false"); +assert.sameValue(sample.getBigInt64(0, null), 0xffn, "ToBoolean: null => false"); +assert.sameValue(sample.getBigInt64(0, ""), 0xffn, "ToBoolean: String .length == 0 => false"); +assert.sameValue(sample.getBigInt64(0, "string"), -0x100000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigInt64(0, "false"), -0x100000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigInt64(0, " "), -0x100000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigInt64(0, Symbol("1")), -0x100000000000000n, + "ToBoolean: Symbol => true"); +assert.sameValue(sample.getBigInt64(0, 0n), 0xffn, "ToBoolean: 0n => false"); +assert.sameValue(sample.getBigInt64(0, 1n), -0x100000000000000n, "ToBoolean: BigInt != 0n => true"); +assert.sameValue(sample.getBigInt64(0, []), -0x100000000000000n, "ToBoolean: any object => true"); +assert.sameValue(sample.getBigInt64(0, {}), -0x100000000000000n, "ToBoolean: any object => true"); +assert.sameValue(sample.getBigInt64(0, Object(false)), -0x100000000000000n, + "ToBoolean: any object => true; no ToPrimitive"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js new file mode 100644 index 0000000000..3161d42157 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-errors.js @@ -0,0 +1,109 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.throws(RangeError, function() { + sample.getBigInt64(-1); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64(-2.5); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64("-2.5"); +}, "ToIndex: parse Number => throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64(-Infinity); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigInt64(9007199254740992); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(RangeError, function() { + sample.getBigInt64(Infinity); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(TypeError, function() { + sample.getBigInt64(0n); +}, "ToIndex: BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64(Object(0n)); +}, "ToIndex: unbox object with internal slot => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return 0n; + } + }); +}, "ToIndex: @@toPrimitive => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return 0n; + } + }); +}, "ToIndex: valueOf => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + toString: function() { + return 0n; + } + }); +}, "ToIndex: toString => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64(Symbol("1")); +}, "ToIndex: Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64(Object(Symbol("1"))); +}, "ToIndex: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToIndex: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return Symbol("1"); + } + }); +}, "ToIndex: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + toString: function() { + return Symbol("1"); + } + }); +}, "ToIndex: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js new file mode 100644 index 0000000000..8e9aa91906 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-toprimitive.js @@ -0,0 +1,190 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return 1; + }, + valueOf: err, + toString: err +}), 0x20602800080017fn, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return 1; + }, + toString: err +}), 0x20602800080017fn, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: toString with no valueOf"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: null, + valueOf: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(sample.getBigInt64({ + valueOf: null, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigInt64({ + valueOf: 1, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigInt64({ + valueOf: {}, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return {}; + }, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return Object(12345); + }, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + sample.getBigInt64({ + valueOf: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + sample.getBigInt64({ + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigInt64({ + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js new file mode 100644 index 0000000000..3531b14a11 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset-wrapped-values.js @@ -0,0 +1,135 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.sameValue(sample.getBigInt64(Object(0)), 0x2702060280008001n, + "ToPrimitive: unbox object with internal slot"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: valueOf"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: toString"); +assert.sameValue(sample.getBigInt64(Object(NaN)), 0x2702060280008001n, + "ToIndex: unbox object with internal slot => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: valueOf => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: toString => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: valueOf => undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: toString => undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => null => 0"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: valueOf => null => 0"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: toString => null => 0"); +assert.sameValue(sample.getBigInt64(Object(true)), 0x20602800080017fn, + "ToIndex: unbox object with internal slot => true => 1"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: @@toPrimitive => true => 1"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: valueOf => true => 1"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: toString => true => 1"); +assert.sameValue(sample.getBigInt64(Object("1")), 0x20602800080017fn, + "ToIndex: unbox object with internal slot => parse Number"); +assert.sameValue(sample.getBigInt64({ + [Symbol.toPrimitive]: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: @@toPrimitive => parse Number"); +assert.sameValue(sample.getBigInt64({ + valueOf: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: valueOf => parse Number"); +assert.sameValue(sample.getBigInt64({ + toString: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: toString => parse Number"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js new file mode 100644 index 0000000000..99df43ec2c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigInt64/toindex-byteoffset.js @@ -0,0 +1,72 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbigint64 +info: | + DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be undefined. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int64"). + + 24.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.sameValue(sample.getBigInt64(0), 0x2702060280008001n); +assert.sameValue(sample.getBigInt64(1), 0x20602800080017fn); +assert.sameValue(sample.getBigInt64(-0.9), 0x2702060280008001n, "ToIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64(0.9), 0x2702060280008001n, "ToIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64(NaN), 0x2702060280008001n, "ToIndex: NaN => 0"); +assert.sameValue(sample.getBigInt64(undefined), 0x2702060280008001n, + "ToIndex: undefined => NaN => 0"); +assert.sameValue(sample.getBigInt64(null), 0x2702060280008001n, "ToIndex: null => 0"); +assert.sameValue(sample.getBigInt64(false), 0x2702060280008001n, "ToIndex: false => 0"); +assert.sameValue(sample.getBigInt64(true), 0x20602800080017fn, "ToIndex: true => 1"); +assert.sameValue(sample.getBigInt64("0"), 0x2702060280008001n, "ToIndex: parse Number"); +assert.sameValue(sample.getBigInt64("1"), 0x20602800080017fn, "ToIndex: parse Number"); +assert.sameValue(sample.getBigInt64(""), 0x2702060280008001n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigInt64("foo"), 0x2702060280008001n, + "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigInt64("true"), 0x2702060280008001n, + "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigInt64(2), 0x602800080017F00n); +assert.sameValue(sample.getBigInt64("2"), 0x602800080017F00n, "toIndex: parse Number"); +assert.sameValue(sample.getBigInt64(2.9), 0x602800080017F00n, "toIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64("2.9"), 0x602800080017F00n, + "toIndex: parse Number => truncate towards 0"); +assert.sameValue(sample.getBigInt64(3), 0x2800080017F0001n); +assert.sameValue(sample.getBigInt64("3"), 0x2800080017F0001n, "toIndex: parse Number"); +assert.sameValue(sample.getBigInt64(3.9), 0x2800080017F0001n, "toIndex: truncate towards 0"); +assert.sameValue(sample.getBigInt64("3.9"), 0x2800080017F0001n, + "toIndex: parse Number => truncate towards 0"); +assert.sameValue(sample.getBigInt64([0]), 0x2702060280008001n, + 'ToIndex: [0].toString() => "0" => 0'); +assert.sameValue(sample.getBigInt64(["1"]), 0x20602800080017fn, + 'ToIndex: ["1"].toString() => "1" => 1'); +assert.sameValue(sample.getBigInt64({}), 0x2702060280008001n, + 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); +assert.sameValue(sample.getBigInt64([]), 0x2702060280008001n, + 'ToIndex: [].toString() => "" => NaN => 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..33dadfc031 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-after-toindex-byteoffset.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, () => sample.getBigUint64(Infinity), + "DataView access at index Infinity should throw"); + +assert.throws(RangeError, () => sample.getBigUint64(-1), + "DataView access at index -1 should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..ada38d0f49 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer-before-outofrange-byteoffset.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Detached buffer is checked before out of range byteOffset's value +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, () => sample.getBigUint64(13), + "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer.js new file mode 100644 index 0000000000..a0cbfa3760 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/detached-buffer.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Throws a TypeError if buffer is detached +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, () => sample.getBigUint64(0), + "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/index-is-out-of-range.js new file mode 100644 index 0000000000..67a70ab7f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/index-is-out-of-range.js @@ -0,0 +1,61 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, () => sample.getBigUint64(Infinity), + "DataView access at index Infinity should throw"); + +assert.throws(RangeError, () => sample.getBigUint64(13), "13 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(12), "12 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(11), "11 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(10), "10 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(9), "9 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(8), "8 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(7), "7 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(6), "6 + 8 > 12"); + +assert.throws(RangeError, () => sample.getBigUint64(5), "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, () => sample.getBigUint64(1), + "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, () => sample.getBigUint64(0), + "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, () => sample.getBigUint64(1), + "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, () => sample.getBigUint64(0), + "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, () => sample.getBigUint64(1), + "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, () => sample.getBigUint64(0), + "0 + 8 > 7 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/length.js new file mode 100644 index 0000000000..7ffed05297 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: DataView.prototype.getBigUint64.length property descriptor +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.getBigUint64, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/name.js new file mode 100644 index 0000000000..b9da2cad7d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: DataView.prototype.getBigUint64.name property descriptor +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.getBigUint64, "name", { + value: "getBigUint64", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..de50598408 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/negative-byteoffset-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Throws a RangeError if getIndex < 0 +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, () => sample.getBigUint64(-1), + "DataView access at index -1 should throw"); + +assert.throws(RangeError, () => sample.getBigUint64(-Infinity), + "DataView access at index -Infinity should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/not-a-constructor.js new file mode 100644 index 0000000000..c9a26de1fa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getBigUint64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getBigUint64), + false, + 'isConstructor(DataView.prototype.getBigUint64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getBigUint64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getBigUint64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/resizable-buffer.js new file mode 100644 index 0000000000..5f6793d1c9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getbiguint64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getBigUint64(0), 0n, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getBigUint64(0), 0n, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getBigUint64(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..42871333f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +features: [DataView, ArrayBuffer, Symbol, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, () => sample.getBigUint64(s)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..5ae6c98629 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Return abrupt from ToNumber(byteOffset) +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf() { + throw new Test262Error(); + } +}; +var bo2 = { + toString() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => sample.getBigUint64(bo1), "valueOf"); + +assert.throws(Test262Error, () => sample.getBigUint64(bo2), "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..c4c2d73306 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-value-clean-arraybuffer.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Return value from Buffer using a clean ArrayBuffer +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getBigUint64(0, true), 0n, "sample.getBigUint64(0, true)"); +assert.sameValue(sample.getBigUint64(1, true), 0n, "sample.getBigUint64(1, true)"); +assert.sameValue(sample.getBigUint64(2, true), 0n, "sample.getBigUint64(2, true)"); +assert.sameValue(sample.getBigUint64(3, true), 0n, "sample.getBigUint64(3, true)"); +assert.sameValue(sample.getBigUint64(4, true), 0n, "sample.getBigUint64(4, true)"); +assert.sameValue(sample.getBigUint64(0, false), 0n, "sample.getBigUint64(0, false)"); +assert.sameValue(sample.getBigUint64(1, false), 0n, "sample.getBigUint64(1, false)"); +assert.sameValue(sample.getBigUint64(2, false), 0n, "sample.getBigUint64(2, false)"); +assert.sameValue(sample.getBigUint64(3, false), 0n, "sample.getBigUint64(3, false)"); +assert.sameValue(sample.getBigUint64(4, false), 0n, "sample.getBigUint64(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values-custom-offset.js new file mode 100644 index 0000000000..60fb4eb104 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values-custom-offset.js @@ -0,0 +1,45 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Return values from Buffer using a custom offset +features: [DataView, ArrayBuffer, DataView.prototype.setUint8, BigInt] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); +sample.setUint8(12, 0x80); +sample.setUint8(13, 0x7f); +sample.setUint8(14, 0xff); +sample.setUint8(15, 0x80); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getBigUint64(0, false), 0x800080017f000102n, "0, false"); +assert.sameValue(sample.getBigUint64(1, false), 0x80017f00010280n, "1, false"); +assert.sameValue(sample.getBigUint64(2, false), 0x80017f000102807fn, "2, false"); +assert.sameValue(sample.getBigUint64(3, false), 0x17f000102807fffn, "3, false"); +assert.sameValue(sample.getBigUint64(4, false), 0x7f000102807fff80n, "4, false"); + +assert.sameValue(sample.getBigUint64(0, true), 0x201007f01800080n, "0, true"); +assert.sameValue(sample.getBigUint64(1, true), 0x800201007f018000n, "1, true"); +assert.sameValue(sample.getBigUint64(2, true), 0x7f800201007f0180n, "2, true"); +assert.sameValue(sample.getBigUint64(3, true), 0xff7f800201007f01n, "3, true"); +assert.sameValue(sample.getBigUint64(4, true), 0x80ff7f800201007fn, "4, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values.js new file mode 100644 index 0000000000..afd53670fa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/return-values.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Return values from Buffer +features: [DataView, ArrayBuffer, DataView.prototype.setUint8, BigInt] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); +sample.setUint8(12, 0x80); +sample.setUint8(13, 0x7f); +sample.setUint8(14, 0xff); +sample.setUint8(15, 0x80); + +assert.sameValue(sample.getBigUint64(0, false), 0x2702060280008001n, "0, false"); +assert.sameValue(sample.getBigUint64(1, false), 0x20602800080017fn, "1, false"); +assert.sameValue(sample.getBigUint64(2, false), 0x602800080017f00n, "2, false"); +assert.sameValue(sample.getBigUint64(3, false), 0x2800080017f0001n, "3, false"); +assert.sameValue(sample.getBigUint64(4, false), 0x800080017f000102n, "4, false"); +assert.sameValue(sample.getBigUint64(5, false), 0x80017f00010280n, "5, false"); +assert.sameValue(sample.getBigUint64(6, false), 0x80017f000102807fn, "6, false"); +assert.sameValue(sample.getBigUint64(7, false), 0x17f000102807fffn, "7, false"); +assert.sameValue(sample.getBigUint64(8, false), 0x7f000102807fff80n, "8, false"); + +assert.sameValue(sample.getBigUint64(0, true), 0x180008002060227n, "0, true"); +assert.sameValue(sample.getBigUint64(1, true), 0x7f01800080020602n, "1, true"); +assert.sameValue(sample.getBigUint64(2, true), 0x7f018000800206n, "2, true"); +assert.sameValue(sample.getBigUint64(3, true), 0x1007f0180008002n, "3, true"); +assert.sameValue(sample.getBigUint64(4, true), 0x201007f01800080n, "4, true"); +assert.sameValue(sample.getBigUint64(5, true), 0x800201007F018000n, "5, true"); +assert.sameValue(sample.getBigUint64(6, true), 0x7f800201007f0180n, "6, true"); +assert.sameValue(sample.getBigUint64(7, true), 0xff7f800201007f01n, "7, true"); +assert.sameValue(sample.getBigUint64(8, true), 0x80ff7f800201007fn, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..21fb077381 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-has-no-dataview-internal.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +features: [DataView, ArrayBuffer, Int8Array, BigInt, arrow-function] +---*/ + +var getBigUint64 = DataView.prototype.getBigUint64; + +assert.throws(TypeError, () => getBigUint64.call({}), "{}"); + +assert.throws(TypeError, () => getBigUint64.call([]), "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, () => getBigUint64.call(ab), "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, () => getBigUint64.call(ta), "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-is-not-object.js new file mode 100644 index 0000000000..f9e4922f05 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/this-is-not-object.js @@ -0,0 +1,28 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getbiguint64 +description: Throws a TypeError if this is not Object +features: [DataView, ArrayBuffer, Symbol, BigInt, arrow-function] +---*/ + +var getBigUint64 = DataView.prototype.getBigUint64; + +assert.throws(TypeError, () => getBigUint64.call(undefined), + "undefined"); + +assert.throws(TypeError, () => getBigUint64.call(null), "null"); + +assert.throws(TypeError, () => getBigUint64.call(1), "1"); + +assert.throws(TypeError, () => getBigUint64.call("string"), "string"); + +assert.throws(TypeError, () => getBigUint64.call(true), "true"); + +assert.throws(TypeError, () => getBigUint64.call(false), "false"); + +var s = Symbol("1"); +assert.throws(TypeError, () => getBigUint64.call(s), "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/to-boolean-littleendian.js new file mode 100644 index 0000000000..d442f3ca2e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/to-boolean-littleendian.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Boolean littleEndian argument coerced in ToBoolean +esid: sec-dataview.prototype.getbiguint64 +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); +sample.setUint8(7, 0xff); +assert.sameValue(sample.getBigUint64(0), 0xffn, "no argument"); + +assert.sameValue(sample.getBigUint64(0, false), 0xffn); +assert.sameValue(sample.getBigUint64(0, true), 0xff00000000000000n); +assert.sameValue(sample.getBigUint64(0, 0), 0xffn, "ToBoolean: 0 => false"); +assert.sameValue(sample.getBigUint64(0, -0), 0xffn, "ToBoolean: -0 => false"); +assert.sameValue(sample.getBigUint64(0, 1), 0xff00000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigUint64(0, -1), 0xff00000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigUint64(0, 0.1), 0xff00000000000000n, "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigUint64(0, Infinity), 0xff00000000000000n, + "ToBoolean: Number != 0 => true"); +assert.sameValue(sample.getBigUint64(0, NaN), 0xffn, "ToBoolean: NaN => false"); +assert.sameValue(sample.getBigUint64(0, undefined), 0xffn, "ToBoolean: undefined => false"); +assert.sameValue(sample.getBigUint64(0, null), 0xffn, "ToBoolean: null => false"); +assert.sameValue(sample.getBigUint64(0, ""), 0xffn, "ToBoolean: String .length == 0 => false"); +assert.sameValue(sample.getBigUint64(0, "string"), 0xff00000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigUint64(0, "false"), 0xff00000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigUint64(0, " "), 0xff00000000000000n, + "ToBoolean: String .length > 0 => true"); +assert.sameValue(sample.getBigUint64(0, Symbol("1")), 0xff00000000000000n, + "ToBoolean: Symbol => true"); +assert.sameValue(sample.getBigUint64(0, 0n), 0xffn, "ToBoolean: 0n => false"); +assert.sameValue(sample.getBigUint64(0, 1n), 0xff00000000000000n, "ToBoolean: BigInt != 0n => true"); +assert.sameValue(sample.getBigUint64(0, []), 0xff00000000000000n, "ToBoolean: any object => true"); +assert.sameValue(sample.getBigUint64(0, {}), 0xff00000000000000n, "ToBoolean: any object => true"); +assert.sameValue(sample.getBigUint64(0, Object(false)), 0xff00000000000000n, + "ToBoolean: any object => true; no ToPrimitive"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-errors.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-errors.js new file mode 100644 index 0000000000..3727b63af7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-errors.js @@ -0,0 +1,97 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbiguint64 +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.throws(RangeError, function() { + sample.getBigUint64(-1); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigUint64(-2.5); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigUint64("-2.5"); +}, "ToIndex: parse Number => throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigUint64(-Infinity); +}, "ToIndex: throw when integerIndex < 0"); +assert.throws(RangeError, function() { + sample.getBigUint64(9007199254740992); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(RangeError, function() { + sample.getBigUint64(Infinity); +}, "ToIndex: throw when integerIndex > 2**53-1"); +assert.throws(TypeError, function() { + sample.getBigUint64(0n); +}, "ToIndex: BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64(Object(0n)); +}, "ToIndex: unbox object with internal slot => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return 0n; + } + }); +}, "ToIndex: @@toPrimitive => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: function() { + return 0n; + } + }); +}, "ToIndex: valueOf => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + toString: function() { + return 0n; + } + }); +}, "ToIndex: toString => BigInt => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64(Symbol("1")); +}, "ToIndex: Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64(Object(Symbol("1"))); +}, "ToIndex: unbox object with internal slot => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return Symbol("1"); + } + }); +}, "ToIndex: @@toPrimitive => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: function() { + return Symbol("1"); + } + }); +}, "ToIndex: valueOf => Symbol => TypeError"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + toString: function() { + return Symbol("1"); + } + }); +}, "ToIndex: toString => Symbol => TypeError"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-toprimitive.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-toprimitive.js new file mode 100644 index 0000000000..5f341c5fe3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-toprimitive.js @@ -0,0 +1,178 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbiguint64 +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return 1; + }, + valueOf: err, + toString: err +}), 0x20602800080017fn, "ToPrimitive: @@toPrimitive takes precedence"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return 1; + }, + toString: err +}), 0x20602800080017fn, "ToPrimitive: valueOf takes precedence over toString"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: toString with no valueOf"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: undefined, + valueOf: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip @@toPrimitive when it's undefined"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: null, + valueOf: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip @@toPrimitive when it's null"); +assert.sameValue(sample.getBigUint64({ + valueOf: null, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigUint64({ + valueOf: 1, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigUint64({ + valueOf: {}, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it's not callable"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return {}; + }, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it returns an object"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return Object(12345); + }, + toString: function() { + return 1; + } +}), 0x20602800080017fn, "ToPrimitive: skip valueOf when it returns an object"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: 1 + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: {} + }); +}, "ToPrimitive: throw when @@toPrimitive is not callable"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return {}; + } + }); +}, "ToPrimitive: throw when @@toPrimitive returns an object"); +assert.throws(MyError, function() { + sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from @@toPrimitive"); +assert.throws(MyError, function() { + sample.getBigUint64({ + valueOf: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from valueOf"); +assert.throws(MyError, function() { + sample.getBigUint64({ + toString: function() { + throw new MyError(); + } + }); +}, "ToPrimitive: propagate errors from toString"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: null, + toString: null + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: 1, + toString: 1 + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: {}, + toString: {} + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: function() { + return Object(1); + }, + toString: function() { + return Object(1); + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); +assert.throws(TypeError, function() { + sample.getBigUint64({ + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + }); +}, "ToPrimitive: throw when skipping both valueOf and toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-wrapped-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-wrapped-values.js new file mode 100644 index 0000000000..79e19bef85 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-wrapped-values.js @@ -0,0 +1,123 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbiguint64 +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8, Symbol.toPrimitive, computed-property-names] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.sameValue(sample.getBigUint64(Object(0)), 0x2702060280008001n, + "ToPrimitive: unbox object with internal slot"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: @@toPrimitive"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: valueOf"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return 0; + } +}), 0x2702060280008001n, "ToPrimitive: toString"); +assert.sameValue(sample.getBigUint64(Object(NaN)), 0x2702060280008001n, + "ToIndex: unbox object with internal slot => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: valueOf => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return NaN; + } +}), 0x2702060280008001n, "ToIndex: toString => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => undefined => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: valueOf => undefined => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return undefined; + } +}), 0x2702060280008001n, "ToIndex: toString => undefined => NaN => 0"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: @@toPrimitive => null => 0"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: valueOf => null => 0"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return null; + } +}), 0x2702060280008001n, "ToIndex: toString => null => 0"); +assert.sameValue(sample.getBigUint64(Object(true)), 0x20602800080017fn, + "ToIndex: unbox object with internal slot => true => 1"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: @@toPrimitive => true => 1"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: valueOf => true => 1"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return true; + } +}), 0x20602800080017fn, "ToIndex: toString => true => 1"); +assert.sameValue(sample.getBigUint64(Object("1")), 0x20602800080017fn, + "ToIndex: unbox object with internal slot => parse Number"); +assert.sameValue(sample.getBigUint64({ + [Symbol.toPrimitive]: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: @@toPrimitive => parse Number"); +assert.sameValue(sample.getBigUint64({ + valueOf: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: valueOf => parse Number"); +assert.sameValue(sample.getBigUint64({ + toString: function() { + return "1"; + } +}), 0x20602800080017fn, "ToIndex: toString => parse Number"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset.js new file mode 100644 index 0000000000..82094fdca9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset.js @@ -0,0 +1,60 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: ToIndex conversions on byteOffset +esid: sec-dataview.prototype.getbiguint64 +features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +sample.setUint8(0, 0x27); +sample.setUint8(1, 0x02); +sample.setUint8(2, 0x06); +sample.setUint8(3, 0x02); +sample.setUint8(4, 0x80); +sample.setUint8(5, 0x00); +sample.setUint8(6, 0x80); +sample.setUint8(7, 0x01); +sample.setUint8(8, 0x7f); +sample.setUint8(9, 0x00); +sample.setUint8(10, 0x01); +sample.setUint8(11, 0x02); + +assert.sameValue(sample.getBigUint64(0), 0x2702060280008001n); +assert.sameValue(sample.getBigUint64(1), 0x20602800080017fn); +assert.sameValue(sample.getBigUint64(-0.9), 0x2702060280008001n, "ToIndex: truncate towards 0"); +assert.sameValue(sample.getBigUint64(0.9), 0x2702060280008001n, "ToIndex: truncate towards 0"); +assert.sameValue(sample.getBigUint64(NaN), 0x2702060280008001n, "ToIndex: NaN => 0"); +assert.sameValue(sample.getBigUint64(undefined), 0x2702060280008001n, + "ToIndex: undefined => NaN => 0"); +assert.sameValue(sample.getBigUint64(null), 0x2702060280008001n, "ToIndex: null => 0"); +assert.sameValue(sample.getBigUint64(false), 0x2702060280008001n, "ToIndex: false => 0"); +assert.sameValue(sample.getBigUint64(true), 0x20602800080017fn, "ToIndex: true => 1"); +assert.sameValue(sample.getBigUint64("0"), 0x2702060280008001n, "ToIndex: parse Number"); +assert.sameValue(sample.getBigUint64("1"), 0x20602800080017fn, "ToIndex: parse Number"); +assert.sameValue(sample.getBigUint64(""), 0x2702060280008001n, "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigUint64("foo"), 0x2702060280008001n, + "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigUint64("true"), 0x2702060280008001n, + "ToIndex: parse Number => NaN => 0"); +assert.sameValue(sample.getBigUint64(2), 0x602800080017F00n); +assert.sameValue(sample.getBigUint64("2"), 0x602800080017F00n, "toIndex: parse Number"); +assert.sameValue(sample.getBigUint64(2.9), 0x602800080017F00n, "toIndex: truncate towards 0"); +assert.sameValue(sample.getBigUint64("2.9"), 0x602800080017F00n, + "toIndex: parse Number => truncate towards 0"); +assert.sameValue(sample.getBigUint64(3), 0x2800080017F0001n); +assert.sameValue(sample.getBigUint64("3"), 0x2800080017F0001n, "toIndex: parse Number"); +assert.sameValue(sample.getBigUint64(3.9), 0x2800080017F0001n, "toIndex: truncate towards 0"); +assert.sameValue(sample.getBigUint64("3.9"), 0x2800080017F0001n, + "toIndex: parse Number => truncate towards 0"); +assert.sameValue(sample.getBigUint64([0]), 0x2702060280008001n, + 'ToIndex: [0].toString() => "0" => 0'); +assert.sameValue(sample.getBigUint64(["1"]), 0x20602800080017fn, + 'ToIndex: ["1"].toString() => "1" => 1'); +assert.sameValue(sample.getBigUint64({}), 0x2702060280008001n, + 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); +assert.sameValue(sample.getBigUint64([]), 0x2702060280008001n, + 'ToIndex: [].toString() => "" => NaN => 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..d675fc45b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getfloat32 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(6); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getFloat32(-1); +}); + +assert.throws(RangeError, function() { + sample.getFloat32(Infinity); +}, "Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..29eb90573d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getfloat32 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getFloat32(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer.js new file mode 100644 index 0000000000..5e8e822850 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/detached-buffer.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-dataview.prototype.getfloat32 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getFloat32(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/index-is-out-of-range.js new file mode 100644 index 0000000000..f7fd925c5c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/index-is-out-of-range.js @@ -0,0 +1,85 @@ +// 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-dataview.prototype.getfloat32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat32(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getFloat32(13); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat32(12); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat32(11); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat32(10); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat32(9); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getFloat32(1); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getFloat32(0); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.getFloat32(1); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.getFloat32(0); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.getFloat32(1); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.getFloat32(0); +}, "0 + 4 > 3 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/length.js new file mode 100644 index 0000000000..8f1256a67b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat32 +description: > + DataView.prototype.getFloat32.length is 1. +info: | + DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getFloat32.length, 1); + +verifyNotEnumerable(DataView.prototype.getFloat32, "length"); +verifyNotWritable(DataView.prototype.getFloat32, "length"); +verifyConfigurable(DataView.prototype.getFloat32, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/minus-zero.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/minus-zero.js new file mode 100644 index 0000000000..4582a3444b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/minus-zero.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-dataview.prototype.getfloat32 +description: > + Return -0 +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 128); +sample.setUint8(1, 0); +sample.setUint8(2, 0); +sample.setUint8(3, 0); + +var result = sample.getFloat32(0); +assert.sameValue(result, -0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/name.js new file mode 100644 index 0000000000..26e5b6d3e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat32 +description: > + DataView.prototype.getFloat32.name is "getFloat32". +info: | + DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getFloat32.name, "getFloat32"); + +verifyNotEnumerable(DataView.prototype.getFloat32, "name"); +verifyNotWritable(DataView.prototype.getFloat32, "name"); +verifyConfigurable(DataView.prototype.getFloat32, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/negative-byteoffset-throws.js new file mode 100644 index 0000000000..4c9e09b683 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/negative-byteoffset-throws.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-dataview.prototype.getfloat32 +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat32(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getFloat32(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/not-a-constructor.js new file mode 100644 index 0000000000..628d35ed6d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getFloat32 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getFloat32), + false, + 'isConstructor(DataView.prototype.getFloat32) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getFloat32(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getFloat32(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/resizable-buffer.js new file mode 100644 index 0000000000..ebad87b82f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getfloat32 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getFloat32(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getFloat32(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getFloat32(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..3303d7adf0 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.getfloat32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getFloat32(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..69b9994b15 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.getfloat32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getFloat32(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getFloat32(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-infinity.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-infinity.js new file mode 100644 index 0000000000..ae41f70725 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-infinity.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-dataview.prototype.getfloat32 +description: > + Return Infinity values +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 128); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 255); +sample.setUint8(5, 128); +sample.setUint8(6, 0); +sample.setUint8(7, 0); + +assert.sameValue(sample.getFloat32(0), Infinity); +assert.sameValue(sample.getFloat32(4), -Infinity); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-nan.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-nan.js new file mode 100644 index 0000000000..263dbd888e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-nan.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-dataview.prototype.getfloat32 +description: > + Return NaN values +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 192); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 255); +sample.setUint8(5, 192); +sample.setUint8(6, 0); +sample.setUint8(7, 0); + +assert.sameValue(sample.getFloat32(0), NaN); +assert.sameValue(sample.getFloat32(4), NaN); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..62e114ce54 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-value-clean-arraybuffer.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getfloat32 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getFloat32(0, true), 0, "sample.getFloat32(0, true)"); +assert.sameValue(sample.getFloat32(1, true), 0, "sample.getFloat32(1, true)"); +assert.sameValue(sample.getFloat32(2, true), 0, "sample.getFloat32(2, true)"); +assert.sameValue(sample.getFloat32(3, true), 0, "sample.getFloat32(3, true)"); +assert.sameValue(sample.getFloat32(4, true), 0, "sample.getFloat32(4, true)"); +assert.sameValue(sample.getFloat32(0, false), 0, "sample.getFloat32(0, false)"); +assert.sameValue(sample.getFloat32(1, false), 0, "sample.getFloat32(1, false)"); +assert.sameValue(sample.getFloat32(2, false), 0, "sample.getFloat32(2, false)"); +assert.sameValue(sample.getFloat32(3, false), 0, "sample.getFloat32(3, false)"); +assert.sameValue(sample.getFloat32(4, false), 0, "sample.getFloat32(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values-custom-offset.js new file mode 100644 index 0000000000..6e9ae93648 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values-custom-offset.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-dataview.prototype.getfloat32 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(4, 75); +sample.setUint8(5, 75); +sample.setUint8(6, 75); +sample.setUint8(7, 75); +sample.setUint8(8, 76); +sample.setUint8(9, 76); +sample.setUint8(10, 77); +sample.setUint8(11, 77); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getFloat32(0, false), 13323083, "0, false"); +assert.sameValue(sample.getFloat32(1, false), 13323084, "1, false"); +assert.sameValue(sample.getFloat32(2, false), 13323340, "2, false"); +assert.sameValue(sample.getFloat32(3, false), 13388877, "3, false"); +assert.sameValue(sample.getFloat32(4, false), 53556532, "4, false"); +assert.sameValue(sample.getFloat32(0, true), 13323083, "0, true"); +assert.sameValue(sample.getFloat32(1, true), 53292332, "1, true"); +assert.sameValue(sample.getFloat32(2, true), 53554476, "2, true"); +assert.sameValue(sample.getFloat32(3, true), 214222000, "3, true"); +assert.sameValue(sample.getFloat32(4, true), 215270592, "4, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values.js new file mode 100644 index 0000000000..498ca364a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/return-values.js @@ -0,0 +1,75 @@ +// 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-dataview.prototype.getfloat32 +description: > + Return values from Buffer +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 66); +sample.setUint8(1, 40); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 64); +sample.setUint8(5, 224); +sample.setUint8(6, 0); +sample.setUint8(7, 0); + +assert.sameValue(sample.getFloat32(0, false), 42, "0, false"); +assert.sameValue(sample.getFloat32(1, false), 7.105481567709626e-15, "1, false"); +assert.sameValue(sample.getFloat32(2, false), 2.327276489550656e-41, "2, false"); +assert.sameValue(sample.getFloat32(3, false), 5.95782781324968e-39, "3, false"); +assert.sameValue(sample.getFloat32(4, false), 7, "4, false"); + +assert.sameValue(sample.getFloat32(0, true), 1.4441781973331565e-41, "0, true"); +assert.sameValue(sample.getFloat32(1, true), 2.000009536743164, "1, true"); +assert.sameValue(sample.getFloat32(2, true), -55340232221128655000, "2, true"); +assert.sameValue(sample.getFloat32(3, true), 2.059411001342953e-38, "3, true"); +assert.sameValue(sample.getFloat32(4, true), 8.04457422399591e-41, "4, true"); + +sample.setUint8(0, 75); +sample.setUint8(1, 75); +sample.setUint8(2, 76); +sample.setUint8(3, 76); +sample.setUint8(4, 75); +sample.setUint8(5, 75); +sample.setUint8(6, 76); +sample.setUint8(7, 76); + +assert.sameValue(sample.getFloat32(0, false), 13323340, "0, false"); +assert.sameValue(sample.getFloat32(1, false), 13388875, "1, false"); +assert.sameValue(sample.getFloat32(2, false), 53554476, "2, false"); +assert.sameValue(sample.getFloat32(3, false), 53292336, "3, false"); +assert.sameValue(sample.getFloat32(4, false), 13323340, "4, false"); +assert.sameValue(sample.getFloat32(0, true), 53554476, "0, true"); +assert.sameValue(sample.getFloat32(1, true), 13388875, "1, true"); +assert.sameValue(sample.getFloat32(2, true), 13323340, "2, true"); +assert.sameValue(sample.getFloat32(3, true), 53292336, "3, true"); +assert.sameValue(sample.getFloat32(4, true), 53554476, "4, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..de45dedbad --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getfloat32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getFloat32 = DataView.prototype.getFloat32; + +assert.throws(TypeError, function() { + getFloat32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getFloat32.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getFloat32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getFloat32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-is-not-object.js new file mode 100644 index 0000000000..f79002c879 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/this-is-not-object.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-dataview.prototype.getfloat32 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getFloat32 = DataView.prototype.getFloat32; + +assert.throws(TypeError, function() { + getFloat32.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getFloat32.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getFloat32.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getFloat32.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getFloat32.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getFloat32.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getFloat32.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/to-boolean-littleendian.js new file mode 100644 index 0000000000..6ad32be527 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/to-boolean-littleendian.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-dataview.prototype.getfloat32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 75); +sample.setUint8(1, 75); +sample.setUint8(2, 76); +sample.setUint8(3, 76); + +// False +assert.sameValue(sample.getFloat32(0), 13323340, "no arg"); +assert.sameValue(sample.getFloat32(0, undefined), 13323340, "undefined"); +assert.sameValue(sample.getFloat32(0, null), 13323340, "null"); +assert.sameValue(sample.getFloat32(0, 0), 13323340, "0"); +assert.sameValue(sample.getFloat32(0, ""), 13323340, "the empty string"); + +// True +assert.sameValue(sample.getFloat32(0, {}), 53554476, "{}"); +assert.sameValue(sample.getFloat32(0, Symbol("1")), 53554476, "symbol"); +assert.sameValue(sample.getFloat32(0, 1), 53554476, "1"); +assert.sameValue(sample.getFloat32(0, "string"), 53554476, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/toindex-byteoffset.js new file mode 100644 index 0000000000..218d7c3116 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat32/toindex-byteoffset.js @@ -0,0 +1,66 @@ +// 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-dataview.prototype.getfloat32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 75); +sample.setUint8(1, 75); +sample.setUint8(2, 76); +sample.setUint8(3, 76); +sample.setUint8(4, 75); +sample.setUint8(5, 75); +sample.setUint8(6, 76); +sample.setUint8(7, 76); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 2; + } +}; + +assert.sameValue(sample.getFloat32(-0), 13323340, "-0"); +assert.sameValue(sample.getFloat32(obj1), 53292336, "object's valueOf"); +assert.sameValue(sample.getFloat32(obj2), 53554476, "object's toString"); +assert.sameValue(sample.getFloat32(""), 13323340, "the Empty string"); +assert.sameValue(sample.getFloat32("0"), 13323340, "string '0'"); +assert.sameValue(sample.getFloat32("2"), 53554476, "string '2'"); +assert.sameValue(sample.getFloat32(true), 13388875, "true"); +assert.sameValue(sample.getFloat32(false), 13323340, "false"); +assert.sameValue(sample.getFloat32(NaN), 13323340, "NaN"); +assert.sameValue(sample.getFloat32(null), 13323340, "null"); +assert.sameValue(sample.getFloat32(0.1), 13323340, "0.1"); +assert.sameValue(sample.getFloat32(0.9), 13323340, "0.9"); +assert.sameValue(sample.getFloat32(1.1), 13388875, "1.1"); +assert.sameValue(sample.getFloat32(1.9), 13388875, "1.9"); +assert.sameValue(sample.getFloat32(-0.1), 13323340, "-0.1"); +assert.sameValue(sample.getFloat32(-0.99999), 13323340, "-0.99999"); +assert.sameValue(sample.getFloat32(undefined), 13323340, "undefined"); +assert.sameValue(sample.getFloat32(), 13323340, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..1db01cc751 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getfloat64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(10); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getFloat64(-1); +}); + +assert.throws(RangeError, function() { + sample.getFloat64(Infinity); +}, "Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..89545900a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getfloat64 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getFloat64(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer.js new file mode 100644 index 0000000000..a54269d581 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/detached-buffer.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-dataview.prototype.getfloat64 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getFloat64(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js new file mode 100644 index 0000000000..ca5220cdf4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/index-is-out-of-range.js @@ -0,0 +1,101 @@ +// 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-dataview.prototype.getfloat64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat64(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getFloat64(13); +}, "13 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(12); +}, "12 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(11); +}, "11 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(10); +}, "10 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(9); +}, "9 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(8); +}, "8 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(7); +}, "7 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(6); +}, "6 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.getFloat64(5); +}, "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getFloat64(1); +}, "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getFloat64(0); +}, "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, function() { + sample.getFloat64(1); +}, "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, function() { + sample.getFloat64(0); +}, "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, function() { + sample.getFloat64(1); +}, "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, function() { + sample.getFloat64(0); +}, "0 + 8 > 7 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/length.js new file mode 100644 index 0000000000..3a2a4d7fcf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat64 +description: > + DataView.prototype.getFloat64.length is 1. +info: | + DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getFloat64.length, 1); + +verifyNotEnumerable(DataView.prototype.getFloat64, "length"); +verifyNotWritable(DataView.prototype.getFloat64, "length"); +verifyConfigurable(DataView.prototype.getFloat64, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/minus-zero.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/minus-zero.js new file mode 100644 index 0000000000..0b90ad4b26 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/minus-zero.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-dataview.prototype.getfloat64 +description: > + Return -0 +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 128); +sample.setUint8(1, 0); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); + +var result = sample.getFloat64(0); +assert.sameValue(result, -0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/name.js new file mode 100644 index 0000000000..2ae4d6ebae --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getfloat64 +description: > + DataView.prototype.getFloat64.name is "getFloat64". +info: | + DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getFloat64.name, "getFloat64"); + +verifyNotEnumerable(DataView.prototype.getFloat64, "name"); +verifyNotWritable(DataView.prototype.getFloat64, "name"); +verifyConfigurable(DataView.prototype.getFloat64, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..805b0a6f43 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/negative-byteoffset-throws.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-dataview.prototype.getfloat64 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getFloat64(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getFloat64(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/not-a-constructor.js new file mode 100644 index 0000000000..551e9935fa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getFloat64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getFloat64), + false, + 'isConstructor(DataView.prototype.getFloat64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getFloat64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getFloat64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/resizable-buffer.js new file mode 100644 index 0000000000..8c49e09894 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getfloat64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getFloat64(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getFloat64(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getFloat64(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..08402ae21f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.getfloat64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getFloat64(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..da490e6539 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.getfloat64 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getFloat64(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getFloat64(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-infinity.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-infinity.js new file mode 100644 index 0000000000..b7fbfce2cb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-infinity.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-dataview.prototype.getfloat64 +description: > + Return Infinity values +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 240); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), Infinity); + +sample.setUint8(0, 255); +sample.setUint8(1, 240); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), -Infinity); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-nan.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-nan.js new file mode 100644 index 0000000000..bee31fbca3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-nan.js @@ -0,0 +1,74 @@ +// 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-dataview.prototype.getfloat64 +description: > + Return NaN values +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 248); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 248, 0, ..."); + +sample.setUint8(0, 127); +sample.setUint8(1, 249); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 249, 0, ..."); + +sample.setUint8(0, 127); +sample.setUint8(1, 250); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 250, 0, ..."); + +sample.setUint8(0, 127); +sample.setUint8(1, 251); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +assert.sameValue(sample.getFloat64(0), NaN, "127, 251, 0, ..."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..d91dc40e6b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-value-clean-arraybuffer.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getfloat64 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getFloat64(0, true), 0, "sample.getFloat64(0, true)"); +assert.sameValue(sample.getFloat64(1, true), 0, "sample.getFloat64(1, true)"); +assert.sameValue(sample.getFloat64(2, true), 0, "sample.getFloat64(2, true)"); +assert.sameValue(sample.getFloat64(3, true), 0, "sample.getFloat64(3, true)"); +assert.sameValue(sample.getFloat64(4, true), 0, "sample.getFloat64(4, true)"); +assert.sameValue(sample.getFloat64(0, false), 0, "sample.getFloat64(0, false)"); +assert.sameValue(sample.getFloat64(1, false), 0, "sample.getFloat64(1, false)"); +assert.sameValue(sample.getFloat64(2, false), 0, "sample.getFloat64(2, false)"); +assert.sameValue(sample.getFloat64(3, false), 0, "sample.getFloat64(3, false)"); +assert.sameValue(sample.getFloat64(4, false), 0, "sample.getFloat64(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js new file mode 100644 index 0000000000..9bcb66017d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values-custom-offset.js @@ -0,0 +1,61 @@ +// 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-dataview.prototype.getfloat64 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(4, 67); +sample.setUint8(5, 67); +sample.setUint8(6, 68); +sample.setUint8(7, 68); +sample.setUint8(8, 67); +sample.setUint8(9, 67); +sample.setUint8(10, 68); +sample.setUint8(11, 68); +sample.setUint8(12, 67); +sample.setUint8(13, 67); +sample.setUint8(14, 68); +sample.setUint8(15, 68); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getFloat64(0, false), 10846169068898440, "0"); +assert.sameValue(sample.getFloat64(1, false), 11409110432516230, "1"); +assert.sameValue(sample.getFloat64(2, false), 747563348316297500000, "2"); +assert.sameValue(sample.getFloat64(3, false), 710670423110242000000, "3"); +assert.sameValue(sample.getFloat64(4, false), 10846169068898440, "4"); + +assert.sameValue(sample.getFloat64(0, true), 747563348316297500000, "0, true"); +assert.sameValue(sample.getFloat64(1, true), 11409110432516230, "1, true"); +assert.sameValue(sample.getFloat64(2, true), 10846169068898440, "2, true"); +assert.sameValue(sample.getFloat64(3, true), 710670423110242000000, "3, true"); +assert.sameValue(sample.getFloat64(4, true), 747563348316297500000, "4, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values.js new file mode 100644 index 0000000000..1f279d40b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/return-values.js @@ -0,0 +1,71 @@ +// 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-dataview.prototype.getfloat64 +description: > + Return values from Buffer +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(16); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 67); +sample.setUint8(1, 67); +sample.setUint8(2, 68); +sample.setUint8(3, 68); +sample.setUint8(4, 67); +sample.setUint8(5, 67); +sample.setUint8(6, 68); +sample.setUint8(7, 68); +sample.setUint8(8, 67); +sample.setUint8(9, 67); +sample.setUint8(10, 68); +sample.setUint8(11, 68); +sample.setUint8(12, 0); +sample.setUint8(13, 0); +sample.setUint8(14, 0); +sample.setUint8(15, 0); + +assert.sameValue(sample.getFloat64(0, false), 10846169068898440, "0, false"); +assert.sameValue(sample.getFloat64(1, false), 11409110432516230, "1, false"); +assert.sameValue(sample.getFloat64(2, false), 747563348316297500000, "2, false"); +assert.sameValue(sample.getFloat64(3, false), 710670423110242000000, "3, false"); +assert.sameValue(sample.getFloat64(4, false), 10846169068898440, "4, false"); +assert.sameValue(sample.getFloat64(5, false), 11409110432516096, "5, false"); +assert.sameValue(sample.getFloat64(6, false), 747563348314040600000, "6, false"); +assert.sameValue(sample.getFloat64(7, false), 710670422532459300000, "7, false"); +assert.sameValue(sample.getFloat64(8, false), 10846166811934720, "8, false"); + +assert.sameValue(sample.getFloat64(0, true), 747563348316297500000, "0, true"); +assert.sameValue(sample.getFloat64(1, true), 11409110432516230, "1, true"); +assert.sameValue(sample.getFloat64(2, true), 10846169068898440, "2, true"); +assert.sameValue(sample.getFloat64(3, true), 710670423110242000000, "3, true"); +assert.sameValue(sample.getFloat64(4, true), 747563348316297500000, "4, true"); +assert.sameValue(sample.getFloat64(5, true), 2.254739805726094e-307, "5, true"); +assert.sameValue(sample.getFloat64(6, true), 3.7084555987028e-310, "6, true"); +assert.sameValue(sample.getFloat64(7, true), 1.44861546824e-312, "7, true"); +assert.sameValue(sample.getFloat64(8, true), 5.65865417e-315, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..5ed74af898 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getfloat64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getFloat64 = DataView.prototype.getFloat64; + +assert.throws(TypeError, function() { + getFloat64.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getFloat64.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getFloat64.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getFloat64.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-is-not-object.js new file mode 100644 index 0000000000..38b3a8f02f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/this-is-not-object.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-dataview.prototype.getfloat64 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getFloat64 = DataView.prototype.getFloat64; + +assert.throws(TypeError, function() { + getFloat64.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getFloat64.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getFloat64.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getFloat64.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getFloat64.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getFloat64.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getFloat64.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.js new file mode 100644 index 0000000000..9e5c105837 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/to-boolean-littleendian.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-dataview.prototype.getfloat64 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 67); +sample.setUint8(1, 17); +sample.setUint8(2, 0); +sample.setUint8(3, 0); +sample.setUint8(4, 0); +sample.setUint8(5, 0); +sample.setUint8(6, 20); +sample.setUint8(7, 68); + +// False +assert.sameValue(sample.getFloat64(0), 1196268651021585, "no arg"); +assert.sameValue(sample.getFloat64(0, undefined), 1196268651021585, "undefined"); +assert.sameValue(sample.getFloat64(0, null), 1196268651021585, "null"); +assert.sameValue(sample.getFloat64(0, 0), 1196268651021585, "0"); +assert.sameValue(sample.getFloat64(0, ""), 1196268651021585, "the empty string"); + +// True +assert.sameValue(sample.getFloat64(0, {}), 92233720368620160000, "{}"); +assert.sameValue(sample.getFloat64(0, Symbol("1")), 92233720368620160000, "symbol"); +assert.sameValue(sample.getFloat64(0, 1), 92233720368620160000, "1"); +assert.sameValue(sample.getFloat64(0, "string"), 92233720368620160000, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/toindex-byteoffset.js new file mode 100644 index 0000000000..4b8a79a93e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getFloat64/toindex-byteoffset.js @@ -0,0 +1,70 @@ +// 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-dataview.prototype.getfloat64 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Float64"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 67); +sample.setUint8(1, 67); +sample.setUint8(2, 68); +sample.setUint8(3, 68); +sample.setUint8(4, 67); +sample.setUint8(5, 67); +sample.setUint8(6, 68); +sample.setUint8(7, 68); +sample.setUint8(8, 67); +sample.setUint8(9, 68); +sample.setUint8(10, 68); +sample.setUint8(11, 68); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getFloat64(-0), 10846169068898440, "-0"); +assert.sameValue(sample.getFloat64(obj1), 747563348316297600000, "{}.valueOf"); +assert.sameValue(sample.getFloat64(obj2), 710670423110275600000, "{}.toString"); +assert.sameValue(sample.getFloat64(""), 10846169068898440, "the Empty string"); +assert.sameValue(sample.getFloat64("0"), 10846169068898440, "string '0'"); +assert.sameValue(sample.getFloat64("2"), 747563348316297600000, "string '2'"); +assert.sameValue(sample.getFloat64(true), 11409110432516230, "true"); +assert.sameValue(sample.getFloat64(false), 10846169068898440, "false"); +assert.sameValue(sample.getFloat64(NaN), 10846169068898440, "NaN"); +assert.sameValue(sample.getFloat64(null), 10846169068898440, "null"); +assert.sameValue(sample.getFloat64(0.1), 10846169068898440, "0.1"); +assert.sameValue(sample.getFloat64(0.9), 10846169068898440, "0.9"); +assert.sameValue(sample.getFloat64(1.1), 11409110432516230, "1.1"); +assert.sameValue(sample.getFloat64(1.9), 11409110432516230, "1.9"); +assert.sameValue(sample.getFloat64(-0.1), 10846169068898440, "-0.1"); +assert.sameValue(sample.getFloat64(-0.99999), 10846169068898440, "-0.99999"); +assert.sameValue(sample.getFloat64(undefined), 10846169068898440, "undefined"); +assert.sameValue(sample.getFloat64(), 10846169068898440, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..9ddf478102 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getint16 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getInt16(Infinity); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.getInt16(-1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..01ee8c16eb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getint16 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getInt16(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer.js new file mode 100644 index 0000000000..e78b10a0b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/detached-buffer.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-dataview.prototype.getint16 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getInt16(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/index-is-out-of-range.js new file mode 100644 index 0000000000..8f3e37ad5a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/index-is-out-of-range.js @@ -0,0 +1,77 @@ +// 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-dataview.prototype.getint16 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt16(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getInt16(13); +}, "13 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.getInt16(12); +}, "12 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.getInt16(11); +}, "11 + 2 > 12"); + +sample = new DataView(buffer, 10); +assert.throws(RangeError, function() { + sample.getInt16(1); +}, "1 + 2 > 2 (offset)"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.getInt16(0); +}, "0 + 2 > 1 (offset)"); + +sample = new DataView(buffer, 0, 2); +assert.throws(RangeError, function() { + sample.getInt16(1); +}, "1 + 2 > 2 (length)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.getInt16(0); +}, "0 + 2 > 1 (length)"); + +sample = new DataView(buffer, 4, 2); +assert.throws(RangeError, function() { + sample.getInt16(1); +}, "1 + 2 > 2 (offset+length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.getInt16(0); +}, "0 + 2 > 1 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/length.js new file mode 100644 index 0000000000..c3b2db9ee3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint16 +description: > + DataView.prototype.getInt16.length is 1. +info: | + DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getInt16.length, 1); + +verifyNotEnumerable(DataView.prototype.getInt16, "length"); +verifyNotWritable(DataView.prototype.getInt16, "length"); +verifyConfigurable(DataView.prototype.getInt16, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/name.js new file mode 100644 index 0000000000..933b5b3ddf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint16 +description: > + DataView.prototype.getInt16.name is "getInt16". +info: | + DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getInt16.name, "getInt16"); + +verifyNotEnumerable(DataView.prototype.getInt16, "name"); +verifyNotWritable(DataView.prototype.getInt16, "name"); +verifyConfigurable(DataView.prototype.getInt16, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/negative-byteoffset-throws.js new file mode 100644 index 0000000000..0fdcc6abce --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/negative-byteoffset-throws.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-dataview.prototype.getint16 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt16(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getInt16(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/not-a-constructor.js new file mode 100644 index 0000000000..f4a3a72970 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getInt16 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getInt16), + false, + 'isConstructor(DataView.prototype.getInt16) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getInt16(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getInt16(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/resizable-buffer.js new file mode 100644 index 0000000000..3b5200371f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getint16 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getInt16(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getInt16(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getInt16(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..d70faf99e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.getint16 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getInt16(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..7909079e7b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.getint16 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getInt16(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getInt16(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..2ff28e4087 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-value-clean-arraybuffer.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getint16 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(6); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getInt16(0, true), 0, "sample.getInt16(0, true)"); +assert.sameValue(sample.getInt16(1, true), 0, "sample.getInt16(1, true)"); +assert.sameValue(sample.getInt16(2, true), 0, "sample.getInt16(2, true)"); +assert.sameValue(sample.getInt16(3, true), 0, "sample.getInt16(3, true)"); +assert.sameValue(sample.getInt16(4, true), 0, "sample.getInt16(4, true)"); +assert.sameValue(sample.getInt16(0, false), 0, "sample.getInt16(0, false)"); +assert.sameValue(sample.getInt16(1, false), 0, "sample.getInt16(1, false)"); +assert.sameValue(sample.getInt16(2, false), 0, "sample.getInt16(2, false)"); +assert.sameValue(sample.getInt16(3, false), 0, "sample.getInt16(3, false)"); +assert.sameValue(sample.getInt16(4, false), 0, "sample.getInt16(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values-custom-offset.js new file mode 100644 index 0000000000..83142c0a0a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values-custom-offset.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-dataview.prototype.getint16 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 2); +sample.setUint8(2, 6); +sample.setUint8(3, 2); +sample.setUint8(4, 128); +sample.setUint8(5, 42); +sample.setUint8(6, 128); +sample.setUint8(7, 39); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getInt16(0, false), -32726, "0, false"); +assert.sameValue(sample.getInt16(1, false), 10880, "1, false"); +assert.sameValue(sample.getInt16(2, false), -32729, "2, false"); + +assert.sameValue(sample.getInt16(0, true), 10880, "0, true"); +assert.sameValue(sample.getInt16(1, true), -32726, "1, true"); +assert.sameValue(sample.getInt16(2, true), 10112, "2, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values.js new file mode 100644 index 0000000000..79ae5ccb36 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/return-values.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-dataview.prototype.getint16 +description: > + Return values from Buffer +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 1); +sample.setUint8(7, 0); + +assert.sameValue(sample.getInt16(0, false), 32767, "0, false"); +assert.sameValue(sample.getInt16(1, false), -1, "1, false"); +assert.sameValue(sample.getInt16(2, false), -1, "2, false"); +assert.sameValue(sample.getInt16(3, false), -128, "3, false"); +assert.sameValue(sample.getInt16(4, false), -32768, "4, false"); +assert.sameValue(sample.getInt16(5, false), 1, "5, false"); +assert.sameValue(sample.getInt16(6, false), 256, "8, false"); + +assert.sameValue(sample.getInt16(0, true), -129, "0, true"); +assert.sameValue(sample.getInt16(1, true), -1, "1, true"); +assert.sameValue(sample.getInt16(2, true), -1, "2, true"); +assert.sameValue(sample.getInt16(3, true), -32513, "3, true"); +assert.sameValue(sample.getInt16(4, true), 128, "4, true"); +assert.sameValue(sample.getInt16(5, true), 256, "5, true"); +assert.sameValue(sample.getInt16(6, true), 1, "6, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..a0fe0077b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getint16 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getInt16 = DataView.prototype.getInt16; + +assert.throws(TypeError, function() { + getInt16.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getInt16.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getInt16.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getInt16.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-is-not-object.js new file mode 100644 index 0000000000..c575a133c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/this-is-not-object.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-dataview.prototype.getint16 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getInt16 = DataView.prototype.getInt16; + +assert.throws(TypeError, function() { + getInt16.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getInt16.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getInt16.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getInt16.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getInt16.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getInt16.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getInt16.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/to-boolean-littleendian.js new file mode 100644 index 0000000000..1965519971 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/to-boolean-littleendian.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-dataview.prototype.getint16 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 42); + +// False +assert.sameValue(sample.getInt16(0), 42, "no arg"); +assert.sameValue(sample.getInt16(0, undefined), 42, "undefined"); +assert.sameValue(sample.getInt16(0, null), 42, "null"); +assert.sameValue(sample.getInt16(0, 0), 42, "0"); +assert.sameValue(sample.getInt16(0, ""), 42, "the empty string"); + +// True +assert.sameValue(sample.getInt16(0, {}), 10752, "{}"); +assert.sameValue(sample.getInt16(0, Symbol("1")), 10752, "symbol"); +assert.sameValue(sample.getInt16(0, 1), 10752, "1"); +assert.sameValue(sample.getInt16(0, "string"), 10752, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt16/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/toindex-byteoffset.js new file mode 100644 index 0000000000..0980996a0f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt16/toindex-byteoffset.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-dataview.prototype.getint16 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 1); +sample.setUint8(3, 127); +sample.setUint8(4, 255); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getInt16(-0), 32767, "-0"); +assert.sameValue(sample.getInt16(obj1), 383, "object's valueOf"); +assert.sameValue(sample.getInt16(obj2), 32767, "object's toString"); +assert.sameValue(sample.getInt16(""), 32767, "the Empty string"); +assert.sameValue(sample.getInt16("0"), 32767, "string '0'"); +assert.sameValue(sample.getInt16("2"), 383, "string '2'"); +assert.sameValue(sample.getInt16(true), -255, "true"); +assert.sameValue(sample.getInt16(false), 32767, "false"); +assert.sameValue(sample.getInt16(NaN), 32767, "NaN"); +assert.sameValue(sample.getInt16(null), 32767, "null"); +assert.sameValue(sample.getInt16(0.1), 32767, "0.1"); +assert.sameValue(sample.getInt16(0.9), 32767, "0.9"); +assert.sameValue(sample.getInt16(1.1), -255, "1.1"); +assert.sameValue(sample.getInt16(1.9), -255, "1.9"); +assert.sameValue(sample.getInt16(-0.1), 32767, "-0.1"); +assert.sameValue(sample.getInt16(-0.99999), 32767, "-0.99999"); +assert.sameValue(sample.getInt16(undefined), 32767, "undefined"); +assert.sameValue(sample.getInt16(), 32767, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..d17f14ce40 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getint32 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getInt32(Infinity); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.getInt32(-1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..0c96f44541 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getint32 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getInt32(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer.js new file mode 100644 index 0000000000..7181df08b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/detached-buffer.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-dataview.prototype.getint32 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getInt32(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js new file mode 100644 index 0000000000..602fa1d02e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js @@ -0,0 +1,88 @@ +// |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-dataview.prototype.getint32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt32(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getInt32(13); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(12); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(11); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(10); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(9); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range.js new file mode 100644 index 0000000000..4aef5a4fa5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/index-is-out-of-range.js @@ -0,0 +1,85 @@ +// 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-dataview.prototype.getint32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt32(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getInt32(13); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(12); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(11); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(10); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(9); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/length.js new file mode 100644 index 0000000000..746487b54a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +description: > + DataView.prototype.getInt32.length is 1. +info: | + DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getInt32.length, 1); + +verifyNotEnumerable(DataView.prototype.getInt32, "length"); +verifyNotWritable(DataView.prototype.getInt32, "length"); +verifyConfigurable(DataView.prototype.getInt32, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/name.js new file mode 100644 index 0000000000..7c44bd6960 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +description: > + DataView.prototype.getInt32.name is "getInt32". +info: | + DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getInt32.name, "getInt32"); + +verifyNotEnumerable(DataView.prototype.getInt32, "name"); +verifyNotWritable(DataView.prototype.getInt32, "name"); +verifyConfigurable(DataView.prototype.getInt32, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js new file mode 100644 index 0000000000..15880f875f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js @@ -0,0 +1,36 @@ +// |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-dataview.prototype.getint32 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt32(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getInt32(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws.js new file mode 100644 index 0000000000..6ef2feeca2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws.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-dataview.prototype.getint32 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt32(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getInt32(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/not-a-constructor.js new file mode 100644 index 0000000000..2e987dc405 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getInt32 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getInt32), + false, + 'isConstructor(DataView.prototype.getInt32) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getInt32(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getInt32(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/resizable-buffer.js new file mode 100644 index 0000000000..71ce0c59d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getint32 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getInt32(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getInt32(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getInt32(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js new file mode 100644 index 0000000000..f95d0faa8b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js @@ -0,0 +1,48 @@ +// |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-dataview.prototype.getint32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getInt32(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getInt32(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js new file mode 100644 index 0000000000..99df359a2b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js @@ -0,0 +1,34 @@ +// |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-dataview.prototype.getint32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [SharedArrayBuffer, Symbol] +---*/ + +var buffer = new SharedArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getInt32(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..1c856d8864 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.getint32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getInt32(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..b1d873f647 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.getint32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getInt32(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getInt32(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js new file mode 100644 index 0000000000..3cd441d8b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js @@ -0,0 +1,47 @@ +// |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-dataview.prototype.getint32 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getInt32(0, true), 0, "sample.getInt32(0, true)"); +assert.sameValue(sample.getInt32(1, true), 0, "sample.getInt32(1, true)"); +assert.sameValue(sample.getInt32(2, true), 0, "sample.getInt32(2, true)"); +assert.sameValue(sample.getInt32(3, true), 0, "sample.getInt32(3, true)"); +assert.sameValue(sample.getInt32(4, true), 0, "sample.getInt32(4, true)"); +assert.sameValue(sample.getInt32(0, false), 0, "sample.getInt32(0, false)"); +assert.sameValue(sample.getInt32(1, false), 0, "sample.getInt32(1, false)"); +assert.sameValue(sample.getInt32(2, false), 0, "sample.getInt32(2, false)"); +assert.sameValue(sample.getInt32(3, false), 0, "sample.getInt32(3, false)"); +assert.sameValue(sample.getInt32(4, false), 0, "sample.getInt32(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..fc6a3d5d28 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getint32 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getInt32(0, true), 0, "sample.getInt32(0, true)"); +assert.sameValue(sample.getInt32(1, true), 0, "sample.getInt32(1, true)"); +assert.sameValue(sample.getInt32(2, true), 0, "sample.getInt32(2, true)"); +assert.sameValue(sample.getInt32(3, true), 0, "sample.getInt32(3, true)"); +assert.sameValue(sample.getInt32(4, true), 0, "sample.getInt32(4, true)"); +assert.sameValue(sample.getInt32(0, false), 0, "sample.getInt32(0, false)"); +assert.sameValue(sample.getInt32(1, false), 0, "sample.getInt32(1, false)"); +assert.sameValue(sample.getInt32(2, false), 0, "sample.getInt32(2, false)"); +assert.sameValue(sample.getInt32(3, false), 0, "sample.getInt32(3, false)"); +assert.sameValue(sample.getInt32(4, false), 0, "sample.getInt32(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js new file mode 100644 index 0000000000..f917d7cad2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js @@ -0,0 +1,61 @@ +// |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-dataview.prototype.getint32 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 39); +sample.setUint8(1, 2); +sample.setUint8(2, 6); +sample.setUint8(3, 2); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 128); +sample.setUint8(7, 1); +sample.setUint8(8, 127); +sample.setUint8(9, 0); +sample.setUint8(10, 127); +sample.setUint8(11, 1); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getInt32(0, false), -2147450879, "0, false"); +assert.sameValue(sample.getInt32(1, false), 8388991, "1, false"); +assert.sameValue(sample.getInt32(2, false), -2147385600, "2, false"); +assert.sameValue(sample.getInt32(3, false), 25100415, "3, false"); + +assert.sameValue(sample.getInt32(0, true), 25165952, "0, true"); +assert.sameValue(sample.getInt32(1, true), 2130804736, "1, true"); +assert.sameValue(sample.getInt32(2, true), 8323456, "2, true"); +assert.sameValue(sample.getInt32(3, true), 2130738945, "3, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset.js new file mode 100644 index 0000000000..8023175309 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-custom-offset.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-dataview.prototype.getint32 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 39); +sample.setUint8(1, 2); +sample.setUint8(2, 6); +sample.setUint8(3, 2); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 128); +sample.setUint8(7, 1); +sample.setUint8(8, 127); +sample.setUint8(9, 0); +sample.setUint8(10, 127); +sample.setUint8(11, 1); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getInt32(0, false), -2147450879, "0, false"); +assert.sameValue(sample.getInt32(1, false), 8388991, "1, false"); +assert.sameValue(sample.getInt32(2, false), -2147385600, "2, false"); +assert.sameValue(sample.getInt32(3, false), 25100415, "3, false"); + +assert.sameValue(sample.getInt32(0, true), 25165952, "0, true"); +assert.sameValue(sample.getInt32(1, true), 2130804736, "1, true"); +assert.sameValue(sample.getInt32(2, true), 8323456, "2, true"); +assert.sameValue(sample.getInt32(3, true), 2130738945, "3, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-sab.js new file mode 100644 index 0000000000..8329958dfd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values-sab.js @@ -0,0 +1,69 @@ +// |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-dataview.prototype.getint32 +description: > + Return values from Buffer +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +sample.setUint8(8, 1); +sample.setUint8(9, 0); +sample.setUint8(10, 0); +sample.setUint8(11, 0); + +assert.sameValue(sample.getInt32(0, false), 2147483647, "0, false"); // 2**32-1 +assert.sameValue(sample.getInt32(1, false), -128, "1, false"); +assert.sameValue(sample.getInt32(2, false), -32768, "2, false"); +assert.sameValue(sample.getInt32(3, false), -8388608, "3, false"); +assert.sameValue(sample.getInt32(4, false), -2147483648, "4, false"); +assert.sameValue(sample.getInt32(5, false), 1, "5, false"); +assert.sameValue(sample.getInt32(6, false), 256, "6, false"); +assert.sameValue(sample.getInt32(7, false), 65536, "7, false"); +assert.sameValue(sample.getInt32(8, false), 16777216, "8, false"); + +assert.sameValue(sample.getInt32(0, true), -129, "0, true"); +assert.sameValue(sample.getInt32(1, true), -2130706433, "1, true"); +assert.sameValue(sample.getInt32(2, true), 8454143, "2, true"); +assert.sameValue(sample.getInt32(3, true), 33023, "3, true"); +assert.sameValue(sample.getInt32(4, true), 128, "4, true"); +assert.sameValue(sample.getInt32(5, true), 16777216, "5, true"); +assert.sameValue(sample.getInt32(6, true), 65536, "6, true"); +assert.sameValue(sample.getInt32(7, true), 256, "7, true"); +assert.sameValue(sample.getInt32(8, true), 1, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values.js new file mode 100644 index 0000000000..3bc1bdc1cf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/return-values.js @@ -0,0 +1,67 @@ +// 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-dataview.prototype.getint32 +description: > + Return values from Buffer +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +sample.setUint8(8, 1); +sample.setUint8(9, 0); +sample.setUint8(10, 0); +sample.setUint8(11, 0); + +assert.sameValue(sample.getInt32(0, false), 2147483647, "0, false"); // 2**32-1 +assert.sameValue(sample.getInt32(1, false), -128, "1, false"); +assert.sameValue(sample.getInt32(2, false), -32768, "2, false"); +assert.sameValue(sample.getInt32(3, false), -8388608, "3, false"); +assert.sameValue(sample.getInt32(4, false), -2147483648, "4, false"); +assert.sameValue(sample.getInt32(5, false), 1, "5, false"); +assert.sameValue(sample.getInt32(6, false), 256, "6, false"); +assert.sameValue(sample.getInt32(7, false), 65536, "7, false"); +assert.sameValue(sample.getInt32(8, false), 16777216, "8, false"); + +assert.sameValue(sample.getInt32(0, true), -129, "0, true"); +assert.sameValue(sample.getInt32(1, true), -2130706433, "1, true"); +assert.sameValue(sample.getInt32(2, true), 8454143, "2, true"); +assert.sameValue(sample.getInt32(3, true), 33023, "3, true"); +assert.sameValue(sample.getInt32(4, true), 128, "4, true"); +assert.sameValue(sample.getInt32(5, true), 16777216, "5, true"); +assert.sameValue(sample.getInt32(6, true), 65536, "6, true"); +assert.sameValue(sample.getInt32(7, true), 256, "7, true"); +assert.sameValue(sample.getInt32(8, true), 1, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000..5a7522ed11 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js @@ -0,0 +1,46 @@ +// |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-dataview.prototype.getint32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getInt32 = DataView.prototype.getInt32; + +assert.throws(TypeError, function() { + getInt32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getInt32.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(1); +assert.throws(TypeError, function() { + getInt32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getInt32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..a08b447ed2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getint32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getInt32 = DataView.prototype.getInt32; + +assert.throws(TypeError, function() { + getInt32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getInt32.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getInt32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getInt32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-is-not-object.js new file mode 100644 index 0000000000..8202cd92ff --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/this-is-not-object.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-dataview.prototype.getint32 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getInt32 = DataView.prototype.getInt32; + +assert.throws(TypeError, function() { + getInt32.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getInt32.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getInt32.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getInt32.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getInt32.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getInt32.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getInt32.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js new file mode 100644 index 0000000000..8dda2db6c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js @@ -0,0 +1,54 @@ +// |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-dataview.prototype.getint32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer, Symbol] +---*/ + +var buffer = new SharedArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 17); +sample.setUint8(2, 4); +sample.setUint8(3, 0); + +// False +assert.sameValue(sample.getInt32(0), 1115136, "no arg"); +assert.sameValue(sample.getInt32(0, undefined), 1115136, "undefined"); +assert.sameValue(sample.getInt32(0, null), 1115136, "null"); +assert.sameValue(sample.getInt32(0, 0), 1115136, "0"); +assert.sameValue(sample.getInt32(0, ""), 1115136, "the empty string"); + +// True +assert.sameValue(sample.getInt32(0, {}), 266496, "{}"); +assert.sameValue(sample.getInt32(0, Symbol("1")), 266496, "symbol"); +assert.sameValue(sample.getInt32(0, 1), 266496, "1"); +assert.sameValue(sample.getInt32(0, "string"), 266496, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian.js new file mode 100644 index 0000000000..63fff2b458 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/to-boolean-littleendian.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-dataview.prototype.getint32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 17); +sample.setUint8(2, 4); +sample.setUint8(3, 0); + +// False +assert.sameValue(sample.getInt32(0), 1115136, "no arg"); +assert.sameValue(sample.getInt32(0, undefined), 1115136, "undefined"); +assert.sameValue(sample.getInt32(0, null), 1115136, "null"); +assert.sameValue(sample.getInt32(0, 0), 1115136, "0"); +assert.sameValue(sample.getInt32(0, ""), 1115136, "the empty string"); + +// True +assert.sameValue(sample.getInt32(0, {}), 266496, "{}"); +assert.sameValue(sample.getInt32(0, Symbol("1")), 266496, "symbol"); +assert.sameValue(sample.getInt32(0, 1), 266496, "1"); +assert.sameValue(sample.getInt32(0, "string"), 266496, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js new file mode 100644 index 0000000000..4d61b846f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js @@ -0,0 +1,68 @@ +// |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-dataview.prototype.getint32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 255); +sample.setUint8(6, 255); +sample.setUint8(7, 255); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getInt32(-0), 2147483647, "-0"); +assert.sameValue(sample.getInt32(obj1), -32513, "object's valueOf"); +assert.sameValue(sample.getInt32(obj2), -8323073, "object's toString"); +assert.sameValue(sample.getInt32(""), 2147483647, "the Empty string"); +assert.sameValue(sample.getInt32("0"), 2147483647, "string '0'"); +assert.sameValue(sample.getInt32("2"), -32513, "string '2'"); +assert.sameValue(sample.getInt32(true), -128, "true"); +assert.sameValue(sample.getInt32(false), 2147483647, "false"); +assert.sameValue(sample.getInt32(NaN), 2147483647, "NaN"); +assert.sameValue(sample.getInt32(null), 2147483647, "null"); +assert.sameValue(sample.getInt32(0.1), 2147483647, "0.1"); +assert.sameValue(sample.getInt32(0.9), 2147483647, "0.9"); +assert.sameValue(sample.getInt32(1.1), -128, "1.1"); +assert.sameValue(sample.getInt32(1.9), -128, "1.9"); +assert.sameValue(sample.getInt32(-0.1), 2147483647, "-0.1"); +assert.sameValue(sample.getInt32(-0.99999), 2147483647, "-0.99999"); +assert.sameValue(sample.getInt32(undefined), 2147483647, "undefined"); +assert.sameValue(sample.getInt32(), 2147483647, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset.js new file mode 100644 index 0000000000..fa3eda1c64 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt32/toindex-byteoffset.js @@ -0,0 +1,66 @@ +// 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-dataview.prototype.getint32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 255); +sample.setUint8(6, 255); +sample.setUint8(7, 255); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getInt32(-0), 2147483647, "-0"); +assert.sameValue(sample.getInt32(obj1), -32513, "object's valueOf"); +assert.sameValue(sample.getInt32(obj2), -8323073, "object's toString"); +assert.sameValue(sample.getInt32(""), 2147483647, "the Empty string"); +assert.sameValue(sample.getInt32("0"), 2147483647, "string '0'"); +assert.sameValue(sample.getInt32("2"), -32513, "string '2'"); +assert.sameValue(sample.getInt32(true), -128, "true"); +assert.sameValue(sample.getInt32(false), 2147483647, "false"); +assert.sameValue(sample.getInt32(NaN), 2147483647, "NaN"); +assert.sameValue(sample.getInt32(null), 2147483647, "null"); +assert.sameValue(sample.getInt32(0.1), 2147483647, "0.1"); +assert.sameValue(sample.getInt32(0.9), 2147483647, "0.9"); +assert.sameValue(sample.getInt32(1.1), -128, "1.1"); +assert.sameValue(sample.getInt32(1.9), -128, "1.9"); +assert.sameValue(sample.getInt32(-0.1), 2147483647, "-0.1"); +assert.sameValue(sample.getInt32(-0.99999), 2147483647, "-0.99999"); +assert.sameValue(sample.getInt32(undefined), 2147483647, "undefined"); +assert.sameValue(sample.getInt32(), 2147483647, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..531aa7c483 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getint8 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getInt8(Infinity); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.getInt8(-1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..9f66d5d05e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getint8 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getInt8(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer.js new file mode 100644 index 0000000000..1f7948e8e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/detached-buffer.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-dataview.prototype.getint8 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getInt8(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/index-is-out-of-range.js new file mode 100644 index 0000000000..2e666bc180 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/index-is-out-of-range.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-dataview.prototype.getint8 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt8(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getInt8(13); +}, "13 + 1 > 12"); + +assert.throws(RangeError, function() { + sample.getInt8(12); +}, "12 + 1 > 12"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.getInt8(1); +}, "1 + 1 > 1 (offset)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.getInt8(1); +}, "1 + 1 > 1 (length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.getInt8(1); +}, "1 + 1 > 1 (offset+length)"); + +sample = new DataView(buffer, 4, 0); +assert.throws(RangeError, function() { + sample.getInt8(0); +}, "0 + 1 > 0 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/length.js new file mode 100644 index 0000000000..7ad4e7999c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint8 +description: > + DataView.prototype.getInt8.length is 1. +info: | + DataView.prototype.getInt8 ( byteOffset ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getInt8.length, 1); + +verifyNotEnumerable(DataView.prototype.getInt8, "length"); +verifyNotWritable(DataView.prototype.getInt8, "length"); +verifyConfigurable(DataView.prototype.getInt8, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/name.js new file mode 100644 index 0000000000..4e56fcf221 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint8 +description: > + DataView.prototype.getInt8.name is "getInt8". +info: | + DataView.prototype.getInt8 ( byteOffset ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getInt8.name, "getInt8"); + +verifyNotEnumerable(DataView.prototype.getInt8, "name"); +verifyNotWritable(DataView.prototype.getInt8, "name"); +verifyConfigurable(DataView.prototype.getInt8, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/negative-byteoffset-throws.js new file mode 100644 index 0000000000..59a731994b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/negative-byteoffset-throws.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-dataview.prototype.getint8 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt8(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getInt8(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/not-a-constructor.js new file mode 100644 index 0000000000..8acdd1a409 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getInt8 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getInt8), + false, + 'isConstructor(DataView.prototype.getInt8) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getInt8(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getInt8(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/resizable-buffer.js new file mode 100644 index 0000000000..b7aca13ad2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getint8 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getInt8(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getInt8(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getInt8(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..810cd87041 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset-symbol.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-dataview.prototype.getint8 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getInt8(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..81039b61fd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getint8 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getInt8(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getInt8(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..a607628659 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-value-clean-arraybuffer.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-dataview.prototype.getint8 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getInt8(0), 0, "sample.getInt8(0)"); +assert.sameValue(sample.getInt8(1), 0, "sample.getInt8(1)"); +assert.sameValue(sample.getInt8(2), 0, "sample.getInt8(2)"); +assert.sameValue(sample.getInt8(3), 0, "sample.getInt8(3)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values-custom-offset.js new file mode 100644 index 0000000000..3d4581a53a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values-custom-offset.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-dataview.prototype.getint8 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 7); +sample.setUint8(1, 7); +sample.setUint8(2, 7); +sample.setUint8(3, 7); +sample.setUint8(4, 1); +sample.setUint8(5, 127); +sample.setUint8(6, 128); +sample.setUint8(7, 255); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getInt8(0), 1); +assert.sameValue(sample.getInt8(1), 127); +assert.sameValue(sample.getInt8(2), -128); +assert.sameValue(sample.getInt8(3), -1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values.js new file mode 100644 index 0000000000..444ae809ae --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/return-values.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-dataview.prototype.getint8 +description: > + Return values from Buffer +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 0); +sample.setUint8(3, 1); + +assert.sameValue(sample.getInt8(0), 127); +assert.sameValue(sample.getInt8(1), -1); +assert.sameValue(sample.getInt8(2), 0); +assert.sameValue(sample.getInt8(3), 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..1cfbfcd93d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-has-no-dataview-internal.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-dataview.prototype.getint8 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getInt8 = DataView.prototype.getInt8; + +assert.throws(TypeError, function() { + getInt8.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getInt8.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getInt8.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getInt8.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-is-not-object.js new file mode 100644 index 0000000000..fe91b28a77 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/this-is-not-object.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-dataview.prototype.getint8 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getInt8 = DataView.prototype.getInt8; + +assert.throws(TypeError, function() { + getInt8.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getInt8.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getInt8.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getInt8.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getInt8.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getInt8.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getInt8.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getInt8/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/toindex-byteoffset.js new file mode 100644 index 0000000000..08b08ef66d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getInt8/toindex-byteoffset.js @@ -0,0 +1,61 @@ +// 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-dataview.prototype.getint8 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Int8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 39); +sample.setUint8(1, 42); +sample.setUint8(2, 7); +sample.setUint8(3, 77); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getInt8(-0), 39, "-0"); +assert.sameValue(sample.getInt8(obj1), 7, "object's valueOf"); +assert.sameValue(sample.getInt8(obj2), 77, "object's toString"); +assert.sameValue(sample.getInt8(""), 39, "the Empty string"); +assert.sameValue(sample.getInt8("0"), 39, "string '0'"); +assert.sameValue(sample.getInt8("2"), 7, "string '2'"); +assert.sameValue(sample.getInt8(true), 42, "true"); +assert.sameValue(sample.getInt8(false), 39, "false"); +assert.sameValue(sample.getInt8(NaN), 39, "NaN"); +assert.sameValue(sample.getInt8(null), 39, "null"); +assert.sameValue(sample.getInt8(0.1), 39, "0.1"); +assert.sameValue(sample.getInt8(0.9), 39, "0.9"); +assert.sameValue(sample.getInt8(1.1), 42, "1.1"); +assert.sameValue(sample.getInt8(1.9), 42, "1.9"); +assert.sameValue(sample.getInt8(-0.1), 39, "-0.1"); +assert.sameValue(sample.getInt8(-0.99999), 39, "-0.99999"); +assert.sameValue(sample.getInt8(undefined), 39, "undefined"); +assert.sameValue(sample.getInt8(), 39, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..1ac2eae0aa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getuint16 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getUint16(Infinity); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.getUint16(-1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..045ed24e11 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getuint16 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getUint16(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer.js new file mode 100644 index 0000000000..bcc7fdd001 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/detached-buffer.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-dataview.prototype.getuint16 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getUint16(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/index-is-out-of-range.js new file mode 100644 index 0000000000..a040f297f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/index-is-out-of-range.js @@ -0,0 +1,77 @@ +// 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-dataview.prototype.getuint16 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getUint16(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getUint16(13); +}, "13 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.getUint16(12); +}, "12 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.getUint16(11); +}, "11 + 2 > 12"); + +sample = new DataView(buffer, 10); +assert.throws(RangeError, function() { + sample.getUint16(1); +}, "1 + 2 > 2 (offset)"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.getUint16(0); +}, "0 + 2 > 1 (offset)"); + +sample = new DataView(buffer, 0, 2); +assert.throws(RangeError, function() { + sample.getUint16(1); +}, "1 + 2 > 2 (length)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.getUint16(0); +}, "0 + 2 > 1 (length)"); + +sample = new DataView(buffer, 4, 2); +assert.throws(RangeError, function() { + sample.getUint16(1); +}, "1 + 2 > 2 (offset+length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.getUint16(0); +}, "0 + 2 > 1 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/length.js new file mode 100644 index 0000000000..3403612bf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getuint16 +description: > + DataView.prototype.getUint16.length is 1. +info: | + DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getUint16.length, 1); + +verifyNotEnumerable(DataView.prototype.getUint16, "length"); +verifyNotWritable(DataView.prototype.getUint16, "length"); +verifyConfigurable(DataView.prototype.getUint16, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/name.js new file mode 100644 index 0000000000..3c39801e23 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getuint16 +description: > + DataView.prototype.getUint16.name is "getUint16". +info: | + DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getUint16.name, "getUint16"); + +verifyNotEnumerable(DataView.prototype.getUint16, "name"); +verifyNotWritable(DataView.prototype.getUint16, "name"); +verifyConfigurable(DataView.prototype.getUint16, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/negative-byteoffset-throws.js new file mode 100644 index 0000000000..8ae049c7c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/negative-byteoffset-throws.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-dataview.prototype.getuint16 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getUint16(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getUint16(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/not-a-constructor.js new file mode 100644 index 0000000000..c56587ca00 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getUint16 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getUint16), + false, + 'isConstructor(DataView.prototype.getUint16) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getUint16(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getUint16(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/resizable-buffer.js new file mode 100644 index 0000000000..0234e3a446 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getuint16 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getUint16(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getUint16(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getUint16(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..fb98252f5c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.getuint16 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getUint16(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..6e515cc09b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.getuint16 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getUint16(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getUint16(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..e8e06c90c9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-value-clean-arraybuffer.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getuint16 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(6); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getUint16(0, true), 0, "sample.getUint16(0, true)"); +assert.sameValue(sample.getUint16(1, true), 0, "sample.getUint16(1, true)"); +assert.sameValue(sample.getUint16(2, true), 0, "sample.getUint16(2, true)"); +assert.sameValue(sample.getUint16(3, true), 0, "sample.getUint16(3, true)"); +assert.sameValue(sample.getUint16(4, true), 0, "sample.getUint16(4, true)"); +assert.sameValue(sample.getUint16(0, false), 0, "sample.getUint16(0, false)"); +assert.sameValue(sample.getUint16(1, false), 0, "sample.getUint16(1, false)"); +assert.sameValue(sample.getUint16(2, false), 0, "sample.getUint16(2, false)"); +assert.sameValue(sample.getUint16(3, false), 0, "sample.getUint16(3, false)"); +assert.sameValue(sample.getUint16(4, false), 0, "sample.getUint16(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values-custom-offset.js new file mode 100644 index 0000000000..abcdd8dd44 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values-custom-offset.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-dataview.prototype.getuint16 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 2); +sample.setUint8(2, 6); +sample.setUint8(3, 2); +sample.setUint8(4, 128); +sample.setUint8(5, 42); +sample.setUint8(6, 128); +sample.setUint8(7, 39); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getUint16(0, false), 32810, "0, false"); +assert.sameValue(sample.getUint16(1, false), 10880, "1, false"); +assert.sameValue(sample.getUint16(2, false), 32807, "2, false"); + +assert.sameValue(sample.getUint16(0, true), 10880, "0, true"); +assert.sameValue(sample.getUint16(1, true), 32810, "1, true"); +assert.sameValue(sample.getUint16(2, true), 10112, "2, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values.js new file mode 100644 index 0000000000..44d8fd1390 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/return-values.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-dataview.prototype.getuint16 +description: > + Return values from Buffer +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 1); +sample.setUint8(7, 0); + +assert.sameValue(sample.getUint16(0, false), 32767, "0, false"); +assert.sameValue(sample.getUint16(1, false), 65535, "1, false"); +assert.sameValue(sample.getUint16(2, false), 65535, "2, false"); +assert.sameValue(sample.getUint16(3, false), 65408, "3, false"); +assert.sameValue(sample.getUint16(4, false), 32768, "4, false"); +assert.sameValue(sample.getUint16(5, false), 1, "5, false"); +assert.sameValue(sample.getUint16(6, false), 256, "8, false"); + +assert.sameValue(sample.getUint16(0, true), 65407, "0, true"); +assert.sameValue(sample.getUint16(1, true), 65535, "1, true"); +assert.sameValue(sample.getUint16(2, true), 65535, "2, true"); +assert.sameValue(sample.getUint16(3, true), 33023, "3, true"); +assert.sameValue(sample.getUint16(4, true), 128, "4, true"); +assert.sameValue(sample.getUint16(5, true), 256, "5, true"); +assert.sameValue(sample.getUint16(6, true), 1, "6, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..c486fcd150 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getuint16 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getUint16 = DataView.prototype.getUint16; + +assert.throws(TypeError, function() { + getUint16.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getUint16.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getUint16.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getUint16.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-is-not-object.js new file mode 100644 index 0000000000..0128f217b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/this-is-not-object.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-dataview.prototype.getuint16 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getUint16 = DataView.prototype.getUint16; + +assert.throws(TypeError, function() { + getUint16.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getUint16.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getUint16.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getUint16.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getUint16.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getUint16.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getUint16.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/to-boolean-littleendian.js new file mode 100644 index 0000000000..168673598b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/to-boolean-littleendian.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-dataview.prototype.getuint16 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 42); + +// False +assert.sameValue(sample.getUint16(0), 42, "no arg"); +assert.sameValue(sample.getUint16(0, undefined), 42, "undefined"); +assert.sameValue(sample.getUint16(0, null), 42, "null"); +assert.sameValue(sample.getUint16(0, 0), 42, "0"); +assert.sameValue(sample.getUint16(0, ""), 42, "the empty string"); + +// True +assert.sameValue(sample.getUint16(0, {}), 10752, "{}"); +assert.sameValue(sample.getUint16(0, Symbol("1")), 10752, "symbol"); +assert.sameValue(sample.getUint16(0, 1), 10752, "1"); +assert.sameValue(sample.getUint16(0, "string"), 10752, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint16/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/toindex-byteoffset.js new file mode 100644 index 0000000000..92b175f438 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint16/toindex-byteoffset.js @@ -0,0 +1,64 @@ +// 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-dataview.prototype.getuint16 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint16"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 1); +sample.setUint8(3, 127); +sample.setUint8(4, 255); +sample.setUint8(5, 1); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getUint16(-0), 32767, "-0"); +assert.sameValue(sample.getUint16(obj1), 383, "object's valueOf"); +assert.sameValue(sample.getUint16(obj2), 32767, "object's toString"); +assert.sameValue(sample.getUint16(""), 32767, "the Empty string"); +assert.sameValue(sample.getUint16("0"), 32767, "string '0'"); +assert.sameValue(sample.getUint16("2"), 383, "string '2'"); +assert.sameValue(sample.getUint16(true), 65281, "true"); +assert.sameValue(sample.getUint16(false), 32767, "false"); +assert.sameValue(sample.getUint16(NaN), 32767, "NaN"); +assert.sameValue(sample.getUint16(null), 32767, "null"); +assert.sameValue(sample.getUint16(0.1), 32767, "0.1"); +assert.sameValue(sample.getUint16(0.9), 32767, "0.9"); +assert.sameValue(sample.getUint16(1.1), 65281, "1.1"); +assert.sameValue(sample.getUint16(1.9), 65281, "1.9"); +assert.sameValue(sample.getUint16(-0.1), 32767, "-0.1"); +assert.sameValue(sample.getUint16(-0.99999), 32767, "-0.99999"); +assert.sameValue(sample.getUint16(undefined), 32767, "undefined"); +assert.sameValue(sample.getUint16(), 32767, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..0b2d1815b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getuint32 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getUint32(Infinity); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.getUint32(-1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..0a70bf98cd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getuint32 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getUint32(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer.js new file mode 100644 index 0000000000..ab544cbb25 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/detached-buffer.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-dataview.prototype.getuint32 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getUint32(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/index-is-out-of-range.js new file mode 100644 index 0000000000..cdd6755ad4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/index-is-out-of-range.js @@ -0,0 +1,85 @@ +// 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-dataview.prototype.getuint32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getUint32(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getUint32(13); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getUint32(12); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getUint32(11); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getUint32(10); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getUint32(9); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getUint32(1); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getUint32(0); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.getUint32(1); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.getUint32(0); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.getUint32(1); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.getUint32(0); +}, "0 + 4 > 3 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/length.js new file mode 100644 index 0000000000..5ca99f56e8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getuint32 +description: > + DataView.prototype.getUint32.length is 1. +info: | + DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getUint32.length, 1); + +verifyNotEnumerable(DataView.prototype.getUint32, "length"); +verifyNotWritable(DataView.prototype.getUint32, "length"); +verifyConfigurable(DataView.prototype.getUint32, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/name.js new file mode 100644 index 0000000000..9e5f2f2a5c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getuint32 +description: > + DataView.prototype.getUint32.name is "getUint32". +info: | + DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getUint32.name, "getUint32"); + +verifyNotEnumerable(DataView.prototype.getUint32, "name"); +verifyNotWritable(DataView.prototype.getUint32, "name"); +verifyConfigurable(DataView.prototype.getUint32, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/negative-byteoffset-throws.js new file mode 100644 index 0000000000..8db5b71b0c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/negative-byteoffset-throws.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-dataview.prototype.getuint32 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getUint32(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getUint32(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/not-a-constructor.js new file mode 100644 index 0000000000..423a22224f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getUint32 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getUint32), + false, + 'isConstructor(DataView.prototype.getUint32) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getUint32(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getUint32(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/resizable-buffer.js new file mode 100644 index 0000000000..e360e676cd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getuint32 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getUint32(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getUint32(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getUint32(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..26ea0d611d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.getuint32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getUint32(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..a732fa6931 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.getuint32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getUint32(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getUint32(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..afef8f1985 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-value-clean-arraybuffer.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getuint32 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getUint32(0, true), 0, "sample.getUint32(0, true)"); +assert.sameValue(sample.getUint32(1, true), 0, "sample.getUint32(1, true)"); +assert.sameValue(sample.getUint32(2, true), 0, "sample.getUint32(2, true)"); +assert.sameValue(sample.getUint32(3, true), 0, "sample.getUint32(3, true)"); +assert.sameValue(sample.getUint32(4, true), 0, "sample.getUint32(4, true)"); +assert.sameValue(sample.getUint32(0, false), 0, "sample.getUint32(0, false)"); +assert.sameValue(sample.getUint32(1, false), 0, "sample.getUint32(1, false)"); +assert.sameValue(sample.getUint32(2, false), 0, "sample.getUint32(2, false)"); +assert.sameValue(sample.getUint32(3, false), 0, "sample.getUint32(3, false)"); +assert.sameValue(sample.getUint32(4, false), 0, "sample.getUint32(4, false)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values-custom-offset.js new file mode 100644 index 0000000000..088bd7d455 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values-custom-offset.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-dataview.prototype.getuint32 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 39); +sample.setUint8(1, 2); +sample.setUint8(2, 6); +sample.setUint8(3, 2); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 128); +sample.setUint8(7, 1); +sample.setUint8(8, 127); +sample.setUint8(9, 0); +sample.setUint8(10, 127); +sample.setUint8(11, 1); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getUint32(0, false), 2147516417, "0, false"); +assert.sameValue(sample.getUint32(1, false), 8388991, "1, false"); +assert.sameValue(sample.getUint32(2, false), 2147581696, "2, false"); +assert.sameValue(sample.getUint32(3, false), 25100415, "3, false"); + +assert.sameValue(sample.getUint32(0, true), 25165952, "0, true"); +assert.sameValue(sample.getUint32(1, true), 2130804736, "1, true"); +assert.sameValue(sample.getUint32(2, true), 8323456, "2, true"); +assert.sameValue(sample.getUint32(3, true), 2130738945, "3, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values.js new file mode 100644 index 0000000000..6162ecf080 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/return-values.js @@ -0,0 +1,67 @@ +// 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-dataview.prototype.getuint32 +description: > + Return values from Buffer +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +sample.setUint8(8, 1); +sample.setUint8(9, 0); +sample.setUint8(10, 0); +sample.setUint8(11, 0); + +assert.sameValue(sample.getUint32(0, false), 2147483647, "0, false"); +assert.sameValue(sample.getUint32(1, false), 4294967168, "1, false"); +assert.sameValue(sample.getUint32(2, false), 4294934528, "2, false"); +assert.sameValue(sample.getUint32(3, false), 4286578688, "3, false"); +assert.sameValue(sample.getUint32(4, false), 2147483648, "4, false"); +assert.sameValue(sample.getUint32(5, false), 1, "5, false"); +assert.sameValue(sample.getUint32(6, false), 256, "6, false"); +assert.sameValue(sample.getUint32(7, false), 65536, "7, false"); +assert.sameValue(sample.getUint32(8, false), 16777216, "8, false"); + +assert.sameValue(sample.getUint32(0, true), 4294967167, "0, true"); +assert.sameValue(sample.getUint32(1, true), 2164260863, "1, true"); +assert.sameValue(sample.getUint32(2, true), 8454143, "2, true"); +assert.sameValue(sample.getUint32(3, true), 33023, "3, true"); +assert.sameValue(sample.getUint32(4, true), 128, "4, true"); +assert.sameValue(sample.getUint32(5, true), 16777216, "5, true"); +assert.sameValue(sample.getUint32(6, true), 65536, "6, true"); +assert.sameValue(sample.getUint32(7, true), 256, "7, true"); +assert.sameValue(sample.getUint32(8, true), 1, "8, true"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..964bb62d3b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getuint32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getUint32 = DataView.prototype.getUint32; + +assert.throws(TypeError, function() { + getUint32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getUint32.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getUint32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getUint32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-is-not-object.js new file mode 100644 index 0000000000..2005481d0e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/this-is-not-object.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-dataview.prototype.getuint32 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getUint32 = DataView.prototype.getUint32; + +assert.throws(TypeError, function() { + getUint32.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getUint32.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getUint32.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getUint32.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getUint32.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getUint32.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getUint32.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/to-boolean-littleendian.js new file mode 100644 index 0000000000..bdeca95c5a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/to-boolean-littleendian.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-dataview.prototype.getuint32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8, Symbol] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 17); +sample.setUint8(2, 4); +sample.setUint8(3, 0); + +// False +assert.sameValue(sample.getUint32(0), 1115136, "no arg"); +assert.sameValue(sample.getUint32(0, undefined), 1115136, "undefined"); +assert.sameValue(sample.getUint32(0, null), 1115136, "null"); +assert.sameValue(sample.getUint32(0, 0), 1115136, "0"); +assert.sameValue(sample.getUint32(0, ""), 1115136, "the empty string"); + +// True +assert.sameValue(sample.getUint32(0, {}), 266496, "{}"); +assert.sameValue(sample.getUint32(0, Symbol("1")), 266496, "symbol"); +assert.sameValue(sample.getUint32(0, 1), 266496, "1"); +assert.sameValue(sample.getUint32(0, "string"), 266496, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint32/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/toindex-byteoffset.js new file mode 100644 index 0000000000..ab37b66f98 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint32/toindex-byteoffset.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-dataview.prototype.getuint32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Uint32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 255); +sample.setUint8(6, 128); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getUint32(-0), 2147483647, "-0"); +assert.sameValue(sample.getUint32(obj1), 4294934783, "object's valueOf"); +assert.sameValue(sample.getUint32(obj2), 4286644096, "object's toString"); +assert.sameValue(sample.getUint32(""), 2147483647, "the Empty string"); +assert.sameValue(sample.getUint32("0"), 2147483647, "string '0'"); +assert.sameValue(sample.getUint32("2"), 4294934783, "string '2'"); +assert.sameValue(sample.getUint32(true), 4294967168, "true"); +assert.sameValue(sample.getUint32(false), 2147483647, "false"); +assert.sameValue(sample.getUint32(NaN), 2147483647, "NaN"); +assert.sameValue(sample.getUint32(null), 2147483647, "null"); +assert.sameValue(sample.getUint32(0.1), 2147483647, "0.1"); +assert.sameValue(sample.getUint32(0.9), 2147483647, "0.9"); +assert.sameValue(sample.getUint32(1.1), 4294967168, "1.1"); +assert.sameValue(sample.getUint32(1.9), 4294967168, "1.9"); +assert.sameValue(sample.getUint32(-0.1), 2147483647, "-0.1"); +assert.sameValue(sample.getUint32(-0.99999), 2147483647, "-0.99999"); +assert.sameValue(sample.getUint32(undefined), 2147483647, "undefined"); +assert.sameValue(sample.getUint32(), 2147483647, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..db6e261aa1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.getuint8 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.getUint8(Infinity); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.getUint8(-1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..681a6b6a5d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.getuint8 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 6. Let buffer be view.[[ViewedArrayBuffer]]. + 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 11. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.getUint8(13); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer.js new file mode 100644 index 0000000000..de74096ec2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/detached-buffer.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-dataview.prototype.getuint8 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 8. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.getUint8(0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/index-is-out-of-range.js new file mode 100644 index 0000000000..919388c0ee --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/index-is-out-of-range.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-dataview.prototype.getuint8 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getUint8(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getUint8(13); +}, "13 + 1 > 12"); + +assert.throws(RangeError, function() { + sample.getUint8(12); +}, "12 + 1 > 12"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.getUint8(1); +}, "1 + 1 > 1 (offset)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.getUint8(1); +}, "1 + 1 > 1 (length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.getUint8(1); +}, "1 + 1 > 1 (offset+length)"); + +sample = new DataView(buffer, 4, 0); +assert.throws(RangeError, function() { + sample.getUint8(0); +}, "0 + 1 > 0 (offset+length)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/length.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/length.js new file mode 100644 index 0000000000..aaa458a70e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getuint8 +description: > + DataView.prototype.getUint8.length is 1. +info: | + DataView.prototype.getUint8 ( byteOffset ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getUint8.length, 1); + +verifyNotEnumerable(DataView.prototype.getUint8, "length"); +verifyNotWritable(DataView.prototype.getUint8, "length"); +verifyConfigurable(DataView.prototype.getUint8, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/name.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/name.js new file mode 100644 index 0000000000..071782c08f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getuint8 +description: > + DataView.prototype.getUint8.name is "getUint8". +info: | + DataView.prototype.getUint8 ( byteOffset ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.getUint8.name, "getUint8"); + +verifyNotEnumerable(DataView.prototype.getUint8, "name"); +verifyNotWritable(DataView.prototype.getUint8, "name"); +verifyConfigurable(DataView.prototype.getUint8, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/negative-byteoffset-throws.js new file mode 100644 index 0000000000..83e79b9408 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/negative-byteoffset-throws.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-dataview.prototype.getuint8 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getUint8(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getUint8(-Infinity); +}, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/not-a-constructor.js new file mode 100644 index 0000000000..63c22bc84a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.getUint8 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.getUint8), + false, + 'isConstructor(DataView.prototype.getUint8) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.getUint8(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.getUint8(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/resizable-buffer.js new file mode 100644 index 0000000000..a7d75e875b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.getuint8 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.getUint8(0), 0, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.getUint8(0), 0, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.getUint8(0); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..f1d359169f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset-symbol.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-dataview.prototype.getuint8 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getUint8(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..2420b6dd76 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.getuint8 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getUint8(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getUint8(bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-value-clean-arraybuffer.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-value-clean-arraybuffer.js new file mode 100644 index 0000000000..a348b7201d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-value-clean-arraybuffer.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-dataview.prototype.getuint8 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getUint8(0), 0, "sample.getUint8(0)"); +assert.sameValue(sample.getUint8(1), 0, "sample.getUint8(1)"); +assert.sameValue(sample.getUint8(2), 0, "sample.getUint8(2)"); +assert.sameValue(sample.getUint8(3), 0, "sample.getUint8(3)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values-custom-offset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values-custom-offset.js new file mode 100644 index 0000000000..33e09da452 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values-custom-offset.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-dataview.prototype.getuint8 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 7); +sample.setUint8(1, 7); +sample.setUint8(2, 7); +sample.setUint8(3, 7); +sample.setUint8(4, 1); +sample.setUint8(5, 127); +sample.setUint8(6, 128); +sample.setUint8(7, 255); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getUint8(0), 1); +assert.sameValue(sample.getUint8(1), 127); +assert.sameValue(sample.getUint8(2), 128); +assert.sameValue(sample.getUint8(3), 255); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values.js new file mode 100644 index 0000000000..f8882d7e43 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/return-values.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-dataview.prototype.getuint8 +description: > + Return values from Buffer +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 0); +sample.setUint8(3, 1); + +assert.sameValue(sample.getUint8(0), 127); +assert.sameValue(sample.getUint8(1), 255); +assert.sameValue(sample.getUint8(2), 0); +assert.sameValue(sample.getUint8(3), 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..fcb5e85a0e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-has-no-dataview-internal.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-dataview.prototype.getuint8 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var getUint8 = DataView.prototype.getUint8; + +assert.throws(TypeError, function() { + getUint8.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getUint8.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + getUint8.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getUint8.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-is-not-object.js new file mode 100644 index 0000000000..f8a9e8874e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/this-is-not-object.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-dataview.prototype.getuint8 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getUint8 = DataView.prototype.getUint8; + +assert.throws(TypeError, function() { + getUint8.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getUint8.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getUint8.call(1); +}, "1"); + +assert.throws(TypeError, function() { + getUint8.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + getUint8.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getUint8.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + getUint8.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/getUint8/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/toindex-byteoffset.js new file mode 100644 index 0000000000..61863b677d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/getUint8/toindex-byteoffset.js @@ -0,0 +1,61 @@ +// 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-dataview.prototype.getuint8 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) + + 1. Let v be the this value. + 2. Return ? GetViewValue(v, byteOffset, true, "Uint8"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.setUint8] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 39); +sample.setUint8(1, 42); +sample.setUint8(2, 7); +sample.setUint8(3, 77); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getUint8(-0), 39, "-0"); +assert.sameValue(sample.getUint8(obj1), 7, "object's valueOf"); +assert.sameValue(sample.getUint8(obj2), 77, "object's toString"); +assert.sameValue(sample.getUint8(""), 39, "the Empty string"); +assert.sameValue(sample.getUint8("0"), 39, "string '0'"); +assert.sameValue(sample.getUint8("2"), 7, "string '1'"); +assert.sameValue(sample.getUint8(true), 42, "true"); +assert.sameValue(sample.getUint8(false), 39, "false"); +assert.sameValue(sample.getUint8(NaN), 39, "NaN"); +assert.sameValue(sample.getUint8(null), 39, "null"); +assert.sameValue(sample.getUint8(0.1), 39, "0.1"); +assert.sameValue(sample.getUint8(0.9), 39, "0.9"); +assert.sameValue(sample.getUint8(1.1), 42, "1.1"); +assert.sameValue(sample.getUint8(1.9), 42, "1.9"); +assert.sameValue(sample.getUint8(-0.1), 39, "-0.1"); +assert.sameValue(sample.getUint8(-0.99999), 39, "-0.99999"); +assert.sameValue(sample.getUint8(undefined), 39, "undefined"); +assert.sameValue(sample.getUint8(), 39, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js new file mode 100644 index 0000000000..2bcb32a723 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-bigint-value.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Detached buffer is checked after ToBigInt(value) +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setBigInt64(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..2764dfe4b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-after-toindex-byteoffset.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setBigInt64(Infinity, 0); +}, "DataView access at index Infinity should throw"); + +assert.throws(RangeError, function() { + sample.setBigInt64(-1, 0); +}, "DataView access at index -1 should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..fe8b7ae517 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer-before-outofrange-byteoffset.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Detached buffer is checked before out of range byteOffset's value +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setBigInt64(13, 0); +}, "detached DataView access should throw"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer.js new file mode 100644 index 0000000000..dd3593d997 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/detached-buffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a TypeError if buffer is detached +includes: [detachArrayBuffer.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setBigInt64(0, 0n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js new file mode 100644 index 0000000000..fbe8c0dd68 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-check-before-value-conversion.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setBigInt64(-1.5, poisoned); +}, "setBigInt64(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setBigInt64(-1, poisoned); +}, "setBigInt64(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setBigInt64(-Infinity, poisoned); +}, "setBigInt64(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setBigInt64(Infinity, poisoned); +}, "setBigInt64(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js new file mode 100644 index 0000000000..acc9ff46f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/index-is-out-of-range.js @@ -0,0 +1,90 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setBigInt64(Infinity, 39n); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setBigInt64(13, 39n); +}, "13 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(12, 39n); +}, "12 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(11, 39n); +}, "11 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(10, 39n); +}, "10 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(9, 39n); +}, "9 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(8, 39n); +}, "8 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(7, 39n); +}, "7 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(6, 39n); +}, "6 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setBigInt64(5, 39n); +}, "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.setBigInt64(1, 39n); +}, "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.setBigInt64(0, 39n); +}, "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, function() { + sample.setBigInt64(1, 39n); +}, "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, function() { + sample.setBigInt64(0, 39n); +}, "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, function() { + sample.setBigInt64(1, 39n); +}, "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, function() { + sample.setBigInt64(0, 39n); +}, "0 + 8 > 7 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getBigInt64(0), 0n, "[0] no value was set"); +assert.sameValue(sample.getBigInt64(4), 0n, "[1] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/length.js new file mode 100644 index 0000000000..5fc041ceec --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: DataView.prototype.setBigInt64.length property descriptor +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.setBigInt64, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/name.js new file mode 100644 index 0000000000..d6dabab340 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: DataView.prototype.setBigInt64.name property descriptor +includes: [propertyHelper.js] +features: [DataView, ArrayBuffer, BigInt] +---*/ + +verifyProperty(DataView.prototype.setBigInt64, "name", { + value: "setBigInt64", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..f404def868 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/negative-byteoffset-throws.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a RangeError if getIndex < 0 +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setBigInt64(-1, 39n); +}, "DataView access at index -1 should throw"); +assert.sameValue(sample.getBigInt64(0), 0n, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setBigInt64(-Infinity, 39n); +}, "DataView access at index -Infinity should throw"); +assert.sameValue(sample.getBigInt64(0), 0n, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/no-value-arg.js new file mode 100644 index 0000000000..474a764b9d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/no-value-arg.js @@ -0,0 +1,16 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Set value as undefined (cast to 0) when value argument is not present +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.throws(TypeError, () => sample.setBigInt64(0)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/not-a-constructor.js new file mode 100644 index 0000000000..3d57145553 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setBigInt64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setBigInt64), + false, + 'isConstructor(DataView.prototype.setBigInt64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setBigInt64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setBigInt64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js new file mode 100644 index 0000000000..6853baf2e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/range-check-after-value-conversion.js @@ -0,0 +1,27 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Index bounds checks are performed after value conversion. +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setBigInt64(100, poisoned); +}, "setBigInt64(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setBigInt64('100', poisoned); +}, "setBigInt64('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/resizable-buffer.js new file mode 100644 index 0000000000..01187e4070 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setbigint64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setBigInt64(0, 10n), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setBigInt64(0, 20n), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setBigInt64(0, 30n); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js new file mode 100644 index 0000000000..6a7a3bedd2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value-symbol.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToBigInt(symbol value) +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setBigInt64(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js new file mode 100644 index 0000000000..3eb4d9d14c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tobigint-value.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToBigInt(value) +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf() { + throw new Test262Error(); + } +}; +var bo2 = { + toString() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setBigInt64(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setBigInt64(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..5cacaaee72 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset-symbol.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setBigInt64(s, 1n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..ed0823dca6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Return abrupt from ToNumber(byteOffset) +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf() { + throw new Test262Error(); + } +}; +var bo2 = { + toString() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setBigInt64(bo1, 1n); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setBigInt64(bo2, 1n); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js new file mode 100644 index 0000000000..932b1aa131 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-little-endian-order.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Set values on the little endian order +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setBigInt64(0, -0x6f80ff08n, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getBigInt64(0), -0x7ff806f00000001n); + +result = sample.setBigInt64(0, -0x7ff8070n, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getBigInt64(0), -0x6f80ff0700000001n); + +result = sample.setBigInt64(0, 0x6f80ff08n, true); +assert.sameValue(result, undefined, "returns undefined #3"); +assert.sameValue(sample.getBigInt64(0), 0x8ff806f00000000n); + +result = sample.setBigInt64(0, 0x8ff806fn, true); +assert.sameValue(result, undefined, "returns undefined #4"); +assert.sameValue(sample.getBigInt64(0), 0x6f80ff0800000000n); + +result = sample.setBigInt64(0, 0xf8007f90n, true); +assert.sameValue(result, undefined, "returns undefined #5"); +assert.sameValue(sample.getBigInt64(0), -0x6f80ff0800000000n); + +result = sample.setBigInt64(0, 0x907f00f8n, true); +assert.sameValue(result, undefined, "returns undefined #6"); +assert.sameValue(sample.getBigInt64(0), -0x7ff807000000000n); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js new file mode 100644 index 0000000000..b30e0667af --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/set-values-return-undefined.js @@ -0,0 +1,45 @@ +// Copyright (C) 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Set values and return undefined +includes: [byteConversionValues.js] +features: [DataView, ArrayBuffer, BigInt, arrow-function] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; + +values.forEach(function(value, i) { + if (value === undefined) { + assert.throws(TypeError, + () => sample.setBigInt64(0, BigInt(value), false), + "value: " + value); + return; + } else if (!Number.isInteger(value)) { + assert.throws(RangeError, + () => sample.setBigInt64(0, BigInt(value), false), + "value " + value); + return; + } + + var result = sample.setBigInt64(0, BigInt(value), false); + + assert.sameValue( + sample.getBigInt64(0), + BigInt(value), + "value: " + value + ); + + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..5385e5b4ab --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-has-no-dataview-internal.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var setBigInt64 = DataView.prototype.setBigInt64; + +assert.throws(TypeError, function() { + setBigInt64.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setBigInt64.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setBigInt64.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setBigInt64.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js new file mode 100644 index 0000000000..8af3056943 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/this-is-not-object.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: Throws a TypeError if this is not Object +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var setBigInt64 = DataView.prototype.setBigInt64; + +assert.throws(TypeError, function() { + setBigInt64.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setBigInt64.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setBigInt64.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setBigInt64.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setBigInt64.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setBigInt64.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setBigInt64.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js new file mode 100644 index 0000000000..5588110c7b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/to-boolean-littleendian.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + Boolean littleEndian argument coerced in ToBoolean +features: [DataView, ArrayBuffer, Symbol, BigInt] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setBigInt64(0, 1n); +assert.sameValue(sample.getBigInt64(0), 1n, "no arg"); +sample.setBigInt64(0, 2n, undefined); +assert.sameValue(sample.getBigInt64(0), 2n, "undefined"); +sample.setBigInt64(0, 3n, null); +assert.sameValue(sample.getBigInt64(0), 3n, "null"); +sample.setBigInt64(0, 4n, 0); +assert.sameValue(sample.getBigInt64(0), 4n, "0"); +sample.setBigInt64(0, 5n, ""); +assert.sameValue(sample.getBigInt64(0), 5n, "the empty string"); + +// True +sample.setBigInt64(0, 6n, {}); +assert.sameValue(sample.getBigInt64(0), 0x600000000000000n, "{}"); +sample.setBigInt64(0, 7n, Symbol("1")); +assert.sameValue(sample.getBigInt64(0), 0x700000000000000n, "symbol"); +sample.setBigInt64(0, 8n, 1); +assert.sameValue(sample.getBigInt64(0), 0x800000000000000n, "1"); +sample.setBigInt64(0, 9n, "string"); +assert.sameValue(sample.getBigInt64(0), 0x900000000000000n, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js new file mode 100644 index 0000000000..22cb07797d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigInt64/toindex-byteoffset.js @@ -0,0 +1,93 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setbigint64 +description: > + ToIndex conversions on byteOffset +features: [DataView, ArrayBuffer, BigInt] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf() { + return 3; + } +}; +var obj2 = { + toString() { + return 4; + } +}; + +sample.setBigInt64(0, 0n); +sample.setBigInt64(-0, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "-0"); + +sample.setBigInt64(3, 0n); +sample.setBigInt64(obj1, 42n); +assert.sameValue(sample.getBigInt64(3), 42n, "object's valueOf"); + +sample.setBigInt64(4, 0n); +sample.setBigInt64(obj2, 42n); +assert.sameValue(sample.getBigInt64(4), 42n, "object's toString"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64("", 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "the Empty string"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64("0", 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "string '0'"); + +sample.setBigInt64(2, 0n); +sample.setBigInt64("2", 42n); +assert.sameValue(sample.getBigInt64(2), 42n, "string '2'"); + +sample.setBigInt64(1, 0n); +sample.setBigInt64(true, 42n); +assert.sameValue(sample.getBigInt64(1), 42n, "true"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(false, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "false"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(NaN, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "NaN"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(null, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "null"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(0.1, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "0.1"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(0.9, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "0.9"); + +sample.setBigInt64(1, 0n); +sample.setBigInt64(1.1, 42n); +assert.sameValue(sample.getBigInt64(1), 42n, "1.1"); + +sample.setBigInt64(1, 0n); +sample.setBigInt64(1.9, 42n); +assert.sameValue(sample.getBigInt64(1), 42n, "1.9"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(-0.1, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "-0.1"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(-0.99999, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "-0.99999"); + +sample.setBigInt64(0, 0n); +sample.setBigInt64(undefined, 42n); +assert.sameValue(sample.getBigInt64(0), 42n, "undefined"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/not-a-constructor.js new file mode 100644 index 0000000000..393dab357e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setBigUint64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setBigUint64), + false, + 'isConstructor(DataView.prototype.setBigUint64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setBigUint64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setBigUint64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/resizable-buffer.js new file mode 100644 index 0000000000..1b43fd088c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setbiguint64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setBigUint64(0, 10n), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setBigUint64(0, 20n), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setBigUint64(0, 30n); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setBigUint64/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..ee90394567 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-number-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-dataview.prototype.setfloat32 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setFloat32(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..dc1077c90b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setfloat32 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setFloat32(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setFloat32(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..ff71c33b1b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setfloat32 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setFloat32(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer.js new file mode 100644 index 0000000000..eea576f719 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/detached-buffer.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-dataview.prototype.setfloat32 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setFloat32(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-check-before-value-conversion.js new file mode 100644 index 0000000000..423ef383f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-check-before-value-conversion.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat32 +description: > + RangeError exception for negative index is thrown before the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setFloat32(-1.5, poisoned); +}, "setFloat32(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat32(-1, poisoned); +}, "setFloat32(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat32(-Infinity, poisoned); +}, "setFloat32(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat32(Infinity, poisoned); +}, "setFloat32(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-is-out-of-range.js new file mode 100644 index 0000000000..b07b8dd70c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/index-is-out-of-range.js @@ -0,0 +1,91 @@ +// 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-dataview.prototype.setfloat32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getFloat32] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setFloat32(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setFloat32(13, 39); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat32(12, 39); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat32(11, 39); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat32(10, 39); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat32(9, 39); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.setFloat32(1, 39); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.setFloat32(0, 39); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.setFloat32(1, 39); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.setFloat32(0, 39); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.setFloat32(1, 39); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.setFloat32(0, 39); +}, "0 + 4 > 3 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getFloat32(0), 0, "[0] no value was set"); +assert.sameValue(sample.getFloat32(4), 0, "[1] no value was set"); +assert.sameValue(sample.getFloat32(8), 0, "[2] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/length.js new file mode 100644 index 0000000000..aeda1f8804 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat32 +description: > + DataView.prototype.setFloat32.length is 2. +info: | + DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setFloat32.length, 2); + +verifyNotEnumerable(DataView.prototype.setFloat32, "length"); +verifyNotWritable(DataView.prototype.setFloat32, "length"); +verifyConfigurable(DataView.prototype.setFloat32, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/name.js new file mode 100644 index 0000000000..497527f0ab --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat32 +description: > + DataView.prototype.setFloat32.name is "setFloat32". +info: | + DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setFloat32.name, "setFloat32"); + +verifyNotEnumerable(DataView.prototype.setFloat32, "name"); +verifyNotWritable(DataView.prototype.setFloat32, "name"); +verifyConfigurable(DataView.prototype.setFloat32, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/negative-byteoffset-throws.js new file mode 100644 index 0000000000..20c0219313 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/negative-byteoffset-throws.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-dataview.prototype.setfloat32 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getFloat32] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setFloat32(-1, 39); +}, "-1"); +assert.sameValue(sample.getFloat32(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setFloat32(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getFloat32(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/no-value-arg.js new file mode 100644 index 0000000000..d08fd8e5d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/no-value-arg.js @@ -0,0 +1,48 @@ +// 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-dataview.prototype.setfloat32 +description: > + Set value as undefined (cast to NaN) when value argument is not present +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 8. 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 binary32 format Not-a-Number encoding. An + implementation must always choose the same encoding for each implementation + distinguishable NaN value. + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getFloat32] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result = sample.setFloat32(0); + +assert.sameValue(sample.getFloat32(0), NaN); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/not-a-constructor.js new file mode 100644 index 0000000000..6388f109ab --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setFloat32 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setFloat32), + false, + 'isConstructor(DataView.prototype.setFloat32) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setFloat32(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setFloat32(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/range-check-after-value-conversion.js new file mode 100644 index 0000000000..b1b40bca43 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat32 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setFloat32(100, poisoned); +}, "setFloat32(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setFloat32('100', poisoned); +}, "setFloat32('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/resizable-buffer.js new file mode 100644 index 0000000000..ed19ccc21c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setfloat32 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setFloat32(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setFloat32(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setFloat32(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..82e48aa548 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.setfloat32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setFloat32(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..8b0ff850c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.setfloat32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setFloat32(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setFloat32(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..e61d0cb072 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value-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-dataview.prototype.setfloat32 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setFloat32(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..69cef138f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/return-abrupt-from-tonumber-value.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-dataview.prototype.setfloat32 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setFloat32(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setFloat32(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-little-endian-order.js new file mode 100644 index 0000000000..eee69e0496 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-little-endian-order.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-dataview.prototype.setfloat32 +description: > + Set values with little endian order. +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 8. 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 binary32 format Not-a-Number encoding. An + implementation must always choose the same encoding for each implementation + distinguishable NaN value. + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getFloat32] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setFloat32(0, 42, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getFloat32(0), 1.4441781973331565e-41); + +result = sample.setFloat32(0, 1.4441781973331565e-41, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getFloat32(0), 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-return-undefined.js new file mode 100644 index 0000000000..9e472a4be0 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/set-values-return-undefined.js @@ -0,0 +1,64 @@ +// 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-dataview.prototype.setfloat32 +description: > + Set values and return undefined +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 8. 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 binary32 format Not-a-Number encoding. An + implementation must always choose the same encoding for each implementation + distinguishable NaN value. + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getFloat32] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Float32; + +values.forEach(function(value, i) { + var result; + var expected = expectedValues[i]; + + result = sample.setFloat32(0, value, false); + + assert.sameValue( + sample.getFloat32(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..4f1af2c988 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setfloat32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setFloat32 = DataView.prototype.setFloat32; + +assert.throws(TypeError, function() { + setFloat32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setFloat32.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setFloat32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setFloat32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-is-not-object.js new file mode 100644 index 0000000000..fd94f84ce1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/this-is-not-object.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-dataview.prototype.setfloat32 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setFloat32 = DataView.prototype.setFloat32; + +assert.throws(TypeError, function() { + setFloat32.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setFloat32.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setFloat32.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setFloat32.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setFloat32.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setFloat32.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setFloat32.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/to-boolean-littleendian.js new file mode 100644 index 0000000000..3683d009b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/to-boolean-littleendian.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-dataview.prototype.setfloat32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 8. 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. [...] + ... +features: [DataView.prototype.getFloat32, Symbol] +---*/ + +var buffer = new ArrayBuffer(4); +var sample = new DataView(buffer, 0); + +// False +sample.setFloat32(0, 1); +assert.sameValue(sample.getFloat32(0), 1, "no arg"); +sample.setFloat32(0, 2, undefined); +assert.sameValue(sample.getFloat32(0), 2, "undefined"); +sample.setFloat32(0, 3, null); +assert.sameValue(sample.getFloat32(0), 3, "null"); +sample.setFloat32(0, 4, 0); +assert.sameValue(sample.getFloat32(0), 4, "0"); +sample.setFloat32(0, 5, ""); +assert.sameValue(sample.getFloat32(0), 5, "the empty string"); + +// True +sample.setFloat32(0, 6, {}); +assert.sameValue(sample.getFloat32(0), 6.89663052202102e-41, "{}"); +sample.setFloat32(0, 7, Symbol("1")); +assert.sameValue(sample.getFloat32(0), 8.04457422399591e-41, "symbol"); +sample.setFloat32(0, 8, 1); +assert.sameValue(sample.getFloat32(0), 9.10844001811131e-44, "1"); +sample.setFloat32(0, 9, "string"); +assert.sameValue(sample.getFloat32(0), 5.830802910055564e-42, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/toindex-byteoffset.js new file mode 100644 index 0000000000..6d74b98bb5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat32/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setfloat32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getFloat32] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setFloat32(0, 0); +sample.setFloat32(-0, 42); +assert.sameValue(sample.getFloat32(0), 42, "-0"); + +sample.setFloat32(3, 0); +sample.setFloat32(obj1, 42); +assert.sameValue(sample.getFloat32(3), 42, "object's valueOf"); + +sample.setFloat32(4, 0); +sample.setFloat32(obj2, 42); +assert.sameValue(sample.getFloat32(4), 42, "object's toString"); + +sample.setFloat32(0, 0); +sample.setFloat32("", 42); +assert.sameValue(sample.getFloat32(0), 42, "the Empty string"); + +sample.setFloat32(0, 0); +sample.setFloat32("0", 42); +assert.sameValue(sample.getFloat32(0), 42, "string '0'"); + +sample.setFloat32(2, 0); +sample.setFloat32("2", 42); +assert.sameValue(sample.getFloat32(2), 42, "string '2'"); + +sample.setFloat32(1, 0); +sample.setFloat32(true, 42); +assert.sameValue(sample.getFloat32(1), 42, "true"); + +sample.setFloat32(0, 0); +sample.setFloat32(false, 42); +assert.sameValue(sample.getFloat32(0), 42, "false"); + +sample.setFloat32(0, 0); +sample.setFloat32(NaN, 42); +assert.sameValue(sample.getFloat32(0), 42, "NaN"); + +sample.setFloat32(0, 0); +sample.setFloat32(null, 42); +assert.sameValue(sample.getFloat32(0), 42, "null"); + +sample.setFloat32(0, 0); +sample.setFloat32(0.1, 42); +assert.sameValue(sample.getFloat32(0), 42, "0.1"); + +sample.setFloat32(0, 0); +sample.setFloat32(0.9, 42); +assert.sameValue(sample.getFloat32(0), 42, "0.9"); + +sample.setFloat32(1, 0); +sample.setFloat32(1.1, 42); +assert.sameValue(sample.getFloat32(1), 42, "1.1"); + +sample.setFloat32(1, 0); +sample.setFloat32(1.9, 42); +assert.sameValue(sample.getFloat32(1), 42, "1.9"); + +sample.setFloat32(0, 0); +sample.setFloat32(-0.1, 42); +assert.sameValue(sample.getFloat32(0), 42, "-0.1"); + +sample.setFloat32(0, 0); +sample.setFloat32(-0.99999, 42); +assert.sameValue(sample.getFloat32(0), 42, "-0.99999"); + +sample.setFloat32(0, 0); +sample.setFloat32(undefined, 42); +assert.sameValue(sample.getFloat32(0), 42, "undefined"); + +sample.setFloat32(0, 7); +sample.setFloat32(); +assert.sameValue(sample.getFloat32(0), NaN, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..e6afffc76c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-number-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-dataview.prototype.setfloat64 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setFloat64(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..18f75ec6e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setfloat64 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setFloat64(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setFloat64(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..22267cb9f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setfloat64 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setFloat64(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer.js new file mode 100644 index 0000000000..db17b64ad3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/detached-buffer.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-dataview.prototype.setfloat64 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setFloat64(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-check-before-value-conversion.js new file mode 100644 index 0000000000..2c4e7c74bc --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat64 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(16), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setFloat64(-1.5, poisoned); +}, "setFloat64(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat64(-1, poisoned); +}, "setFloat64(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat64(-Infinity, poisoned); +}, "setFloat64(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setFloat64(Infinity, poisoned); +}, "setFloat64(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-is-out-of-range.js new file mode 100644 index 0000000000..1e241ceefb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/index-is-out-of-range.js @@ -0,0 +1,106 @@ +// 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-dataview.prototype.setfloat64 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getFloat64] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setFloat64(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setFloat64(13, 39); +}, "13 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(12, 39); +}, "12 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(11, 39); +}, "11 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(10, 39); +}, "10 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(9, 39); +}, "9 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(8, 39); +}, "8 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(7, 39); +}, "7 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(6, 39); +}, "6 + 8 > 12"); + +assert.throws(RangeError, function() { + sample.setFloat64(5, 39); +}, "5 + 8 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.setFloat64(1, 39); +}, "1 + 8 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.setFloat64(0, 39); +}, "0 + 8 > 3 (offset)"); + +sample = new DataView(buffer, 0, 8); +assert.throws(RangeError, function() { + sample.setFloat64(1, 39); +}, "1 + 8 > 8 (length)"); + +sample = new DataView(buffer, 0, 7); +assert.throws(RangeError, function() { + sample.setFloat64(0, 39); +}, "0 + 8 > 7 (length)"); + +sample = new DataView(buffer, 4, 8); +assert.throws(RangeError, function() { + sample.setFloat64(1, 39); +}, "1 + 8 > 8 (offset+length)"); + +sample = new DataView(buffer, 4, 7); +assert.throws(RangeError, function() { + sample.setFloat64(0, 39); +}, "0 + 8 > 7 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getFloat64(0), 0, "[0] no value was set"); +assert.sameValue(sample.getFloat64(4), 0, "[1] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/length.js new file mode 100644 index 0000000000..50eb0bbe97 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat64 +description: > + DataView.prototype.setFloat64.length is 2. +info: | + DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setFloat64.length, 2); + +verifyNotEnumerable(DataView.prototype.setFloat64, "length"); +verifyNotWritable(DataView.prototype.setFloat64, "length"); +verifyConfigurable(DataView.prototype.setFloat64, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/name.js new file mode 100644 index 0000000000..05ca0ec912 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat64 +description: > + DataView.prototype.setFloat64.name is "setFloat64". +info: | + DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setFloat64.name, "setFloat64"); + +verifyNotEnumerable(DataView.prototype.setFloat64, "name"); +verifyNotWritable(DataView.prototype.setFloat64, "name"); +verifyConfigurable(DataView.prototype.setFloat64, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/negative-byteoffset-throws.js new file mode 100644 index 0000000000..485d261056 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/negative-byteoffset-throws.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-dataview.prototype.setfloat64 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getFloat64] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setFloat64(-1, 39); +}, "-1"); +assert.sameValue(sample.getFloat64(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setFloat64(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getFloat64(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/no-value-arg.js new file mode 100644 index 0000000000..3add593d31 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/no-value-arg.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-dataview.prototype.setfloat64 +description: > + Set value as undefined (cast to NaN) when value argument is not present +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 9. 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 the same encoding for each implementation + distinguishable NaN value. + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getFloat64] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result = sample.setFloat64(0); + +assert.sameValue(sample.getFloat64(0), NaN); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/not-a-constructor.js new file mode 100644 index 0000000000..12ff2af998 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setFloat64 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setFloat64), + false, + 'isConstructor(DataView.prototype.setFloat64) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setFloat64(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setFloat64(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/range-check-after-value-conversion.js new file mode 100644 index 0000000000..13e06afcf6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setfloat64 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setFloat64(100, poisoned); +}, "setFloat64(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setFloat64('100', poisoned); +}, "setFloat64('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/resizable-buffer.js new file mode 100644 index 0000000000..4441e2911b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setfloat64 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setFloat64(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setFloat64(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setFloat64(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..337b76b876 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.setfloat64 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setFloat64(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..2ba52123f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.setfloat64 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setFloat64(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setFloat64(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..13e37c34c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value-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-dataview.prototype.setfloat64 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setFloat64(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..f57197fc08 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/return-abrupt-from-tonumber-value.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-dataview.prototype.setfloat64 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setFloat64(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setFloat64(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-little-endian-order.js new file mode 100644 index 0000000000..968b3b4561 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-little-endian-order.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-dataview.prototype.setfloat64 +description: > + Set values on little endian order +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 9. 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 the same encoding for each implementation + distinguishable NaN value. + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setFloat64(0, 42, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getFloat64(0), 8.759e-320); + +result = sample.setFloat64(0, 8.759e-320, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getFloat64(0), 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-return-undefined.js new file mode 100644 index 0000000000..eeee042d56 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/set-values-return-undefined.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-dataview.prototype.setfloat64 +description: > + Set values and return undefined +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 9. 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 the same encoding for each implementation + distinguishable NaN value. + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Float64; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setFloat64(0, value, false); + + assert.sameValue( + sample.getFloat64(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..8d0f7917ac --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setfloat64 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setFloat64 = DataView.prototype.setFloat64; + +assert.throws(TypeError, function() { + setFloat64.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setFloat64.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setFloat64.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setFloat64.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-is-not-object.js new file mode 100644 index 0000000000..aaceaf423f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/this-is-not-object.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-dataview.prototype.setfloat64 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setFloat64 = DataView.prototype.setFloat64; + +assert.throws(TypeError, function() { + setFloat64.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setFloat64.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setFloat64.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setFloat64.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setFloat64.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setFloat64.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setFloat64.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/to-boolean-littleendian.js new file mode 100644 index 0000000000..293506a0fa --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/to-boolean-littleendian.js @@ -0,0 +1,58 @@ +// 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-dataview.prototype.setfloat64 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 9. 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. [...] + ... +features: [DataView.prototype.getFloat64, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setFloat64(0, 1); +assert.sameValue(sample.getFloat64(0), 1, "no arg"); +sample.setFloat64(0, 2, undefined); +assert.sameValue(sample.getFloat64(0), 2, "undefined"); +sample.setFloat64(0, 3, null); +assert.sameValue(sample.getFloat64(0), 3, "null"); +sample.setFloat64(0, 4, 0); +assert.sameValue(sample.getFloat64(0), 4, "0"); +sample.setFloat64(0, 5, ""); +assert.sameValue(sample.getFloat64(0), 5, "the empty string"); + +// True +sample.setFloat64(0, 3.067e-320, {}); +assert.sameValue(sample.getFloat64(0), 6, "{}"); +sample.setFloat64(0, 3.573e-320, Symbol("1")); +assert.sameValue(sample.getFloat64(0), 7, "symbol"); +sample.setFloat64(0, 4.079e-320, 1); +assert.sameValue(sample.getFloat64(0), 8, "1"); +sample.setFloat64(0, 4.332e-320, "string"); +assert.sameValue(sample.getFloat64(0), 9, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/toindex-byteoffset.js new file mode 100644 index 0000000000..8e283a0662 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setFloat64/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setfloat64 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Float64", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getFloat64] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setFloat64(0, 0); +sample.setFloat64(-0, 42); +assert.sameValue(sample.getFloat64(0), 42, "-0"); + +sample.setFloat64(3, 0); +sample.setFloat64(obj1, 42); +assert.sameValue(sample.getFloat64(3), 42, "object's valueOf"); + +sample.setFloat64(4, 0); +sample.setFloat64(obj2, 42); +assert.sameValue(sample.getFloat64(4), 42, "object's toString"); + +sample.setFloat64(0, 0); +sample.setFloat64("", 42); +assert.sameValue(sample.getFloat64(0), 42, "the Empty string"); + +sample.setFloat64(0, 0); +sample.setFloat64("0", 42); +assert.sameValue(sample.getFloat64(0), 42, "string '0'"); + +sample.setFloat64(2, 0); +sample.setFloat64("2", 42); +assert.sameValue(sample.getFloat64(2), 42, "string '2'"); + +sample.setFloat64(1, 0); +sample.setFloat64(true, 42); +assert.sameValue(sample.getFloat64(1), 42, "true"); + +sample.setFloat64(0, 0); +sample.setFloat64(false, 42); +assert.sameValue(sample.getFloat64(0), 42, "false"); + +sample.setFloat64(0, 0); +sample.setFloat64(NaN, 42); +assert.sameValue(sample.getFloat64(0), 42, "NaN"); + +sample.setFloat64(0, 0); +sample.setFloat64(null, 42); +assert.sameValue(sample.getFloat64(0), 42, "null"); + +sample.setFloat64(0, 0); +sample.setFloat64(0.1, 42); +assert.sameValue(sample.getFloat64(0), 42, "0.1"); + +sample.setFloat64(0, 0); +sample.setFloat64(0.9, 42); +assert.sameValue(sample.getFloat64(0), 42, "0.9"); + +sample.setFloat64(1, 0); +sample.setFloat64(1.1, 42); +assert.sameValue(sample.getFloat64(1), 42, "1.1"); + +sample.setFloat64(1, 0); +sample.setFloat64(1.9, 42); +assert.sameValue(sample.getFloat64(1), 42, "1.9"); + +sample.setFloat64(0, 0); +sample.setFloat64(-0.1, 42); +assert.sameValue(sample.getFloat64(0), 42, "-0.1"); + +sample.setFloat64(0, 0); +sample.setFloat64(-0.99999, 42); +assert.sameValue(sample.getFloat64(0), 42, "-0.99999"); + +sample.setFloat64(0, 0); +sample.setFloat64(undefined, 42); +assert.sameValue(sample.getFloat64(0), 42, "undefined"); + +sample.setFloat64(0, 7); +sample.setFloat64(); +assert.sameValue(sample.getFloat64(0), NaN, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..71ef941539 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-number-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-dataview.prototype.setint16 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setInt16(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..f4a2b0550e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setint16 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setInt16(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setInt16(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..2334785e2c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setint16 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setInt16(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer.js new file mode 100644 index 0000000000..a88ffb946c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/detached-buffer.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-dataview.prototype.setint16 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setInt16(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-check-before-value-conversion.js new file mode 100644 index 0000000000..94f3a3a408 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint16 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setInt16(-1.5, poisoned); +}, "setInt16(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt16(-1, poisoned); +}, "setInt16(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt16(-Infinity, poisoned); +}, "setInt16(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt16(Infinity, poisoned); +}, "setInt16(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-is-out-of-range.js new file mode 100644 index 0000000000..9cf3b095b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/index-is-out-of-range.js @@ -0,0 +1,86 @@ +// 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-dataview.prototype.setint16 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getInt16] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setInt16(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setInt16(13, 39); +}, "13 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.setInt16(12, 39); +}, "12 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.setInt16(11, 39); +}, "11 + 2 > 12"); + +sample = new DataView(buffer, 10); +assert.throws(RangeError, function() { + sample.setInt16(1, 39); +}, "1 + 2 > 2 (offset)"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.setInt16(0, 39); +}, "0 + 2 > 1 (offset)"); + +sample = new DataView(buffer, 0, 2); +assert.throws(RangeError, function() { + sample.setInt16(1, 39); +}, "1 + 2 > 2 (length)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.setInt16(0, 39); +}, "0 + 2 > 1 (length)"); + +sample = new DataView(buffer, 4, 2); +assert.throws(RangeError, function() { + sample.setInt16(1, 39); +}, "1 + 2 > 2 (offset+length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.setInt16(0, 39); +}, "0 + 2 > 1 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getInt16(0), 0, "[0] no value was set"); +assert.sameValue(sample.getInt16(2), 0, "[1] no value was set"); +assert.sameValue(sample.getInt16(4), 0, "[2] no value was set"); +assert.sameValue(sample.getInt16(6), 0, "[3] no value was set"); +assert.sameValue(sample.getInt16(8), 0, "[4] no value was set"); +assert.sameValue(sample.getInt16(10), 0, "[5] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/length.js new file mode 100644 index 0000000000..74e11083b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint16 +description: > + DataView.prototype.setInt16.length is 2. +info: | + DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setInt16.length, 2); + +verifyNotEnumerable(DataView.prototype.setInt16, "length"); +verifyNotWritable(DataView.prototype.setInt16, "length"); +verifyConfigurable(DataView.prototype.setInt16, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/name.js new file mode 100644 index 0000000000..15220b4d94 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint16 +description: > + DataView.prototype.setInt16.name is "setInt16". +info: | + DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setInt16.name, "setInt16"); + +verifyNotEnumerable(DataView.prototype.setInt16, "name"); +verifyNotWritable(DataView.prototype.setInt16, "name"); +verifyConfigurable(DataView.prototype.setInt16, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/negative-byteoffset-throws.js new file mode 100644 index 0000000000..196b9c8114 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/negative-byteoffset-throws.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-dataview.prototype.setint16 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getInt16] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setInt16(-1, 39); +}, "-1"); +assert.sameValue(sample.getInt16(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setInt16(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getInt16(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/no-value-arg.js new file mode 100644 index 0000000000..0b6cba7ace --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/no-value-arg.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-dataview.prototype.setint16 +description: > + Set value as undefined (cast to 0) when value argument is not present +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt16] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setInt16(0, 42); + +var result = sample.setInt16(0); + +assert.sameValue(sample.getInt16(0), 0); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/not-a-constructor.js new file mode 100644 index 0000000000..b04ec4ac06 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setInt16 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setInt16), + false, + 'isConstructor(DataView.prototype.setInt16) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setInt16(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setInt16(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/range-check-after-value-conversion.js new file mode 100644 index 0000000000..5feddb7aa1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint16 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setInt16(100, poisoned); +}, "setInt16(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setInt16('100', poisoned); +}, "setInt16('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/resizable-buffer.js new file mode 100644 index 0000000000..60e526c507 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setint16 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setInt16(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setInt16(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setInt16(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..8cdfe3a475 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.setint16 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setInt16(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..024f07c36a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.setint16 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setInt16(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setInt16(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..b57bb1779f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value-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-dataview.prototype.setint16 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setInt16(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..678dbdce66 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/return-abrupt-from-tonumber-value.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-dataview.prototype.setint16 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setInt16(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setInt16(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-little-endian-order.js new file mode 100644 index 0000000000..8b08c66b6c --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-little-endian-order.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-dataview.prototype.setint16 +description: > + Set values on the little endian order +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt16] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setInt16(0, -1870724872, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getInt16(0), -2048); + +result = sample.setInt16(0, -134185072, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getInt16(0), -28545); + +result = sample.setInt16(0, 1870724872, true); +assert.sameValue(result, undefined, "returns undefined #3"); +assert.sameValue(sample.getInt16(0), 2303); + +result = sample.setInt16(0, 150962287, true); +assert.sameValue(result, undefined, "returns undefined #4"); +assert.sameValue(sample.getInt16(0), 28544); + +result = sample.setInt16(0, 4160782224, true); +assert.sameValue(result, undefined, "returns undefined #5"); +assert.sameValue(sample.getInt16(0), -28545); + +result = sample.setInt16(0, 2424242424, true); +assert.sameValue(result, undefined, "returns undefined #6"); +assert.sameValue(sample.getInt16(0), -2048); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-return-undefined.js new file mode 100644 index 0000000000..32e033aed6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/set-values-return-undefined.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-dataview.prototype.setint16 +description: > + Set values and return undefined +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt16] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Int16; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setInt16(0, value, false); + + assert.sameValue( + sample.getInt16(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..a1b16b2367 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setint16 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setInt16 = DataView.prototype.setInt16; + +assert.throws(TypeError, function() { + setInt16.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setInt16.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setInt16.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setInt16.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-is-not-object.js new file mode 100644 index 0000000000..c42e5d76bd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/this-is-not-object.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-dataview.prototype.setint16 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setInt16 = DataView.prototype.setInt16; + +assert.throws(TypeError, function() { + setInt16.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setInt16.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setInt16.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setInt16.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setInt16.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setInt16.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setInt16.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/to-boolean-littleendian.js new file mode 100644 index 0000000000..bab3bb956f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/to-boolean-littleendian.js @@ -0,0 +1,48 @@ +// 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-dataview.prototype.setint16 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). +features: [DataView.prototype.getInt16, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setInt16(0, 1); +assert.sameValue(sample.getInt16(0), 1, "no arg"); +sample.setInt16(0, 2, undefined); +assert.sameValue(sample.getInt16(0), 2, "undefined"); +sample.setInt16(0, 3, null); +assert.sameValue(sample.getInt16(0), 3, "null"); +sample.setInt16(0, 4, 0); +assert.sameValue(sample.getInt16(0), 4, "0"); +sample.setInt16(0, 5, ""); +assert.sameValue(sample.getInt16(0), 5, "the empty string"); + +// True +sample.setInt16(0, 1536, {}); +assert.sameValue(sample.getInt16(0), 6, "{}"); +sample.setInt16(0, 1792, Symbol("1")); +assert.sameValue(sample.getInt16(0), 7, "symbol"); +sample.setInt16(0, 2048, 1); +assert.sameValue(sample.getInt16(0), 8, "1"); +sample.setInt16(0, 2304, "string"); +assert.sameValue(sample.getInt16(0), 9, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt16/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/toindex-byteoffset.js new file mode 100644 index 0000000000..35216a89ce --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt16/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setint16 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getInt16] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setInt16(0, 0); +sample.setInt16(-0, 42); +assert.sameValue(sample.getInt16(0), 42, "-0"); + +sample.setInt16(3, 0); +sample.setInt16(obj1, 42); +assert.sameValue(sample.getInt16(3), 42, "object's valueOf"); + +sample.setInt16(4, 0); +sample.setInt16(obj2, 42); +assert.sameValue(sample.getInt16(4), 42, "object's toString"); + +sample.setInt16(0, 0); +sample.setInt16("", 42); +assert.sameValue(sample.getInt16(0), 42, "the Empty string"); + +sample.setInt16(0, 0); +sample.setInt16("0", 42); +assert.sameValue(sample.getInt16(0), 42, "string '0'"); + +sample.setInt16(2, 0); +sample.setInt16("2", 42); +assert.sameValue(sample.getInt16(2), 42, "string '2'"); + +sample.setInt16(1, 0); +sample.setInt16(true, 42); +assert.sameValue(sample.getInt16(1), 42, "true"); + +sample.setInt16(0, 0); +sample.setInt16(false, 42); +assert.sameValue(sample.getInt16(0), 42, "false"); + +sample.setInt16(0, 0); +sample.setInt16(NaN, 42); +assert.sameValue(sample.getInt16(0), 42, "NaN"); + +sample.setInt16(0, 0); +sample.setInt16(null, 42); +assert.sameValue(sample.getInt16(0), 42, "null"); + +sample.setInt16(0, 0); +sample.setInt16(0.1, 42); +assert.sameValue(sample.getInt16(0), 42, "0.1"); + +sample.setInt16(0, 0); +sample.setInt16(0.9, 42); +assert.sameValue(sample.getInt16(0), 42, "0.9"); + +sample.setInt16(1, 0); +sample.setInt16(1.1, 42); +assert.sameValue(sample.getInt16(1), 42, "1.1"); + +sample.setInt16(1, 0); +sample.setInt16(1.9, 42); +assert.sameValue(sample.getInt16(1), 42, "1.9"); + +sample.setInt16(0, 0); +sample.setInt16(-0.1, 42); +assert.sameValue(sample.getInt16(0), 42, "-0.1"); + +sample.setInt16(0, 0); +sample.setInt16(-0.99999, 42); +assert.sameValue(sample.getInt16(0), 42, "-0.99999"); + +sample.setInt16(0, 0); +sample.setInt16(undefined, 42); +assert.sameValue(sample.getInt16(0), 42, "undefined"); + +sample.setInt16(0, 7); +sample.setInt16(); +assert.sameValue(sample.getInt16(0), 0, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..1fee962cef --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-number-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-dataview.prototype.setint32 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setInt32(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..cfdbccf386 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setint32 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setInt32(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setInt32(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..03bfbd9630 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setint32 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setInt32(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer.js new file mode 100644 index 0000000000..609960bbf8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/detached-buffer.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-dataview.prototype.setint32 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setInt32(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-check-before-value-conversion.js new file mode 100644 index 0000000000..28678d90cd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint32 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setInt32(-1.5, poisoned); +}, "setInt32(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt32(-1, poisoned); +}, "setInt32(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt32(-Infinity, poisoned); +}, "setInt32(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt32(Infinity, poisoned); +}, "setInt32(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-is-out-of-range.js new file mode 100644 index 0000000000..93041dd8e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/index-is-out-of-range.js @@ -0,0 +1,91 @@ +// 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-dataview.prototype.setint32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getInt32] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setInt32(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setInt32(13, 39); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setInt32(12, 39); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setInt32(11, 39); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setInt32(10, 39); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setInt32(9, 39); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.setInt32(1, 39); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.setInt32(0, 39); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.setInt32(1, 39); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.setInt32(0, 39); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.setInt32(1, 39); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.setInt32(0, 39); +}, "0 + 4 > 3 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getInt32(0), 0, "[0] no value was set"); +assert.sameValue(sample.getInt32(4), 0, "[1] no value was set"); +assert.sameValue(sample.getInt32(8), 0, "[2] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/length.js new file mode 100644 index 0000000000..57bcc4db46 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint32 +description: > + DataView.prototype.setInt32.length is 2. +info: | + DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setInt32.length, 2); + +verifyNotEnumerable(DataView.prototype.setInt32, "length"); +verifyNotWritable(DataView.prototype.setInt32, "length"); +verifyConfigurable(DataView.prototype.setInt32, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/name.js new file mode 100644 index 0000000000..54f2572e30 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint32 +description: > + DataView.prototype.setInt32.name is "setInt32". +info: | + DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setInt32.name, "setInt32"); + +verifyNotEnumerable(DataView.prototype.setInt32, "name"); +verifyNotWritable(DataView.prototype.setInt32, "name"); +verifyConfigurable(DataView.prototype.setInt32, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/negative-byteoffset-throws.js new file mode 100644 index 0000000000..10e1e2181f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/negative-byteoffset-throws.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-dataview.prototype.setint32 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getInt32] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setInt32(-1, 39); +}, "-1"); +assert.sameValue(sample.getInt32(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setInt32(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getInt32(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/no-value-arg.js new file mode 100644 index 0000000000..f738757269 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/no-value-arg.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-dataview.prototype.setint32 +description: > + Set value as undefined (cast to 0) when value argument is not present +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt32] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setInt32(0, 42); + +var result = sample.setInt32(0); + +assert.sameValue(sample.getInt32(0), 0); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/not-a-constructor.js new file mode 100644 index 0000000000..2f73e1a327 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setInt32 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setInt32), + false, + 'isConstructor(DataView.prototype.setInt32) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setInt32(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setInt32(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/range-check-after-value-conversion.js new file mode 100644 index 0000000000..472769b483 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint32 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setInt32(100, poisoned); +}, "setInt32(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setInt32('100', poisoned); +}, "setInt32('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/resizable-buffer.js new file mode 100644 index 0000000000..5711b7cfbc --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setint32 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setInt32(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setInt32(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setInt32(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..86ae517e9e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.setint32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setInt32(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..45b74aa38e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.setint32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setInt32(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setInt32(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..f9e496350a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value-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-dataview.prototype.setint32 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setInt32(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..025dddab57 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/return-abrupt-from-tonumber-value.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-dataview.prototype.setint32 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setInt32(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setInt32(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-little-endian-order.js new file mode 100644 index 0000000000..041568e2c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-little-endian-order.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-dataview.prototype.setint32 +description: > + Set values on the little endian order +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt32] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setInt32(0, -1870724872, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getInt32(0), -134185072); + +result = sample.setInt32(0, -134185072, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getInt32(0), -1870724872); + +result = sample.setInt32(0, 1870724872, true); +assert.sameValue(result, undefined, "returns undefined #3"); +assert.sameValue(sample.getInt32(0), 150962287); + +result = sample.setInt32(0, 150962287, true); +assert.sameValue(result, undefined, "returns undefined #4"); +assert.sameValue(sample.getInt32(0), 1870724872); + +result = sample.setInt32(0, 4160782224, true); +assert.sameValue(result, undefined, "returns undefined #5"); +assert.sameValue(sample.getInt32(0), -1870724872); + +result = sample.setInt32(0, 2424242424, true); +assert.sameValue(result, undefined, "returns undefined #6"); +assert.sameValue(sample.getInt32(0), -134185072); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-return-undefined.js new file mode 100644 index 0000000000..bd50828e2a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/set-values-return-undefined.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-dataview.prototype.setint32 +description: > + Set values and return undefined +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt32] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Int32; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setInt32(0, value, false); + + assert.sameValue( + sample.getInt32(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..bb76600920 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setint32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setInt32 = DataView.prototype.setInt32; + +assert.throws(TypeError, function() { + setInt32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setInt32.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setInt32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setInt32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-is-not-object.js new file mode 100644 index 0000000000..21b39a6fd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/this-is-not-object.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-dataview.prototype.setint32 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setInt32 = DataView.prototype.setInt32; + +assert.throws(TypeError, function() { + setInt32.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setInt32.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setInt32.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setInt32.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setInt32.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setInt32.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setInt32.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/to-boolean-littleendian.js new file mode 100644 index 0000000000..a292f0348f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/to-boolean-littleendian.js @@ -0,0 +1,48 @@ +// 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-dataview.prototype.setint32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). +features: [DataView.prototype.getInt32, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setInt32(0, 1); +assert.sameValue(sample.getInt32(0), 1, "no arg"); +sample.setInt32(0, 2, undefined); +assert.sameValue(sample.getInt32(0), 2, "undefined"); +sample.setInt32(0, 3, null); +assert.sameValue(sample.getInt32(0), 3, "null"); +sample.setInt32(0, 4, 0); +assert.sameValue(sample.getInt32(0), 4, "0"); +sample.setInt32(0, 5, ""); +assert.sameValue(sample.getInt32(0), 5, "the empty string"); + +// True +sample.setInt32(0, 6, {}); +assert.sameValue(sample.getInt32(0), 100663296, "{}"); +sample.setInt32(0, 7, Symbol("1")); +assert.sameValue(sample.getInt32(0), 117440512, "symbol"); +sample.setInt32(0, 8, 1); +assert.sameValue(sample.getInt32(0), 134217728, "1"); +sample.setInt32(0, 9, "string"); +assert.sameValue(sample.getInt32(0), 150994944, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt32/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/toindex-byteoffset.js new file mode 100644 index 0000000000..3dcccb1bf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt32/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setint32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getInt32] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setInt32(0, 0); +sample.setInt32(-0, 42); +assert.sameValue(sample.getInt32(0), 42, "-0"); + +sample.setInt32(3, 0); +sample.setInt32(obj1, 42); +assert.sameValue(sample.getInt32(3), 42, "object's valueOf"); + +sample.setInt32(4, 0); +sample.setInt32(obj2, 42); +assert.sameValue(sample.getInt32(4), 42, "object's toString"); + +sample.setInt32(0, 0); +sample.setInt32("", 42); +assert.sameValue(sample.getInt32(0), 42, "the Empty string"); + +sample.setInt32(0, 0); +sample.setInt32("0", 42); +assert.sameValue(sample.getInt32(0), 42, "string '0'"); + +sample.setInt32(2, 0); +sample.setInt32("2", 42); +assert.sameValue(sample.getInt32(2), 42, "string '2'"); + +sample.setInt32(1, 0); +sample.setInt32(true, 42); +assert.sameValue(sample.getInt32(1), 42, "true"); + +sample.setInt32(0, 0); +sample.setInt32(false, 42); +assert.sameValue(sample.getInt32(0), 42, "false"); + +sample.setInt32(0, 0); +sample.setInt32(NaN, 42); +assert.sameValue(sample.getInt32(0), 42, "NaN"); + +sample.setInt32(0, 0); +sample.setInt32(null, 42); +assert.sameValue(sample.getInt32(0), 42, "null"); + +sample.setInt32(0, 0); +sample.setInt32(0.1, 42); +assert.sameValue(sample.getInt32(0), 42, "0.1"); + +sample.setInt32(0, 0); +sample.setInt32(0.9, 42); +assert.sameValue(sample.getInt32(0), 42, "0.9"); + +sample.setInt32(1, 0); +sample.setInt32(1.1, 42); +assert.sameValue(sample.getInt32(1), 42, "1.1"); + +sample.setInt32(1, 0); +sample.setInt32(1.9, 42); +assert.sameValue(sample.getInt32(1), 42, "1.9"); + +sample.setInt32(0, 0); +sample.setInt32(-0.1, 42); +assert.sameValue(sample.getInt32(0), 42, "-0.1"); + +sample.setInt32(0, 0); +sample.setInt32(-0.99999, 42); +assert.sameValue(sample.getInt32(0), 42, "-0.99999"); + +sample.setInt32(0, 0); +sample.setInt32(undefined, 42); +assert.sameValue(sample.getInt32(0), 42, "undefined"); + +sample.setInt32(0, 7); +sample.setInt32(); +assert.sameValue(sample.getInt32(0), 0, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..58a539fcd9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-number-value.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-dataview.prototype.setint8 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setInt8(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..5fd6958dc2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setint8 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setInt8(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setInt8(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..28cde6f371 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setint8 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setInt8(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer.js new file mode 100644 index 0000000000..86c1aa40ea --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/detached-buffer.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-dataview.prototype.setint8 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setInt8(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-check-before-value-conversion.js new file mode 100644 index 0000000000..fa111eef8d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint8 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setInt8(-1.5, poisoned); +}, "setInt8(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt8(-1, poisoned); +}, "setInt8(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt8(-Infinity, poisoned); +}, "setInt8(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setInt8(Infinity, poisoned); +}, "setInt8(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-is-out-of-range.js new file mode 100644 index 0000000000..e93b99ca0d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/index-is-out-of-range.js @@ -0,0 +1,64 @@ +// 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-dataview.prototype.setint8 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getInt8] +---*/ + +var sample; +var buffer = new ArrayBuffer(4); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setInt8(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setInt8(5, 39); +}, "5 + 1 > 4"); + +assert.throws(RangeError, function() { + sample.setInt8(4, 39); +}, "4 + 1 > 4"); + +sample = new DataView(buffer, 3); +assert.throws(RangeError, function() { + sample.setInt8(1, 39); +}, "1 + 1 > 1 (offset)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.setInt8(1, 39); +}, "1 + 1 > 1 (length)"); + +sample = new DataView(buffer, 2, 1); +assert.throws(RangeError, function() { + sample.setInt8(1, 39); +}, "1 + 1 > 1 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getInt8(0), 0, "[0] no value was set"); +assert.sameValue(sample.getInt8(1), 0, "[1] no value was set"); +assert.sameValue(sample.getInt8(2), 0, "[2] no value was set"); +assert.sameValue(sample.getInt8(3), 0, "[3] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/length.js new file mode 100644 index 0000000000..8900d3121e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint8 +description: > + DataView.prototype.setInt8.length is 2. +info: | + DataView.prototype.setInt8 ( byteOffset, value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setInt8.length, 2); + +verifyNotEnumerable(DataView.prototype.setInt8, "length"); +verifyNotWritable(DataView.prototype.setInt8, "length"); +verifyConfigurable(DataView.prototype.setInt8, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/name.js new file mode 100644 index 0000000000..8464b328a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint8 +description: > + DataView.prototype.setInt8.name is "setInt8". +info: | + DataView.prototype.setInt8 ( byteOffset, value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setInt8.name, "setInt8"); + +verifyNotEnumerable(DataView.prototype.setInt8, "name"); +verifyNotWritable(DataView.prototype.setInt8, "name"); +verifyConfigurable(DataView.prototype.setInt8, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/negative-byteoffset-throws.js new file mode 100644 index 0000000000..2cc5867f07 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/negative-byteoffset-throws.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-dataview.prototype.setint8 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getInt8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setInt8(-1, 39); +}, "-1"); +assert.sameValue(sample.getInt8(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setInt8(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getInt8(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/no-value-arg.js new file mode 100644 index 0000000000..78c87e2733 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/no-value-arg.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-dataview.prototype.setint8 +description: > + Set value as undefined (cast to 0) when value argument is not present +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt8] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setInt8(0, 42); + +var result = sample.setInt8(0); + +assert.sameValue(sample.getInt8(0), 0); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/not-a-constructor.js new file mode 100644 index 0000000000..e497bc1d7b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setInt8 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setInt8), + false, + 'isConstructor(DataView.prototype.setInt8) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setInt8(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setInt8(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/range-check-after-value-conversion.js new file mode 100644 index 0000000000..b9cea0a684 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setint8 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setInt8(100, poisoned); +}, "setInt8(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setInt8('100', poisoned); +}, "setInt8('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/resizable-buffer.js new file mode 100644 index 0000000000..cde2d9b2a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setint8 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setInt8(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setInt8(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setInt8(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..27e6528f34 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset-symbol.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-dataview.prototype.setint8 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setInt8(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..f53f6f4ae4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setint8 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setInt8(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setInt8(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..1388e283bb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value-symbol.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-dataview.prototype.setint8 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setInt8(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..372bda34db --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/return-abrupt-from-tonumber-value.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setint8 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setInt8(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setInt8(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/set-values-return-undefined.js new file mode 100644 index 0000000000..c6dbe254ad --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/set-values-return-undefined.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-dataview.prototype.setint8 +description: > + Set values and return undefined +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getInt8] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Int8; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setInt8(0, value); + + assert.sameValue( + sample.getInt8(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..eb042dc6c8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-has-no-dataview-internal.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-dataview.prototype.setint8 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setInt8 = DataView.prototype.setInt8; + +assert.throws(TypeError, function() { + setInt8.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setInt8.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setInt8.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setInt8.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-is-not-object.js new file mode 100644 index 0000000000..64c207deaf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/this-is-not-object.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-dataview.prototype.setint8 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setInt8 = DataView.prototype.setInt8; + +assert.throws(TypeError, function() { + setInt8.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setInt8.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setInt8.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setInt8.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setInt8.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setInt8.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setInt8.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setInt8/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/toindex-byteoffset.js new file mode 100644 index 0000000000..9e939f43a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setInt8/toindex-byteoffset.js @@ -0,0 +1,109 @@ +// 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-dataview.prototype.setint8 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Int8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getInt8] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setInt8(0, 0); +sample.setInt8(-0, 42); +assert.sameValue(sample.getInt8(0), 42, "-0"); + +sample.setInt8(3, 0); +sample.setInt8(obj1, 42); +assert.sameValue(sample.getInt8(3), 42, "object's valueOf"); + +sample.setInt8(4, 0); +sample.setInt8(obj2, 42); +assert.sameValue(sample.getInt8(4), 42, "object's toString"); + +sample.setInt8(0, 0); +sample.setInt8("", 42); +assert.sameValue(sample.getInt8(0), 42, "the Empty string"); + +sample.setInt8(0, 0); +sample.setInt8("0", 42); +assert.sameValue(sample.getInt8(0), 42, "string '0'"); + +sample.setInt8(2, 0); +sample.setInt8("2", 42); +assert.sameValue(sample.getInt8(2), 42, "string '2'"); + +sample.setInt8(1, 0); +sample.setInt8(true, 42); +assert.sameValue(sample.getInt8(1), 42, "true"); + +sample.setInt8(0, 0); +sample.setInt8(false, 42); +assert.sameValue(sample.getInt8(0), 42, "false"); + +sample.setInt8(0, 0); +sample.setInt8(NaN, 42); +assert.sameValue(sample.getInt8(0), 42, "NaN"); + +sample.setInt8(0, 0); +sample.setInt8(null, 42); +assert.sameValue(sample.getInt8(0), 42, "null"); + +sample.setInt8(0, 0); +sample.setInt8(0.1, 42); +assert.sameValue(sample.getInt8(0), 42, "0.1"); + +sample.setInt8(0, 0); +sample.setInt8(0.9, 42); +assert.sameValue(sample.getInt8(0), 42, "0.9"); + +sample.setInt8(1, 0); +sample.setInt8(1.1, 42); +assert.sameValue(sample.getInt8(1), 42, "1.1"); + +sample.setInt8(1, 0); +sample.setInt8(1.9, 42); +assert.sameValue(sample.getInt8(1), 42, "1.9"); + +sample.setInt8(0, 0); +sample.setInt8(-0.1, 42); +assert.sameValue(sample.getInt8(0), 42, "-0.1"); + +sample.setInt8(0, 0); +sample.setInt8(-0.99999, 42); +assert.sameValue(sample.getInt8(0), 42, "-0.99999"); + +sample.setInt8(0, 0); +sample.setInt8(undefined, 42); +assert.sameValue(sample.getInt8(0), 42, "undefined"); + +sample.setInt8(0, 7); +sample.setInt8(); +assert.sameValue(sample.getInt8(0), 0, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..f0e4118831 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-number-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-dataview.prototype.setuint16 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setUint16(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..bdf0baf8c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setuint16 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setUint16(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setUint16(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..33ed84ce9f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setuint16 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setUint16(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer.js new file mode 100644 index 0000000000..65303caa08 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/detached-buffer.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-dataview.prototype.setuint16 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setUint16(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-check-before-value-conversion.js new file mode 100644 index 0000000000..ead25e1bf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint16 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setUint16(-1.5, poisoned); +}, "setUint16(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint16(-1, poisoned); +}, "setUint16(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint16(-Infinity, poisoned); +}, "setUint16(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint16(Infinity, poisoned); +}, "setUint16(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-is-out-of-range.js new file mode 100644 index 0000000000..207c90f9d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/index-is-out-of-range.js @@ -0,0 +1,86 @@ +// 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-dataview.prototype.setuint16 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getUint16] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setUint16(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setUint16(13, 39); +}, "13 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.setUint16(12, 39); +}, "12 + 2 > 12"); + +assert.throws(RangeError, function() { + sample.setUint16(11, 39); +}, "11 + 2 > 12"); + +sample = new DataView(buffer, 10); +assert.throws(RangeError, function() { + sample.setUint16(1, 39); +}, "1 + 2 > 2 (offset)"); + +sample = new DataView(buffer, 11); +assert.throws(RangeError, function() { + sample.setUint16(0, 39); +}, "0 + 2 > 1 (offset)"); + +sample = new DataView(buffer, 0, 2); +assert.throws(RangeError, function() { + sample.setUint16(1, 39); +}, "1 + 2 > 2 (length)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.setUint16(0, 39); +}, "0 + 2 > 1 (length)"); + +sample = new DataView(buffer, 4, 2); +assert.throws(RangeError, function() { + sample.setUint16(1, 39); +}, "1 + 2 > 2 (offset+length)"); + +sample = new DataView(buffer, 4, 1); +assert.throws(RangeError, function() { + sample.setUint16(0, 39); +}, "0 + 2 > 1 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getUint16(0), 0, "[0] no value was set"); +assert.sameValue(sample.getUint16(2), 0, "[1] no value was set"); +assert.sameValue(sample.getUint16(4), 0, "[2] no value was set"); +assert.sameValue(sample.getUint16(6), 0, "[3] no value was set"); +assert.sameValue(sample.getUint16(8), 0, "[4] no value was set"); +assert.sameValue(sample.getUint16(10), 0, "[5] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/length.js new file mode 100644 index 0000000000..51e8fa626d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint16 +description: > + DataView.prototype.setUint16.length is 2. +info: | + DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setUint16.length, 2); + +verifyNotEnumerable(DataView.prototype.setUint16, "length"); +verifyNotWritable(DataView.prototype.setUint16, "length"); +verifyConfigurable(DataView.prototype.setUint16, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/name.js new file mode 100644 index 0000000000..25d12bb4b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint16 +description: > + DataView.prototype.setUint16.name is "setUint16". +info: | + DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setUint16.name, "setUint16"); + +verifyNotEnumerable(DataView.prototype.setUint16, "name"); +verifyNotWritable(DataView.prototype.setUint16, "name"); +verifyConfigurable(DataView.prototype.setUint16, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/negative-byteoffset-throws.js new file mode 100644 index 0000000000..56ddc490ab --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/negative-byteoffset-throws.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-dataview.prototype.setuint16 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getUint16] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setUint16(-1, 39); +}, "-1"); +assert.sameValue(sample.getUint16(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setUint16(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getUint16(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/no-value-arg.js new file mode 100644 index 0000000000..9879b45513 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/no-value-arg.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-dataview.prototype.setuint16 +description: > + Set value as undefined (cast to 0) when value argument is not present +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getUint16] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint16(0, 42); + +var result = sample.setUint16(0); + +assert.sameValue(sample.getUint16(0), 0); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/not-a-constructor.js new file mode 100644 index 0000000000..d03027a4e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setUint16 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setUint16), + false, + 'isConstructor(DataView.prototype.setUint16) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setUint16(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setUint16(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/range-check-after-value-conversion.js new file mode 100644 index 0000000000..755b2644fb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint16 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setUint16(100, poisoned); +}, "setUint16(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setUint16('100', poisoned); +}, "setUint16('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/resizable-buffer.js new file mode 100644 index 0000000000..c250f4b613 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setuint16 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setUint16(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setUint16(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setUint16(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..cb2f133ec5 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.setuint16 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setUint16(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..8e7637bd85 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.setuint16 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setUint16(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setUint16(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..e905ee0178 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value-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-dataview.prototype.setuint16 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setUint16(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..f7f7cd3bc3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/return-abrupt-from-tonumber-value.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-dataview.prototype.setuint16 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setUint16(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setUint16(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-little-endian-order.js new file mode 100644 index 0000000000..bf6cda5068 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-little-endian-order.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-dataview.prototype.setuint16 +description: > + Set values on the little endian order +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getUint16] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setUint16(0, -1870724872, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getUint16(0), 63488); + +result = sample.setUint16(0, -134185072, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getUint16(0), 36991); + +result = sample.setUint16(0, 1870724872, true); +assert.sameValue(result, undefined, "returns undefined #3"); +assert.sameValue(sample.getUint16(0), 2303); + +result = sample.setUint16(0, 150962287, true); +assert.sameValue(result, undefined, "returns undefined #4"); +assert.sameValue(sample.getUint16(0), 28544); + +result = sample.setUint16(0, 4160782224, true); +assert.sameValue(result, undefined, "returns undefined #5"); +assert.sameValue(sample.getUint16(0), 36991); + +result = sample.setUint16(0, 2424242424, true); +assert.sameValue(result, undefined, "returns undefined #6"); +assert.sameValue(sample.getUint16(0), 63488); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-return-undefined.js new file mode 100644 index 0000000000..84e0d5dd3f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/set-values-return-undefined.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-dataview.prototype.setuint16 +description: > + Set values and return undefined +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getUint16] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Uint16; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setUint16(0, value, false); + + assert.sameValue( + sample.getUint16(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..5efe888f3e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setuint16 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setUint16 = DataView.prototype.setUint16; + +assert.throws(TypeError, function() { + setUint16.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setUint16.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setUint16.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setUint16.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-is-not-object.js new file mode 100644 index 0000000000..035e3a2558 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/this-is-not-object.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-dataview.prototype.setuint16 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setUint16 = DataView.prototype.setUint16; + +assert.throws(TypeError, function() { + setUint16.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setUint16.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setUint16.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setUint16.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setUint16.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setUint16.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setUint16.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/to-boolean-littleendian.js new file mode 100644 index 0000000000..e2f4241bde --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/to-boolean-littleendian.js @@ -0,0 +1,48 @@ +// 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-dataview.prototype.setuint16 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). +features: [DataView.prototype.getUint16, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setUint16(0, 1); +assert.sameValue(sample.getUint16(0), 1, "no arg"); +sample.setUint16(0, 2, undefined); +assert.sameValue(sample.getUint16(0), 2, "undefined"); +sample.setUint16(0, 3, null); +assert.sameValue(sample.getUint16(0), 3, "null"); +sample.setUint16(0, 4, 0); +assert.sameValue(sample.getUint16(0), 4, "0"); +sample.setUint16(0, 5, ""); +assert.sameValue(sample.getUint16(0), 5, "the empty string"); + +// True +sample.setUint16(0, 1536, {}); +assert.sameValue(sample.getUint16(0), 6, "{}"); +sample.setUint16(0, 1792, Symbol("1")); +assert.sameValue(sample.getUint16(0), 7, "symbol"); +sample.setUint16(0, 2048, 1); +assert.sameValue(sample.getUint16(0), 8, "1"); +sample.setUint16(0, 2304, "string"); +assert.sameValue(sample.getUint16(0), 9, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint16/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/toindex-byteoffset.js new file mode 100644 index 0000000000..69b90a1efd --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint16/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setuint16 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.19 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint16", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getUint16] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setUint16(0, 0); +sample.setUint16(-0, 42); +assert.sameValue(sample.getUint16(0), 42, "-0"); + +sample.setUint16(3, 0); +sample.setUint16(obj1, 42); +assert.sameValue(sample.getUint16(3), 42, "object's valueOf"); + +sample.setUint16(4, 0); +sample.setUint16(obj2, 42); +assert.sameValue(sample.getUint16(4), 42, "object's toString"); + +sample.setUint16(0, 0); +sample.setUint16("", 42); +assert.sameValue(sample.getUint16(0), 42, "the Empty string"); + +sample.setUint16(0, 0); +sample.setUint16("0", 42); +assert.sameValue(sample.getUint16(0), 42, "string '0'"); + +sample.setUint16(2, 0); +sample.setUint16("2", 42); +assert.sameValue(sample.getUint16(2), 42, "string '2'"); + +sample.setUint16(1, 0); +sample.setUint16(true, 42); +assert.sameValue(sample.getUint16(1), 42, "true"); + +sample.setUint16(0, 0); +sample.setUint16(false, 42); +assert.sameValue(sample.getUint16(0), 42, "false"); + +sample.setUint16(0, 0); +sample.setUint16(NaN, 42); +assert.sameValue(sample.getUint16(0), 42, "NaN"); + +sample.setUint16(0, 0); +sample.setUint16(null, 42); +assert.sameValue(sample.getUint16(0), 42, "null"); + +sample.setUint16(0, 0); +sample.setUint16(0.1, 42); +assert.sameValue(sample.getUint16(0), 42, "0.1"); + +sample.setUint16(0, 0); +sample.setUint16(0.9, 42); +assert.sameValue(sample.getUint16(0), 42, "0.9"); + +sample.setUint16(1, 0); +sample.setUint16(1.1, 42); +assert.sameValue(sample.getUint16(1), 42, "1.1"); + +sample.setUint16(1, 0); +sample.setUint16(1.9, 42); +assert.sameValue(sample.getUint16(1), 42, "1.9"); + +sample.setUint16(0, 0); +sample.setUint16(-0.1, 42); +assert.sameValue(sample.getUint16(0), 42, "-0.1"); + +sample.setUint16(0, 0); +sample.setUint16(-0.99999, 42); +assert.sameValue(sample.getUint16(0), 42, "-0.99999"); + +sample.setUint16(0, 0); +sample.setUint16(undefined, 42); +assert.sameValue(sample.getUint16(0), 42, "undefined"); + +sample.setUint16(0, 7); +sample.setUint16(); +assert.sameValue(sample.getUint16(0), 0, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..ca570f545a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-number-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-dataview.prototype.setuint32 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setUint32(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..ecf195dd1e --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setuint32 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setUint32(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setUint32(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..14c8c4a43a --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setuint32 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setUint32(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer.js new file mode 100644 index 0000000000..08019db635 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/detached-buffer.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-dataview.prototype.setuint32 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setUint32(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-check-before-value-conversion.js new file mode 100644 index 0000000000..aa465c1052 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint32 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setUint32(-1.5, poisoned); +}, "setUint32(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint32(-1, poisoned); +}, "setUint32(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint32(-Infinity, poisoned); +}, "setUint32(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint32(Infinity, poisoned); +}, "setUint32(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-is-out-of-range.js new file mode 100644 index 0000000000..cd12cd8007 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/index-is-out-of-range.js @@ -0,0 +1,91 @@ +// 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-dataview.prototype.setuint32 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [DataView.prototype.getUint32] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setUint32(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setUint32(13, 39); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setUint32(12, 39); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setUint32(11, 39); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setUint32(10, 39); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.setUint32(9, 39); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.setUint32(1, 39); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.setUint32(0, 39); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.setUint32(1, 39); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.setUint32(0, 39); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.setUint32(1, 39); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.setUint32(0, 39); +}, "0 + 4 > 3 (offset+length)"); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.getUint32(0), 0, "[0] no value was set"); +assert.sameValue(sample.getUint32(4), 0, "[1] no value was set"); +assert.sameValue(sample.getUint32(8), 0, "[2] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/length.js new file mode 100644 index 0000000000..274874d9b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint32 +description: > + DataView.prototype.setUint32.length is 2. +info: | + DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setUint32.length, 2); + +verifyNotEnumerable(DataView.prototype.setUint32, "length"); +verifyNotWritable(DataView.prototype.setUint32, "length"); +verifyConfigurable(DataView.prototype.setUint32, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/name.js new file mode 100644 index 0000000000..1d72ad1c79 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint32 +description: > + DataView.prototype.setUint32.name is "setUint32". +info: | + DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setUint32.name, "setUint32"); + +verifyNotEnumerable(DataView.prototype.setUint32, "name"); +verifyNotWritable(DataView.prototype.setUint32, "name"); +verifyConfigurable(DataView.prototype.setUint32, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/negative-byteoffset-throws.js new file mode 100644 index 0000000000..3e0f96350f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/negative-byteoffset-throws.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-dataview.prototype.setuint32 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getUint32] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setUint32(-1, 39); +}, "-1"); +assert.sameValue(sample.getUint32(0), 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setUint32(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(sample.getUint32(0), 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/no-value-arg.js new file mode 100644 index 0000000000..68697dfc05 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/no-value-arg.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-dataview.prototype.setuint32 +description: > + Set value as undefined (cast to 0) when value argument is not present +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getUint32] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint32(0, 42); + +var result = sample.setUint32(0); + +assert.sameValue(sample.getUint32(0), 0); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/not-a-constructor.js new file mode 100644 index 0000000000..91a589a3c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setUint32 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setUint32), + false, + 'isConstructor(DataView.prototype.setUint32) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setUint32(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setUint32(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/range-check-after-value-conversion.js new file mode 100644 index 0000000000..e7ba9a0e6b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint32 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setUint32(100, poisoned); +}, "setUint32(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setUint32('100', poisoned); +}, "setUint32('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/resizable-buffer.js new file mode 100644 index 0000000000..71992cf377 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setuint32 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setUint32(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setUint32(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setUint32(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..df21505d84 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset-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-dataview.prototype.setuint32 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setUint32(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..e98f8ce40d --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-byteoffset.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-dataview.prototype.setuint32 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setUint32(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setUint32(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..1a22e5a016 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value-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-dataview.prototype.setuint32 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setUint32(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..389b1d1db7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/return-abrupt-from-tonumber-value.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-dataview.prototype.setuint32 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setUint32(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setUint32(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-little-endian-order.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-little-endian-order.js new file mode 100644 index 0000000000..2a89dbf774 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-little-endian-order.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-dataview.prototype.setuint32 +description: > + Set values on the little endian order +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getUint32] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var result; + +result = sample.setUint32(0, -1870724872, true); +assert.sameValue(result, undefined, "returns undefined #1"); +assert.sameValue(sample.getUint32(0), 4160782224); + +result = sample.setUint32(0, -134185072, true); +assert.sameValue(result, undefined, "returns undefined #2"); +assert.sameValue(sample.getUint32(0), 2424242424); + +result = sample.setUint32(0, 1870724872, true); +assert.sameValue(result, undefined, "returns undefined #3"); +assert.sameValue(sample.getUint32(0), 150962287); + +result = sample.setUint32(0, 150962287, true); +assert.sameValue(result, undefined, "returns undefined #4"); +assert.sameValue(sample.getUint32(0), 1870724872); + +result = sample.setUint32(0, 4160782224, true); +assert.sameValue(result, undefined, "returns undefined #5"); +assert.sameValue(sample.getUint32(0), 2424242424); + +result = sample.setUint32(0, 2424242424, true); +assert.sameValue(result, undefined, "returns undefined #6"); +assert.sameValue(sample.getUint32(0), 4160782224); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-return-undefined.js new file mode 100644 index 0000000000..48351905d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/set-values-return-undefined.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-dataview.prototype.setuint32 +description: > + Set values and return undefined +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [DataView.prototype.getUint32] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Uint32; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setUint32(0, value, false); + + assert.sameValue( + sample.getUint32(0), + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..12af87f218 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-has-no-dataview-internal.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setuint32 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setUint32 = DataView.prototype.setUint32; + +assert.throws(TypeError, function() { + setUint32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setUint32.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setUint32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setUint32.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-is-not-object.js new file mode 100644 index 0000000000..af4cf58dac --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/this-is-not-object.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-dataview.prototype.setuint32 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setUint32 = DataView.prototype.setUint32; + +assert.throws(TypeError, function() { + setUint32.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setUint32.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setUint32.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setUint32.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setUint32.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setUint32.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setUint32.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/to-boolean-littleendian.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/to-boolean-littleendian.js new file mode 100644 index 0000000000..d7148aba73 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/to-boolean-littleendian.js @@ -0,0 +1,48 @@ +// 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-dataview.prototype.setuint32 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). +features: [DataView.prototype.getUint32, Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +// False +sample.setUint32(0, 1); +assert.sameValue(sample.getUint32(0), 1, "no arg"); +sample.setUint32(0, 2, undefined); +assert.sameValue(sample.getUint32(0), 2, "undefined"); +sample.setUint32(0, 3, null); +assert.sameValue(sample.getUint32(0), 3, "null"); +sample.setUint32(0, 4, 0); +assert.sameValue(sample.getUint32(0), 4, "0"); +sample.setUint32(0, 5, ""); +assert.sameValue(sample.getUint32(0), 5, "the empty string"); + +// True +sample.setUint32(0, 6, {}); +assert.sameValue(sample.getUint32(0), 100663296, "{}"); +sample.setUint32(0, 7, Symbol("1")); +assert.sameValue(sample.getUint32(0), 117440512, "symbol"); +sample.setUint32(0, 8, 1); +assert.sameValue(sample.getUint32(0), 134217728, "1"); +sample.setUint32(0, 9, "string"); +assert.sameValue(sample.getUint32(0), 150994944, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint32/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/toindex-byteoffset.js new file mode 100644 index 0000000000..d1b2d66234 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint32/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setuint32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Uint32", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [DataView.prototype.getUint32] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setUint32(0, 0); +sample.setUint32(-0, 42); +assert.sameValue(sample.getUint32(0), 42, "-0"); + +sample.setUint32(3, 0); +sample.setUint32(obj1, 42); +assert.sameValue(sample.getUint32(3), 42, "object's valueOf"); + +sample.setUint32(4, 0); +sample.setUint32(obj2, 42); +assert.sameValue(sample.getUint32(4), 42, "object's toString"); + +sample.setUint32(0, 0); +sample.setUint32("", 42); +assert.sameValue(sample.getUint32(0), 42, "the Empty string"); + +sample.setUint32(0, 0); +sample.setUint32("0", 42); +assert.sameValue(sample.getUint32(0), 42, "string '0'"); + +sample.setUint32(2, 0); +sample.setUint32("2", 42); +assert.sameValue(sample.getUint32(2), 42, "string '2'"); + +sample.setUint32(1, 0); +sample.setUint32(true, 42); +assert.sameValue(sample.getUint32(1), 42, "true"); + +sample.setUint32(0, 0); +sample.setUint32(false, 42); +assert.sameValue(sample.getUint32(0), 42, "false"); + +sample.setUint32(0, 0); +sample.setUint32(NaN, 42); +assert.sameValue(sample.getUint32(0), 42, "NaN"); + +sample.setUint32(0, 0); +sample.setUint32(null, 42); +assert.sameValue(sample.getUint32(0), 42, "null"); + +sample.setUint32(0, 0); +sample.setUint32(0.1, 42); +assert.sameValue(sample.getUint32(0), 42, "0.1"); + +sample.setUint32(0, 0); +sample.setUint32(0.9, 42); +assert.sameValue(sample.getUint32(0), 42, "0.9"); + +sample.setUint32(1, 0); +sample.setUint32(1.1, 42); +assert.sameValue(sample.getUint32(1), 42, "1.1"); + +sample.setUint32(1, 0); +sample.setUint32(1.9, 42); +assert.sameValue(sample.getUint32(1), 42, "1.9"); + +sample.setUint32(0, 0); +sample.setUint32(-0.1, 42); +assert.sameValue(sample.getUint32(0), 42, "-0.1"); + +sample.setUint32(0, 0); +sample.setUint32(-0.99999, 42); +assert.sameValue(sample.getUint32(0), 42, "-0.99999"); + +sample.setUint32(0, 0); +sample.setUint32(undefined, 42); +assert.sameValue(sample.getUint32(0), 42, "undefined"); + +sample.setUint32(0, 7); +sample.setUint32(); +assert.sameValue(sample.getUint32(0), 0, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/browser.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-number-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-number-value.js new file mode 100644 index 0000000000..ee1f8720ee --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-number-value.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-dataview.prototype.setuint8 +description: > + Detached buffer is checked after ToNumber(value) +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var v = { + valueOf: function() { + throw new Test262Error(); + } +}; + +$DETACHBUFFER(buffer); +assert.throws(Test262Error, function() { + sample.setUint8(0, v); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-toindex-byteoffset.js new file mode 100644 index 0000000000..d7a82e4146 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-after-toindex-byteoffset.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-dataview.prototype.setuint8 +description: > + Detached buffer is only checked after ToIndex(requestIndex) +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... + 7. Let buffer be view.[[ViewedArrayBuffer]]. + 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(RangeError, function() { + sample.setUint8(Infinity, 0); +}, "Infinity"); + +assert.throws(RangeError, function() { + sample.setUint8(-1, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-before-outofrange-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-before-outofrange-byteoffset.js new file mode 100644 index 0000000000..49e9170195 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer-before-outofrange-byteoffset.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-dataview.prototype.setuint8 +description: > + Detached buffer is checked before out of range byteOffset's value +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var sample; +var buffer = new ArrayBuffer(12); + +sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); + +assert.throws(TypeError, function() { + sample.setUint8(13, 0); +}, "13"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer.js new file mode 100644 index 0000000000..83fb2fa491 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/detached-buffer.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-dataview.prototype.setuint8 +description: > + Throws a TypeError if buffer is detached +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 9. Let buffer be the value of view's [[ViewedArrayBuffer]] internal slot. + 10. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [detachArrayBuffer.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +$DETACHBUFFER(buffer); +assert.throws(TypeError, function() { + sample.setUint8(0, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-check-before-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-check-before-value-conversion.js new file mode 100644 index 0000000000..afba92f418 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-check-before-value-conversion.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint8 +description: > + RangeError exception for negative or non-integral index is thrown before + the value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error("valueOf called"); + } +}; + +assert.throws(RangeError, function() { + dataView.setUint8(-1.5, poisoned); +}, "setUint8(-1.5, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint8(-1, poisoned); +}, "setUint8(-1, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint8(-Infinity, poisoned); +}, "setUint8(-Infinity, poisoned)"); + +assert.throws(RangeError, function() { + dataView.setUint8(Infinity, poisoned); +}, "setUint8(Infinity, poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-is-out-of-range.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-is-out-of-range.js new file mode 100644 index 0000000000..b0fa531885 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/index-is-out-of-range.js @@ -0,0 +1,64 @@ +// 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-dataview.prototype.setuint8 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 11. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 12. Let viewSize be the value of view's [[ByteLength]] internal slot. + 13. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 14. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [Uint8Array] +---*/ + +var sample; +var buffer = new ArrayBuffer(4); +var typedArray = new Uint8Array(buffer, 0); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.setUint8(Infinity, 39); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.setUint8(5, 39); +}, "5 + 1 > 4"); + +assert.throws(RangeError, function() { + sample.setUint8(4, 39); +}, "4 + 1 > 4"); + +sample = new DataView(buffer, 3); +assert.throws(RangeError, function() { + sample.setUint8(1, 39); +}, "1 + 1 > 1 (offset)"); + +sample = new DataView(buffer, 0, 1); +assert.throws(RangeError, function() { + sample.setUint8(1, 39); +}, "1 + 1 > 1 (length)"); + +sample = new DataView(buffer, 2, 1); +assert.throws(RangeError, function() { + sample.setUint8(1, 39); +}, "1 + 1 > 1 (offset+length)"); + +assert.sameValue(typedArray[0], 0, "[0] no value was set"); +assert.sameValue(typedArray[1], 0, "[1] no value was set"); +assert.sameValue(typedArray[2], 0, "[2] no value was set"); +assert.sameValue(typedArray[3], 0, "[3] no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/length.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/length.js new file mode 100644 index 0000000000..63f58f4637 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint8 +description: > + DataView.prototype.setUint8.length is 2. +info: | + DataView.prototype.setUint8 ( byteOffset, value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setUint8.length, 2); + +verifyNotEnumerable(DataView.prototype.setUint8, "length"); +verifyNotWritable(DataView.prototype.setUint8, "length"); +verifyConfigurable(DataView.prototype.setUint8, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/name.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/name.js new file mode 100644 index 0000000000..f023fc8bdf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint8 +description: > + DataView.prototype.setUint8.name is "setUint8". +info: | + DataView.prototype.setUint8 ( byteOffset, value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(DataView.prototype.setUint8.name, "setUint8"); + +verifyNotEnumerable(DataView.prototype.setUint8, "name"); +verifyNotWritable(DataView.prototype.setUint8, "name"); +verifyConfigurable(DataView.prototype.setUint8, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/negative-byteoffset-throws.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/negative-byteoffset-throws.js new file mode 100644 index 0000000000..c9f3dd198b --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/negative-byteoffset-throws.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-dataview.prototype.setuint8 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [Uint8Array] +---*/ + +var buffer = new ArrayBuffer(2); +var sample = new DataView(buffer, 0); +var typedArray = new Uint8Array(buffer, 0); + +assert.throws(RangeError, function() { + sample.setUint8(-1, 39); +}, "-1"); +assert.sameValue(typedArray[0], 0, "-1 - no value was set"); + +assert.throws(RangeError, function() { + sample.setUint8(-Infinity, 39); +}, "-Infinity"); +assert.sameValue(typedArray[0], 0, "-Infinity - no value was set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/no-value-arg.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/no-value-arg.js new file mode 100644 index 0000000000..906573b8dc --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/no-value-arg.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-dataview.prototype.setuint8 +description: > + Set value as undefined (cast to 0) when value argument is not present +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [Uint8Array] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); +var typedArray = new Uint8Array(buffer, 0); + +sample.setUint8(0, 42); + +var result = sample.setUint8(0); + +assert.sameValue(typedArray[0], 0); +assert.sameValue(result, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/not-a-constructor.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/not-a-constructor.js new file mode 100644 index 0000000000..25899332b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/not-a-constructor.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-ecmascript-standard-built-in-objects +description: > + DataView.prototype.setUint8 does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, DataView, arrow-function, ArrayBuffer] +---*/ + +assert.sameValue( + isConstructor(DataView.prototype.setUint8), + false, + 'isConstructor(DataView.prototype.setUint8) must return false' +); + +assert.throws(TypeError, () => { + let dv = new DataView(new ArrayBuffer(16)); new dv.setUint8(0, 0); +}, '`let dv = new DataView(new ArrayBuffer(16)); new dv.setUint8(0, 0)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/range-check-after-value-conversion.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/range-check-after-value-conversion.js new file mode 100644 index 0000000000..d4b92dfdc6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/range-check-after-value-conversion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.setuint8 +description: > + Index bounds checks are performed after value conversion. +info: | + ... + 3. Return SetViewValue(v, byteOffset, littleEndian, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + ... + 3. Let numberIndex be ToNumber(requestIndex). + 4. Let getIndex be ? ToInteger(numberIndex). + ... + 6. Let numberValue be ? ToNumber(value). + ... + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +---*/ + +var dataView = new DataView(new ArrayBuffer(8), 0); + +var poisoned = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + dataView.setUint8(100, poisoned); +}, "setUint8(100, poisoned)"); + +assert.throws(Test262Error, function() { + dataView.setUint8('100', poisoned); +}, "setUint8('100', poisoned)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/resizable-buffer.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/resizable-buffer.js new file mode 100644 index 0000000000..42e86ddf39 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/resizable-buffer.js @@ -0,0 +1,44 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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-dataview.prototype.setuint8 +description: Throws a TypeError if buffer is out-of-bounds +features: [DataView, ArrayBuffer, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +var buffer = new ArrayBuffer(24, {maxByteLength: 32}); +var sample = new DataView(buffer, 0, 16); + +try { + buffer.resize(32); +} catch (_) {} + +assert.sameValue(sample.setUint8(0, 10), undefined, 'following grow'); + +try { + buffer.resize(16); +} catch (_) {} + +assert.sameValue(sample.setUint8(0, 20), undefined, 'following shrink (within bounds)'); + +var expectedError; +try { + buffer.resize(8); + expectedError = TypeError; +} catch (_) { + expectedError = Test262Error; +} + +assert.throws(expectedError, function() { + sample.setUint8(0, 30); + throw new Test262Error('the operation completed successfully'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..c8d19210bf --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset-symbol.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-dataview.prototype.setuint8 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setUint8(s, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset.js new file mode 100644 index 0000000000..aa42bac545 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-byteoffset.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setuint8 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setUint8(bo1, 1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setUint8(bo2, 1); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value-symbol.js new file mode 100644 index 0000000000..ba55ac06fc --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value-symbol.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-dataview.prototype.setuint8 +description: > + Return abrupt from ToNumber(symbol value) +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.setUint8(0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value.js new file mode 100644 index 0000000000..c103c850d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/return-abrupt-from-tonumber-value.js @@ -0,0 +1,44 @@ +// 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-dataview.prototype.setuint8 +description: > + Return abrupt from ToNumber(value) +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 7. Let numberValue be ? ToNumber(value). + ... +---*/ + +var buffer = new ArrayBuffer(8); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.setUint8(0, bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.setUint8(0, bo2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/set-values-return-undefined.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/set-values-return-undefined.js new file mode 100644 index 0000000000..724a54baa8 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/set-values-return-undefined.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-dataview.prototype.setuint8 +description: > + Set values and return undefined +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 15. Let bufferIndex be getIndex + viewOffset. + 16. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, isLittleEndian). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) + + ... + 11. Store the individual bytes of rawBytes into block, in order, starting at + block[byteIndex]. + 12. Return NormalCompletion(undefined). +features: [Uint8Array] +includes: [byteConversionValues.js] +---*/ + +var buffer = new ArrayBuffer(1); +var sample = new DataView(buffer, 0); +var typedArray = new Uint8Array(buffer, 0); + +var values = byteConversionValues.values; +var expectedValues = byteConversionValues.expected.Uint8; + +values.forEach(function(value, i) { + var expected = expectedValues[i]; + + var result = sample.setUint8(0, value); + + assert.sameValue( + typedArray[0], + expected, + "value: " + value + ); + assert.sameValue( + result, + undefined, + "return is undefined, value: " + value + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-has-no-dataview-internal.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-has-no-dataview-internal.js new file mode 100644 index 0000000000..9c613e9d39 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-has-no-dataview-internal.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-dataview.prototype.setuint8 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [Int8Array] +---*/ + +var setUint8 = DataView.prototype.setUint8; + +assert.throws(TypeError, function() { + setUint8.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + setUint8.call([]); +}, "[]"); + +var ab = new ArrayBuffer(1); +assert.throws(TypeError, function() { + setUint8.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + setUint8.call(ta); +}, "TypedArray"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-is-not-object.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-is-not-object.js new file mode 100644 index 0000000000..2ca48299e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/this-is-not-object.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-dataview.prototype.setuint8 +description: Throws a TypeError if this is not Object +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + 1. If Type(view) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var setUint8 = DataView.prototype.setUint8; + +assert.throws(TypeError, function() { + setUint8.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + setUint8.call(null); +}, "null"); + +assert.throws(TypeError, function() { + setUint8.call(1); +}, "1"); + +assert.throws(TypeError, function() { + setUint8.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + setUint8.call(true); +}, "true"); + +assert.throws(TypeError, function() { + setUint8.call(false); +}, "false"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + setUint8.call(s); +}, "symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/setUint8/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/toindex-byteoffset.js new file mode 100644 index 0000000000..b74f2a689f --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/prototype/setUint8/toindex-byteoffset.js @@ -0,0 +1,110 @@ +// 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-dataview.prototype.setuint8 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) + + 1. Let v be the this value. + 2. Return ? SetViewValue(v, byteOffset, true, "Uint8", value). + + 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [Uint8Array] +---*/ + +var buffer = new ArrayBuffer(12); +var sample = new DataView(buffer, 0); +var typedArray = new Uint8Array(buffer, 0); + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +sample.setUint8(0, 0); +sample.setUint8(-0, 42); +assert.sameValue(typedArray[0], 42, "-0"); + +sample.setUint8(3, 0); +sample.setUint8(obj1, 42); +assert.sameValue(typedArray[3], 42, "object's valueOf"); + +sample.setUint8(4, 0); +sample.setUint8(obj2, 42); +assert.sameValue(typedArray[4], 42, "object's toString"); + +sample.setUint8(0, 0); +sample.setUint8("", 42); +assert.sameValue(typedArray[0], 42, "the Empty string"); + +sample.setUint8(0, 0); +sample.setUint8("0", 42); +assert.sameValue(typedArray[0], 42, "string '0'"); + +sample.setUint8(2, 0); +sample.setUint8("2", 42); +assert.sameValue(typedArray[2], 42, "string '2'"); + +sample.setUint8(1, 0); +sample.setUint8(true, 42); +assert.sameValue(typedArray[1], 42, "true"); + +sample.setUint8(0, 0); +sample.setUint8(false, 42); +assert.sameValue(typedArray[0], 42, "false"); + +sample.setUint8(0, 0); +sample.setUint8(NaN, 42); +assert.sameValue(typedArray[0], 42, "NaN"); + +sample.setUint8(0, 0); +sample.setUint8(null, 42); +assert.sameValue(typedArray[0], 42, "null"); + +sample.setUint8(0, 0); +sample.setUint8(0.1, 42); +assert.sameValue(typedArray[0], 42, "0.1"); + +sample.setUint8(0, 0); +sample.setUint8(0.9, 42); +assert.sameValue(typedArray[0], 42, "0.9"); + +sample.setUint8(1, 0); +sample.setUint8(1.1, 42); +assert.sameValue(typedArray[1], 42, "1.1"); + +sample.setUint8(1, 0); +sample.setUint8(1.9, 42); +assert.sameValue(typedArray[1], 42, "1.9"); + +sample.setUint8(0, 0); +sample.setUint8(-0.1, 42); +assert.sameValue(typedArray[0], 42, "-0.1"); + +sample.setUint8(0, 0); +sample.setUint8(-0.99999, 42); +assert.sameValue(typedArray[0], 42, "-0.99999"); + +sample.setUint8(0, 0); +sample.setUint8(undefined, 42); +assert.sameValue(typedArray[0], 42, "undefined"); + +sample.setUint8(0, 7); +sample.setUint8(); +assert.sameValue(typedArray[0], 0, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/prototype/shell.js b/js/src/tests/test262/built-ins/DataView/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js new file mode 100644 index 0000000000..b583d8e673 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js @@ -0,0 +1,44 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js new file mode 100644 index 0000000000..2893e211eb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js @@ -0,0 +1,29 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(symbol byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +features: [SharedArrayBuffer, Symbol] +---*/ + +var buffer = new SharedArrayBuffer(8); +var s = Symbol("1"); + +assert.throws(TypeError, function() { + new DataView(buffer, 0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js new file mode 100644 index 0000000000..bfb97019f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol.js @@ -0,0 +1,27 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(symbol byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +features: [Symbol] +---*/ + +var buffer = new ArrayBuffer(8); +var s = Symbol("1"); + +assert.throws(TypeError, function() { + new DataView(buffer, 0, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength.js new file mode 100644 index 0000000000..75b05d0c25 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-bytelength.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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +---*/ + +var buffer = new ArrayBuffer(8); + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-sab.js new file mode 100644 index 0000000000..393db5ad69 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +features: [SharedArrayBuffer] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var ab = new SharedArrayBuffer(0); + +assert.throws(Test262Error, function() { + new DataView(ab, obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js new file mode 100644 index 0000000000..d917975b33 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js @@ -0,0 +1,26 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +features: [SharedArrayBuffer, Symbol] +---*/ + +var s = Symbol("1"); +var ab = new SharedArrayBuffer(0); + +assert.throws(TypeError, function() { + new DataView(ab, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js new file mode 100644 index 0000000000..03fec5a1f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol.js @@ -0,0 +1,24 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +features: [Symbol] +---*/ + +var s = Symbol("1"); +var ab = new ArrayBuffer(0); + +assert.throws(TypeError, function() { + new DataView(ab, s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset.js b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset.js new file mode 100644 index 0000000000..a557efc350 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-abrupt-tonumber-byteoffset.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-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var ab = new ArrayBuffer(0); + +assert.throws(Test262Error, function() { + new DataView(ab, obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-instance-sab.js b/js/src/tests/test262/built-ins/DataView/return-instance-sab.js new file mode 100644 index 0000000000..714d276de2 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-instance-sab.js @@ -0,0 +1,33 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + Returns new instance +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var ab, sample; + +ab = new SharedArrayBuffer(1); +sample = new DataView(ab, 0); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +ab = new SharedArrayBuffer(1); +sample = new DataView(ab, 1); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/return-instance.js b/js/src/tests/test262/built-ins/DataView/return-instance.js new file mode 100644 index 0000000000..ee6eaa7cfb --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/return-instance.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-dataview-buffer-byteoffset-bytelength +description: > + Returns new instance +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. +---*/ + +var ab, sample; + +ab = new ArrayBuffer(1); +sample = new DataView(ab, 0); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +ab = new ArrayBuffer(1); +sample = new DataView(ab, 1); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/shell.js b/js/src/tests/test262/built-ins/DataView/shell.js new file mode 100644 index 0000000000..b436b5c0b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/shell.js @@ -0,0 +1,490 @@ +// 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 + ], + 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: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/DataView/toindex-bytelength-sab.js b/js/src/tests/test262/built-ins/DataView/toindex-bytelength-sab.js new file mode 100644 index 0000000000..9514d7b8c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/toindex-bytelength-sab.js @@ -0,0 +1,98 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + ToIndex conversions on byteLength +info: | + 24.2.2.1 DataView ( buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 9. Else, + a. Let viewByteLength be ? ToIndex(byteLength). + b. If offset + viewByteLength > bufferByteLength, throw a RangeError + exception. + ... + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +features: [SharedArrayBuffer] +---*/ + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +var sample; +var ab = new SharedArrayBuffer(42); + +sample = new DataView(ab, 0, -0); +assert.sameValue(sample.byteLength, 0, "-0"); + +sample = new DataView(ab, 0, obj1); +assert.sameValue(sample.byteLength, 3, "object's valueOf"); + +sample = new DataView(ab, 0, obj2); +assert.sameValue(sample.byteLength, 4, "object's toString"); + +sample = new DataView(ab, 0, ""); +assert.sameValue(sample.byteLength, 0, "the Empty string"); + +sample = new DataView(ab, 0, "0"); +assert.sameValue(sample.byteLength, 0, "string '0'"); + +sample = new DataView(ab, 0, "1"); +assert.sameValue(sample.byteLength, 1, "string '1'"); + +sample = new DataView(ab, 0, true); +assert.sameValue(sample.byteLength, 1, "true"); + +sample = new DataView(ab, 0, false); +assert.sameValue(sample.byteLength, 0, "false"); + +sample = new DataView(ab, 0, NaN); +assert.sameValue(sample.byteLength, 0, "NaN"); + +sample = new DataView(ab, 0, null); +assert.sameValue(sample.byteLength, 0, "null"); + +sample = new DataView(ab, 0, 0.1); +assert.sameValue(sample.byteLength, 0, "0.1"); + +sample = new DataView(ab, 0, 0.9); +assert.sameValue(sample.byteLength, 0, "0.9"); + +sample = new DataView(ab, 0, 1.1); +assert.sameValue(sample.byteLength, 1, "1.1"); + +sample = new DataView(ab, 0, 1.9); +assert.sameValue(sample.byteLength, 1, "1.9"); + +sample = new DataView(ab, 0, -0.1); +assert.sameValue(sample.byteLength, 0, "-0.1"); + +sample = new DataView(ab, 0, -0.99999); +assert.sameValue(sample.byteLength, 0, "-0.99999"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/toindex-bytelength.js b/js/src/tests/test262/built-ins/DataView/toindex-bytelength.js new file mode 100644 index 0000000000..7eb472d8a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/toindex-bytelength.js @@ -0,0 +1,95 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + ToIndex conversions on byteLength +info: | + 24.2.2.1 DataView ( buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 9. Else, + a. Let viewByteLength be ? ToIndex(byteLength). + b. If offset + viewByteLength > bufferByteLength, throw a RangeError + exception. + ... + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +---*/ + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +var sample; +var ab = new ArrayBuffer(42); + +sample = new DataView(ab, 0, -0); +assert.sameValue(sample.byteLength, 0, "-0"); + +sample = new DataView(ab, 0, obj1); +assert.sameValue(sample.byteLength, 3, "object's valueOf"); + +sample = new DataView(ab, 0, obj2); +assert.sameValue(sample.byteLength, 4, "object's toString"); + +sample = new DataView(ab, 0, ""); +assert.sameValue(sample.byteLength, 0, "the Empty string"); + +sample = new DataView(ab, 0, "0"); +assert.sameValue(sample.byteLength, 0, "string '0'"); + +sample = new DataView(ab, 0, "1"); +assert.sameValue(sample.byteLength, 1, "string '1'"); + +sample = new DataView(ab, 0, true); +assert.sameValue(sample.byteLength, 1, "true"); + +sample = new DataView(ab, 0, false); +assert.sameValue(sample.byteLength, 0, "false"); + +sample = new DataView(ab, 0, NaN); +assert.sameValue(sample.byteLength, 0, "NaN"); + +sample = new DataView(ab, 0, null); +assert.sameValue(sample.byteLength, 0, "null"); + +sample = new DataView(ab, 0, 0.1); +assert.sameValue(sample.byteLength, 0, "0.1"); + +sample = new DataView(ab, 0, 0.9); +assert.sameValue(sample.byteLength, 0, "0.9"); + +sample = new DataView(ab, 0, 1.1); +assert.sameValue(sample.byteLength, 1, "1.1"); + +sample = new DataView(ab, 0, 1.9); +assert.sameValue(sample.byteLength, 1, "1.9"); + +sample = new DataView(ab, 0, -0.1); +assert.sameValue(sample.byteLength, 0, "-0.1"); + +sample = new DataView(ab, 0, -0.99999); +assert.sameValue(sample.byteLength, 0, "-0.99999"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/toindex-byteoffset-sab.js b/js/src/tests/test262/built-ins/DataView/toindex-byteoffset-sab.js new file mode 100644 index 0000000000..591a216594 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/toindex-byteoffset-sab.js @@ -0,0 +1,96 @@ +// |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-dataview-buffer-byteoffset-bytelength +description: > + ToIndex conversions on byteOffset +info: | + 24.2.2.1 DataView ( buffer, byteOffset, byteLength ) + + ... + 4. Let offset be ? ToIndex(byteOffset). + ... + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +features: [SharedArrayBuffer] +---*/ + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +var sample; +var ab = new SharedArrayBuffer(42); + +sample = new DataView(ab, -0); +assert.sameValue(sample.byteOffset, 0, "-0"); + +sample = new DataView(ab, obj1); +assert.sameValue(sample.byteOffset, 3, "object's valueOf"); + +sample = new DataView(ab, obj2); +assert.sameValue(sample.byteOffset, 4, "object's toString"); + +sample = new DataView(ab, ""); +assert.sameValue(sample.byteOffset, 0, "the Empty string"); + +sample = new DataView(ab, "0"); +assert.sameValue(sample.byteOffset, 0, "string '0'"); + +sample = new DataView(ab, "1"); +assert.sameValue(sample.byteOffset, 1, "string '1'"); + +sample = new DataView(ab, true); +assert.sameValue(sample.byteOffset, 1, "true"); + +sample = new DataView(ab, false); +assert.sameValue(sample.byteOffset, 0, "false"); + +sample = new DataView(ab, NaN); +assert.sameValue(sample.byteOffset, 0, "NaN"); + +sample = new DataView(ab, null); +assert.sameValue(sample.byteOffset, 0, "null"); + +sample = new DataView(ab, undefined); +assert.sameValue(sample.byteOffset, 0, "undefined"); + +sample = new DataView(ab, 0.1); +assert.sameValue(sample.byteOffset, 0, "0.1"); + +sample = new DataView(ab, 0.9); +assert.sameValue(sample.byteOffset, 0, "0.9"); + +sample = new DataView(ab, 1.1); +assert.sameValue(sample.byteOffset, 1, "1.1"); + +sample = new DataView(ab, 1.9); +assert.sameValue(sample.byteOffset, 1, "1.9"); + +sample = new DataView(ab, -0.1); +assert.sameValue(sample.byteOffset, 0, "-0.1"); + +sample = new DataView(ab, -0.99999); +assert.sameValue(sample.byteOffset, 0, "-0.99999"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/DataView/toindex-byteoffset.js b/js/src/tests/test262/built-ins/DataView/toindex-byteoffset.js new file mode 100644 index 0000000000..eb85ea2dd3 --- /dev/null +++ b/js/src/tests/test262/built-ins/DataView/toindex-byteoffset.js @@ -0,0 +1,93 @@ +// 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-dataview-buffer-byteoffset-bytelength +description: > + ToIndex conversions on byteOffset +info: | + 24.2.2.1 DataView ( buffer, byteOffset, byteLength ) + + ... + 4. Let offset be ? ToIndex(byteOffset). + ... + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +---*/ + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +var sample; +var ab = new ArrayBuffer(42); + +sample = new DataView(ab, -0); +assert.sameValue(sample.byteOffset, 0, "-0"); + +sample = new DataView(ab, obj1); +assert.sameValue(sample.byteOffset, 3, "object's valueOf"); + +sample = new DataView(ab, obj2); +assert.sameValue(sample.byteOffset, 4, "object's toString"); + +sample = new DataView(ab, ""); +assert.sameValue(sample.byteOffset, 0, "the Empty string"); + +sample = new DataView(ab, "0"); +assert.sameValue(sample.byteOffset, 0, "string '0'"); + +sample = new DataView(ab, "1"); +assert.sameValue(sample.byteOffset, 1, "string '1'"); + +sample = new DataView(ab, true); +assert.sameValue(sample.byteOffset, 1, "true"); + +sample = new DataView(ab, false); +assert.sameValue(sample.byteOffset, 0, "false"); + +sample = new DataView(ab, NaN); +assert.sameValue(sample.byteOffset, 0, "NaN"); + +sample = new DataView(ab, null); +assert.sameValue(sample.byteOffset, 0, "null"); + +sample = new DataView(ab, undefined); +assert.sameValue(sample.byteOffset, 0, "undefined"); + +sample = new DataView(ab, 0.1); +assert.sameValue(sample.byteOffset, 0, "0.1"); + +sample = new DataView(ab, 0.9); +assert.sameValue(sample.byteOffset, 0, "0.9"); + +sample = new DataView(ab, 1.1); +assert.sameValue(sample.byteOffset, 1, "1.1"); + +sample = new DataView(ab, 1.9); +assert.sameValue(sample.byteOffset, 1, "1.9"); + +sample = new DataView(ab, -0.1); +assert.sameValue(sample.byteOffset, 0, "-0.1"); + +sample = new DataView(ab, -0.99999); +assert.sameValue(sample.byteOffset, 0, "-0.99999"); + +reportCompare(0, 0); -- cgit v1.2.3