kg_js/
lib.rs

1use std::ffi::CStr;
2use std::ops::{Deref};
3use std::os::raw::*;
4
5mod bindings;
6use self::bindings::*;
7
8pub use self::bindings::DukType;
9pub use console::*;
10pub use ctx::*;
11pub use engine::*;
12pub use interop::*;
13pub use error::*;
14
15mod console;
16mod ctx;
17mod engine;
18pub mod alloc;
19mod interop;
20mod error;
21
22#[cfg(feature = "serde")]
23pub mod ser;
24#[cfg(feature = "serde")]
25pub mod de;
26
27const FUNC_NAME_PROP: &[u8] = b"name";
28
29const DUK_EXEC_SUCCESS: i32 = 0;
30
31pub trait ReadJs {
32    fn read_js(ctx: &DukContext, obj_index: i32) -> Result<Self, JsError>
33    where
34        Self: Sized;
35
36    fn read_js_top(ctx: &DukContext) -> Result<Self, JsError>
37    where
38        Self: Sized,
39    {
40        let idx = ctx.normalize_index(-1);
41        Self::read_js(ctx, idx)
42    }
43}
44
45pub trait WriteJs {
46    fn write_js(&self, ctx: &DukContext) -> Result<(), JsError>;
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
50#[repr(i32)]
51pub enum Return {
52    Undefined = 0,
53    Top = 1,
54    Error = -1,
55    EvalError = -2,
56    RangeError = -3,
57    ReferenceError = -4,
58    SyntaxError = -5,
59    TypeError = -6,
60    UriError = -7,
61}
62