about summary refs log tree commit diff stats
path: root/src/js
Commit message (Collapse)AuthorAgeFilesLines
* twtstr: misc refactoringsbptato2024-10-011-1/+1
|
* timeout: accept err stream as parambptato2024-09-301-8/+6
| | | | | gets rid of a todo. (not sure why I thought this was important, but it sure looks nicer)
* Replace std/selectors with pollbptato2024-09-231-40/+73
| | | | | | | | | | | | std/selectors uses OS-specific selector APIs, which sounds good in theory (faster than poll!), but sucks for portability in practice. Sure, you can fix portability bugs, but who knows how many there are on untested platforms... poll is standard, so if it works on one computer it should work on all other ones. (I hope.) As a bonus, I rewrote the timeout API for poll, which incidentally fixes setTimeout across forks. Also, SIGWINCH should now work on all platforms (as we self-pipe instead of signalfd/kqueue magic).
* xhr: more progressbptato2024-08-151-15/+13
| | | | | | | | | | * add responseText, response * add net tests -> currently sync XHR only; should find a way to do async tests... * update monoucha -> simplified & updated some related code that no longer worked properly
* Update monouchabptato2024-08-095-41/+45
|
* cssvalues, twtstr, mediaquery: refactor & fixesbptato2024-08-021-5/+8
| | | | | | | * cssvalues, twtstr: unify enum parsing code paths, parse enums by bisearch instead of hash tables * mediaquery: refactor (long overdue), fix range comparison syntax parsing, make ident comparisons case-insensitive (as they should be)
* console, client: optimize console.log (etc.)bptato2024-07-301-16/+37
| | | | use JSValue varargs instead
* buffer, pager, config: add meta-refresh + misc fixesbptato2024-07-281-5/+15
| | | | | | | | | * buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
* timeout: simplify, misc fixesbptato2024-07-161-76/+47
| | | | | | Merge timeout & interval code paths. This fixes clearTimeout not clearing intervals.
* encoding: simplifybptato2024-07-141-66/+15
| | | | use the new API instead of the convoluted decodercore + growbuf thing
* timeout: fix jsvalue leakbptato2024-07-101-13/+27
|
* Update monouchabptato2024-06-222-2/+2
|
* misc cleanupsbptato2024-06-221-1/+1
|
* img, term: try to detect unknown images, improve kitty encoderbptato2024-06-211-8/+12
| | | | | | * preserve alpha in kitty + simplify encoder * pass unknown image types to stbi (as image/x-unknown) and let it detect the type
* img, loader: separate out png codec into cgi, misc improvementsbptato2024-06-202-3/+3
| | | | | | | | | | | | | | | * multi-processed and sandboxed PNG decoding & encoding (through local CGI) * improved request body passing (including support for output id as response body) * simplified & faster blob()/text() - now every request starts suspended, and OngoingData.buf has been replaced with loader's buffering capability * image caching: we no longer pull bitmaps from the container after every single getLines call Next steps: replace our bespoke PNG decoder with something more usable, add other decoders, and make them stream.
* Update Chame, Chagashibptato2024-06-131-56/+9
|
* Move JS wrapper into Monouchabptato2024-06-0317-3021/+29
| | | | Operation "modularize Chawan somewhat" part 3
* js: improve jsregex interfacebptato2024-06-031-16/+13
| | | | | | | It's easier to just use nested seqs here. (This also fixes reverse-search highlighting the last capture group instead of the whole match.)
* js: change jsstfunc syntaxbptato2024-06-031-2/+2
| | | | | | Interface:function -> Interface.function for consistency with regular JS syntax
* js: fix runtime cleanupbptato2024-06-031-18/+29
| | | | | | | | | | | | | | This is a minefield. Intuitively, you would think that just clearing the opaque and manually freeing registered object should be enough. Unfortunately, this is not true; we do not store whether we are actually holding a reference to registered JS objects, so this approach leads to double frees. Instead, we add a QJS callback that is called right after the final GC cleanup, but before the list_free assertion. This way, we can be sure that any object still in our registry is referenced by us, and can therefore unreference them safely.
* js: small misc changesbptato2024-06-021-13/+15
| | | | just sync'ing
* Fix GCC 14 compilationbptato2024-05-301-15/+22
| | | | | | | | TODO: find the exact flags we need instead of -fpermissive. See also: https://todo.sr.ht/~bptato/chawan/12 https://forum.nim-lang.org/t/11587
* html: improve Request, derive Client from Windowbptato2024-05-201-3/+5
| | | | | | | * make Client an instance of Window (for less special casing) * misc work on Request & fetch * improve origin comparison (opaque origins of same URLs are now considered the same)
* js: allow var instead of ptrbptato2024-05-122-26/+32
|
* fromjs: remove broken uint64 converterbptato2024-05-091-5/+0
| | | | It would silently truncate the upper 32 bits... not a very bright idea.
* js: fix compileModulebptato2024-05-082-2/+2
|
* js: clean up eval wrappersbptato2024-05-081-6/+4
|
* js: fix finalizer effectsbptato2024-05-081-1/+2
|
* js: refactorbptato2024-05-0813-137/+43
| | | | | | | * prefix to-be-separated modules with js * remove dynstreams dependency * untangle from EmptyPromise * move typeptr into tojs
* js: fix compilation on 1.6.14bptato2024-05-062-4/+3
| | | | | | | | | * resolve empty promises without params, not a single undefined param (we can't just unsafeAddr constants on 1.6.14, and I don't see why we need to pass undefined?) * same in client with InternalError * explicitly convert static `asglobal' to bool (1.6.14 turns unquoted enums into ints...)
* color: separate out JS convertersbptato2024-05-051-0/+46
| | | | | ansi2html depends on color, but we definitely do not want to link it to QJS, so the converters must be moved into a separate module.
* Use isSome instead of isOkbptato2024-05-052-22/+17
| | | | no point in having identical overloads
* js: move fromJS_or_return nil check to JSError toJSbptato2024-05-042-7/+4
|
* client: make quit() actually quit, misc fixesbptato2024-05-044-56/+37
| | | | | | | * unwind the QJS stack with an uncatchable exception when quit is called * clean up JS references in JSRuntime free even when the Nim counterparts are still alive * simplify some tests
* js: fix various leaks etc.bptato2024-05-037-163/+188
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* cssparser: refactorbptato2024-05-011-2/+0
| | | | | | | | | * factor out skipWhitespace * remove streams dependency (cssparser could never stream without blocking the event loop, so we were just passing a StringStream in all cases, which made the whole streaming pointless.)
* Remove unnecessary unsigned castsbptato2024-04-261-1/+1
| | | | | Unsigned operations and conversions to unsigned types always wrap/narrow without checks, so no need to manually mask/cast/etc. them.
* data: replace std/base64 with atobbptato2024-04-251-64/+4
| | | | | | | | | | std's version is known to be broken on versions we still support, and it makes no sense to use different decoders anyway. (This does introduce a bit of a dependency hell, because js/base64 depends on js/javascript which tries to bring in the entire QuickJS runtime. So we move that out into twtstr, and manually convert a Result[string, string] to DOMException in js/base64.)
* js: fix some incorrect defineProperty usagebptato2024-04-212-3/+2
| | | | It consumes a value, so we must dup those that we pass.
* js: override default toString tag of globalbptato2024-04-211-1/+5
| | | | Some JS modules use this to check if they are running in a browser.
* base64: rewrite btoa toobptato2024-04-211-3/+39
| | | | why not
* base64: rewrite atobbptato2024-04-211-6/+65
| | | | | | | | | Turns out std/base64's `decode' is broken: atob(" ") would panic. So we no longer use that. Basic testing indicates that the new version is closer to the standard- mandated behavior than the old one was. OTOH I assume it's somewhat slower, but that can be improved later if it proves to be a bottleneck.
* Update code stylebptato2024-04-1711-256/+273
| | | | | | * separate params with ; (semicolon) instead of , (colon) * reduce screaming snake case use * wrap long lines
* js: remove automatic function -> closure conversionbptato2024-04-153-68/+24
| | | | | | | | | | | | | | | It's a bad idea for several reasons: * it's inefficient; must allocate an environment for a closure in Nim, even though we already have one in JS * writing macros for automatically creating functions with variadic arguments is suprisingly difficult (see the entire `js/javascript' module) * it never really worked properly, because we never freed the associated function pointer. We hardly used it anyway, so the easiest fix is to get rid of it completely.
* remove dead code, fix openArray casingbptato2024-04-081-2/+2
|
* js: proper distinction between Opt/Optionbptato2024-03-243-38/+19
| | | | | | | | | | | | | | | | until now, this had very strange (and inconsistent) semantics: * err() was used for exception propagation, but also as a null value * Option accepted undefined as a none value, but not null * Opt and Option were used interchangeably (and mostly randomly) Now, Result is always used for error reporting, and err(nil) means JS_EXCEPTION. (Opt is a special case of Result where we don't care about the error type, and is not used in JS.) Option on the other hand means "nullable variation of normally non-nullable type", and translates to JS_NULL. In JS we mainly use it for turning strings nullable.
* io: derive DynStream from RootObj (not Stream)bptato2024-03-243-17/+16
| | | | | | | | This way they are no longer compatible, but we no longer need them to be compatible anyway. (This also forces us to throw out the old serialize module, and use packet writers everywhere.)
* config: clean up/simplifybptato2024-03-171-4/+6
| | | | | | | | | * Parse the default config at runtime. There's no significant performance difference, but this makes it much less painful to write config code. * Add better error reporting * Make fromJS2 easier to use * Unquote ChaPaths while parsing config
* man: rewrite in Nimbptato2024-03-131-21/+22
| | | | | | | | | | | | Depending on Perl just for this is silly. Now we use libregexp for filtering basically the same things as w3mman2html did. This required another patch to QuickJS to avoid pulling in the entire JS engine, but in return, we can now run regexes without a dummy JS context global variable. Also, man.nim now tries to find a man command on the system even if it's not in /usr/bin/man.
* loader: rework process modelbptato2024-03-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally we had several loader processes so that the loader did not need asynchronity for loading several buffers at once. Since then, the scope of what loader does has been reduced significantly, and with that loader has become mostly asynchronous. This patch finishes the above work as follows: * We only fork a single loader process for the browser. It is a waste of resources to do otherwise, and would have made future work on a download manager very difficult. * loader becomes (almost) fully async. Now the only sync part is a) processing commands and b) waiting for clients to consume responses. b) is a bit more problematic than a), but should not cause problems unless some other horrible bug exists in a client. (TODO: make it fully async.) This gives us a noticable improvement in CSS loading speed, since all resources can now be queried at once (even before the previous ones are connected). * Buffers now only get processes when the *connection* is finished. So headers, status code, etc. are handled by the client, and the buffer is forked when the loader starts streaming the response body. As a result, mailcap entries can simply dup2 the first UNIX domain socket connection as their stdin. This allows us to remove the ugly (and slow) `canredir' hack, which required us to send file handles on a tour accross the entire codebase. * The "cache" has been reworked somewhat: - Since canredir is gone, buffer-level requests usually start in a suspended state, and are explicitly resumed only after the client could decide whether it wants to cache the response. - Instead of a flag on Request and the URL as the cache key, we now use a global counter and the special `cache:' scheme. * misc fixes: referer_from is now actually respected by buffers (not just the pager), load info display should work slightly better, etc.