From 970378356d0d7239b332baa37470455391b5e6e4 Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 3 May 2024 01:41:38 +0200 Subject: js: fix various leaks etc. Previously we didn't actually free the main JS runtime, probably because you can't do this without first waiting for JS to unwind the stack. (This has the unfortunate effect that code now *can* run after quit(). TODO: find a fix for this.) This isn't a huge problem per se, we only have one of these and the OS can clean it up. However, it also disabled the JS_FreeRuntime leak check, which resulted in sieve-like behavior (manual refcounting is a pain). So now we choose the other tradeoff: quit no longer runs exitnow, but it waits for the event loop to run to the end and only then exits the browser. Then, before exit we free the JS context & runtime, and also all JS values allocated by config. Fixes: * fix `ad' flag not being set for just one siteconf/omnirule * fix various leaks (since leak check is enabled now) * use ptr UncheckedArray[JSValue] for QJS bindings that take an array * allow JSAtom in jsgetprop etc., also disallow int types other than uint32 * do not set a destructor for globals --- src/bindings/quickjs.nim | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/bindings') diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim index 164f7dad..7a3eee54 100644 --- a/src/bindings/quickjs.nim +++ b/src/bindings/quickjs.nim @@ -80,7 +80,8 @@ type JSCFunction* = proc(ctx: JSContext; this_val: JSValue; argc: cint; argv: ptr UncheckedArray[JSValue]): JSValue {.cdecl.} JSCFunctionData* = proc(ctx: JSContext; this_val: JSValue; argc: cint; - argv: ptr JSValue; magic: cint; func_data: ptr JSValue): JSValue {.cdecl.} + argv: ptr UncheckedArray[JSValue]; magic: cint; + func_data: ptr UncheckedArray[JSValue]): JSValue {.cdecl.} JSGetterFunction* = proc(ctx: JSContext; this_val: JSValue): JSValue {.cdecl.} JSSetterFunction* = proc(ctx: JSContext; this_val, val: JSValue): JSValue {.cdecl.} @@ -90,7 +91,7 @@ type magic: cint): JSValue {.cdecl.} JSInterruptHandler* = proc(rt: JSRuntime; opaque: pointer): cint {.cdecl.} JSClassID* = uint32 - JSAtom* = uint32 + JSAtom* = distinct uint32 JSClassFinalizer* = proc(rt: JSRuntime; val: JSValue) {.cdecl.} JSClassCheckDestroy* = proc(rt: JSRuntime; val: JSValue): JS_BOOL {.cdecl.} JSClassGCMark* = proc(rt: JSRuntime; val: JSValue; mark_func: JS_MarkFunc) @@ -100,8 +101,8 @@ type module_name: cstringConst; opaque: pointer): cstring {.cdecl.} JSModuleLoaderFunc* = proc(ctx: JSContext; module_name: cstringConst, opaque: pointer): JSModuleDef {.cdecl.} - JSJobFunc* = proc(ctx: JSContext; argc: cint; argv: ptr JSValue): JSValue - {.cdecl.} + JSJobFunc* = proc(ctx: JSContext; argc: cint; + argv: ptr UncheckedArray[JSValue]): JSValue {.cdecl.} JSGCObjectHeader* {.importc, header: qjsheader.} = object JSFreeArrayBufferDataFunc* = proc(rt: JSRuntime; opaque, p: pointer) {.cdecl.} @@ -185,7 +186,7 @@ type base: cint JSCFunctionListEntryPropList = object - tab: ptr JSCFunctionListEntry + tab: ptr UncheckedArray[JSCFunctionListEntry] len: cint JSCFunctionListEntryU* {.union.} = object @@ -372,8 +373,8 @@ proc JS_NewObjectClass*(ctx: JSContext; class_id: JSClassID): JSValue proc JS_NewObjectProto*(ctx: JSContext; proto: JSValue): JSValue proc JS_NewObjectProtoClass*(ctx: JSContext; proto: JSValue; class_id: JSClassID): JSValue -proc JS_NewPromiseCapability*(ctx: JSContext; resolving_funcs: ptr JSValue): - JSValue +proc JS_NewPromiseCapability*(ctx: JSContext; + resolving_funcs: ptr UncheckedArray[JSValue]): JSValue proc JS_SetOpaque*(obj: JSValue; opaque: pointer) proc JS_GetOpaque*(obj: JSValue; class_id: JSClassID): pointer proc JS_GetOpaque2*(ctx: JSContext; obj: JSValue; class_id: JSClassID): pointer @@ -422,7 +423,7 @@ proc JS_FreeAtomRT*(rt: JSRuntime; atom: JSAtom) proc JS_NewCFunction2*(ctx: JSContext; cfunc: JSCFunction; name: cstring; length: cint; proto: JSCFunctionEnum; magic: cint): JSValue proc JS_NewCFunctionData*(ctx: JSContext; cfunc: JSCFunctionData; - length, magic, data_len: cint; data: ptr JSValue): JSValue + length, magic, data_len: cint; data: ptr UncheckedArray[JSValue]): JSValue proc JS_NewCFunction*(ctx: JSContext; cfunc: JSCFunction; name: cstring; length: cint): JSValue @@ -453,13 +454,13 @@ proc JS_GetOwnPropertyNames*(ctx: JSContext; proc JS_GetOwnProperty*(ctx: JSContext; desc: ptr JSPropertyDescriptor; obj: JSValue; prop: JSAtom): cint proc JS_Call*(ctx: JSContext; func_obj, this_obj: JSValue; argc: cint; - argv: ptr JSValue): JSValue + argv: ptr UncheckedArray[JSValue]): JSValue proc JS_NewObjectFromCtor*(ctx: JSContext; ctor: JSValue; class_id: JSClassID): JSValue proc JS_Invoke*(ctx: JSContext; this_obj: JSValue; atom: JSAtom; argc: cint; - argv: ptr JSValue): JSValue + argv: ptr UncheckedArray[JSValue]): JSValue proc JS_CallConstructor*(ctx: JSContext; func_obj: JSValue; argc: cint; - argv: ptr JSValue): JSValue + argv: ptr UncheckedArray[JSValue]): JSValue proc JS_DefineProperty*(ctx: JSContext; this_obj: JSValue; prop: JSAtom; val, getter, setter: JSValue; flags: cint): cint @@ -544,7 +545,7 @@ proc JS_GetImportMeta*(ctx: JSContext; m: JSModuleDef): JSValue proc JS_GetModuleName*(ctx: JSContext; m: JSModuleDef): JSAtom proc JS_EnqueueJob*(ctx: JSContext; job_func: JSJobFunc; argc: cint; - argv: ptr JSValue): cint + argv: ptr UncheckedArray[JSValue]): cint proc JS_IsJobPending*(rt: JSRuntime): JS_BOOL proc JS_ExecutePendingJob*(rt: JSRuntime; pctx: ptr JSContext): cint -- cgit 1.4.1-2-gfad0 ^
3326769 ^
50871fc ^







d282ab6 ^


50871fc ^


50871fc ^

ddbef09 ^




50871fc ^






5ea5932 ^

50871fc ^






c1e489f ^
50871fc ^




a5ff830 ^


d282ab6 ^
a5ff830 ^


50871fc ^
a5ff830 ^
50871fc ^



ddbef09 ^
50871fc ^
ddbef09 ^


50871fc ^
3326769 ^
50871fc ^


ddbef09 ^

50871fc ^





a5ff830 ^

c1e489f ^


3326769 ^



a5ff830 ^



f69c528 ^


944222f ^
f69c528 ^
a5ff830 ^

5ea5932 ^

d282ab6 ^
5ea5932 ^








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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138