forked from servo/rust-mozjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.rs
97 lines (80 loc) · 2.37 KB
/
js.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import ptr::{null, addr_of};
import result::{result, ok, err, extensions};
import libc::c_char;
import name_pool::{name_pool, methods};
import str::unsafe::from_c_str;
import io::writer_util;
import libc::types::common::c99::*;
import jsapi::*;
import jsapi::bindgen::*;
export JSOPTION_STRICT;
export JSOPTION_WERROR;
export JSOPTION_VAROBJFIX;
export JSOPTION_METHODJIT;
export JSCLASS_GLOBAL_FLAGS;
export crust;
export rust;
export jsapi;
export global;
// These are just macros in jsapi.h
import JS_NewRuntime = jsapi::bindgen::JS_Init;
export JS_NewRuntime;
import JS_DestroyRuntime = jsapi::bindgen::JS_Finish;
export JS_DestroyRuntime;
/*
FIXME: Not sure where JS_Lock is
import JS_LockRuntime = jsapi::bindgen::JS_Lock;
export JS_LockRuntime;
import JS_UnlockRuntime = jsapi::bindgen::JS_Unlock;
export JS_UnlockRuntime;
*/
export JS_ARGV;
export JS_SET_RVAL;
export JSVAL_VOID;
export JSVAL_NULL;
export JSVAL_ZERO;
export JSVAL_ONE;
export JSVAL_FALSE;
export JSVAL_TRUE;
/* Look in this directory for spidermonkey */
#[link_args = "-L."]
/* Link to the static js library */
#[link_args = "-ljs_static"]
native mod m { }
// FIXME: Add the remaining options
const JSOPTION_STRICT: uint32_t = 0b00000000000001u32;
const JSOPTION_WERROR: uint32_t = 0b00000000000010u32;
const JSOPTION_VAROBJFIX: uint32_t = 0b00000000000100u32;
const JSOPTION_METHODJIT: uint32_t = 0b10000000000000u32;
const JSCLASS_GLOBAL_FLAGS: uint32_t = 0x47d00du32;
const default_heapsize: u32 = 8_u32 * 1024_u32 * 1024_u32;
const default_stacksize: uint = 8192u;
const ERR: JSBool = 0_i32;
const JSVAL_VOID: u64 = 0x0001fff2_00000000_u64;
const JSVAL_NULL: u64 = 0x0001fff6_00000000_u64;
const JSVAL_ZERO: u64 = 0x0001fff1_00000000_u64;
const JSVAL_ONE: u64 = 0x0001fff1_00000001_u64;
const JSVAL_FALSE: u64 = 0x0001fff3_00000000_u64;
const JSVAL_TRUE: u64 = 0x0001fff3_00000001_u64;
fn result(n: JSBool) -> result<(),()> {
if n != ERR {ok(())} else {err(())}
}
type named_functions = @{
names: [str],
funcs: [JSFunctionSpec]
};
impl ptr_methods<T: copy> for *T {
unsafe fn +(idx: uint) -> *T {
ptr::offset(self, idx)
}
unsafe fn [](idx: uint) -> T {
*(self + idx)
}
}
unsafe fn JS_ARGV(_cx: *JSContext, vp: *jsval) -> *jsval {
vp + 2u
}
unsafe fn JS_SET_RVAL(_cx: *JSContext, vp: *jsval, v: jsval) {
let vp: *mut jsval = unsafe::reinterpret_cast(vp);
*vp = v;
}