Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,15 @@ impl Context {
/// Note that index 0 currently has a special meaning for Chrome's debugger.
#[inline(always)]
pub fn set_embedder_data(&self, slot: i32, data: Local<'_, Value>) {
// Initialize the annex when slot count > INTERNAL_SLOT_COUNT.
self.get_annex_mut(true);

unsafe {
v8__Context__SetEmbedderData(self, slot, &*data);
v8__Context__SetEmbedderData(
self,
slot + Self::INTERNAL_SLOT_COUNT,
&*data,
);
}
}

Expand All @@ -329,7 +336,11 @@ impl Context {
scope: &PinScope<'s, '_, ()>,
slot: i32,
) -> Option<Local<'s, Value>> {
unsafe { scope.cast_local(|_| v8__Context__GetEmbedderData(self, slot)) }
unsafe {
scope.cast_local(|_| {
v8__Context__GetEmbedderData(self, slot + Self::INTERNAL_SLOT_COUNT)
})
}
}

#[inline(always)]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5739,6 +5739,7 @@ fn snapshot_creator_context_embedder_data() {
let one_val = v8::Number::new(scope, 1.0).into();
assert!(prop.same_value(one_val));
}
context.clear_all_slots();
scope.set_default_context(context);
}

Expand Down Expand Up @@ -5772,6 +5773,7 @@ fn snapshot_creator_context_embedder_data() {
let value = context.get_embedder_data(scope, 2).unwrap();
assert!(value.same_value(x));
}
context.clear_all_slots();
scope.set_default_context(context);
}
snapshot_creator
Expand Down
Loading