Skip to main content

v8/
external_references.rs

1// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
2
3use crate::FunctionCallback;
4use crate::IndexedDefinerCallback;
5use crate::IndexedDeleterCallback;
6use crate::IndexedGetterCallback;
7use crate::IndexedQueryCallback;
8use crate::IndexedSetterCallback;
9use crate::MessageCallback;
10use crate::NamedDefinerCallback;
11use crate::NamedDeleterCallback;
12use crate::NamedGetterCallback;
13use crate::NamedQueryCallback;
14use crate::NamedSetterCallback;
15use crate::PropertyEnumeratorCallback;
16use crate::fast_api::CFunctionInfo;
17use std::ffi::c_void;
18use std::fmt::Debug;
19
20#[derive(Clone, Copy)]
21pub union ExternalReference {
22  pub function: FunctionCallback,
23  pub named_getter: NamedGetterCallback,
24  pub named_setter: NamedSetterCallback,
25  pub named_definer: NamedDefinerCallback,
26  pub named_deleter: NamedDeleterCallback,
27  pub named_query: NamedQueryCallback,
28  pub indexed_getter: IndexedGetterCallback,
29  pub indexed_setter: IndexedSetterCallback,
30  pub indexed_definer: IndexedDefinerCallback,
31  pub indexed_deleter: IndexedDeleterCallback,
32  pub indexed_query: IndexedQueryCallback,
33  pub enumerator: PropertyEnumeratorCallback,
34  pub message: MessageCallback,
35  pub pointer: *mut c_void,
36  pub type_info: *const CFunctionInfo,
37}
38
39impl Debug for ExternalReference {
40  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41    // SAFETY: All union fields are the same size
42    unsafe { (self.pointer).fmt(f) }
43  }
44}
45
46impl PartialEq for ExternalReference {
47  fn eq(&self, other: &Self) -> bool {
48    unsafe { self.pointer.eq(&other.pointer) }
49  }
50}