0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-13 17:40:23 -05:00
denoland-rusty-v8/src/external_references.rs
Luca Casonato e7f96ac708
Improved ObjectTemplate::set_*_handlers (#1237)
Prior to this commit, `v8::NamedPropertyHandlerConfiguration`
and `v8::IndexedPropertyHandlerConfiguration` did not expose the
`definer` hook, or `flags`.

This commit adds these options. In the process of doing this a couple of
other changes were made:

- Bitflag enum consts are now member consts of the related struct.
  This is done because PropertyHandlerFlags has conflicts with
  PropertyAttribute.
- PropertyDescriptor gets all C++ introspection methods exposed to Rust.
- NamedPropertyHandlerConfiguration callback types get rustdoc comments.
- IndexedPropertyHandlerConfiguration callback types get rustdoc
  comments.
- GenericNamedPropertySetterCallback gets a ReturnValue parameter, to
  signal trap passthrough.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-05-26 13:14:18 +02:00

64 lines
1.7 KiB
Rust

// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
use crate::support::intptr_t;
use crate::FunctionCallback;
use crate::IndexedDefinerCallback;
use crate::IndexedGetterCallback;
use crate::IndexedSetterCallback;
use crate::MessageCallback;
use crate::NamedDefinerCallback;
use crate::NamedGetterCallback;
use crate::NamedSetterCallback;
use crate::PropertyEnumeratorCallback;
use std::ffi::c_void;
#[derive(Clone, Copy)]
pub union ExternalReference<'s> {
pub function: FunctionCallback,
pub named_getter: NamedGetterCallback<'s>,
pub named_setter: NamedSetterCallback<'s>,
pub named_definer: NamedDefinerCallback<'s>,
pub indexed_getter: IndexedGetterCallback<'s>,
pub indexed_setter: IndexedSetterCallback<'s>,
pub indexed_definer: IndexedDefinerCallback<'s>,
pub enumerator: PropertyEnumeratorCallback<'s>,
pub message: MessageCallback,
pub pointer: *mut c_void,
}
#[derive(Debug, Clone)]
pub struct ExternalReferences {
null_terminated: Vec<intptr_t>,
}
unsafe impl Sync for ExternalReferences {}
impl ExternalReferences {
#[inline(always)]
pub fn new(refs: &[ExternalReference]) -> Self {
let null_terminated = refs
.iter()
.map(|&r| unsafe { std::mem::transmute(r) })
.chain(std::iter::once(0)) // Add null terminator.
.collect::<Vec<intptr_t>>();
Self { null_terminated }
}
#[inline(always)]
pub fn as_ptr(&self) -> *const intptr_t {
self.null_terminated.as_ptr()
}
}
impl std::ops::Deref for ExternalReferences {
type Target = [intptr_t];
fn deref(&self) -> &Self::Target {
&self.null_terminated
}
}
impl std::borrow::Borrow<[intptr_t]> for ExternalReferences {
fn borrow(&self) -> &[intptr_t] {
self
}
}