Skip to content

Commit 9fdf040

Browse files
committed
Fix get/set_embedder_data to create annex and offset by internal slot count
1 parent 773cb51 commit 9fdf040

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/context.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,15 @@ impl Context {
316316
/// Note that index 0 currently has a special meaning for Chrome's debugger.
317317
#[inline(always)]
318318
pub fn set_embedder_data(&self, slot: i32, data: Local<'_, Value>) {
319+
// Initialize the annex when slot count > INTERNAL_SLOT_COUNT.
320+
self.get_annex_mut(true);
321+
319322
unsafe {
320-
v8__Context__SetEmbedderData(self, slot, &*data);
323+
v8__Context__SetEmbedderData(
324+
self,
325+
slot + Self::INTERNAL_SLOT_COUNT,
326+
&*data,
327+
);
321328
}
322329
}
323330

@@ -329,7 +336,11 @@ impl Context {
329336
scope: &PinScope<'s, '_, ()>,
330337
slot: i32,
331338
) -> Option<Local<'s, Value>> {
332-
unsafe { scope.cast_local(|_| v8__Context__GetEmbedderData(self, slot)) }
339+
unsafe {
340+
scope.cast_local(|_| {
341+
v8__Context__GetEmbedderData(self, slot + Self::INTERNAL_SLOT_COUNT)
342+
})
343+
}
333344
}
334345

335346
#[inline(always)]

0 commit comments

Comments
 (0)