diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-15 22:09:32 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-15 22:13:51 +0200 |
commit | 0d8ebdce2897244d8297eecd175441e541292b94 (patch) | |
tree | 8331642e3a2163530651801c21556ef39c8ecdaa /src/js/jstypes.nim | |
parent | 8df9ef9cbbd284afac4d26494d45253a43aa3146 (diff) | |
download | chawan-0d8ebdce2897244d8297eecd175441e541292b94.tar.gz |
js: remove automatic function -> closure conversion
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.
Diffstat (limited to 'src/js/jstypes.nim')
-rw-r--r-- | src/js/jstypes.nim | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/js/jstypes.nim b/src/js/jstypes.nim index 5336f067..9e1d72ea 100644 --- a/src/js/jstypes.nim +++ b/src/js/jstypes.nim @@ -33,3 +33,11 @@ type func high*(abuf: JSArrayBuffer): int = return int(abuf.len) - 1 + +# A specialization of JSValue to make writing generic code for functions +# easier. +type JSValueFunction* = ref object + fun*: JSValue + +converter toJSValue*(f: JSValueFunction): JSValue = + f.fun |