Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start tidying #255

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

run rustfmt

  • Loading branch information
edunham committed Apr 19, 2016
commit ee9dafa8c811e80a7d0c46f6a95bf5da45fbe4b6
@@ -1,6 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use jsapi::JSProtoKey;
use libc::c_uint;
@@ -18,38 +18,39 @@ pub const JSID_TYPE_MASK: i64 = 7;
pub const JSFUN_CONSTRUCTOR: u32 = 0x400; /* native that can be called as a ctor */

pub const JSPROP_ENUMERATE: c_uint = 0x01;
pub const JSPROP_READONLY: c_uint = 0x02;
pub const JSPROP_READONLY: c_uint = 0x02;
pub const JSPROP_PERMANENT: c_uint = 0x04;
pub const JSPROP_GETTER: c_uint = 0x10;
pub const JSPROP_SETTER: c_uint = 0x20;
pub const JSPROP_SHARED: c_uint = 0x40;
pub const JSPROP_SHARED: c_uint = 0x40;
pub const JSPROP_NATIVE_ACCESSORS: c_uint = 0x08;

pub const JSCLASS_RESERVED_SLOTS_SHIFT: c_uint = 8;
pub const JSCLASS_RESERVED_SLOTS_WIDTH: c_uint = 8;
pub const JSCLASS_RESERVED_SLOTS_MASK: c_uint = ((1 << JSCLASS_RESERVED_SLOTS_WIDTH) - 1) as c_uint;

pub const JSCLASS_HIGH_FLAGS_SHIFT: c_uint =
JSCLASS_RESERVED_SLOTS_SHIFT + JSCLASS_RESERVED_SLOTS_WIDTH;
pub const JSCLASS_HIGH_FLAGS_SHIFT: c_uint = JSCLASS_RESERVED_SLOTS_SHIFT +
JSCLASS_RESERVED_SLOTS_WIDTH;
pub const JSCLASS_IS_GLOBAL: c_uint = 1 << (JSCLASS_HIGH_FLAGS_SHIFT + 1);
pub const JSCLASS_GLOBAL_APPLICATION_SLOTS: c_uint = 4;
pub const JSCLASS_GLOBAL_SLOT_COUNT: c_uint = JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProtoKey::JSProto_LIMIT as u32 * 3 + 31;
pub const JSCLASS_GLOBAL_SLOT_COUNT: c_uint = JSCLASS_GLOBAL_APPLICATION_SLOTS +
JSProtoKey::JSProto_LIMIT as u32 * 3 +
31;

pub const JSCLASS_IS_DOMJSCLASS: u32 = 1 << 4;
pub const JSCLASS_IMPLEMENTS_BARRIERS: u32 = 1 << 5;
pub const JSCLASS_USERBIT1: u32 = 1 << 7;

pub const JSCLASS_IS_PROXY: u32 = 1 << (JSCLASS_HIGH_FLAGS_SHIFT+4);
pub const JSCLASS_IS_PROXY: u32 = 1 << (JSCLASS_HIGH_FLAGS_SHIFT + 4);

pub const JSSLOT_PROXY_PRIVATE: u32 = 1;

pub const JS_DEFAULT_ZEAL_FREQ: u32 = 100;

pub const JSITER_ENUMERATE: c_uint = 0x1;
pub const JSITER_FOREACH: c_uint = 0x2;
pub const JSITER_KEYVALUE: c_uint = 0x4;
pub const JSITER_OWNONLY: c_uint = 0x8;
pub const JSITER_HIDDEN: c_uint = 0x10;
pub const JSITER_SYMBOLS: c_uint = 0x20;
pub const JSITER_ENUMERATE: c_uint = 0x1;
pub const JSITER_FOREACH: c_uint = 0x2;
pub const JSITER_KEYVALUE: c_uint = 0x4;
pub const JSITER_OWNONLY: c_uint = 0x8;
pub const JSITER_HIDDEN: c_uint = 0x10;
pub const JSITER_SYMBOLS: c_uint = 0x20;
pub const JSITER_SYMBOLSONLY: c_uint = 0x40;

@@ -1,6 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//! Conversions of Rust values to and from `JSVal`.
//!
@@ -180,9 +180,11 @@ impl ToJSValConvertible for HandleValue {
}

#[inline]
unsafe fn convert_int_from_jsval<T, M>(cx: *mut JSContext, value: HandleValue,
unsafe fn convert_int_from_jsval<T, M>(cx: *mut JSContext,
value: HandleValue,
option: ConversionBehavior,
convert_fn: unsafe fn(*mut JSContext, HandleValue) -> Result<M, ()>)
convert_fn: unsafe fn(*mut JSContext, HandleValue)
-> Result<M, ()>)
-> Result<T, ()>
where T: Bounded + Zero + As<f64>,
M: Zero + As<T>,
@@ -481,26 +483,28 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Vec<T> {
for (index, obj) in self.iter().enumerate() {
obj.to_jsval(cx, val.handle_mut());

assert!(JS_DefineElement(cx, js_array.handle(),
index as u32, val.handle(), JSPROP_ENUMERATE, None, None));
assert!(JS_DefineElement(cx,
js_array.handle(),
index as u32,
val.handle(),
JSPROP_ENUMERATE,
None,
None));
}

rval.set(ObjectValue(&*js_array.handle().get()));
}
}

impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T> {
impl<C: Clone, T: FromJSValConvertible<Config = C>> FromJSValConvertible for Vec<T> {
type Config = C;

unsafe fn from_jsval(cx: *mut JSContext,
value: HandleValue,
option: C)
-> Result<Vec<T>, ()> {
unsafe fn from_jsval(cx: *mut JSContext, value: HandleValue, option: C) -> Result<Vec<T>, ()> {
let mut length = 0;

if !value.is_object() {
throw_type_error(cx, "Non objects cannot be converted to sequence");
return Err(())
return Err(());
}

let obj = RootedObject::new(cx, value.to_object());
@@ -1,6 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//! Functions to throw JavaScript exceptions from Rust.

@@ -12,12 +12,10 @@ use std::ffi::CString;
use std::{mem, ptr};

/// Format string used to throw javascript errors.
static ERROR_FORMAT_STRING_STRING: [libc::c_char; 4] = [
'{' as libc::c_char,
'0' as libc::c_char,
'}' as libc::c_char,
0 as libc::c_char,
];
static ERROR_FORMAT_STRING_STRING: [libc::c_char; 4] = ['{' as libc::c_char,
'0' as libc::c_char,
'}' as libc::c_char,
0 as libc::c_char];

/// Format string struct used to throw `TypeError`s.
static mut TYPE_ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString {
@@ -42,8 +40,10 @@ unsafe extern "C" fn get_error_message(_user_ref: *mut libc::c_void,
match num {
JSExnType::JSEXN_TYPEERR => &TYPE_ERROR_FORMAT_STRING as *const JSErrorFormatString,
JSExnType::JSEXN_RANGEERR => &RANGE_ERROR_FORMAT_STRING as *const JSErrorFormatString,
_ => panic!("Bad js error number given to get_error_message: {}",
error_number),
_ => {
panic!("Bad js error number given to get_error_message: {}",
error_number)
}
}
}

@@ -3,8 +3,8 @@ use jsapi::*;
pub const JS_STRUCTURED_CLONE_VERSION: u32 = 5;

pub enum Action { }
unsafe impl Sync for ProxyTraps { }
/* automatically generated by rust-bindgen */
unsafe impl Sync for ProxyTraps {}
// automatically generated by rust-bindgen

#[repr(C)]
#[derive(Copy, Clone)]
@@ -147,15 +147,19 @@ pub struct ProxyTraps {
(obj: *mut JSObject) -> bool>,
}
impl ::std::default::Default for ProxyTraps {
fn default() -> ProxyTraps { unsafe { ::std::mem::zeroed() } }
fn default() -> ProxyTraps {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct WrapperProxyHandler {
pub mTraps: ProxyTraps,
}
impl ::std::default::Default for WrapperProxyHandler {
fn default() -> WrapperProxyHandler { unsafe { ::std::mem::zeroed() } }
fn default() -> WrapperProxyHandler {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Copy, Clone)]
@@ -164,53 +168,74 @@ pub struct ForwardingProxyHandler {
pub mExtra: *const ::libc::c_void,
}
impl ::std::default::Default for ForwardingProxyHandler {
fn default() -> ForwardingProxyHandler { unsafe { ::std::mem::zeroed() } }
fn default() -> ForwardingProxyHandler {
unsafe { ::std::mem::zeroed() }
}
}
extern "C" {
pub fn InvokeGetOwnPropertyDescriptor(handler: *const ::libc::c_void,
cx: *mut JSContext,
proxy: HandleObject, id: HandleId,
desc:
MutableHandle<JSPropertyDescriptor>)
-> bool;
proxy: HandleObject,
id: HandleId,
desc: MutableHandle<JSPropertyDescriptor>)
-> bool;
pub fn InvokeHasOwn(handler: *const ::libc::c_void,
cx: *mut JSContext, proxy: HandleObject,
id: HandleId, bp: *mut bool) -> bool;
cx: *mut JSContext,
proxy: HandleObject,
id: HandleId,
bp: *mut bool)
-> bool;
pub fn RUST_JS_NumberValue(d: f64) -> Value;
pub fn RUST_FUNCTION_VALUE_TO_JITINFO(v: Value) -> *const JSJitInfo;
pub fn CallJitGetterOp(info: *const JSJitInfo, cx: *mut JSContext,
pub fn CallJitGetterOp(info: *const JSJitInfo,
cx: *mut JSContext,
thisObj: HandleObject,
specializedThis: *mut ::libc::c_void, argc: u32,
vp: *mut Value) -> bool;
pub fn CallJitSetterOp(info: *const JSJitInfo, cx: *mut JSContext,
specializedThis: *mut ::libc::c_void,
argc: u32,
vp: *mut Value)
-> bool;
pub fn CallJitSetterOp(info: *const JSJitInfo,
cx: *mut JSContext,
thisObj: HandleObject,
specializedThis: *mut ::libc::c_void, argc: u32,
vp: *mut Value) -> bool;
pub fn CallJitMethodOp(info: *const JSJitInfo, cx: *mut JSContext,
specializedThis: *mut ::libc::c_void,
argc: u32,
vp: *mut Value)
-> bool;
pub fn CallJitMethodOp(info: *const JSJitInfo,
cx: *mut JSContext,
thisObj: HandleObject,
specializedThis: *mut ::libc::c_void, argc: u32,
vp: *mut Value) -> bool;
specializedThis: *mut ::libc::c_void,
argc: u32,
vp: *mut Value)
-> bool;
pub fn CreateProxyHandler(aTraps: *const ProxyTraps,
aExtra: *const ::libc::c_void)
-> *const ::libc::c_void;
pub fn CreateWrapperProxyHandler(aTraps: *const ProxyTraps)
-> *const ::libc::c_void;
-> *const ::libc::c_void;
pub fn CreateWrapperProxyHandler(aTraps: *const ProxyTraps) -> *const ::libc::c_void;
pub fn GetCrossCompartmentWrapper() -> *const ::libc::c_void;
pub fn NewCompileOptions(aCx: *mut JSContext, aFile: *const ::libc::c_char,
aLine: u32) -> *mut ReadOnlyCompileOptions;
pub fn NewCompileOptions(aCx: *mut JSContext,
aFile: *const ::libc::c_char,
aLine: u32)
-> *mut ReadOnlyCompileOptions;
pub fn DeleteCompileOptions(aOpts: *mut ReadOnlyCompileOptions);
pub fn NewProxyObject(aCx: *mut JSContext,
aHandler: *const ::libc::c_void, aPriv: HandleValue,
proto: *mut JSObject, parent: *mut JSObject,
call: *mut JSObject, construct: *mut JSObject)
-> *mut JSObject;
pub fn WrapperNew(aCx: *mut JSContext, aObj: HandleObject,
aHandler: *const ::libc::c_void, aClass: *const JSClass,
aHandler: *const ::libc::c_void,
aPriv: HandleValue,
proto: *mut JSObject,
parent: *mut JSObject,
call: *mut JSObject,
construct: *mut JSObject)
-> *mut JSObject;
pub fn WrapperNew(aCx: *mut JSContext,
aObj: HandleObject,
aHandler: *const ::libc::c_void,
aClass: *const JSClass,
aSingleton: bool)
-> *mut JSObject;
pub fn NewWindowProxy(aCx: *mut JSContext, aObj: HandleObject,
-> *mut JSObject;
pub fn NewWindowProxy(aCx: *mut JSContext,
aObj: HandleObject,
aHandler: *const ::libc::c_void)
-> *mut JSObject;
-> *mut JSObject;
pub fn GetProxyExtra(obj: *mut JSObject, slot: u32) -> Value;
pub fn GetProxyPrivate(obj: *mut JSObject) -> Value;
pub fn SetProxyExtra(obj: *mut JSObject, slot: u32, val: Value);
@@ -220,11 +245,10 @@ extern "C" {
pub fn RUST_JSID_IS_STRING(id: HandleId) -> bool;
pub fn RUST_JSID_TO_STRING(id: HandleId) -> *mut JSString;
pub fn RUST_SET_JITINFO(func: *mut JSFunction, info: *const JSJitInfo);
pub fn RUST_INTERNED_STRING_TO_JSID(cx: *mut JSContext,
str: *mut JSString) -> jsid;
pub fn RUST_INTERNED_STRING_TO_JSID(cx: *mut JSContext, str: *mut JSString) -> jsid;
pub fn RUST_js_GetErrorMessage(userRef: *mut ::libc::c_void,
errorNumber: u32)
-> *const JSErrorFormatString;
-> *const JSErrorFormatString;
pub fn IsProxyHandlerFamily(obj: *mut JSObject) -> u8;
pub fn GetProxyHandlerExtra(obj: *mut JSObject) -> *const ::libc::c_void;
pub fn GetProxyHandler(obj: *mut JSObject) -> *const ::libc::c_void;
@@ -233,10 +257,8 @@ extern "C" {
pub fn UnwrapObject(obj: *mut JSObject, stopAtOuter: u8) -> *mut JSObject;
pub fn UncheckedUnwrapObject(obj: *mut JSObject, stopAtOuter: u8) -> *mut JSObject;
pub fn AppendToAutoIdVector(v: *mut AutoIdVector, id: jsid) -> bool;
pub fn CreateAutoObjectVector(aCx: *mut JSContext)
-> *mut AutoObjectVector;
pub fn AppendToAutoObjectVector(v: *mut AutoObjectVector,
obj: *mut JSObject) -> bool;
pub fn CreateAutoObjectVector(aCx: *mut JSContext) -> *mut AutoObjectVector;
pub fn AppendToAutoObjectVector(v: *mut AutoObjectVector, obj: *mut JSObject) -> bool;
pub fn DeleteAutoObjectVector(v: *mut AutoObjectVector);
pub fn CollectServoSizes(rt: *mut JSRuntime, sizes: *mut ServoSizes) -> bool;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.