devela/lang/prog/ffi/js/primitives.rs
1// devela::lang::prog::ffi::js::types::primitives
2
3#![allow(non_camel_case_types, non_upper_case_globals)]
4
5/* numbers */
6
7#[doc = crate::_tags!(primitive num)]
8/// A JavaScript Number.
9#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
10///
11/// All numeric values are represented as IEEE 754 **64-bit floating-point** values.
12///
13/// JavaScript does not distinguish between integers and floating-point numbers at the type level.
14pub type js_number = f64;
15
16#[doc = crate::_tags!(primitive num)]
17/// A JavaScript signed 32-bit integer.
18#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
19///
20/// JavaScript does not have true integer types, but **bitwise operations** and certain APIs
21/// force numbers into signed 32-bit integer representation (`i32`).
22///
23/// - **To ensure signed 32-bit behavior in JavaScript:** use `Int32Array` instead of plain arrays.
24/// - **To coerce a number into an `i32`:** use `num | 0` in JavaScript.
25/// - **Bitwise shifts (`<<`, `>>`) operate on signed 32-bit integers.**
26pub type js_int32 = i32;
27
28#[doc = crate::_tags!(primitive num)]
29/// A JavaScript unsigned 32-bit integer.
30#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
31///
32/// JavaScript lacks native unsigned integers, but **the `>>>` operator** treats numbers as unsigned **`u32`**.
33/// Some APIs, such as `Uint32Array`, also provide unsigned integer behavior.
34///
35/// - **To ensure unsigned 32-bit behavior in JavaScript:** use `Uint32Array` instead of plain arrays.
36/// - **To coerce a number into a `u32`:** use `num >>> 0` in JavaScript.
37/// - **Only `>>>` (unsigned right shift) preserves unsigned semantics.**
38pub type js_uint32 = u32;
39
40/* numeric constants */
41// MAYBE
42
43// /// The JavaScript `NaN` (Not-a-Number) value.
44// pub const js_nan: js_number = js_number::NAN;
45// /// The JavaScript `Infinity` value.
46// pub const js_infinity: js_number = js_number::INFINITY;
47// /// The JavaScript `-Infinity` value.
48// pub const js_neg_infinity: js_number = js_number::NEG_INFINITY;
49
50/* boolean */
51
52#[doc = crate::_tags!(primitive logic)]
53/// A JavaScript boolean (`true` / `false`).
54#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
55pub type js_bool = bool;
56
57/* string */
58
59#[doc = crate::_tags!(primitive text)]
60/// A JavaScript string reference.
61#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
62///
63/// JavaScript strings are **UTF-16 internally**, but Rust typically interacts with them
64/// as **UTF-8**. This type represents a pointer to a UTF-8 encoded string.
65pub type js_str = *const u8;
66
67/* special types */
68
69#[doc = crate::_tags!(primitive no)]
70/// The JavaScript `null` value.
71#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
72///
73/// Though `null` is distinct from `undefined` in JavaScript,
74/// both are often treated interchangeably.
75/// In Rust, `null` is mapped to the unit type `()`.
76pub type js_null = ();
77
78#[doc = crate::_tags!(primitive no)]
79/// The JavaScript `undefined` value.
80#[doc = crate::_doc_meta!{location("lang/prog/ffi/js")}]
81///
82/// In Rust, `undefined` is represented as the unit type `()`, as it carries no meaningful value.
83pub type js_undefined = ();