mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-27 17:49:12 -05:00
feat: Add bindings for continuation embedder data (#1184)
Adds bindings for: - v8::Context::GetContinuationPreservedEmbedderData - v8::Context::SetContinuationPreservedEmbedderData These APIs are available on the "HandleScope". --------- Co-authored-by: Bert Belder <bertbelder@gmail.com>
This commit is contained in:
parent
83b54692c1
commit
3b6d79c0e6
3 changed files with 72 additions and 0 deletions
|
@ -1726,6 +1726,18 @@ const v8::Context* v8__Context__FromSnapshot(v8::Isolate* isolate,
|
||||||
return maybe_local_to_ptr(maybe_local);
|
return maybe_local_to_ptr(maybe_local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void v8__Context__SetContinuationPreservedEmbedderData(v8::Context& context,
|
||||||
|
const v8::Value* data) {
|
||||||
|
auto c = ptr_to_local(&context);
|
||||||
|
c->SetContinuationPreservedEmbedderData(ptr_to_local(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
const v8::Value* v8__Context__GetContinuationPreservedEmbedderData(
|
||||||
|
const v8::Context& context) {
|
||||||
|
auto value = ptr_to_local(&context)->GetContinuationPreservedEmbedderData();
|
||||||
|
return local_to_ptr(value);
|
||||||
|
}
|
||||||
|
|
||||||
const v8::String* v8__Message__Get(const v8::Message& self) {
|
const v8::String* v8__Message__Get(const v8::Message& self) {
|
||||||
return local_to_ptr(self.Get());
|
return local_to_ptr(self.Get());
|
||||||
}
|
}
|
||||||
|
|
36
src/scope.rs
36
src/scope.rs
|
@ -286,6 +286,35 @@ impl<'s> HandleScope<'s> {
|
||||||
.and_then(|data| data.try_into())
|
.and_then(|data| data.try_into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn set_continuation_preserved_embedder_data(
|
||||||
|
&mut self,
|
||||||
|
data: Local<Value>,
|
||||||
|
) {
|
||||||
|
unsafe {
|
||||||
|
let sd = data::ScopeData::get_mut(self);
|
||||||
|
raw::v8__Context__SetContinuationPreservedEmbedderData(
|
||||||
|
sd.get_current_context(),
|
||||||
|
&*data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn get_continuation_preserved_embedder_data(
|
||||||
|
&mut self,
|
||||||
|
) -> Local<'s, Value> {
|
||||||
|
unsafe {
|
||||||
|
self
|
||||||
|
.cast_local(|sd| {
|
||||||
|
raw::v8__Context__GetContinuationPreservedEmbedderData(
|
||||||
|
sd.get_current_context(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A HandleScope which first allocates a handle in the current scope
|
/// A HandleScope which first allocates a handle in the current scope
|
||||||
|
@ -1690,6 +1719,13 @@ mod raw {
|
||||||
this: *const Context,
|
this: *const Context,
|
||||||
index: usize,
|
index: usize,
|
||||||
) -> *const Data;
|
) -> *const Data;
|
||||||
|
pub(super) fn v8__Context__SetContinuationPreservedEmbedderData(
|
||||||
|
this: *const Context,
|
||||||
|
value: *const Value,
|
||||||
|
);
|
||||||
|
pub(super) fn v8__Context__GetContinuationPreservedEmbedderData(
|
||||||
|
this: *const Context,
|
||||||
|
) -> *const Value;
|
||||||
|
|
||||||
pub(super) fn v8__HandleScope__CONSTRUCT(
|
pub(super) fn v8__HandleScope__CONSTRUCT(
|
||||||
buf: *mut MaybeUninit<HandleScope>,
|
buf: *mut MaybeUninit<HandleScope>,
|
||||||
|
|
|
@ -4011,6 +4011,30 @@ fn array_buffer_view() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn continuation_preserved_embedder_data() {
|
||||||
|
let _setup_guard = setup::parallel_test();
|
||||||
|
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 data = scope.get_continuation_preserved_embedder_data();
|
||||||
|
assert!(data.is_undefined());
|
||||||
|
|
||||||
|
let value = v8::String::new(scope, "hello").unwrap();
|
||||||
|
scope.set_continuation_preserved_embedder_data(value.into());
|
||||||
|
let data = scope.get_continuation_preserved_embedder_data();
|
||||||
|
assert!(data.is_string());
|
||||||
|
assert_eq!(data.to_rust_string_lossy(scope), "hello");
|
||||||
|
|
||||||
|
eval(scope, "b = 2 + 3").unwrap();
|
||||||
|
let data = scope.get_continuation_preserved_embedder_data();
|
||||||
|
assert!(data.is_string());
|
||||||
|
assert_eq!(data.to_rust_string_lossy(scope), "hello");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn snapshot_creator() {
|
fn snapshot_creator() {
|
||||||
let _setup_guard = setup::sequential_test();
|
let _setup_guard = setup::sequential_test();
|
||||||
|
|
Loading…
Reference in a new issue