diff options
author | bptato <nincsnevem662@gmail.com> | 2024-05-03 01:41:38 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-05-03 01:58:12 +0200 |
commit | 970378356d0d7239b332baa37470455391b5e6e4 (patch) | |
tree | 87d93162295b12652137193982c5b3c88e1a3758 /test | |
parent | c48f2caedabbcda03724c43935f4175aac3ecf90 (diff) | |
download | chawan-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 'test')
-rw-r--r-- | test/js/class.html | 30 | ||||
-rw-r--r-- | test/js/encode_decode.html | 57 |
2 files changed, 37 insertions, 50 deletions
diff --git a/test/js/class.html b/test/js/class.html index 7c14049e..5ee2f869 100644 --- a/test/js/class.html +++ b/test/js/class.html @@ -1,23 +1,17 @@ <!doctype html> <title>Element class test</title> <div class="a b c">Fail</div> +<script src=asserts.js></script> <script> -(function() { - let div = document.getElementsByClassName("a")[0] - const classes = ["a", "b", "c"]; - let cl = div.classList; - for (let i = 0; i < classes.length; ++i) { - if (cl[i] !== classes[i]) - return; - } - const classes2 = ["x", "y", "z"]; - div.setAttribute("class", classes2.join(' ')); - let i = 0; - for (let x of cl) { - if (x != classes2[i]) - return; - ++i; - } - div.textContent = "Success"; -})(); +const div = document.getElementsByClassName("a")[0] +const classes = ["a", "b", "c"]; +let cl = div.classList; +for (let i = 0; i < classes.length; ++i) + assert_equals(cl[i], classes[i]); +const classes2 = ["x", "y", "z"]; +div.setAttribute("class", classes2.join(' ')); +let i = 0; +for (let x of cl) + assert_equals(x, classes2[i++]); +div.textContent = "Success"; </script> diff --git a/test/js/encode_decode.html b/test/js/encode_decode.html index 069ddc72..82e9676c 100644 --- a/test/js/encode_decode.html +++ b/test/js/encode_decode.html @@ -1,39 +1,32 @@ <!doctype html> <title>TextEncoder/TextDecoder test</title> <div id="success">Fail</div> +<script src=asserts.js></script> <script> -(function() { - /* Adapted from: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem */ - function base64ToBytes(base64) { - const binString = atob(base64); - const result = []; - for (const c of binString) - result.push(Uint8Array.from(c, (m) => m.codePointAt(0))); - return result; - } +/* Adapted from: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem */ +function base64ToBytes(base64) { + const binString = atob(base64); + const result = []; + for (const c of binString) + result.push(Uint8Array.from(c, (m) => m.codePointAt(0))); + return result; +} - function bytesToBase64(bytes) { - const binString = String.fromCodePoint(...bytes); - return btoa(binString); - } +function bytesToBase64(bytes) { + const binString = String.fromCodePoint(...bytes); + return btoa(binString); +} - const utf8 = new TextEncoder().encode("a Ā 𐀀 文 🦄") - const b64utf8 = bytesToBase64(utf8); - if (b64utf8 !== "YSDEgCDwkICAIOaWhyDwn6aE") { - console.log(b64utf8); - return; - } - const dec = new TextDecoder(); - const bytes = base64ToBytes(b64utf8); - const a = []; - let res = ""; - for (const c of bytes) - res += dec.decode(c, {stream: true}); - res += dec.decode(); - if (res !== "a Ā 𐀀 文 🦄") { - console.log(res); - return; - } - document.getElementById("success").textContent = "Success"; -})(); +const utf8 = new TextEncoder().encode("a Ā 𐀀 文 🦄") +const b64utf8 = bytesToBase64(utf8); +assert_equals(b64utf8, "YSDEgCDwkICAIOaWhyDwn6aE") +const dec = new TextDecoder(); +const bytes = base64ToBytes(b64utf8); +const a = []; +let res = ""; +for (const c of bytes) + res += dec.decode(c, {stream: true}); +res += dec.decode(); +assert_equals(res, "a Ā 𐀀 文 🦄"); +document.getElementById("success").textContent = "Success"; </script> |