crow/js.crow (source)

Contains functions for JavaScript primitive operations.

Functions here are marked 'bare' even if they may allocate; 'bare' doesn't matter in JS,
but many functions that need to be 'bare' for native code need to use these functions.

as-js[t] js-any(a t) bare, unsafe

cast[t] t(a js-any) bare, unsafe

js-global js-any() bare, unsafe

js-global js-any(name symbol) bare, unsafe

subscript js-any(a js-any, key string) bare, unsafe

a[key]

subscript js-any(a js-any, key nat64) bare, unsafe

In JavaScript, the argument to a subscript is always a string,
and array indices are implicitly converted to strings.

subscript js-any(a js-any, key float64) bare, unsafe

set-subscript[t] void(a js-any, key string, value t) bare, unsafe

a[key] = value

set-subscript[t] void(a js-any, key nat64, value t) bare, unsafe

set-subscript[t] void(a js-any, key float64, value t) bare, unsafe

call js-any(a js-any) bare, unsafe

a()
WARN: This does not 'await' the result.
WARN: 'get' followed by 'call' may not work. Use 'call-property' instead.

call[p0] js-any(a js-any, arg p0) bare, unsafe

a(arg)

call[p0, p1] js-any(a js-any, arg0 p0, arg1 p1) bare, unsafe

a(arg0, arg1)

call[p0, p1, p2] js-any(a js-any, arg0 p0, arg1 p1, arg2 p2) bare, unsafe

a(arg0, arg1, arg2)

call-new js-any(a js-any) bare, unsafe

new a()

call-new[p0] js-any(a js-any, arg p0) bare, unsafe

new a(arg)

call-new[p0, p1] js-any(a js-any, arg p0, arg1 p1) bare, unsafe

new a(arg0, arg1)

call-new[p0, p1, p2] js-any(a js-any, arg p0, arg1 p1, arg2 p2) bare, unsafe

new a(arg0, arg1, arg2)

call-property js-any(a js-any, name string) bare, unsafe

a[name]()

call-property[p0] js-any(a js-any, name string, arg p0) bare, unsafe

a[name](arg)

call-property[p0, p1] js-any(a js-any, name string, arg0 p0, arg1 p1) bare, unsafe

a[name](arg0, arg1)

call-property[p0, p1, p2] js-any(a js-any, name string, arg0 p0, arg1 p1, arg2 p2) bare, unsafe

a[name](arg0, arg1, arg2)

call-property-spread[p] js-any(a js-any, name string, args p array) bare, unsafe

a[name](...args)

js-cast[out, in] out(a in) bare, unsafe

Treat one type as another. This is a noop in JS.

This should only be done if the input value can be treated as the output type.
For example, a nat8 can be treated as a nat64 since they are both represented as BigInts
and every valid nat8 value is a valid nat64 value.

However, you should usually use a to function (such as to nat64(a nat8))
since those are safe and cross-platform.

null js-any() bare

undefined js-any() bare

await js-any(a js-any) bare, unsafe

typeof string(a js-any) bare, unsafe

== bool(a js-any, b js-any) bare, unsafe

NOTE: This is actually JavaScript's === operator.

instanceof bool(a js-any, b js-any) bare, unsafe

< bool(a js-any, b js-any) bare, unsafe

+ js-any(a js-any, b js-any) bare, unsafe

new js-any(...properties (symbol, js-any) tuple2 array) bare

Create a new JavaScript object.
("x", 1::float.as-js), ("y", "why") is like { x: 1, y: "why" } in JavaScript.

to-js-object js-any(properties (symbol, js-any) tuple2 array) bare

eval js-any(source string) bare, unsafe

Calls JavaScript's 'eval' function. 'source' should be JavaScript source code.
This could be useful for making use of JS features that don't have a Crow analog,
or if you just have a big chunk of JS code and don't have time to translate it to Crow.

This happens in its own scope, so don't count on anything being in the enclosing scope.
Instead, eval a function literal, then call it, like "x => f(x)".eval call x.
If appropriate, remember to make the function async and await the result.

js-any builtin