mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-23 07:29:56 -05:00
Make Symbol work with context-less HandleScope (#550)
v8::Symbol is like v8::String and other primitives, it doesn't need an active v8::Context.
This commit is contained in:
parent
c1509cac08
commit
343d7f2800
2 changed files with 7 additions and 6 deletions
|
@ -19,7 +19,7 @@ extern "C" {
|
||||||
|
|
||||||
macro_rules! well_known {
|
macro_rules! well_known {
|
||||||
($name:ident, $binding:ident) => {
|
($name:ident, $binding:ident) => {
|
||||||
pub fn $name<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Symbol> {
|
pub fn $name<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Symbol> {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn $binding(isolate: *mut Isolate) -> *const Symbol;
|
fn $binding(isolate: *mut Isolate) -> *const Symbol;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ impl Symbol {
|
||||||
/// Create a symbol. If description is not empty, it will be used as the
|
/// Create a symbol. If description is not empty, it will be used as the
|
||||||
/// description.
|
/// description.
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
description: Option<Local<String>>,
|
description: Option<Local<String>>,
|
||||||
) -> Local<'s, Symbol> {
|
) -> Local<'s, Symbol> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -54,7 +54,7 @@ impl Symbol {
|
||||||
/// To minimize the potential for clashes, use qualified descriptions as keys.
|
/// To minimize the potential for clashes, use qualified descriptions as keys.
|
||||||
/// Corresponds to v8::Symbol::For() in C++.
|
/// Corresponds to v8::Symbol::For() in C++.
|
||||||
pub fn for_global<'s>(
|
pub fn for_global<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
description: Local<String>,
|
description: Local<String>,
|
||||||
) -> Local<'s, Symbol> {
|
) -> Local<'s, Symbol> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -68,7 +68,7 @@ impl Symbol {
|
||||||
/// Returns the description string of the symbol, or undefined if none.
|
/// Returns the description string of the symbol, or undefined if none.
|
||||||
pub fn description<'s>(
|
pub fn description<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
) -> Local<'s, Value> {
|
) -> Local<'s, Value> {
|
||||||
unsafe { scope.cast_local(|_| v8__Symbol__Description(&*self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Symbol__Description(&*self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3835,8 +3835,6 @@ fn symbol() {
|
||||||
let _setup_guard = setup();
|
let _setup_guard = setup();
|
||||||
let isolate = &mut v8::Isolate::new(Default::default());
|
let isolate = &mut v8::Isolate::new(Default::default());
|
||||||
let scope = &mut v8::HandleScope::new(isolate);
|
let scope = &mut v8::HandleScope::new(isolate);
|
||||||
let context = v8::Context::new(scope);
|
|
||||||
let scope = &mut v8::ContextScope::new(scope, context);
|
|
||||||
|
|
||||||
let desc = v8::String::new(scope, "a description").unwrap();
|
let desc = v8::String::new(scope, "a description").unwrap();
|
||||||
|
|
||||||
|
@ -3854,6 +3852,9 @@ fn symbol() {
|
||||||
assert!(s_pub2 != s);
|
assert!(s_pub2 != s);
|
||||||
assert!(s_pub == s_pub2);
|
assert!(s_pub == s_pub2);
|
||||||
|
|
||||||
|
let context = v8::Context::new(scope);
|
||||||
|
let scope = &mut v8::ContextScope::new(scope, context);
|
||||||
|
|
||||||
let s = eval(scope, "Symbol.asyncIterator").unwrap();
|
let s = eval(scope, "Symbol.asyncIterator").unwrap();
|
||||||
assert!(s == v8::Symbol::get_async_iterator(scope));
|
assert!(s == v8::Symbol::get_async_iterator(scope));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue