about summary refs log tree commit diff stats
path: root/src/js
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* quickjs: reduce diff with upstreambptato2024-03-022-6/+8
| | | | | | * the uint8array thing is probably from txiki.js, but we never used it * upstream now has JS_GetClassID, importing that instead... (so this commit won't build :/)
* dom: add onload content attribute to bodybptato2024-02-243-3/+26
|
* dom: print parse errors to consolebptato2024-02-241-6/+8
| | | | instead of trying to evaluate exceptions...
* Replace Chakasu with Chagashibptato2024-02-222-53/+147
| | | | | | The API is horrid :( but at least it copies less. TODO: think of a better API.
* regex: compileSearchRegex improvementsbptato2024-02-181-9/+7
| | | | | * do not eat \\c, \\C * emulate vi-style word boundary matching (\<, \>) with \b
* regex: re-work compileSearchRegexbptato2024-02-175-65/+62
| | | | | | | I've gotten tired of not being able to search for forward slashes. Now it works like in vim, and you can also set default ignore case in the config.
* js: fix fromJSEnumbptato2024-02-082-6/+17
| | | | std enum parsing uses Nim ident matching rules, which is incorrect here.
* regex: fix 8-bit narrow strings in JSbptato2024-02-051-1/+1
| | | | | The previous approach to add UTF-8 support to libregexp was broken. This time, we use a separate flag (cbuf_len == 3) to indicate UTF-8 input.
* js: always use var destructorbptato2024-01-291-8/+2
| | | | See https://forum.nim-lang.org/t/10807
* js: update pragma docsbptato2024-01-241-3/+9
|
* js: define toStringTag properlybptato2024-01-242-3/+12
|
* js: allow specifying static function name, small refactoringbptato2024-01-241-58/+60
| | | | | | | | * static function names can now be defined using the syntax `Class:functionName' (or just use `Class' to take the default name * fix URL.canParse with 1 argument only * do not store JSFuncGenerator for constructors; just put the function node in BoundFunctions
* js: small improvementsbptato2024-01-172-21/+53
| | | | | * turn JSFuncGenerator into a ref object (it's faster this way) * remove strformat dependency
* Use errDOMException template everywherebptato2024-01-111-4/+4
|
* js: merge some type modules into jstypesbptato2024-01-119-44/+45
| | | | They only had type definitions, no need to put them in separate modules.
* js: use Nim allocatorbptato2024-01-081-1/+19
|
* Use std/* imports everywherebptato2024-01-076-19/+19
|
* tojs: document + remove unused JSCFunction converterbptato2024-01-071-7/+41
|
* Fix some casing issuesbptato2024-01-061-4/+4
|
* Compile with styleCheck:usagesbptato2023-12-283-3/+3
| | | | much better
* dom: use JS_EvalFunction; add module fetching stubsbptato2023-12-251-0/+7
| | | | (still no module support in buffer...)
* bindings/quickjs: cint -> csize_tbptato2023-12-231-2/+3
| | | | | | cint was incorrect :/ Makes me wonder if maybe we should just use futhark after all...
* js: fix nil deref in jsgetpropbptato2023-12-201-4/+9
| | | | Turns out desc can in fact be nil.
* pager: add marksbptato2023-12-091-0/+15
| | | | | Default is vi-style, but w3m-style marks work as well; see bonus/w3m.toml.
* event: remove ctx from CustomEventbptato2023-12-032-23/+38
| | | | | Instead, make finalizers optionally pass their runtime for resource deallocation.
* pager, container: add text selection/copyingbptato2023-12-032-0/+26
| | | | | | | | | | * Add select & copy selection functionality to container * Fix bug in generateSwapOutput where output could be misplaced because of zero-width cells * Add fromJSPromise, call runJSJobs in every iteration of the headed event loop * "await" pager actions that output a promise * Change default view source keybinding to `\'
* Get rid of clang 16 workaroundbptato2023-12-021-2/+3
| | | | | * bindings/quickjs: importc and use correct pointer types * add constcharp module for when it is unavoidable
* js: get rid of emitbptato2023-12-021-22/+15
| | | | now I know how to :P
* js: get rid of getJSValuebptato2023-12-021-10/+9
| | | | just use an UncheckedArray in the binding
* html: add HTMLElement.dataset (+ some twtstr cleanup)bptato2023-12-011-6/+14
|
* js: simplify toJSP0bptato2023-11-302-31/+11
| | | | | | | * Expose js_create_from_ctor from QuickJS and directly use that (instead of badly recreating it) * Do not call defineUnforgeable twice (it is inevitably called in toJSP0, so jsctor does not need it)
* js: allow subclassing platform objects in JSbptato2023-11-303-5/+50
|
* intl: stub out Intl.PluralRulesbptato2023-11-302-0/+26
|
* js: remove nonsensical comment linebptato2023-11-261-1/+0
|
* fromjs: fix fromJSOption with nilbptato2023-11-211-1/+1
| | | | Use option() instead of some()
* js: refine isInstanceOf check in functionsbptato2023-10-253-13/+30
| | | | Special case the global object, check for inheritance, etc.