0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-23 15:50:11 -05:00

Add HandleScope::new2 hack to construct from const ref (#290)

This commit is contained in:
Ryan Dahl 2020-02-20 03:14:19 -05:00 committed by GitHub
parent d3bbd05634
commit 4f0662ed57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View file

@ -45,6 +45,11 @@ impl<'s> HandleScope {
let isolate: *mut Isolate = parent.isolate();
Scope::new(isolate, parent)
}
// TODO(ry) Remove this. This is a hack so we can upgrade Deno.
pub unsafe fn new2(isolate: &Isolate) -> Scope<'s, Self> {
Scope::new_root(isolate as *const _ as *mut Isolate)
}
}
unsafe impl<'s> ScopeDefinition<'s> for HandleScope {

View file

@ -4,9 +4,9 @@ error[E0277]: the trait bound `rusty_v8::scope::Entered<'_, rusty_v8::scope::Cal
7 | let _hs = v8::EscapableHandleScope::new(cs.enter());
| ^^^^^^^^^^ the trait `rusty_v8::scope_traits::ToLocal<'_>` is not implemented for `rusty_v8::scope::Entered<'_, rusty_v8::scope::CallbackScope>`
|
::: $WORKSPACE/src/handle_scope.rs:71:8
::: $WORKSPACE/src/handle_scope.rs:76:8
|
71 | P: ToLocalOrReturnsLocal<'p>,
76 | P: ToLocalOrReturnsLocal<'p>,
| ------------------------- required by this bound in `rusty_v8::handle_scope::EscapableHandleScope::new`
|
= help: the following implementations were found:

View file

@ -50,6 +50,18 @@ fn handle_scope_nested() {
}
}
#[test]
fn handle_scope_hack() {
let _setup_guard = setup();
let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params);
let mut hs = unsafe { v8::HandleScope::new2(&isolate) };
let scope1 = hs.enter();
let l1 = v8::Integer::new(scope1, -123);
assert_eq!(v8::Integer::value(&l1), -123);
}
#[test]
#[allow(clippy::float_cmp)]
fn handle_scope_numbers() {