Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.debug
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memwatch
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
core.crypto
core.crypto.keys
core.doc
core.encoding
core.encoding.base64
core.encoding.csv
core.encoding.hex
core.encoding.json
core.encoding.kdl
core.encoding.osad
core.encoding.utf8
core.encoding.xml
core.hash
core.hash.md5
core.hash.sha1
core.hash.sha256
core.heap
core.intrinsics
core.intrinsics.atomics
core.intrinsics.onyx
core.intrinsics.types
core.intrinsics.wasm
core.io
core.io.binary
core.iter
core.js
core.list
core.map
core.math
core.memory
core.misc
core.net
core.os
core.random
core.set
core.slice
core.string
core.sync
core.test
core.thread
core.time
main
runtime
runtime.info
runtime.platform
runtime.vars
simd

package core.js

ValuePool
ValuePool :: struct {
    values: [..] Value
}

To aid in managing Values that are created over the life time of the program, ValuePool collects all of the Values and allows for releasing them all at once.

Methods
ValuePool.add
ValuePool.add :: (vp: &ValuePool, v: Value) -> void
ValuePool.destroy
ValuePool.destroy :: (vp: &ValuePool) -> void
ValuePool.release_all
ValuePool.release_all :: (vp: &ValuePool) -> void
ValuePool.remove
ValuePool.remove :: (vp: &ValuePool, v: Value) -> void
Type
Type :: enum {
    Undefined :: 0
    Null :: 1
    Boolean :: 2
    Number :: 3
    String :: 4
    Symbol :: 5
    Object :: 6
    Function :: 7
}
Func
Func :: #distinct DISTINCT TYPE

Represents an Onyx function that can be called by JavaScript.

Methods
Func.from
Func.from :: (f: (Value, [] Value) -> Value) -> Func

Creates a JavaScript function that wraps an Onyx function.

Func.leak
Func.leak :: (f: Func) -> Func
Func.release
Func.release :: (f: Func) -> void
Value
Value :: #distinct u64

Used to represent a JavaScript value.

Methods
Value.as_bool
Value.as_bool :: (v: Value) -> ? bool

Converts a Value into a bool. If the value is not internally of boolean type, None is returned.

Value.as_float
Value.as_float :: (v: Value) -> ? f64

Converts a Value into a f64. If the value is not internally of float type, None is returned.

Value.as_int
Value.as_int :: (v: Value) -> ? i32

Converts a Value into a i32. If the value is not internally of float type, None is returned.

Value.as_str
Value.as_str :: (v: Value) -> ? [] u8

Converts a Value into a str. If the value is not internally of str type, None is returned.

Note that this function returns a string that is allocated on the heap. The caller is responsible for managing the returned string.

Value.call
Value.call :: (v: Value, method: [] u8, args: [] any) -> Value
Value.call :: (v: Value, method: [] u8, args: ..any) -> Value
Value.copy_to_js
Value.copy_to_js :: (v: Value, buf: [] u8) -> i32

Copies data into a Uint8Array in JS from a buffer in Onyx. Returns the number of bytes copied, or -1 if the value was not a Uint8Array.

Value.copy_to_onyx
Value.copy_to_onyx :: (v: Value, buf: [] u8) -> i32

Copies data from a Uint8Array in JS to a buffer in Onyx. Returns the number of bytes copied, or -1 if the value was not a Uint8Array.

Value.delete
Value.delete :: (v: Value, property: [] u8) -> void

Invokes the JavaScript delete operator on the specified property.

Value.equals
Value.equals :: (v1: Value, v2: Value) -> bool
Value.from
Value.from :: (m: Map(str, $V)) -> ? Value
Value.from :: (a: any) -> ? Value
Value.get
Value.get :: (v: Value, prop: [] u8) -> Value

Retrieves the evaluation of vprop] in JavaScript.

Value.index
Value.index :: (v: Value, i: i32) -> Value

Retrieves the evaluation of vi] in JavaScript.

Value.instance_of
Value.instance_of :: (v: Value, base: Value) -> bool

Returns the evaluation of the instanceof operator in JavaScript.

Value.invoke
Value.invoke :: (v: Value, args: ..any) -> Value
Value.invoke :: (v: Value, args: ..any) -> Value
Value.is_nan
Value.is_nan :: (v: Value) -> bool
Value.is_null
Value.is_null :: (v: Value) -> bool
Value.is_undefined
Value.is_undefined :: (v: Value) -> bool
Value.leak
Value.leak :: (v: Value) -> Value

Removes the Value from current ValuePool. This means that the Value will not be automatically collected, and must be released with Value.release.

Value.length
Value.length :: (v: Value) -> i32

Special case for ->get("length"). Because it is required so often, this optimization is quite nice.

Value.new
Value.new :: (v: Value, args: ..any) -> Value

Invokes the new operator on the Value, with arguments args.

Value.new_array
Value.new_array :: () -> Value

Creates a new JavaScript array and returns the Value handle to it.

Value.new_object
Value.new_object :: () -> Value

Creates a new JavaScript object and returns the Value handle to it.

Value.release
Value.release :: (v: Value) -> void

Releases the Value from the JavaScript heap. The Value should not be used after this method is called.

Value.set
Value.set :: (v: Value, prop: [] u8, value: Value) -> void
Value.set :: (v: Value, prop: str, value: $T) -> void
Value.set :: (v: Value, index: i32, value: Value) -> void
Value.set :: (v: Value, index: i32, value: $T) -> void
Value.truthy
Value.truthy :: (v: Value) -> bool

JavaScript defines a "falsesy" value as undefined, null, false, 0, and "". All other values are "truthy".

Value.type
Value.type :: (v: Value) -> Type

Returns the internal type of the Value.

get_pool
get_pool :: () -> &ValuePool

Gets the current ValuePool in use.

release_pooled_objects
release_pooled_objects :: () -> void

Releases all objects in the current ValuePool.

set_pool
set_pool :: (vp: &ValuePool) -> void

Sets the ValuePool to use.

setup_default_pool
setup_default_pool :: () -> void

Creates a new ValuePool and uses it. The old ValuePool is forgotten.

temp_pool
temp_pool :: macro (body: Code) -> u32
temp_pool :: macro () -> void

Helper macro to create a ValuePool that is scoped to a block.