Skip to content

Commit

Permalink
Some clean-ups after making Locker a Scope (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jan 21, 2020
1 parent 44d58f8 commit b3d93da
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
17 changes: 5 additions & 12 deletions src/binding.cc
Expand Up @@ -631,14 +631,12 @@ void v8__Template__Set(v8::Template& self, v8::Local<v8::Name> key,
}

v8::ObjectTemplate* v8__ObjectTemplate__New(
v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> templ) {
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> templ) {
return local_to_ptr(v8::ObjectTemplate::New(isolate, templ));
}

v8::Object* v8__ObjectTemplate__NewInstance(
v8::ObjectTemplate& self,
v8::Local<v8::Context> context) {
v8::Object* v8__ObjectTemplate__NewInstance(v8::ObjectTemplate& self,
v8::Local<v8::Context> context) {
return maybe_local_to_ptr(self.NewInstance(context));
}

Expand Down Expand Up @@ -903,8 +901,8 @@ v8::Function* v8__FunctionTemplate__GetFunction(
return maybe_local_to_ptr(self->GetFunction(context));
}

void v8__FunctionTemplate__SetClassName(
v8::Local<v8::FunctionTemplate> self, v8::Local<v8::String> name) {
void v8__FunctionTemplate__SetClassName(v8::Local<v8::FunctionTemplate> self,
v8::Local<v8::String> name) {
self->SetClassName(name);
}

Expand Down Expand Up @@ -942,11 +940,6 @@ v8::Value* v8__ReturnValue__Get(const v8::ReturnValue<v8::Value>& self) {
return local_to_ptr(self.Get());
}

v8::Isolate* v8__ReturnValue__GetIsolate(
const v8::ReturnValue<v8::Value>& self) {
return self.GetIsolate();
}

int v8__StackTrace__GetFrameCount(v8::StackTrace* self) {
return self->GetFrameCount();
}
Expand Down
3 changes: 1 addition & 2 deletions src/scope.rs
Expand Up @@ -176,8 +176,7 @@ impl<'s, S, P> Entered<'s, S, P> {
/// instead.
///
/// A CallbackScope can be created from the following inputs:
/// - `&mut Isolate`
/// ` - `Local<Context>`
/// - `Local<Context>`
/// - `Local<Message>`
/// - `Local<Object>`
/// - `Local<Promise>`
Expand Down
16 changes: 0 additions & 16 deletions src/scope_traits.rs
Expand Up @@ -14,7 +14,6 @@ use crate::Locker;
use crate::Message;
use crate::Object;
use crate::PropertyCallbackInfo;
use crate::ReturnValue;

pub(crate) mod internal {
use super::*;
Expand All @@ -33,7 +32,6 @@ pub(crate) mod internal {
fn v8__PropertyCallbackInfo__GetIsolate(
self_: &PropertyCallbackInfo,
) -> *mut Isolate;
fn v8__ReturnValue__GetIsolate(self_: &ReturnValue) -> *mut Isolate;
}

/// Internal trait for retrieving a raw Isolate pointer from various V8
Expand Down Expand Up @@ -132,29 +130,15 @@ pub(crate) mod internal {
unsafe { v8__PropertyCallbackInfo__GetIsolate(self) }
}
}

impl<'a> GetRawIsolate for ReturnValue<'a> {
fn get_raw_isolate(&self) -> *mut Isolate {
unsafe { v8__ReturnValue__GetIsolate(self) }
}
}
}

use internal::GetRawIsolate;

/// Trait for retrieving the current isolate from a scope object.
pub trait InIsolate {
// Do not implement this trait on unscoped Isolate references
// (e.g. OwnedIsolate) or on shared references *e.g. &Isolate).
fn isolate(&mut self) -> &mut Isolate;
}

impl InIsolate for Locker {
fn isolate(&mut self) -> &mut Isolate {
unsafe { &mut *self.get_raw_isolate() }
}
}

impl<'s, S, P> InIsolate for Entered<'s, S, P>
where
S: internal::GetRawIsolate,
Expand Down
4 changes: 2 additions & 2 deletions tests/compile_fail/handle_scope_escape_lifetime.rs
Expand Up @@ -2,8 +2,8 @@
use rusty_v8 as v8;

pub fn main() {
let mut locker: v8::Locker = mock();
let mut hs0 = v8::HandleScope::new(&mut locker);
let mut locker = v8::Locker::new(mock());
let mut hs0 = v8::HandleScope::new(locker.enter());
let hs0 = hs0.enter();

let _fail = {
Expand Down
4 changes: 2 additions & 2 deletions tests/compile_fail/handle_scope_lifetimes.rs
Expand Up @@ -2,8 +2,8 @@
use rusty_v8 as v8;

pub fn main() {
let mut locker: v8::Locker = mock();
let mut root_hs = v8::HandleScope::new(&mut locker);
let mut locker = v8::Locker::new(mock());
let mut root_hs = v8::HandleScope::new(locker.enter());
let root_hs = root_hs.enter();

{
Expand Down

0 comments on commit b3d93da

Please sign in to comment.