@@ -148,33 +148,25 @@ impl ArrayBuffer {
148
148
) -> JsResult < JsValue > {
149
149
// 1. Let O be the this value.
150
150
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
151
- let obj = if let Some ( obj) = this. as_object ( ) {
152
- obj
153
- } else {
154
- return Err ( JsNativeError :: typ ( )
155
- . with_message ( "ArrayBuffer.byteLength called with non-object value" )
156
- . into ( ) ) ;
157
- } ;
151
+ let obj = this. as_object ( ) . ok_or_else ( || {
152
+ JsNativeError :: typ ( ) . with_message ( "ArrayBuffer.byteLength called with non-object value" )
153
+ } ) ?;
158
154
let obj = obj. borrow ( ) ;
159
- let o = if let Some ( o) = obj. as_array_buffer ( ) {
160
- o
161
- } else {
162
- return Err ( JsNativeError :: typ ( )
163
- . with_message ( "ArrayBuffer.byteLength called with invalid object" )
164
- . into ( ) ) ;
165
- } ;
155
+ let buf = obj. as_array_buffer ( ) . ok_or_else ( || {
156
+ JsNativeError :: typ ( ) . with_message ( "ArrayBuffer.byteLength called with invalid object" )
157
+ } ) ?;
166
158
167
159
// TODO: Shared Array Buffer
168
160
// 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
169
161
170
162
// 4. If IsDetachedBuffer(O) is true, return +0𝔽.
171
- if Self :: is_detached_buffer ( o ) {
163
+ if Self :: is_detached_buffer ( buf ) {
172
164
return Ok ( 0 . into ( ) ) ;
173
165
}
174
166
175
167
// 5. Let length be O.[[ArrayBufferByteLength]].
176
168
// 6. Return 𝔽(length).
177
- Ok ( o . array_buffer_byte_length . into ( ) )
169
+ Ok ( buf . array_buffer_byte_length . into ( ) )
178
170
}
179
171
180
172
/// `25.1.5.3 ArrayBuffer.prototype.slice ( start, end )`
@@ -186,34 +178,26 @@ impl ArrayBuffer {
186
178
fn slice ( this : & JsValue , args : & [ JsValue ] , context : & mut Context ) -> JsResult < JsValue > {
187
179
// 1. Let O be the this value.
188
180
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
189
- let obj = if let Some ( obj) = this. as_object ( ) {
190
- obj
191
- } else {
192
- return Err ( JsNativeError :: typ ( )
193
- . with_message ( "ArrayBuffer.slice called with non-object value" )
194
- . into ( ) ) ;
195
- } ;
181
+ let obj = this. as_object ( ) . ok_or_else ( || {
182
+ JsNativeError :: typ ( ) . with_message ( "ArrayBuffer.slice called with non-object value" )
183
+ } ) ?;
196
184
let obj_borrow = obj. borrow ( ) ;
197
- let o = if let Some ( o) = obj_borrow. as_array_buffer ( ) {
198
- o
199
- } else {
200
- return Err ( JsNativeError :: typ ( )
201
- . with_message ( "ArrayBuffer.slice called with invalid object" )
202
- . into ( ) ) ;
203
- } ;
185
+ let buf = obj_borrow. as_array_buffer ( ) . ok_or_else ( || {
186
+ JsNativeError :: typ ( ) . with_message ( "ArrayBuffer.slice called with invalid object" )
187
+ } ) ?;
204
188
205
189
// TODO: Shared Array Buffer
206
190
// 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
207
191
208
192
// 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
209
- if Self :: is_detached_buffer ( o ) {
193
+ if Self :: is_detached_buffer ( buf ) {
210
194
return Err ( JsNativeError :: typ ( )
211
195
. with_message ( "ArrayBuffer.slice called with detached buffer" )
212
196
. into ( ) ) ;
213
197
}
214
198
215
199
// 5. Let len be O.[[ArrayBufferByteLength]].
216
- let len = o . array_buffer_byte_length as i64 ;
200
+ let len = buf . array_buffer_byte_length as i64 ;
217
201
218
202
// 6. Let relativeStart be ? ToIntegerOrInfinity(start).
219
203
let relative_start = args. get_or_undefined ( 0 ) . to_integer_or_infinity ( context) ?;
@@ -298,14 +282,14 @@ impl ArrayBuffer {
298
282
299
283
// 22. NOTE: Side-effects of the above steps may have detached O.
300
284
// 23. If IsDetachedBuffer(O) is true, throw a TypeError exception.
301
- if Self :: is_detached_buffer ( o ) {
285
+ if Self :: is_detached_buffer ( buf ) {
302
286
return Err ( JsNativeError :: typ ( )
303
287
. with_message ( "ArrayBuffer detached while ArrayBuffer.slice was running" )
304
288
. into ( ) ) ;
305
289
}
306
290
307
291
// 24. Let fromBuf be O.[[ArrayBufferData]].
308
- let from_buf = o
292
+ let from_buf = buf
309
293
. array_buffer_data
310
294
. as_ref ( )
311
295
. expect ( "ArrayBuffer cannot be detached here" ) ;
@@ -389,13 +373,9 @@ impl ArrayBuffer {
389
373
390
374
// 2. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
391
375
// 3. Let srcBlock be srcBuffer.[[ArrayBufferData]].
392
- let src_block = if let Some ( b) = & self . array_buffer_data {
393
- b
394
- } else {
395
- return Err ( JsNativeError :: syntax ( )
396
- . with_message ( "Cannot clone detached array buffer" )
397
- . into ( ) ) ;
398
- } ;
376
+ let src_block = self . array_buffer_data . as_deref ( ) . ok_or_else ( || {
377
+ JsNativeError :: syntax ( ) . with_message ( "Cannot clone detached array buffer" )
378
+ } ) ?;
399
379
400
380
{
401
381
// 4. Let targetBlock be targetBuffer.[[ArrayBufferData]].
0 commit comments