Skip to content

Commit e733a7c

Browse files
committed
Support the updated spidermonkey bindings
1 parent 32daa17 commit e733a7c

20 files changed

+234
-223
lines changed

components/script/dom/bindings/callback.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ impl CallbackInterface {
122122
let obj = RootedObject::new(cx, self.callback());
123123
unsafe {
124124
let c_name = CString::new(name).unwrap();
125-
if JS_GetProperty(cx, obj.handle(), c_name.as_ptr(),
126-
callable.handle_mut()) == 0 {
125+
if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(),
126+
callable.handle_mut()) {
127127
return Err(Error::JSFailed);
128128
}
129129

130130
if !callable.ptr.is_object() ||
131-
IsCallable(callable.ptr.to_object()) == 0 {
131+
!IsCallable(callable.ptr.to_object()) {
132132
return Err(Error::Type(
133133
format!("The value of the {} property is not callable", name)));
134134
}
@@ -145,7 +145,7 @@ pub fn wrap_call_this_object<T: Reflectable>(cx: *mut JSContext,
145145
assert!(!rval.get().is_null());
146146

147147
unsafe {
148-
if JS_WrapObject(cx, rval) == 0 {
148+
if !JS_WrapObject(cx, rval) {
149149
rval.set(ptr::null_mut());
150150
}
151151
}
@@ -198,11 +198,11 @@ impl Drop for CallSetup {
198198
unsafe { JS_LeaveCompartment(self.cx, self.old_compartment); }
199199
let need_to_deal_with_exception =
200200
self.handling == ExceptionHandling::Report &&
201-
unsafe { JS_IsExceptionPending(self.cx) } != 0;
201+
unsafe { JS_IsExceptionPending(self.cx) };
202202
if need_to_deal_with_exception {
203203
unsafe {
204204
let old_global = RootedObject::new(self.cx, self.exception_compartment.ptr);
205-
let saved = JS_SaveFrameChain(self.cx) != 0;
205+
let saved = JS_SaveFrameChain(self.cx);
206206
{
207207
let _ac = JSAutoCompartment::new(self.cx, old_global.ptr);
208208
JS_ReportPendingException(self.cx);

components/script/dom/bindings/codegen/CodegenRust.py

Lines changed: 87 additions & 85 deletions
Large diffs are not rendered by default.

components/script/dom/bindings/conversions.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl ToJSValConvertible for () {
186186
impl ToJSValConvertible for JSVal {
187187
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
188188
rval.set(*self);
189-
if unsafe { JS_WrapValue(cx, rval) } == 0 {
189+
if unsafe { !JS_WrapValue(cx, rval) } {
190190
panic!("JS_WrapValue failed.");
191191
}
192192
}
@@ -195,7 +195,7 @@ impl ToJSValConvertible for JSVal {
195195
impl ToJSValConvertible for HandleValue {
196196
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
197197
rval.set(self.get());
198-
if unsafe { JS_WrapValue(cx, rval) } == 0 {
198+
if unsafe { !JS_WrapValue(cx, rval) } {
199199
panic!("JS_WrapValue failed.");
200200
}
201201
}
@@ -397,7 +397,7 @@ impl ToJSValConvertible for str {
397397
let mut string_utf16: Vec<u16> = Vec::with_capacity(self.len());
398398
unsafe {
399399
string_utf16.extend(self.utf16_units());
400-
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr() as *const i16,
400+
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(),
401401
string_utf16.len() as libc::size_t);
402402
if jsstr.is_null() {
403403
panic!("JS_NewUCStringCopyN failed");
@@ -426,7 +426,7 @@ pub enum StringificationBehavior {
426426
/// contain valid UTF-16.
427427
pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
428428
let mut length = 0;
429-
let latin1 = unsafe { JS_StringHasLatin1Chars(s) != 0 };
429+
let latin1 = unsafe { JS_StringHasLatin1Chars(s) };
430430
if latin1 {
431431
let chars = unsafe {
432432
JS_GetLatin1StringCharsAndLength(cx, ptr::null(), s, &mut length)
@@ -479,7 +479,7 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
479479
/// string, or if the string does not contain valid UTF-16.
480480
pub fn jsid_to_str(cx: *mut JSContext, id: HandleId) -> DOMString {
481481
unsafe {
482-
assert!(RUST_JSID_IS_STRING(id) != 0);
482+
assert!(RUST_JSID_IS_STRING(id));
483483
jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
484484
}
485485
}
@@ -519,7 +519,7 @@ impl FromJSValConvertible for USVString {
519519
debug!("ToString failed");
520520
return Err(());
521521
}
522-
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) != 0 };
522+
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) };
523523
if latin1 {
524524
return Ok(USVString(jsstring_to_str(cx, jsstr)));
525525
}
@@ -555,7 +555,7 @@ impl FromJSValConvertible for ByteString {
555555
return Err(());
556556
}
557557

558-
let latin1 = unsafe { JS_StringHasLatin1Chars(string) != 0 };
558+
let latin1 = unsafe { JS_StringHasLatin1Chars(string) };
559559
if latin1 {
560560
let mut length = 0;
561561
let chars = unsafe {
@@ -591,7 +591,7 @@ impl ToJSValConvertible for Reflector {
591591
let obj = self.get_jsobject().get();
592592
assert!(!obj.is_null());
593593
rval.set(ObjectValue(unsafe { &*obj }));
594-
if unsafe { JS_WrapValue(cx, rval) } == 0 {
594+
if unsafe { !JS_WrapValue(cx, rval) } {
595595
panic!("JS_WrapValue failed.");
596596
}
597597
}
@@ -670,14 +670,14 @@ pub unsafe fn private_from_proto_chain(mut obj: *mut JSObject,
670670
proto_id: u16, proto_depth: u16)
671671
-> Result<*const libc::c_void, ()> {
672672
let dom_class = try!(get_dom_class(obj).or_else(|_| {
673-
if IsWrapper(obj) == 1 {
673+
if IsWrapper(obj) {
674674
debug!("found wrapper");
675675
obj = UnwrapObject(obj, /* stopAtOuter = */ 0);
676676
if obj.is_null() {
677677
debug!("unwrapping security wrapper failed");
678678
Err(())
679679
} else {
680-
assert!(IsWrapper(obj) == 0);
680+
assert!(!IsWrapper(obj));
681681
debug!("unwrapped successfully");
682682
get_dom_class(obj)
683683
}
@@ -774,7 +774,7 @@ impl ToJSValConvertible for *mut JSObject {
774774
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
775775
rval.set(ObjectOrNullValue(*self));
776776
unsafe {
777-
assert!(JS_WrapValue(cx, rval) != 0);
777+
assert!(JS_WrapValue(cx, rval));
778778
}
779779
}
780780
}

components/script/dom/bindings/error.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use dom::bindings::global::GlobalRef;
1010
use dom::domexception::{DOMErrorName, DOMException};
1111
use js::jsapi::JSAutoCompartment;
1212
use js::jsapi::{JSContext, JSObject, RootedValue};
13-
use js::jsapi::{JSErrorFormatString, JSExnType, JS_ReportErrorNumber1};
13+
use js::jsapi::{JSErrorFormatString, JSExnType, JS_ReportErrorNumber};
1414
use js::jsapi::{JS_IsExceptionPending, JS_ReportPendingException, JS_SetPendingException};
1515
use js::jsapi::{JS_RestoreFrameChain, JS_SaveFrameChain};
1616
use js::jsval::UndefinedValue;
@@ -105,22 +105,22 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
105105
Error::QuotaExceeded => DOMErrorName::QuotaExceededError,
106106
Error::TypeMismatch => DOMErrorName::TypeMismatchError,
107107
Error::Type(message) => {
108-
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
108+
assert!(unsafe { !JS_IsExceptionPending(cx) });
109109
throw_type_error(cx, &message);
110110
return;
111111
},
112112
Error::Range(message) => {
113-
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
113+
assert!(unsafe { !JS_IsExceptionPending(cx) });
114114
throw_range_error(cx, &message);
115115
return;
116116
},
117117
Error::JSFailed => {
118-
assert!(unsafe { JS_IsExceptionPending(cx) } == 1);
118+
assert!(unsafe { JS_IsExceptionPending(cx) });
119119
return;
120120
}
121121
};
122122

123-
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
123+
assert!(unsafe { !JS_IsExceptionPending(cx) });
124124
let exception = DOMException::new(global, code);
125125
let mut thrown = RootedValue::new(cx, UndefinedValue());
126126
exception.to_jsval(cx, thrown.handle_mut());
@@ -132,13 +132,13 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
132132
/// Report a pending exception, thereby clearing it.
133133
pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) {
134134
unsafe {
135-
if JS_IsExceptionPending(cx) != 0 {
135+
if JS_IsExceptionPending(cx) {
136136
let saved = JS_SaveFrameChain(cx);
137137
{
138138
let _ac = JSAutoCompartment::new(cx, obj);
139139
JS_ReportPendingException(cx);
140140
}
141-
if saved != 0 {
141+
if saved {
142142
JS_RestoreFrameChain(cx);
143143
}
144144
}
@@ -148,15 +148,15 @@ pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) {
148148
/// Throw an exception to signal that a `JSVal` can not be converted to any of
149149
/// the types in an IDL union type.
150150
pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) {
151-
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
151+
assert!(unsafe { !JS_IsExceptionPending(cx) });
152152
let error = format!("argument could not be converted to any of: {}", names);
153153
throw_type_error(cx, &error);
154154
}
155155

156156
/// Throw an exception to signal that a `JSObject` can not be converted to a
157157
/// given DOM type.
158158
pub fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) {
159-
debug_assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
159+
debug_assert!(unsafe { !JS_IsExceptionPending(cx) });
160160
let error = format!("\"this\" object does not implement interface {}.",
161161
proto_id_to_name(proto_id));
162162
throw_type_error(cx, &error);
@@ -205,7 +205,7 @@ unsafe extern fn get_error_message(_user_ref: *mut libc::c_void,
205205
fn throw_js_error(cx: *mut JSContext, error: &str, error_number: u32) {
206206
let error = CString::new(error).unwrap();
207207
unsafe {
208-
JS_ReportErrorNumber1(cx,
208+
JS_ReportErrorNumber(cx,
209209
Some(get_error_message),
210210
ptr::null_mut(), error_number, error.as_ptr());
211211
}

components/script/dom/bindings/proxyhandler.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use js::jsapi::{JSErrNum, JS_StrictPropertyStub};
1818
use js::jsapi::{JS_DefinePropertyById6, JS_NewObjectWithGivenProto};
1919
use js::jsapi::{JS_GetPropertyDescriptorById};
2020
use js::jsval::ObjectValue;
21-
use js::{JSFalse, JSTrue};
2221
use js::{JSPROP_ENUMERATE, JSPROP_GETTER, JSPROP_READONLY};
2322
use libc;
2423
use std::{mem, ptr};
@@ -33,19 +32,19 @@ pub unsafe extern fn get_property_descriptor(cx: *mut JSContext,
3332
proxy: HandleObject,
3433
id: HandleId,
3534
desc: MutableHandle<JSPropertyDescriptor>)
36-
-> u8 {
35+
-> bool {
3736
let handler = GetProxyHandler(proxy.get());
38-
if InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) == 0 {
39-
return JSFalse;
37+
if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) {
38+
return false;
4039
}
4140
if !desc.get().obj.is_null() {
42-
return JSTrue;
41+
return true;
4342
}
4443

4544
let mut proto = RootedObject::new(cx, ptr::null_mut());
46-
if GetObjectProto(cx, proxy, proto.handle_mut()) == 0 {
45+
if !GetObjectProto(cx, proxy, proto.handle_mut()) {
4746
desc.get().obj = ptr::null_mut();
48-
return JSTrue;
47+
return true;
4948
}
5049

5150
JS_GetPropertyDescriptorById(cx, proto.handle(), id, desc)
@@ -55,13 +54,13 @@ pub unsafe extern fn get_property_descriptor(cx: *mut JSContext,
5554
pub unsafe extern fn define_property(cx: *mut JSContext, proxy: HandleObject,
5655
id: HandleId, desc: Handle<JSPropertyDescriptor>,
5756
result: *mut ObjectOpResult)
58-
-> u8 {
57+
-> bool {
5958
//FIXME: Workaround for https://github.com/mozilla/rust/issues/13385
6059
let setter: *const libc::c_void = mem::transmute(desc.get().setter);
6160
let setter_stub: *const libc::c_void = mem::transmute(JS_StrictPropertyStub);
6261
if (desc.get().attrs & JSPROP_GETTER) != 0 && setter == setter_stub {
63-
(*result).code_ = JSErrNum::JSMSG_GETTER_ONLY as u32;
64-
return JSTrue;
62+
(*result).code_ = JSErrNum::JSMSG_GETTER_ONLY as ::libc::uintptr_t;
63+
return true;
6564
}
6665

6766
let expando = RootedObject::new(cx, ensure_expando_object(cx, proxy));
@@ -70,11 +69,11 @@ pub unsafe extern fn define_property(cx: *mut JSContext, proxy: HandleObject,
7069

7170
/// Deletes an expando off the given `proxy`.
7271
pub unsafe extern fn delete(cx: *mut JSContext, proxy: HandleObject, id: HandleId,
73-
bp: *mut ObjectOpResult) -> u8 {
72+
bp: *mut ObjectOpResult) -> bool {
7473
let expando = RootedObject::new(cx, get_expando_object(proxy));
7574
if expando.ptr.is_null() {
7675
(*bp).code_ = 0 /* OkCode */;
77-
return JSTrue;
76+
return true;
7877
}
7978

8079
delete_property_by_id(cx, expando.handle(), id, bp)
@@ -83,16 +82,16 @@ pub unsafe extern fn delete(cx: *mut JSContext, proxy: HandleObject, id: HandleI
8382
/// Controls whether the Extensible bit can be changed
8483
pub unsafe extern fn prevent_extensions(_cx: *mut JSContext,
8584
_proxy: HandleObject,
86-
result: *mut ObjectOpResult) -> u8 {
87-
(*result).code_ = JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS as u32;
88-
JSTrue
85+
result: *mut ObjectOpResult) -> bool {
86+
(*result).code_ = JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS as ::libc::uintptr_t;
87+
true
8988
}
9089

9190
/// Reports whether the object is Extensible
9291
pub unsafe extern fn is_extensible(_cx: *mut JSContext, _proxy: HandleObject,
93-
succeeded: *mut u8) -> u8 {
94-
*succeeded = JSTrue;
95-
JSTrue
92+
succeeded: *mut bool) -> bool {
93+
*succeeded = true;
94+
true
9695
}
9796

9897
/// Get the expando object, or null if there is none.

components/script/dom/bindings/structuredclone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl StructuredCloneData {
3131
ptr::null(), ptr::null_mut(),
3232
HandleValue::undefined())
3333
};
34-
if result == 0 {
34+
if !result {
3535
unsafe { JS_ClearPendingException(cx); }
3636
return Err(Error::DataClone);
3737
}
@@ -49,7 +49,7 @@ impl StructuredCloneData {
4949
assert!(JS_ReadStructuredClone(
5050
global.get_cx(), self.data, self.nbytes,
5151
JS_STRUCTURED_CLONE_VERSION, rval,
52-
ptr::null(), ptr::null_mut()) != 0);
52+
ptr::null(), ptr::null_mut()));
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)