javascript

Standard Library documentation

Evaluate JavaScript from ZuzuScript.

Module

Name
javascript
Area
Standard Library
Source
modules/javascript.zzm

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

  • JS

    Runtime-supported JavaScript bridge class.

    • JS.eval(String code)

      Parameters: code is JavaScript source text. Returns: JSResult. Evaluates code in the host JavaScript runtime.

  • JSResult

    Wrapper for a JavaScript value returned by JS.eval() or JSResult.eval().

    • result.eval(String code)

      Parameters: code is JavaScript source text. Returns: JSResult. Evaluates code with the wrapped JavaScript value bound to this.

    • result.isSafe()

      Parameters: none. Returns: Boolean. Returns true when value() 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.