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

Some handle improvements. #275

Merged
merged 2 commits into from Jun 28, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -311,13 +311,13 @@ impl<'a, T> RootedGuard<'a, T> {
}
}

pub fn handle(&self) -> Handle<T> where T: Copy {
pub fn handle(&self) -> Handle<T> {
unsafe {
Handle::from_marked_location(&self.root.ptr)
}
}

pub fn handle_mut(&mut self) -> MutableHandle<T> where T: Copy {
pub fn handle_mut(&mut self) -> MutableHandle<T> {
unsafe {
MutableHandle::from_marked_location(&mut self.root.ptr)
}
@@ -365,8 +365,10 @@ macro_rules! rooted {
}
}

impl<T: Copy> Handle<T> {
pub fn get(&self) -> T {
impl<T> Handle<T> {
pub fn get(&self) -> T
where T: Copy
{
unsafe { *self.ptr }
}

@@ -378,38 +380,50 @@ impl<T: Copy> Handle<T> {
}
}

impl<T: Copy> Deref for Handle<T> {
impl<T> Deref for Handle<T> {
type Target = T;

fn deref<'a>(&'a self) -> &'a T {
unsafe { &*self.ptr }
}
}

impl<T: Copy> MutableHandle<T> {
impl<T> MutableHandle<T> {
pub unsafe fn from_marked_location(ptr: *mut T) -> MutableHandle<T> {
MutableHandle {
_base: MutableHandleBase { _phantom0: PhantomData },
ptr: ptr,
}
}

pub fn to_handle(&self) -> Handle<T> {
pub fn handle(&self) -> Handle<T> {
unsafe {
Handle::from_marked_location(self.ptr as *const _)
}
}

pub fn get(&self) -> T
where T: Copy
{
unsafe { *self.ptr }
}

pub fn set(&self, v: T)
where T: Copy
{
unsafe { *self.ptr = v }
}
}

impl<T: Copy> Deref for MutableHandle<T> {
impl<T> Deref for MutableHandle<T> {
type Target = T;

fn deref<'a>(&'a self) -> &'a T {
unsafe { &*self.ptr }
}
}

impl<T: Copy> DerefMut for MutableHandle<T> {
impl<T> DerefMut for MutableHandle<T> {
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
unsafe { &mut *self.ptr }
}
@@ -435,22 +449,6 @@ impl HandleObject {
}
}

impl<T: Copy> MutableHandle<T> {
pub fn get(&self) -> T {
unsafe { *self.ptr }
}

pub fn set(&self, v: T) {
unsafe { *self.ptr = v }
}

pub fn handle(&self) -> Handle<T> {
unsafe {
Handle::from_marked_location(&*self.ptr)
}
}
}

impl Default for jsid {
fn default() -> jsid { JSID_VOID }
}
@@ -679,7 +677,7 @@ impl JSJitGetterCallArgs {
impl JSJitSetterCallArgs {
pub fn get(&self, i: u32) -> HandleValue {
assert!(i == 0);
self._base.to_handle()
self._base.handle()
}
}

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