@@ -86,6 +86,7 @@ describe('angular', function() {
86
86
expect ( copy ( src ) instanceof Uint8Array ) . toBeTruthy ( ) ;
87
87
expect ( dst ) . toEqual ( src ) ;
88
88
expect ( dst ) . not . toBe ( src ) ;
89
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
89
90
}
90
91
} ) ;
91
92
@@ -97,6 +98,7 @@ describe('angular', function() {
97
98
expect ( copy ( src ) instanceof Uint8ClampedArray ) . toBeTruthy ( ) ;
98
99
expect ( dst ) . toEqual ( src ) ;
99
100
expect ( dst ) . not . toBe ( src ) ;
101
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
100
102
}
101
103
} ) ;
102
104
@@ -108,6 +110,7 @@ describe('angular', function() {
108
110
expect ( copy ( src ) instanceof Uint16Array ) . toBeTruthy ( ) ;
109
111
expect ( dst ) . toEqual ( src ) ;
110
112
expect ( dst ) . not . toBe ( src ) ;
113
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
111
114
}
112
115
} ) ;
113
116
@@ -119,6 +122,7 @@ describe('angular', function() {
119
122
expect ( copy ( src ) instanceof Uint32Array ) . toBeTruthy ( ) ;
120
123
expect ( dst ) . toEqual ( src ) ;
121
124
expect ( dst ) . not . toBe ( src ) ;
125
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
122
126
}
123
127
} ) ;
124
128
@@ -130,6 +134,7 @@ describe('angular', function() {
130
134
expect ( copy ( src ) instanceof Int8Array ) . toBeTruthy ( ) ;
131
135
expect ( dst ) . toEqual ( src ) ;
132
136
expect ( dst ) . not . toBe ( src ) ;
137
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
133
138
}
134
139
} ) ;
135
140
@@ -141,6 +146,7 @@ describe('angular', function() {
141
146
expect ( copy ( src ) instanceof Int16Array ) . toBeTruthy ( ) ;
142
147
expect ( dst ) . toEqual ( src ) ;
143
148
expect ( dst ) . not . toBe ( src ) ;
149
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
144
150
}
145
151
} ) ;
146
152
@@ -152,6 +158,7 @@ describe('angular', function() {
152
158
expect ( copy ( src ) instanceof Int32Array ) . toBeTruthy ( ) ;
153
159
expect ( dst ) . toEqual ( src ) ;
154
160
expect ( dst ) . not . toBe ( src ) ;
161
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
155
162
}
156
163
} ) ;
157
164
@@ -163,6 +170,7 @@ describe('angular', function() {
163
170
expect ( copy ( src ) instanceof Float32Array ) . toBeTruthy ( ) ;
164
171
expect ( dst ) . toEqual ( src ) ;
165
172
expect ( dst ) . not . toBe ( src ) ;
173
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
166
174
}
167
175
} ) ;
168
176
@@ -174,6 +182,49 @@ describe('angular', function() {
174
182
expect ( copy ( src ) instanceof Float64Array ) . toBeTruthy ( ) ;
175
183
expect ( dst ) . toEqual ( src ) ;
176
184
expect ( dst ) . not . toBe ( src ) ;
185
+ expect ( dst . buffer ) . not . toBe ( src . buffer ) ;
186
+ }
187
+ } ) ;
188
+
189
+ it ( 'should copy an ArrayBuffer with no destination' , function ( ) {
190
+ if ( typeof ArrayBuffer !== 'undefined' ) {
191
+ var src = new ArrayBuffer ( 8 ) ;
192
+ new Int32Array ( src ) . set ( [ 1 , 2 ] ) ;
193
+
194
+ var dst = copy ( src ) ;
195
+ expect ( dst instanceof ArrayBuffer ) . toBeTruthy ( ) ;
196
+ expect ( dst ) . toEqual ( src ) ;
197
+ expect ( dst ) . not . toBe ( src ) ;
198
+ }
199
+ } ) ;
200
+
201
+ it ( 'should handle ArrayBuffer objects with multiple references' , function ( ) {
202
+ if ( typeof ArrayBuffer !== 'undefined' ) {
203
+ var buffer = new ArrayBuffer ( 8 ) ;
204
+ var src = [ new Int32Array ( buffer ) , new Float32Array ( buffer ) ] ;
205
+ src [ 0 ] . set ( [ 1 , 2 ] ) ;
206
+
207
+ var dst = copy ( src ) ;
208
+ expect ( dst ) . toEqual ( src ) ;
209
+ expect ( dst [ 0 ] ) . not . toBe ( src [ 0 ] ) ;
210
+ expect ( dst [ 1 ] ) . not . toBe ( src [ 1 ] ) ;
211
+ expect ( dst [ 0 ] . buffer ) . toBe ( dst [ 1 ] . buffer ) ;
212
+ expect ( dst [ 0 ] . buffer ) . not . toBe ( buffer ) ;
213
+ }
214
+ } ) ;
215
+
216
+ it ( 'should handle Int32Array objects with multiple references' , function ( ) {
217
+ if ( typeof Int32Array !== 'undefined' ) {
218
+ var arr = new Int32Array ( 2 ) ;
219
+ var src = [ arr , arr ] ;
220
+ arr . set ( [ 1 , 2 ] ) ;
221
+
222
+ var dst = copy ( src ) ;
223
+ expect ( dst ) . toEqual ( src ) ;
224
+ expect ( dst ) . not . toBe ( src ) ;
225
+ expect ( dst [ 0 ] ) . not . toBe ( src [ 0 ] ) ;
226
+ expect ( dst [ 0 ] ) . toBe ( dst [ 1 ] ) ;
227
+ expect ( dst [ 0 ] . buffer ) . toBe ( dst [ 1 ] . buffer ) ;
177
228
}
178
229
} ) ;
179
230
@@ -258,6 +309,15 @@ describe('angular', function() {
258
309
}
259
310
} ) ;
260
311
312
+ it ( "should throw an exception if an ArrayBuffer is the destination" , function ( ) {
313
+ if ( typeof ArrayBuffer !== 'undefined' ) {
314
+ var src = new ArrayBuffer ( 5 ) ;
315
+ var dst = new ArrayBuffer ( 5 ) ;
316
+ expect ( function ( ) { copy ( src , dst ) ; } )
317
+ . toThrowMinErr ( "ng" , "cpta" , "Can't copy! TypedArray destination cannot be mutated." ) ;
318
+ }
319
+ } ) ;
320
+
261
321
it ( "should deeply copy an array into an existing array" , function ( ) {
262
322
var src = [ 1 , { name :"value" } ] ;
263
323
var dst = [ { key :"v" } ] ;
0 commit comments