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 all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -8,9 +8,14 @@ env:
- FEATURES=""
- FEATURES="debugmozjs"

before_script:
- export PATH=$HOME/.local/bin:/Users/travis/Library/Python/2.7/bin:$PATH
- pip install servo_tidy --user `whoami`

script:
- cargo build --verbose --features "$FEATURES"
- cargo test --verbose --features "$FEATURES"
- servo-tidy

branches:
except:
15 gen.py
@@ -2,29 +2,30 @@
# 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/.

import argparse, subprocess;
import subprocess

bindgen = "bindgen";
bindgen = "bindgen"

jsapi = "../mozjs/js/src/jsapi.h"
includes = [
"-I", "../mozjs/js/src/dist/include",
]
]
sysincludes = [
"-isystem", "/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5/include",
"-isystem", "/usr/lib/gcc/x86_64-redhat-linux/4.7.0/include",
]
]

args = [
bindgen,
"-l", "mozjs",
"-o", "jsapi.rs",
"-match" ,"js",
jsapi]
"-match", "js",
jsapi
]
args += includes + sysincludes

subprocess.call(args)

# To generate jsglue:
# DYLD_LIBRARY_PATH=~/versioned/rust-mozilla/build/llvm/x86_64-apple-darwin/Release+Asserts/lib/ ~/versioned/rust-bindgen/bindgen ./jsglue.c -I ../../build/src/mozjs/dist/include/ -match glue > glue.rs

@@ -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`.
//!
@@ -31,16 +31,16 @@ use JSPROP_ENUMERATE;
use error::throw_type_error;
use glue::RUST_JS_NumberValue;
use jsapi::{JSContext, JSObject, JSString, HandleValue, MutableHandleValue};
use jsapi::{JS_NewUCStringCopyN, JS_StringHasLatin1Chars, JS_WrapValue};
use jsapi::{JS_GetArrayLength, JS_GetElement};
use jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetTwoByteStringCharsAndLength};
use jsapi::{JS_NewArrayObject1, JS_DefineElement, RootedValue, RootedObject};
use jsapi::{JS_GetArrayLength, JS_GetElement};
use jsapi::{JS_NewUCStringCopyN, JS_StringHasLatin1Chars, JS_WrapValue};
use jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
use jsval::{JSVal, ObjectValue, ObjectOrNullValue, StringValue};
use rust::{ToBoolean, ToNumber, ToUint16, ToInt32, ToUint32, ToInt64, ToUint64, ToString};
use libc;
use num::Float;
use num::traits::{Bounded, Zero};
use rust::{ToBoolean, ToNumber, ToUint16, ToInt32, ToUint32, ToInt64, ToUint64, ToString};
use std::rc::Rc;
use std::{ptr, slice};

@@ -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)
}
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.