@@ -15,6 +15,39 @@ for (let ctor of ctors) {
15
15
const lengthTracking = new ctor ( rab ) ;
16
16
const lengthTrackingWithOffset = new ctor ( rab , 2 * ctor . BYTES_PER_ELEMENT ) ;
17
17
18
+ assert . notSameValue ( fixedLength . length , 0 ) ;
19
+ assert . notSameValue ( fixedLengthWithOffset . length , 0 ) ;
20
+ assert . notSameValue ( lengthTracking . length , 0 ) ;
21
+ assert . notSameValue ( lengthTrackingWithOffset . length , 0 ) ;
22
+
23
+ // "Fixed length" TAs backed by RABs can shrink then re-grow.
24
+ assert . throws ( TypeError , function ( ) {
25
+ Object . seal ( fixedLength ) ;
26
+ } ) ;
27
+ assert . throws ( TypeError , function ( ) {
28
+ Object . seal ( fixedLengthWithOffset ) ;
29
+ } ) ;
30
+ assert . throws ( TypeError , function ( ) {
31
+ Object . seal ( lengthTracking ) ;
32
+ } ) ;
33
+ assert . throws ( TypeError , function ( ) {
34
+ Object . seal ( lengthTrackingWithOffset ) ;
35
+ } ) ;
36
+ }
37
+
38
+ for ( let ctor of ctors ) {
39
+ const rab = new ArrayBuffer ( 4 * ctor . BYTES_PER_ELEMENT , { maxByteLength : 8 * ctor . BYTES_PER_ELEMENT } ) ;
40
+ const rabZeroLength = new ArrayBuffer ( 0 , { maxByteLength : 8 * ctor . BYTES_PER_ELEMENT } ) ;
41
+ const fixedLength = new ctor ( rab , 0 , 0 ) ;
42
+ const fixedLengthWithOffset = new ctor ( rab , 2 * ctor . BYTES_PER_ELEMENT , 0 ) ;
43
+ const lengthTracking = new ctor ( rabZeroLength ) ;
44
+ const lengthTrackingWithOffset = new ctor ( rab , 4 * ctor . BYTES_PER_ELEMENT ) ;
45
+
46
+ assert . sameValue ( fixedLength . length , 0 ) ;
47
+ assert . sameValue ( fixedLengthWithOffset . length , 0 ) ;
48
+ assert . sameValue ( lengthTracking . length , 0 ) ;
49
+ assert . sameValue ( lengthTrackingWithOffset . length , 0 ) ;
50
+
18
51
// "Fixed length" TAs backed by RABs can shrink then re-grow.
19
52
assert . throws ( TypeError , function ( ) {
20
53
Object . seal ( fixedLength ) ;
@@ -37,7 +70,43 @@ for (let ctor of ctors) {
37
70
const lengthTracking = new ctor ( gsab ) ;
38
71
const lengthTrackingWithOffset = new ctor ( gsab , 2 * ctor . BYTES_PER_ELEMENT ) ;
39
72
40
- // Fixed length TAs backed by GSABs can't shrink, and so are allowed.
73
+ assert . notSameValue ( fixedLength . length , 0 ) ;
74
+ assert . notSameValue ( fixedLengthWithOffset . length , 0 ) ;
75
+ assert . notSameValue ( lengthTracking . length , 0 ) ;
76
+ assert . notSameValue ( lengthTrackingWithOffset . length , 0 ) ;
77
+
78
+ // Fixed length TAs backed by GSABs can't shrink, and so are allowed. TypedArray
79
+ // properties can't be redefined to non-configurable, so this still throws.
80
+ assert . throws ( TypeError , function ( ) {
81
+ Object . seal ( fixedLength ) ;
82
+ } ) ;
83
+ assert . throws ( TypeError , function ( ) {
84
+ Object . seal ( fixedLengthWithOffset ) ;
85
+ } ) ;
86
+ assert . throws ( TypeError , function ( ) {
87
+ Object . seal ( lengthTracking ) ;
88
+ } ) ;
89
+ assert . throws ( TypeError , function ( ) {
90
+ Object . seal ( lengthTrackingWithOffset ) ;
91
+ } ) ;
92
+ }
93
+
94
+ for ( let ctor of ctors ) {
95
+ const gsab = new SharedArrayBuffer ( 4 * ctor . BYTES_PER_ELEMENT , { maxByteLength : 8 * ctor . BYTES_PER_ELEMENT } ) ;
96
+ const gsabZeroLength = new SharedArrayBuffer ( 0 , { maxByteLength : 8 * ctor . BYTES_PER_ELEMENT } ) ;
97
+ const fixedLength = new ctor ( gsab , 0 , 0 ) ;
98
+ const fixedLengthWithOffset = new ctor ( gsab , 2 * ctor . BYTES_PER_ELEMENT , 0 ) ;
99
+ const lengthTracking = new ctor ( gsabZeroLength ) ;
100
+ const lengthTrackingWithOffset = new ctor ( gsab , 4 * ctor . BYTES_PER_ELEMENT ) ;
101
+
102
+ assert . sameValue ( fixedLength . length , 0 ) ;
103
+ assert . sameValue ( fixedLengthWithOffset . length , 0 ) ;
104
+ assert . sameValue ( lengthTracking . length , 0 ) ;
105
+ assert . sameValue ( lengthTrackingWithOffset . length , 0 ) ;
106
+
107
+ // Fixed zero-length TAs backed by GSABs can't shrink, and so are allowed. If
108
+ // the TypedArray is zero length, there's no attempt to redefine TypedArray
109
+ // properties.
41
110
Object . seal ( fixedLength ) ;
42
111
Object . seal ( fixedLengthWithOffset ) ;
43
112
assert . throws ( TypeError , function ( ) {
0 commit comments