NAME
javascript - Evaluate JavaScript from ZuzuScript.
SYNOPSIS
from javascript import JS, JSResult;
let r := JS.eval("[ 7, 8, 9 ]");
assert( r instanceof JSResult );
let j := r.toJSON();
let r2 := r.eval(" this[1] ");
assert( r2 instanceof JSResult );
let n;
n := r2.value() if r2.isSafe();
IMPLEMENTATION SUPPORT
This module is supported by zuzu-js on Node, Electron, and Browser. It is not supported by zuzu.pl or zuzu-rust.
DESCRIPTION
This runtime-supported module is only implemented by zuzu-js.
JS.eval(String code) evaluates JavaScript and returns JSResult.
JSResult.eval(String code) evaluates more JavaScript with the wrapped value bound to this, again returning JSResult.
JSResult.isSafe() reports whether value() can convert the wrapped JavaScript value into a native Zuzu value.
JSResult.value() returns the converted Zuzu value for safe results.
JSResult.toJSON() serializes the wrapped JavaScript value as JSON.
EXPORTS
Classes
JSRuntime-supported JavaScript bridge class.
JS.eval(String code)Parameters:
codeis JavaScript source text. Returns:JSResult. Evaluatescodein the host JavaScript runtime.
JSResultWrapper for a JavaScript value returned by
JS.eval()orJSResult.eval().result.eval(String code)Parameters:
codeis JavaScript source text. Returns:JSResult. Evaluatescodewith the wrapped JavaScript value bound tothis.result.isSafe()Parameters: none. Returns:
Boolean. Returns true whenvalue()can convert the wrapped JavaScript value into a native ZuzuScript value.result.value()Parameters: none. Returns: value. Converts and returns the wrapped JavaScript value when
isSafe()is true.result.toJSON()Parameters: none. Returns:
String. Serializes the wrapped JavaScript value as JSON text.
COPYRIGHT AND LICENCE
javascript is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.