Skip to content

Commit

Permalink
servo: Merge #7727 - Support the updated spidermonkey bindings (from …
Browse files Browse the repository at this point in the history
…michaelwu:update-bindings); r=jdm

Still need to finish the rust-mozjs update and make cargo use it, but it's close enough that I don't expect much to change on the servo side.

Some changes here
- bools are properly translated now
- char16_t is handled as u16 now
- JS_GlobalObjectTraceHook isn't mangled now
- JSJitInfo has been adjusted
- A const fn is used to generate bitfields in JSJitInfo
- Manually generating handles now requires calling an unsafe function. It's not actually required, but it's too much of a hassle to generate them manually now due to bindgen++ adding base classes now.

Source-Repo: https://github.com/servo/servo
Source-Revision: b34fd5bd7e55be1d577df5cf70b41af8a6cc716b
  • Loading branch information
michaelwu committed Oct 14, 2015
1 parent fe0f123 commit e4dfd5f
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 224 deletions.
12 changes: 6 additions & 6 deletions servo/components/script/dom/bindings/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ impl CallbackInterface {
let obj = RootedObject::new(cx, self.callback());
unsafe {
let c_name = CString::new(name).unwrap();
if JS_GetProperty(cx, obj.handle(), c_name.as_ptr(),
callable.handle_mut()) == 0 {
if !JS_GetProperty(cx, obj.handle(), c_name.as_ptr(),
callable.handle_mut()) {
return Err(Error::JSFailed);
}

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

unsafe {
if JS_WrapObject(cx, rval) == 0 {
if !JS_WrapObject(cx, rval) {
rval.set(ptr::null_mut());
}
}
Expand Down Expand Up @@ -198,11 +198,11 @@ impl Drop for CallSetup {
unsafe { JS_LeaveCompartment(self.cx, self.old_compartment); }
let need_to_deal_with_exception =
self.handling == ExceptionHandling::Report &&
unsafe { JS_IsExceptionPending(self.cx) } != 0;
unsafe { JS_IsExceptionPending(self.cx) };
if need_to_deal_with_exception {
unsafe {
let old_global = RootedObject::new(self.cx, self.exception_compartment.ptr);
let saved = JS_SaveFrameChain(self.cx) != 0;
let saved = JS_SaveFrameChain(self.cx);
{
let _ac = JSAutoCompartment::new(self.cx, old_global.ptr);
JS_ReportPendingException(self.cx);
Expand Down
172 changes: 87 additions & 85 deletions servo/components/script/dom/bindings/codegen/CodegenRust.py

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions servo/components/script/dom/bindings/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl ToJSValConvertible for () {
impl ToJSValConvertible for JSVal {
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
rval.set(*self);
if unsafe { JS_WrapValue(cx, rval) } == 0 {
if unsafe { !JS_WrapValue(cx, rval) } {
panic!("JS_WrapValue failed.");
}
}
Expand All @@ -195,7 +195,7 @@ impl ToJSValConvertible for JSVal {
impl ToJSValConvertible for HandleValue {
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
rval.set(self.get());
if unsafe { JS_WrapValue(cx, rval) } == 0 {
if unsafe { !JS_WrapValue(cx, rval) } {
panic!("JS_WrapValue failed.");
}
}
Expand Down Expand Up @@ -397,7 +397,7 @@ impl ToJSValConvertible for str {
let mut string_utf16: Vec<u16> = Vec::with_capacity(self.len());
unsafe {
string_utf16.extend(self.utf16_units());
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr() as *const i16,
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(),
string_utf16.len() as libc::size_t);
if jsstr.is_null() {
panic!("JS_NewUCStringCopyN failed");
Expand Down Expand Up @@ -426,7 +426,7 @@ pub enum StringificationBehavior {
/// contain valid UTF-16.
pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
let mut length = 0;
let latin1 = unsafe { JS_StringHasLatin1Chars(s) != 0 };
let latin1 = unsafe { JS_StringHasLatin1Chars(s) };
if latin1 {
let chars = unsafe {
JS_GetLatin1StringCharsAndLength(cx, ptr::null(), s, &mut length)
Expand Down Expand Up @@ -479,7 +479,7 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
/// string, or if the string does not contain valid UTF-16.
pub fn jsid_to_str(cx: *mut JSContext, id: HandleId) -> DOMString {
unsafe {
assert!(RUST_JSID_IS_STRING(id) != 0);
assert!(RUST_JSID_IS_STRING(id));
jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
}
}
Expand Down Expand Up @@ -519,7 +519,7 @@ impl FromJSValConvertible for USVString {
debug!("ToString failed");
return Err(());
}
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) != 0 };
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) };
if latin1 {
return Ok(USVString(jsstring_to_str(cx, jsstr)));
}
Expand Down Expand Up @@ -555,7 +555,7 @@ impl FromJSValConvertible for ByteString {
return Err(());
}

let latin1 = unsafe { JS_StringHasLatin1Chars(string) != 0 };
let latin1 = unsafe { JS_StringHasLatin1Chars(string) };
if latin1 {
let mut length = 0;
let chars = unsafe {
Expand All @@ -577,7 +577,7 @@ impl FromJSValConvertible for ByteString {
let char_vec = slice::from_raw_parts(chars, length as usize);

if char_vec.iter().any(|&c| c > 0xFF) {
// XXX Throw
throw_type_error(cx, "Invalid ByteString");
Err(())
} else {
Ok(ByteString::new(char_vec.iter().map(|&c| c as u8).collect()))
Expand All @@ -591,7 +591,7 @@ impl ToJSValConvertible for Reflector {
let obj = self.get_jsobject().get();
assert!(!obj.is_null());
rval.set(ObjectValue(unsafe { &*obj }));
if unsafe { JS_WrapValue(cx, rval) } == 0 {
if unsafe { !JS_WrapValue(cx, rval) } {
panic!("JS_WrapValue failed.");
}
}
Expand Down Expand Up @@ -670,14 +670,14 @@ pub unsafe fn private_from_proto_chain(mut obj: *mut JSObject,
proto_id: u16, proto_depth: u16)
-> Result<*const libc::c_void, ()> {
let dom_class = try!(get_dom_class(obj).or_else(|_| {
if IsWrapper(obj) == 1 {
if IsWrapper(obj) {
debug!("found wrapper");
obj = UnwrapObject(obj, /* stopAtOuter = */ 0);
if obj.is_null() {
debug!("unwrapping security wrapper failed");
Err(())
} else {
assert!(IsWrapper(obj) == 0);
assert!(!IsWrapper(obj));
debug!("unwrapped successfully");
get_dom_class(obj)
}
Expand Down Expand Up @@ -774,7 +774,7 @@ impl ToJSValConvertible for *mut JSObject {
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
rval.set(ObjectOrNullValue(*self));
unsafe {
assert!(JS_WrapValue(cx, rval) != 0);
assert!(JS_WrapValue(cx, rval));
}
}
}
20 changes: 10 additions & 10 deletions servo/components/script/dom/bindings/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dom::bindings::global::GlobalRef;
use dom::domexception::{DOMErrorName, DOMException};
use js::jsapi::JSAutoCompartment;
use js::jsapi::{JSContext, JSObject, RootedValue};
use js::jsapi::{JSErrorFormatString, JSExnType, JS_ReportErrorNumber1};
use js::jsapi::{JSErrorFormatString, JSExnType, JS_ReportErrorNumber};
use js::jsapi::{JS_IsExceptionPending, JS_ReportPendingException, JS_SetPendingException};
use js::jsapi::{JS_RestoreFrameChain, JS_SaveFrameChain};
use js::jsval::UndefinedValue;
Expand Down Expand Up @@ -105,22 +105,22 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
Error::QuotaExceeded => DOMErrorName::QuotaExceededError,
Error::TypeMismatch => DOMErrorName::TypeMismatchError,
Error::Type(message) => {
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
assert!(unsafe { !JS_IsExceptionPending(cx) });
throw_type_error(cx, &message);
return;
},
Error::Range(message) => {
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
assert!(unsafe { !JS_IsExceptionPending(cx) });
throw_range_error(cx, &message);
return;
},
Error::JSFailed => {
assert!(unsafe { JS_IsExceptionPending(cx) } == 1);
assert!(unsafe { JS_IsExceptionPending(cx) });
return;
}
};

assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
assert!(unsafe { !JS_IsExceptionPending(cx) });
let exception = DOMException::new(global, code);
let mut thrown = RootedValue::new(cx, UndefinedValue());
exception.to_jsval(cx, thrown.handle_mut());
Expand All @@ -132,13 +132,13 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
/// Report a pending exception, thereby clearing it.
pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) {
unsafe {
if JS_IsExceptionPending(cx) != 0 {
if JS_IsExceptionPending(cx) {
let saved = JS_SaveFrameChain(cx);
{
let _ac = JSAutoCompartment::new(cx, obj);
JS_ReportPendingException(cx);
}
if saved != 0 {
if saved {
JS_RestoreFrameChain(cx);
}
}
Expand All @@ -148,15 +148,15 @@ pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) {
/// Throw an exception to signal that a `JSVal` can not be converted to any of
/// the types in an IDL union type.
pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) {
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
assert!(unsafe { !JS_IsExceptionPending(cx) });
let error = format!("argument could not be converted to any of: {}", names);
throw_type_error(cx, &error);
}

/// Throw an exception to signal that a `JSObject` can not be converted to a
/// given DOM type.
pub fn throw_invalid_this(cx: *mut JSContext, proto_id: u16) {
debug_assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
debug_assert!(unsafe { !JS_IsExceptionPending(cx) });
let error = format!("\"this\" object does not implement interface {}.",
proto_id_to_name(proto_id));
throw_type_error(cx, &error);
Expand Down Expand Up @@ -205,7 +205,7 @@ unsafe extern fn get_error_message(_user_ref: *mut libc::c_void,
fn throw_js_error(cx: *mut JSContext, error: &str, error_number: u32) {
let error = CString::new(error).unwrap();
unsafe {
JS_ReportErrorNumber1(cx,
JS_ReportErrorNumber(cx,
Some(get_error_message),
ptr::null_mut(), error_number, error.as_ptr());
}
Expand Down
35 changes: 17 additions & 18 deletions servo/components/script/dom/bindings/proxyhandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use js::jsapi::{JSErrNum, JS_StrictPropertyStub};
use js::jsapi::{JS_DefinePropertyById6, JS_NewObjectWithGivenProto};
use js::jsapi::{JS_GetPropertyDescriptorById};
use js::jsval::ObjectValue;
use js::{JSFalse, JSTrue};
use js::{JSPROP_ENUMERATE, JSPROP_GETTER, JSPROP_READONLY};
use libc;
use std::{mem, ptr};
Expand All @@ -33,19 +32,19 @@ pub unsafe extern fn get_property_descriptor(cx: *mut JSContext,
proxy: HandleObject,
id: HandleId,
desc: MutableHandle<JSPropertyDescriptor>)
-> u8 {
-> bool {
let handler = GetProxyHandler(proxy.get());
if InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) == 0 {
return JSFalse;
if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) {
return false;
}
if !desc.get().obj.is_null() {
return JSTrue;
return true;
}

let mut proto = RootedObject::new(cx, ptr::null_mut());
if GetObjectProto(cx, proxy, proto.handle_mut()) == 0 {
if !GetObjectProto(cx, proxy, proto.handle_mut()) {
desc.get().obj = ptr::null_mut();
return JSTrue;
return true;
}

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

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

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

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

/// Reports whether the object is Extensible
pub unsafe extern fn is_extensible(_cx: *mut JSContext, _proxy: HandleObject,
succeeded: *mut u8) -> u8 {
*succeeded = JSTrue;
JSTrue
succeeded: *mut bool) -> bool {
*succeeded = true;
true
}

/// Get the expando object, or null if there is none.
Expand Down
4 changes: 2 additions & 2 deletions servo/components/script/dom/bindings/structuredclone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl StructuredCloneData {
ptr::null(), ptr::null_mut(),
HandleValue::undefined())
};
if result == 0 {
if !result {
unsafe { JS_ClearPendingException(cx); }
return Err(Error::DataClone);
}
Expand All @@ -49,7 +49,7 @@ impl StructuredCloneData {
assert!(JS_ReadStructuredClone(
global.get_cx(), self.data, self.nbytes,
JS_STRUCTURED_CLONE_VERSION, rval,
ptr::null(), ptr::null_mut()) != 0);
ptr::null(), ptr::null_mut()));
}
}
}
Expand Down
Loading

0 comments on commit e4dfd5f

Please sign in to comment.