about summary refs log tree commit diff stats
path: root/lib/monoucha0/monoucha/javascript.nim
Commit message (Collapse)AuthorAgeFilesLines
* javascript: clean up getMemoryUsagebptato2025-05-071-26/+29
|
* jserror: simplify custom error creationbptato2025-03-291-9/+7
| | | | | | | The old API was needlessly complex and suggested that it could only be used for DOMException (which is not the case). (Also optimized out code lookup from the DOMException constructor.)
* Re-add JSValueConstbptato2025-03-121-29/+34
| | | | | | | | | This time, I've also ported over the consistency check to prevent some ownership bugs. Unfortunately, the check is very limited, and it is still possible to double-free or leak JSValues. I think it would be possible to make coverage 100%, but only with ARC...
* javascript: simplify a bitbptato2025-03-111-6/+3
|
* tojs: misc cleanupbptato2025-03-071-7/+9
| | | | | | | * optimize toJS set * change defineProperty wrappers to return an enum If we're going to wrap defineProperty, then let's do it properly.
* javascript: remove ishtmldda from registerTypebptato2025-03-061-7/+5
| | | | | | | It's simpler and more efficient to handle this in the DOM. (The interface was also confusing/broken in that it only really accepted one htmldda class.)
* javascript: generate gc_mark functionsbptato2025-03-061-11/+41
| | | | | Not having them is a bad omen; I think the only reason this hasn't caused an issue yet is that only a few types embed JSValues.
* javascript: fix finalizers with non-RootRef derived objectsbptato2025-02-201-2/+2
| | | | | | We were calling the wrong getTypePtr. Also, fix some manual tests.
* fromjs, javascript: optimize out class name registrybptato2025-02-191-18/+3
| | | | | | | | Instead of hashing the class name for isInstanceOf, we now just reuse the Nim type pointer -> JSClassID map, which should be more efficient. This removes getClass and hasClass; these can be replaced by just reusing the class ID returned from registerType.
* javascript: fix multiple registerType statements on same typebptato2025-02-151-2/+2
| | | | Fixes setTimeout etc. not working on client.
* javascript: small cleanupbptato2025-02-081-115/+95
|
* javascript: remove fromJSThis error messagesbptato2025-02-081-25/+23
| | | | fromJS is enough
* javascript, jsopaque: call finalizers without corresponding JSValuebptato2025-02-051-14/+22
| | | | | | | | | | | | Previously, nim_finalize_for_js only called a finalizer if the opaque Nim object already had a corresponding JSValue. This was probably an oversight (at least I had no idea this worked this way), so now we always call the finalizer. The upshot is that this means that finalizers can now receive a nil runtime in this case, so finalizers not prepared for this might break. The solution is to either explicitly nil-check the runtime, or to ensure that such objects always get converted to a JSValue first.
* javascript: derive ctor functions from parent ctor functionsbptato2025-02-021-3/+9
| | | | no idea why JS_NewCFunction3 is not public...
* javascript: inline makeCtorJSCallAndRetbptato2025-02-021-10/+5
|
* javascript, tojs: fix an ownership bugbptato2025-01-311-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was breaking acid3 - occasionally. Fun times! The bug occurred in a case where a Nim object failed to transfer ownership to JS when 1. Nim object created 2. Nim drops reference, but JS keeps it 3. JS drops reference, but Nim keeps it (because of another Nim object holding onto it) 4. JS acquires reference, Nim drops it because in 4, JS got two references (per toJS behavior), and Nim didn't get any. The actual acid3 test, reduced: L1 d = document.createTextNode("iteration " + i + " at " + d); Text JS1 -> Nim1 Anchor 0 L2 document.createElement('a') Text JS1 -> Nim1 Anchor JS1 -> Nim1 L3 .appendChild(d); Text JS1 -> Nim2 Anchor JS1 <- Nim1 <-> Nim1 L4 d = d.parentNode; Text JS1 <- Nim1 Anchor JS2 -> Nim1 <-> Nim1 ^^^ bug! After this patch, the last line looks like Anchor JS1 -> Nim2 <-> Nim1 (I haven't been able to reduce the bug to a test case that doesn't have to run for seconds :/ triggering the GC manually doesn't cut it for some reason.) As noted in the comments, the implementation isn't optimal. I've described a hack there that could be used to increase performance; we'll see if it's actually needed.
* javascript: fix .jsget on JSValuebptato2025-01-281-5/+10
| | | | | | | | | | | | | | Since toJS doesn't create a new value, `node' must be dup'd if it is a JSValue. Also, forbid .jsset on JSValue as it was broken as well and it's not obvious what the intention is when using it. (Probably it should free the old value, but did the user think of setting it? :P) I can see why I made toJS not dup the value - to make returning consistent with Nim's semantics - but it really makes things confusing... implicitly behaving as lent might be better, albeit less convenient.
* javascript: clean up & optimizebptato2025-01-221-307/+217
| | | | welp, it doesn't really seem to make things faster...
* javascript: allow sink parametersbptato2025-01-221-0/+3
|
* javascript: add .jsrget, .jsrfgetbptato2025-01-221-53/+125
| | | | Implements the [Replaceable] WebIDL property.
* Add 'lib/monoucha0/' from commit '33efaee783c2adb20df019a8bc924411c4a97e7f'bptato2025-01-181-0/+1590
git-subtree-dir: lib/monoucha0 git-subtree-mainline: b56abad0883c0b4179f9c329a7169bb544fac4a5 git-subtree-split: 33efaee783c2adb20df019a8bc924411c4a97e7f