mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-22 04:40:01 +00:00
Access to raw v8::Context slots (#1092)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
c06986c12e
commit
8a3a049d9f
@ -52,6 +52,7 @@ extern "C" {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
const ANNEX_SLOT: c_int = 1;
|
const ANNEX_SLOT: c_int = 1;
|
||||||
|
const INTERNAL_SLOT_COUNT: c_int = 1;
|
||||||
|
|
||||||
/// Creates a new context.
|
/// Creates a new context.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -307,6 +308,32 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn set_aligned_pointer_in_embedder_data(
|
||||||
|
&self,
|
||||||
|
slot: i32,
|
||||||
|
data: *mut c_void,
|
||||||
|
) {
|
||||||
|
v8__Context__SetAlignedPointerInEmbedderData(
|
||||||
|
self,
|
||||||
|
slot + Self::INTERNAL_SLOT_COUNT,
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn get_aligned_pointer_from_embedder_data(
|
||||||
|
&self,
|
||||||
|
slot: i32,
|
||||||
|
) -> *mut c_void {
|
||||||
|
unsafe {
|
||||||
|
v8__Context__GetAlignedPointerFromEmbedderData(
|
||||||
|
self,
|
||||||
|
slot + Self::INTERNAL_SLOT_COUNT,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new context from a (non-default) context snapshot. There
|
/// Create a new context from a (non-default) context snapshot. There
|
||||||
/// is no way to provide a global object template since we do not create
|
/// is no way to provide a global object template since we do not create
|
||||||
/// a new global object from template, but we can reuse a global object.
|
/// a new global object from template, but we can reuse a global object.
|
||||||
|
@ -7674,6 +7674,46 @@ fn isolate_data_slots() {
|
|||||||
assert_eq!(actual1, expected1);
|
assert_eq!(actual1, expected1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn context_embedder_data() {
|
||||||
|
let _setup_guard = setup();
|
||||||
|
let isolate = &mut v8::Isolate::new(Default::default());
|
||||||
|
let global_context;
|
||||||
|
|
||||||
|
let expected0 = "Bla";
|
||||||
|
let expected1 = 123.456f64;
|
||||||
|
{
|
||||||
|
let scope = &mut v8::HandleScope::new(isolate);
|
||||||
|
let context = v8::Context::new(scope);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
context.set_aligned_pointer_in_embedder_data(
|
||||||
|
0,
|
||||||
|
&expected0 as *const _ as *mut &str as *mut c_void,
|
||||||
|
);
|
||||||
|
context.set_aligned_pointer_in_embedder_data(
|
||||||
|
1,
|
||||||
|
&expected1 as *const _ as *mut f64 as *mut c_void,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
global_context = v8::Global::new(scope, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let scope = &mut v8::HandleScope::new(isolate);
|
||||||
|
let context = global_context.open(scope);
|
||||||
|
let actual0 =
|
||||||
|
context.get_aligned_pointer_from_embedder_data(0) as *mut &str;
|
||||||
|
let actual0 = unsafe { *actual0 };
|
||||||
|
assert_eq!(actual0, expected0);
|
||||||
|
|
||||||
|
let actual1 = context.get_aligned_pointer_from_embedder_data(1) as *mut f64;
|
||||||
|
let actual1 = unsafe { *actual1 };
|
||||||
|
assert_eq!(actual1, expected1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn host_create_shadow_realm_context_callback() {
|
fn host_create_shadow_realm_context_callback() {
|
||||||
let _setup_guard = setup();
|
let _setup_guard = setup();
|
||||||
|
Loading…
Reference in New Issue
Block a user