about summary refs log tree commit diff stats
path: root/src/js/jsutils.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-03 01:41:38 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-03 01:58:12 +0200
commit970378356d0d7239b332baa37470455391b5e6e4 (patch)
tree87d93162295b12652137193982c5b3c88e1a3758 /src/js/jsutils.nim
parentc48f2caedabbcda03724c43935f4175aac3ecf90 (diff)
downloadchawan-970378356d0d7239b332baa37470455391b5e6e4.tar.gz
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
Diffstat (limited to 'src/js/jsutils.nim')
-rw-r--r--src/js/jsutils.nim9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/js/jsutils.nim b/src/js/jsutils.nim
new file mode 100644
index 00000000..b8a8398e
--- /dev/null
+++ b/src/js/jsutils.nim
@@ -0,0 +1,9 @@
+import bindings/quickjs
+
+template toJSValueArray*(a: openArray[JSValue]): ptr UncheckedArray[JSValue] =
+  cast[ptr UncheckedArray[JSValue]](unsafeAddr a[0])
+
+# Warning: this must be a template, because we're taking the address of
+# the passed value, and Nim is pass-by-value.
+template toJSValueArray*(a: JSValue): ptr UncheckedArray[JSValue] =
+  cast[ptr UncheckedArray[JSValue]](unsafeAddr a)
revision' href='/ahoang/chawan/blame/src/ips/forkserver.nim?id=ee930b0f5a587768d340c4204cf1f2e9fb818c89'>^
d9e430c8 ^
31fbd611 ^
b96d8cc5 ^
df40fcdd ^
896489a6 ^


eb2e57c9 ^
896489a6 ^




181ea25b ^
896489a6 ^





e5d170aa ^
136d8d9e ^

896489a6 ^
e80ae4b1 ^

31fbd611 ^
b96d8cc5 ^
31fbd611 ^
136d8d9e ^

e80ae4b1 ^

896489a6 ^
d526deb9 ^


896489a6 ^
eb2e57c9 ^




896489a6 ^

aaacdc35 ^
896489a6 ^

d0c4570f ^






a02c408f ^
896489a6 ^





d0c4570f ^
896489a6 ^



58dee598 ^





4e0fd8c7 ^

2c4f1b5a ^
58dee598 ^
896489a6 ^




73c9788a ^

896489a6 ^

a02c408f ^
896489a6 ^









31fbd611 ^
c2004e4a ^


896489a6 ^
d0c4570f ^

896489a6 ^
d0c4570f ^

896489a6 ^


c2004e4a ^




181ea25b ^

a02c408f ^
58dee598 ^
c2004e4a ^
58dee598 ^



4e0fd8c7 ^

2c4f1b5a ^
58dee598 ^
c2004e4a ^

73c9788a ^

c2004e4a ^
a02c408f ^
896489a6 ^



4b482418 ^

896489a6 ^














e80ae4b1 ^

a02c408f ^


eb2e57c9 ^


5f88adcc ^
eb2e57c9 ^
896489a6 ^
4b482418 ^
896489a6 ^













181ea25b ^


896489a6 ^



181ea25b ^

896489a6 ^




d0c4570f ^
896489a6 ^
896489a6 ^
181ea25b ^



896489a6 ^

181ea25b ^

896489a6 ^

181ea25b ^
896489a6 ^
58dee598 ^
896489a6 ^


181ea25b ^

896489a6 ^



181ea25b ^
d526deb9 ^




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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243