forked from cory/tildefriends
Merge branches/quickjs to trunk. This is the way.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3621 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
435
deps/quickjs/doc/quickjs.html
vendored
435
deps/quickjs/doc/quickjs.html
vendored
@ -1,8 +1,7 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
|
||||
<!-- Created by GNU Texinfo 6.1, http://www.gnu.org/software/texinfo/ -->
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>QuickJS Javascript Engine</title>
|
||||
|
||||
<meta name="description" content="QuickJS Javascript Engine">
|
||||
@ -10,6 +9,7 @@
|
||||
<meta name="resource-type" content="document">
|
||||
<meta name="distribution" content="global">
|
||||
<meta name="Generator" content="makeinfo">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link href="#SEC_Contents" rel="contents" title="Table of Contents">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
@ -72,11 +72,10 @@ ul.no-bullet {list-style: none}
|
||||
<ul class="no-bullet">
|
||||
<li><a name="toc-Language-support" href="#Language-support">3.1 Language support</a>
|
||||
<ul class="no-bullet">
|
||||
<li><a name="toc-ES2019-support" href="#ES2019-support">3.1.1 ES2019 support</a></li>
|
||||
<li><a name="toc-JSON" href="#JSON">3.1.2 JSON</a></li>
|
||||
<li><a name="toc-ECMA402" href="#ECMA402">3.1.3 ECMA402</a></li>
|
||||
<li><a name="toc-Extensions" href="#Extensions">3.1.4 Extensions</a></li>
|
||||
<li><a name="toc-Mathematical-extensions" href="#Mathematical-extensions">3.1.5 Mathematical extensions</a></li>
|
||||
<li><a name="toc-ES2020-support" href="#ES2020-support">3.1.1 ES2020 support</a></li>
|
||||
<li><a name="toc-ECMA402" href="#ECMA402">3.1.2 ECMA402</a></li>
|
||||
<li><a name="toc-Extensions" href="#Extensions">3.1.3 Extensions</a></li>
|
||||
<li><a name="toc-Mathematical-extensions" href="#Mathematical-extensions">3.1.4 Mathematical extensions</a></li>
|
||||
</ul></li>
|
||||
<li><a name="toc-Modules" href="#Modules">3.2 Modules</a></li>
|
||||
<li><a name="toc-Standard-library" href="#Standard-library">3.3 Standard library</a>
|
||||
@ -118,7 +117,7 @@ ul.no-bullet {list-style: none}
|
||||
</ul></li>
|
||||
<li><a name="toc-RegExp" href="#RegExp">4.4 RegExp</a></li>
|
||||
<li><a name="toc-Unicode" href="#Unicode">4.5 Unicode</a></li>
|
||||
<li><a name="toc-BigInt-and-BigFloat" href="#BigInt-and-BigFloat">4.6 BigInt and BigFloat</a></li>
|
||||
<li><a name="toc-BigInt_002c-BigFloat_002c-BigDecimal" href="#BigInt_002c-BigFloat_002c-BigDecimal">4.6 BigInt, BigFloat, BigDecimal</a></li>
|
||||
</ul></li>
|
||||
<li><a name="toc-License" href="#License">5 License</a></li>
|
||||
|
||||
@ -130,34 +129,34 @@ ul.no-bullet {list-style: none}
|
||||
<h2 class="chapter">1 Introduction</h2>
|
||||
|
||||
<p>QuickJS is a small and embeddable Javascript engine. It supports the
|
||||
ES2019 specification
|
||||
ES2020 specification
|
||||
<a name="DOCF1" href="#FOOT1"><sup>1</sup></a>
|
||||
including modules, asynchronous generators and proxies.
|
||||
including modules, asynchronous generators, proxies and BigInt.
|
||||
</p>
|
||||
<p>It optionally supports mathematical extensions such as big integers
|
||||
(BigInt), big floating point numbers (BigFloat) and operator
|
||||
overloading.
|
||||
<p>It supports mathematical extensions such as big decimal float float
|
||||
numbers (BigDecimal), big binary floating point numbers (BigFloat),
|
||||
and operator overloading.
|
||||
</p>
|
||||
<a name="Main-Features"></a>
|
||||
<h3 class="section">1.1 Main Features</h3>
|
||||
|
||||
<ul>
|
||||
<li> Small and easily embeddable: just a few C files, no external dependency, 180 KiB of x86 code for a simple “hello world” program.
|
||||
<li> Small and easily embeddable: just a few C files, no external dependency, 210 KiB of x86 code for a simple “hello world” program.
|
||||
|
||||
</li><li> Fast interpreter with very low startup time: runs the 69000 tests of the ECMAScript Test Suite<a name="DOCF2" href="#FOOT2"><sup>2</sup></a> in about 95 seconds on a single core of a desktop PC. The complete life cycle of a runtime instance completes in less than 300 microseconds.
|
||||
|
||||
</li><li> Almost complete ES2019 support including modules, asynchronous
|
||||
</li><li> Almost complete ES2020 support including modules, asynchronous
|
||||
generators and full Annex B support (legacy web compatibility). Many
|
||||
features from the upcoming ES2020 specification
|
||||
features from the upcoming ES2021 specification
|
||||
<a name="DOCF3" href="#FOOT3"><sup>3</sup></a> are also supported.
|
||||
|
||||
</li><li> Passes nearly 100% of the ECMAScript Test Suite tests when selecting the ES2019 features.
|
||||
</li><li> Passes nearly 100% of the ECMAScript Test Suite tests when selecting the ES2020 features.
|
||||
|
||||
</li><li> Can compile Javascript sources to executables with no external dependency.
|
||||
</li><li> Compile Javascript sources to executables with no external dependency.
|
||||
|
||||
</li><li> Garbage collection using reference counting (to reduce memory usage and have deterministic behavior) with cycle removal.
|
||||
|
||||
</li><li> Mathematical extensions: BigInt, BigFloat, operator overloading, bigint mode, math mode.
|
||||
</li><li> Mathematical extensions: BigDecimal, BigFloat, operator overloading, bigint mode, math mode.
|
||||
|
||||
</li><li> Command line interpreter with contextual colorization and completion implemented in Javascript.
|
||||
|
||||
@ -200,29 +199,13 @@ Javascript files and/or expressions as arguments to execute them:
|
||||
|
||||
<p>generates a <code>hello</code> executable with no external dependency.
|
||||
</p>
|
||||
<p><code>qjsbn</code> and <code>qjscbn</code> are the corresponding interpreter and
|
||||
compiler with the mathematical extensions:
|
||||
</p>
|
||||
<div class="example">
|
||||
<pre class="example">./qjsbn examples/pi.js 1000
|
||||
</pre></div>
|
||||
|
||||
<p>displays 1000 digits of PI.
|
||||
</p>
|
||||
<div class="example">
|
||||
<pre class="example">./qjsbnc -o pi examples/pi.js
|
||||
./pi 1000
|
||||
</pre></div>
|
||||
|
||||
<p>compiles and executes the PI program.
|
||||
</p>
|
||||
<a name="Command-line-options"></a>
|
||||
<h3 class="section">2.3 Command line options</h3>
|
||||
|
||||
<a name="qjs-interpreter"></a>
|
||||
<h4 class="subsection">2.3.1 <code>qjs</code> interpreter</h4>
|
||||
|
||||
<pre class="verbatim">usage: qjs [options] [files]
|
||||
<pre class="verbatim">usage: qjs [options] [file [args]]
|
||||
</pre>
|
||||
<p>Options are:
|
||||
</p><dl compact="compact">
|
||||
@ -243,18 +226,35 @@ compiler with the mathematical extensions:
|
||||
</dd>
|
||||
<dt><code>-m</code></dt>
|
||||
<dt><code>--module</code></dt>
|
||||
<dd><p>Load as ES6 module (default=autodetect).
|
||||
<dd><p>Load as ES6 module (default=autodetect). A module is autodetected if
|
||||
the filename extension is <code>.mjs</code> or if the first keyword of the
|
||||
source is <code>import</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>--script</code></dt>
|
||||
<dd><p>Load as ES6 script (default=autodetect).
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>--bignum</code></dt>
|
||||
<dd><p>Enable the bignum extensions: BigDecimal object, BigFloat object and
|
||||
the <code>"use math"</code> directive.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>-I file</code></dt>
|
||||
<dt><code>--include file</code></dt>
|
||||
<dd><p>Include an additional file.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<p>Advanced options are:
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>--std</code></dt>
|
||||
<dd><p>Make the <code>std</code> and <code>os</code> modules available to the loaded
|
||||
script even if it is not a module.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>-d</code></dt>
|
||||
<dt><code>--dump</code></dt>
|
||||
<dd><p>Dump the memory usage stats.
|
||||
@ -293,6 +293,13 @@ executable file.
|
||||
<dd><p>Compile as Javascript module (default=autodetect).
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>-D module_name</code></dt>
|
||||
<dd><p>Compile a dynamically loaded module and its dependencies. This option
|
||||
is needed when your code uses the <code>import</code> keyword or the
|
||||
<code>os.Worker</code> constructor because the compiler cannot statically
|
||||
find the name of the dynamically loaded modules.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>-M module_name[,cname]</code></dt>
|
||||
<dd><p>Add initialization code for an external C module. See the
|
||||
<code>c_module</code> example.
|
||||
@ -308,16 +315,21 @@ executable is smaller and faster. This option is automatically set
|
||||
when the <code>-fno-x</code> options are used.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>-fno-[eval|string-normalize|regexp|json|proxy|map|typedarray|promise]</code></dt>
|
||||
<dt><code>-fno-[eval|string-normalize|regexp|json|proxy|map|typedarray|promise|bigint]</code></dt>
|
||||
<dd><p>Disable selected language features to produce a smaller executable file.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>-fbignum</code></dt>
|
||||
<dd><p>Enable the bignum extensions: BigDecimal object, BigFloat object and
|
||||
the <code>"use math"</code> directive.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<a name="qjscalc-application"></a>
|
||||
<h3 class="section">2.4 <code>qjscalc</code> application</h3>
|
||||
|
||||
<p>The <code>qjscalc</code> application is a superset of the <code>qjsbn</code>
|
||||
<p>The <code>qjscalc</code> application is a superset of the <code>qjs</code>
|
||||
command line interpreter implementing a Javascript calculator with
|
||||
arbitrarily large integer and floating point numbers, fractions,
|
||||
complex numbers, polynomials and matrices. The source code is in
|
||||
@ -333,13 +345,8 @@ QuickJS archive.
|
||||
<a name="Test262-_0028ECMAScript-Test-Suite_0029"></a>
|
||||
<h3 class="section">2.6 Test262 (ECMAScript Test Suite)</h3>
|
||||
|
||||
<p>A test262 runner is included in the QuickJS archive.
|
||||
</p>
|
||||
<p>For reference, the full test262 tests are provided in the archive
|
||||
<samp>qjs-tests-yyyy-mm-dd.tar.xz</samp>. You just need to untar it into the
|
||||
QuickJS source code directory.
|
||||
</p>
|
||||
<p>Alternatively, the test262 tests can be installed with:
|
||||
<p>A test262 runner is included in the QuickJS archive. The test262 tests
|
||||
can be installed in the QuickJS source directory with:
|
||||
</p>
|
||||
<div class="example">
|
||||
<pre class="example">git clone https://github.com/tc39/test262.git test262
|
||||
@ -358,11 +365,10 @@ slow string initialization function is optimized).
|
||||
<pre class="example">make test2
|
||||
</pre></div>
|
||||
|
||||
<p>The configuration files <code>test262.conf</code> (resp
|
||||
<code>test262bn.conf</code> for the bignum version, <code>test262o.conf</code> for
|
||||
the old ES5.1 tests<a name="DOCF4" href="#FOOT4"><sup>4</sup></a>)) contain the options
|
||||
to run the various tests. Tests can be excluded based on features or
|
||||
filename.
|
||||
<p>The configuration files <code>test262.conf</code>
|
||||
(resp. <code>test262o.conf</code> for the old ES5.1 tests<a name="DOCF4" href="#FOOT4"><sup>4</sup></a>))
|
||||
contain the options to run the various tests. Tests can be excluded
|
||||
based on features or filename.
|
||||
</p>
|
||||
<p>The file <code>test262_errors.txt</code> contains the current list of
|
||||
errors. The runner displays a message when a new error appears or when
|
||||
@ -394,33 +400,26 @@ about 100 seconds).
|
||||
<a name="Language-support"></a>
|
||||
<h3 class="section">3.1 Language support</h3>
|
||||
|
||||
<a name="ES2019-support"></a>
|
||||
<h4 class="subsection">3.1.1 ES2019 support</h4>
|
||||
<a name="ES2020-support"></a>
|
||||
<h4 class="subsection">3.1.1 ES2020 support</h4>
|
||||
|
||||
<p>The ES2019 specification is almost fully supported including the Annex
|
||||
<p>The ES2020 specification is almost fully supported including the Annex
|
||||
B (legacy web compatibility) and the Unicode related features.
|
||||
</p>
|
||||
<p>The following features are not supported yet:
|
||||
</p>
|
||||
<ul>
|
||||
<li> Realms (althougth the C API supports different runtimes and contexts)
|
||||
|
||||
</li><li> Tail calls<a name="DOCF6" href="#FOOT6"><sup>6</sup></a>
|
||||
<li> Tail calls<a name="DOCF6" href="#FOOT6"><sup>6</sup></a>
|
||||
|
||||
</li></ul>
|
||||
|
||||
<a name="JSON"></a>
|
||||
<h4 class="subsection">3.1.2 JSON</h4>
|
||||
|
||||
<p>The JSON parser is currently more tolerant than the specification.
|
||||
</p>
|
||||
<a name="ECMA402"></a>
|
||||
<h4 class="subsection">3.1.3 ECMA402</h4>
|
||||
<h4 class="subsection">3.1.2 ECMA402</h4>
|
||||
|
||||
<p>ECMA402 (Internationalization API) is not supported.
|
||||
</p>
|
||||
<a name="Extensions"></a>
|
||||
<h4 class="subsection">3.1.4 Extensions</h4>
|
||||
<h4 class="subsection">3.1.3 Extensions</h4>
|
||||
|
||||
<ul>
|
||||
<li> The directive <code>"use strip"</code> indicates that the debug information (including the source code of the functions) should not be retained to save memory. As <code>"use strict"</code>, the directive can be global to a script or local to a function.
|
||||
@ -430,14 +429,13 @@ B (legacy web compatibility) and the Unicode related features.
|
||||
</li></ul>
|
||||
|
||||
<a name="Mathematical-extensions"></a>
|
||||
<h4 class="subsection">3.1.5 Mathematical extensions</h4>
|
||||
<h4 class="subsection">3.1.4 Mathematical extensions</h4>
|
||||
|
||||
<p>The mathematical extensions are available in the <code>qjsbn</code> version and are fully
|
||||
backward compatible with standard Javascript. See <code>jsbignum.pdf</code>
|
||||
for more information.
|
||||
<p>The mathematical extensions are fully backward compatible with
|
||||
standard Javascript. See <code>jsbignum.pdf</code> for more information.
|
||||
</p>
|
||||
<ul>
|
||||
<li> The <code>BigInt</code> (big integers) TC39 proposal is supported.
|
||||
<li> <code>BigDecimal</code> support: arbitrary large floating point numbers in base 10.
|
||||
|
||||
</li><li> <code>BigFloat</code> support: arbitrary large floating point numbers in base 2.
|
||||
|
||||
@ -503,58 +501,56 @@ and <samp>stdio.h</samp> and a few other utilities.
|
||||
<dd><p>Exit the process.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>evalScript(str)</code></dt>
|
||||
<dd><p>Evaluate the string <code>str</code> as a script (global eval).
|
||||
<dt><code>evalScript(str, options = undefined)</code></dt>
|
||||
<dd><p>Evaluate the string <code>str</code> as a script (global
|
||||
eval). <code>options</code> is an optional object containing the following
|
||||
optional properties:
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>backtrace_barrier</code></dt>
|
||||
<dd><p>Boolean (default = false). If true, error backtraces do not list the
|
||||
stack frames below the evalScript.
|
||||
</p></dd>
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
<dt><code>loadScript(filename)</code></dt>
|
||||
<dd><p>Evaluate the file <code>filename</code> as a script (global eval).
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>Error(errno)</code></dt>
|
||||
<dd>
|
||||
<p><code>std.Error</code> constructor. Error instances contain the field
|
||||
<code>errno</code> (error code) and <code>message</code> (result of
|
||||
<code>std.Error.strerror(errno)</code>).
|
||||
</p>
|
||||
<p>The constructor contains the following fields:
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>EINVAL</code></dt>
|
||||
<dt><code>EIO</code></dt>
|
||||
<dt><code>EACCES</code></dt>
|
||||
<dt><code>EEXIST</code></dt>
|
||||
<dt><code>ENOSPC</code></dt>
|
||||
<dt><code>ENOSYS</code></dt>
|
||||
<dt><code>EBUSY</code></dt>
|
||||
<dt><code>ENOENT</code></dt>
|
||||
<dt><code>EPERM</code></dt>
|
||||
<dt><code>EPIPE</code></dt>
|
||||
<dd><p>Integer value of common errors (additional error codes may be defined).
|
||||
</p></dd>
|
||||
<dt><code>strerror(errno)</code></dt>
|
||||
<dd><p>Return a string that describes the error <code>errno</code>.
|
||||
</p></dd>
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
<dt><code>open(filename, flags)</code></dt>
|
||||
<dd><p>Open a file (wrapper to the libc <code>fopen()</code>). Throws
|
||||
<code>std.Error</code> in case of I/O error.
|
||||
<dt><code>loadFile(filename)</code></dt>
|
||||
<dd><p>Load the file <code>filename</code> and return it as a string assuming UTF-8
|
||||
encoding. Return <code>null</code> in case of I/O error.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>popen(command, flags)</code></dt>
|
||||
<dd><p>Open a process by creating a pipe (wrapper to the libc <code>popen()</code>). Throws
|
||||
<code>std.Error</code> in case of I/O error.
|
||||
<dt><code>open(filename, flags, errorObj = undefined)</code></dt>
|
||||
<dd><p>Open a file (wrapper to the libc <code>fopen()</code>). Return the FILE
|
||||
object or <code>null</code> in case of I/O error. If <code>errorObj</code> is not
|
||||
undefined, set its <code>errno</code> property to the error code or to 0 if
|
||||
no error occured.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>fdopen(fd, flags)</code></dt>
|
||||
<dt><code>popen(command, flags, errorObj = undefined)</code></dt>
|
||||
<dd><p>Open a process by creating a pipe (wrapper to the libc
|
||||
<code>popen()</code>). Return the FILE
|
||||
object or <code>null</code> in case of I/O error. If <code>errorObj</code> is not
|
||||
undefined, set its <code>errno</code> property to the error code or to 0 if
|
||||
no error occured.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>fdopen(fd, flags, errorObj = undefined)</code></dt>
|
||||
<dd><p>Open a file from a file handle (wrapper to the libc
|
||||
<code>fdopen()</code>). Throws <code>std.Error</code> in case of I/O error.
|
||||
<code>fdopen()</code>). Return the FILE
|
||||
object or <code>null</code> in case of I/O error. If <code>errorObj</code> is not
|
||||
undefined, set its <code>errno</code> property to the error code or to 0 if
|
||||
no error occured.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>tmpfile()</code></dt>
|
||||
<dd><p>Open a temporary file. Throws <code>std.Error</code> in case of I/O error.
|
||||
<dt><code>tmpfile(errorObj = undefined)</code></dt>
|
||||
<dd><p>Open a temporary file. Return the FILE
|
||||
object or <code>null</code> in case of I/O error. If <code>errorObj</code> is not
|
||||
undefined, set its <code>errno</code> property to the error code or to 0 if
|
||||
no error occured.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>puts(str)</code></dt>
|
||||
@ -562,7 +558,7 @@ and <samp>stdio.h</samp> and a few other utilities.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>printf(fmt, ...args)</code></dt>
|
||||
<dd><p>Equivalent to <code>std.out.printf(fmt, ...args)</code>
|
||||
<dd><p>Equivalent to <code>std.out.printf(fmt, ...args)</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>sprintf(fmt, ...args)</code></dt>
|
||||
@ -581,6 +577,29 @@ and <samp>stdio.h</samp> and a few other utilities.
|
||||
<dd><p>Constants for seek().
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>Error</code></dt>
|
||||
<dd>
|
||||
<p>Enumeration object containing the integer value of common errors
|
||||
(additional error codes may be defined):
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>EINVAL</code></dt>
|
||||
<dt><code>EIO</code></dt>
|
||||
<dt><code>EACCES</code></dt>
|
||||
<dt><code>EEXIST</code></dt>
|
||||
<dt><code>ENOSPC</code></dt>
|
||||
<dt><code>ENOSYS</code></dt>
|
||||
<dt><code>EBUSY</code></dt>
|
||||
<dt><code>ENOENT</code></dt>
|
||||
<dt><code>EPERM</code></dt>
|
||||
<dt><code>EPIPE</code></dt>
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
<dt><code>strerror(errno)</code></dt>
|
||||
<dd><p>Return a string that describes the error <code>errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>gc()</code></dt>
|
||||
<dd><p>Manually invoke the cycle removal algorithm. The cycle removal
|
||||
algorithm is automatically started when needed, so this function is
|
||||
@ -592,6 +611,19 @@ useful in case of specific memory constraints or for testing.
|
||||
<code>undefined</code> if it is not defined.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>setenv(name, value)</code></dt>
|
||||
<dd><p>Set the value of the environment variable <code>name</code> to the string
|
||||
<code>value</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>unsetenv(name)</code></dt>
|
||||
<dd><p>Delete the environment variable <code>name</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>getenviron()</code></dt>
|
||||
<dd><p>Return an object containing the environment variables as key-value pairs.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>urlGet(url, options = undefined)</code></dt>
|
||||
<dd>
|
||||
<p>Download <code>url</code> using the <samp>curl</samp> command line
|
||||
@ -606,16 +638,33 @@ optional properties:
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>full</code></dt>
|
||||
<dd><p>Boolean (default = false). If true, return the an object contains
|
||||
<dd>
|
||||
<p>Boolean (default = false). If true, return the an object contains
|
||||
the properties <code>response</code> (response content),
|
||||
<code>responseHeaders</code> (headers separated by CRLF), <code>status</code>
|
||||
(status code). If <code>full</code> is false, only the response is
|
||||
returned if the status is between 200 and 299. Otherwise an
|
||||
<code>std.Error</code> exception is raised.
|
||||
(status code). <code>response</code> is <code>null</code> is case of protocol or
|
||||
network error. If <code>full</code> is false, only the response is
|
||||
returned if the status is between 200 and 299. Otherwise <code>null</code>
|
||||
is returned.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
<dt><code>parseExtJSON(str)</code></dt>
|
||||
<dd>
|
||||
<p>Parse <code>str</code> using a superset of <code>JSON.parse</code>. The
|
||||
following extensions are accepted:
|
||||
</p>
|
||||
<ul>
|
||||
<li> Single line and multiline comments
|
||||
</li><li> unquoted properties (ASCII-only Javascript identifiers)
|
||||
</li><li> trailing comma in array and object definitions
|
||||
</li><li> single quoted strings
|
||||
</li><li> <code>\f</code> and <code>\v</code> are accepted as space characters
|
||||
</li><li> leading plus in numbers
|
||||
</li><li> octal (<code>0o</code> prefix) and hexadecimal (<code>0x</code> prefix) numbers
|
||||
</li></ul>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
@ -623,29 +672,45 @@ optional properties:
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>close()</code></dt>
|
||||
<dd><p>Close the file.
|
||||
<dd><p>Close the file. Return 0 if OK or <code>-errno</code> in case of I/O error.
|
||||
</p></dd>
|
||||
<dt><code>puts(str)</code></dt>
|
||||
<dd><p>Outputs the string with the UTF-8 encoding.
|
||||
</p></dd>
|
||||
<dt><code>printf(fmt, ...args)</code></dt>
|
||||
<dd><p>Formatted printf, same formats as the libc printf.
|
||||
</p></dd>
|
||||
<dd><p>Formatted printf.
|
||||
</p>
|
||||
<p>The same formats as the standard C library <code>printf</code> are
|
||||
supported. Integer format types (e.g. <code>%d</code>) truncate the Numbers
|
||||
or BigInts to 32 bits. Use the <code>l</code> modifier (e.g. <code>%ld</code>) to
|
||||
truncate to 64 bits.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>flush()</code></dt>
|
||||
<dd><p>Flush the buffered file.
|
||||
</p></dd>
|
||||
<dt><code>seek(offset, whence)</code></dt>
|
||||
<dd><p>Seek to a give file position (whence is <code>std.SEEK_*</code>). Throws a
|
||||
<code>std.Error</code> in case of I/O error.
|
||||
<dd><p>Seek to a give file position (whence is
|
||||
<code>std.SEEK_*</code>). <code>offset</code> can be a number or a bigint. Return
|
||||
0 if OK or <code>-errno</code> in case of I/O error.
|
||||
</p></dd>
|
||||
<dt><code>tell()</code></dt>
|
||||
<dd><p>Return the current file position.
|
||||
</p></dd>
|
||||
<dt><code>tello()</code></dt>
|
||||
<dd><p>Return the current file position as a bigint.
|
||||
</p></dd>
|
||||
<dt><code>eof()</code></dt>
|
||||
<dd><p>Return true if end of file.
|
||||
</p></dd>
|
||||
<dt><code>fileno()</code></dt>
|
||||
<dd><p>Return the associated OS handle.
|
||||
</p></dd>
|
||||
<dt><code>error()</code></dt>
|
||||
<dd><p>Return true if there was an error.
|
||||
</p></dd>
|
||||
<dt><code>clearerr()</code></dt>
|
||||
<dd><p>Clear the error indication.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>read(buffer, position, length)</code></dt>
|
||||
@ -655,7 +720,7 @@ position <code>position</code> (wrapper to the libc <code>fread</code>).
|
||||
</dd>
|
||||
<dt><code>write(buffer, position, length)</code></dt>
|
||||
<dd><p>Write <code>length</code> bytes to the file from the ArrayBuffer <code>buffer</code> at byte
|
||||
position <code>position</code> (wrapper to the libc <code>fread</code>).
|
||||
position <code>position</code> (wrapper to the libc <code>fwrite</code>).
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>getline()</code></dt>
|
||||
@ -663,8 +728,14 @@ position <code>position</code> (wrapper to the libc <code>fread</code>).
|
||||
the trailing line feed.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>readAsString(max_size = undefined)</code></dt>
|
||||
<dd><p>Read <code>max_size</code> bytes from the file and return them as a string
|
||||
assuming UTF-8 encoding. If <code>max_size</code> is not present, the file
|
||||
is read up its end.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>getByte()</code></dt>
|
||||
<dd><p>Return the next byte from the file.
|
||||
<dd><p>Return the next byte from the file. Return -1 if the end of file is reached.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>putByte(c)</code></dt>
|
||||
@ -682,6 +753,7 @@ the trailing line feed.
|
||||
</li><li> signals
|
||||
</li><li> timers
|
||||
</li><li> asynchronous I/O
|
||||
</li><li> workers (threads)
|
||||
</li></ul>
|
||||
|
||||
<p>The OS functions usually return 0 if OK or an OS specific negative
|
||||
@ -713,7 +785,9 @@ error code.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>seek(fd, offset, whence)</code></dt>
|
||||
<dd><p>Seek in the file. Use <code>std.SEEK_*</code> for <code>whence</code>.
|
||||
<dd><p>Seek in the file. Use <code>std.SEEK_*</code> for
|
||||
<code>whence</code>. <code>offset</code> is either a number or a bigint. If
|
||||
<code>offset</code> is a bigint, a bigint is returned too.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>read(fd, buffer, offset, length)</code></dt>
|
||||
@ -741,11 +815,11 @@ Return the number of written bytes or < 0 if error.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>remove(filename)</code></dt>
|
||||
<dd><p>Remove a file. Return 0 if OK or < 0 if error.
|
||||
<dd><p>Remove a file. Return 0 if OK or <code>-errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>rename(oldname, newname)</code></dt>
|
||||
<dd><p>Rename a file. Return 0 if OK or < 0 if error.
|
||||
<dd><p>Rename a file. Return 0 if OK or <code>-errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>realpath(path)</code></dt>
|
||||
@ -758,8 +832,12 @@ pathname of <code>path</code> and <code>err</code> the error code.
|
||||
and <code>err</code> the error code.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>chdir(path)</code></dt>
|
||||
<dd><p>Change the current directory. Return 0 if OK or <code>-errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>mkdir(path, mode = 0o777)</code></dt>
|
||||
<dd><p>Create a directory at <code>path</code>. Return the error code.
|
||||
<dd><p>Create a directory at <code>path</code>. Return 0 if OK or <code>-errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>stat(path)</code></dt>
|
||||
@ -791,11 +869,11 @@ itself.
|
||||
</dd>
|
||||
<dt><code>utimes(path, atime, mtime)</code></dt>
|
||||
<dd><p>Change the access and modification times of the file <code>path</code>. The
|
||||
times are specified in milliseconds since 1970.
|
||||
times are specified in milliseconds since 1970. Return 0 if OK or <code>-errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>symlink(target, linkpath)</code></dt>
|
||||
<dd><p>Create a link at <code>linkpath</code> containing the string <code>target</code>.
|
||||
<dd><p>Create a link at <code>linkpath</code> containing the string <code>target</code>. Return 0 if OK or <code>-errno</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>readlink(path)</code></dt>
|
||||
@ -813,21 +891,21 @@ the error code.
|
||||
<dd><p>Add a read handler to the file handle <code>fd</code>. <code>func</code> is called
|
||||
each time there is data pending for <code>fd</code>. A single read handler
|
||||
per file handle is supported. Use <code>func = null</code> to remove the
|
||||
hander.
|
||||
handler.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>setWriteHandler(fd, func)</code></dt>
|
||||
<dd><p>Add a write handler to the file handle <code>fd</code>. <code>func</code> is
|
||||
called each time data can be written to <code>fd</code>. A single write
|
||||
handler per file handle is supported. Use <code>func = null</code> to remove
|
||||
the hander.
|
||||
the handler.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>signal(signal, func)</code></dt>
|
||||
<dd><p>Call the function <code>func</code> when the signal <code>signal</code>
|
||||
happens. Only a single handler per signal number is supported. Use
|
||||
<code>null</code> to set the default handler or <code>undefined</code> to ignore
|
||||
the signal.
|
||||
the signal. Signal handlers can only be defined in the main thread.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>SIGINT</code></dt>
|
||||
@ -850,7 +928,7 @@ object containing optional parameters:
|
||||
<dl compact="compact">
|
||||
<dt><code>block</code></dt>
|
||||
<dd><p>Boolean (default = true). If true, wait until the process is
|
||||
termined. In this case, <code>exec</code> return the exit code if positive
|
||||
terminated. In this case, <code>exec</code> return the exit code if positive
|
||||
or the negated signal number if the process was interrupted by a
|
||||
signal. If false, do not block and return the process id of the child.
|
||||
</p>
|
||||
@ -872,13 +950,28 @@ object containing optional parameters:
|
||||
<dt><code>stdout</code></dt>
|
||||
<dt><code>stderr</code></dt>
|
||||
<dd><p>If present, set the handle in the child for stdin, stdout or stderr.
|
||||
</p>
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>env</code></dt>
|
||||
<dd><p>Object. If present, set the process environment from the object
|
||||
key-value pairs. Otherwise use the same environment as the current
|
||||
process.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>uid</code></dt>
|
||||
<dd><p>Integer. If present, the process uid with <code>setuid</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>gid</code></dt>
|
||||
<dd><p>Integer. If present, the process gid with <code>setgid</code>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
<dt><code>waitpid(pid, options)</code></dt>
|
||||
<dd><p><code>waitpid</code> Unix system call. Return the array <code>[ret, status]</code>.
|
||||
<dd><p><code>waitpid</code> Unix system call. Return the array <code>[ret,
|
||||
status]</code>. <code>ret</code> contains <code>-errno</code> in case of error.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>WNOHANG</code></dt>
|
||||
@ -915,6 +1008,50 @@ to the timer.
|
||||
<dd><p>Return a string representing the platform: <code>"linux"</code>, <code>"darwin"</code>,
|
||||
<code>"win32"</code> or <code>"js"</code>.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>Worker(module_filename)</code></dt>
|
||||
<dd><p>Constructor to create a new thread (worker) with an API close to the
|
||||
<code>WebWorkers</code>. <code>module_filename</code> is a string specifying the
|
||||
module filename which is executed in the newly created thread. As for
|
||||
dynamically imported module, it is relative to the current script or
|
||||
module path. Threads normally don’t share any data and communicate
|
||||
between each other with messages. Nested workers are not supported. An
|
||||
example is available in <samp>tests/test_worker.js</samp>.
|
||||
</p>
|
||||
<p>The worker class has the following static properties:
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>parent</code></dt>
|
||||
<dd><p>In the created worker, <code>Worker.parent</code> represents the parent
|
||||
worker and is used to send or receive messages.
|
||||
</p></dd>
|
||||
</dl>
|
||||
|
||||
<p>The worker instances have the following properties:
|
||||
</p>
|
||||
<dl compact="compact">
|
||||
<dt><code>postMessage(msg)</code></dt>
|
||||
<dd>
|
||||
<p>Send a message to the corresponding worker. <code>msg</code> is cloned in
|
||||
the destination worker using an algorithm similar to the <code>HTML</code>
|
||||
structured clone algorithm. <code>SharedArrayBuffer</code> are shared
|
||||
between workers.
|
||||
</p>
|
||||
<p>Current limitations: <code>Map</code> and <code>Set</code> are not supported
|
||||
yet.
|
||||
</p>
|
||||
</dd>
|
||||
<dt><code>onmessage</code></dt>
|
||||
<dd>
|
||||
<p>Getter and setter. Set a function which is called each time a
|
||||
message is received. The function is called with a single
|
||||
argument. It is an object with a <code>data</code> property containing the
|
||||
received message. The thread is not terminated if there is at least
|
||||
one non <code>null</code> <code>onmessage</code> handler.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
@ -934,7 +1071,7 @@ supported.
|
||||
</p>
|
||||
<p><code>JSContext</code> represents a Javascript context (or Realm). Each
|
||||
JSContext has its own global objects and system objects. There can be
|
||||
several JSContexts per JSRuntime and they can share objects, similary
|
||||
several JSContexts per JSRuntime and they can share objects, similar
|
||||
to frames of the same origin sharing Javascript objects in a
|
||||
web browser.
|
||||
</p>
|
||||
@ -943,7 +1080,7 @@ web browser.
|
||||
|
||||
<p><code>JSValue</code> represents a Javascript value which can be a primitive
|
||||
type or an object. Reference counting is used, so it is important to
|
||||
explicitely duplicate (<code>JS_DupValue()</code>, increment the reference
|
||||
explicitly duplicate (<code>JS_DupValue()</code>, increment the reference
|
||||
count) or free (<code>JS_FreeValue()</code>, decrement the reference count)
|
||||
JSValues.
|
||||
</p>
|
||||
@ -965,9 +1102,9 @@ general rule, C functions take constant <code>JSValue</code>s as parameters
|
||||
<h4 class="subsection">3.4.4 Exceptions</h4>
|
||||
|
||||
<p>Exceptions: most C functions can return a Javascript exception. It
|
||||
must be explicitely tested and handled by the C code. The specific
|
||||
must be explicitly tested and handled by the C code. The specific
|
||||
<code>JSValue</code> <code>JS_EXCEPTION</code> indicates that an exception
|
||||
occured. The actual exception object is stored in the
|
||||
occurred. The actual exception object is stored in the
|
||||
<code>JSContext</code> and can be retrieved with <code>JS_GetException()</code>.
|
||||
</p>
|
||||
<a name="Script-evaluation"></a>
|
||||
@ -1171,16 +1308,16 @@ stack holds the Javascript parameters and local variables.
|
||||
<a name="RegExp"></a>
|
||||
<h3 class="section">4.4 RegExp</h3>
|
||||
|
||||
<p>A specific regular expression engine was developped. It is both small
|
||||
<p>A specific regular expression engine was developed. It is both small
|
||||
and efficient and supports all the ES2020 features including the
|
||||
Unicode properties. As the Javascript compiler, it directly generates
|
||||
bytecode without a parse tree.
|
||||
</p>
|
||||
<p>Backtracking with an explicit stack is used so that there is no
|
||||
recursion on the system stack. Simple quantizers are specifically
|
||||
recursion on the system stack. Simple quantifiers are specifically
|
||||
optimized to avoid recursions.
|
||||
</p>
|
||||
<p>Infinite recursions coming from quantizers with empty terms are
|
||||
<p>Infinite recursions coming from quantifiers with empty terms are
|
||||
avoided.
|
||||
</p>
|
||||
<p>The full regexp library weights about 15 KiB (x86 code), excluding the
|
||||
@ -1189,9 +1326,9 @@ Unicode library.
|
||||
<a name="Unicode"></a>
|
||||
<h3 class="section">4.5 Unicode</h3>
|
||||
|
||||
<p>A specific Unicode library was developped so that there is no
|
||||
<p>A specific Unicode library was developed so that there is no
|
||||
dependency on an external large Unicode library such as ICU. All the
|
||||
Unicode tables are compressed while keeping a reasonnable access
|
||||
Unicode tables are compressed while keeping a reasonable access
|
||||
speed.
|
||||
</p>
|
||||
<p>The library supports case conversion, Unicode normalization, Unicode
|
||||
@ -1200,11 +1337,11 @@ binary properties.
|
||||
</p>
|
||||
<p>The full Unicode library weights about 45 KiB (x86 code).
|
||||
</p>
|
||||
<a name="BigInt-and-BigFloat"></a>
|
||||
<h3 class="section">4.6 BigInt and BigFloat</h3>
|
||||
<a name="BigInt_002c-BigFloat_002c-BigDecimal"></a>
|
||||
<h3 class="section">4.6 BigInt, BigFloat, BigDecimal</h3>
|
||||
|
||||
<p>BigInt and BigFloat are implemented with the <code>libbf</code>
|
||||
library<a name="DOCF7" href="#FOOT7"><sup>7</sup></a>. It weights about 60
|
||||
<p>BigInt, BigFloat and BigDecimal are implemented with the <code>libbf</code>
|
||||
library<a name="DOCF7" href="#FOOT7"><sup>7</sup></a>. It weights about 90
|
||||
KiB (x86 code) and provides arbitrary precision IEEE 754 floating
|
||||
point operations and transcendental functions with exact rounding.
|
||||
</p>
|
||||
@ -1221,15 +1358,15 @@ Bellard and Charlie Gordon.
|
||||
<h4 class="footnotes-heading">Footnotes</h4>
|
||||
|
||||
<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
|
||||
<p><a href="https://www.ecma-international.org/ecma-262/10.0">https://www.ecma-international.org/ecma-262/10.0</a></p>
|
||||
<p><a href="https://tc39.es/ecma262/">https://tc39.es/ecma262/</a></p>
|
||||
<h3><a name="FOOT2" href="#DOCF2">(2)</a></h3>
|
||||
<p><a href="https://github.com/tc39/test262">https://github.com/tc39/test262</a></p>
|
||||
<h3><a name="FOOT3" href="#DOCF3">(3)</a></h3>
|
||||
<p><a href="https://tc39.github.io/ecma262/">https://tc39.github.io/ecma262/</a></p>
|
||||
<h3><a name="FOOT4" href="#DOCF4">(4)</a></h3>
|
||||
<p>The old ES5.1 tests can be extracted with
|
||||
<code>git clone --single-branch --branch es5-tests
|
||||
https://github.com/tc39/test262.git test262o</code></p>
|
||||
<p>The old
|
||||
ES5.1 tests can be extracted with <code>git clone --single-branch
|
||||
--branch es5-tests https://github.com/tc39/test262.git test262o</code></p>
|
||||
<h3><a name="FOOT5" href="#DOCF5">(5)</a></h3>
|
||||
<p><a href="https://github.com/bterlson/test262-harness">https://github.com/bterlson/test262-harness</a></p>
|
||||
<h3><a name="FOOT6" href="#DOCF6">(6)</a></h3>
|
||||
|
Reference in New Issue
Block a user