@@ -53,11 +53,10 @@ use crate::{
53
53
} ;
54
54
55
55
use super :: abstract_operations:: {
56
- TypedArrayWithBufferWitnessRecords , is_typed_array_out_of_bounds,
57
- is_valid_integer_index_generic, make_typed_array_with_buffer_witness_record,
58
- typed_array_byte_length, typed_array_create_from_constructor_with_length,
59
- typed_array_create_same_type, typed_array_length, typed_array_species_create_with_length,
60
- validate_typed_array,
56
+ TypedArrayWithBufferWitnessRecords , is_typed_array_out_of_bounds, is_valid_integer_index,
57
+ make_typed_array_with_buffer_witness_record, typed_array_byte_length,
58
+ typed_array_create_from_constructor_with_length, typed_array_create_same_type,
59
+ typed_array_length, typed_array_species_create_with_length, validate_typed_array,
61
60
} ;
62
61
63
62
pub struct TypedArrayIntrinsicObject ;
@@ -2162,94 +2161,16 @@ impl TypedArrayPrototype {
2162
2161
let ta_record = validate_typed_array ( agent, o, Ordering :: SeqCst , gc. nogc ( ) )
2163
2162
. unbind ( ) ?
2164
2163
. bind ( gc. nogc ( ) ) ;
2165
- let o = match ta_record. object {
2166
- TypedArray :: Int8Array ( _) => with_typed_array :: < i8 > (
2167
- agent,
2168
- ta_record. unbind ( ) ,
2169
- index. unbind ( ) ,
2170
- value. unbind ( ) ,
2171
- gc,
2172
- ) ,
2173
- TypedArray :: Uint8Array ( _) => with_typed_array :: < u8 > (
2174
- agent,
2175
- ta_record. unbind ( ) ,
2176
- index. unbind ( ) ,
2177
- value. unbind ( ) ,
2178
- gc,
2179
- ) ,
2180
- TypedArray :: Uint8ClampedArray ( _) => with_typed_array :: < U8Clamped > (
2181
- agent,
2182
- ta_record. unbind ( ) ,
2183
- index. unbind ( ) ,
2184
- value. unbind ( ) ,
2185
- gc,
2186
- ) ,
2187
- TypedArray :: Int16Array ( _) => with_typed_array :: < i16 > (
2188
- agent,
2189
- ta_record. unbind ( ) ,
2190
- index. unbind ( ) ,
2191
- value. unbind ( ) ,
2192
- gc,
2193
- ) ,
2194
- TypedArray :: Uint16Array ( _) => with_typed_array :: < u16 > (
2195
- agent,
2196
- ta_record. unbind ( ) ,
2197
- index. unbind ( ) ,
2198
- value. unbind ( ) ,
2199
- gc,
2200
- ) ,
2201
- TypedArray :: Int32Array ( _) => with_typed_array :: < i32 > (
2202
- agent,
2203
- ta_record. unbind ( ) ,
2204
- index. unbind ( ) ,
2205
- value. unbind ( ) ,
2206
- gc,
2207
- ) ,
2208
- TypedArray :: Uint32Array ( _) => with_typed_array :: < u32 > (
2209
- agent,
2210
- ta_record. unbind ( ) ,
2211
- index. unbind ( ) ,
2212
- value. unbind ( ) ,
2213
- gc,
2214
- ) ,
2215
- TypedArray :: BigInt64Array ( _) => with_typed_array :: < i64 > (
2216
- agent,
2217
- ta_record. unbind ( ) ,
2218
- index. unbind ( ) ,
2219
- value. unbind ( ) ,
2220
- gc,
2221
- ) ,
2222
- TypedArray :: BigUint64Array ( _) => with_typed_array :: < u64 > (
2223
- agent,
2224
- ta_record. unbind ( ) ,
2225
- index. unbind ( ) ,
2226
- value. unbind ( ) ,
2227
- gc,
2228
- ) ,
2229
- #[ cfg( feature = "proposal-float16array" ) ]
2230
- TypedArray :: Float16Array ( _) => with_typed_array :: < f16 > (
2231
- agent,
2232
- ta_record. unbind ( ) ,
2233
- index. unbind ( ) ,
2234
- value. unbind ( ) ,
2235
- gc,
2236
- ) ,
2237
- TypedArray :: Float32Array ( _) => with_typed_array :: < f32 > (
2238
- agent,
2239
- ta_record. unbind ( ) ,
2240
- index. unbind ( ) ,
2241
- value. unbind ( ) ,
2242
- gc,
2243
- ) ,
2244
- TypedArray :: Float64Array ( _) => with_typed_array :: < f64 > (
2164
+ let o = with_typed_array_viewable ! (
2165
+ ta_record. object,
2166
+ with_typed_array:: <T >(
2245
2167
agent,
2246
2168
ta_record. unbind( ) ,
2247
2169
index. unbind( ) ,
2248
2170
value. unbind( ) ,
2249
2171
gc,
2250
- ) ,
2251
- } ;
2252
-
2172
+ )
2173
+ ) ;
2253
2174
o. map ( |o| o. into_value ( ) )
2254
2175
}
2255
2176
@@ -2947,6 +2868,7 @@ fn split_typed_array_views<'a, T: Viewable + std::fmt::Debug>(
2947
2868
let a_ptr = a_slice. as_mut_ptr ( ) ;
2948
2869
let a_len = a_slice. len ( ) ;
2949
2870
let o_aligned = viewable_slice :: < T > ( agent, o, gc) . unwrap ( ) ;
2871
+ // SAFETY: Confirmed beforehand that the two ArrayBuffers are in separate memory regions.
2950
2872
let a_aligned = unsafe { std:: slice:: from_raw_parts_mut ( a_ptr, a_len) } ;
2951
2873
Ok ( ( a_aligned, o_aligned) )
2952
2874
}
@@ -2958,10 +2880,14 @@ fn with_typed_array<'a, T: Viewable + std::fmt::Debug>(
2958
2880
value : Value ,
2959
2881
mut gc : GcScope < ' a , ' _ > ,
2960
2882
) -> JsResult < ' a , TypedArray < ' a > > {
2883
+ let ta_record = ta_record. bind ( gc. nogc ( ) ) ;
2961
2884
let index = index. bind ( gc. nogc ( ) ) ;
2962
2885
let value = value. bind ( gc. nogc ( ) ) ;
2963
2886
let o = ta_record. object ;
2887
+ let scoped_o = o. scope ( agent, gc. nogc ( ) ) ;
2964
2888
let scoped_value = value. scope ( agent, gc. nogc ( ) ) ;
2889
+ // 3. Let len be TypedArrayLength(taRecord).
2890
+ let len = typed_array_length :: < T > ( agent, & ta_record, gc. nogc ( ) ) as i64 ;
2965
2891
// 4. Let relativeIndex be ? ToIntegerOrInfinity(index).
2966
2892
// 5. If relativeIndex ≥ 0, let actualIndex be relativeIndex.
2967
2893
let relative_index = if let Value :: Integer ( index) = index {
@@ -2972,16 +2898,20 @@ fn with_typed_array<'a, T: Viewable + std::fmt::Debug>(
2972
2898
. bind ( gc. nogc ( ) )
2973
2899
. into_i64 ( )
2974
2900
} ;
2975
- let numeric_value = scoped_value
2976
- . get ( agent)
2977
- . into_value ( )
2978
- . to_numeric ( agent, gc. reborrow ( ) )
2979
- . unbind ( ) ?
2980
- . bind ( gc. nogc ( ) ) ;
2981
- // 7. If O.[[ContentType]] is bigint, let numericValue be ? ToBigInt(value).
2982
- let numeric_value = T :: from_le_value ( agent, numeric_value) ;
2983
- // 3. Let len be TypedArrayLength(taRecord).
2984
- let len = typed_array_length :: < T > ( agent, & ta_record, gc. nogc ( ) ) as i64 ;
2901
+ // 7. If O.[[ContentType]] is BIGINT, let numericValue be ? ToBigInt(value).
2902
+ let numeric_value = if T :: IS_BIGINT {
2903
+ to_big_int ( agent, scoped_value. get ( agent) , gc. reborrow ( ) )
2904
+ . unbind ( ) ?
2905
+ . bind ( gc. nogc ( ) )
2906
+ . into_numeric ( )
2907
+ } else {
2908
+ // 8. Else, let numericValue be ? ToNumber(value).
2909
+ to_number ( agent, scoped_value. get ( agent) , gc. reborrow ( ) )
2910
+ . unbind ( ) ?
2911
+ . bind ( gc. nogc ( ) )
2912
+ . into_numeric ( )
2913
+ } ;
2914
+ let numeric_value = T :: from_ne_value ( agent, numeric_value) ;
2985
2915
// 5. If relativeIndex ≥ 0, let actualIndex be relativeIndex.
2986
2916
let actual_index = if relative_index >= 0 {
2987
2917
relative_index
@@ -2990,15 +2920,15 @@ fn with_typed_array<'a, T: Viewable + std::fmt::Debug>(
2990
2920
len + relative_index
2991
2921
} ;
2992
2922
// 9. If IsValidIntegerIndex(O, 𝔽(actualIndex)) is false, throw a RangeError exception.
2993
- if is_valid_integer_index_generic ( agent, o , actual_index, gc. nogc ( ) ) . is_none ( ) {
2923
+ if is_valid_integer_index :: < T > ( agent, scoped_o . get ( agent ) , actual_index, gc. nogc ( ) ) . is_none ( ) {
2994
2924
return Err ( agent. throw_exception_with_static_message (
2995
2925
ExceptionType :: RangeError ,
2996
2926
"Index out of bounds" ,
2997
2927
gc. into_nogc ( ) ,
2998
2928
) ) ;
2999
2929
}
3000
2930
// 10. Let A be ? TypedArrayCreateSameType(O, « 𝔽(len) »).
3001
- let a = typed_array_create_same_type ( agent, o , len, gc. reborrow ( ) )
2931
+ let a = typed_array_create_same_type ( agent, scoped_o . get ( agent ) , len, gc. reborrow ( ) )
3002
2932
. unbind ( ) ?
3003
2933
. bind ( gc. nogc ( ) ) ;
3004
2934
// 11. Let k be 0.
@@ -3008,7 +2938,8 @@ fn with_typed_array<'a, T: Viewable + std::fmt::Debug>(
3008
2938
// c. Else, let fromValue be ! Get(O, Pk).
3009
2939
// d. Perform ! Set(A, Pk, fromValue, true).
3010
2940
// e. Set k to k + 1.
3011
- let ( a_slice, o_slice) = split_typed_array_views :: < T > ( agent, a, o, gc. nogc ( ) ) . unwrap ( ) ;
2941
+ let ( a_slice, o_slice) =
2942
+ split_typed_array_views :: < T > ( agent, a, scoped_o. get ( agent) , gc. nogc ( ) ) . unwrap ( ) ;
3012
2943
let len = len as usize ;
3013
2944
let a_slice = & mut a_slice[ ..len] ;
3014
2945
let o_slice = & o_slice[ ..len] ;
0 commit comments