Summary

Adapt SPOCK runtime for more JS engines

Metadata

Description

Currently the environment assumes either a browser or node.js for output primitives that perform I/O with the console, but the ecosystem of J engines has grown, so we need to accomodate other implementations.

> Thanks! I found the line in
> /usr/share/chicken/spock/spock-runtime.js
> and replaced
> SPOCK.log = console.log; // Node.JS
> with
> SPOCK.log = function() {
> process.stdout.write(Array.from(arguments).join("")) };
>
> There are similar replacements to be made in
> spock-runtime[-min/debug/debug-min].js,

(reported by Nathan Thern)

siiky contributed this information:

> Is there a way to detect whether we run on node?

There doesn't seem to be any _one_ reliable way to determine the JS engine, but there are heuristics:

The following should work well enough if you don't define these variables yourself[9][10]:

if (typeof window !== 'undefined') {

 // probably web browser

} else if (typeof process !== 'undefined' && process.versions.node) { // or `process.release.name === 'node'`

 // probably Node.js/Deno

} else if (typeof process !== 'undefined' && process.versions.bun) {

 // probably Bun

}

[0] https://developer.mozilla.org/en-US/docs/Web/API/Window [1] https://nodejs.org/docs/latest-v22.x/api/globals.html#process [2] https://docs.deno.com/runtime/fundamentals/node/ [3] https://nodejs.org/docs/latest-v22.x/api/process.html#processrelease [4] https://docs.deno.com/api/node/process/~/Process.release [5] https://nodejs.org/docs/latest-v0.10.x/api/process.html#process_process_versions [6] https://nodejs.org/docs/latest-v22.x/api/process.html#processversions [7] https://docs.deno.com/api/node/process/~/Process.versions [8] https://github.com/oven-sh/bun/blob/4760d78b325b62ee62d6e47b7e8b29e58099bf4a/docs/guides/util/detect-bun.mdx [9] https://stackoverflow.com/a/4224668 [10] https://stackoverflow.com/a/35813135