Coverage Report

Created: 2025-06-16 06:50

/rust/git/checkouts/mozjs-fa11ffc7d4f1cc2d/d90edd1/mozjs-sys/src/jsimpls.rs
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
use crate::jsapi::glue::JS_ForOfIteratorInit;
6
use crate::jsapi::glue::JS_ForOfIteratorNext;
7
use crate::jsapi::jsid;
8
use crate::jsapi::mozilla;
9
use crate::jsapi::JSAutoRealm;
10
use crate::jsapi::JSContext;
11
use crate::jsapi::JSErrNum;
12
use crate::jsapi::JSFunctionSpec;
13
use crate::jsapi::JSJitGetterCallArgs;
14
use crate::jsapi::JSJitMethodCallArgs;
15
use crate::jsapi::JSJitSetterCallArgs;
16
use crate::jsapi::JSNativeWrapper;
17
use crate::jsapi::JSObject;
18
use crate::jsapi::JSPropertySpec;
19
use crate::jsapi::JSPropertySpec_Kind;
20
use crate::jsapi::JSPropertySpec_Name;
21
use crate::jsapi::JS;
22
use crate::jsapi::JS::Scalar::Type;
23
use crate::jsgc::RootKind;
24
use crate::jsid::VoidId;
25
use crate::jsval::UndefinedValue;
26
27
use std::marker::PhantomData;
28
use std::ops::Deref;
29
use std::ops::DerefMut;
30
use std::os::raw::c_void;
31
use std::ptr;
32
33
impl<T> Deref for JS::Handle<T> {
34
    type Target = T;
35
36
0
    fn deref<'a>(&'a self) -> &'a T {
37
0
        unsafe { &*self.ptr }
38
0
    }
39
}
40
41
impl<T> Deref for JS::MutableHandle<T> {
42
    type Target = T;
43
44
0
    fn deref<'a>(&'a self) -> &'a T {
45
0
        unsafe { &*self.ptr }
46
0
    }
47
}
48
49
impl<T> DerefMut for JS::MutableHandle<T> {
50
0
    fn deref_mut<'a>(&'a mut self) -> &'a mut T {
51
0
        unsafe { &mut *self.ptr }
52
0
    }
