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

Initial implementation for sequence arguments #229

Merged
merged 2 commits into from Dec 30, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Add test for Vec conversion

  • Loading branch information
emilio committed Dec 30, 2015
commit 06327e37b1bc6b7905677e395be13b4e997f3bbf
@@ -63,6 +63,9 @@ pub mod glue;
pub mod jsval;
pub mod rust;

#[cfg(test)]
mod tests;

pub use consts::*;

use heapsize::HeapSizeOf;
@@ -0,0 +1,61 @@

use consts::{JSCLASS_RESERVED_SLOTS_MASK,JSCLASS_RESERVED_SLOTS_SHIFT,JSCLASS_GLOBAL_SLOT_COUNT,JSCLASS_IS_GLOBAL};
use jsapi::JS_GlobalObjectTraceHook;
use conversions::*;
use jsval::*;
use rust::*;
use jsapi::{CallArgs,CompartmentOptions,OnNewGlobalHookOption,Rooted,Value, JS_NewGlobalObject};
use jsapi::{RootedValue, RootedObject, JSAutoRequest, JSAutoCompartment, JS_Init, JSClass};
use std::ptr;

static CLASS: &'static JSClass = &JSClass {
name: b"test\0" as *const u8 as *const _,
flags: JSCLASS_IS_GLOBAL | ((JSCLASS_GLOBAL_SLOT_COUNT & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT),
addProperty: None,
delProperty: None,
getProperty: None,
setProperty: None,
enumerate: None,
resolve: None,
convert: None,
finalize: None,
call: None,
hasInstance: None,
construct: None,
trace: Some(JS_GlobalObjectTraceHook),
reserved: [0 as *mut _; 25]
};


#[test]
fn test_vec_conversion() {
unsafe{
assert!(JS_Init());
}

let rt = Runtime::new();
let cx = rt.cx();

let glob = RootedObject::new(cx, 0 as *mut _);
let _ar = JSAutoRequest::new(cx);

let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
let c_option = CompartmentOptions::default();
let global = unsafe {
JS_NewGlobalObject(cx, CLASS, ptr::null_mut(), h_option, &c_option)
};
let global_root = Rooted::new(cx, global);
let global = global_root.handle();

let _ac = JSAutoCompartment::new(cx, global.get());

let orig_vec: Vec<f32> = vec![1.0, 2.9, 3.0];
let mut rval = RootedValue::new(cx, UndefinedValue());

let converted = unsafe {
orig_vec.to_jsval(cx, rval.handle_mut());
Vec::<f32>::from_jsval(cx, rval.handle(), ()).unwrap()
};

assert_eq!(orig_vec, converted);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.