-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathruntime.v
75 lines (63 loc) · 1.54 KB
/
runtime.v
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
module vjs
@[typedef]
struct C.JSRuntime {}
// Runtime structure based on `JSRuntime` in qjs
// and implemented into `ref`.
pub struct Runtime {
ref &C.JSRuntime
}
// JSError structure.
@[params]
pub struct JSError {
Error
pub mut:
name string = 'Error'
stack string
message string
}
// lookup/print JSError message.
pub fn (err &JSError) msg() string {
return '${err.message}\n${err.stack}'
}
fn C.JS_NewRuntime() &C.JSRuntime
fn C.JS_SetCanBlock(&C.JSRuntime, int)
fn C.JS_FreeRuntime(&C.JSRuntime)
fn C.JS_RunGC(&C.JSRuntime)
fn C.JS_SetMaxStackSize(&C.JSRuntime, usize)
fn C.JS_SetGCThreshold(&C.JSRuntime, usize)
fn C.JS_SetMemoryLimit(&C.JSRuntime, usize)
fn C.JS_IsJobPending(&C.JSRuntime) bool
// Create new Runtime.
// Example:
// ```v
// rt := vjs.new_runtime()
// ```
pub fn new_runtime() Runtime {
rt := Runtime{C.JS_NewRuntime()}
C.JS_SetCanBlock(rt.ref, 1)
return rt
}
// Check if job is pending
pub fn (rt Runtime) is_job_pending() bool {
return C.JS_IsJobPending(rt.ref)
}
// Set limit memory. (default to unlimited)
pub fn (rt Runtime) set_memory_limit(limit u32) {
C.JS_SetMemoryLimit(rt.ref, usize(limit))
}
// Set maximum stack size. (default to 255)
pub fn (rt Runtime) set_max_stack_size(stack_size u32) {
C.JS_SetMaxStackSize(rt.ref, usize(stack_size))
}
// Set gc threshold.
pub fn (rt Runtime) set_gc_threshold(th i64) {
C.JS_SetGCThreshold(rt.ref, usize(th))
}
// Run qjs garbage collector
pub fn (rt Runtime) run_gc() {
C.JS_RunGC(rt.ref)
}
// Free runtime
pub fn (rt &Runtime) free() {
C.JS_FreeRuntime(rt.ref)
}