53
}
54
55
impl Default for jsid {
56
0
    fn default() -> Self {
57
0
        VoidId()
58
0
    }
59
}
60
61
impl Default for JS::PropertyDescriptor {
62
0
    fn default() -> Self {
63
0
        JS::PropertyDescriptor {
64
0
            _bitfield_align_1: [],
65
0
            _bitfield_1: Default::default(),
66
0
            getter_: ptr::null_mut(),
67
0
            setter_: ptr::null_mut(),
68
0
            value_: UndefinedValue(),
69
0
        }
70
0
    }
71
}
72
73
impl Drop for JSAutoRealm {
74
26.3k
    fn drop(&mut self) {
75
26.3k
        unsafe {
76
26.3k
            JS::LeaveRealm(self.cx_, self.oldRealm_);
77
26.3k
        }
78
26.3k
    }
79
}
80
81
impl<T> JS::Handle<T> {
82
0
    pub fn get(&self) -> T
83
0
    where
84
0
        T: Copy,
85
0
    {
86
0
        unsafe { *self.ptr }
87
0
    }
88
89
13.1k
    pub unsafe fn from_marked_location(ptr: *const T) -> JS::Handle<T> {
90
13.1k
        JS::Handle {
91
13.1k
            ptr: ptr as *mut T,
92
13.1k
            _phantom_0: PhantomData,
93
13.1k
        }
94
13.1k
    }
Unexecuted instantiation: <mozjs_sys::generated::root::JS::Handle<mozjs_sys::generated::root::JS::Value>>::from_marked_location
<mozjs_sys::generated::root::JS::Handle<*mut mozjs_sys::generated::root::JSObject>>::from_marked_location
Line
Count
Source
89
13.1k
    pub unsafe fn from_marked_location(ptr: *const T) -> JS::Handle<T> {
90
13.1k
        JS::Handle {
91
13.1k
            ptr: ptr as *mut T,
92
13.1k
            _phantom_0: PhantomData,
93
13.1k
        }
94
13.1k
    }
95
}
96
97
impl<T> JS::MutableHandle<T> {
98
39.4k
    pub unsafe fn from_marked_location(ptr: *mut T) -> JS::MutableHandle<T> {
99
39.4k
        JS::MutableHandle {
100
39.4k
            ptr,
101
39.4k
            _phantom_0: PhantomData,
102
39.4k
        }
103
39.4k
    }
<mozjs_sys::generated::root::JS::MutableHandle<mozjs_sys::generated::root::JS::Value>>::from_marked_location
Line
Count
Source
98
39.4k
    pub unsafe fn from_marked_location(ptr: *mut T) -> JS::MutableHandle<T> {
99
39.4k
        JS::MutableHandle {
100
39.4k
            ptr,
101
39.4k
            _phantom_0: PhantomData,
102
39.4k
        }
103
39.4k
    }
Unexecuted instantiation: <mozjs_sys::generated::root::JS::MutableHandle<*mut mozjs_sys::generated::root::JSObject>>::from_marked_location
Unexecuted instantiation: <mozjs_sys::generated::root::JS::MutableHandle<*mut mozjs_sys::generated::root::JSString>>::from_marked_location
Unexecuted instantiation: <mozjs_sys::generated::root::JS::MutableHandle<_>>::from_marked_location
104
105
0
    pub fn handle(&self) -> JS::Handle<T> {
106
0
        unsafe { JS::Handle::from_marked_location(self.ptr as *const _) }
107
0
    }
108
109
0
    pub fn get(&self) -> T
110
0
    where
111
0
        T: Copy,
112
0
    {
113
0
        unsafe { *self.ptr }
114
0
    }
115
116
0
    pub fn set(&self, v: T)
117
0
    where
118
0
        T: Copy,
119
0
    {
120
0
        unsafe { *self.ptr = v }
121
0
    }
122
}
123
124
impl JS::HandleValue {
125
0
    pub fn null() -> JS::HandleValue {
126
0
        unsafe { JS::NullHandleValue }
127
0
    }
128
129
0
    pub fn undefined() -> JS::HandleValue {
130
0
        unsafe { JS::UndefinedHandleValue }
131
0
    }
132
}
133
134
impl JS::HandleValueArray {
135
0
    pub fn new() -> JS::HandleValueArray {
136
0
        JS::HandleValueArray {
137
0
            length_: 0,
138
0
            elements_: ptr::null(),
139
0
        }
140
0
    }
141
142
13.1k
    pub unsafe fn from_rooted_slice(values: &[JS::Value]) -> JS::HandleValueArray {
143
13.1k
        JS::HandleValueArray {
144
13.1k
            length_: values.len(),
145
13.1k
            elements_: values.as_ptr(),
146
13.1k
        }
147
13.1k
    }
148
}
149
150
const NULL_OBJECT: *mut JSObject = 0 as *mut JSObject;
151
152
impl JS::HandleObject {
153
0
    pub fn null() -> JS::HandleObject {
154
0
        unsafe { JS::HandleObject::from_marked_location(&NULL_OBJECT) }
155
0
    }
156
}
157
158
// ___________________________________________________________________________
159
// Implementations for various things in jsapi.rs
160
161
impl JSAutoRealm {
162
26.3k
    pub fn new(cx: *mut JSContext, target: *mut JSObject) -> JSAutoRealm {
163
26.3k
        JSAutoRealm {
164
26.3k
            cx_: cx,
165
26.3k
            oldRealm_: unsafe { JS::EnterRealm(cx, target) },
166
26.3k
        }
167
26.3k
    }
168
}
169
170
impl JS::AutoGCRooter {
171
0
    pub fn new_unrooted(kind: JS::AutoGCRooterKind) -> JS::AutoGCRooter {
172
0
        JS::AutoGCRooter {
173
0
            down: ptr::null_mut(),
174
0
            kind_: kind,
175
0
            stackTop: ptr::null_mut(),
176
0
        }
177
0
    }
178
179
0
    pub unsafe fn add_to_root_stack(&mut self, cx: *mut JSContext) {
180
0
        #[allow(non_snake_case)]
181
0
        let autoGCRooters: *mut _ = {
182
0
            let rooting_cx = cx as *mut JS::RootingContext;
183
0
            &mut (*rooting_cx).autoGCRooters_[self.kind_ as usize]
184
0
        };
185
0
        self.stackTop = autoGCRooters as *mut *mut _;
186
0
        self.down = *autoGCRooters as *mut _;
187
0
188
0
        assert!(*self.stackTop != self);
189
0
        *autoGCRooters = self as *mut _ as _;
190
0
    }
191
192
0
    pub unsafe fn remove_from_root_stack(&mut self) {
193
0
        assert!(*self.stackTop == self);
194
0
        *self.stackTop = self.down;
195
0
    }
196
}
197
198
impl JSJitMethodCallArgs {
199
    #[inline]
200
0
    pub fn get(&self, i: u32) -> JS::HandleValue {
201
0
        unsafe {
202
0
            if i < self.argc_ {
203
0
                JS::HandleValue::from_marked_location(self.argv_.offset(i as isize))
204
            } else {
205
0
                JS::UndefinedHandleValue
206
            }
207
        }
208
0
    }
209
210
    #[inline]
211
0
    pub fn index(&self, i: u32) -> JS::HandleValue {
212
0
        assert!(i < self.argc_);
213
0
        unsafe { JS::HandleValue::from_marked_location(self.argv_.offset(i as isize)) }
214
0
    }
215
216
    #[inline]
217
0
    pub fn index_mut(&self, i: u32) -> JS::MutableHandleValue {
218
0
        assert!(i < self.argc_);
219
0
        unsafe { JS::MutableHandleValue::from_marked_location(self.argv_.offset(i as isize)) }
220
0
    }
221
222
    #[inline]
223
0
    pub fn rval(&self) -> JS::MutableHandleValue {
224
0
        unsafe { JS::MutableHandleValue::from_marked_location(self.argv_.offset(-2)) }
225
0
    }
226
}
227
228
impl JSJitGetterCallArgs {
229
    #[inline]
230
0
    pub fn rval(&self) -> JS::MutableHandleValue {
231
0
        self._base
232
0
    }
233
}
234
235
// XXX need to hack up bindgen to convert this better so we don't have
236
//     to duplicate so much code here
237
impl JS::CallArgs {
238
    #[inline]
239
0
    pub unsafe fn from_vp(vp: *mut JS::Value, argc: u32) -> JS::CallArgs {
240
0
        // For some reason, with debugmozjs, calling
241
0
        // JS_CallArgsFromVp(argc, vp)
242
0
        // produces a SEGV caused by the vp being overwritten by the argc.
243
0
        // TODO: debug this!
244
0
        JS::CallArgs {
245
0
            _bitfield_align_1: Default::default(),
246
0
            _bitfield_1: JS::CallArgs::new_bitfield_1((*vp.offset(1)).is_magic(), false),
247
0
            argc_: argc,
248
0
            argv_: vp.offset(2),
249
0
            #[cfg(not(feature = "debugmozjs"))]
250
0
            __bindgen_padding_0: [0, 0, 0],
251
0
            #[cfg(feature = "debugmozjs")]
252
0
            wantUsedRval_: JS::detail::IncludeUsedRval { usedRval_: false },
253
0
        }
254
0
    }
255
256
    #[inline]
257
0
    pub fn index(&self, i: u32) -> JS::HandleValue {
258
0
        assert!(i < self.argc_);
259
0
        unsafe { JS::HandleValue::from_marked_location(self.argv_.offset(i as isize)) }
260
0
    }
261
262
    #[inline]
263
0
    pub fn index_mut(&self, i: u32) -> JS::MutableHandleValue {
264
0
        assert!(i < self.argc_);
265
0
        unsafe { JS::MutableHandleValue::from_marked_location(self.argv_.offset(i as isize)) }
266
0
    }
267
268
    #[inline]
269
0
    pub fn get(&self, i: u32) -> JS::HandleValue {
270
0
        unsafe {
271
0
            if i < self.argc_ {
272
0
                JS::HandleValue::from_marked_location(self.argv_.offset(i as isize))
273
            } else {
274
0
                JS::UndefinedHandleValue
275
            }
276
        }
277
0
    }
278
279
    #[inline]
280
0
    pub fn rval(&self) -> JS::MutableHandleValue {
281
0
        unsafe { JS::MutableHandleValue::from_marked_location(self.argv_.offset(-2)) }
282
0
    }
283
284
    #[inline]
285
0
    pub fn thisv(&self) -> JS::HandleValue {
286
0
        unsafe { JS::HandleValue::from_marked_location(self.argv_.offset(-1)) }
287
0
    }
288
289
    #[inline]
290
0
    pub fn calleev(&self) -> JS::HandleValue {
291
0
        unsafe { JS::HandleValue::from_marked_location(self.argv_.offset(-2)) }
292
0
    }
293
294
    #[inline]
295
0
    pub fn callee(&self) -> *mut JSObject {
296
0
        self.calleev().to_object()
297
0
    }
298
299
    #[inline]
300
0
    pub fn new_target(&self) -> JS::MutableHandleValue {
301
0
        assert!(self.constructing_());
302
        unsafe {
303
0
            JS::MutableHandleValue::from_marked_location(self.argv_.offset(self.argc_ as isize))
304
0
        }
305
0
    }
306
307
    #[inline]
308
0
    pub fn is_constructing(&self) -> bool {
309
0
        unsafe { (*self.argv_.offset(-1)).is_magic() }
310
0
    }
311
}
312
313
impl JSJitSetterCallArgs {
314
    #[inline]
315
0
    pub fn get(&self, i: u32) -> JS::HandleValue {
316
0
        assert!(i == 0);
317
0
        self._base.handle()
318
0
    }
319
}
320
321
impl JSFunctionSpec {
322
    pub const ZERO: Self = JSFunctionSpec {
323
        name: JSPropertySpec_Name {
324
            string_: ptr::null(),
325
        },
326
        selfHostedName: 0 as *const _,
327
        flags: 0,
328
        nargs: 0,
329
        call: JSNativeWrapper::ZERO,
330
    };
331
332
0
    pub fn is_zeroed(&self) -> bool {
333
0
        (unsafe { self.name.string_.is_null() })
334
0
            && self.selfHostedName.is_null()
335
0
            && self.flags == 0
336
0
            && self.nargs == 0
337
0
            && self.call.is_zeroed()
338
0
    }
339
}
340
341
impl JSPropertySpec {
342
    pub const ZERO: Self = JSPropertySpec {
343
        name: JSPropertySpec_Name {
344
            string_: ptr::null(),
345
        },
346
        attributes_: 0,
347
        kind_: JSPropertySpec_Kind::NativeAccessor,
348
        u: crate::jsapi::JSPropertySpec_AccessorsOrValue {
349
            accessors: crate::jsapi::JSPropertySpec_AccessorsOrValue_Accessors {
350
                getter: crate::jsapi::JSPropertySpec_Accessor {
351
                    native: JSNativeWrapper::ZERO,
352
                },
353
                setter: crate::jsapi::JSPropertySpec_Accessor {
354
                    native: JSNativeWrapper::ZERO,
355
                },
356
            },
357
        },
358
    };
359
360
    /// https://searchfox.org/mozilla-central/rev/2bdaa395cb841b28f8ef74882a61df5efeedb42b/js/public/PropertySpec.h#305-307
361
0
    pub fn is_accessor(&self) -> bool {
362
0
        self.kind_ == JSPropertySpec_Kind::NativeAccessor
363
0
            || self.kind_ == JSPropertySpec_Kind::SelfHostedAccessor
364
0
    }
365
366
0
    pub fn is_zeroed(&self) -> bool {
367
0
        (unsafe { self.name.string_.is_null() })
368
0
            && self.attributes_ == 0
369
0
            && self.is_accessor()
370
0
            && unsafe { self.u.accessors.getter.native.is_zeroed() }
371
0
            && unsafe { self.u.accessors.setter.native.is_zeroed() }
372
0
    }
373
}
374
375
impl JSNativeWrapper {
376
    pub const ZERO: Self = JSNativeWrapper {
377
        info: 0 as *const _,
378
        op: None,
379
    };
380
381
0
    pub fn is_zeroed(&self) -> bool {
382
0
        self.op.is_none() && self.info.is_null()
383
0
    }
384
}
385
386
impl<T> JS::Rooted<T> {
387
65.7k
    pub fn new_unrooted() -> JS::Rooted<T> {
388
65.7k
        JS::Rooted {
389
65.7k
            stack: ptr::null_mut(),
390
65.7k
            prev: ptr::null_mut(),
391
65.7k
            ptr: unsafe { std::mem::zeroed() },
392
65.7k
        }
393
65.7k
    }
<mozjs_sys::jsgc::Rooted<mozjs_sys::generated::root::JS::Value>>::new_unrooted
Line
Count
Source
387
52.6k
    pub fn new_unrooted() -> JS::Rooted<T> {
388
52.6k
        JS::Rooted {
389
52.6k
            stack: ptr::null_mut(),
390
52.6k
            prev: ptr::null_mut(),
391
52.6k
            ptr: unsafe { std::mem::zeroed() },
392
52.6k
        }
393
52.6k
    }
<mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSObject>>::new_unrooted
Line
Count
Source
387
13.1k
    pub fn new_unrooted() -> JS::Rooted<T> {
388
13.1k
        JS::Rooted {
389
13.1k
            stack: ptr::null_mut(),
390
13.1k
            prev: ptr::null_mut(),
391
13.1k
            ptr: unsafe { std::mem::zeroed() },
392
13.1k
        }
393
13.1k
    }
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSString>>::new_unrooted
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<_>>::new_unrooted
394
395
65.7k
    unsafe fn get_rooting_context(cx: *mut JSContext) -> *mut JS::RootingContext {
396
65.7k
        cx as *mut JS::RootingContext
397
65.7k
    }
<mozjs_sys::jsgc::Rooted<mozjs_sys::generated::root::JS::Value>>::get_rooting_context
Line
Count
Source
395
52.6k
    unsafe fn get_rooting_context(cx: *mut JSContext) -> *mut JS::RootingContext {
396
52.6k
        cx as *mut JS::RootingContext
397
52.6k
    }
<mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSObject>>::get_rooting_context
Line
Count
Source
395
13.1k
    unsafe fn get_rooting_context(cx: *mut JSContext) -> *mut JS::RootingContext {
396
13.1k
        cx as *mut JS::RootingContext
397
13.1k
    }
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSString>>::get_rooting_context
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<_>>::get_rooting_context
398
399
65.7k
    unsafe fn get_root_stack(cx: *mut JSContext) -> *mut *mut JS::Rooted<*mut c_void>
400
65.7k
    where
401
65.7k
        T: RootKind,
402
65.7k
    {
403
65.7k
        let kind = T::rootKind() as usize;
404
65.7k
        let rooting_cx = Self::get_rooting_context(cx);
405
65.7k
        &mut (*rooting_cx).stackRoots_[kind] as *mut _ as *mut _
406
65.7k
    }
<mozjs_sys::jsgc::Rooted<mozjs_sys::generated::root::JS::Value>>::get_root_stack
Line
Count
Source
399
52.6k
    unsafe fn get_root_stack(cx: *mut JSContext) -> *mut *mut JS::Rooted<*mut c_void>
400
52.6k
    where
401
52.6k
        T: RootKind,
402
52.6k
    {
403
52.6k
        let kind = T::rootKind() as usize;
404
52.6k
        let rooting_cx = Self::get_rooting_context(cx);
405
52.6k
        &mut (*rooting_cx).stackRoots_[kind] as *mut _ as *mut _
406
52.6k
    }
<mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSObject>>::get_root_stack
Line
Count
Source
399
13.1k
    unsafe fn get_root_stack(cx: *mut JSContext) -> *mut *mut JS::Rooted<*mut c_void>
400
13.1k
    where
401
13.1k
        T: RootKind,
402
13.1k
    {
403
13.1k
        let kind = T::rootKind() as usize;
404
13.1k
        let rooting_cx = Self::get_rooting_context(cx);
405
13.1k
        &mut (*rooting_cx).stackRoots_[kind] as *mut _ as *mut _
406
13.1k
    }
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSString>>::get_root_stack
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<_>>::get_root_stack
407
408
65.7k
    pub unsafe fn add_to_root_stack(&mut self, cx: *mut JSContext)
409
65.7k
    where
410
65.7k
        T: RootKind,
411
65.7k
    {
412
65.7k
        let stack = Self::get_root_stack(cx);
413
65.7k
        self.stack = stack;
414
65.7k
        self.prev = *stack;
415
65.7k
416
65.7k
        *stack = self as *mut _ as usize as _;
417
65.7k
    }
<mozjs_sys::jsgc::Rooted<mozjs_sys::generated::root::JS::Value>>::add_to_root_stack
Line
Count
Source
408
52.6k
    pub unsafe fn add_to_root_stack(&mut self, cx: *mut JSContext)
409
52.6k
    where
410
52.6k
        T: RootKind,
411
52.6k
    {
412
52.6k
        let stack = Self::get_root_stack(cx);
413
52.6k
        self.stack = stack;
414
52.6k
        self.prev = *stack;
415
52.6k
416
52.6k
        *stack = self as *mut _ as usize as _;
417
52.6k
    }
<mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSObject>>::add_to_root_stack
Line
Count
Source
408
13.1k
    pub unsafe fn add_to_root_stack(&mut self, cx: *mut JSContext)
409
13.1k
    where
410
13.1k
        T: RootKind,
411
13.1k
    {
412
13.1k
        let stack = Self::get_root_stack(cx);
413
13.1k
        self.stack = stack;
414
13.1k
        self.prev = *stack;
415
13.1k
416
13.1k
        *stack = self as *mut _ as usize as _;
417
13.1k
    }
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSString>>::add_to_root_stack
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<_>>::add_to_root_stack
418
419
65.7k
    pub unsafe fn remove_from_root_stack(&mut self) {
420
65.7k
        assert!(*self.stack == self as *mut _ as usize as _);
421
65.7k
        *self.stack = self.prev;
422
65.7k
    }
<mozjs_sys::jsgc::Rooted<mozjs_sys::generated::root::JS::Value>>::remove_from_root_stack
Line
Count
Source
419
52.6k
    pub unsafe fn remove_from_root_stack(&mut self) {
420
52.6k
        assert!(*self.stack == self as *mut _ as usize as _);
421
52.6k
        *self.stack = self.prev;
422
52.6k
    }
<mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSObject>>::remove_from_root_stack
Line
Count
Source
419
13.1k
    pub unsafe fn remove_from_root_stack(&mut self) {
420
13.1k
        assert!(*self.stack == self as *mut _ as usize as _);
421
13.1k
        *self.stack = self.prev;
422
13.1k
    }
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<*mut mozjs_sys::generated::root::JSString>>::remove_from_root_stack
Unexecuted instantiation: <mozjs_sys::jsgc::Rooted<_>>::remove_from_root_stack
423
}
424
425
impl JS::ObjectOpResult {
426
0
    pub fn ok(&self) -> bool {
427
0
        assert_ne!(
428
0
            self.code_,
429
0
            JS::ObjectOpResult_SpecialCodes::Uninitialized as usize
430
0
        );
431
0
        self.code_ == JS::ObjectOpResult_SpecialCodes::OkCode as usize
432
0
    }
433
434
    /// Set this ObjectOpResult to true and return true.
435
0
    pub fn succeed(&mut self) -> bool {
436
0
        self.code_ = JS::ObjectOpResult_SpecialCodes::OkCode as usize;
437
0
        true
438
0
    }
439
440
0
    pub fn fail(&mut self, code: JSErrNum) -> bool {
441
0
        assert_ne!(
442
0
            code as usize,
443
0
            JS::ObjectOpResult_SpecialCodes::OkCode as usize
444
0
        );
445
0
        self.code_ = code as usize;
446
0
        true
447
0
    }
448
449
0
    pub fn fail_cant_redefine_prop(&mut self) -> bool {
450
0
        self.fail(JSErrNum::JSMSG_CANT_REDEFINE_PROP)
451
0
    }
452
453
0
    pub fn fail_read_only(&mut self) -> bool {
454
0
        self.fail(JSErrNum::JSMSG_READ_ONLY)
455
0
    }
456
457
0
    pub fn fail_getter_only(&mut self) -> bool {
458
0
        self.fail(JSErrNum::JSMSG_GETTER_ONLY)
459
0
    }
460
461
0
    pub fn fail_cant_delete(&mut self) -> bool {
462
0
        self.fail(JSErrNum::JSMSG_CANT_DELETE)
463
0
    }
464
465
0
    pub fn fail_cant_set_interposed(&mut self) -> bool {
466
0
        self.fail(JSErrNum::JSMSG_CANT_SET_INTERPOSED)
467
0
    }
468
469
0
    pub fn fail_cant_define_window_element(&mut self) -> bool {
470
0
        self.fail(JSErrNum::JSMSG_CANT_DEFINE_WINDOW_ELEMENT)
471
0
    }
472
473
0
    pub fn fail_cant_delete_window_element(&mut self) -> bool {
474
0
        self.fail(JSErrNum::JSMSG_CANT_DELETE_WINDOW_ELEMENT)
475
0
    }
476
477
0
    pub fn fail_cant_define_window_named_property(&mut self) -> bool {
478
0
        self.fail(JSErrNum::JSMSG_CANT_DEFINE_WINDOW_NAMED_PROPERTY)
479
0
    }
480
481
0
    pub fn fail_cant_delete_window_named_property(&mut self) -> bool {
482
0
        self.fail(JSErrNum::JSMSG_CANT_DELETE_WINDOW_NAMED_PROPERTY)
483
0
    }
484
485
0
    pub fn fail_cant_define_window_non_configurable(&mut self) -> bool {
486
0
        self.fail(JSErrNum::JSMSG_CANT_DEFINE_WINDOW_NC)
487
0
    }
488
489
0
    pub fn fail_cant_prevent_extensions(&mut self) -> bool {
490
0
        self.fail(JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS)
491
0
    }
492
493
0
    pub fn fail_cant_set_proto(&mut self) -> bool {
494
0
        self.fail(JSErrNum::JSMSG_CANT_SET_PROTO)
495
0
    }
496
497
0
    pub fn fail_no_named_setter(&mut self) -> bool {
498
0
        self.fail(JSErrNum::JSMSG_NO_NAMED_SETTER)
499
0
    }
500
501
0
    pub fn fail_no_indexed_setter(&mut self) -> bool {
502
0
        self.fail(JSErrNum::JSMSG_NO_INDEXED_SETTER)
503
0
    }
504
505
0
    pub fn fail_not_data_descriptor(&mut self) -> bool {
506
0
        self.fail(JSErrNum::JSMSG_NOT_DATA_DESCRIPTOR)
507
0
    }
508
509
0
    pub fn fail_invalid_descriptor(&mut self) -> bool {
510
0
        self.fail(JSErrNum::JSMSG_INVALID_DESCRIPTOR)
511
0
    }
512
513
0
    pub fn fail_bad_array_length(&mut self) -> bool {
514
0
        self.fail(JSErrNum::JSMSG_BAD_ARRAY_LENGTH)
515
0
    }
516
517
0
    pub fn fail_bad_index(&mut self) -> bool {
518
0
        self.fail(JSErrNum::JSMSG_BAD_INDEX)
519
0
    }
520
521
0
    pub fn failure_code(&self) -> u32 {
522
0
        assert!(!self.ok());
523
0
        self.code_ as u32
524
0
    }
525
526
    #[deprecated]
527
    #[allow(non_snake_case)]
528
0
    pub fn failNoNamedSetter(&mut self) -> bool {
529
0
        self.fail_no_named_setter()
530
0
    }
531
}
532
533
impl Default for JS::ObjectOpResult {
534
0
    fn default() -> JS::ObjectOpResult {
535
0
        JS::ObjectOpResult {
536
0
            code_: JS::ObjectOpResult_SpecialCodes::Uninitialized as usize,
537
0
        }
538
0
    }
539
}
540
541
impl JS::ForOfIterator {
542
0
    pub unsafe fn init(
543
0
        &mut self,
544
0
        iterable: JS::HandleValue,
545
0
        non_iterable_behavior: JS::ForOfIterator_NonIterableBehavior,
546
0
    ) -> bool {
547
0
        JS_ForOfIteratorInit(self, iterable, non_iterable_behavior)
548
0
    }
549
550
0
    pub unsafe fn next(&mut self, val: JS::MutableHandleValue, done: *mut bool) -> bool {
551
0
        JS_ForOfIteratorNext(self, val, done)
552
0
    }
553
}
554
555
impl<T> mozilla::Range<T> {
556
0
    pub fn new(start: &mut T, end: &mut T) -> mozilla::Range<T> {
557
0
        mozilla::Range {
558
0
            mStart: mozilla::RangedPtr {
559
0
                mPtr: start,
560
0
                #[cfg(feature = "debugmozjs")]
561
0
                mRangeStart: start,
562
0
                #[cfg(feature = "debugmozjs")]
563
0
                mRangeEnd: end,
564
0
                _phantom_0: PhantomData,
565
0
            },
566
0
            mEnd: mozilla::RangedPtr {
567
0
                mPtr: end,
568
0
                #[cfg(feature = "debugmozjs")]
569
0
                mRangeStart: start,
570
0
                #[cfg(feature = "debugmozjs")]
571
0
                mRangeEnd: end,
572
0
                _phantom_0: PhantomData,
573
0
            },
574
0
            _phantom_0: PhantomData,
575
0
        }
576
0
    }
577
}
578
579
impl Type {
580
    /// Returns byte size of Type (if possible to determine)
581
    ///
582
    /// <https://searchfox.org/mozilla-central/rev/396a6123691f7ab3ffb449dcbe95304af6f9df3c/js/public/ScalarType.h#66>
583
0
    pub const fn byte_size(&self) -> Option<usize> {
584
0
        match self {
585
0
            Type::Int8 | Type::Uint8 | Type::Uint8Clamped => Some(1),
586
0
            Type::Int16 | Type::Uint16 | Type::Float16 => Some(2),
587
0
            Type::Int32 | Type::Uint32 | Type::Float32 => Some(4),
588
0
            Type::Int64 | Type::Float64 | Type::BigInt64 | Type::BigUint64 => Some(8),
589
0
            Type::Simd128 => Some(16),
590
0
            Type::MaxTypedArrayViewType => None,
591
        }
592
0
    }
593
}