1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ --> 4<head> 5<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 6<title>QuickJS Javascript Engine</title> 7 8<meta name="description" content="QuickJS Javascript Engine"> 9<meta name="keywords" content="QuickJS Javascript Engine"> 10<meta name="resource-type" content="document"> 11<meta name="distribution" content="global"> 12<meta name="Generator" content="makeinfo"> 13<link href="#SEC_Contents" rel="contents" title="Table of Contents"> 14<style type="text/css"> 15<!-- 16a.summary-letter {text-decoration: none} 17blockquote.indentedblock {margin-right: 0em} 18blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} 19blockquote.smallquotation {font-size: smaller} 20div.display {margin-left: 3.2em} 21div.example {margin-left: 3.2em} 22div.lisp {margin-left: 3.2em} 23div.smalldisplay {margin-left: 3.2em} 24div.smallexample {margin-left: 3.2em} 25div.smalllisp {margin-left: 3.2em} 26kbd {font-style: oblique} 27pre.display {font-family: inherit} 28pre.format {font-family: inherit} 29pre.menu-comment {font-family: serif} 30pre.menu-preformatted {font-family: serif} 31pre.smalldisplay {font-family: inherit; font-size: smaller} 32pre.smallexample {font-size: smaller} 33pre.smallformat {font-family: inherit; font-size: smaller} 34pre.smalllisp {font-size: smaller} 35span.nolinebreak {white-space: nowrap} 36span.roman {font-family: initial; font-weight: normal} 37span.sansserif {font-family: sans-serif; font-weight: normal} 38ul.no-bullet {list-style: none} 39--> 40</style> 41<meta name="viewport" content="width=device-width, initial-scale=1.0"> 42 43 44</head> 45 46<body lang="en"> 47<h1 class="settitle" align="center">QuickJS Javascript Engine</h1> 48 49<a name="SEC_Contents"></a> 50<h2 class="contents-heading">Table of Contents</h2> 51 52<div class="contents"> 53<ul class="no-bullet"> 54<li><a name="toc-Introduction" href="#Introduction">1 Introduction</a> 55<ul class="no-bullet"> 56 <li><a name="toc-Main-Features" href="#Main-Features">1.1 Main Features</a></li> 57</ul></li> 58<li><a name="toc-Usage" href="#Usage">2 Usage</a> 59<ul class="no-bullet"> 60 <li><a name="toc-Installation" href="#Installation">2.1 Installation</a></li> 61 <li><a name="toc-Quick-start" href="#Quick-start">2.2 Quick start</a></li> 62 <li><a name="toc-Command-line-options" href="#Command-line-options">2.3 Command line options</a> 63 <ul class="no-bullet"> 64 <li><a name="toc-qjs-interpreter" href="#qjs-interpreter">2.3.1 <code>qjs</code> interpreter</a></li> 65 <li><a name="toc-qjsc-compiler" href="#qjsc-compiler">2.3.2 <code>qjsc</code> compiler</a></li> 66 </ul></li> 67 <li><a name="toc-qjscalc-application" href="#qjscalc-application">2.4 <code>qjscalc</code> application</a></li> 68 <li><a name="toc-Built_002din-tests" href="#Built_002din-tests">2.5 Built-in tests</a></li> 69 <li><a name="toc-Test262-_0028ECMAScript-Test-Suite_0029" href="#Test262-_0028ECMAScript-Test-Suite_0029">2.6 Test262 (ECMAScript Test Suite)</a></li> 70</ul></li> 71<li><a name="toc-Specifications" href="#Specifications">3 Specifications</a> 72<ul class="no-bullet"> 73 <li><a name="toc-Language-support" href="#Language-support">3.1 Language support</a> 74 <ul class="no-bullet"> 75 <li><a name="toc-ES2019-support" href="#ES2019-support">3.1.1 ES2019 support</a></li> 76 <li><a name="toc-JSON" href="#JSON">3.1.2 JSON</a></li> 77 <li><a name="toc-ECMA402" href="#ECMA402">3.1.3 ECMA402</a></li> 78 <li><a name="toc-Extensions" href="#Extensions">3.1.4 Extensions</a></li> 79 <li><a name="toc-Mathematical-extensions" href="#Mathematical-extensions">3.1.5 Mathematical extensions</a></li> 80 </ul></li> 81 <li><a name="toc-Modules" href="#Modules">3.2 Modules</a></li> 82 <li><a name="toc-Standard-library" href="#Standard-library">3.3 Standard library</a> 83 <ul class="no-bullet"> 84 <li><a name="toc-Global-objects" href="#Global-objects">3.3.1 Global objects</a></li> 85 <li><a name="toc-std-module" href="#std-module">3.3.2 <code>std</code> module</a></li> 86 <li><a name="toc-os-module" href="#os-module">3.3.3 <code>os</code> module</a></li> 87 </ul></li> 88 <li><a name="toc-QuickJS-C-API" href="#QuickJS-C-API">3.4 QuickJS C API</a> 89 <ul class="no-bullet"> 90 <li><a name="toc-Runtime-and-contexts" href="#Runtime-and-contexts">3.4.1 Runtime and contexts</a></li> 91 <li><a name="toc-JSValue" href="#JSValue">3.4.2 JSValue</a></li> 92 <li><a name="toc-C-functions" href="#C-functions">3.4.3 C functions</a></li> 93 <li><a name="toc-Exceptions" href="#Exceptions">3.4.4 Exceptions</a></li> 94 <li><a name="toc-Script-evaluation" href="#Script-evaluation">3.4.5 Script evaluation</a></li> 95 <li><a name="toc-JS-Classes" href="#JS-Classes">3.4.6 JS Classes</a></li> 96 <li><a name="toc-C-Modules" href="#C-Modules">3.4.7 C Modules</a></li> 97 <li><a name="toc-Memory-handling" href="#Memory-handling">3.4.8 Memory handling</a></li> 98 <li><a name="toc-Execution-timeout-and-interrupts" href="#Execution-timeout-and-interrupts">3.4.9 Execution timeout and interrupts</a></li> 99 </ul></li> 100</ul></li> 101<li><a name="toc-Internals" href="#Internals">4 Internals</a> 102<ul class="no-bullet"> 103 <li><a name="toc-Bytecode" href="#Bytecode">4.1 Bytecode</a></li> 104 <li><a name="toc-Executable-generation" href="#Executable-generation">4.2 Executable generation</a> 105 <ul class="no-bullet"> 106 <li><a name="toc-qjsc-compiler-1" href="#qjsc-compiler-1">4.2.1 <code>qjsc</code> compiler</a></li> 107 <li><a name="toc-Binary-JSON" href="#Binary-JSON">4.2.2 Binary JSON</a></li> 108 </ul></li> 109 <li><a name="toc-Runtime" href="#Runtime">4.3 Runtime</a> 110 <ul class="no-bullet"> 111 <li><a name="toc-Strings" href="#Strings">4.3.1 Strings</a></li> 112 <li><a name="toc-Objects" href="#Objects">4.3.2 Objects</a></li> 113 <li><a name="toc-Atoms" href="#Atoms">4.3.3 Atoms</a></li> 114 <li><a name="toc-Numbers" href="#Numbers">4.3.4 Numbers</a></li> 115 <li><a name="toc-Garbage-collection" href="#Garbage-collection">4.3.5 Garbage collection</a></li> 116 <li><a name="toc-JSValue-1" href="#JSValue-1">4.3.6 JSValue</a></li> 117 <li><a name="toc-Function-call" href="#Function-call">4.3.7 Function call</a></li> 118 </ul></li> 119 <li><a name="toc-RegExp" href="#RegExp">4.4 RegExp</a></li> 120 <li><a name="toc-Unicode" href="#Unicode">4.5 Unicode</a></li> 121 <li><a name="toc-BigInt-and-BigFloat" href="#BigInt-and-BigFloat">4.6 BigInt and BigFloat</a></li> 122</ul></li> 123<li><a name="toc-License" href="#License">5 License</a></li> 124 125</ul> 126</div> 127 128 129<a name="Introduction"></a> 130<h2 class="chapter">1 Introduction</h2> 131 132<p>QuickJS is a small and embeddable Javascript engine. It supports the 133ES2019 specification 134<a name="DOCF1" href="#FOOT1"><sup>1</sup></a> 135including modules, asynchronous generators and proxies. 136</p> 137<p>It optionally supports mathematical extensions such as big integers 138(BigInt), big floating point numbers (BigFloat) and operator 139overloading. 140</p> 141<a name="Main-Features"></a> 142<h3 class="section">1.1 Main Features</h3> 143 144<ul> 145<li> Small and easily embeddable: just a few C files, no external dependency, 180 KiB of x86 code for a simple “hello world” program. 146 147</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. 148 149</li><li> Almost complete ES2019 support including modules, asynchronous 150generators and full Annex B support (legacy web compatibility). Many 151features from the upcoming ES2020 specification 152<a name="DOCF3" href="#FOOT3"><sup>3</sup></a> are also supported. 153 154</li><li> Passes nearly 100% of the ECMAScript Test Suite tests when selecting the ES2019 features. 155 156</li><li> Can compile Javascript sources to executables with no external dependency. 157 158</li><li> Garbage collection using reference counting (to reduce memory usage and have deterministic behavior) with cycle removal. 159 160</li><li> Mathematical extensions: BigInt, BigFloat, operator overloading, bigint mode, math mode. 161 162</li><li> Command line interpreter with contextual colorization and completion implemented in Javascript. 163 164</li><li> Small built-in standard library with C library wrappers. 165 166</li></ul> 167 168<a name="Usage"></a> 169<h2 class="chapter">2 Usage</h2> 170 171<a name="Installation"></a> 172<h3 class="section">2.1 Installation</h3> 173 174<p>A Makefile is provided to compile the engine on Linux or MacOS/X. A 175preliminary Windows support is available thru cross compilation on a 176Linux host with the MingGW tools. 177</p> 178<p>Edit the top of the <code>Makefile</code> if you wish to select specific 179options then run <code>make</code>. 180</p> 181<p>You can type <code>make install</code> as root if you wish to install the binaries and support files to 182<code>/usr/local</code> (this is not necessary to use QuickJS). 183</p> 184<a name="Quick-start"></a> 185<h3 class="section">2.2 Quick start</h3> 186 187<p><code>qjs</code> is the command line interpreter (Read-Eval-Print Loop). You can pass 188Javascript files and/or expressions as arguments to execute them: 189</p> 190<div class="example"> 191<pre class="example">./qjs examples/hello.js 192</pre></div> 193 194<p><code>qjsc</code> is the command line compiler: 195</p> 196<div class="example"> 197<pre class="example">./qjsc -o hello examples/hello.js 198./hello 199</pre></div> 200 201<p>generates a <code>hello</code> executable with no external dependency. 202</p> 203<p><code>qjsbn</code> and <code>qjscbn</code> are the corresponding interpreter and 204compiler with the mathematical extensions: 205</p> 206<div class="example"> 207<pre class="example">./qjsbn examples/pi.js 1000 208</pre></div> 209 210<p>displays 1000 digits of PI. 211</p> 212<div class="example"> 213<pre class="example">./qjsbnc -o pi examples/pi.js 214./pi 1000 215</pre></div> 216 217<p>compiles and executes the PI program. 218</p> 219<a name="Command-line-options"></a> 220<h3 class="section">2.3 Command line options</h3> 221 222<a name="qjs-interpreter"></a> 223<h4 class="subsection">2.3.1 <code>qjs</code> interpreter</h4> 224 225<pre class="verbatim">usage: qjs [options] [files] 226</pre> 227<p>Options are: 228</p><dl compact="compact"> 229<dt><code>-h</code></dt> 230<dt><code>--help</code></dt> 231<dd><p>List options. 232</p> 233</dd> 234<dt><code>-e <code>EXPR</code></code></dt> 235<dt><code>--eval <code>EXPR</code></code></dt> 236<dd><p>Evaluate EXPR. 237</p> 238</dd> 239<dt><code>-i</code></dt> 240<dt><code>--interactive</code></dt> 241<dd><p>Go to interactive mode (it is not the default when files are provided on the command line). 242</p> 243</dd> 244<dt><code>-m</code></dt> 245<dt><code>--module</code></dt> 246<dd><p>Load as ES6 module (default=autodetect). 247</p> 248</dd> 249<dt><code>--script</code></dt> 250<dd><p>Load as ES6 script (default=autodetect). 251</p> 252</dd> 253</dl> 254 255<p>Advanced options are: 256</p> 257<dl compact="compact"> 258<dt><code>-d</code></dt> 259<dt><code>--dump</code></dt> 260<dd><p>Dump the memory usage stats. 261</p> 262</dd> 263<dt><code>-q</code></dt> 264<dt><code>--quit</code></dt> 265<dd><p>just instantiate the interpreter and quit. 266</p> 267</dd> 268</dl> 269 270<a name="qjsc-compiler"></a> 271<h4 class="subsection">2.3.2 <code>qjsc</code> compiler</h4> 272 273<pre class="verbatim">usage: qjsc [options] [files] 274</pre> 275<p>Options are: 276</p><dl compact="compact"> 277<dt><code>-c</code></dt> 278<dd><p>Only output bytecode in a C file. The default is to output an executable file. 279</p></dd> 280<dt><code>-e</code></dt> 281<dd><p>Output <code>main()</code> and bytecode in a C file. The default is to output an 282executable file. 283</p></dd> 284<dt><code>-o output</code></dt> 285<dd><p>Set the output filename (default = <samp>out.c</samp> or <samp>a.out</samp>). 286</p> 287</dd> 288<dt><code>-N cname</code></dt> 289<dd><p>Set the C name of the generated data. 290</p> 291</dd> 292<dt><code>-m</code></dt> 293<dd><p>Compile as Javascript module (default=autodetect). 294</p> 295</dd> 296<dt><code>-M module_name[,cname]</code></dt> 297<dd><p>Add initialization code for an external C module. See the 298<code>c_module</code> example. 299</p> 300</dd> 301<dt><code>-x</code></dt> 302<dd><p>Byte swapped output (only used for cross compilation). 303</p> 304</dd> 305<dt><code>-flto</code></dt> 306<dd><p>Use link time optimization. The compilation is slower but the 307executable is smaller and faster. This option is automatically set 308when the <code>-fno-x</code> options are used. 309</p> 310</dd> 311<dt><code>-fno-[eval|string-normalize|regexp|json|proxy|map|typedarray|promise]</code></dt> 312<dd><p>Disable selected language features to produce a smaller executable file. 313</p> 314</dd> 315</dl> 316 317<a name="qjscalc-application"></a> 318<h3 class="section">2.4 <code>qjscalc</code> application</h3> 319 320<p>The <code>qjscalc</code> application is a superset of the <code>qjsbn</code> 321command line interpreter implementing a Javascript calculator with 322arbitrarily large integer and floating point numbers, fractions, 323complex numbers, polynomials and matrices. The source code is in 324<samp>qjscalc.js</samp>. More documentation and a web version are available at 325<a href="http://numcalc.com">http://numcalc.com</a>. 326</p> 327<a name="Built_002din-tests"></a> 328<h3 class="section">2.5 Built-in tests</h3> 329 330<p>Run <code>make test</code> to run the few built-in tests included in the 331QuickJS archive. 332</p> 333<a name="Test262-_0028ECMAScript-Test-Suite_0029"></a> 334<h3 class="section">2.6 Test262 (ECMAScript Test Suite)</h3> 335 336<p>A test262 runner is included in the QuickJS archive. 337</p> 338<p>For reference, the full test262 tests are provided in the archive 339<samp>qjs-tests-yyyy-mm-dd.tar.xz</samp>. You just need to untar it into the 340QuickJS source code directory. 341</p> 342<p>Alternatively, the test262 tests can be installed with: 343</p> 344<div class="example"> 345<pre class="example">git clone https://github.com/tc39/test262.git test262 346cd test262 347patch -p1 < ../tests/test262.patch 348cd .. 349</pre></div> 350 351<p>The patch adds the implementation specific <code>harness</code> functions 352and optimizes the inefficient RegExp character classes and Unicode 353property escapes tests (the tests themselves are not modified, only a 354slow string initialization function is optimized). 355</p> 356<p>The tests can be run with 357</p><div class="example"> 358<pre class="example">make test2 359</pre></div> 360 361<p>The configuration files <code>test262.conf</code> (resp 362<code>test262bn.conf</code> for the bignum version, <code>test262o.conf</code> for 363the old ES5.1 tests<a name="DOCF4" href="#FOOT4"><sup>4</sup></a>)) contain the options 364to run the various tests. Tests can be excluded based on features or 365filename. 366</p> 367<p>The file <code>test262_errors.txt</code> contains the current list of 368errors. The runner displays a message when a new error appears or when 369an existing error is corrected or modified. Use the <code>-u</code> option 370to update the current list of errors (or <code>make test2-update</code>). 371</p> 372<p>The file <code>test262_report.txt</code> contains the logs of all the 373tests. It is useful to have a clearer analysis of a particular 374error. In case of crash, the last line corresponds to the failing 375test. 376</p> 377<p>Use the syntax <code>./run-test262 -c test262.conf -f filename.js</code> to 378run a single test. Use the syntax <code>./run-test262 -c test262.conf 379N</code> to start testing at test number <code>N</code>. 380</p> 381<p>For more information, run <code>./run-test262</code> to see the command line 382options of the test262 runner. 383</p> 384<p><code>run-test262</code> accepts the <code>-N</code> option to be invoked from 385<code>test262-harness</code><a name="DOCF5" href="#FOOT5"><sup>5</sup></a> 386thru <code>eshost</code>. Unless you want to compare QuickJS with other 387engines under the same conditions, we do not recommend to run the 388tests this way as it is much slower (typically half an hour instead of 389about 100 seconds). 390</p> 391<a name="Specifications"></a> 392<h2 class="chapter">3 Specifications</h2> 393 394<a name="Language-support"></a> 395<h3 class="section">3.1 Language support</h3> 396 397<a name="ES2019-support"></a> 398<h4 class="subsection">3.1.1 ES2019 support</h4> 399 400<p>The ES2019 specification is almost fully supported including the Annex 401B (legacy web compatibility) and the Unicode related features. 402</p> 403<p>The following features are not supported yet: 404</p> 405<ul> 406<li> Realms (althougth the C API supports different runtimes and contexts) 407 408</li><li> Tail calls<a name="DOCF6" href="#FOOT6"><sup>6</sup></a> 409 410</li></ul> 411 412<a name="JSON"></a> 413<h4 class="subsection">3.1.2 JSON</h4> 414 415<p>The JSON parser is currently more tolerant than the specification. 416</p> 417<a name="ECMA402"></a> 418<h4 class="subsection">3.1.3 ECMA402</h4> 419 420<p>ECMA402 (Internationalization API) is not supported. 421</p> 422<a name="Extensions"></a> 423<h4 class="subsection">3.1.4 Extensions</h4> 424 425<ul> 426<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. 427 428</li><li> The first line of a script beginning with <code>#!</code> is ignored. 429 430</li></ul> 431 432<a name="Mathematical-extensions"></a> 433<h4 class="subsection">3.1.5 Mathematical extensions</h4> 434 435<p>The mathematical extensions are available in the <code>qjsbn</code> version and are fully 436backward compatible with standard Javascript. See <code>jsbignum.pdf</code> 437for more information. 438</p> 439<ul> 440<li> The <code>BigInt</code> (big integers) TC39 proposal is supported. 441 442</li><li> <code>BigFloat</code> support: arbitrary large floating point numbers in base 2. 443 444</li><li> Operator overloading. 445 446</li><li> The directive <code>"use bigint"</code> enables the bigint mode where integers are <code>BigInt</code> by default. 447 448</li><li> The directive <code>"use math"</code> enables the math mode where the division and power operators on integers produce fractions. Floating point literals are <code>BigFloat</code> by default and integers are <code>BigInt</code> by default. 449 450</li></ul> 451 452<a name="Modules"></a> 453<h3 class="section">3.2 Modules</h3> 454 455<p>ES6 modules are fully supported. The default name resolution is the 456following: 457</p> 458<ul> 459<li> Module names with a leading <code>.</code> or <code>..</code> are relative 460to the current module path. 461 462</li><li> Module names without a leading <code>.</code> or <code>..</code> are system 463modules, such as <code>std</code> or <code>os</code>. 464 465</li><li> Module names ending with <code>.so</code> are native modules using the 466QuickJS C API. 467 468</li></ul> 469 470<a name="Standard-library"></a> 471<h3 class="section">3.3 Standard library</h3> 472 473<p>The standard library is included by default in the command line 474interpreter. It contains the two modules <code>std</code> and <code>os</code> and 475a few global objects. 476</p> 477<a name="Global-objects"></a> 478<h4 class="subsection">3.3.1 Global objects</h4> 479 480<dl compact="compact"> 481<dt><code>scriptArgs</code></dt> 482<dd><p>Provides the command line arguments. The first argument is the script name. 483</p></dd> 484<dt><code>print(...args)</code></dt> 485<dd><p>Print the arguments separated by spaces and a trailing newline. 486</p></dd> 487<dt><code>console.log(...args)</code></dt> 488<dd><p>Same as print(). 489</p> 490</dd> 491</dl> 492 493<a name="std-module"></a> 494<h4 class="subsection">3.3.2 <code>std</code> module</h4> 495 496<p>The <code>std</code> module provides wrappers to the libc <samp>stdlib.h</samp> 497and <samp>stdio.h</samp> and a few other utilities. 498</p> 499<p>Available exports: 500</p> 501<dl compact="compact"> 502<dt><code>exit(n)</code></dt> 503<dd><p>Exit the process. 504</p> 505</dd> 506<dt><code>evalScript(str)</code></dt> 507<dd><p>Evaluate the string <code>str</code> as a script (global eval). 508</p> 509</dd> 510<dt><code>loadScript(filename)</code></dt> 511<dd><p>Evaluate the file <code>filename</code> as a script (global eval). 512</p> 513</dd> 514<dt><code>Error(errno)</code></dt> 515<dd> 516<p><code>std.Error</code> constructor. Error instances contain the field 517<code>errno</code> (error code) and <code>message</code> (result of 518<code>std.Error.strerror(errno)</code>). 519</p> 520<p>The constructor contains the following fields: 521</p> 522<dl compact="compact"> 523<dt><code>EINVAL</code></dt> 524<dt><code>EIO</code></dt> 525<dt><code>EACCES</code></dt> 526<dt><code>EEXIST</code></dt> 527<dt><code>ENOSPC</code></dt> 528<dt><code>ENOSYS</code></dt> 529<dt><code>EBUSY</code></dt> 530<dt><code>ENOENT</code></dt> 531<dt><code>EPERM</code></dt> 532<dt><code>EPIPE</code></dt> 533<dd><p>Integer value of common errors (additional error codes may be defined). 534 </p></dd> 535<dt><code>strerror(errno)</code></dt> 536<dd><p>Return a string that describes the error <code>errno</code>. 537 </p></dd> 538</dl> 539 540</dd> 541<dt><code>open(filename, flags)</code></dt> 542<dd><p>Open a file (wrapper to the libc <code>fopen()</code>). Throws 543<code>std.Error</code> in case of I/O error. 544</p> 545</dd> 546<dt><code>popen(command, flags)</code></dt> 547<dd><p>Open a process by creating a pipe (wrapper to the libc <code>popen()</code>). Throws 548<code>std.Error</code> in case of I/O error. 549</p> 550</dd> 551<dt><code>fdopen(fd, flags)</code></dt> 552<dd><p>Open a file from a file handle (wrapper to the libc 553<code>fdopen()</code>). Throws <code>std.Error</code> in case of I/O error. 554</p> 555</dd> 556<dt><code>tmpfile()</code></dt> 557<dd><p>Open a temporary file. Throws <code>std.Error</code> in case of I/O error. 558</p> 559</dd> 560<dt><code>puts(str)</code></dt> 561<dd><p>Equivalent to <code>std.out.puts(str)</code>. 562</p> 563</dd> 564<dt><code>printf(fmt, ...args)</code></dt> 565<dd><p>Equivalent to <code>std.out.printf(fmt, ...args)</code> 566</p> 567</dd> 568<dt><code>sprintf(fmt, ...args)</code></dt> 569<dd><p>Equivalent to the libc sprintf(). 570</p> 571</dd> 572<dt><code>in</code></dt> 573<dt><code>out</code></dt> 574<dt><code>err</code></dt> 575<dd><p>Wrappers to the libc file <code>stdin</code>, <code>stdout</code>, <code>stderr</code>. 576</p> 577</dd> 578<dt><code>SEEK_SET</code></dt> 579<dt><code>SEEK_CUR</code></dt> 580<dt><code>SEEK_END</code></dt> 581<dd><p>Constants for seek(). 582</p> 583</dd> 584<dt><code>gc()</code></dt> 585<dd><p>Manually invoke the cycle removal algorithm. The cycle removal 586algorithm is automatically started when needed, so this function is 587useful in case of specific memory constraints or for testing. 588</p> 589</dd> 590<dt><code>getenv(name)</code></dt> 591<dd><p>Return the value of the environment variable <code>name</code> or 592<code>undefined</code> if it is not defined. 593</p> 594</dd> 595<dt><code>urlGet(url, options = undefined)</code></dt> 596<dd> 597<p>Download <code>url</code> using the <samp>curl</samp> command line 598utility. <code>options</code> is an optional object containing the following 599optional properties: 600</p> 601<dl compact="compact"> 602<dt><code>binary</code></dt> 603<dd><p>Boolean (default = false). If true, the response is an ArrayBuffer 604 instead of a string. When a string is returned, the data is assumed 605 to be UTF-8 encoded. 606</p> 607</dd> 608<dt><code>full</code></dt> 609<dd><p>Boolean (default = false). If true, return the an object contains 610 the properties <code>response</code> (response content), 611 <code>responseHeaders</code> (headers separated by CRLF), <code>status</code> 612 (status code). If <code>full</code> is false, only the response is 613 returned if the status is between 200 and 299. Otherwise an 614 <code>std.Error</code> exception is raised. 615</p> 616</dd> 617</dl> 618 619</dd> 620</dl> 621 622<p>FILE prototype: 623</p> 624<dl compact="compact"> 625<dt><code>close()</code></dt> 626<dd><p>Close the file. 627</p></dd> 628<dt><code>puts(str)</code></dt> 629<dd><p>Outputs the string with the UTF-8 encoding. 630</p></dd> 631<dt><code>printf(fmt, ...args)</code></dt> 632<dd><p>Formatted printf, same formats as the libc printf. 633</p></dd> 634<dt><code>flush()</code></dt> 635<dd><p>Flush the buffered file. 636</p></dd> 637<dt><code>seek(offset, whence)</code></dt> 638<dd><p>Seek to a give file position (whence is <code>std.SEEK_*</code>). Throws a 639<code>std.Error</code> in case of I/O error. 640</p></dd> 641<dt><code>tell()</code></dt> 642<dd><p>Return the current file position. 643</p></dd> 644<dt><code>eof()</code></dt> 645<dd><p>Return true if end of file. 646</p></dd> 647<dt><code>fileno()</code></dt> 648<dd><p>Return the associated OS handle. 649</p> 650</dd> 651<dt><code>read(buffer, position, length)</code></dt> 652<dd><p>Read <code>length</code> bytes from the file to the ArrayBuffer <code>buffer</code> at byte 653position <code>position</code> (wrapper to the libc <code>fread</code>). 654</p> 655</dd> 656<dt><code>write(buffer, position, length)</code></dt> 657<dd><p>Write <code>length</code> bytes to the file from the ArrayBuffer <code>buffer</code> at byte 658position <code>position</code> (wrapper to the libc <code>fread</code>). 659</p> 660</dd> 661<dt><code>getline()</code></dt> 662<dd><p>Return the next line from the file, assuming UTF-8 encoding, excluding 663the trailing line feed. 664</p> 665</dd> 666<dt><code>getByte()</code></dt> 667<dd><p>Return the next byte from the file. 668</p> 669</dd> 670<dt><code>putByte(c)</code></dt> 671<dd><p>Write one byte to the file. 672</p></dd> 673</dl> 674 675<a name="os-module"></a> 676<h4 class="subsection">3.3.3 <code>os</code> module</h4> 677 678<p>The <code>os</code> module provides Operating System specific functions: 679</p> 680<ul> 681<li> low level file access 682</li><li> signals 683</li><li> timers 684</li><li> asynchronous I/O 685</li></ul> 686 687<p>The OS functions usually return 0 if OK or an OS specific negative 688error code. 689</p> 690<p>Available exports: 691</p> 692<dl compact="compact"> 693<dt><code>open(filename, flags, mode = 0o666)</code></dt> 694<dd><p>Open a file. Return a handle or < 0 if error. 695</p> 696</dd> 697<dt><code>O_RDONLY</code></dt> 698<dt><code>O_WRONLY</code></dt> 699<dt><code>O_RDWR</code></dt> 700<dt><code>O_APPEND</code></dt> 701<dt><code>O_CREAT</code></dt> 702<dt><code>O_EXCL</code></dt> 703<dt><code>O_TRUNC</code></dt> 704<dd><p>POSIX open flags. 705</p> 706</dd> 707<dt><code>O_TEXT</code></dt> 708<dd><p>(Windows specific). Open the file in text mode. The default is binary mode. 709</p> 710</dd> 711<dt><code>close(fd)</code></dt> 712<dd><p>Close the file handle <code>fd</code>. 713</p> 714</dd> 715<dt><code>seek(fd, offset, whence)</code></dt> 716<dd><p>Seek in the file. Use <code>std.SEEK_*</code> for <code>whence</code>. 717</p> 718</dd> 719<dt><code>read(fd, buffer, offset, length)</code></dt> 720<dd><p>Read <code>length</code> bytes from the file handle <code>fd</code> to the 721ArrayBuffer <code>buffer</code> at byte position <code>offset</code>. 722Return the number of read bytes or < 0 if error. 723</p> 724</dd> 725<dt><code>write(fd, buffer, offset, length)</code></dt> 726<dd><p>Write <code>length</code> bytes to the file handle <code>fd</code> from the 727ArrayBuffer <code>buffer</code> at byte position <code>offset</code>. 728Return the number of written bytes or < 0 if error. 729</p> 730</dd> 731<dt><code>isatty(fd)</code></dt> 732<dd><p>Return <code>true</code> is <code>fd</code> is a TTY (terminal) handle. 733</p> 734</dd> 735<dt><code>ttyGetWinSize(fd)</code></dt> 736<dd><p>Return the TTY size as <code>[width, height]</code> or <code>null</code> if not available. 737</p> 738</dd> 739<dt><code>ttySetRaw(fd)</code></dt> 740<dd><p>Set the TTY in raw mode. 741</p> 742</dd> 743<dt><code>remove(filename)</code></dt> 744<dd><p>Remove a file. Return 0 if OK or < 0 if error. 745</p> 746</dd> 747<dt><code>rename(oldname, newname)</code></dt> 748<dd><p>Rename a file. Return 0 if OK or < 0 if error. 749</p> 750</dd> 751<dt><code>realpath(path)</code></dt> 752<dd><p>Return <code>[str, err]</code> where <code>str</code> is the canonicalized absolute 753pathname of <code>path</code> and <code>err</code> the error code. 754</p> 755</dd> 756<dt><code>getcwd()</code></dt> 757<dd><p>Return <code>[str, err]</code> where <code>str</code> is the current working directory 758and <code>err</code> the error code. 759</p> 760</dd> 761<dt><code>mkdir(path, mode = 0o777)</code></dt> 762<dd><p>Create a directory at <code>path</code>. Return the error code. 763</p> 764</dd> 765<dt><code>stat(path)</code></dt> 766<dt><code>lstat(path)</code></dt> 767<dd> 768<p>Return <code>[obj, err]</code> where <code>obj</code> is an object containing the 769file status of <code>path</code>. <code>err</code> is the error code. The 770following fields are defined in <code>obj</code>: dev, ino, mode, nlink, 771uid, gid, rdev, size, blocks, atime, mtime, ctime. The times are 772specified in milliseconds since 1970. <code>lstat()</code> is the same as 773<code>stat()</code> excepts that it returns information about the link 774itself. 775</p> 776</dd> 777<dt><code>S_IFMT</code></dt> 778<dt><code>S_IFIFO</code></dt> 779<dt><code>S_IFCHR</code></dt> 780<dt><code>S_IFDIR</code></dt> 781<dt><code>S_IFBLK</code></dt> 782<dt><code>S_IFREG</code></dt> 783<dt><code>S_IFSOCK</code></dt> 784<dt><code>S_IFLNK</code></dt> 785<dt><code>S_ISGID</code></dt> 786<dt><code>S_ISUID</code></dt> 787<dd><p>Constants to interpret the <code>mode</code> property returned by 788<code>stat()</code>. They have the same value as in the C system header 789<samp>sys/stat.h</samp>. 790</p> 791</dd> 792<dt><code>utimes(path, atime, mtime)</code></dt> 793<dd><p>Change the access and modification times of the file <code>path</code>. The 794times are specified in milliseconds since 1970. 795</p> 796</dd> 797<dt><code>symlink(target, linkpath)</code></dt> 798<dd><p>Create a link at <code>linkpath</code> containing the string <code>target</code>. 799</p> 800</dd> 801<dt><code>readlink(path)</code></dt> 802<dd><p>Return <code>[str, err]</code> where <code>str</code> is the link target and <code>err</code> 803the error code. 804</p> 805</dd> 806<dt><code>readdir(path)</code></dt> 807<dd><p>Return <code>[array, err]</code> where <code>array</code> is an array of strings 808containing the filenames of the directory <code>path</code>. <code>err</code> is 809the error code. 810</p> 811</dd> 812<dt><code>setReadHandler(fd, func)</code></dt> 813<dd><p>Add a read handler to the file handle <code>fd</code>. <code>func</code> is called 814each time there is data pending for <code>fd</code>. A single read handler 815per file handle is supported. Use <code>func = null</code> to remove the 816hander. 817</p> 818</dd> 819<dt><code>setWriteHandler(fd, func)</code></dt> 820<dd><p>Add a write handler to the file handle <code>fd</code>. <code>func</code> is 821called each time data can be written to <code>fd</code>. A single write 822handler per file handle is supported. Use <code>func = null</code> to remove 823the hander. 824</p> 825</dd> 826<dt><code>signal(signal, func)</code></dt> 827<dd><p>Call the function <code>func</code> when the signal <code>signal</code> 828happens. Only a single handler per signal number is supported. Use 829<code>null</code> to set the default handler or <code>undefined</code> to ignore 830the signal. 831</p> 832</dd> 833<dt><code>SIGINT</code></dt> 834<dt><code>SIGABRT</code></dt> 835<dt><code>SIGFPE</code></dt> 836<dt><code>SIGILL</code></dt> 837<dt><code>SIGSEGV</code></dt> 838<dt><code>SIGTERM</code></dt> 839<dd><p>POSIX signal numbers. 840</p> 841</dd> 842<dt><code>kill(pid, sig)</code></dt> 843<dd><p>Send the signal <code>sig</code> to the process <code>pid</code>. 844</p> 845</dd> 846<dt><code>exec(args[, options])</code></dt> 847<dd><p>Execute a process with the arguments <code>args</code>. <code>options</code> is an 848object containing optional parameters: 849</p> 850<dl compact="compact"> 851<dt><code>block</code></dt> 852<dd><p>Boolean (default = true). If true, wait until the process is 853 termined. In this case, <code>exec</code> return the exit code if positive 854 or the negated signal number if the process was interrupted by a 855 signal. If false, do not block and return the process id of the child. 856</p> 857</dd> 858<dt><code>usePath</code></dt> 859<dd><p>Boolean (default = true). If true, the file is searched in the 860 <code>PATH</code> environment variable. 861</p> 862</dd> 863<dt><code>file</code></dt> 864<dd><p>String (default = <code>args[0]</code>). Set the file to be executed. 865</p> 866</dd> 867<dt><code>cwd</code></dt> 868<dd><p>String. If present, set the working directory of the new process. 869</p> 870</dd> 871<dt><code>stdin</code></dt> 872<dt><code>stdout</code></dt> 873<dt><code>stderr</code></dt> 874<dd><p>If present, set the handle in the child for stdin, stdout or stderr. 875</p> 876</dd> 877</dl> 878 879</dd> 880<dt><code>waitpid(pid, options)</code></dt> 881<dd><p><code>waitpid</code> Unix system call. Return the array <code>[ret, status]</code>. 882</p> 883</dd> 884<dt><code>WNOHANG</code></dt> 885<dd><p>Constant for the <code>options</code> argument of <code>waitpid</code>. 886</p> 887</dd> 888<dt><code>dup(fd)</code></dt> 889<dd><p><code>dup</code> Unix system call. 890</p> 891</dd> 892<dt><code>dup2(oldfd, newfd)</code></dt> 893<dd><p><code>dup2</code> Unix system call. 894</p> 895</dd> 896<dt><code>pipe()</code></dt> 897<dd><p><code>pipe</code> Unix system call. Return two handles as <code>[read_fd, 898write_fd]</code> or null in case of error. 899</p> 900</dd> 901<dt><code>sleep(delay_ms)</code></dt> 902<dd><p>Sleep during <code>delay_ms</code> milliseconds. 903</p> 904</dd> 905<dt><code>setTimeout(func, delay)</code></dt> 906<dd><p>Call the function <code>func</code> after <code>delay</code> ms. Return a handle 907to the timer. 908</p> 909</dd> 910<dt><code>clearTimeout(handle)</code></dt> 911<dd><p>Cancel a timer. 912</p> 913</dd> 914<dt><code>platform</code></dt> 915<dd><p>Return a string representing the platform: <code>"linux"</code>, <code>"darwin"</code>, 916<code>"win32"</code> or <code>"js"</code>. 917</p> 918</dd> 919</dl> 920 921<a name="QuickJS-C-API"></a> 922<h3 class="section">3.4 QuickJS C API</h3> 923 924<p>The C API was designed to be simple and efficient. The C API is 925defined in the header <code>quickjs.h</code>. 926</p> 927<a name="Runtime-and-contexts"></a> 928<h4 class="subsection">3.4.1 Runtime and contexts</h4> 929 930<p><code>JSRuntime</code> represents a Javascript runtime corresponding to an 931object heap. Several runtimes can exist at the same time but they 932cannot exchange objects. Inside a given runtime, no multi-threading is 933supported. 934</p> 935<p><code>JSContext</code> represents a Javascript context (or Realm). Each 936JSContext has its own global objects and system objects. There can be 937several JSContexts per JSRuntime and they can share objects, similary 938to frames of the same origin sharing Javascript objects in a 939web browser. 940</p> 941<a name="JSValue"></a> 942<h4 class="subsection">3.4.2 JSValue</h4> 943 944<p><code>JSValue</code> represents a Javascript value which can be a primitive 945type or an object. Reference counting is used, so it is important to 946explicitely duplicate (<code>JS_DupValue()</code>, increment the reference 947count) or free (<code>JS_FreeValue()</code>, decrement the reference count) 948JSValues. 949</p> 950<a name="C-functions"></a> 951<h4 class="subsection">3.4.3 C functions</h4> 952 953<p>C functions can be created with 954<code>JS_NewCFunction()</code>. <code>JS_SetPropertyFunctionList()</code> is a 955shortcut to easily add functions, setters and getters properties to a 956given object. 957</p> 958<p>Unlike other embedded Javascript engines, there is no implicit stack, 959so C functions get their parameters as normal C parameters. As a 960general rule, C functions take constant <code>JSValue</code>s as parameters 961(so they don’t need to free them) and return a newly allocated (=live) 962<code>JSValue</code>. 963</p> 964<a name="Exceptions"></a> 965<h4 class="subsection">3.4.4 Exceptions</h4> 966 967<p>Exceptions: most C functions can return a Javascript exception. It 968must be explicitely tested and handled by the C code. The specific 969<code>JSValue</code> <code>JS_EXCEPTION</code> indicates that an exception 970occured. The actual exception object is stored in the 971<code>JSContext</code> and can be retrieved with <code>JS_GetException()</code>. 972</p> 973<a name="Script-evaluation"></a> 974<h4 class="subsection">3.4.5 Script evaluation</h4> 975 976<p>Use <code>JS_Eval()</code> to evaluate a script or module source. 977</p> 978<p>If the script or module was compiled to bytecode with <code>qjsc</code>, it 979can be evaluated by calling <code>js_std_eval_binary()</code>. The advantage 980is that no compilation is needed so it is faster and smaller because 981the compiler can be removed from the executable if no <code>eval</code> is 982required. 983</p> 984<p>Note: the bytecode format is linked to a given QuickJS 985version. Moreover, no security check is done before its 986execution. Hence the bytecode should not be loaded from untrusted 987sources. That’s why there is no option to output the bytecode to a 988binary file in <code>qjsc</code>. 989</p> 990<a name="JS-Classes"></a> 991<h4 class="subsection">3.4.6 JS Classes</h4> 992 993<p>C opaque data can be attached to a Javascript object. The type of the 994C opaque data is determined with the class ID (<code>JSClassID</code>) of 995the object. Hence the first step is to register a new class ID and JS 996class (<code>JS_NewClassID()</code>, <code>JS_NewClass()</code>). Then you can 997create objects of this class with <code>JS_NewObjectClass()</code> and get or 998set the C opaque point with 999<code>JS_GetOpaque()</code>/<code>JS_SetOpaque()</code>. 1000</p> 1001<p>When defining a new JS class, it is possible to declare a finalizer 1002which is called when the object is destroyed. A <code>gc_mark</code> method 1003can be provided so that the cycle removal algorithm can find the other 1004objects referenced by this object. Other methods are available to 1005define exotic object behaviors. 1006</p> 1007<p>The Class ID are globally allocated (i.e. for all runtimes). The 1008JSClass are allocated per <code>JSRuntime</code>. <code>JS_SetClassProto()</code> 1009is used to define a prototype for a given class in a given 1010JSContext. <code>JS_NewObjectClass()</code> sets this prototype in the 1011created object. 1012</p> 1013<p>Examples are available in <samp>quickjs-libc.c</samp>. 1014</p> 1015<a name="C-Modules"></a> 1016<h4 class="subsection">3.4.7 C Modules</h4> 1017 1018<p>Native ES6 modules are supported and can be dynamically or statically 1019linked. Look at the <samp>test_bjson</samp> and <samp>bjson.so</samp> 1020examples. The standard library <samp>quickjs-libc.c</samp> is also a good example 1021of a native module. 1022</p> 1023<a name="Memory-handling"></a> 1024<h4 class="subsection">3.4.8 Memory handling</h4> 1025 1026<p>Use <code>JS_SetMemoryLimit()</code> to set a global memory allocation limit 1027to a given JSRuntime. 1028</p> 1029<p>Custom memory allocation functions can be provided with 1030<code>JS_NewRuntime2()</code>. 1031</p> 1032<p>The maximum system stack size can be set with <code>JS_SetMaxStackSize()</code>. 1033</p> 1034<a name="Execution-timeout-and-interrupts"></a> 1035<h4 class="subsection">3.4.9 Execution timeout and interrupts</h4> 1036 1037<p>Use <code>JS_SetInterruptHandler()</code> to set a callback which is 1038regularly called by the engine when it is executing code. This 1039callback can be used to implement an execution timeout. 1040</p> 1041<p>It is used by the command line interpreter to implement a 1042<code>Ctrl-C</code> handler. 1043</p> 1044<a name="Internals"></a> 1045<h2 class="chapter">4 Internals</h2> 1046 1047<a name="Bytecode"></a> 1048<h3 class="section">4.1 Bytecode</h3> 1049 1050<p>The compiler generates bytecode directly with no intermediate 1051representation such as a parse tree, hence it is very fast. Several 1052optimizations passes are done over the generated bytecode. 1053</p> 1054<p>A stack-based bytecode was chosen because it is simple and generates 1055compact code. 1056</p> 1057<p>For each function, the maximum stack size is computed at compile time so that 1058no runtime stack overflow tests are needed. 1059</p> 1060<p>A separate compressed line number table is maintained for the debug 1061information. 1062</p> 1063<p>Access to closure variables is optimized and is almost as fast as local 1064variables. 1065</p> 1066<p>Direct <code>eval</code> in strict mode is optimized. 1067</p> 1068<a name="Executable-generation"></a> 1069<h3 class="section">4.2 Executable generation</h3> 1070 1071<a name="qjsc-compiler-1"></a> 1072<h4 class="subsection">4.2.1 <code>qjsc</code> compiler</h4> 1073 1074<p>The <code>qjsc</code> compiler generates C sources from Javascript files. By 1075default the C sources are compiled with the system compiler 1076(<code>gcc</code> or <code>clang</code>). 1077</p> 1078<p>The generated C source contains the bytecode of the compiled functions 1079or modules. If a full complete executable is needed, it also 1080contains a <code>main()</code> function with the necessary C code to initialize the 1081Javascript engine and to load and execute the compiled functions and 1082modules. 1083</p> 1084<p>Javascript code can be mixed with C modules. 1085</p> 1086<p>In order to have smaller executables, specific Javascript features can 1087be disabled, in particular <code>eval</code> or the regular expressions. The 1088code removal relies on the Link Time Optimization of the system 1089compiler. 1090</p> 1091<a name="Binary-JSON"></a> 1092<h4 class="subsection">4.2.2 Binary JSON</h4> 1093 1094<p><code>qjsc</code> works by compiling scripts or modules and then serializing 1095them to a binary format. A subset of this format (without functions or 1096modules) can be used as binary JSON. The example <samp>test_bjson.js</samp> 1097shows how to use it. 1098</p> 1099<p>Warning: the binary JSON format may change without notice, so it 1100should not be used to store persistent data. The <samp>test_bjson.js</samp> 1101example is only used to test the binary object format functions. 1102</p> 1103<a name="Runtime"></a> 1104<h3 class="section">4.3 Runtime</h3> 1105 1106<a name="Strings"></a> 1107<h4 class="subsection">4.3.1 Strings</h4> 1108 1109<p>Strings are stored either as an 8 bit or a 16 bit array of 1110characters. Hence random access to characters is always fast. 1111</p> 1112<p>The C API provides functions to convert Javascript Strings to C UTF-8 encoded 1113strings. The most common case where the Javascript string contains 1114only ASCII characters involves no copying. 1115</p> 1116<a name="Objects"></a> 1117<h4 class="subsection">4.3.2 Objects</h4> 1118 1119<p>The object shapes (object prototype, property names and flags) are shared 1120between objects to save memory. 1121</p> 1122<p>Arrays with no holes (except at the end of the array) are optimized. 1123</p> 1124<p>TypedArray accesses are optimized. 1125</p> 1126<a name="Atoms"></a> 1127<h4 class="subsection">4.3.3 Atoms</h4> 1128 1129<p>Object property names and some strings are stored as Atoms (unique 1130strings) to save memory and allow fast comparison. Atoms are 1131represented as a 32 bit integer. Half of the atom range is reserved for 1132immediate integer literals from <em>0</em> to <em>2^{31}-1</em>. 1133</p> 1134<a name="Numbers"></a> 1135<h4 class="subsection">4.3.4 Numbers</h4> 1136 1137<p>Numbers are represented either as 32-bit signed integers or 64-bit IEEE-754 1138floating point values. Most operations have fast paths for the 32-bit 1139integer case. 1140</p> 1141<a name="Garbage-collection"></a> 1142<h4 class="subsection">4.3.5 Garbage collection</h4> 1143 1144<p>Reference counting is used to free objects automatically and 1145deterministically. A separate cycle removal pass is done when the allocated 1146memory becomes too large. The cycle removal algorithm only uses the 1147reference counts and the object content, so no explicit garbage 1148collection roots need to be manipulated in the C code. 1149</p> 1150<a name="JSValue-1"></a> 1151<h4 class="subsection">4.3.6 JSValue</h4> 1152 1153<p>It is a Javascript value which can be a primitive type (such as 1154Number, String, ...) or an Object. NaN boxing is used in the 32-bit version 1155to store 64-bit floating point numbers. The representation is 1156optimized so that 32-bit integers and reference counted values can be 1157efficiently tested. 1158</p> 1159<p>In 64-bit code, JSValue are 128-bit large and no NaN boxing is used. The 1160rationale is that in 64-bit code memory usage is less critical. 1161</p> 1162<p>In both cases (32 or 64 bits), JSValue exactly fits two CPU registers, 1163so it can be efficiently returned by C functions. 1164</p> 1165<a name="Function-call"></a> 1166<h4 class="subsection">4.3.7 Function call</h4> 1167 1168<p>The engine is optimized so that function calls are fast. The system 1169stack holds the Javascript parameters and local variables. 1170</p> 1171<a name="RegExp"></a> 1172<h3 class="section">4.4 RegExp</h3> 1173 1174<p>A specific regular expression engine was developped. It is both small 1175and efficient and supports all the ES2020 features including the 1176Unicode properties. As the Javascript compiler, it directly generates 1177bytecode without a parse tree. 1178</p> 1179<p>Backtracking with an explicit stack is used so that there is no 1180recursion on the system stack. Simple quantizers are specifically 1181optimized to avoid recursions. 1182</p> 1183<p>Infinite recursions coming from quantizers with empty terms are 1184avoided. 1185</p> 1186<p>The full regexp library weights about 15 KiB (x86 code), excluding the 1187Unicode library. 1188</p> 1189<a name="Unicode"></a> 1190<h3 class="section">4.5 Unicode</h3> 1191 1192<p>A specific Unicode library was developped so that there is no 1193dependency on an external large Unicode library such as ICU. All the 1194Unicode tables are compressed while keeping a reasonnable access 1195speed. 1196</p> 1197<p>The library supports case conversion, Unicode normalization, Unicode 1198script queries, Unicode general category queries and all Unicode 1199binary properties. 1200</p> 1201<p>The full Unicode library weights about 45 KiB (x86 code). 1202</p> 1203<a name="BigInt-and-BigFloat"></a> 1204<h3 class="section">4.6 BigInt and BigFloat</h3> 1205 1206<p>BigInt and BigFloat are implemented with the <code>libbf</code> 1207library<a name="DOCF7" href="#FOOT7"><sup>7</sup></a>. It weights about 60 1208KiB (x86 code) and provides arbitrary precision IEEE 754 floating 1209point operations and transcendental functions with exact rounding. 1210</p> 1211<a name="License"></a> 1212<h2 class="chapter">5 License</h2> 1213 1214<p>QuickJS is released under the MIT license. 1215</p> 1216<p>Unless otherwise specified, the QuickJS sources are copyright Fabrice 1217Bellard and Charlie Gordon. 1218</p> 1219<div class="footnote"> 1220<hr> 1221<h4 class="footnotes-heading">Footnotes</h4> 1222 1223<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3> 1224<p><a href="https://www.ecma-international.org/ecma-262/10.0">https://www.ecma-international.org/ecma-262/10.0</a></p> 1225<h3><a name="FOOT2" href="#DOCF2">(2)</a></h3> 1226<p><a href="https://github.com/tc39/test262">https://github.com/tc39/test262</a></p> 1227<h3><a name="FOOT3" href="#DOCF3">(3)</a></h3> 1228<p><a href="https://tc39.github.io/ecma262/">https://tc39.github.io/ecma262/</a></p> 1229<h3><a name="FOOT4" href="#DOCF4">(4)</a></h3> 1230<p>The old ES5.1 tests can be extracted with 1231<code>git clone --single-branch --branch es5-tests 1232https://github.com/tc39/test262.git test262o</code></p> 1233<h3><a name="FOOT5" href="#DOCF5">(5)</a></h3> 1234<p><a href="https://github.com/bterlson/test262-harness">https://github.com/bterlson/test262-harness</a></p> 1235<h3><a name="FOOT6" href="#DOCF6">(6)</a></h3> 1236<p>We believe the current specification of tails calls is too complicated and presents limited practical interests.</p> 1237<h3><a name="FOOT7" href="#DOCF7">(7)</a></h3> 1238<p><a href="https://bellard.org/libbf">https://bellard.org/libbf</a></p> 1239</div> 1240<hr> 1241 1242 1243 1244</body> 1245</html> 1246