| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | --- | 
					
						
							|  |  |  | title: JavaScript Engines | 
					
						
							| 
									
										
										
										
											2023-02-28 11:40:44 +00:00
										 |  |  | pagination_prev: demos/bigdata/index | 
					
						
							|  |  |  | pagination_next: solutions/input | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import current from '/version.js'; | 
					
						
							|  |  |  | import Tabs from '@theme/Tabs'; | 
					
						
							|  |  |  | import TabItem from '@theme/TabItem'; | 
					
						
							| 
									
										
										
										
											2023-09-22 06:32:55 +00:00
										 |  |  | import CodeBlock from '@theme/CodeBlock'; | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | import EngineData from '/data/engines.js' | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | [SheetJS](https://sheetjs.com) is a JavaScript library for reading and writing | 
					
						
							|  |  |  | data from spreadsheets. | 
					
						
							| 
									
										
										
										
											2023-02-13 04:07:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | JavaScript code cannot be directly executed on most modern computers. A software | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | component ("JavaScript engine") executes code. After embedding a JS engine, | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | programs can leverage SheetJS libraries to process spreadsheets and data. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | The demos in this section showcase a number of JS engines and language bindings. | 
					
						
							|  |  |  | In each case, we will build a sample application that embeds a JS engine, loads | 
					
						
							|  |  |  | SheetJS library scripts, and reads and writes spreadsheet files. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## General Caveats
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | There are many JS engines with different design goals. Some are designed for | 
					
						
							|  |  |  | low-power or low-memory environments. Others aim for interoperability with | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | specific programming languages or environments. Typically they support ES3 and | 
					
						
							|  |  |  | are capable of running SheetJS code. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | Common browser and NodeJS APIs are often missing from light-weight JS engines. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | **Global** | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | Some engines do not provide `globalThis` or `global` or `window`. A `global` | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | variable can be exposed in one line that should be run in the JS engine: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | var global = (function(){ return this; }).call(null); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | **Console** | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 09:26:06 +00:00
										 |  |  | Some engines do not provide a `console` object but offer other ways to print to | 
					
						
							|  |  |  | standard output. For example, Hermes[^1] provides `print()`. A `console` object | 
					
						
							|  |  |  | should be created using the engine print function: | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | var console = { log: function(x) { print(x); } }; | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | **Binary Data** | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | Some engines do not provide easy ways to exchange binary data. For example, some | 
					
						
							|  |  |  | libraries pass null-terminated arrays, which would truncate XLSX, XLS, and other | 
					
						
							|  |  |  | exports. APIs that accept pointers without length should be avoided. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | Base64 strings are safe, as they do not use null characters, but should only be | 
					
						
							|  |  |  | used when there is no safe way to pass `ArrayBuffer` or `Uint8Array` objects. | 
					
						
							|  |  |  | The SheetJS `read`[^2] and `write`[^3] methods directly support Base64 strings. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | **Byte Conventions** | 
					
						
							| 
									
										
										
										
											2023-05-22 08:06:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-28 17:13:57 +00:00
										 |  |  | Java has no native concept of unsigned bytes. Values in a `byte[]` are limited | 
					
						
							| 
									
										
										
										
											2023-05-22 08:06:09 +00:00
										 |  |  | to the range `-128 .. 127`. They need to be fixed within the JS engine. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Some engines support typed arrays. The `Uint8Array` constructor will fix values: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | var signed_data = [-48, -49, 17, -32, /* ... */]; // 0xD0 0xCF 0x11 0xE0 ... | 
					
						
							|  |  |  | var fixed_data = new Uint8Array(signed_data); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | When `Uint8Array` is not supported, values can be fixed with bitwise operations: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | var signed_data = [-48, -49, 17, -32, /* ... */]; // 0xD0 0xCF 0x11 0xE0 ... | 
					
						
							|  |  |  | var fixed_data = new Array(signed_data.length); | 
					
						
							|  |  |  | for(var i = 0; i < signed_data.length; ++i) fixed_data[i] = signed_data[i] & 0xFF; | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 04:07:25 +00:00
										 |  |  | ## Engines
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | :::info pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Demos are tested across multiple operating systems (Windows, MacOS and Linux) | 
					
						
							|  |  |  | across multiple architectures (x64 and ARM64). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ::: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <EngineData/> | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Boa
 | 
					
						
							| 
									
										
										
										
											2023-05-22 08:06:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Boa is an embeddable JS engine written in Rust. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/boa). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### ChakraCore
 | 
					
						
							| 
									
										
										
										
											2023-04-09 06:58:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ChakraCore is an embeddable JS engine written in C++. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/chakra). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Duktape
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 04:07:25 +00:00
										 |  |  | Duktape is an embeddable JS engine written in C. It has been ported to a number | 
					
						
							|  |  |  | of exotic architectures and operating systems. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 04:07:25 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/duktape). | 
					
						
							| 
									
										
										
										
											2024-03-12 06:47:52 +00:00
										 |  |  | The demo includes examples in C, Perl, PHP, Python and Zig. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Goja
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-14 06:54:02 +00:00
										 |  |  | Goja is a pure Go implementation of ECMAScript 5. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-14 06:54:02 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/goja). | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Hermes
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-30 06:41:09 +00:00
										 |  |  | Hermes is an embeddable JS engine written in C++. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-30 06:41:09 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/hermes). | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### JavaScriptCore
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-23 03:20:02 +00:00
										 |  |  | iOS and MacOS ship with the JavaScriptCore framework for running JS code from | 
					
						
							| 
									
										
										
										
											2023-02-13 04:07:25 +00:00
										 |  |  | Swift and Objective-C. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 04:07:25 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/jsc). | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### JerryScript
 | 
					
						
							| 
									
										
										
										
											2022-08-18 08:41:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | JerryScript is a lightweight JavaScript engine designed for use in low-memory | 
					
						
							| 
									
										
										
										
											2024-01-23 09:26:06 +00:00
										 |  |  | environments including microcontrollers. | 
					
						
							| 
									
										
										
										
											2023-09-22 06:32:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 09:26:06 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/jerryscript). | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Jint
 | 
					
						
							| 
									
										
										
										
											2023-09-17 04:57:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Jint is an embeddable JS engine for .NET written in C#. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/jint). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Nashorn
 | 
					
						
							| 
									
										
										
										
											2023-03-28 04:57:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Nashorn shipped with some versions of Java.  It is now a standalone library. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/nashorn). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### QuickJS
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | QuickJS is an embeddable JS engine written in C.  It provides a separate set of | 
					
						
							|  |  |  | functions for interacting with the filesystem and the global object.  It can run | 
					
						
							|  |  |  | the standalone browser scripts. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-12 06:25:57 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/quickjs). | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### Rhino
 | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-15 01:00:49 +00:00
										 |  |  | Rhino is an ES3+ engine in Java. | 
					
						
							| 
									
										
										
										
											2022-08-08 06:59:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-15 01:00:49 +00:00
										 |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/rhino). | 
					
						
							| 
									
										
										
										
											2023-05-22 08:06:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 03:29:45 +00:00
										 |  |  | #### V8
 | 
					
						
							| 
									
										
										
										
											2023-05-22 08:06:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | V8 is an embeddable JS engine written in C++. It powers Chromium and Chrome, | 
					
						
							|  |  |  | NodeJS and Deno, Adobe UXP and other platforms. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This demo has been moved [to a dedicated page](/docs/demos/engines/v8). | 
					
						
							|  |  |  | The demo includes examples in C++ and Rust. | 
					
						
							| 
									
										
										
										
											2023-08-03 02:49:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-12 01:04:37 +00:00
										 |  |  | The ["Python + Pandas" demo](/docs/demos/math/pandas) uses V8 with Python. | 
					
						
							| 
									
										
										
										
											2023-08-03 02:49:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-15 02:52:56 +00:00
										 |  |  | [^1]: See ["Initialize Hermes"](/docs/demos/engines/hermes#initialize-hermes) in the Hermes demo. | 
					
						
							|  |  |  | [^2]: See [`read` in "Reading Files"](/docs/api/parse-options) | 
					
						
							|  |  |  | [^3]: See [`write` in "Writing Files"](/docs/api/write-options) |