0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-24 15:19:31 -05:00

Make Private work with context-less HandleScope (#549)

v8::Private is like v8::String and other primitives, it doesn't need an
active v8::Context.
This commit is contained in:
Ben Noordhuis 2020-12-07 22:48:51 +01:00 committed by GitHub
parent 4e8eaf94c3
commit 530c876aff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -20,7 +20,7 @@ extern "C" {
impl Private {
/// Create a private symbol. If name is not empty, it will be the description.
pub fn new<'s>(
scope: &mut HandleScope<'s>,
scope: &mut HandleScope<'s, ()>,
name: Option<Local<String>>,
) -> Local<'s, Private> {
unsafe {
@ -42,7 +42,7 @@ impl Private {
/// To minimize the potential for clashes, use qualified names as keys,
/// e.g., "Class#property".
pub fn for_api<'s>(
scope: &mut HandleScope<'s>,
scope: &mut HandleScope<'s, ()>,
name: Option<Local<String>>,
) -> Local<'s, Private> {
unsafe {
@ -57,7 +57,7 @@ impl Private {
}
/// Returns the print name string of the private symbol, or undefined if none.
pub fn name<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
pub fn name<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Private__Name(&*self)) }.unwrap()
}
}

View file

@ -3873,8 +3873,6 @@ fn private() {
let _setup_guard = setup();
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let p = v8::Private::new(scope, None);
assert!(p.name(scope) == v8::undefined(scope));
@ -3891,6 +3889,9 @@ fn private() {
assert!(p_api2 != p);
assert!(p_api == p_api2);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let object = v8::Object::new(scope);
let sentinel = v8::Object::new(scope).into();
assert!(!object.has_private(scope, p).unwrap());