├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── quickjs-2019-07-09 ├── Makefile ├── TODO ├── VERSION ├── bjson.c ├── cutils.c ├── cutils.h ├── doc │ ├── jsbignum.html │ ├── jsbignum.pdf │ ├── jsbignum.texi │ ├── quickjs.html │ ├── quickjs.pdf │ └── quickjs.texi ├── examples │ ├── c_module.js │ ├── fib.c │ ├── fib_module.js │ ├── hello.js │ ├── hello_module.js │ └── pi.js ├── jscompress.c ├── libbf.c ├── libbf.h ├── libregexp-opcode.h ├── libregexp.c ├── libregexp.h ├── libunicode-table.h ├── libunicode.c ├── libunicode.h ├── list.h ├── qjs.c ├── qjsc.c ├── qjscalc.js ├── quickjs-atom.h ├── quickjs-libc.c ├── quickjs-libc.h ├── quickjs-opcode.h ├── quickjs.c ├── quickjs.h ├── readme.txt ├── release.sh ├── repl.js ├── run-test262.c ├── test262.conf ├── test262_errors.txt ├── test262bn.conf ├── test262bn_errors.txt ├── test262o.conf ├── test262o_errors.txt ├── tests │ ├── microbench.js │ ├── test262.patch │ ├── test_bignum.js │ ├── test_bjson.js │ ├── test_builtin.js │ ├── test_closure.js │ ├── test_loop.js │ ├── test_op.js │ └── test_std.js ├── unicode_gen.c ├── unicode_gen_def.h └── wrapper-helpers.c ├── quickjs-2019-07-28 ├── Changelog ├── Makefile ├── TODO ├── VERSION ├── bjson.c ├── cutils.c ├── cutils.h ├── doc │ ├── jsbignum.html │ ├── jsbignum.pdf │ ├── jsbignum.texi │ ├── quickjs.html │ ├── quickjs.pdf │ └── quickjs.texi ├── examples │ ├── c_module.js │ ├── fib.c │ ├── fib_module.js │ ├── hello.js │ ├── hello_module.js │ └── pi.js ├── jscompress.c ├── libbf.c ├── libbf.h ├── libregexp-opcode.h ├── libregexp.c ├── libregexp.h ├── libunicode-table.h ├── libunicode.c ├── libunicode.h ├── list.h ├── qjs.c ├── qjsc.c ├── qjscalc.js ├── quickjs-atom.h ├── quickjs-libc.c ├── quickjs-libc.h ├── quickjs-opcode.h ├── quickjs.c ├── quickjs.h ├── readme.txt ├── release.sh ├── repl.js ├── run-test262.c ├── test262.conf ├── test262_errors.txt ├── test262bn.conf ├── test262bn_errors.txt ├── test262o.conf ├── test262o_errors.txt ├── tests │ ├── microbench.js │ ├── test262.patch │ ├── test_bignum.js │ ├── test_bjson.js │ ├── test_builtin.js │ ├── test_closure.js │ ├── test_loop.js │ ├── test_op.js │ └── test_std.js ├── unicode_download.sh ├── unicode_gen.c ├── unicode_gen_def.h └── wrapper-helpers.c ├── src └── lib.rs └── wrapper.h /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "quickjs-sys" 3 | version = "0.1.0" 4 | authors = ["seu "] 5 | edition = "2018" 6 | license = "MIT" 7 | repository = "https://github.com/flanfly/quickjs-sys" 8 | homepage = "https://bellard.org/quickjs/" 9 | documentation = "https://bellard.org/quickjs/quickjs.html" 10 | description = "Low-level Rust bindings for Fabrice Bellards QuickJS Javascript Engine" 11 | 12 | [dependencies] 13 | 14 | [build-dependencies] 15 | bindgen = "0.50" 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2018 Fabrice Bellard 2 | Copyright (c) 2017-2018 Charlie Gordon 3 | Copyright (c) 2019 Kai Michaelis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # quickjs-sys 2 | 3 | Low-level Rust bindings for the [QuickJS Javascript Engine](https://bellard.org/quickjs/). 4 | 5 | ```toml 6 | # Cargo.toml 7 | [dependencies] 8 | quickjs-sys = "0.1" 9 | ``` 10 | 11 | The documentation of the C API can be found 12 | [here](https://bellard.org/quickjs/quickjs.html). 13 | 14 | # License 15 | 16 | The QuickJS library by Fabrice Bellard and Charlie Gordon as well as 17 | this bindings are licensed under the MIT license, ([LICENSE](LICENSE) or 18 | https://opensource.org/licenses/MIT) 19 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | extern crate bindgen; 2 | 3 | use std::env; 4 | use std::path::PathBuf; 5 | use std::process::Command; 6 | 7 | const QUICKJS_VERSION: &'static str = "quickjs-2019-07-28"; 8 | 9 | fn main() { 10 | // compile quickjs 11 | if cfg!(target_os = "linux") || cfg!(target_os = "macos") { 12 | Command::new("make") 13 | .arg("libquickjs.bn.lto.a") 14 | .current_dir(QUICKJS_VERSION) 15 | .status() 16 | .expect("failed to make!"); 17 | } else { 18 | unimplemented!() 19 | } 20 | 21 | println!("cargo:rustc-link-search={}/{}", env::var("CARGO_MANIFEST_DIR").unwrap(), QUICKJS_VERSION); 22 | println!("cargo:rustc-link-lib=static=quickjs.bn.lto"); 23 | 24 | // The bindgen::Builder is the main entry point 25 | // to bindgen, and lets you build up options for 26 | // the resulting bindings. 27 | let bindings = bindgen::Builder::default() 28 | // The input header we would like to generate 29 | // bindings for. 30 | .header("wrapper.h") 31 | .clang_arg(format!("-I{}", QUICKJS_VERSION)) 32 | // Finish the builder and generate the bindings. 33 | .generate() 34 | // Unwrap the Result and panic on failure. 35 | .expect("Unable to generate bindings"); 36 | 37 | // Write the bindings to the $OUT_DIR/bindings.rs file. 38 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 39 | bindings 40 | .write_to_file(out_path.join("bindings.rs")) 41 | .expect("Couldn't write bindings!"); 42 | } 43 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/TODO: -------------------------------------------------------------------------------- 1 | - 64-bit atoms in 64-bit mode? 2 | - rename CONFIG_ALL_UNICODE, CONFIG_BIGNUM, CONFIG_ATOMICS, CONFIG_CHECK_JSVALUE ? 3 | - unify coding style and naming conventions 4 | - use names from the ECMA spec in library implementation 5 | - modules: if no ".", use a well known module loading path ? 6 | - use JSHoistedDef only for global variables (JSHoistedDef.var_name != JS_ATOM_NULL) 7 | - add index in JSVarDef and is_arg flag to merge args and vars in JSFunctionDef 8 | - replace most JSVarDef flags with var_type enumeration 9 | - use byte code emitters with typed arguments (for clarity) 10 | - use 2 bytecode DynBufs in JSFunctionDef, one for reading, one for writing 11 | and use the same wrappers in all phases 12 | - use more generic method for line numbers in resolve_variables and resolve_labels 13 | - bignum: 14 | - fix div/pow div by zero exception in doc & code in bigint mode 15 | - fix Atomics support 16 | 17 | Memory: 18 | - test border cases for max number of atoms, object properties, string length 19 | - add emergency malloc mode for out of memory exceptions. 20 | - test all DynBuf memory errors 21 | - test all js_realloc memory errors 22 | - bignum: handle memory errors 23 | - use memory pools for objects, etc? 24 | - improve JS_ComputeMemoryUsage() with more info 25 | 26 | Optimizations: 27 | - use auto-init properties for more global objects 28 | - reuse stack slots for disjoint scopes, if strip 29 | - optimize `for of` iterator for built-in array objects 30 | - add heuristic to avoid some cycles in closures 31 | - small String (0-2 charcodes) with immediate storage 32 | - perform static string concatenation at compile time 33 | - optimize string concatenation with ropes or miniropes? 34 | - add implicit numeric strings for Uint32 numbers? 35 | - optimize `s += a + b`, `s += a.b` and similar simple expressions 36 | - ensure string canonical representation and optimise comparisons and hashes? 37 | - remove JSObject.first_weak_ref, use bit+context based hashed array for weak references 38 | - optimize function storage with length and name accessors? 39 | - property access optimization on the global object, functions, 40 | prototypes and special non extensible objects. 41 | - create object literals with the correct length by backpatching length argument 42 | - remove redundant set_loc_uninitialized/check_uninitialized opcodes 43 | - peephole optim: push_atom_value, to_propkey -> push_atom_value 44 | - peephole optim: put_loc x, get_loc_check x -> set_loc x 45 | - comparative performance benchmark 46 | - use variable name when throwing uninitialized exception if available 47 | - convert slow array to fast array when all properties != length are numeric 48 | - optimize destructuring assignments for global and local variables 49 | - implement some form of tail-call-optimization 50 | - debugger keyword support 51 | - optmize OP_apply 52 | - optimize f(...b) 53 | 54 | Extensions: 55 | - support more features in [features] section 56 | - add TC39 stage 3 proposals: String.prototype.matchAll, Symbol.matchAll 57 | - fix preprocessor bug if nested #ifdef in jscompress.c 58 | - add built-in preprocessor in compiler, get rid of jscompress 59 | handle #if, #ifdef, #line, limited support for #define 60 | - limited support for web assembly 61 | - get rid of __loadScript, use more common name 62 | - BSD sockets 63 | - Process or thread control 64 | - use custom printf to avoid C library compatibility issues 65 | - use custom timezone support to avoid C library compatibility issues 66 | 67 | REPL: 68 | - strip internal functions from stack trace 69 | - readline: support MS Windows terminal 70 | - readline: handle dynamic terminal resizing 71 | - multiline editing 72 | - debugger 73 | - runtime object and function inspectors 74 | - interactive object browser 75 | - use more generic approach to display evaluation results 76 | - improve directive handling: dispatch, colorize, completion... 77 | - save history 78 | - close all predefined methods in repl.js and jscalc.js 79 | 80 | Test262o: 0/11266 errors, 459 excluded 81 | Test262: 0/55855 errors, 504 excluded, 1559 skipped 82 | Test262bn: 0/57176 errors, 724 excluded, 675 skipped 83 | test262 commit: 94b1e80ab3440413df916cd56d29c5a2fa2ac451 84 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/VERSION: -------------------------------------------------------------------------------- 1 | 2019-07-09 2 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/bjson.c: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS: binary JSON module (test only) 3 | * 4 | * Copyright (c) 2017-2019 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #include "quickjs-libc.h" 25 | #include "cutils.h" 26 | 27 | static JSValue js_bjson_read(JSContext *ctx, JSValueConst this_val, 28 | int argc, JSValueConst *argv) 29 | { 30 | uint8_t *buf; 31 | uint64_t pos, len; 32 | JSValue obj; 33 | size_t size; 34 | 35 | if (JS_ToIndex(ctx, &pos, argv[1])) 36 | return JS_EXCEPTION; 37 | if (JS_ToIndex(ctx, &len, argv[2])) 38 | return JS_EXCEPTION; 39 | buf = JS_GetArrayBuffer(ctx, &size, argv[0]); 40 | if (!buf) 41 | return JS_EXCEPTION; 42 | if (pos + len > size) 43 | return JS_ThrowRangeError(ctx, "array buffer overflow"); 44 | obj = JS_ReadObject(ctx, buf + pos, len, 0); 45 | return obj; 46 | } 47 | 48 | static JSValue js_bjson_write(JSContext *ctx, JSValueConst this_val, 49 | int argc, JSValueConst *argv) 50 | { 51 | size_t len; 52 | uint8_t *buf; 53 | JSValue array; 54 | 55 | buf = JS_WriteObject(ctx, &len, argv[0], 0); 56 | if (!buf) 57 | return JS_EXCEPTION; 58 | array = JS_NewArrayBufferCopy(ctx, buf, len); 59 | js_free(ctx, buf); 60 | return array; 61 | } 62 | 63 | static const JSCFunctionListEntry js_bjson_funcs[] = { 64 | JS_CFUNC_DEF("read", 3, js_bjson_read ), 65 | JS_CFUNC_DEF("write", 1, js_bjson_write ), 66 | }; 67 | 68 | static int js_bjson_init(JSContext *ctx, JSModuleDef *m) 69 | { 70 | return JS_SetModuleExportList(ctx, m, js_bjson_funcs, 71 | countof(js_bjson_funcs)); 72 | } 73 | 74 | #ifdef JS_SHARED_LIBRARY 75 | #define JS_INIT_MODULE js_init_module 76 | #else 77 | #define JS_INIT_MODULE js_init_module_bjson 78 | #endif 79 | 80 | JSModuleDef *JS_INIT_MODULE(JSContext *ctx, const char *module_name) 81 | { 82 | JSModuleDef *m; 83 | m = JS_NewCModule(ctx, module_name, js_bjson_init); 84 | if (!m) 85 | return NULL; 86 | JS_AddModuleExportList(ctx, m, js_bjson_funcs, countof(js_bjson_funcs)); 87 | return m; 88 | } 89 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/cutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * C utilities 3 | * 4 | * Copyright (c) 2017 Fabrice Bellard 5 | * Copyright (c) 2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | #ifndef CUTILS_H 26 | #define CUTILS_H 27 | 28 | #include 29 | #include 30 | 31 | /* set if CPU is big endian */ 32 | #undef WORDS_BIGENDIAN 33 | 34 | #define likely(x) __builtin_expect(!!(x), 1) 35 | #define unlikely(x) __builtin_expect(!!(x), 0) 36 | #define force_inline inline __attribute__((always_inline)) 37 | #define no_inline __attribute__((noinline)) 38 | 39 | #define xglue(x, y) x ## y 40 | #define glue(x, y) xglue(x, y) 41 | #define stringify(s) tostring(s) 42 | #define tostring(s) #s 43 | 44 | #ifndef offsetof 45 | #define offsetof(type, field) ((size_t) &((type *)0)->field) 46 | #endif 47 | #ifndef countof 48 | #define countof(x) (sizeof(x) / sizeof((x)[0])) 49 | #endif 50 | 51 | typedef int BOOL; 52 | 53 | #ifndef FALSE 54 | enum { 55 | FALSE = 0, 56 | TRUE = 1, 57 | }; 58 | #endif 59 | 60 | void pstrcpy(char *buf, int buf_size, const char *str); 61 | char *pstrcat(char *buf, int buf_size, const char *s); 62 | int strstart(const char *str, const char *val, const char **ptr); 63 | int has_suffix(const char *str, const char *suffix); 64 | 65 | static inline int max_int(int a, int b) 66 | { 67 | if (a > b) 68 | return a; 69 | else 70 | return b; 71 | } 72 | 73 | static inline int min_int(int a, int b) 74 | { 75 | if (a < b) 76 | return a; 77 | else 78 | return b; 79 | } 80 | 81 | static inline uint32_t max_uint32(uint32_t a, uint32_t b) 82 | { 83 | if (a > b) 84 | return a; 85 | else 86 | return b; 87 | } 88 | 89 | static inline uint32_t min_uint32(uint32_t a, uint32_t b) 90 | { 91 | if (a < b) 92 | return a; 93 | else 94 | return b; 95 | } 96 | 97 | static inline int64_t max_int64(int64_t a, int64_t b) 98 | { 99 | if (a > b) 100 | return a; 101 | else 102 | return b; 103 | } 104 | 105 | static inline int64_t min_int64(int64_t a, int64_t b) 106 | { 107 | if (a < b) 108 | return a; 109 | else 110 | return b; 111 | } 112 | 113 | /* WARNING: undefined if a = 0 */ 114 | static inline int clz32(unsigned int a) 115 | { 116 | return __builtin_clz(a); 117 | } 118 | 119 | /* WARNING: undefined if a = 0 */ 120 | static inline int clz64(uint64_t a) 121 | { 122 | return __builtin_clzll(a); 123 | } 124 | 125 | /* WARNING: undefined if a = 0 */ 126 | static inline int ctz32(unsigned int a) 127 | { 128 | return __builtin_ctz(a); 129 | } 130 | 131 | /* WARNING: undefined if a = 0 */ 132 | static inline int ctz64(uint64_t a) 133 | { 134 | return __builtin_ctzll(a); 135 | } 136 | 137 | struct __attribute__((packed)) packed_u64 { 138 | uint64_t v; 139 | }; 140 | 141 | struct __attribute__((packed)) packed_u32 { 142 | uint32_t v; 143 | }; 144 | 145 | struct __attribute__((packed)) packed_u16 { 146 | uint16_t v; 147 | }; 148 | 149 | static inline uint64_t get_u64(const uint8_t *tab) 150 | { 151 | return ((const struct packed_u64 *)tab)->v; 152 | } 153 | 154 | static inline int64_t get_i64(const uint8_t *tab) 155 | { 156 | return (int64_t)((const struct packed_u64 *)tab)->v; 157 | } 158 | 159 | static inline void put_u64(uint8_t *tab, uint64_t val) 160 | { 161 | ((struct packed_u64 *)tab)->v = val; 162 | } 163 | 164 | static inline uint32_t get_u32(const uint8_t *tab) 165 | { 166 | return ((const struct packed_u32 *)tab)->v; 167 | } 168 | 169 | static inline int32_t get_i32(const uint8_t *tab) 170 | { 171 | return (int32_t)((const struct packed_u32 *)tab)->v; 172 | } 173 | 174 | static inline void put_u32(uint8_t *tab, uint32_t val) 175 | { 176 | ((struct packed_u32 *)tab)->v = val; 177 | } 178 | 179 | static inline uint32_t get_u16(const uint8_t *tab) 180 | { 181 | return ((const struct packed_u16 *)tab)->v; 182 | } 183 | 184 | static inline int32_t get_i16(const uint8_t *tab) 185 | { 186 | return (int16_t)((const struct packed_u16 *)tab)->v; 187 | } 188 | 189 | static inline void put_u16(uint8_t *tab, uint16_t val) 190 | { 191 | ((struct packed_u16 *)tab)->v = val; 192 | } 193 | 194 | static inline uint32_t get_u8(const uint8_t *tab) 195 | { 196 | return *tab; 197 | } 198 | 199 | static inline int32_t get_i8(const uint8_t *tab) 200 | { 201 | return (int8_t)*tab; 202 | } 203 | 204 | static inline void put_u8(uint8_t *tab, uint8_t val) 205 | { 206 | *tab = val; 207 | } 208 | 209 | static inline uint16_t bswap16(uint16_t x) 210 | { 211 | return (x >> 8) | (x << 8); 212 | } 213 | 214 | static inline uint32_t bswap32(uint32_t v) 215 | { 216 | return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) | 217 | ((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24); 218 | } 219 | 220 | static inline uint64_t bswap64(uint64_t v) 221 | { 222 | return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) | 223 | ((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) | 224 | ((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) | 225 | ((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) | 226 | ((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) | 227 | ((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) | 228 | ((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) | 229 | ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8)); 230 | } 231 | 232 | /* XXX: should take an extra argument to pass slack information to the caller */ 233 | typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size); 234 | 235 | typedef struct DynBuf { 236 | uint8_t *buf; 237 | size_t size; 238 | size_t allocated_size; 239 | BOOL error; /* true if a memory allocation error occurred */ 240 | DynBufReallocFunc *realloc_func; 241 | void *opaque; /* for realloc_func */ 242 | } DynBuf; 243 | 244 | void dbuf_init(DynBuf *s); 245 | void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func); 246 | int dbuf_realloc(DynBuf *s, size_t new_size); 247 | int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len); 248 | int dbuf_put(DynBuf *s, const uint8_t *data, size_t len); 249 | int dbuf_put_self(DynBuf *s, size_t offset, size_t len); 250 | int dbuf_putc(DynBuf *s, uint8_t c); 251 | int dbuf_putstr(DynBuf *s, const char *str); 252 | static inline int dbuf_put_u16(DynBuf *s, uint16_t val) 253 | { 254 | return dbuf_put(s, (uint8_t *)&val, 2); 255 | } 256 | static inline int dbuf_put_u32(DynBuf *s, uint32_t val) 257 | { 258 | return dbuf_put(s, (uint8_t *)&val, 4); 259 | } 260 | static inline int dbuf_put_u64(DynBuf *s, uint64_t val) 261 | { 262 | return dbuf_put(s, (uint8_t *)&val, 8); 263 | } 264 | int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s, 265 | const char *fmt, ...); 266 | void dbuf_free(DynBuf *s); 267 | static inline BOOL dbuf_error(DynBuf *s) { 268 | return s->error; 269 | } 270 | 271 | #define UTF8_CHAR_LEN_MAX 6 272 | 273 | int unicode_to_utf8(uint8_t *buf, unsigned int c); 274 | int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp); 275 | 276 | static inline int from_hex(int c) 277 | { 278 | if (c >= '0' && c <= '9') 279 | return c - '0'; 280 | else if (c >= 'A' && c <= 'F') 281 | return c - 'A' + 10; 282 | else if (c >= 'a' && c <= 'f') 283 | return c - 'a' + 10; 284 | else 285 | return -1; 286 | } 287 | 288 | void rqsort(void *base, size_t nmemb, size_t size, 289 | int (*cmp)(const void *, const void *, void *), 290 | void *arg); 291 | 292 | #endif /* CUTILS_H */ 293 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/doc/jsbignum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-09/doc/jsbignum.pdf -------------------------------------------------------------------------------- /quickjs-2019-07-09/doc/quickjs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-09/doc/quickjs.pdf -------------------------------------------------------------------------------- /quickjs-2019-07-09/examples/c_module.js: -------------------------------------------------------------------------------- 1 | /* example of JS module importing a C module */ 2 | 3 | import { fib } from "./fib.so"; 4 | 5 | console.log("Hello World"); 6 | console.log("fib(10)=", fib(10)); 7 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/examples/fib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS: Example of C module 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #include "../quickjs.h" 25 | 26 | #define countof(x) (sizeof(x) / sizeof((x)[0])) 27 | 28 | static int fib(int n) 29 | { 30 | if (n <= 0) 31 | return 0; 32 | else if (n == 1) 33 | return 1; 34 | else 35 | return fib(n - 1) + fib(n - 2); 36 | } 37 | 38 | static JSValue js_fib(JSContext *ctx, JSValueConst this_val, 39 | int argc, JSValueConst *argv) 40 | { 41 | int n, res; 42 | if (JS_ToInt32(ctx, &n, argv[0])) 43 | return JS_EXCEPTION; 44 | res = fib(n); 45 | return JS_NewInt32(ctx, res); 46 | } 47 | 48 | static const JSCFunctionListEntry js_fib_funcs[] = { 49 | JS_CFUNC_DEF("fib", 1, js_fib ), 50 | }; 51 | 52 | static int js_fib_init(JSContext *ctx, JSModuleDef *m) 53 | { 54 | return JS_SetModuleExportList(ctx, m, js_fib_funcs, 55 | countof(js_fib_funcs)); 56 | } 57 | 58 | #ifdef JS_SHARED_LIBRARY 59 | #define JS_INIT_MODULE js_init_module 60 | #else 61 | #define JS_INIT_MODULE js_init_module_fib 62 | #endif 63 | 64 | JSModuleDef *JS_INIT_MODULE(JSContext *ctx, const char *module_name) 65 | { 66 | JSModuleDef *m; 67 | m = JS_NewCModule(ctx, module_name, js_fib_init); 68 | if (!m) 69 | return NULL; 70 | JS_AddModuleExportList(ctx, m, js_fib_funcs, countof(js_fib_funcs)); 71 | return m; 72 | } 73 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/examples/fib_module.js: -------------------------------------------------------------------------------- 1 | /* fib module */ 2 | export function fib(n) 3 | { 4 | if (n <= 0) 5 | return 0; 6 | else if (n == 1) 7 | return 1; 8 | else 9 | return fib(n - 1) + fib(n - 2); 10 | } 11 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/examples/hello.js: -------------------------------------------------------------------------------- 1 | console.log("Hello World"); 2 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/examples/hello_module.js: -------------------------------------------------------------------------------- 1 | /* example of JS module */ 2 | 3 | import { fib } from "./fib_module.js"; 4 | 5 | console.log("Hello World"); 6 | console.log("fib(10)=", fib(10)); 7 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/examples/pi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * PI computation in Javascript using the QuickJS bignum extensions 3 | */ 4 | "use strict"; 5 | "use bigint"; 6 | 7 | /* compute PI with a precision of 'prec' bits */ 8 | function calc_pi(prec) { 9 | const CHUD_A = 13591409; 10 | const CHUD_B = 545140134; 11 | const CHUD_C = 640320; 12 | const CHUD_C3 = 10939058860032000; /* C^3/24 */ 13 | const CHUD_BITS_PER_TERM = 47.11041313821584202247; /* log2(C/12)*3 */ 14 | 15 | /* return [P, Q, G] */ 16 | function chud_bs(a, b, need_G) { 17 | var c, P, Q, G, P1, Q1, G1, P2, Q2, G2; 18 | if (a == (b - 1)) { 19 | G = (2 * b - 1) * (6 * b - 1) * (6 * b - 5); 20 | P = BigFloat(G * (CHUD_B * b + CHUD_A)); 21 | if (b & 1) 22 | P = -P; 23 | G = BigFloat(G); 24 | Q = BigFloat(b * b * b * CHUD_C3); 25 | } else { 26 | c = (a + b) >> 1; 27 | [P1, Q1, G1] = chud_bs(a, c, true); 28 | [P2, Q2, G2] = chud_bs(c, b, need_G); 29 | P = P1 * Q2 + P2 * G1; 30 | Q = Q1 * Q2; 31 | if (need_G) 32 | G = G1 * G2; 33 | else 34 | G = 0; 35 | } 36 | return [P, Q, G]; 37 | } 38 | 39 | var n, P, Q, G; 40 | /* number of serie terms */ 41 | n = Math.ceil(BigFloatEnv.prec / CHUD_BITS_PER_TERM) + 10; 42 | [P, Q, G] = chud_bs(0, n, false); 43 | Q = Q / (P + Q * CHUD_A); 44 | G = (CHUD_C / 12) * BigFloat.sqrt(CHUD_C); 45 | return Q * G; 46 | } 47 | 48 | (function() { 49 | var r, n_digits, n_bits; 50 | if (typeof scriptArgs != "undefined") { 51 | if (scriptArgs.length < 2) { 52 | print("usage: pi n_digits"); 53 | return; 54 | } 55 | n_digits = scriptArgs[1]; 56 | } else { 57 | n_digits = 1000; 58 | } 59 | n_bits = Math.ceil(n_digits * Math.log2(10)); 60 | /* we add more bits to reduce the probability of bad rounding for 61 | the last digits */ 62 | BigFloatEnv.setPrec( () => { 63 | r = calc_pi(); 64 | print(r.toFixed(n_digits, BigFloatEnv.RNDZ)); 65 | }, n_bits + 32); 66 | })(); 67 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/libregexp-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifdef DEF 26 | 27 | DEF(invalid, 1) /* never used */ 28 | DEF(char, 3) 29 | DEF(char32, 5) 30 | DEF(dot, 1) 31 | DEF(any, 1) /* same as dot but match any character including line terminator */ 32 | DEF(line_start, 1) 33 | DEF(line_end, 1) 34 | DEF(goto, 5) 35 | DEF(split_goto_first, 5) 36 | DEF(split_next_first, 5) 37 | DEF(match, 1) 38 | DEF(save_start, 2) /* save start position */ 39 | DEF(save_end, 2) /* save end position, must come after saved_start */ 40 | DEF(save_reset, 3) /* reset save positions */ 41 | DEF(loop, 5) /* decrement the top the stack and goto if != 0 */ 42 | DEF(push_i32, 5) /* push integer on the stack */ 43 | DEF(drop, 1) 44 | DEF(word_boundary, 1) 45 | DEF(not_word_boundary, 1) 46 | DEF(back_reference, 2) 47 | DEF(backward_back_reference, 2) /* must come after back_reference */ 48 | DEF(range, 3) /* variable length */ 49 | DEF(range32, 3) /* variable length */ 50 | DEF(lookahead, 5) 51 | DEF(negative_lookahead, 5) 52 | DEF(push_char_pos, 1) /* push the character position on the stack */ 53 | DEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character 54 | position */ 55 | DEF(prev, 1) /* go to the previous char */ 56 | DEF(simple_greedy_quant, 17) 57 | 58 | #endif /* DEF */ 59 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/libregexp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBREGEXP_H 25 | #define LIBREGEXP_H 26 | 27 | #include 28 | 29 | #include "libunicode.h" 30 | 31 | #define LRE_BOOL int /* for documentation purposes */ 32 | 33 | #define LRE_FLAG_GLOBAL (1 << 0) 34 | #define LRE_FLAG_IGNORECASE (1 << 1) 35 | #define LRE_FLAG_MULTILINE (1 << 2) 36 | #define LRE_FLAG_DOTALL (1 << 3) 37 | #define LRE_FLAG_UTF16 (1 << 4) 38 | #define LRE_FLAG_STICKY (1 << 5) 39 | 40 | #define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */ 41 | 42 | uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size, 43 | const char *buf, size_t buf_len, int re_flags, 44 | void *opaque); 45 | int lre_get_capture_count(const uint8_t *bc_buf); 46 | int lre_get_flags(const uint8_t *bc_buf); 47 | int lre_exec(uint8_t **capture, 48 | const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen, 49 | int cbuf_type, void *opaque); 50 | 51 | int lre_parse_escape(const uint8_t **pp, int allow_utf16); 52 | LRE_BOOL lre_is_space(int c); 53 | 54 | /* must be provided by the user */ 55 | LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size); 56 | void *lre_realloc(void *opaque, void *ptr, size_t size); 57 | 58 | /* JS identifier test */ 59 | extern uint32_t const lre_id_start_table_ascii[4]; 60 | extern uint32_t const lre_id_continue_table_ascii[4]; 61 | 62 | static inline int lre_js_is_ident_first(int c) 63 | { 64 | if ((uint32_t)c < 128) { 65 | return (lre_id_start_table_ascii[c >> 5] >> (c & 31)) & 1; 66 | } else { 67 | #ifdef CONFIG_ALL_UNICODE 68 | return lre_is_id_start(c); 69 | #else 70 | return !lre_is_space(c); 71 | #endif 72 | } 73 | } 74 | 75 | static inline int lre_js_is_ident_next(int c) 76 | { 77 | if ((uint32_t)c < 128) { 78 | return (lre_id_continue_table_ascii[c >> 5] >> (c & 31)) & 1; 79 | } else { 80 | /* ZWNJ and ZWJ are accepted in identifiers */ 81 | #ifdef CONFIG_ALL_UNICODE 82 | return lre_is_id_continue(c) || c == 0x200C || c == 0x200D; 83 | #else 84 | return !lre_is_space(c) || c == 0x200C || c == 0x200D; 85 | #endif 86 | } 87 | } 88 | 89 | #undef LRE_BOOL 90 | 91 | #endif /* LIBREGEXP_H */ 92 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/libunicode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Unicode utilities 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBUNICODE_H 25 | #define LIBUNICODE_H 26 | 27 | #include 28 | 29 | #define LRE_BOOL int /* for documentation purposes */ 30 | 31 | /* define it to include all the unicode tables (40KB larger) */ 32 | #define CONFIG_ALL_UNICODE 33 | 34 | #define LRE_CC_RES_LEN_MAX 3 35 | 36 | typedef enum { 37 | UNICODE_NFC, 38 | UNICODE_NFD, 39 | UNICODE_NFKC, 40 | UNICODE_NFKD, 41 | } UnicodeNormalizationEnum; 42 | 43 | int lre_case_conv(uint32_t *res, uint32_t c, int conv_type); 44 | LRE_BOOL lre_is_cased(uint32_t c); 45 | LRE_BOOL lre_is_case_ignorable(uint32_t c); 46 | 47 | /* char ranges */ 48 | 49 | typedef struct { 50 | int len; /* in points, always even */ 51 | int size; 52 | uint32_t *points; /* points sorted by increasing value */ 53 | void *mem_opaque; 54 | void *(*realloc_func)(void *opaque, void *ptr, size_t size); 55 | } CharRange; 56 | 57 | typedef enum { 58 | CR_OP_UNION, 59 | CR_OP_INTER, 60 | CR_OP_XOR, 61 | } CharRangeOpEnum; 62 | 63 | void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); 64 | void cr_free(CharRange *cr); 65 | int cr_realloc(CharRange *cr, int size); 66 | int cr_copy(CharRange *cr, const CharRange *cr1); 67 | 68 | static inline int cr_add_point(CharRange *cr, uint32_t v) 69 | { 70 | if (cr->len >= cr->size) { 71 | if (cr_realloc(cr, cr->len + 1)) 72 | return -1; 73 | } 74 | cr->points[cr->len++] = v; 75 | return 0; 76 | } 77 | 78 | static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2) 79 | { 80 | if ((cr->len + 2) > cr->size) { 81 | if (cr_realloc(cr, cr->len + 2)) 82 | return -1; 83 | } 84 | cr->points[cr->len++] = c1; 85 | cr->points[cr->len++] = c2; 86 | return 0; 87 | } 88 | 89 | int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len); 90 | 91 | static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2) 92 | { 93 | uint32_t b_pt[2]; 94 | b_pt[0] = c1; 95 | b_pt[1] = c2 + 1; 96 | return cr_union1(cr, b_pt, 2); 97 | } 98 | 99 | int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len, 100 | const uint32_t *b_pt, int b_len, int op); 101 | 102 | int cr_invert(CharRange *cr); 103 | 104 | #ifdef CONFIG_ALL_UNICODE 105 | 106 | LRE_BOOL lre_is_id_start(uint32_t c); 107 | LRE_BOOL lre_is_id_continue(uint32_t c); 108 | 109 | int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len, 110 | UnicodeNormalizationEnum n_type, 111 | void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); 112 | 113 | /* Unicode character range functions */ 114 | 115 | int unicode_script(CharRange *cr, 116 | const char *script_name, LRE_BOOL is_ext); 117 | int unicode_general_category(CharRange *cr, const char *gc_name); 118 | int unicode_prop(CharRange *cr, const char *prop_name); 119 | 120 | #endif /* CONFIG_ALL_UNICODE */ 121 | 122 | #undef LRE_BOOL 123 | 124 | #endif /* LIBUNICODE_H */ 125 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Linux klist like system 3 | * 4 | * Copyright (c) 2016-2017 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIST_H 25 | #define LIST_H 26 | 27 | #ifndef NULL 28 | #include 29 | #endif 30 | 31 | struct list_head { 32 | struct list_head *prev; 33 | struct list_head *next; 34 | }; 35 | 36 | #define LIST_HEAD_INIT(el) { &(el), &(el) } 37 | 38 | /* return the pointer of type 'type *' containing 'el' as field 'member' */ 39 | #define list_entry(el, type, member) \ 40 | ((type *)((uint8_t *)(el) - offsetof(type, member))) 41 | 42 | static inline void init_list_head(struct list_head *head) 43 | { 44 | head->prev = head; 45 | head->next = head; 46 | } 47 | 48 | /* insert 'el' between 'prev' and 'next' */ 49 | static inline void __list_add(struct list_head *el, 50 | struct list_head *prev, struct list_head *next) 51 | { 52 | prev->next = el; 53 | el->prev = prev; 54 | el->next = next; 55 | next->prev = el; 56 | } 57 | 58 | /* add 'el' at the head of the list 'head' (= after element head) */ 59 | static inline void list_add(struct list_head *el, struct list_head *head) 60 | { 61 | __list_add(el, head, head->next); 62 | } 63 | 64 | /* add 'el' at the end of the list 'head' (= before element head) */ 65 | static inline void list_add_tail(struct list_head *el, struct list_head *head) 66 | { 67 | __list_add(el, head->prev, head); 68 | } 69 | 70 | static inline void list_del(struct list_head *el) 71 | { 72 | struct list_head *prev, *next; 73 | prev = el->prev; 74 | next = el->next; 75 | prev->next = next; 76 | next->prev = prev; 77 | el->prev = NULL; /* fail safe */ 78 | el->next = NULL; /* fail safe */ 79 | } 80 | 81 | static inline int list_empty(struct list_head *el) 82 | { 83 | return el->next == el; 84 | } 85 | 86 | #define list_for_each(el, head) \ 87 | for(el = (head)->next; el != (head); el = el->next) 88 | 89 | #define list_for_each_safe(el, el1, head) \ 90 | for(el = (head)->next, el1 = el->next; el != (head); \ 91 | el = el1, el1 = el->next) 92 | 93 | #define list_for_each_prev(el, head) \ 94 | for(el = (head)->prev; el != (head); el = el->prev) 95 | 96 | #define list_for_each_prev_safe(el, el1, head) \ 97 | for(el = (head)->prev, el1 = el->prev; el != (head); \ 98 | el = el1, el1 = el->prev) 99 | 100 | #endif /* LIST_H */ 101 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/quickjs-atom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS atom definitions 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * Copyright (c) 2017-2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | #ifdef DEF 27 | 28 | /* Note: first atoms are considered as keywords in the parser */ 29 | DEF(null, "null") /* must be first */ 30 | DEF(false, "false") 31 | DEF(true, "true") 32 | DEF(if, "if") 33 | DEF(else, "else") 34 | DEF(return, "return") 35 | DEF(var, "var") 36 | DEF(this, "this") 37 | DEF(delete, "delete") 38 | DEF(void, "void") 39 | DEF(typeof, "typeof") 40 | DEF(new, "new") 41 | DEF(in, "in") 42 | DEF(instanceof, "instanceof") 43 | DEF(do, "do") 44 | DEF(while, "while") 45 | DEF(for, "for") 46 | DEF(break, "break") 47 | DEF(continue, "continue") 48 | DEF(switch, "switch") 49 | DEF(case, "case") 50 | DEF(default, "default") 51 | DEF(throw, "throw") 52 | DEF(try, "try") 53 | DEF(catch, "catch") 54 | DEF(finally, "finally") 55 | DEF(function, "function") 56 | DEF(debugger, "debugger") 57 | DEF(with, "with") 58 | /* FutureReservedWord */ 59 | DEF(class, "class") 60 | DEF(const, "const") 61 | DEF(enum, "enum") 62 | DEF(export, "export") 63 | DEF(extends, "extends") 64 | DEF(import, "import") 65 | DEF(super, "super") 66 | /* FutureReservedWords when parsing strict mode code */ 67 | DEF(implements, "implements") 68 | DEF(interface, "interface") 69 | DEF(let, "let") 70 | DEF(package, "package") 71 | DEF(private, "private") 72 | DEF(protected, "protected") 73 | DEF(public, "public") 74 | DEF(static, "static") 75 | DEF(yield, "yield") 76 | DEF(await, "await") 77 | 78 | /* empty string */ 79 | DEF(empty_string, "") 80 | /* identifiers */ 81 | DEF(length, "length") 82 | DEF(fileName, "fileName") 83 | DEF(lineNumber, "lineNumber") 84 | DEF(message, "message") 85 | DEF(stack, "stack") 86 | DEF(name, "name") 87 | DEF(toString, "toString") 88 | DEF(toLocaleString, "toLocaleString") 89 | DEF(valueOf, "valueOf") 90 | DEF(eval, "eval") 91 | DEF(prototype, "prototype") 92 | DEF(constructor, "constructor") 93 | DEF(configurable, "configurable") 94 | DEF(writable, "writable") 95 | DEF(enumerable, "enumerable") 96 | DEF(value, "value") 97 | DEF(get, "get") 98 | DEF(set, "set") 99 | DEF(of, "of") 100 | DEF(__proto__, "__proto__") 101 | DEF(undefined, "undefined") 102 | DEF(number, "number") 103 | DEF(boolean, "boolean") 104 | DEF(string, "string") 105 | DEF(object, "object") 106 | DEF(symbol, "symbol") 107 | DEF(integer, "integer") 108 | DEF(unknown, "unknown") 109 | DEF(arguments, "arguments") 110 | DEF(callee, "callee") 111 | DEF(caller, "caller") 112 | DEF(_eval_, "") 113 | DEF(_ret_, "") 114 | DEF(_var_, "") 115 | DEF(_with_, "") 116 | DEF(lastIndex, "lastIndex") 117 | DEF(target, "target") 118 | DEF(index, "index") 119 | DEF(input, "input") 120 | DEF(defineProperties, "defineProperties") 121 | DEF(apply, "apply") 122 | DEF(join, "join") 123 | DEF(concat, "concat") 124 | DEF(split, "split") 125 | DEF(construct, "construct") 126 | DEF(getPrototypeOf, "getPrototypeOf") 127 | DEF(setPrototypeOf, "setPrototypeOf") 128 | DEF(isExtensible, "isExtensible") 129 | DEF(preventExtensions, "preventExtensions") 130 | DEF(has, "has") 131 | DEF(deleteProperty, "deleteProperty") 132 | DEF(defineProperty, "defineProperty") 133 | DEF(getOwnPropertyDescriptor, "getOwnPropertyDescriptor") 134 | DEF(ownKeys, "ownKeys") 135 | DEF(add, "add") 136 | DEF(done, "done") 137 | DEF(next, "next") 138 | DEF(values, "values") 139 | DEF(source, "source") 140 | DEF(flags, "flags") 141 | DEF(global, "global") 142 | DEF(unicode, "unicode") 143 | DEF(raw, "raw") 144 | DEF(new_target, "new.target") 145 | DEF(this_active_func, "this.active_func") 146 | DEF(home_object, "") 147 | DEF(as, "as") 148 | DEF(from, "from") 149 | DEF(_default_, "*default*") 150 | DEF(_star_, "*") 151 | DEF(Module, "Module") 152 | DEF(then, "then") 153 | DEF(resolve, "resolve") 154 | DEF(reject, "reject") 155 | DEF(promise, "promise") 156 | DEF(proxy, "proxy") 157 | DEF(revoke, "revoke") 158 | DEF(async, "async") 159 | DEF(exec, "exec") 160 | DEF(groups, "groups") 161 | #ifdef CONFIG_BIGNUM 162 | DEF(bigint, "bigint") 163 | DEF(bigfloat, "bigfloat") 164 | #endif 165 | #ifdef CONFIG_ATOMICS 166 | DEF(not_equal, "not-equal") 167 | DEF(timed_out, "timed-out") 168 | DEF(ok, "ok") 169 | #endif 170 | DEF(toJSON, "toJSON") 171 | /* class names */ 172 | DEF(Object, "Object") 173 | DEF(Array, "Array") 174 | DEF(Error, "Error") 175 | DEF(Number, "Number") 176 | DEF(String, "String") 177 | DEF(Boolean, "Boolean") 178 | DEF(Symbol, "Symbol") 179 | DEF(Arguments, "Arguments") 180 | DEF(Math, "Math") 181 | DEF(JSON, "JSON") 182 | DEF(Date, "Date") 183 | DEF(Function, "Function") 184 | DEF(GeneratorFunction, "GeneratorFunction") 185 | DEF(ForInIterator, "ForInIterator") 186 | DEF(RegExp, "RegExp") 187 | DEF(ArrayBuffer, "ArrayBuffer") 188 | DEF(SharedArrayBuffer, "SharedArrayBuffer") 189 | /* must keep same order as class IDs for typed arrays */ 190 | DEF(Uint8ClampedArray, "Uint8ClampedArray") 191 | DEF(Int8Array, "Int8Array") 192 | DEF(Uint8Array, "Uint8Array") 193 | DEF(Int16Array, "Int16Array") 194 | DEF(Uint16Array, "Uint16Array") 195 | DEF(Int32Array, "Int32Array") 196 | DEF(Uint32Array, "Uint32Array") 197 | #ifdef CONFIG_BIGNUM 198 | DEF(BigInt64Array, "BigInt64Array") 199 | DEF(BigUint64Array, "BigUint64Array") 200 | #endif 201 | DEF(Float32Array, "Float32Array") 202 | DEF(Float64Array, "Float64Array") 203 | DEF(DataView, "DataView") 204 | #ifdef CONFIG_BIGNUM 205 | DEF(BigInt, "BigInt") 206 | DEF(BigFloat, "BigFloat") 207 | DEF(BigFloatEnv, "BigFloatEnv") 208 | #endif 209 | DEF(Map, "Map") 210 | DEF(Set, "Set") /* Map + 1 */ 211 | DEF(WeakMap, "WeakMap") /* Map + 2 */ 212 | DEF(WeakSet, "WeakSet") /* Map + 3 */ 213 | DEF(Map_Iterator, "Map Iterator") 214 | DEF(Set_Iterator, "Set Iterator") 215 | DEF(Array_Iterator, "Array Iterator") 216 | DEF(String_Iterator, "String Iterator") 217 | DEF(Generator, "Generator") 218 | DEF(Proxy, "Proxy") 219 | DEF(Promise, "Promise") 220 | DEF(PromiseResolveFunction, "PromiseResolveFunction") 221 | DEF(PromiseRejectFunction, "PromiseRejectFunction") 222 | DEF(AsyncFunction, "AsyncFunction") 223 | DEF(AsyncFunctionResolve, "AsyncFunctionResolve") 224 | DEF(AsyncFunctionReject, "AsyncFunctionReject") 225 | DEF(AsyncGeneratorFunction, "AsyncGeneratorFunction") 226 | DEF(AsyncGenerator, "AsyncGenerator") 227 | DEF(EvalError, "EvalError") 228 | DEF(RangeError, "RangeError") 229 | DEF(ReferenceError, "ReferenceError") 230 | DEF(SyntaxError, "SyntaxError") 231 | DEF(TypeError, "TypeError") 232 | DEF(URIError, "URIError") 233 | DEF(InternalError, "InternalError") 234 | 235 | /* symbols */ 236 | DEF(Symbol_toPrimitive, "Symbol.toPrimitive") 237 | DEF(Symbol_iterator, "Symbol.iterator") 238 | DEF(Symbol_match, "Symbol.match") 239 | DEF(Symbol_replace, "Symbol.replace") 240 | DEF(Symbol_search, "Symbol.search") 241 | DEF(Symbol_split, "Symbol.split") 242 | DEF(Symbol_toStringTag, "Symbol.toStringTag") 243 | DEF(Symbol_isConcatSpreadable, "Symbol.isConcatSpreadable") 244 | DEF(Symbol_hasInstance, "Symbol.hasInstance") 245 | DEF(Symbol_species, "Symbol.species") 246 | DEF(Symbol_unscopables, "Symbol.unscopables") 247 | DEF(Symbol_asyncIterator, "Symbol.asyncIterator") 248 | #ifdef CONFIG_BIGNUM 249 | DEF(Symbol_operatorOrder, "Symbol.operatorOrder") 250 | DEF(Symbol_operatorAdd, "Symbol.operatorAdd") 251 | DEF(Symbol_operatorSub, "Symbol.operatorSub") 252 | DEF(Symbol_operatorMul, "Symbol.operatorMul") 253 | DEF(Symbol_operatorDiv, "Symbol.operatorDiv") 254 | DEF(Symbol_operatorMod, "Symbol.operatorMod") 255 | DEF(Symbol_operatorPow, "Symbol.operatorPow") 256 | DEF(Symbol_operatorShl, "Symbol.operatorShl") 257 | DEF(Symbol_operatorShr, "Symbol.operatorShr") 258 | DEF(Symbol_operatorAnd, "Symbol.operatorAnd") 259 | DEF(Symbol_operatorOr, "Symbol.operatorOr") 260 | DEF(Symbol_operatorXor, "Symbol.operatorXor") 261 | DEF(Symbol_operatorCmpLT, "Symbol.operatorCmpLT") 262 | DEF(Symbol_operatorCmpLE, "Symbol.operatorCmpLE") 263 | DEF(Symbol_operatorCmpEQ, "Symbol.operatorCmpEQ") 264 | DEF(Symbol_operatorPlus, "Symbol.operatorPlus") 265 | DEF(Symbol_operatorNeg, "Symbol.operatorNeg") 266 | DEF(Symbol_operatorNot, "Symbol.operatorNot") 267 | DEF(Symbol_operatorInc, "Symbol.operatorInc") 268 | DEF(Symbol_operatorDec, "Symbol.operatorDec") 269 | DEF(Symbol_operatorMathDiv, "Symbol.operatorMathDiv") 270 | DEF(Symbol_operatorMathMod, "Symbol.operatorMathMod") 271 | DEF(Symbol_operatorMathPow, "Symbol.operatorMathPow") 272 | #endif 273 | 274 | #endif /* DEF */ 275 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/quickjs-libc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS C library 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef QUICKJS_LIBC_H 25 | #define QUICKJS_LIBC_H 26 | 27 | #include 28 | #include 29 | 30 | #include "quickjs.h" 31 | 32 | JSModuleDef *js_init_module_std(JSContext *ctx, const char *module_name); 33 | JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name); 34 | void js_std_add_helpers(JSContext *ctx, int argc, char **argv); 35 | void js_std_loop(JSContext *ctx); 36 | void js_std_free_handlers(JSRuntime *rt); 37 | void js_std_dump_error(JSContext *ctx); 38 | uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename); 39 | JSModuleDef *js_module_loader(JSContext *ctx, 40 | const char *module_name, void *opaque); 41 | void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len, 42 | int flags); 43 | 44 | #endif /* QUICKJS_LIBC_H */ 45 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/readme.txt: -------------------------------------------------------------------------------- 1 | The main documentation is in doc/quickjs.pdf or doc/quickjs.html. 2 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Release the QuickJS source code 3 | 4 | set -e 5 | 6 | version=`cat VERSION` 7 | 8 | if [ "$1" = "-h" ] ; then 9 | echo "release.sh [all]" 10 | echo "" 11 | echo "all: build all the archives. Otherwise only build the quickjs source archive." 12 | exit 1 13 | fi 14 | 15 | 16 | if [ "$1" = "all" ] ; then 17 | 18 | #################################################" 19 | # unicode data 20 | 21 | d="quickjs-${version}" 22 | name="quickjs-unicode-data-${version}" 23 | outdir="/tmp/${d}" 24 | 25 | rm -rf $outdir 26 | mkdir -p $outdir $outdir/unicode 27 | 28 | cp unicode/* $outdir/unicode 29 | 30 | ( cd /tmp && tar Jcvf /tmp/${name}.tar.xz ${d} ) 31 | 32 | #################################################" 33 | # all tests 34 | 35 | d="quickjs-${version}" 36 | name="quickjs-tests-${version}" 37 | outdir="/tmp/${d}" 38 | 39 | rm -rf $outdir 40 | mkdir -p $outdir $outdir/test262o $outdir/test262 $outdir/tests 41 | 42 | cp -a test262o/test $outdir/test262o 43 | 44 | cp -a test262/test test262/harness $outdir/test262 45 | 46 | cp -a tests/bench-v8 $outdir/tests 47 | 48 | ( cd /tmp && tar Jcvf /tmp/${name}.tar.xz ${d} ) 49 | 50 | fi # all 51 | 52 | #################################################" 53 | # quickjs 54 | 55 | make build_doc 56 | 57 | d="quickjs-${version}" 58 | outdir="/tmp/${d}" 59 | 60 | rm -rf $outdir 61 | mkdir -p $outdir $outdir/doc $outdir/tests $outdir/examples 62 | 63 | cp Makefile VERSION TODO readme.txt release.sh \ 64 | qjs.c qjsc.c qjscalc.js repl.js \ 65 | quickjs.c quickjs.h quickjs-atom.h \ 66 | quickjs-libc.c quickjs-libc.h quickjs-opcode.h \ 67 | cutils.c cutils.h list.h \ 68 | libregexp.c libregexp.h libregexp-opcode.h \ 69 | libunicode.c libunicode.h libunicode-table.h \ 70 | libbf.c libbf.h \ 71 | jscompress.c unicode_gen.c unicode_gen_def.h \ 72 | bjson.c \ 73 | run-test262.c test262o.conf test262.conf test262bn.conf \ 74 | test262o_errors.txt test262_errors.txt test262bn_errors.txt \ 75 | $outdir 76 | 77 | cp tests/*.js tests/*.patch $outdir/tests 78 | 79 | cp examples/*.js examples/*.c $outdir/examples 80 | 81 | cp doc/quickjs.texi doc/quickjs.pdf doc/quickjs.html \ 82 | doc/jsbignum.texi doc/jsbignum.html doc/jsbignum.pdf \ 83 | $outdir/doc 84 | 85 | ( cd /tmp && tar Jcvf /tmp/${d}.tar.xz ${d} ) 86 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/test262.conf: -------------------------------------------------------------------------------- 1 | [config] 2 | # general settings for test262 ES6 version 3 | 4 | # framework style: old, new 5 | style=new 6 | 7 | # handle tests tagged as [noStrict]: yes, no, skip 8 | nostrict=yes 9 | 10 | # handle tests tagged as [strictOnly]: yes, no, skip 11 | strict=yes 12 | 13 | # test mode: default, default-nostrict, default-strict, strict, nostrict, both, all 14 | mode=default 15 | 16 | # handle tests flagged as [async]: yes, no, skip 17 | # for these, load 'harness/doneprintHandle.js' prior to test 18 | # and expect `print('Test262:AsyncTestComplete')` to be called for 19 | # successful termination 20 | async=yes 21 | 22 | # handle tests flagged as [module]: yes, no, skip 23 | module=yes 24 | 25 | # output error messages: yes, no 26 | verbose=yes 27 | 28 | # load harness files from this directory 29 | harnessdir=test262/harness 30 | 31 | # names of harness include files to skip 32 | #harnessexclude= 33 | 34 | # name of the error file for known errors 35 | errorfile=test262_errors.txt 36 | 37 | # exclude tests enumerated in this file (see also [exclude] section) 38 | #excludefile=test262_exclude.txt 39 | 40 | # report test results to this file 41 | reportfile=test262_report.txt 42 | 43 | # enumerate tests from this directory 44 | testdir=test262/test 45 | 46 | [features] 47 | # Standard language features and proposed extensions 48 | # list the features that are included 49 | # skipped features are tagged as such to avoid warnings 50 | 51 | Array.prototype.flat 52 | Array.prototype.flatMap 53 | Array.prototype.flatten 54 | Array.prototype.values 55 | ArrayBuffer 56 | arrow-function 57 | async-functions 58 | async-iteration 59 | Atomics 60 | BigInt=skip 61 | caller 62 | class 63 | class-fields-private=skip 64 | class-fields-public=skip 65 | computed-property-names 66 | const 67 | cross-realm=skip 68 | DataView 69 | DataView.prototype.getFloat32 70 | DataView.prototype.getFloat64 71 | DataView.prototype.getInt16 72 | DataView.prototype.getInt32 73 | DataView.prototype.getInt8 74 | DataView.prototype.getUint16 75 | DataView.prototype.getUint32 76 | DataView.prototype.setUint8 77 | default-arg 78 | default-parameters 79 | destructuring-assignment 80 | destructuring-binding 81 | export-star-as-namespace-from-module=skip 82 | Float32Array 83 | Float64Array 84 | for-of 85 | generators 86 | global 87 | Int8Array 88 | IsHTMLDDA=skip 89 | json-superset 90 | let 91 | Map 92 | new.target 93 | numeric-separator-literal 94 | object-rest 95 | object-spread 96 | Object.is 97 | optional-catch-binding 98 | Promise.prototype.finally 99 | Proxy 100 | Reflect 101 | Reflect.construct 102 | Reflect.set 103 | Reflect.setPrototypeOf 104 | regexp-dotall 105 | regexp-lookbehind 106 | regexp-named-groups 107 | regexp-unicode-property-escapes 108 | Set 109 | SharedArrayBuffer 110 | string-trimming 111 | String.fromCodePoint 112 | String.prototype.endsWith 113 | String.prototype.includes 114 | String.prototype.matchAll=skip 115 | String.prototype.trimEnd 116 | String.prototype.trimStart 117 | super 118 | Symbol 119 | Symbol.asyncIterator 120 | Symbol.hasInstance 121 | Symbol.isConcatSpreadable 122 | Symbol.iterator 123 | Symbol.match 124 | Symbol.matchAll=skip 125 | Symbol.prototype.description 126 | Symbol.replace 127 | Symbol.search 128 | Symbol.species 129 | Symbol.split 130 | Symbol.toPrimitive 131 | Symbol.toStringTag 132 | Symbol.unscopables 133 | tail-call-optimization=skip 134 | template 135 | TypedArray 136 | u180e 137 | Uint16Array 138 | Uint8Array 139 | Uint8ClampedArray 140 | WeakMap 141 | WeakSet 142 | 143 | [exclude] 144 | # list excluded tests and directories here 145 | 146 | # intl not supported 147 | test262/test/intl402/ 148 | 149 | # these builtins are not supported: 150 | test262/test/built-ins/BigInt/ 151 | 152 | # mislabelled feature Symbol.match -> Symbol.matchAll 153 | test262/test/built-ins/Symbol/matchAll/prop-desc.js 154 | 155 | # incompatible with the "caller" feature 156 | test262/test/built-ins/Function/prototype/restricted-property-caller.js 157 | test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js 158 | 159 | # no debugger keyword support 160 | test262/test/language/statements/debugger/statement.js 161 | 162 | # bogus html close comment test with syntax error 163 | test262/test/annexB/built-ins/Function/createdynfn-html-close-comment-params.js 164 | 165 | # bogus test #14 compares 2 consecutive calls to Date(), may be different if unlucky 166 | #test262/test/built-ins/Date/S15.9.2.1_A2.js 167 | 168 | # slow tests 169 | #test262/test/built-ins/RegExp/CharacterClassEscapes/ 170 | #test262/test/built-ins/RegExp/property-escapes/ 171 | 172 | [tests] 173 | # list test files or use config.testdir 174 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/test262_errors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-09/test262_errors.txt -------------------------------------------------------------------------------- /quickjs-2019-07-09/test262bn.conf: -------------------------------------------------------------------------------- 1 | [config] 2 | # general settings for test262 ES6 bignum version 3 | 4 | # framework style: old, new 5 | style=new 6 | 7 | # handle tests tagged as [noStrict]: yes, no, skip 8 | nostrict=yes 9 | 10 | # handle tests tagged as [strictOnly]: yes, no, skip 11 | strict=yes 12 | 13 | # test mode: default, default-nostrict, default-strict, strict, nostrict, both, all 14 | mode=default 15 | 16 | # handle tests flagged as [async]: yes, no, skip 17 | # for these, load 'harness/doneprintHandle.js' prior to test 18 | # and expect `print('Test262:AsyncTestComplete')` to be called for 19 | # successful termination 20 | async=yes 21 | 22 | # handle tests flagged as [module]: yes, no, skip 23 | module=yes 24 | 25 | # output error messages: yes, no 26 | verbose=yes 27 | 28 | # load harness files from this directory 29 | harnessdir=test262/harness 30 | 31 | # names of harness include files to skip 32 | # bignum version does not support Atomics 33 | harnessexclude=testAtomics.js 34 | 35 | # name of the error file for known errors 36 | errorfile=test262bn_errors.txt 37 | 38 | # exclude tests enumerated in this file (see also [exclude] section) 39 | #excludefile=test262bn_exclude.txt 40 | 41 | # report test results to this file 42 | reportfile=test262bn_report.txt 43 | 44 | # enumerate tests from this directory 45 | testdir=test262/test 46 | 47 | [features] 48 | # Standard language features and proposed extensions 49 | # list the features that are included 50 | # skipped features are tagged as such to avoid warnings 51 | 52 | Array.prototype.flat 53 | Array.prototype.flatMap 54 | Array.prototype.flatten 55 | Array.prototype.values 56 | ArrayBuffer 57 | arrow-function 58 | async-functions 59 | async-iteration 60 | Atomics=skip 61 | BigInt 62 | caller 63 | class 64 | class-fields-private=skip 65 | class-fields-public=skip 66 | computed-property-names 67 | const 68 | cross-realm=skip 69 | DataView 70 | DataView.prototype.getFloat32 71 | DataView.prototype.getFloat64 72 | DataView.prototype.getInt16 73 | DataView.prototype.getInt32 74 | DataView.prototype.getInt8 75 | DataView.prototype.getUint16 76 | DataView.prototype.getUint32 77 | DataView.prototype.setUint8 78 | default-arg 79 | default-parameters 80 | destructuring-assignment 81 | destructuring-binding 82 | export-star-as-namespace-from-module=skip 83 | Float32Array 84 | Float64Array 85 | for-of 86 | generators 87 | global 88 | Int8Array 89 | IsHTMLDDA=skip 90 | json-superset 91 | let 92 | Map 93 | new.target 94 | numeric-separator-literal 95 | object-rest 96 | object-spread 97 | Object.is 98 | optional-catch-binding 99 | Promise.prototype.finally 100 | Proxy 101 | Reflect 102 | Reflect.construct 103 | Reflect.set 104 | Reflect.setPrototypeOf 105 | regexp-dotall 106 | regexp-lookbehind 107 | regexp-named-groups 108 | regexp-unicode-property-escapes 109 | Set 110 | SharedArrayBuffer=skip 111 | string-trimming 112 | String.fromCodePoint 113 | String.prototype.endsWith 114 | String.prototype.includes 115 | String.prototype.matchAll=skip 116 | String.prototype.trimEnd 117 | String.prototype.trimStart 118 | super 119 | Symbol 120 | Symbol.asyncIterator 121 | Symbol.hasInstance 122 | Symbol.isConcatSpreadable 123 | Symbol.iterator 124 | Symbol.match 125 | Symbol.matchAll=skip 126 | Symbol.prototype.description 127 | Symbol.replace 128 | Symbol.search 129 | Symbol.species 130 | Symbol.split 131 | Symbol.toPrimitive 132 | Symbol.toStringTag 133 | Symbol.unscopables 134 | tail-call-optimization=skip 135 | template 136 | TypedArray 137 | u180e 138 | Uint16Array 139 | Uint8Array 140 | Uint8ClampedArray 141 | WeakMap 142 | WeakSet 143 | 144 | [exclude] 145 | # list excluded tests and directories here 146 | 147 | # intl not supported 148 | test262/test/intl402/ 149 | 150 | # these builtins are not supported: 151 | test262/test/built-ins/Atomics/ 152 | test262/test/built-ins/SharedArrayBuffer/ 153 | 154 | # mislabelled feature Symbol.match -> Symbol.matchAll 155 | test262/test/built-ins/Symbol/matchAll/prop-desc.js 156 | 157 | # incompatible with the "caller" feature 158 | test262/test/built-ins/Function/prototype/restricted-property-caller.js 159 | test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js 160 | 161 | # no debugger keyword support 162 | test262/test/language/statements/debugger/statement.js 163 | 164 | # bogus html close comment test with syntax error 165 | test262/test/annexB/built-ins/Function/createdynfn-html-close-comment-params.js 166 | 167 | # bogus test #14 compares 2 consecutive calls to Date(), may be different if unlucky 168 | #test262/test/built-ins/Date/S15.9.2.1_A2.js 169 | 170 | # slow tests 171 | #test262/test/built-ins/RegExp/CharacterClassEscapes/ 172 | #test262/test/built-ins/RegExp/property-escapes/ 173 | 174 | [tests] 175 | # list test files or use config.testdir 176 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/test262bn_errors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-09/test262bn_errors.txt -------------------------------------------------------------------------------- /quickjs-2019-07-09/test262o_errors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-09/test262o_errors.txt -------------------------------------------------------------------------------- /quickjs-2019-07-09/tests/test_bignum.js: -------------------------------------------------------------------------------- 1 | "use math"; 2 | "use strict"; 3 | 4 | function assert(actual, expected, message) { 5 | if (arguments.length == 1) 6 | expected = true; 7 | 8 | if (actual === expected) 9 | return; 10 | 11 | if (actual !== null && expected !== null 12 | && typeof actual == 'object' && typeof expected == 'object' 13 | && actual.toString() === expected.toString()) 14 | return; 15 | 16 | throw Error("assertion failed: got |" + actual + "|" + 17 | ", expected |" + expected + "|" + 18 | (message ? " (" + message + ")" : "")); 19 | } 20 | 21 | // load more elaborate version of assert if available 22 | try { __loadScript("test_assert.js"); } catch(e) {} 23 | 24 | /*----------------*/ 25 | 26 | function pow(a, n) 27 | { 28 | var r, i; 29 | r = 1; 30 | for(i = 0; i < n; i++) 31 | r *= a; 32 | return r; 33 | } 34 | 35 | function test_integer() 36 | { 37 | var a, r; 38 | a = pow(3, 100); 39 | assert((a - 1) != a); 40 | assert(a == 515377520732011331036461129765621272702107522001); 41 | assert(a == 0x5a4653ca673768565b41f775d6947d55cf3813d1); 42 | assert(Integer.isInteger(1) === true); 43 | assert(Integer.isInteger(1.0) === false); 44 | 45 | assert(Integer.floorLog2(0) === -1); 46 | assert(Integer.floorLog2(7) === 2); 47 | 48 | r = 1 << 31; 49 | assert(r, 2147483648, "1 << 31 === 2147483648"); 50 | 51 | r = 1 << 32; 52 | assert(r, 4294967296, "1 << 32 === 4294967296"); 53 | 54 | r = (1 << 31) < 0; 55 | assert(r, false, "(1 << 31) < 0 === false"); 56 | } 57 | 58 | function test_divrem(div1, a, b, q) 59 | { 60 | var div, divrem, t; 61 | div = Integer[div1]; 62 | divrem = Integer[div1 + "rem"]; 63 | assert(div(a, b) == q); 64 | t = divrem(a, b); 65 | assert(t[0] == q); 66 | assert(a == b * q + t[1]); 67 | } 68 | 69 | function test_idiv1(div, a, b, r) 70 | { 71 | test_divrem(div, a, b, r[0]); 72 | test_divrem(div, -a, b, r[1]); 73 | test_divrem(div, a, -b, r[2]); 74 | test_divrem(div, -a, -b, r[3]); 75 | } 76 | 77 | function test_idiv() 78 | { 79 | test_idiv1("tdiv", 3, 2, [1, -1, -1, 1]); 80 | test_idiv1("fdiv", 3, 2, [1, -2, -2, 1]); 81 | test_idiv1("cdiv", 3, 2, [2, -1, -1, 2]); 82 | test_idiv1("ediv", 3, 2, [1, -2, -1, 2]); 83 | } 84 | 85 | function test_float() 86 | { 87 | var e, a, b, sqrt2; 88 | 89 | assert(typeof 1 === "bigint"); 90 | assert(typeof 1.0 === "bigfloat"); 91 | assert(1 == 1.0); 92 | assert(1 !== 1.0); 93 | 94 | e = new BigFloatEnv(128); 95 | assert(e.prec == 128); 96 | a = BigFloat.sqrt(2, e); 97 | assert(a == BigFloat.parseFloat("0x1.6a09e667f3bcc908b2fb1366ea957d3e", 0, e)); 98 | assert(e.inexact === true); 99 | assert(BigFloat.fpRound(a) == 0x1.6a09e667f3bcd); 100 | 101 | b = BigFloatEnv.setPrec(BigFloat.sqrt.bind(null, 2), 128); 102 | assert(a == b); 103 | } 104 | 105 | /* jscalc tests */ 106 | 107 | function test_modulo() 108 | { 109 | var i, p, a, b; 110 | 111 | /* Euclidian modulo operator */ 112 | assert((-3) % 2 == 1); 113 | assert(3 % (-2) == 1); 114 | 115 | p = 101; 116 | for(i = 1; i < p; i++) { 117 | a = Integer.invmod(i, p); 118 | assert(a >= 0 && a < p); 119 | assert((i * a) % p == 1); 120 | } 121 | 122 | assert(Integer.isPrime(2^107-1)); 123 | assert(!Integer.isPrime((2^107-1) * (2^89-1))); 124 | a = Integer.factor((2^89-1)*2^3*11*13^2*1009); 125 | assert(a == [ 2,2,2,11,13,13,1009,618970019642690137449562111 ]); 126 | } 127 | 128 | function test_mod() 129 | { 130 | var a, b, p; 131 | 132 | a = Mod(3, 101); 133 | b = Mod(-1, 101); 134 | assert((a + b) == Mod(2, 101)); 135 | assert(a ^ 100 == Mod(1, 101)); 136 | 137 | p = 2 ^ 607 - 1; /* mersenne prime */ 138 | a = Mod(3, p) ^ (p - 1); 139 | assert(a == Mod(1, p)); 140 | } 141 | 142 | function test_polynomial() 143 | { 144 | var a, b, q, r, t, i; 145 | a = (1 + X) ^ 4; 146 | assert(a == X^4+4*X^3+6*X^2+4*X+1); 147 | 148 | r = (1 + X); 149 | q = (1+X+X^2); 150 | b = (1 - X^2); 151 | a = q * b + r; 152 | t = Polynomial.divrem(a, b); 153 | assert(t[0] == q); 154 | assert(t[1] == r); 155 | 156 | a = 1 + 2*X + 3*X^2; 157 | assert(a.apply(0.1) == 1.23); 158 | 159 | a = 1-2*X^2+2*X^3; 160 | assert(deriv(a) == (6*X^2-4*X)); 161 | assert(deriv(integ(a)) == a); 162 | 163 | a = (X-1)*(X-2)*(X-3)*(X-4)*(X-0.1); 164 | r = polroots(a); 165 | for(i = 0; i < r.length; i++) { 166 | b = abs(a.apply(r[i])); 167 | assert(b <= 1e-13); 168 | } 169 | } 170 | 171 | function test_poly_mod() 172 | { 173 | var a, p; 174 | 175 | /* modulo using polynomials */ 176 | p = X^2 + X + 1; 177 | a = PolyMod(3+X, p) ^ 10; 178 | assert(a == PolyMod(-3725*X-18357, p)); 179 | 180 | a = PolyMod(1/X, 1+X^2); 181 | assert(a == PolyMod(-X, X^2+1)); 182 | } 183 | 184 | function test_rfunc() 185 | { 186 | var a; 187 | a = (X+1)/((X+1)*(X-1)); 188 | assert(a == 1/(X-1)); 189 | a = (X + 2) / (X - 2); 190 | assert(a.apply(1/3) == -7/5); 191 | 192 | assert(deriv((X^2-X+1)/(X-1)) == (X^2-2*X)/(X^2-2*X+1)); 193 | } 194 | 195 | function test_series() 196 | { 197 | var a, b; 198 | a = 1+X+O(X^5); 199 | b = a.inverse(); 200 | assert(b == 1-X+X^2-X^3+X^4+O(X^5)); 201 | assert(deriv(b) == -1+2*X-3*X^2+4*X^3+O(X^4)); 202 | assert(deriv(integ(b)) == b); 203 | 204 | a = Series(1/(1-X), 5); 205 | assert(a == 1+X+X^2+X^3+X^4+O(X^5)); 206 | b = a.apply(0.1); 207 | assert(b == 1.1111); 208 | 209 | assert(exp(3*X^2+O(X^10)) == 1+3*X^2+9/2*X^4+9/2*X^6+27/8*X^8+O(X^10)); 210 | assert(sin(X+O(X^6)) == X-1/6*X^3+1/120*X^5+O(X^6)); 211 | assert(cos(X+O(X^6)) == 1-1/2*X^2+1/24*X^4+O(X^6)); 212 | assert(tan(X+O(X^8)) == X+1/3*X^3+2/15*X^5+17/315*X^7+O(X^8)); 213 | assert((1+X+O(X^6))^(2+X) == 1+2*X+2*X^2+3/2*X^3+5/6*X^4+5/12*X^5+O(X^6)); 214 | } 215 | 216 | function test_matrix() 217 | { 218 | var a, b, r; 219 | a = [[1, 2],[3, 4]]; 220 | b = [3, 4]; 221 | r = a * b; 222 | assert(r == [11, 25]); 223 | r = (a^-1) * 2; 224 | assert(r == [[-4, 2],[3, -1]]); 225 | 226 | assert(norm2([1,2,3]) == 14); 227 | 228 | assert(diag([1,2,3]) == [ [ 1, 0, 0 ], [ 0, 2, 0 ], [ 0, 0, 3 ] ]); 229 | assert(trans(a) == [ [ 1, 3 ], [ 2, 4 ] ]); 230 | assert(trans([1,2,3]) == [[1,2,3]]); 231 | assert(trace(a) == 5); 232 | 233 | assert(charpoly(Matrix.hilbert(4)) == X^4-176/105*X^3+3341/12600*X^2-41/23625*X+1/6048000); 234 | assert(det(Matrix.hilbert(4)) == 1/6048000); 235 | 236 | a = [[1,2,1],[-2,-3,1],[3,5,0]]; 237 | assert(rank(a) == 2); 238 | assert(ker(a) == [ [ 5 ], [ -3 ], [ 1 ] ]); 239 | 240 | assert(dp([1, 2, 3], [3, -4, -7]) === -26); 241 | assert(cp([1, 2, 3], [3, -4, -7]) == [ -2, 16, -10 ]); 242 | } 243 | 244 | function assert_eq(a, ref) 245 | { 246 | assert(abs(a / ref - 1.0) <= 1e-15); 247 | } 248 | 249 | function test_trig() 250 | { 251 | assert_eq(sin(1/2), 0.479425538604203); 252 | assert_eq(sin(2+3*I), 9.154499146911428-4.168906959966565*I); 253 | assert_eq(cos(2+3*I), -4.189625690968807-9.109227893755337*I); 254 | assert_eq((2+0.5*I)^(1.1-0.5*I), 2.494363021357619-0.23076804554558092*I); 255 | assert_eq(sqrt(2*I), 1 + I); 256 | } 257 | 258 | test_integer(); 259 | test_idiv(); 260 | test_float(); 261 | 262 | test_modulo(); 263 | test_mod(); 264 | test_polynomial(); 265 | test_poly_mod(); 266 | test_rfunc(); 267 | test_series(); 268 | test_matrix(); 269 | test_trig(); 270 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/tests/test_bjson.js: -------------------------------------------------------------------------------- 1 | import * as bjson from "../bjson.so"; 2 | 3 | function assert(b, str) 4 | { 5 | if (b) { 6 | return; 7 | } else { 8 | throw Error("assertion failed: " + str); 9 | } 10 | } 11 | 12 | function toHex(a) 13 | { 14 | var i, s = "", tab, v; 15 | tab = new Uint8Array(a); 16 | for(i = 0; i < tab.length; i++) { 17 | v = tab[i].toString(16); 18 | if (v.length < 2) 19 | v = "0" + v; 20 | if (i !== 0) 21 | s += " "; 22 | s += v; 23 | } 24 | return s; 25 | } 26 | 27 | function toStr(a) 28 | { 29 | var s, i, props, prop; 30 | 31 | switch(typeof(a)) { 32 | case "object": 33 | if (a === null) 34 | return "null"; 35 | if (Array.isArray(a)) { 36 | s = "["; 37 | for(i = 0; i < a.length; i++) { 38 | if (i != 0) 39 | s += ","; 40 | s += toStr(a[i]); 41 | } 42 | s += "]"; 43 | } else { 44 | props = Object.keys(a); 45 | s = "{"; 46 | for(i = 0; i < props.length; i++) { 47 | if (i != 0) 48 | s += ","; 49 | prop = props[i]; 50 | s += prop + ":" + toStr(a[prop]); 51 | } 52 | s += "}"; 53 | } 54 | return s; 55 | case "undefined": 56 | return "undefined"; 57 | case "string": 58 | return a.__quote(); 59 | case "number": 60 | case "bigfloat": 61 | if (a == 0 && 1 / a < 0) 62 | return "-0"; 63 | else 64 | return a.toString(); 65 | break; 66 | default: 67 | return a.toString(); 68 | } 69 | } 70 | 71 | function bjson_test(a) 72 | { 73 | var buf, r, a_str, r_str; 74 | a_str = toStr(a); 75 | buf = bjson.write(a); 76 | if (0) { 77 | print(a_str, "->", toHex(buf)); 78 | } 79 | r = bjson.read(buf, 0, buf.byteLength); 80 | r_str = toStr(r); 81 | if (a_str != r_str) { 82 | print(a_str); 83 | print(r_str); 84 | assert(false); 85 | } 86 | } 87 | 88 | function bjson_test_all() 89 | { 90 | var obj; 91 | 92 | bjson_test({x:1, y:2, if:3}); 93 | bjson_test([1, 2, 3]); 94 | bjson_test([1.0, "aa", true, false, undefined, null, NaN, -Infinity, -0.0]); 95 | if (typeof BigInt !== "undefined") { 96 | bjson_test([BigInt("1"), -BigInt("0x123456789"), 97 | BigInt("0x123456789abcdef123456789abcdef")]); 98 | } 99 | if (typeof BigFloat !== "undefined") { 100 | BigFloatEnv.setPrec(function () { 101 | bjson_test([BigFloat("0.1"), BigFloat("-1e30"), BigFloat("0"), 102 | BigFloat("-0"), BigFloat("Infinity"), BigFloat("-Infinity"), 103 | 0.0 / BigFloat("0"), BigFloat.MAX_VALUE, 104 | BigFloat.MIN_VALUE]); 105 | }, 113, 15); 106 | } 107 | 108 | /* tested with a circular reference */ 109 | obj = {}; 110 | obj.x = obj; 111 | try { 112 | bjson.write(obj); 113 | assert(false); 114 | } catch(e) { 115 | assert(e instanceof TypeError); 116 | } 117 | } 118 | 119 | bjson_test_all(); 120 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/tests/test_closure.js: -------------------------------------------------------------------------------- 1 | function assert(actual, expected, message) { 2 | if (arguments.length == 1) 3 | expected = true; 4 | 5 | if (actual === expected) 6 | return; 7 | 8 | if (actual !== null && expected !== null 9 | && typeof actual == 'object' && typeof expected == 'object' 10 | && actual.toString() === expected.toString()) 11 | return; 12 | 13 | throw Error("assertion failed: got |" + actual + "|" + 14 | ", expected |" + expected + "|" + 15 | (message ? " (" + message + ")" : "")); 16 | } 17 | 18 | // load more elaborate version of assert if available 19 | try { __loadScript("test_assert.js"); } catch(e) {} 20 | 21 | /*----------------*/ 22 | 23 | var log_str = ""; 24 | 25 | function log(str) 26 | { 27 | log_str += str + ","; 28 | } 29 | 30 | function f(a, b, c) 31 | { 32 | var x = 10; 33 | log("a="+a); 34 | function g(d) { 35 | function h() { 36 | log("d=" + d); 37 | log("x=" + x); 38 | } 39 | log("b=" + b); 40 | log("c=" + c); 41 | h(); 42 | } 43 | g(4); 44 | return g; 45 | } 46 | 47 | var g1 = f(1, 2, 3); 48 | g1(5); 49 | 50 | assert(log_str, "a=1,b=2,c=3,d=4,x=10,b=2,c=3,d=5,x=10,", "closure1"); 51 | 52 | function test_closure1() 53 | { 54 | function f2() 55 | { 56 | var val = 1; 57 | 58 | function set(a) { 59 | val = a; 60 | } 61 | function get(a) { 62 | return val; 63 | } 64 | return { "set": set, "get": get }; 65 | } 66 | 67 | var obj = f2(); 68 | obj.set(10); 69 | var r; 70 | r = obj.get(); 71 | assert(r, 10, "closure2"); 72 | } 73 | 74 | function test_closure2() 75 | { 76 | var expr_func = function myfunc1(n) { 77 | function myfunc2(n) { 78 | return myfunc1(n - 1); 79 | } 80 | if (n == 0) 81 | return 0; 82 | else 83 | return myfunc2(n); 84 | }; 85 | var r; 86 | r = expr_func(1); 87 | assert(r, 0, "expr_func"); 88 | } 89 | 90 | function test_closure3() 91 | { 92 | function fib(n) 93 | { 94 | if (n <= 0) 95 | return 0; 96 | else if (n == 1) 97 | return 1; 98 | else 99 | return fib(n - 1) + fib(n - 2); 100 | } 101 | 102 | var fib_func = function fib1(n) 103 | { 104 | if (n <= 0) 105 | return 0; 106 | else if (n == 1) 107 | return 1; 108 | else 109 | return fib1(n - 1) + fib1(n - 2); 110 | }; 111 | 112 | assert(fib(6), 8, "fib"); 113 | assert(fib_func(6), 8, "fib_func"); 114 | } 115 | 116 | function test_arrow_function() 117 | { 118 | "use strict"; 119 | 120 | function f1() { 121 | return (() => arguments)(); 122 | } 123 | function f2() { 124 | return (() => this)(); 125 | } 126 | function f3() { 127 | return (() => eval("this"))(); 128 | } 129 | function f4() { 130 | return (() => eval("new.target"))(); 131 | } 132 | var a; 133 | 134 | a = f1(1, 2); 135 | assert(a.length, 2); 136 | assert(a[0] === 1 && a[1] === 2); 137 | 138 | assert(f2.call("this_val") === "this_val"); 139 | assert(f3.call("this_val") === "this_val"); 140 | assert(new f4() === f4); 141 | 142 | var o1 = { f() { return this; } }; 143 | var o2 = { f() { 144 | return (() => eval("super.f()"))(); 145 | } }; 146 | o2.__proto__ = o1; 147 | 148 | assert(o2.f() === o2); 149 | } 150 | 151 | function test_with() 152 | { 153 | var o1 = { x: "o1", y: "o1" }; 154 | var x = "local"; 155 | eval('var z="var_obj";'); 156 | assert(z === "var_obj"); 157 | with (o1) { 158 | assert(x === "o1"); 159 | assert(eval("x") === "o1"); 160 | var f = function () { 161 | o2 = { x: "o2" }; 162 | with (o2) { 163 | assert(x === "o2"); 164 | assert(y === "o1"); 165 | assert(z === "var_obj"); 166 | assert(eval("x") === "o2"); 167 | assert(eval("y") === "o1"); 168 | assert(eval("z") === "var_obj"); 169 | assert(eval('eval("x")') === "o2"); 170 | } 171 | }; 172 | f(); 173 | } 174 | } 175 | 176 | function test_eval_closure() 177 | { 178 | var tab; 179 | 180 | tab = []; 181 | for(let i = 0; i < 3; i++) { 182 | eval("tab.push(function g1() { return i; })"); 183 | } 184 | for(let i = 0; i < 3; i++) { 185 | assert(tab[i]() === i); 186 | } 187 | 188 | tab = []; 189 | for(let i = 0; i < 3; i++) { 190 | let f = function f() { 191 | eval("tab.push(function g2() { return i; })"); 192 | }; 193 | f(); 194 | } 195 | for(let i = 0; i < 3; i++) { 196 | assert(tab[i]() === i); 197 | } 198 | } 199 | 200 | function test_eval_const() 201 | { 202 | const a = 1; 203 | var success = false; 204 | var f = function () { 205 | eval("a = 1"); 206 | }; 207 | try { 208 | f(); 209 | } catch(e) { 210 | success = (e instanceof TypeError); 211 | } 212 | assert(success); 213 | } 214 | 215 | test_closure1(); 216 | test_closure2(); 217 | test_closure3(); 218 | test_arrow_function(); 219 | test_with(); 220 | test_eval_closure(); 221 | test_eval_const(); 222 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/tests/test_loop.js: -------------------------------------------------------------------------------- 1 | function assert(actual, expected, message) { 2 | if (arguments.length == 1) 3 | expected = true; 4 | 5 | if (actual === expected) 6 | return; 7 | 8 | if (actual !== null && expected !== null 9 | && typeof actual == 'object' && typeof expected == 'object' 10 | && actual.toString() === expected.toString()) 11 | return; 12 | 13 | throw Error("assertion failed: got |" + actual + "|" + 14 | ", expected |" + expected + "|" + 15 | (message ? " (" + message + ")" : "")); 16 | } 17 | 18 | // load more elaborate version of assert if available 19 | try { __loadScript("test_assert.js"); } catch(e) {} 20 | 21 | /*----------------*/ 22 | 23 | function test_while() 24 | { 25 | var i, c; 26 | i = 0; 27 | c = 0; 28 | while (i < 3) { 29 | c++; 30 | i++; 31 | } 32 | assert(c === 3); 33 | } 34 | 35 | function test_while_break() 36 | { 37 | var i, c; 38 | i = 0; 39 | c = 0; 40 | while (i < 3) { 41 | c++; 42 | if (i == 1) 43 | break; 44 | i++; 45 | } 46 | assert(c === 2 && i === 1); 47 | } 48 | 49 | function test_do_while() 50 | { 51 | var i, c; 52 | i = 0; 53 | c = 0; 54 | do { 55 | c++; 56 | i++; 57 | } while (i < 3); 58 | assert(c === 3 && i === 3); 59 | } 60 | 61 | function test_for() 62 | { 63 | var i, c; 64 | c = 0; 65 | for(i = 0; i < 3; i++) { 66 | c++; 67 | } 68 | assert(c === 3 && i === 3); 69 | 70 | c = 0; 71 | for(var j = 0; j < 3; j++) { 72 | c++; 73 | } 74 | assert(c === 3 && j === 3); 75 | } 76 | 77 | function test_for_in() 78 | { 79 | var i, tab, a, b; 80 | 81 | tab = []; 82 | for(i in {x:1, y: 2}) { 83 | tab.push(i); 84 | } 85 | assert(tab.toString(), "x,y", "for_in"); 86 | 87 | /* prototype chain test */ 88 | a = {x:2, y: 2, "1": 3}; 89 | b = {"4" : 3 }; 90 | Object.setPrototypeOf(a, b); 91 | tab = []; 92 | for(i in a) { 93 | tab.push(i); 94 | } 95 | assert(tab.toString(), "1,x,y,4", "for_in"); 96 | 97 | /* non enumerable properties hide enumerables ones in the 98 | prototype chain */ 99 | a = {y: 2, "1": 3}; 100 | Object.defineProperty(a, "x", { value: 1 }); 101 | b = {"x" : 3 }; 102 | Object.setPrototypeOf(a, b); 103 | tab = []; 104 | for(i in a) { 105 | tab.push(i); 106 | } 107 | assert(tab.toString(), "1,y", "for_in"); 108 | 109 | /* array optimization */ 110 | a = []; 111 | for(i = 0; i < 10; i++) 112 | a.push(i); 113 | tab = []; 114 | for(i in a) { 115 | tab.push(i); 116 | } 117 | assert(tab.toString(), "0,1,2,3,4,5,6,7,8,9", "for_in"); 118 | 119 | /* iterate with a field */ 120 | a={x:0}; 121 | tab = []; 122 | for(a.x in {x:1, y: 2}) { 123 | tab.push(a.x); 124 | } 125 | assert(tab.toString(), "x,y", "for_in"); 126 | 127 | /* iterate with a variable field */ 128 | a=[0]; 129 | tab = []; 130 | for(a[0] in {x:1, y: 2}) { 131 | tab.push(a[0]); 132 | } 133 | assert(tab.toString(), "x,y", "for_in"); 134 | 135 | /* variable definition in the for in */ 136 | tab = []; 137 | for(var j in {x:1, y: 2}) { 138 | tab.push(j); 139 | } 140 | assert(tab.toString(), "x,y", "for_in"); 141 | 142 | /* variable assigment in the for in */ 143 | tab = []; 144 | for(var k = 2 in {x:1, y: 2}) { 145 | tab.push(k); 146 | } 147 | assert(tab.toString(), "x,y", "for_in"); 148 | } 149 | 150 | function test_for_in2() 151 | { 152 | var i; 153 | tab = []; 154 | for(i in {x:1, y: 2, z:3}) { 155 | if (i === "y") 156 | continue; 157 | tab.push(i); 158 | } 159 | assert(tab.toString() == "x,z"); 160 | 161 | tab = []; 162 | for(i in {x:1, y: 2, z:3}) { 163 | if (i === "z") 164 | break; 165 | tab.push(i); 166 | } 167 | assert(tab.toString() == "x,y"); 168 | } 169 | 170 | function test_for_break() 171 | { 172 | var i, c; 173 | c = 0; 174 | L1: for(i = 0; i < 3; i++) { 175 | c++; 176 | if (i == 0) 177 | continue; 178 | while (1) { 179 | break L1; 180 | } 181 | } 182 | assert(c === 2 && i === 1); 183 | } 184 | 185 | function test_switch1() 186 | { 187 | var i, a, s; 188 | s = ""; 189 | for(i = 0; i < 3; i++) { 190 | a = "?"; 191 | switch(i) { 192 | case 0: 193 | a = "a"; 194 | break; 195 | case 1: 196 | a = "b"; 197 | break; 198 | default: 199 | a = "c"; 200 | break; 201 | } 202 | s += a; 203 | } 204 | assert(s === "abc" && i === 3); 205 | } 206 | 207 | function test_switch2() 208 | { 209 | var i, a, s; 210 | s = ""; 211 | for(i = 0; i < 4; i++) { 212 | a = "?"; 213 | switch(i) { 214 | case 0: 215 | a = "a"; 216 | break; 217 | case 1: 218 | a = "b"; 219 | break; 220 | case 2: 221 | continue; 222 | default: 223 | a = "" + i; 224 | break; 225 | } 226 | s += a; 227 | } 228 | assert(s === "ab3" && i === 4); 229 | } 230 | 231 | function test_try_catch1() 232 | { 233 | try { 234 | throw "hello"; 235 | } catch (e) { 236 | assert(e, "hello", "catch"); 237 | return; 238 | } 239 | assert(false, "catch"); 240 | } 241 | 242 | function test_try_catch2() 243 | { 244 | var a; 245 | try { 246 | a = 1; 247 | } catch (e) { 248 | a = 2; 249 | } 250 | assert(a, 1, "catch"); 251 | } 252 | 253 | function test_try_catch3() 254 | { 255 | var s; 256 | s = ""; 257 | try { 258 | s += "t"; 259 | } catch (e) { 260 | s += "c"; 261 | } finally { 262 | s += "f"; 263 | } 264 | assert(s, "tf", "catch"); 265 | } 266 | 267 | function test_try_catch4() 268 | { 269 | var s; 270 | s = ""; 271 | try { 272 | s += "t"; 273 | throw "c"; 274 | } catch (e) { 275 | s += e; 276 | } finally { 277 | s += "f"; 278 | } 279 | assert(s, "tcf", "catch"); 280 | } 281 | 282 | function test_try_catch5() 283 | { 284 | var s; 285 | s = ""; 286 | for(;;) { 287 | try { 288 | s += "t"; 289 | break; 290 | s += "b"; 291 | } finally { 292 | s += "f"; 293 | } 294 | } 295 | assert(s, "tf", "catch"); 296 | } 297 | 298 | function test_try_catch6() 299 | { 300 | function f() { 301 | try { 302 | s += 't'; 303 | return 1; 304 | } finally { 305 | s += "f"; 306 | } 307 | } 308 | var s = ""; 309 | assert(f() === 1); 310 | assert(s, "tf", "catch6"); 311 | } 312 | 313 | function test_try_catch7() 314 | { 315 | var s; 316 | s = ""; 317 | 318 | try { 319 | try { 320 | s += "t"; 321 | throw "a"; 322 | } finally { 323 | s += "f"; 324 | } 325 | } catch(e) { 326 | s += e; 327 | } finally { 328 | s += "g"; 329 | } 330 | assert(s, "tfag", "catch"); 331 | } 332 | 333 | function test_try_catch8() 334 | { 335 | var i, s; 336 | 337 | s = ""; 338 | for(var i in {x:1, y:2}) { 339 | try { 340 | s += i; 341 | throw "a"; 342 | } catch (e) { 343 | s += e; 344 | } finally { 345 | s += "f"; 346 | } 347 | } 348 | assert(s === "xafyaf"); 349 | } 350 | 351 | test_while(); 352 | test_while_break(); 353 | test_do_while(); 354 | test_for(); 355 | test_for_break(); 356 | test_switch1(); 357 | test_switch2(); 358 | test_for_in(); 359 | test_for_in2(); 360 | 361 | test_try_catch1(); 362 | test_try_catch2(); 363 | test_try_catch3(); 364 | test_try_catch4(); 365 | test_try_catch5(); 366 | test_try_catch6(); 367 | test_try_catch7(); 368 | test_try_catch8(); 369 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/tests/test_op.js: -------------------------------------------------------------------------------- 1 | function assert(actual, expected, message) { 2 | if (arguments.length == 1) 3 | expected = true; 4 | 5 | if (actual === expected) 6 | return; 7 | 8 | if (actual !== null && expected !== null 9 | && typeof actual == 'object' && typeof expected == 'object' 10 | && actual.toString() === expected.toString()) 11 | return; 12 | 13 | throw Error("assertion failed: got |" + actual + "|" + 14 | ", expected |" + expected + "|" + 15 | (message ? " (" + message + ")" : "")); 16 | } 17 | 18 | // load more elaborate version of assert if available 19 | try { __loadScript("test_assert.js"); } catch(e) {} 20 | 21 | /*----------------*/ 22 | 23 | function test_op1() 24 | { 25 | var r, a; 26 | r = 1 + 2; 27 | assert(r, 3, "1 + 2 === 3"); 28 | 29 | r = 1 - 2; 30 | assert(r, -1, "1 - 2 === -1"); 31 | 32 | r = -1; 33 | assert(r, -1, "-1 === -1"); 34 | 35 | r = +2; 36 | assert(r, 2, "+2 === 2"); 37 | 38 | r = 2 * 3; 39 | assert(r, 6, "2 * 3 === 6"); 40 | 41 | r = 4 / 2; 42 | assert(r, 2, "4 / 2 === 2"); 43 | 44 | r = 4 % 3; 45 | assert(r, 1, "4 % 3 === 3"); 46 | 47 | r = 4 << 2; 48 | assert(r, 16, "4 << 2 === 16"); 49 | 50 | r = 1 << 0; 51 | assert(r, 1, "1 << 0 === 1"); 52 | 53 | r = 1 << 31; 54 | assert(r, -2147483648, "1 << 31 === -2147483648"); 55 | 56 | r = 1 << 32; 57 | assert(r, 1, "1 << 32 === 1"); 58 | 59 | r = (1 << 31) < 0; 60 | assert(r, true, "(1 << 31) < 0 === true"); 61 | 62 | r = -4 >> 1; 63 | assert(r, -2, "-4 >> 1 === -2"); 64 | 65 | r = -4 >>> 1; 66 | assert(r, 0x7ffffffe, "-4 >>> 1 === 0x7ffffffe"); 67 | 68 | r = 1 & 1; 69 | assert(r, 1, "1 & 1 === 1"); 70 | 71 | r = 0 | 1; 72 | assert(r, 1, "0 | 1 === 1"); 73 | 74 | r = 1 ^ 1; 75 | assert(r, 0, "1 ^ 1 === 0"); 76 | 77 | r = ~1; 78 | assert(r, -2, "~1 === -2"); 79 | 80 | r = !1; 81 | assert(r, false, "!1 === false"); 82 | 83 | assert((1 < 2), true, "(1 < 2) === true"); 84 | 85 | assert((2 > 1), true, "(2 > 1) === true"); 86 | 87 | assert(('b' > 'a'), true, "('b' > 'a') === true"); 88 | 89 | assert(2 ** 8, 256, "2 ** 8 === 256"); 90 | } 91 | 92 | function test_cvt() 93 | { 94 | assert((NaN | 0) === 0); 95 | assert((Infinity | 0) === 0); 96 | assert(((-Infinity) | 0) === 0); 97 | assert(("12345" | 0) === 12345); 98 | assert(("0x12345" | 0) === 0x12345); 99 | assert(((4294967296 * 3 - 4) | 0) === -4); 100 | 101 | assert(("12345" >>> 0) === 12345); 102 | assert(("0x12345" >>> 0) === 0x12345); 103 | assert((NaN >>> 0) === 0); 104 | assert((Infinity >>> 0) === 0); 105 | assert(((-Infinity) >>> 0) === 0); 106 | assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4)); 107 | } 108 | 109 | function test_eq() 110 | { 111 | assert(null == undefined); 112 | assert(undefined == null); 113 | assert(true == 1); 114 | assert(0 == false); 115 | assert("" == 0); 116 | assert("123" == 123); 117 | assert("122" != 123); 118 | assert((new Number(1)) == 1); 119 | assert(2 == (new Number(2))); 120 | assert((new String("abc")) == "abc"); 121 | assert({} != "abc"); 122 | } 123 | 124 | function test_inc_dec() 125 | { 126 | var a, r; 127 | 128 | a = 1; 129 | r = a++; 130 | assert(r === 1 && a === 2, true, "++"); 131 | 132 | a = 1; 133 | r = ++a; 134 | assert(r === 2 && a === 2, true, "++"); 135 | 136 | a = 1; 137 | r = a--; 138 | assert(r === 1 && a === 0, true, "--"); 139 | 140 | a = 1; 141 | r = --a; 142 | assert(r === 0 && a === 0, true, "--"); 143 | 144 | a = {x:true}; 145 | a.x++; 146 | assert(a.x, 2, "++"); 147 | 148 | a = {x:true}; 149 | a.x--; 150 | assert(a.x, 0, "--"); 151 | 152 | a = [true]; 153 | a[0]++; 154 | assert(a[0], 2, "++"); 155 | 156 | a = {x:true}; 157 | r = a.x++; 158 | assert(r === 1 && a.x === 2, true, "++"); 159 | 160 | a = {x:true}; 161 | r = a.x--; 162 | assert(r === 1 && a.x === 0, true, "--"); 163 | 164 | a = [true]; 165 | r = a[0]++; 166 | assert(r === 1 && a[0] === 2, true, "++"); 167 | 168 | a = [true]; 169 | r = a[0]--; 170 | assert(r === 1 && a[0] === 0, true, "--"); 171 | } 172 | 173 | function F(x) 174 | { 175 | this.x = x; 176 | } 177 | 178 | function test_op2() 179 | { 180 | var a, b; 181 | a = new Object; 182 | a.x = 1; 183 | assert(a.x, 1, "new"); 184 | b = new F(2); 185 | assert(b.x, 2, "new"); 186 | 187 | a = {x : 2}; 188 | assert(("x" in a), true, "in"); 189 | assert(("y" in a), false, "in"); 190 | 191 | a = {}; 192 | assert((a instanceof Object), true, "instanceof"); 193 | assert((a instanceof String), false, "instanceof"); 194 | 195 | assert((typeof 1), "number", "typeof"); 196 | assert((typeof Object), "function", "typeof"); 197 | assert((typeof null), "object", "typeof"); 198 | assert((typeof unknown_var), "undefined", "typeof"); 199 | 200 | a = {x: 1, y: 1}; 201 | assert((delete a.x), true, "delete"); 202 | assert(("x" in a), false, "delete"); 203 | 204 | a = {x: 1, if: 2}; 205 | assert(a.if === 2); 206 | } 207 | 208 | function test_prototype() 209 | { 210 | function f() { } 211 | assert(f.prototype.constructor, f, "prototype"); 212 | } 213 | 214 | function test_arguments() 215 | { 216 | function f2() { 217 | assert(arguments.length, 2, "arguments"); 218 | assert(arguments[0], 1, "arguments"); 219 | assert(arguments[1], 3, "arguments"); 220 | } 221 | f2(1, 3); 222 | } 223 | 224 | function test_class() 225 | { 226 | var o; 227 | class C { 228 | constructor() { 229 | this.x = 10; 230 | } 231 | f() { 232 | return 1; 233 | } 234 | static F() { 235 | return -1; 236 | } 237 | get y() { 238 | return 12; 239 | } 240 | }; 241 | class D extends C { 242 | constructor() { 243 | super(); 244 | this.z = 20; 245 | } 246 | g() { 247 | return 2; 248 | } 249 | static G() { 250 | return -2; 251 | } 252 | h() { 253 | return super.f(); 254 | } 255 | static H() { 256 | return super["F"](); 257 | } 258 | } 259 | 260 | assert(C.F() === -1); 261 | assert(Object.getOwnPropertyDescriptor(C.prototype, "y").get.name === "get y"); 262 | 263 | o = new C(); 264 | assert(o.f() === 1); 265 | assert(o.x === 10); 266 | 267 | assert(D.F() === -1); 268 | assert(D.G() === -2); 269 | assert(D.H() === -1); 270 | 271 | o = new D(); 272 | assert(o.f() === 1); 273 | assert(o.g() === 2); 274 | assert(o.x === 10); 275 | assert(o.z === 20); 276 | assert(o.h() === 1); 277 | 278 | /* test class name scope */ 279 | var E1 = class E { static F() { return E; } }; 280 | assert(E1 === E1.F()); 281 | }; 282 | 283 | function test_template() 284 | { 285 | var a, b; 286 | b = 123; 287 | a = `abc${b}d`; 288 | assert(a === "abc123d"); 289 | 290 | a = String.raw `abc${b}d`; 291 | assert(a === "abc123d"); 292 | } 293 | 294 | test_op1(); 295 | test_cvt(); 296 | test_eq(); 297 | test_inc_dec(); 298 | test_op2(); 299 | test_prototype(); 300 | test_arguments(); 301 | test_class(); 302 | test_template(); 303 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/tests/test_std.js: -------------------------------------------------------------------------------- 1 | import * as std from "std"; 2 | import * as os from "os"; 3 | 4 | function assert(actual, expected, message) { 5 | if (arguments.length == 1) 6 | expected = true; 7 | 8 | if (actual === expected) 9 | return; 10 | 11 | if (actual !== null && expected !== null 12 | && typeof actual == 'object' && typeof expected == 'object' 13 | && actual.toString() === expected.toString()) 14 | return; 15 | 16 | throw Error("assertion failed: got |" + actual + "|" + 17 | ", expected |" + expected + "|" + 18 | (message ? " (" + message + ")" : "")); 19 | } 20 | 21 | // load more elaborate version of assert if available 22 | try { std.loadScript("test_assert.js"); } catch(e) {} 23 | 24 | /*----------------*/ 25 | 26 | function test_printf() 27 | { 28 | assert(std.sprintf("a=%d s=%s", 123, "abc"), "a=123 s=abc"); 29 | } 30 | 31 | function test_file1() 32 | { 33 | var f, len, str, size, buf, ret, i, str1; 34 | 35 | f = std.tmpfile(); 36 | str = "hello world\n"; 37 | f.puts(str); 38 | 39 | f.seek(0, std.SEEK_SET); 40 | str1 = f.readAsString(); 41 | assert(str1 === str); 42 | 43 | f.seek(0, std.SEEK_END); 44 | size = f.tell(); 45 | assert(size === str.length); 46 | 47 | f.seek(0, std.SEEK_SET); 48 | 49 | buf = new Uint8Array(size); 50 | ret = f.read(buf.buffer, 0, size); 51 | assert(ret === size); 52 | for(i = 0; i < size; i++) 53 | assert(buf[i] === str.charCodeAt(i)); 54 | 55 | f.close(); 56 | } 57 | 58 | function test_file2() 59 | { 60 | var f, str, i, size; 61 | f = std.tmpfile(); 62 | str = "hello world\n"; 63 | size = str.length; 64 | for(i = 0; i < size; i++) 65 | f.putByte(str.charCodeAt(i)); 66 | f.seek(0, std.SEEK_SET); 67 | for(i = 0; i < size; i++) { 68 | assert(str.charCodeAt(i) === f.getByte()); 69 | } 70 | assert(f.getByte() === -1); 71 | f.close(); 72 | } 73 | 74 | function test_getline() 75 | { 76 | var f, line, line_count, lines, i; 77 | 78 | lines = ["hello world", "line 1", "line 2" ]; 79 | f = std.tmpfile(); 80 | for(i = 0; i < lines.length; i++) { 81 | f.puts(lines[i], "\n"); 82 | } 83 | 84 | f.seek(0, std.SEEK_SET); 85 | assert(!f.eof()); 86 | line_count = 0; 87 | for(;;) { 88 | line = f.getline(); 89 | if (line === null) 90 | break; 91 | assert(line == lines[line_count]); 92 | line_count++; 93 | } 94 | assert(f.eof()); 95 | assert(line_count === lines.length); 96 | 97 | f.close(); 98 | } 99 | 100 | function test_os() 101 | { 102 | var fd, fname, buf, buf2, i; 103 | 104 | assert(os.isatty(0)); 105 | 106 | fname = "tmp_file.txt"; 107 | fd = os.open(fname, os.O_RDWR | os.O_CREAT | os.O_TRUNC); 108 | assert(fd >= 0); 109 | 110 | buf = new Uint8Array(10); 111 | for(i = 0; i < buf.length; i++) 112 | buf[i] = i; 113 | assert(os.write(fd, buf.buffer, 0, buf.length) === buf.length); 114 | 115 | assert(os.seek(fd, 0, os.SEEK_SET) === 0); 116 | buf2 = new Uint8Array(buf.length); 117 | assert(os.read(fd, buf2.buffer, 0, buf2.length) === buf2.length); 118 | 119 | for(i = 0; i < buf.length; i++) 120 | assert(buf[i] == buf2[i]); 121 | 122 | assert(os.close(fd) === 0); 123 | 124 | assert(os.remove(fname) === 0); 125 | 126 | fd = os.open(fname, os.O_RDONLY); 127 | assert(fd < 0); 128 | } 129 | 130 | function test_timer() 131 | { 132 | var th, i; 133 | 134 | /* just test that a timer can be inserted and removed */ 135 | th = []; 136 | for(i = 0; i < 3; i++) 137 | th[i] = os.setTimeout(1000, function () { }); 138 | for(i = 0; i < 3; i++) 139 | os.clearTimeout(th[i]); 140 | } 141 | 142 | test_printf(); 143 | test_file1(); 144 | test_file2(); 145 | test_getline(); 146 | test_os(); 147 | test_timer(); 148 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/unicode_gen_def.h: -------------------------------------------------------------------------------- 1 | #ifdef UNICODE_GENERAL_CATEGORY 2 | DEF(Cn, "Unassigned") /* must be zero */ 3 | DEF(Lu, "Uppercase_Letter") 4 | DEF(Ll, "Lowercase_Letter") 5 | DEF(Lt, "Titlecase_Letter") 6 | DEF(Lm, "Modifier_Letter") 7 | DEF(Lo, "Other_Letter") 8 | DEF(Mn, "Nonspacing_Mark") 9 | DEF(Mc, "Spacing_Mark") 10 | DEF(Me, "Enclosing_Mark") 11 | DEF(Nd, "Decimal_Number,digit") 12 | DEF(Nl, "Letter_Number") 13 | DEF(No, "Other_Number") 14 | DEF(Sm, "Math_Symbol") 15 | DEF(Sc, "Currency_Symbol") 16 | DEF(Sk, "Modifier_Symbol") 17 | DEF(So, "Other_Symbol") 18 | DEF(Pc, "Connector_Punctuation") 19 | DEF(Pd, "Dash_Punctuation") 20 | DEF(Ps, "Open_Punctuation") 21 | DEF(Pe, "Close_Punctuation") 22 | DEF(Pi, "Initial_Punctuation") 23 | DEF(Pf, "Final_Punctuation") 24 | DEF(Po, "Other_Punctuation") 25 | DEF(Zs, "Space_Separator") 26 | DEF(Zl, "Line_Separator") 27 | DEF(Zp, "Paragraph_Separator") 28 | DEF(Cc, "Control,cntrl") 29 | DEF(Cf, "Format") 30 | DEF(Cs, "Surrogate") 31 | DEF(Co, "Private_Use") 32 | /* synthetic properties */ 33 | DEF(LC, "Cased_Letter") 34 | DEF(L, "Letter") 35 | DEF(M, "Mark,Combining_Mark") 36 | DEF(N, "Number") 37 | DEF(S, "Symbol") 38 | DEF(P, "Punctuation,punct") 39 | DEF(Z, "Separator") 40 | DEF(C, "Other") 41 | #endif 42 | 43 | #ifdef UNICODE_SCRIPT 44 | DEF(Unknown, "Zzzz") 45 | DEF(Adlam, "Adlm") 46 | DEF(Ahom, "Ahom") 47 | DEF(Anatolian_Hieroglyphs, "Hluw") 48 | DEF(Arabic, "Arab") 49 | DEF(Armenian, "Armn") 50 | DEF(Avestan, "Avst") 51 | DEF(Balinese, "Bali") 52 | DEF(Bamum, "Bamu") 53 | DEF(Bassa_Vah, "Bass") 54 | DEF(Batak, "Batk") 55 | DEF(Bengali, "Beng") 56 | DEF(Bhaiksuki, "Bhks") 57 | DEF(Bopomofo, "Bopo") 58 | DEF(Brahmi, "Brah") 59 | DEF(Braille, "Brai") 60 | DEF(Buginese, "Bugi") 61 | DEF(Buhid, "Buhd") 62 | DEF(Canadian_Aboriginal, "Cans") 63 | DEF(Carian, "Cari") 64 | DEF(Caucasian_Albanian, "Aghb") 65 | DEF(Chakma, "Cakm") 66 | DEF(Cham, "Cham") 67 | DEF(Cherokee, "Cher") 68 | DEF(Common, "Zyyy") 69 | DEF(Coptic, "Copt,Qaac") 70 | DEF(Cuneiform, "Xsux") 71 | DEF(Cypriot, "Cprt") 72 | DEF(Cyrillic, "Cyrl") 73 | DEF(Deseret, "Dsrt") 74 | DEF(Devanagari, "Deva") 75 | DEF(Dogra, "Dogr") 76 | DEF(Duployan, "Dupl") 77 | DEF(Egyptian_Hieroglyphs, "Egyp") 78 | DEF(Elbasan, "Elba") 79 | DEF(Ethiopic, "Ethi") 80 | DEF(Georgian, "Geor") 81 | DEF(Glagolitic, "Glag") 82 | DEF(Gothic, "Goth") 83 | DEF(Grantha, "Gran") 84 | DEF(Greek, "Grek") 85 | DEF(Gujarati, "Gujr") 86 | DEF(Gunjala_Gondi, "Gong") 87 | DEF(Gurmukhi, "Guru") 88 | DEF(Han, "Hani") 89 | DEF(Hangul, "Hang") 90 | DEF(Hanifi_Rohingya, "Rohg") 91 | DEF(Hanunoo, "Hano") 92 | DEF(Hatran, "Hatr") 93 | DEF(Hebrew, "Hebr") 94 | DEF(Hiragana, "Hira") 95 | DEF(Imperial_Aramaic, "Armi") 96 | DEF(Inherited, "Zinh,Qaai") 97 | DEF(Inscriptional_Pahlavi, "Phli") 98 | DEF(Inscriptional_Parthian, "Prti") 99 | DEF(Javanese, "Java") 100 | DEF(Kaithi, "Kthi") 101 | DEF(Kannada, "Knda") 102 | DEF(Katakana, "Kana") 103 | DEF(Kayah_Li, "Kali") 104 | DEF(Kharoshthi, "Khar") 105 | DEF(Khmer, "Khmr") 106 | DEF(Khojki, "Khoj") 107 | DEF(Khudawadi, "Sind") 108 | DEF(Lao, "Laoo") 109 | DEF(Latin, "Latn") 110 | DEF(Lepcha, "Lepc") 111 | DEF(Limbu, "Limb") 112 | DEF(Linear_A, "Lina") 113 | DEF(Linear_B, "Linb") 114 | DEF(Lisu, "Lisu") 115 | DEF(Lycian, "Lyci") 116 | DEF(Lydian, "Lydi") 117 | DEF(Makasar, "Maka") 118 | DEF(Mahajani, "Mahj") 119 | DEF(Malayalam, "Mlym") 120 | DEF(Mandaic, "Mand") 121 | DEF(Manichaean, "Mani") 122 | DEF(Marchen, "Marc") 123 | DEF(Masaram_Gondi, "Gonm") 124 | DEF(Medefaidrin, "Medf") 125 | DEF(Meetei_Mayek, "Mtei") 126 | DEF(Mende_Kikakui, "Mend") 127 | DEF(Meroitic_Cursive, "Merc") 128 | DEF(Meroitic_Hieroglyphs, "Mero") 129 | DEF(Miao, "Plrd") 130 | DEF(Modi, "Modi") 131 | DEF(Mongolian, "Mong") 132 | DEF(Mro, "Mroo") 133 | DEF(Multani, "Mult") 134 | DEF(Myanmar, "Mymr") 135 | DEF(Nabataean, "Nbat") 136 | DEF(New_Tai_Lue, "Talu") 137 | DEF(Newa, "Newa") 138 | DEF(Nko, "Nkoo") 139 | DEF(Nushu, "Nshu") 140 | DEF(Ogham, "Ogam") 141 | DEF(Ol_Chiki, "Olck") 142 | DEF(Old_Hungarian, "Hung") 143 | DEF(Old_Italic, "Ital") 144 | DEF(Old_North_Arabian, "Narb") 145 | DEF(Old_Permic, "Perm") 146 | DEF(Old_Persian, "Xpeo") 147 | DEF(Old_Sogdian, "Sogo") 148 | DEF(Old_South_Arabian, "Sarb") 149 | DEF(Old_Turkic, "Orkh") 150 | DEF(Oriya, "Orya") 151 | DEF(Osage, "Osge") 152 | DEF(Osmanya, "Osma") 153 | DEF(Pahawh_Hmong, "Hmng") 154 | DEF(Palmyrene, "Palm") 155 | DEF(Pau_Cin_Hau, "Pauc") 156 | DEF(Phags_Pa, "Phag") 157 | DEF(Phoenician, "Phnx") 158 | DEF(Psalter_Pahlavi, "Phlp") 159 | DEF(Rejang, "Rjng") 160 | DEF(Runic, "Runr") 161 | DEF(Samaritan, "Samr") 162 | DEF(Saurashtra, "Saur") 163 | DEF(Sharada, "Shrd") 164 | DEF(Shavian, "Shaw") 165 | DEF(Siddham, "Sidd") 166 | DEF(SignWriting, "Sgnw") 167 | DEF(Sinhala, "Sinh") 168 | DEF(Sogdian, "Sogd") 169 | DEF(Sora_Sompeng, "Sora") 170 | DEF(Soyombo, "Soyo") 171 | DEF(Sundanese, "Sund") 172 | DEF(Syloti_Nagri, "Sylo") 173 | DEF(Syriac, "Syrc") 174 | DEF(Tagalog, "Tglg") 175 | DEF(Tagbanwa, "Tagb") 176 | DEF(Tai_Le, "Tale") 177 | DEF(Tai_Tham, "Lana") 178 | DEF(Tai_Viet, "Tavt") 179 | DEF(Takri, "Takr") 180 | DEF(Tamil, "Taml") 181 | DEF(Tangut, "Tang") 182 | DEF(Telugu, "Telu") 183 | DEF(Thaana, "Thaa") 184 | DEF(Thai, "Thai") 185 | DEF(Tibetan, "Tibt") 186 | DEF(Tifinagh, "Tfng") 187 | DEF(Tirhuta, "Tirh") 188 | DEF(Ugaritic, "Ugar") 189 | DEF(Vai, "Vaii") 190 | DEF(Warang_Citi, "Wara") 191 | DEF(Yi, "Yiii") 192 | DEF(Zanabazar_Square, "Zanb") 193 | #endif 194 | 195 | #ifdef UNICODE_PROP_LIST 196 | /* Prop list not exported to regexp */ 197 | DEF(Hyphen, "") 198 | DEF(Other_Math, "") 199 | DEF(Other_Alphabetic, "") 200 | DEF(Other_Lowercase, "") 201 | DEF(Other_Uppercase, "") 202 | DEF(Other_Grapheme_Extend, "") 203 | DEF(Other_Default_Ignorable_Code_Point, "") 204 | DEF(Other_ID_Start, "") 205 | DEF(Other_ID_Continue, "") 206 | DEF(Prepended_Concatenation_Mark, "") 207 | /* additional computed properties for smaller tables */ 208 | DEF(ID_Continue1, "") 209 | DEF(XID_Start1, "") 210 | DEF(XID_Continue1, "") 211 | DEF(Changes_When_Titlecased1, "") 212 | DEF(Changes_When_Casefolded1, "") 213 | DEF(Changes_When_NFKC_Casefolded1, "") 214 | 215 | /* Prop list exported to JS */ 216 | DEF(ASCII_Hex_Digit, "AHex") 217 | DEF(Bidi_Control, "Bidi_C") 218 | DEF(Dash, "") 219 | DEF(Deprecated, "Dep") 220 | DEF(Diacritic, "Dia") 221 | DEF(Extender, "Ext") 222 | DEF(Hex_Digit, "Hex") 223 | DEF(IDS_Binary_Operator, "IDSB") 224 | DEF(IDS_Trinary_Operator, "IDST") 225 | DEF(Ideographic, "Ideo") 226 | DEF(Join_Control, "Join_C") 227 | DEF(Logical_Order_Exception, "LOE") 228 | DEF(Noncharacter_Code_Point, "NChar") 229 | DEF(Pattern_Syntax, "Pat_Syn") 230 | DEF(Pattern_White_Space, "Pat_WS") 231 | DEF(Quotation_Mark, "QMark") 232 | DEF(Radical, "") 233 | DEF(Regional_Indicator, "RI") 234 | DEF(Sentence_Terminal, "STerm") 235 | DEF(Soft_Dotted, "SD") 236 | DEF(Terminal_Punctuation, "Term") 237 | DEF(Unified_Ideograph, "UIdeo") 238 | DEF(Variation_Selector, "VS") 239 | DEF(White_Space, "space") 240 | DEF(Bidi_Mirrored, "Bidi_M") 241 | DEF(Emoji, "") 242 | DEF(Emoji_Component, "") 243 | DEF(Emoji_Modifier, "") 244 | DEF(Emoji_Modifier_Base, "") 245 | DEF(Emoji_Presentation, "") 246 | DEF(Extended_Pictographic, "") 247 | DEF(Default_Ignorable_Code_Point, "DI") 248 | DEF(ID_Start, "IDS") 249 | DEF(Case_Ignorable, "CI") 250 | 251 | /* other binary properties */ 252 | DEF(ASCII,"") 253 | DEF(Alphabetic, "Alpha") 254 | DEF(Any, "") 255 | DEF(Assigned,"") 256 | DEF(Cased, "") 257 | DEF(Changes_When_Casefolded, "CWCF") 258 | DEF(Changes_When_Casemapped, "CWCM") 259 | DEF(Changes_When_Lowercased, "CWL") 260 | DEF(Changes_When_NFKC_Casefolded, "CWKCF") 261 | DEF(Changes_When_Titlecased, "CWT") 262 | DEF(Changes_When_Uppercased, "CWU") 263 | DEF(Grapheme_Base, "Gr_Base") 264 | DEF(Grapheme_Extend, "Gr_Ext") 265 | DEF(ID_Continue, "IDC") 266 | DEF(Lowercase, "Lower") 267 | DEF(Math, "") 268 | DEF(Uppercase, "Upper") 269 | DEF(XID_Continue, "XIDC") 270 | DEF(XID_Start, "XIDS") 271 | 272 | /* internal tables with index */ 273 | DEF(Cased1, "") 274 | 275 | #endif 276 | -------------------------------------------------------------------------------- /quickjs-2019-07-09/wrapper-helpers.c: -------------------------------------------------------------------------------- 1 | #include "quickjs.h" 2 | 3 | JSValue Helper_JS_NewFloat64(JSContext *ctx, double d) { 4 | return JS_NewFloat64(ctx, d); 5 | } 6 | 7 | JSValue Helper_JS_NewBool(JSContext *ctx, JS_BOOL val) { 8 | return JS_NewBool(ctx, val); 9 | } 10 | 11 | void Helper_JS_FreeValue(JSContext *ctx, JSValue v) { 12 | return JS_FreeValue(ctx, v); 13 | } 14 | 15 | JSValue Helper_JS_DupValue(JSContext *ctx, JSValueConst v) { 16 | return JS_DupValue(ctx, v); 17 | } 18 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/Changelog: -------------------------------------------------------------------------------- 1 | 2019-07-28: 2 | 3 | - added dynamic import 4 | - added Promise.allSettled 5 | - added String.prototype.matchAll 6 | - added Object.fromEntries 7 | - reduced number of ticks in await 8 | - added BigInt support in Atomics 9 | - exported JS_NewPromiseCapability() 10 | - misc async function and async generator fixes 11 | - enabled hashbang support by default 12 | 13 | 2019-07-21: 14 | 15 | - updated test262 tests 16 | - updated to Unicode version 12.1.0 17 | - fixed missing Date object in qjsc 18 | - fixed multi-context creation 19 | - misc ES2020 related fixes 20 | - simplified power and division operators in bignum extension 21 | - fixed several crash conditions 22 | 23 | 2019-07-09: 24 | 25 | - first public release 26 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/TODO: -------------------------------------------------------------------------------- 1 | - fix regexp skip in js_parse_skip_parens_token() 2 | - 64-bit atoms in 64-bit mode? 3 | - rename CONFIG_ALL_UNICODE, CONFIG_BIGNUM, CONFIG_ATOMICS, CONFIG_CHECK_JSVALUE ? 4 | - unify coding style and naming conventions 5 | - use names from the ECMA spec in library implementation 6 | - modules: if no ".", use a well known module loading path ? 7 | - use JSHoistedDef only for global variables (JSHoistedDef.var_name != JS_ATOM_NULL) 8 | - add index in JSVarDef and is_arg flag to merge args and vars in JSFunctionDef 9 | - replace most JSVarDef flags with var_type enumeration 10 | - use byte code emitters with typed arguments (for clarity) 11 | - use 2 bytecode DynBufs in JSFunctionDef, one for reading, one for writing 12 | and use the same wrappers in all phases 13 | - use more generic method for line numbers in resolve_variables and resolve_labels 14 | 15 | Memory: 16 | - test border cases for max number of atoms, object properties, string length 17 | - add emergency malloc mode for out of memory exceptions. 18 | - test all DynBuf memory errors 19 | - test all js_realloc memory errors 20 | - bignum: handle memory errors 21 | - use memory pools for objects, etc? 22 | - improve JS_ComputeMemoryUsage() with more info 23 | 24 | Optimizations: 25 | - use auto-init properties for more global objects 26 | - reuse stack slots for disjoint scopes, if strip 27 | - optimize `for of` iterator for built-in array objects 28 | - add heuristic to avoid some cycles in closures 29 | - small String (0-2 charcodes) with immediate storage 30 | - perform static string concatenation at compile time 31 | - optimize string concatenation with ropes or miniropes? 32 | - add implicit numeric strings for Uint32 numbers? 33 | - optimize `s += a + b`, `s += a.b` and similar simple expressions 34 | - ensure string canonical representation and optimise comparisons and hashes? 35 | - remove JSObject.first_weak_ref, use bit+context based hashed array for weak references 36 | - optimize function storage with length and name accessors? 37 | - property access optimization on the global object, functions, 38 | prototypes and special non extensible objects. 39 | - create object literals with the correct length by backpatching length argument 40 | - remove redundant set_loc_uninitialized/check_uninitialized opcodes 41 | - peephole optim: push_atom_value, to_propkey -> push_atom_value 42 | - peephole optim: put_loc x, get_loc_check x -> set_loc x 43 | - comparative performance benchmark 44 | - use variable name when throwing uninitialized exception if available 45 | - convert slow array to fast array when all properties != length are numeric 46 | - optimize destructuring assignments for global and local variables 47 | - implement some form of tail-call-optimization 48 | - debugger keyword support 49 | - optimize OP_apply 50 | - optimize f(...b) 51 | 52 | Extensions: 53 | - support more features in [features] section 54 | - add TC39 stage 3 proposals: String.prototype.matchAll, Symbol.matchAll 55 | - fix preprocessor bug if nested #ifdef in jscompress.c 56 | - add built-in preprocessor in compiler, get rid of jscompress 57 | handle #if, #ifdef, #line, limited support for #define 58 | - limited support for web assembly 59 | - get rid of __loadScript, use more common name 60 | - BSD sockets 61 | - Process or thread control 62 | - use custom printf to avoid C library compatibility issues 63 | - use custom timezone support to avoid C library compatibility issues 64 | 65 | REPL: 66 | - strip internal functions from stack trace 67 | - readline: support MS Windows terminal 68 | - readline: handle dynamic terminal resizing 69 | - multiline editing 70 | - debugger 71 | - runtime object and function inspectors 72 | - interactive object browser 73 | - use more generic approach to display evaluation results 74 | - improve directive handling: dispatch, colorize, completion... 75 | - save history 76 | - close all predefined methods in repl.js and jscalc.js 77 | 78 | Test262o: 0/11262 errors, 463 excluded 79 | Test262: 33/58145 errors, 785 excluded, 5576 skipped 80 | Test262bn: 39/60250 errors, 718 excluded, 4587 skipped 81 | test262 commit: 2ee3864136747ee69401b2d266e234cdd0a95965 82 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/VERSION: -------------------------------------------------------------------------------- 1 | 2019-07-28 2 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/bjson.c: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS: binary JSON module (test only) 3 | * 4 | * Copyright (c) 2017-2019 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #include "quickjs-libc.h" 25 | #include "cutils.h" 26 | 27 | static JSValue js_bjson_read(JSContext *ctx, JSValueConst this_val, 28 | int argc, JSValueConst *argv) 29 | { 30 | uint8_t *buf; 31 | uint64_t pos, len; 32 | JSValue obj; 33 | size_t size; 34 | 35 | if (JS_ToIndex(ctx, &pos, argv[1])) 36 | return JS_EXCEPTION; 37 | if (JS_ToIndex(ctx, &len, argv[2])) 38 | return JS_EXCEPTION; 39 | buf = JS_GetArrayBuffer(ctx, &size, argv[0]); 40 | if (!buf) 41 | return JS_EXCEPTION; 42 | if (pos + len > size) 43 | return JS_ThrowRangeError(ctx, "array buffer overflow"); 44 | obj = JS_ReadObject(ctx, buf + pos, len, 0); 45 | return obj; 46 | } 47 | 48 | static JSValue js_bjson_write(JSContext *ctx, JSValueConst this_val, 49 | int argc, JSValueConst *argv) 50 | { 51 | size_t len; 52 | uint8_t *buf; 53 | JSValue array; 54 | 55 | buf = JS_WriteObject(ctx, &len, argv[0], 0); 56 | if (!buf) 57 | return JS_EXCEPTION; 58 | array = JS_NewArrayBufferCopy(ctx, buf, len); 59 | js_free(ctx, buf); 60 | return array; 61 | } 62 | 63 | static const JSCFunctionListEntry js_bjson_funcs[] = { 64 | JS_CFUNC_DEF("read", 3, js_bjson_read ), 65 | JS_CFUNC_DEF("write", 1, js_bjson_write ), 66 | }; 67 | 68 | static int js_bjson_init(JSContext *ctx, JSModuleDef *m) 69 | { 70 | return JS_SetModuleExportList(ctx, m, js_bjson_funcs, 71 | countof(js_bjson_funcs)); 72 | } 73 | 74 | #ifdef JS_SHARED_LIBRARY 75 | #define JS_INIT_MODULE js_init_module 76 | #else 77 | #define JS_INIT_MODULE js_init_module_bjson 78 | #endif 79 | 80 | JSModuleDef *JS_INIT_MODULE(JSContext *ctx, const char *module_name) 81 | { 82 | JSModuleDef *m; 83 | m = JS_NewCModule(ctx, module_name, js_bjson_init); 84 | if (!m) 85 | return NULL; 86 | JS_AddModuleExportList(ctx, m, js_bjson_funcs, countof(js_bjson_funcs)); 87 | return m; 88 | } 89 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/cutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * C utilities 3 | * 4 | * Copyright (c) 2017 Fabrice Bellard 5 | * Copyright (c) 2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | #ifndef CUTILS_H 26 | #define CUTILS_H 27 | 28 | #include 29 | #include 30 | 31 | /* set if CPU is big endian */ 32 | #undef WORDS_BIGENDIAN 33 | 34 | #define likely(x) __builtin_expect(!!(x), 1) 35 | #define unlikely(x) __builtin_expect(!!(x), 0) 36 | #define force_inline inline __attribute__((always_inline)) 37 | #define no_inline __attribute__((noinline)) 38 | 39 | #define xglue(x, y) x ## y 40 | #define glue(x, y) xglue(x, y) 41 | #define stringify(s) tostring(s) 42 | #define tostring(s) #s 43 | 44 | #ifndef offsetof 45 | #define offsetof(type, field) ((size_t) &((type *)0)->field) 46 | #endif 47 | #ifndef countof 48 | #define countof(x) (sizeof(x) / sizeof((x)[0])) 49 | #endif 50 | 51 | typedef int BOOL; 52 | 53 | #ifndef FALSE 54 | enum { 55 | FALSE = 0, 56 | TRUE = 1, 57 | }; 58 | #endif 59 | 60 | void pstrcpy(char *buf, int buf_size, const char *str); 61 | char *pstrcat(char *buf, int buf_size, const char *s); 62 | int strstart(const char *str, const char *val, const char **ptr); 63 | int has_suffix(const char *str, const char *suffix); 64 | 65 | static inline int max_int(int a, int b) 66 | { 67 | if (a > b) 68 | return a; 69 | else 70 | return b; 71 | } 72 | 73 | static inline int min_int(int a, int b) 74 | { 75 | if (a < b) 76 | return a; 77 | else 78 | return b; 79 | } 80 | 81 | static inline uint32_t max_uint32(uint32_t a, uint32_t b) 82 | { 83 | if (a > b) 84 | return a; 85 | else 86 | return b; 87 | } 88 | 89 | static inline uint32_t min_uint32(uint32_t a, uint32_t b) 90 | { 91 | if (a < b) 92 | return a; 93 | else 94 | return b; 95 | } 96 | 97 | static inline int64_t max_int64(int64_t a, int64_t b) 98 | { 99 | if (a > b) 100 | return a; 101 | else 102 | return b; 103 | } 104 | 105 | static inline int64_t min_int64(int64_t a, int64_t b) 106 | { 107 | if (a < b) 108 | return a; 109 | else 110 | return b; 111 | } 112 | 113 | /* WARNING: undefined if a = 0 */ 114 | static inline int clz32(unsigned int a) 115 | { 116 | return __builtin_clz(a); 117 | } 118 | 119 | /* WARNING: undefined if a = 0 */ 120 | static inline int clz64(uint64_t a) 121 | { 122 | return __builtin_clzll(a); 123 | } 124 | 125 | /* WARNING: undefined if a = 0 */ 126 | static inline int ctz32(unsigned int a) 127 | { 128 | return __builtin_ctz(a); 129 | } 130 | 131 | /* WARNING: undefined if a = 0 */ 132 | static inline int ctz64(uint64_t a) 133 | { 134 | return __builtin_ctzll(a); 135 | } 136 | 137 | struct __attribute__((packed)) packed_u64 { 138 | uint64_t v; 139 | }; 140 | 141 | struct __attribute__((packed)) packed_u32 { 142 | uint32_t v; 143 | }; 144 | 145 | struct __attribute__((packed)) packed_u16 { 146 | uint16_t v; 147 | }; 148 | 149 | static inline uint64_t get_u64(const uint8_t *tab) 150 | { 151 | return ((const struct packed_u64 *)tab)->v; 152 | } 153 | 154 | static inline int64_t get_i64(const uint8_t *tab) 155 | { 156 | return (int64_t)((const struct packed_u64 *)tab)->v; 157 | } 158 | 159 | static inline void put_u64(uint8_t *tab, uint64_t val) 160 | { 161 | ((struct packed_u64 *)tab)->v = val; 162 | } 163 | 164 | static inline uint32_t get_u32(const uint8_t *tab) 165 | { 166 | return ((const struct packed_u32 *)tab)->v; 167 | } 168 | 169 | static inline int32_t get_i32(const uint8_t *tab) 170 | { 171 | return (int32_t)((const struct packed_u32 *)tab)->v; 172 | } 173 | 174 | static inline void put_u32(uint8_t *tab, uint32_t val) 175 | { 176 | ((struct packed_u32 *)tab)->v = val; 177 | } 178 | 179 | static inline uint32_t get_u16(const uint8_t *tab) 180 | { 181 | return ((const struct packed_u16 *)tab)->v; 182 | } 183 | 184 | static inline int32_t get_i16(const uint8_t *tab) 185 | { 186 | return (int16_t)((const struct packed_u16 *)tab)->v; 187 | } 188 | 189 | static inline void put_u16(uint8_t *tab, uint16_t val) 190 | { 191 | ((struct packed_u16 *)tab)->v = val; 192 | } 193 | 194 | static inline uint32_t get_u8(const uint8_t *tab) 195 | { 196 | return *tab; 197 | } 198 | 199 | static inline int32_t get_i8(const uint8_t *tab) 200 | { 201 | return (int8_t)*tab; 202 | } 203 | 204 | static inline void put_u8(uint8_t *tab, uint8_t val) 205 | { 206 | *tab = val; 207 | } 208 | 209 | static inline uint16_t bswap16(uint16_t x) 210 | { 211 | return (x >> 8) | (x << 8); 212 | } 213 | 214 | static inline uint32_t bswap32(uint32_t v) 215 | { 216 | return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) | 217 | ((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24); 218 | } 219 | 220 | static inline uint64_t bswap64(uint64_t v) 221 | { 222 | return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) | 223 | ((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) | 224 | ((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) | 225 | ((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) | 226 | ((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) | 227 | ((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) | 228 | ((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) | 229 | ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8)); 230 | } 231 | 232 | /* XXX: should take an extra argument to pass slack information to the caller */ 233 | typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size); 234 | 235 | typedef struct DynBuf { 236 | uint8_t *buf; 237 | size_t size; 238 | size_t allocated_size; 239 | BOOL error; /* true if a memory allocation error occurred */ 240 | DynBufReallocFunc *realloc_func; 241 | void *opaque; /* for realloc_func */ 242 | } DynBuf; 243 | 244 | void dbuf_init(DynBuf *s); 245 | void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func); 246 | int dbuf_realloc(DynBuf *s, size_t new_size); 247 | int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len); 248 | int dbuf_put(DynBuf *s, const uint8_t *data, size_t len); 249 | int dbuf_put_self(DynBuf *s, size_t offset, size_t len); 250 | int dbuf_putc(DynBuf *s, uint8_t c); 251 | int dbuf_putstr(DynBuf *s, const char *str); 252 | static inline int dbuf_put_u16(DynBuf *s, uint16_t val) 253 | { 254 | return dbuf_put(s, (uint8_t *)&val, 2); 255 | } 256 | static inline int dbuf_put_u32(DynBuf *s, uint32_t val) 257 | { 258 | return dbuf_put(s, (uint8_t *)&val, 4); 259 | } 260 | static inline int dbuf_put_u64(DynBuf *s, uint64_t val) 261 | { 262 | return dbuf_put(s, (uint8_t *)&val, 8); 263 | } 264 | int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s, 265 | const char *fmt, ...); 266 | void dbuf_free(DynBuf *s); 267 | static inline BOOL dbuf_error(DynBuf *s) { 268 | return s->error; 269 | } 270 | 271 | #define UTF8_CHAR_LEN_MAX 6 272 | 273 | int unicode_to_utf8(uint8_t *buf, unsigned int c); 274 | int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp); 275 | 276 | static inline int from_hex(int c) 277 | { 278 | if (c >= '0' && c <= '9') 279 | return c - '0'; 280 | else if (c >= 'A' && c <= 'F') 281 | return c - 'A' + 10; 282 | else if (c >= 'a' && c <= 'f') 283 | return c - 'a' + 10; 284 | else 285 | return -1; 286 | } 287 | 288 | void rqsort(void *base, size_t nmemb, size_t size, 289 | int (*cmp)(const void *, const void *, void *), 290 | void *arg); 291 | 292 | #endif /* CUTILS_H */ 293 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/doc/jsbignum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-28/doc/jsbignum.pdf -------------------------------------------------------------------------------- /quickjs-2019-07-28/doc/quickjs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-28/doc/quickjs.pdf -------------------------------------------------------------------------------- /quickjs-2019-07-28/examples/c_module.js: -------------------------------------------------------------------------------- 1 | /* example of JS module importing a C module */ 2 | 3 | import { fib } from "./fib.so"; 4 | 5 | console.log("Hello World"); 6 | console.log("fib(10)=", fib(10)); 7 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/examples/fib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS: Example of C module 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #include "../quickjs.h" 25 | 26 | #define countof(x) (sizeof(x) / sizeof((x)[0])) 27 | 28 | static int fib(int n) 29 | { 30 | if (n <= 0) 31 | return 0; 32 | else if (n == 1) 33 | return 1; 34 | else 35 | return fib(n - 1) + fib(n - 2); 36 | } 37 | 38 | static JSValue js_fib(JSContext *ctx, JSValueConst this_val, 39 | int argc, JSValueConst *argv) 40 | { 41 | int n, res; 42 | if (JS_ToInt32(ctx, &n, argv[0])) 43 | return JS_EXCEPTION; 44 | res = fib(n); 45 | return JS_NewInt32(ctx, res); 46 | } 47 | 48 | static const JSCFunctionListEntry js_fib_funcs[] = { 49 | JS_CFUNC_DEF("fib", 1, js_fib ), 50 | }; 51 | 52 | static int js_fib_init(JSContext *ctx, JSModuleDef *m) 53 | { 54 | return JS_SetModuleExportList(ctx, m, js_fib_funcs, 55 | countof(js_fib_funcs)); 56 | } 57 | 58 | #ifdef JS_SHARED_LIBRARY 59 | #define JS_INIT_MODULE js_init_module 60 | #else 61 | #define JS_INIT_MODULE js_init_module_fib 62 | #endif 63 | 64 | JSModuleDef *JS_INIT_MODULE(JSContext *ctx, const char *module_name) 65 | { 66 | JSModuleDef *m; 67 | m = JS_NewCModule(ctx, module_name, js_fib_init); 68 | if (!m) 69 | return NULL; 70 | JS_AddModuleExportList(ctx, m, js_fib_funcs, countof(js_fib_funcs)); 71 | return m; 72 | } 73 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/examples/fib_module.js: -------------------------------------------------------------------------------- 1 | /* fib module */ 2 | export function fib(n) 3 | { 4 | if (n <= 0) 5 | return 0; 6 | else if (n == 1) 7 | return 1; 8 | else 9 | return fib(n - 1) + fib(n - 2); 10 | } 11 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/examples/hello.js: -------------------------------------------------------------------------------- 1 | console.log("Hello World"); 2 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/examples/hello_module.js: -------------------------------------------------------------------------------- 1 | /* example of JS module */ 2 | 3 | import { fib } from "./fib_module.js"; 4 | 5 | console.log("Hello World"); 6 | console.log("fib(10)=", fib(10)); 7 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/examples/pi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * PI computation in Javascript using the QuickJS bignum extensions 3 | */ 4 | "use strict"; 5 | "use bigint"; 6 | 7 | /* compute PI with a precision of 'prec' bits */ 8 | function calc_pi(prec) { 9 | const CHUD_A = 13591409; 10 | const CHUD_B = 545140134; 11 | const CHUD_C = 640320; 12 | const CHUD_C3 = 10939058860032000; /* C^3/24 */ 13 | const CHUD_BITS_PER_TERM = 47.11041313821584202247; /* log2(C/12)*3 */ 14 | 15 | /* return [P, Q, G] */ 16 | function chud_bs(a, b, need_G) { 17 | var c, P, Q, G, P1, Q1, G1, P2, Q2, G2; 18 | if (a == (b - 1)) { 19 | G = (2 * b - 1) * (6 * b - 1) * (6 * b - 5); 20 | P = BigFloat(G * (CHUD_B * b + CHUD_A)); 21 | if (b & 1) 22 | P = -P; 23 | G = BigFloat(G); 24 | Q = BigFloat(b * b * b * CHUD_C3); 25 | } else { 26 | c = (a + b) >> 1; 27 | [P1, Q1, G1] = chud_bs(a, c, true); 28 | [P2, Q2, G2] = chud_bs(c, b, need_G); 29 | P = P1 * Q2 + P2 * G1; 30 | Q = Q1 * Q2; 31 | if (need_G) 32 | G = G1 * G2; 33 | else 34 | G = 0; 35 | } 36 | return [P, Q, G]; 37 | } 38 | 39 | var n, P, Q, G; 40 | /* number of serie terms */ 41 | n = Math.ceil(BigFloatEnv.prec / CHUD_BITS_PER_TERM) + 10; 42 | [P, Q, G] = chud_bs(0, n, false); 43 | Q = Q / (P + Q * CHUD_A); 44 | G = (CHUD_C / 12) * BigFloat.sqrt(CHUD_C); 45 | return Q * G; 46 | } 47 | 48 | (function() { 49 | var r, n_digits, n_bits; 50 | if (typeof scriptArgs != "undefined") { 51 | if (scriptArgs.length < 2) { 52 | print("usage: pi n_digits"); 53 | return; 54 | } 55 | n_digits = scriptArgs[1]; 56 | } else { 57 | n_digits = 1000; 58 | } 59 | n_bits = Math.ceil(n_digits * Math.log2(10)); 60 | /* we add more bits to reduce the probability of bad rounding for 61 | the last digits */ 62 | BigFloatEnv.setPrec( () => { 63 | r = calc_pi(); 64 | print(r.toFixed(n_digits, BigFloatEnv.RNDZ)); 65 | }, n_bits + 32); 66 | })(); 67 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/libregexp-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifdef DEF 26 | 27 | DEF(invalid, 1) /* never used */ 28 | DEF(char, 3) 29 | DEF(char32, 5) 30 | DEF(dot, 1) 31 | DEF(any, 1) /* same as dot but match any character including line terminator */ 32 | DEF(line_start, 1) 33 | DEF(line_end, 1) 34 | DEF(goto, 5) 35 | DEF(split_goto_first, 5) 36 | DEF(split_next_first, 5) 37 | DEF(match, 1) 38 | DEF(save_start, 2) /* save start position */ 39 | DEF(save_end, 2) /* save end position, must come after saved_start */ 40 | DEF(save_reset, 3) /* reset save positions */ 41 | DEF(loop, 5) /* decrement the top the stack and goto if != 0 */ 42 | DEF(push_i32, 5) /* push integer on the stack */ 43 | DEF(drop, 1) 44 | DEF(word_boundary, 1) 45 | DEF(not_word_boundary, 1) 46 | DEF(back_reference, 2) 47 | DEF(backward_back_reference, 2) /* must come after back_reference */ 48 | DEF(range, 3) /* variable length */ 49 | DEF(range32, 3) /* variable length */ 50 | DEF(lookahead, 5) 51 | DEF(negative_lookahead, 5) 52 | DEF(push_char_pos, 1) /* push the character position on the stack */ 53 | DEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character 54 | position */ 55 | DEF(prev, 1) /* go to the previous char */ 56 | DEF(simple_greedy_quant, 17) 57 | 58 | #endif /* DEF */ 59 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/libregexp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBREGEXP_H 25 | #define LIBREGEXP_H 26 | 27 | #include 28 | 29 | #include "libunicode.h" 30 | 31 | #define LRE_BOOL int /* for documentation purposes */ 32 | 33 | #define LRE_FLAG_GLOBAL (1 << 0) 34 | #define LRE_FLAG_IGNORECASE (1 << 1) 35 | #define LRE_FLAG_MULTILINE (1 << 2) 36 | #define LRE_FLAG_DOTALL (1 << 3) 37 | #define LRE_FLAG_UTF16 (1 << 4) 38 | #define LRE_FLAG_STICKY (1 << 5) 39 | 40 | #define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */ 41 | 42 | uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size, 43 | const char *buf, size_t buf_len, int re_flags, 44 | void *opaque); 45 | int lre_get_capture_count(const uint8_t *bc_buf); 46 | int lre_get_flags(const uint8_t *bc_buf); 47 | int lre_exec(uint8_t **capture, 48 | const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen, 49 | int cbuf_type, void *opaque); 50 | 51 | int lre_parse_escape(const uint8_t **pp, int allow_utf16); 52 | LRE_BOOL lre_is_space(int c); 53 | 54 | /* must be provided by the user */ 55 | LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size); 56 | void *lre_realloc(void *opaque, void *ptr, size_t size); 57 | 58 | /* JS identifier test */ 59 | extern uint32_t const lre_id_start_table_ascii[4]; 60 | extern uint32_t const lre_id_continue_table_ascii[4]; 61 | 62 | static inline int lre_js_is_ident_first(int c) 63 | { 64 | if ((uint32_t)c < 128) { 65 | return (lre_id_start_table_ascii[c >> 5] >> (c & 31)) & 1; 66 | } else { 67 | #ifdef CONFIG_ALL_UNICODE 68 | return lre_is_id_start(c); 69 | #else 70 | return !lre_is_space(c); 71 | #endif 72 | } 73 | } 74 | 75 | static inline int lre_js_is_ident_next(int c) 76 | { 77 | if ((uint32_t)c < 128) { 78 | return (lre_id_continue_table_ascii[c >> 5] >> (c & 31)) & 1; 79 | } else { 80 | /* ZWNJ and ZWJ are accepted in identifiers */ 81 | #ifdef CONFIG_ALL_UNICODE 82 | return lre_is_id_continue(c) || c == 0x200C || c == 0x200D; 83 | #else 84 | return !lre_is_space(c) || c == 0x200C || c == 0x200D; 85 | #endif 86 | } 87 | } 88 | 89 | #undef LRE_BOOL 90 | 91 | #endif /* LIBREGEXP_H */ 92 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/libunicode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Unicode utilities 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBUNICODE_H 25 | #define LIBUNICODE_H 26 | 27 | #include 28 | 29 | #define LRE_BOOL int /* for documentation purposes */ 30 | 31 | /* define it to include all the unicode tables (40KB larger) */ 32 | #define CONFIG_ALL_UNICODE 33 | 34 | #define LRE_CC_RES_LEN_MAX 3 35 | 36 | typedef enum { 37 | UNICODE_NFC, 38 | UNICODE_NFD, 39 | UNICODE_NFKC, 40 | UNICODE_NFKD, 41 | } UnicodeNormalizationEnum; 42 | 43 | int lre_case_conv(uint32_t *res, uint32_t c, int conv_type); 44 | LRE_BOOL lre_is_cased(uint32_t c); 45 | LRE_BOOL lre_is_case_ignorable(uint32_t c); 46 | 47 | /* char ranges */ 48 | 49 | typedef struct { 50 | int len; /* in points, always even */ 51 | int size; 52 | uint32_t *points; /* points sorted by increasing value */ 53 | void *mem_opaque; 54 | void *(*realloc_func)(void *opaque, void *ptr, size_t size); 55 | } CharRange; 56 | 57 | typedef enum { 58 | CR_OP_UNION, 59 | CR_OP_INTER, 60 | CR_OP_XOR, 61 | } CharRangeOpEnum; 62 | 63 | void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); 64 | void cr_free(CharRange *cr); 65 | int cr_realloc(CharRange *cr, int size); 66 | int cr_copy(CharRange *cr, const CharRange *cr1); 67 | 68 | static inline int cr_add_point(CharRange *cr, uint32_t v) 69 | { 70 | if (cr->len >= cr->size) { 71 | if (cr_realloc(cr, cr->len + 1)) 72 | return -1; 73 | } 74 | cr->points[cr->len++] = v; 75 | return 0; 76 | } 77 | 78 | static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2) 79 | { 80 | if ((cr->len + 2) > cr->size) { 81 | if (cr_realloc(cr, cr->len + 2)) 82 | return -1; 83 | } 84 | cr->points[cr->len++] = c1; 85 | cr->points[cr->len++] = c2; 86 | return 0; 87 | } 88 | 89 | int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len); 90 | 91 | static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2) 92 | { 93 | uint32_t b_pt[2]; 94 | b_pt[0] = c1; 95 | b_pt[1] = c2 + 1; 96 | return cr_union1(cr, b_pt, 2); 97 | } 98 | 99 | int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len, 100 | const uint32_t *b_pt, int b_len, int op); 101 | 102 | int cr_invert(CharRange *cr); 103 | 104 | #ifdef CONFIG_ALL_UNICODE 105 | 106 | LRE_BOOL lre_is_id_start(uint32_t c); 107 | LRE_BOOL lre_is_id_continue(uint32_t c); 108 | 109 | int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len, 110 | UnicodeNormalizationEnum n_type, 111 | void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); 112 | 113 | /* Unicode character range functions */ 114 | 115 | int unicode_script(CharRange *cr, 116 | const char *script_name, LRE_BOOL is_ext); 117 | int unicode_general_category(CharRange *cr, const char *gc_name); 118 | int unicode_prop(CharRange *cr, const char *prop_name); 119 | 120 | #endif /* CONFIG_ALL_UNICODE */ 121 | 122 | #undef LRE_BOOL 123 | 124 | #endif /* LIBUNICODE_H */ 125 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Linux klist like system 3 | * 4 | * Copyright (c) 2016-2017 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIST_H 25 | #define LIST_H 26 | 27 | #ifndef NULL 28 | #include 29 | #endif 30 | 31 | struct list_head { 32 | struct list_head *prev; 33 | struct list_head *next; 34 | }; 35 | 36 | #define LIST_HEAD_INIT(el) { &(el), &(el) } 37 | 38 | /* return the pointer of type 'type *' containing 'el' as field 'member' */ 39 | #define list_entry(el, type, member) \ 40 | ((type *)((uint8_t *)(el) - offsetof(type, member))) 41 | 42 | static inline void init_list_head(struct list_head *head) 43 | { 44 | head->prev = head; 45 | head->next = head; 46 | } 47 | 48 | /* insert 'el' between 'prev' and 'next' */ 49 | static inline void __list_add(struct list_head *el, 50 | struct list_head *prev, struct list_head *next) 51 | { 52 | prev->next = el; 53 | el->prev = prev; 54 | el->next = next; 55 | next->prev = el; 56 | } 57 | 58 | /* add 'el' at the head of the list 'head' (= after element head) */ 59 | static inline void list_add(struct list_head *el, struct list_head *head) 60 | { 61 | __list_add(el, head, head->next); 62 | } 63 | 64 | /* add 'el' at the end of the list 'head' (= before element head) */ 65 | static inline void list_add_tail(struct list_head *el, struct list_head *head) 66 | { 67 | __list_add(el, head->prev, head); 68 | } 69 | 70 | static inline void list_del(struct list_head *el) 71 | { 72 | struct list_head *prev, *next; 73 | prev = el->prev; 74 | next = el->next; 75 | prev->next = next; 76 | next->prev = prev; 77 | el->prev = NULL; /* fail safe */ 78 | el->next = NULL; /* fail safe */ 79 | } 80 | 81 | static inline int list_empty(struct list_head *el) 82 | { 83 | return el->next == el; 84 | } 85 | 86 | #define list_for_each(el, head) \ 87 | for(el = (head)->next; el != (head); el = el->next) 88 | 89 | #define list_for_each_safe(el, el1, head) \ 90 | for(el = (head)->next, el1 = el->next; el != (head); \ 91 | el = el1, el1 = el->next) 92 | 93 | #define list_for_each_prev(el, head) \ 94 | for(el = (head)->prev; el != (head); el = el->prev) 95 | 96 | #define list_for_each_prev_safe(el, el1, head) \ 97 | for(el = (head)->prev, el1 = el->prev; el != (head); \ 98 | el = el1, el1 = el->prev) 99 | 100 | #endif /* LIST_H */ 101 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/quickjs-libc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS C library 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef QUICKJS_LIBC_H 25 | #define QUICKJS_LIBC_H 26 | 27 | #include 28 | #include 29 | 30 | #include "quickjs.h" 31 | 32 | JSModuleDef *js_init_module_std(JSContext *ctx, const char *module_name); 33 | JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name); 34 | void js_std_add_helpers(JSContext *ctx, int argc, char **argv); 35 | void js_std_loop(JSContext *ctx); 36 | void js_std_free_handlers(JSRuntime *rt); 37 | void js_std_dump_error(JSContext *ctx); 38 | uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename); 39 | JSModuleDef *js_module_loader(JSContext *ctx, 40 | const char *module_name, void *opaque); 41 | void js_std_eval_binary(JSContext *ctx, const uint8_t *buf, size_t buf_len, 42 | int flags); 43 | 44 | #endif /* QUICKJS_LIBC_H */ 45 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/readme.txt: -------------------------------------------------------------------------------- 1 | The main documentation is in doc/quickjs.pdf or doc/quickjs.html. 2 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Release the QuickJS source code 3 | 4 | set -e 5 | 6 | version=`cat VERSION` 7 | 8 | if [ "$1" = "-h" ] ; then 9 | echo "release.sh [all]" 10 | echo "" 11 | echo "all: build all the archives. Otherwise only build the quickjs source archive." 12 | exit 1 13 | fi 14 | 15 | 16 | if [ "$1" = "all" ] ; then 17 | 18 | #################################################" 19 | # unicode data 20 | 21 | d="quickjs-${version}" 22 | name="quickjs-unicode-data-${version}" 23 | outdir="/tmp/${d}" 24 | 25 | rm -rf $outdir 26 | mkdir -p $outdir $outdir/unicode 27 | 28 | cp unicode/* $outdir/unicode 29 | 30 | ( cd /tmp && tar Jcvf /tmp/${name}.tar.xz ${d} ) 31 | 32 | #################################################" 33 | # all tests 34 | 35 | d="quickjs-${version}" 36 | name="quickjs-tests-${version}" 37 | outdir="/tmp/${d}" 38 | 39 | rm -rf $outdir 40 | mkdir -p $outdir $outdir/test262o $outdir/test262 $outdir/tests 41 | 42 | cp -a test262o/test $outdir/test262o 43 | 44 | cp -a test262/test test262/harness $outdir/test262 45 | 46 | cp -a tests/bench-v8 $outdir/tests 47 | 48 | ( cd /tmp && tar Jcvf /tmp/${name}.tar.xz ${d} ) 49 | 50 | fi # all 51 | 52 | #################################################" 53 | # quickjs 54 | 55 | make build_doc 56 | 57 | d="quickjs-${version}" 58 | outdir="/tmp/${d}" 59 | 60 | rm -rf $outdir 61 | mkdir -p $outdir $outdir/doc $outdir/tests $outdir/examples 62 | 63 | cp Makefile VERSION TODO Changelog readme.txt release.sh unicode_download.sh \ 64 | qjs.c qjsc.c qjscalc.js repl.js \ 65 | quickjs.c quickjs.h quickjs-atom.h \ 66 | quickjs-libc.c quickjs-libc.h quickjs-opcode.h \ 67 | cutils.c cutils.h list.h \ 68 | libregexp.c libregexp.h libregexp-opcode.h \ 69 | libunicode.c libunicode.h libunicode-table.h \ 70 | libbf.c libbf.h \ 71 | jscompress.c unicode_gen.c unicode_gen_def.h \ 72 | bjson.c \ 73 | run-test262.c test262o.conf test262.conf test262bn.conf \ 74 | test262o_errors.txt test262_errors.txt test262bn_errors.txt \ 75 | $outdir 76 | 77 | cp tests/*.js tests/*.patch $outdir/tests 78 | 79 | cp examples/*.js examples/*.c $outdir/examples 80 | 81 | cp doc/quickjs.texi doc/quickjs.pdf doc/quickjs.html \ 82 | doc/jsbignum.texi doc/jsbignum.html doc/jsbignum.pdf \ 83 | $outdir/doc 84 | 85 | ( cd /tmp && tar Jcvf /tmp/${d}.tar.xz ${d} ) 86 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/test262.conf: -------------------------------------------------------------------------------- 1 | [config] 2 | # general settings for test262 ES6 version 3 | 4 | # framework style: old, new 5 | style=new 6 | 7 | # handle tests tagged as [noStrict]: yes, no, skip 8 | nostrict=yes 9 | 10 | # handle tests tagged as [strictOnly]: yes, no, skip 11 | strict=yes 12 | 13 | # test mode: default, default-nostrict, default-strict, strict, nostrict, both, all 14 | mode=default 15 | 16 | # handle tests flagged as [async]: yes, no, skip 17 | # for these, load 'harness/doneprintHandle.js' prior to test 18 | # and expect `print('Test262:AsyncTestComplete')` to be called for 19 | # successful termination 20 | async=yes 21 | 22 | # handle tests flagged as [module]: yes, no, skip 23 | module=yes 24 | 25 | # output error messages: yes, no 26 | verbose=yes 27 | 28 | # load harness files from this directory 29 | harnessdir=test262/harness 30 | 31 | # names of harness include files to skip 32 | #harnessexclude= 33 | 34 | # name of the error file for known errors 35 | errorfile=test262_errors.txt 36 | 37 | # exclude tests enumerated in this file (see also [exclude] section) 38 | #excludefile=test262_exclude.txt 39 | 40 | # report test results to this file 41 | reportfile=test262_report.txt 42 | 43 | # enumerate tests from this directory 44 | testdir=test262/test 45 | 46 | [features] 47 | # Standard language features and proposed extensions 48 | # list the features that are included 49 | # skipped features are tagged as such to avoid warnings 50 | 51 | Array.prototype.flat 52 | Array.prototype.flatMap 53 | Array.prototype.flatten 54 | Array.prototype.values 55 | ArrayBuffer 56 | arrow-function 57 | async-functions 58 | async-iteration 59 | Atomics 60 | BigInt=skip 61 | caller 62 | class 63 | class-fields-private=skip 64 | class-fields-public=skip 65 | class-methods-private=skip 66 | class-static-fields-public=skip 67 | class-static-fields-private=skip 68 | class-static-methods-private=skip 69 | computed-property-names 70 | const 71 | cross-realm=skip 72 | DataView 73 | DataView.prototype.getFloat32 74 | DataView.prototype.getFloat64 75 | DataView.prototype.getInt16 76 | DataView.prototype.getInt32 77 | DataView.prototype.getInt8 78 | DataView.prototype.getUint16 79 | DataView.prototype.getUint32 80 | DataView.prototype.setUint8 81 | default-arg 82 | default-parameters 83 | destructuring-assignment 84 | destructuring-binding 85 | dynamic-import 86 | export-star-as-namespace-from-module 87 | FinalizationGroup=skip 88 | Float32Array 89 | Float64Array 90 | for-of 91 | generators 92 | globalThis=skip 93 | hashbang 94 | host-gc-required=skip 95 | import.meta=skip 96 | Int32Array 97 | Int8Array 98 | IsHTMLDDA=skip 99 | json-superset 100 | let 101 | Map 102 | new.target 103 | numeric-separator-literal 104 | object-rest 105 | object-spread 106 | Object.fromEntries 107 | Object.is 108 | optional-catch-binding 109 | Promise.allSettled 110 | Promise.prototype.finally 111 | Proxy 112 | proxy-missing-checks=skip 113 | Reflect 114 | Reflect.construct 115 | Reflect.set 116 | Reflect.setPrototypeOf 117 | regexp-dotall 118 | regexp-lookbehind 119 | regexp-named-groups 120 | regexp-unicode-property-escapes 121 | rest-parameters 122 | Set 123 | SharedArrayBuffer 124 | string-trimming 125 | String.fromCodePoint 126 | String.prototype.endsWith 127 | String.prototype.includes 128 | String.prototype.matchAll 129 | String.prototype.trimEnd 130 | String.prototype.trimStart 131 | super 132 | Symbol 133 | Symbol.asyncIterator 134 | Symbol.hasInstance 135 | Symbol.isConcatSpreadable 136 | Symbol.iterator 137 | Symbol.match 138 | Symbol.matchAll 139 | Symbol.prototype.description 140 | Symbol.replace 141 | Symbol.search 142 | Symbol.species 143 | Symbol.split 144 | Symbol.toPrimitive 145 | Symbol.toStringTag 146 | Symbol.unscopables 147 | tail-call-optimization=skip 148 | template 149 | TypedArray 150 | u180e 151 | Uint16Array 152 | Uint8Array 153 | Uint8ClampedArray 154 | WeakMap 155 | WeakRef=skip 156 | WeakSet 157 | well-formed-json-stringify 158 | 159 | [exclude] 160 | # list excluded tests and directories here 161 | 162 | # intl not supported 163 | test262/test/intl402/ 164 | 165 | # these builtins are not supported: 166 | test262/test/built-ins/BigInt/ 167 | 168 | # incompatible with the "caller" feature 169 | test262/test/built-ins/Function/prototype/restricted-property-caller.js 170 | test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js 171 | 172 | # no debugger keyword support 173 | test262/test/language/statements/debugger/statement.js 174 | 175 | # bogus html close comment test with syntax error 176 | test262/test/annexB/built-ins/Function/createdynfn-html-close-comment-params.js 177 | 178 | # bogus tests 179 | test262/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen.js 180 | test262/test/language/expressions/dynamic-import/for-await-resolution-and-error.js 181 | 182 | # slow tests 183 | #test262/test/built-ins/RegExp/CharacterClassEscapes/ 184 | #test262/test/built-ins/RegExp/property-escapes/ 185 | 186 | [tests] 187 | # list test files or use config.testdir 188 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/test262_errors.txt: -------------------------------------------------------------------------------- 1 | test262/test/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js:25: Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all 2 | test262/test/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js:25: strict mode: Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all 3 | test262/test/annexB/language/eval-code/direct/var-env-lower-lex-catch-non-strict.js:32: SyntaxError: redeclaration of err 4 | test262/test/annexB/language/function-code/function-redeclaration-block.js:18: SyntaxError: invalid redefinition of lexical identifier 5 | test262/test/annexB/language/function-code/function-redeclaration-switch.js:32: SyntaxError: invalid redefinition of lexical identifier 6 | test262/test/annexB/language/statements/try/catch-redeclared-for-of-var.js:19: SyntaxError: invalid redefinition of lexical identifier 7 | test262/test/annexB/language/statements/try/catch-redeclared-for-of-var.js:19: strict mode: SyntaxError: invalid redefinition of lexical identifier 8 | test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:19: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.) 9 | test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:19: strict mode: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.) 10 | test262/test/built-ins/TypedArray/prototype/sort/stability.js:15: Test262Error: pre-sorted (Testing with Float64Array.) 11 | test262/test/built-ins/TypedArray/prototype/sort/stability.js:15: strict mode: Test262Error: pre-sorted (Testing with Float64Array.) 12 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-function.js:37: unexpected error type: Test262: This statement should not be evaluated. 13 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-function.js:37: strict mode: unexpected error type: Test262: This statement should not be evaluated. 14 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-generator.js:37: unexpected error type: Test262: This statement should not be evaluated. 15 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-generator.js:37: strict mode: unexpected error type: Test262: This statement should not be evaluated. 16 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-class.js:36: unexpected error type: Test262: This statement should not be evaluated. 17 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-class.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 18 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-const.js:36: unexpected error type: Test262: This statement should not be evaluated. 19 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-const.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 20 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-function.js:36: unexpected error type: Test262: This statement should not be evaluated. 21 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-function.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 22 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-generator.js:37: unexpected error type: Test262: This statement should not be evaluated. 23 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-generator.js:37: strict mode: unexpected error type: Test262: This statement should not be evaluated. 24 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-let.js:36: unexpected error type: Test262: This statement should not be evaluated. 25 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-let.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 26 | test262/test/language/computed-property-names/class/static/method-number.js:9: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'prototype', 'name', 'a', 'c'])` returns `true` 27 | test262/test/language/computed-property-names/class/static/method-number.js:9: strict mode: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'prototype', 'name', 'a', 'c'])` returns `true` 28 | test262/test/language/computed-property-names/class/static/method-string.js:9: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'b', 'c', 'd'])` returns `true` 29 | test262/test/language/computed-property-names/class/static/method-string.js:9: strict mode: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'b', 'c', 'd'])` returns `true` 30 | test262/test/language/computed-property-names/class/static/method-symbol.js:10: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'c'])` returns `true` 31 | test262/test/language/computed-property-names/class/static/method-symbol.js:10: strict mode: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'c'])` returns `true` 32 | test262/test/language/expressions/dynamic-import/usage-from-eval.js:26: TypeError: $DONE() not called 33 | test262/test/language/expressions/dynamic-import/usage-from-eval.js:26: strict mode: TypeError: $DONE() not called 34 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/test262bn.conf: -------------------------------------------------------------------------------- 1 | [config] 2 | # general settings for test262 ES6 bignum version 3 | 4 | # framework style: old, new 5 | style=new 6 | 7 | # handle tests tagged as [noStrict]: yes, no, skip 8 | nostrict=yes 9 | 10 | # handle tests tagged as [strictOnly]: yes, no, skip 11 | strict=yes 12 | 13 | # test mode: default, default-nostrict, default-strict, strict, nostrict, both, all 14 | mode=default 15 | 16 | # handle tests flagged as [async]: yes, no, skip 17 | # for these, load 'harness/doneprintHandle.js' prior to test 18 | # and expect `print('Test262:AsyncTestComplete')` to be called for 19 | # successful termination 20 | async=yes 21 | 22 | # handle tests flagged as [module]: yes, no, skip 23 | module=yes 24 | 25 | # output error messages: yes, no 26 | verbose=yes 27 | 28 | # load harness files from this directory 29 | harnessdir=test262/harness 30 | 31 | # names of harness include files to skip 32 | # bignum version does not support Atomics 33 | harnessexclude=testAtomics.js 34 | 35 | # name of the error file for known errors 36 | errorfile=test262bn_errors.txt 37 | 38 | # exclude tests enumerated in this file (see also [exclude] section) 39 | #excludefile=test262bn_exclude.txt 40 | 41 | # report test results to this file 42 | reportfile=test262bn_report.txt 43 | 44 | # enumerate tests from this directory 45 | testdir=test262/test 46 | 47 | [features] 48 | # Standard language features and proposed extensions 49 | # list the features that are included 50 | # skipped features are tagged as such to avoid warnings 51 | 52 | Array.prototype.flat 53 | Array.prototype.flatMap 54 | Array.prototype.flatten 55 | Array.prototype.values 56 | ArrayBuffer 57 | arrow-function 58 | async-functions 59 | async-iteration 60 | Atomics 61 | BigInt 62 | caller 63 | class 64 | class-fields-private=skip 65 | class-fields-public=skip 66 | class-methods-private=skip 67 | class-static-fields-public=skip 68 | class-static-fields-private=skip 69 | class-static-methods-private=skip 70 | computed-property-names 71 | const 72 | cross-realm=skip 73 | DataView 74 | DataView.prototype.getFloat32 75 | DataView.prototype.getFloat64 76 | DataView.prototype.getInt16 77 | DataView.prototype.getInt32 78 | DataView.prototype.getInt8 79 | DataView.prototype.getUint16 80 | DataView.prototype.getUint32 81 | DataView.prototype.setUint8 82 | default-arg 83 | default-parameters 84 | destructuring-assignment 85 | destructuring-binding 86 | dynamic-import 87 | export-star-as-namespace-from-module 88 | FinalizationGroup=skip 89 | Float32Array 90 | Float64Array 91 | for-of 92 | generators 93 | globalThis=skip 94 | hashbang 95 | host-gc-required=skip 96 | import.meta=skip 97 | Int32Array 98 | Int8Array 99 | IsHTMLDDA=skip 100 | json-superset 101 | let 102 | Map 103 | new.target 104 | numeric-separator-literal 105 | object-rest 106 | object-spread 107 | Object.fromEntries 108 | Object.is 109 | optional-catch-binding 110 | Promise.allSettled 111 | Promise.prototype.finally 112 | Proxy 113 | proxy-missing-checks=skip 114 | Reflect 115 | Reflect.construct 116 | Reflect.set 117 | Reflect.setPrototypeOf 118 | regexp-dotall 119 | regexp-lookbehind 120 | regexp-named-groups 121 | regexp-unicode-property-escapes 122 | rest-parameters 123 | Set 124 | SharedArrayBuffer 125 | string-trimming 126 | String.fromCodePoint 127 | String.prototype.endsWith 128 | String.prototype.includes 129 | String.prototype.matchAll 130 | String.prototype.trimEnd 131 | String.prototype.trimStart 132 | super 133 | Symbol 134 | Symbol.asyncIterator 135 | Symbol.hasInstance 136 | Symbol.isConcatSpreadable 137 | Symbol.iterator 138 | Symbol.match 139 | Symbol.matchAll 140 | Symbol.prototype.description 141 | Symbol.replace 142 | Symbol.search 143 | Symbol.species 144 | Symbol.split 145 | Symbol.toPrimitive 146 | Symbol.toStringTag 147 | Symbol.unscopables 148 | tail-call-optimization=skip 149 | template 150 | TypedArray 151 | u180e 152 | Uint16Array 153 | Uint8Array 154 | Uint8ClampedArray 155 | WeakMap 156 | WeakRef=skip 157 | WeakSet 158 | well-formed-json-stringify 159 | 160 | [exclude] 161 | # list excluded tests and directories here 162 | 163 | # intl not supported 164 | test262/test/intl402/ 165 | 166 | # incompatible with the "caller" feature 167 | test262/test/built-ins/Function/prototype/restricted-property-caller.js 168 | test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js 169 | 170 | # no debugger keyword support 171 | test262/test/language/statements/debugger/statement.js 172 | 173 | # bogus html close comment test with syntax error 174 | test262/test/annexB/built-ins/Function/createdynfn-html-close-comment-params.js 175 | 176 | # bogus tests 177 | test262/test/language/expressions/dynamic-import/for-await-resolution-and-error-agen.js 178 | test262/test/language/expressions/dynamic-import/for-await-resolution-and-error.js 179 | 180 | # slow tests 181 | #test262/test/built-ins/RegExp/CharacterClassEscapes/ 182 | #test262/test/built-ins/RegExp/property-escapes/ 183 | 184 | [tests] 185 | # list test files or use config.testdir 186 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/test262bn_errors.txt: -------------------------------------------------------------------------------- 1 | test262/test/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js:25: Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all 2 | test262/test/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js:25: strict mode: Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all 3 | test262/test/annexB/language/eval-code/direct/var-env-lower-lex-catch-non-strict.js:32: SyntaxError: redeclaration of err 4 | test262/test/annexB/language/function-code/function-redeclaration-block.js:18: SyntaxError: invalid redefinition of lexical identifier 5 | test262/test/annexB/language/function-code/function-redeclaration-switch.js:32: SyntaxError: invalid redefinition of lexical identifier 6 | test262/test/annexB/language/statements/try/catch-redeclared-for-of-var.js:19: SyntaxError: invalid redefinition of lexical identifier 7 | test262/test/annexB/language/statements/try/catch-redeclared-for-of-var.js:19: strict mode: SyntaxError: invalid redefinition of lexical identifier 8 | test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:19: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.) 9 | test262/test/built-ins/TypedArray/prototype/sort/sort-tonumber.js:19: strict mode: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.) 10 | test262/test/built-ins/TypedArray/prototype/sort/stability.js:15: Test262Error: pre-sorted (Testing with Float64Array.) 11 | test262/test/built-ins/TypedArray/prototype/sort/stability.js:15: strict mode: Test262Error: pre-sorted (Testing with Float64Array.) 12 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-function.js:37: unexpected error type: Test262: This statement should not be evaluated. 13 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-function.js:37: strict mode: unexpected error type: Test262: This statement should not be evaluated. 14 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-generator.js:37: unexpected error type: Test262: This statement should not be evaluated. 15 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-async-generator.js:37: strict mode: unexpected error type: Test262: This statement should not be evaluated. 16 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-class.js:36: unexpected error type: Test262: This statement should not be evaluated. 17 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-class.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 18 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-const.js:36: unexpected error type: Test262: This statement should not be evaluated. 19 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-const.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 20 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-function.js:36: unexpected error type: Test262: This statement should not be evaluated. 21 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-function.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 22 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-generator.js:37: unexpected error type: Test262: This statement should not be evaluated. 23 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-generator.js:37: strict mode: unexpected error type: Test262: This statement should not be evaluated. 24 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-let.js:36: unexpected error type: Test262: This statement should not be evaluated. 25 | test262/test/language/block-scope/syntax/redeclaration/inner-block-var-name-redeclaration-attempt-with-let.js:36: strict mode: unexpected error type: Test262: This statement should not be evaluated. 26 | test262/test/language/computed-property-names/class/static/method-number.js:9: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'prototype', 'name', 'a', 'c'])` returns `true` 27 | test262/test/language/computed-property-names/class/static/method-number.js:9: strict mode: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'prototype', 'name', 'a', 'c'])` returns `true` 28 | test262/test/language/computed-property-names/class/static/method-string.js:9: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'b', 'c', 'd'])` returns `true` 29 | test262/test/language/computed-property-names/class/static/method-string.js:9: strict mode: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'b', 'c', 'd'])` returns `true` 30 | test262/test/language/computed-property-names/class/static/method-symbol.js:10: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'c'])` returns `true` 31 | test262/test/language/computed-property-names/class/static/method-symbol.js:10: strict mode: Test262Error: `compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'c'])` returns `true` 32 | test262/test/language/expressions/dynamic-import/usage-from-eval.js:26: TypeError: $DONE() not called 33 | test262/test/language/expressions/dynamic-import/usage-from-eval.js:26: strict mode: TypeError: $DONE() not called 34 | test262/test/language/literals/bigint/legacy-octal-like-invalid-00n.js:26: unexpected error type: Test262: This statement should not be evaluated. 35 | test262/test/language/literals/bigint/legacy-octal-like-invalid-01n.js:26: unexpected error type: Test262: This statement should not be evaluated. 36 | test262/test/language/literals/bigint/legacy-octal-like-invalid-07n.js:26: unexpected error type: Test262: This statement should not be evaluated. 37 | test262/test/language/literals/bigint/non-octal-like-invalid-0008n.js:26: unexpected error type: Test262: This statement should not be evaluated. 38 | test262/test/language/literals/bigint/non-octal-like-invalid-09n.js:26: unexpected error type: Test262: This statement should not be evaluated. 39 | test262/test/language/literals/bigint/non-octal-like-invalid-012348n.js:26: unexpected error type: Test262: This statement should not be evaluated. 40 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/test262o_errors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flanfly/quickjs-sys/a5afcb404e69099d2e52c99d3a7643eefc684233/quickjs-2019-07-28/test262o_errors.txt -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test262.patch: -------------------------------------------------------------------------------- 1 | diff --git a/harness/atomicsHelper.js b/harness/atomicsHelper.js 2 | index 135c16e..b19f2ef 100644 3 | --- a/harness/atomicsHelper.js 4 | +++ b/harness/atomicsHelper.js 5 | @@ -222,10 +222,14 @@ $262.agent.waitUntil = function(typedArray, index, expected) { 6 | * } 7 | */ 8 | $262.agent.timeouts = { 9 | - yield: 100, 10 | - small: 200, 11 | - long: 1000, 12 | - huge: 10000, 13 | +// yield: 100, 14 | +// small: 200, 15 | +// long: 1000, 16 | +// huge: 10000, 17 | + yield: 20, 18 | + small: 20, 19 | + long: 100, 20 | + huge: 1000, 21 | }; 22 | 23 | /** 24 | diff --git a/harness/doneprintHandle.js b/harness/doneprintHandle.js 25 | index a6ea799..b3dec87 100644 26 | --- a/harness/doneprintHandle.js 27 | +++ b/harness/doneprintHandle.js 28 | @@ -18,5 +18,6 @@ function $DONE(error) { 29 | } 30 | } else { 31 | __consolePrintHandle__('Test262:AsyncTestComplete'); 32 | + $async_done = true; 33 | } 34 | } 35 | diff --git a/harness/regExpUtils.js b/harness/regExpUtils.js 36 | index 2abfee3..e7c07b1 100644 37 | --- a/harness/regExpUtils.js 38 | +++ b/harness/regExpUtils.js 39 | @@ -5,24 +5,27 @@ description: | 40 | Collection of functions used to assert the correctness of RegExp objects. 41 | ---*/ 42 | 43 | +if ($262 && typeof $262.codePointRange === "function") { 44 | + /* use C function to build the codePointRange (much faster with 45 | + slow JS engines) */ 46 | + codePointRange = $262.codePointRange; 47 | +} else { 48 | + codePointRange = function codePointRange(start, end) { 49 | + const codePoints = []; 50 | + let length = 0; 51 | + for (codePoint = start; codePoint < end; codePoint++) { 52 | + codePoints[length++] = codePoint; 53 | + } 54 | + return String.fromCodePoint.apply(null, codePoints); 55 | + } 56 | +} 57 | + 58 | function buildString({ loneCodePoints, ranges }) { 59 | - const CHUNK_SIZE = 10000; 60 | - let result = Reflect.apply(String.fromCodePoint, null, loneCodePoints); 61 | - for (let i = 0; i < ranges.length; i++) { 62 | - const range = ranges[i]; 63 | - const start = range[0]; 64 | - const end = range[1]; 65 | - const codePoints = []; 66 | - for (let length = 0, codePoint = start; codePoint <= end; codePoint++) { 67 | - codePoints[length++] = codePoint; 68 | - if (length === CHUNK_SIZE) { 69 | - result += Reflect.apply(String.fromCodePoint, null, codePoints); 70 | - codePoints.length = length = 0; 71 | - } 72 | + let result = String.fromCodePoint.apply(null, loneCodePoints); 73 | + for (const [start, end] of ranges) { 74 | + result += codePointRange(start, end + 1); 75 | } 76 | - result += Reflect.apply(String.fromCodePoint, null, codePoints); 77 | - } 78 | - return result; 79 | + return result; 80 | } 81 | 82 | function testPropertyEscapes(regex, string, expression) { 83 | diff --git a/test/language/comments/hashbang/use-strict.js b/test/language/comments/hashbang/use-strict.js 84 | index 962614c..541c115 100644 85 | --- a/test/language/comments/hashbang/use-strict.js 86 | +++ b/test/language/comments/hashbang/use-strict.js 87 | @@ -10,7 +10,7 @@ description: > 88 | info: | 89 | HashbangComment:: 90 | #! SingleLineCommentChars[opt] 91 | -flags: [raw] 92 | +flags: [raw, noStrict] 93 | features: [hashbang] 94 | ---*/ 95 | 96 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test_bignum.js: -------------------------------------------------------------------------------- 1 | "use math"; 2 | "use strict"; 3 | 4 | function assert(actual, expected, message) { 5 | if (arguments.length == 1) 6 | expected = true; 7 | 8 | if (actual === expected) 9 | return; 10 | 11 | if (actual !== null && expected !== null 12 | && typeof actual == 'object' && typeof expected == 'object' 13 | && actual.toString() === expected.toString()) 14 | return; 15 | 16 | throw Error("assertion failed: got |" + actual + "|" + 17 | ", expected |" + expected + "|" + 18 | (message ? " (" + message + ")" : "")); 19 | } 20 | 21 | // load more elaborate version of assert if available 22 | try { __loadScript("test_assert.js"); } catch(e) {} 23 | 24 | /*----------------*/ 25 | 26 | function pow(a, n) 27 | { 28 | var r, i; 29 | r = 1; 30 | for(i = 0; i < n; i++) 31 | r *= a; 32 | return r; 33 | } 34 | 35 | function test_integer() 36 | { 37 | var a, r; 38 | a = pow(3, 100); 39 | assert((a - 1) != a); 40 | assert(a == 515377520732011331036461129765621272702107522001); 41 | assert(a == 0x5a4653ca673768565b41f775d6947d55cf3813d1); 42 | assert(Integer.isInteger(1) === true); 43 | assert(Integer.isInteger(1.0) === false); 44 | 45 | assert(Integer.floorLog2(0) === -1); 46 | assert(Integer.floorLog2(7) === 2); 47 | 48 | r = 1 << 31; 49 | assert(r, 2147483648, "1 << 31 === 2147483648"); 50 | 51 | r = 1 << 32; 52 | assert(r, 4294967296, "1 << 32 === 4294967296"); 53 | 54 | r = (1 << 31) < 0; 55 | assert(r, false, "(1 << 31) < 0 === false"); 56 | } 57 | 58 | function test_divrem(div1, a, b, q) 59 | { 60 | var div, divrem, t; 61 | div = Integer[div1]; 62 | divrem = Integer[div1 + "rem"]; 63 | assert(div(a, b) == q); 64 | t = divrem(a, b); 65 | assert(t[0] == q); 66 | assert(a == b * q + t[1]); 67 | } 68 | 69 | function test_idiv1(div, a, b, r) 70 | { 71 | test_divrem(div, a, b, r[0]); 72 | test_divrem(div, -a, b, r[1]); 73 | test_divrem(div, a, -b, r[2]); 74 | test_divrem(div, -a, -b, r[3]); 75 | } 76 | 77 | function test_idiv() 78 | { 79 | test_idiv1("tdiv", 3, 2, [1, -1, -1, 1]); 80 | test_idiv1("fdiv", 3, 2, [1, -2, -2, 1]); 81 | test_idiv1("cdiv", 3, 2, [2, -1, -1, 2]); 82 | test_idiv1("ediv", 3, 2, [1, -2, -1, 2]); 83 | } 84 | 85 | function test_float() 86 | { 87 | var e, a, b, sqrt2; 88 | 89 | assert(typeof 1 === "bigint"); 90 | assert(typeof 1.0 === "bigfloat"); 91 | assert(1 == 1.0); 92 | assert(1 !== 1.0); 93 | 94 | e = new BigFloatEnv(128); 95 | assert(e.prec == 128); 96 | a = BigFloat.sqrt(2, e); 97 | assert(a == BigFloat.parseFloat("0x1.6a09e667f3bcc908b2fb1366ea957d3e", 0, e)); 98 | assert(e.inexact === true); 99 | assert(BigFloat.fpRound(a) == 0x1.6a09e667f3bcd); 100 | 101 | b = BigFloatEnv.setPrec(BigFloat.sqrt.bind(null, 2), 128); 102 | assert(a == b); 103 | } 104 | 105 | /* jscalc tests */ 106 | 107 | function test_modulo() 108 | { 109 | var i, p, a, b; 110 | 111 | /* Euclidian modulo operator */ 112 | assert((-3) % 2 == 1); 113 | assert(3 % (-2) == 1); 114 | 115 | p = 101; 116 | for(i = 1; i < p; i++) { 117 | a = Integer.invmod(i, p); 118 | assert(a >= 0 && a < p); 119 | assert((i * a) % p == 1); 120 | } 121 | 122 | assert(Integer.isPrime(2^107-1)); 123 | assert(!Integer.isPrime((2^107-1) * (2^89-1))); 124 | a = Integer.factor((2^89-1)*2^3*11*13^2*1009); 125 | assert(a == [ 2,2,2,11,13,13,1009,618970019642690137449562111 ]); 126 | } 127 | 128 | function test_mod() 129 | { 130 | var a, b, p; 131 | 132 | a = Mod(3, 101); 133 | b = Mod(-1, 101); 134 | assert((a + b) == Mod(2, 101)); 135 | assert(a ^ 100 == Mod(1, 101)); 136 | 137 | p = 2 ^ 607 - 1; /* mersenne prime */ 138 | a = Mod(3, p) ^ (p - 1); 139 | assert(a == Mod(1, p)); 140 | } 141 | 142 | function test_polynomial() 143 | { 144 | var a, b, q, r, t, i; 145 | a = (1 + X) ^ 4; 146 | assert(a == X^4+4*X^3+6*X^2+4*X+1); 147 | 148 | r = (1 + X); 149 | q = (1+X+X^2); 150 | b = (1 - X^2); 151 | a = q * b + r; 152 | t = Polynomial.divrem(a, b); 153 | assert(t[0] == q); 154 | assert(t[1] == r); 155 | 156 | a = 1 + 2*X + 3*X^2; 157 | assert(a.apply(0.1) == 1.23); 158 | 159 | a = 1-2*X^2+2*X^3; 160 | assert(deriv(a) == (6*X^2-4*X)); 161 | assert(deriv(integ(a)) == a); 162 | 163 | a = (X-1)*(X-2)*(X-3)*(X-4)*(X-0.1); 164 | r = polroots(a); 165 | for(i = 0; i < r.length; i++) { 166 | b = abs(a.apply(r[i])); 167 | assert(b <= 1e-13); 168 | } 169 | } 170 | 171 | function test_poly_mod() 172 | { 173 | var a, p; 174 | 175 | /* modulo using polynomials */ 176 | p = X^2 + X + 1; 177 | a = PolyMod(3+X, p) ^ 10; 178 | assert(a == PolyMod(-3725*X-18357, p)); 179 | 180 | a = PolyMod(1/X, 1+X^2); 181 | assert(a == PolyMod(-X, X^2+1)); 182 | } 183 | 184 | function test_rfunc() 185 | { 186 | var a; 187 | a = (X+1)/((X+1)*(X-1)); 188 | assert(a == 1/(X-1)); 189 | a = (X + 2) / (X - 2); 190 | assert(a.apply(1/3) == -7/5); 191 | 192 | assert(deriv((X^2-X+1)/(X-1)) == (X^2-2*X)/(X^2-2*X+1)); 193 | } 194 | 195 | function test_series() 196 | { 197 | var a, b; 198 | a = 1+X+O(X^5); 199 | b = a.inverse(); 200 | assert(b == 1-X+X^2-X^3+X^4+O(X^5)); 201 | assert(deriv(b) == -1+2*X-3*X^2+4*X^3+O(X^4)); 202 | assert(deriv(integ(b)) == b); 203 | 204 | a = Series(1/(1-X), 5); 205 | assert(a == 1+X+X^2+X^3+X^4+O(X^5)); 206 | b = a.apply(0.1); 207 | assert(b == 1.1111); 208 | 209 | assert(exp(3*X^2+O(X^10)) == 1+3*X^2+9/2*X^4+9/2*X^6+27/8*X^8+O(X^10)); 210 | assert(sin(X+O(X^6)) == X-1/6*X^3+1/120*X^5+O(X^6)); 211 | assert(cos(X+O(X^6)) == 1-1/2*X^2+1/24*X^4+O(X^6)); 212 | assert(tan(X+O(X^8)) == X+1/3*X^3+2/15*X^5+17/315*X^7+O(X^8)); 213 | assert((1+X+O(X^6))^(2+X) == 1+2*X+2*X^2+3/2*X^3+5/6*X^4+5/12*X^5+O(X^6)); 214 | } 215 | 216 | function test_matrix() 217 | { 218 | var a, b, r; 219 | a = [[1, 2],[3, 4]]; 220 | b = [3, 4]; 221 | r = a * b; 222 | assert(r == [11, 25]); 223 | r = (a^-1) * 2; 224 | assert(r == [[-4, 2],[3, -1]]); 225 | 226 | assert(norm2([1,2,3]) == 14); 227 | 228 | assert(diag([1,2,3]) == [ [ 1, 0, 0 ], [ 0, 2, 0 ], [ 0, 0, 3 ] ]); 229 | assert(trans(a) == [ [ 1, 3 ], [ 2, 4 ] ]); 230 | assert(trans([1,2,3]) == [[1,2,3]]); 231 | assert(trace(a) == 5); 232 | 233 | assert(charpoly(Matrix.hilbert(4)) == X^4-176/105*X^3+3341/12600*X^2-41/23625*X+1/6048000); 234 | assert(det(Matrix.hilbert(4)) == 1/6048000); 235 | 236 | a = [[1,2,1],[-2,-3,1],[3,5,0]]; 237 | assert(rank(a) == 2); 238 | assert(ker(a) == [ [ 5 ], [ -3 ], [ 1 ] ]); 239 | 240 | assert(dp([1, 2, 3], [3, -4, -7]) === -26); 241 | assert(cp([1, 2, 3], [3, -4, -7]) == [ -2, 16, -10 ]); 242 | } 243 | 244 | function assert_eq(a, ref) 245 | { 246 | assert(abs(a / ref - 1.0) <= 1e-15); 247 | } 248 | 249 | function test_trig() 250 | { 251 | assert_eq(sin(1/2), 0.479425538604203); 252 | assert_eq(sin(2+3*I), 9.154499146911428-4.168906959966565*I); 253 | assert_eq(cos(2+3*I), -4.189625690968807-9.109227893755337*I); 254 | assert_eq((2+0.5*I)^(1.1-0.5*I), 2.494363021357619-0.23076804554558092*I); 255 | assert_eq(sqrt(2*I), 1 + I); 256 | } 257 | 258 | test_integer(); 259 | test_idiv(); 260 | test_float(); 261 | 262 | test_modulo(); 263 | test_mod(); 264 | test_polynomial(); 265 | test_poly_mod(); 266 | test_rfunc(); 267 | test_series(); 268 | test_matrix(); 269 | test_trig(); 270 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test_bjson.js: -------------------------------------------------------------------------------- 1 | import * as bjson from "../bjson.so"; 2 | 3 | function assert(b, str) 4 | { 5 | if (b) { 6 | return; 7 | } else { 8 | throw Error("assertion failed: " + str); 9 | } 10 | } 11 | 12 | function toHex(a) 13 | { 14 | var i, s = "", tab, v; 15 | tab = new Uint8Array(a); 16 | for(i = 0; i < tab.length; i++) { 17 | v = tab[i].toString(16); 18 | if (v.length < 2) 19 | v = "0" + v; 20 | if (i !== 0) 21 | s += " "; 22 | s += v; 23 | } 24 | return s; 25 | } 26 | 27 | function toStr(a) 28 | { 29 | var s, i, props, prop; 30 | 31 | switch(typeof(a)) { 32 | case "object": 33 | if (a === null) 34 | return "null"; 35 | if (Array.isArray(a)) { 36 | s = "["; 37 | for(i = 0; i < a.length; i++) { 38 | if (i != 0) 39 | s += ","; 40 | s += toStr(a[i]); 41 | } 42 | s += "]"; 43 | } else { 44 | props = Object.keys(a); 45 | s = "{"; 46 | for(i = 0; i < props.length; i++) { 47 | if (i != 0) 48 | s += ","; 49 | prop = props[i]; 50 | s += prop + ":" + toStr(a[prop]); 51 | } 52 | s += "}"; 53 | } 54 | return s; 55 | case "undefined": 56 | return "undefined"; 57 | case "string": 58 | return a.__quote(); 59 | case "number": 60 | case "bigfloat": 61 | if (a == 0 && 1 / a < 0) 62 | return "-0"; 63 | else 64 | return a.toString(); 65 | break; 66 | default: 67 | return a.toString(); 68 | } 69 | } 70 | 71 | function bjson_test(a) 72 | { 73 | var buf, r, a_str, r_str; 74 | a_str = toStr(a); 75 | buf = bjson.write(a); 76 | if (0) { 77 | print(a_str, "->", toHex(buf)); 78 | } 79 | r = bjson.read(buf, 0, buf.byteLength); 80 | r_str = toStr(r); 81 | if (a_str != r_str) { 82 | print(a_str); 83 | print(r_str); 84 | assert(false); 85 | } 86 | } 87 | 88 | function bjson_test_all() 89 | { 90 | var obj; 91 | 92 | bjson_test({x:1, y:2, if:3}); 93 | bjson_test([1, 2, 3]); 94 | bjson_test([1.0, "aa", true, false, undefined, null, NaN, -Infinity, -0.0]); 95 | if (typeof BigInt !== "undefined") { 96 | bjson_test([BigInt("1"), -BigInt("0x123456789"), 97 | BigInt("0x123456789abcdef123456789abcdef")]); 98 | } 99 | if (typeof BigFloat !== "undefined") { 100 | BigFloatEnv.setPrec(function () { 101 | bjson_test([BigFloat("0.1"), BigFloat("-1e30"), BigFloat("0"), 102 | BigFloat("-0"), BigFloat("Infinity"), BigFloat("-Infinity"), 103 | 0.0 / BigFloat("0"), BigFloat.MAX_VALUE, 104 | BigFloat.MIN_VALUE]); 105 | }, 113, 15); 106 | } 107 | 108 | /* tested with a circular reference */ 109 | obj = {}; 110 | obj.x = obj; 111 | try { 112 | bjson.write(obj); 113 | assert(false); 114 | } catch(e) { 115 | assert(e instanceof TypeError); 116 | } 117 | } 118 | 119 | bjson_test_all(); 120 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test_closure.js: -------------------------------------------------------------------------------- 1 | function assert(actual, expected, message) { 2 | if (arguments.length == 1) 3 | expected = true; 4 | 5 | if (actual === expected) 6 | return; 7 | 8 | if (actual !== null && expected !== null 9 | && typeof actual == 'object' && typeof expected == 'object' 10 | && actual.toString() === expected.toString()) 11 | return; 12 | 13 | throw Error("assertion failed: got |" + actual + "|" + 14 | ", expected |" + expected + "|" + 15 | (message ? " (" + message + ")" : "")); 16 | } 17 | 18 | // load more elaborate version of assert if available 19 | try { __loadScript("test_assert.js"); } catch(e) {} 20 | 21 | /*----------------*/ 22 | 23 | var log_str = ""; 24 | 25 | function log(str) 26 | { 27 | log_str += str + ","; 28 | } 29 | 30 | function f(a, b, c) 31 | { 32 | var x = 10; 33 | log("a="+a); 34 | function g(d) { 35 | function h() { 36 | log("d=" + d); 37 | log("x=" + x); 38 | } 39 | log("b=" + b); 40 | log("c=" + c); 41 | h(); 42 | } 43 | g(4); 44 | return g; 45 | } 46 | 47 | var g1 = f(1, 2, 3); 48 | g1(5); 49 | 50 | assert(log_str, "a=1,b=2,c=3,d=4,x=10,b=2,c=3,d=5,x=10,", "closure1"); 51 | 52 | function test_closure1() 53 | { 54 | function f2() 55 | { 56 | var val = 1; 57 | 58 | function set(a) { 59 | val = a; 60 | } 61 | function get(a) { 62 | return val; 63 | } 64 | return { "set": set, "get": get }; 65 | } 66 | 67 | var obj = f2(); 68 | obj.set(10); 69 | var r; 70 | r = obj.get(); 71 | assert(r, 10, "closure2"); 72 | } 73 | 74 | function test_closure2() 75 | { 76 | var expr_func = function myfunc1(n) { 77 | function myfunc2(n) { 78 | return myfunc1(n - 1); 79 | } 80 | if (n == 0) 81 | return 0; 82 | else 83 | return myfunc2(n); 84 | }; 85 | var r; 86 | r = expr_func(1); 87 | assert(r, 0, "expr_func"); 88 | } 89 | 90 | function test_closure3() 91 | { 92 | function fib(n) 93 | { 94 | if (n <= 0) 95 | return 0; 96 | else if (n == 1) 97 | return 1; 98 | else 99 | return fib(n - 1) + fib(n - 2); 100 | } 101 | 102 | var fib_func = function fib1(n) 103 | { 104 | if (n <= 0) 105 | return 0; 106 | else if (n == 1) 107 | return 1; 108 | else 109 | return fib1(n - 1) + fib1(n - 2); 110 | }; 111 | 112 | assert(fib(6), 8, "fib"); 113 | assert(fib_func(6), 8, "fib_func"); 114 | } 115 | 116 | function test_arrow_function() 117 | { 118 | "use strict"; 119 | 120 | function f1() { 121 | return (() => arguments)(); 122 | } 123 | function f2() { 124 | return (() => this)(); 125 | } 126 | function f3() { 127 | return (() => eval("this"))(); 128 | } 129 | function f4() { 130 | return (() => eval("new.target"))(); 131 | } 132 | var a; 133 | 134 | a = f1(1, 2); 135 | assert(a.length, 2); 136 | assert(a[0] === 1 && a[1] === 2); 137 | 138 | assert(f2.call("this_val") === "this_val"); 139 | assert(f3.call("this_val") === "this_val"); 140 | assert(new f4() === f4); 141 | 142 | var o1 = { f() { return this; } }; 143 | var o2 = { f() { 144 | return (() => eval("super.f()"))(); 145 | } }; 146 | o2.__proto__ = o1; 147 | 148 | assert(o2.f() === o2); 149 | } 150 | 151 | function test_with() 152 | { 153 | var o1 = { x: "o1", y: "o1" }; 154 | var x = "local"; 155 | eval('var z="var_obj";'); 156 | assert(z === "var_obj"); 157 | with (o1) { 158 | assert(x === "o1"); 159 | assert(eval("x") === "o1"); 160 | var f = function () { 161 | o2 = { x: "o2" }; 162 | with (o2) { 163 | assert(x === "o2"); 164 | assert(y === "o1"); 165 | assert(z === "var_obj"); 166 | assert(eval("x") === "o2"); 167 | assert(eval("y") === "o1"); 168 | assert(eval("z") === "var_obj"); 169 | assert(eval('eval("x")') === "o2"); 170 | } 171 | }; 172 | f(); 173 | } 174 | } 175 | 176 | function test_eval_closure() 177 | { 178 | var tab; 179 | 180 | tab = []; 181 | for(let i = 0; i < 3; i++) { 182 | eval("tab.push(function g1() { return i; })"); 183 | } 184 | for(let i = 0; i < 3; i++) { 185 | assert(tab[i]() === i); 186 | } 187 | 188 | tab = []; 189 | for(let i = 0; i < 3; i++) { 190 | let f = function f() { 191 | eval("tab.push(function g2() { return i; })"); 192 | }; 193 | f(); 194 | } 195 | for(let i = 0; i < 3; i++) { 196 | assert(tab[i]() === i); 197 | } 198 | } 199 | 200 | function test_eval_const() 201 | { 202 | const a = 1; 203 | var success = false; 204 | var f = function () { 205 | eval("a = 1"); 206 | }; 207 | try { 208 | f(); 209 | } catch(e) { 210 | success = (e instanceof TypeError); 211 | } 212 | assert(success); 213 | } 214 | 215 | test_closure1(); 216 | test_closure2(); 217 | test_closure3(); 218 | test_arrow_function(); 219 | test_with(); 220 | test_eval_closure(); 221 | test_eval_const(); 222 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test_loop.js: -------------------------------------------------------------------------------- 1 | function assert(actual, expected, message) { 2 | if (arguments.length == 1) 3 | expected = true; 4 | 5 | if (actual === expected) 6 | return; 7 | 8 | if (actual !== null && expected !== null 9 | && typeof actual == 'object' && typeof expected == 'object' 10 | && actual.toString() === expected.toString()) 11 | return; 12 | 13 | throw Error("assertion failed: got |" + actual + "|" + 14 | ", expected |" + expected + "|" + 15 | (message ? " (" + message + ")" : "")); 16 | } 17 | 18 | // load more elaborate version of assert if available 19 | try { __loadScript("test_assert.js"); } catch(e) {} 20 | 21 | /*----------------*/ 22 | 23 | function test_while() 24 | { 25 | var i, c; 26 | i = 0; 27 | c = 0; 28 | while (i < 3) { 29 | c++; 30 | i++; 31 | } 32 | assert(c === 3); 33 | } 34 | 35 | function test_while_break() 36 | { 37 | var i, c; 38 | i = 0; 39 | c = 0; 40 | while (i < 3) { 41 | c++; 42 | if (i == 1) 43 | break; 44 | i++; 45 | } 46 | assert(c === 2 && i === 1); 47 | } 48 | 49 | function test_do_while() 50 | { 51 | var i, c; 52 | i = 0; 53 | c = 0; 54 | do { 55 | c++; 56 | i++; 57 | } while (i < 3); 58 | assert(c === 3 && i === 3); 59 | } 60 | 61 | function test_for() 62 | { 63 | var i, c; 64 | c = 0; 65 | for(i = 0; i < 3; i++) { 66 | c++; 67 | } 68 | assert(c === 3 && i === 3); 69 | 70 | c = 0; 71 | for(var j = 0; j < 3; j++) { 72 | c++; 73 | } 74 | assert(c === 3 && j === 3); 75 | } 76 | 77 | function test_for_in() 78 | { 79 | var i, tab, a, b; 80 | 81 | tab = []; 82 | for(i in {x:1, y: 2}) { 83 | tab.push(i); 84 | } 85 | assert(tab.toString(), "x,y", "for_in"); 86 | 87 | /* prototype chain test */ 88 | a = {x:2, y: 2, "1": 3}; 89 | b = {"4" : 3 }; 90 | Object.setPrototypeOf(a, b); 91 | tab = []; 92 | for(i in a) { 93 | tab.push(i); 94 | } 95 | assert(tab.toString(), "1,x,y,4", "for_in"); 96 | 97 | /* non enumerable properties hide enumerables ones in the 98 | prototype chain */ 99 | a = {y: 2, "1": 3}; 100 | Object.defineProperty(a, "x", { value: 1 }); 101 | b = {"x" : 3 }; 102 | Object.setPrototypeOf(a, b); 103 | tab = []; 104 | for(i in a) { 105 | tab.push(i); 106 | } 107 | assert(tab.toString(), "1,y", "for_in"); 108 | 109 | /* array optimization */ 110 | a = []; 111 | for(i = 0; i < 10; i++) 112 | a.push(i); 113 | tab = []; 114 | for(i in a) { 115 | tab.push(i); 116 | } 117 | assert(tab.toString(), "0,1,2,3,4,5,6,7,8,9", "for_in"); 118 | 119 | /* iterate with a field */ 120 | a={x:0}; 121 | tab = []; 122 | for(a.x in {x:1, y: 2}) { 123 | tab.push(a.x); 124 | } 125 | assert(tab.toString(), "x,y", "for_in"); 126 | 127 | /* iterate with a variable field */ 128 | a=[0]; 129 | tab = []; 130 | for(a[0] in {x:1, y: 2}) { 131 | tab.push(a[0]); 132 | } 133 | assert(tab.toString(), "x,y", "for_in"); 134 | 135 | /* variable definition in the for in */ 136 | tab = []; 137 | for(var j in {x:1, y: 2}) { 138 | tab.push(j); 139 | } 140 | assert(tab.toString(), "x,y", "for_in"); 141 | 142 | /* variable assigment in the for in */ 143 | tab = []; 144 | for(var k = 2 in {x:1, y: 2}) { 145 | tab.push(k); 146 | } 147 | assert(tab.toString(), "x,y", "for_in"); 148 | } 149 | 150 | function test_for_in2() 151 | { 152 | var i; 153 | tab = []; 154 | for(i in {x:1, y: 2, z:3}) { 155 | if (i === "y") 156 | continue; 157 | tab.push(i); 158 | } 159 | assert(tab.toString() == "x,z"); 160 | 161 | tab = []; 162 | for(i in {x:1, y: 2, z:3}) { 163 | if (i === "z") 164 | break; 165 | tab.push(i); 166 | } 167 | assert(tab.toString() == "x,y"); 168 | } 169 | 170 | function test_for_break() 171 | { 172 | var i, c; 173 | c = 0; 174 | L1: for(i = 0; i < 3; i++) { 175 | c++; 176 | if (i == 0) 177 | continue; 178 | while (1) { 179 | break L1; 180 | } 181 | } 182 | assert(c === 2 && i === 1); 183 | } 184 | 185 | function test_switch1() 186 | { 187 | var i, a, s; 188 | s = ""; 189 | for(i = 0; i < 3; i++) { 190 | a = "?"; 191 | switch(i) { 192 | case 0: 193 | a = "a"; 194 | break; 195 | case 1: 196 | a = "b"; 197 | break; 198 | default: 199 | a = "c"; 200 | break; 201 | } 202 | s += a; 203 | } 204 | assert(s === "abc" && i === 3); 205 | } 206 | 207 | function test_switch2() 208 | { 209 | var i, a, s; 210 | s = ""; 211 | for(i = 0; i < 4; i++) { 212 | a = "?"; 213 | switch(i) { 214 | case 0: 215 | a = "a"; 216 | break; 217 | case 1: 218 | a = "b"; 219 | break; 220 | case 2: 221 | continue; 222 | default: 223 | a = "" + i; 224 | break; 225 | } 226 | s += a; 227 | } 228 | assert(s === "ab3" && i === 4); 229 | } 230 | 231 | function test_try_catch1() 232 | { 233 | try { 234 | throw "hello"; 235 | } catch (e) { 236 | assert(e, "hello", "catch"); 237 | return; 238 | } 239 | assert(false, "catch"); 240 | } 241 | 242 | function test_try_catch2() 243 | { 244 | var a; 245 | try { 246 | a = 1; 247 | } catch (e) { 248 | a = 2; 249 | } 250 | assert(a, 1, "catch"); 251 | } 252 | 253 | function test_try_catch3() 254 | { 255 | var s; 256 | s = ""; 257 | try { 258 | s += "t"; 259 | } catch (e) { 260 | s += "c"; 261 | } finally { 262 | s += "f"; 263 | } 264 | assert(s, "tf", "catch"); 265 | } 266 | 267 | function test_try_catch4() 268 | { 269 | var s; 270 | s = ""; 271 | try { 272 | s += "t"; 273 | throw "c"; 274 | } catch (e) { 275 | s += e; 276 | } finally { 277 | s += "f"; 278 | } 279 | assert(s, "tcf", "catch"); 280 | } 281 | 282 | function test_try_catch5() 283 | { 284 | var s; 285 | s = ""; 286 | for(;;) { 287 | try { 288 | s += "t"; 289 | break; 290 | s += "b"; 291 | } finally { 292 | s += "f"; 293 | } 294 | } 295 | assert(s, "tf", "catch"); 296 | } 297 | 298 | function test_try_catch6() 299 | { 300 | function f() { 301 | try { 302 | s += 't'; 303 | return 1; 304 | } finally { 305 | s += "f"; 306 | } 307 | } 308 | var s = ""; 309 | assert(f() === 1); 310 | assert(s, "tf", "catch6"); 311 | } 312 | 313 | function test_try_catch7() 314 | { 315 | var s; 316 | s = ""; 317 | 318 | try { 319 | try { 320 | s += "t"; 321 | throw "a"; 322 | } finally { 323 | s += "f"; 324 | } 325 | } catch(e) { 326 | s += e; 327 | } finally { 328 | s += "g"; 329 | } 330 | assert(s, "tfag", "catch"); 331 | } 332 | 333 | function test_try_catch8() 334 | { 335 | var i, s; 336 | 337 | s = ""; 338 | for(var i in {x:1, y:2}) { 339 | try { 340 | s += i; 341 | throw "a"; 342 | } catch (e) { 343 | s += e; 344 | } finally { 345 | s += "f"; 346 | } 347 | } 348 | assert(s === "xafyaf"); 349 | } 350 | 351 | test_while(); 352 | test_while_break(); 353 | test_do_while(); 354 | test_for(); 355 | test_for_break(); 356 | test_switch1(); 357 | test_switch2(); 358 | test_for_in(); 359 | test_for_in2(); 360 | 361 | test_try_catch1(); 362 | test_try_catch2(); 363 | test_try_catch3(); 364 | test_try_catch4(); 365 | test_try_catch5(); 366 | test_try_catch6(); 367 | test_try_catch7(); 368 | test_try_catch8(); 369 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test_op.js: -------------------------------------------------------------------------------- 1 | function assert(actual, expected, message) { 2 | if (arguments.length == 1) 3 | expected = true; 4 | 5 | if (actual === expected) 6 | return; 7 | 8 | if (actual !== null && expected !== null 9 | && typeof actual == 'object' && typeof expected == 'object' 10 | && actual.toString() === expected.toString()) 11 | return; 12 | 13 | throw Error("assertion failed: got |" + actual + "|" + 14 | ", expected |" + expected + "|" + 15 | (message ? " (" + message + ")" : "")); 16 | } 17 | 18 | // load more elaborate version of assert if available 19 | try { __loadScript("test_assert.js"); } catch(e) {} 20 | 21 | /*----------------*/ 22 | 23 | function test_op1() 24 | { 25 | var r, a; 26 | r = 1 + 2; 27 | assert(r, 3, "1 + 2 === 3"); 28 | 29 | r = 1 - 2; 30 | assert(r, -1, "1 - 2 === -1"); 31 | 32 | r = -1; 33 | assert(r, -1, "-1 === -1"); 34 | 35 | r = +2; 36 | assert(r, 2, "+2 === 2"); 37 | 38 | r = 2 * 3; 39 | assert(r, 6, "2 * 3 === 6"); 40 | 41 | r = 4 / 2; 42 | assert(r, 2, "4 / 2 === 2"); 43 | 44 | r = 4 % 3; 45 | assert(r, 1, "4 % 3 === 3"); 46 | 47 | r = 4 << 2; 48 | assert(r, 16, "4 << 2 === 16"); 49 | 50 | r = 1 << 0; 51 | assert(r, 1, "1 << 0 === 1"); 52 | 53 | r = 1 << 31; 54 | assert(r, -2147483648, "1 << 31 === -2147483648"); 55 | 56 | r = 1 << 32; 57 | assert(r, 1, "1 << 32 === 1"); 58 | 59 | r = (1 << 31) < 0; 60 | assert(r, true, "(1 << 31) < 0 === true"); 61 | 62 | r = -4 >> 1; 63 | assert(r, -2, "-4 >> 1 === -2"); 64 | 65 | r = -4 >>> 1; 66 | assert(r, 0x7ffffffe, "-4 >>> 1 === 0x7ffffffe"); 67 | 68 | r = 1 & 1; 69 | assert(r, 1, "1 & 1 === 1"); 70 | 71 | r = 0 | 1; 72 | assert(r, 1, "0 | 1 === 1"); 73 | 74 | r = 1 ^ 1; 75 | assert(r, 0, "1 ^ 1 === 0"); 76 | 77 | r = ~1; 78 | assert(r, -2, "~1 === -2"); 79 | 80 | r = !1; 81 | assert(r, false, "!1 === false"); 82 | 83 | assert((1 < 2), true, "(1 < 2) === true"); 84 | 85 | assert((2 > 1), true, "(2 > 1) === true"); 86 | 87 | assert(('b' > 'a'), true, "('b' > 'a') === true"); 88 | 89 | assert(2 ** 8, 256, "2 ** 8 === 256"); 90 | } 91 | 92 | function test_cvt() 93 | { 94 | assert((NaN | 0) === 0); 95 | assert((Infinity | 0) === 0); 96 | assert(((-Infinity) | 0) === 0); 97 | assert(("12345" | 0) === 12345); 98 | assert(("0x12345" | 0) === 0x12345); 99 | assert(((4294967296 * 3 - 4) | 0) === -4); 100 | 101 | assert(("12345" >>> 0) === 12345); 102 | assert(("0x12345" >>> 0) === 0x12345); 103 | assert((NaN >>> 0) === 0); 104 | assert((Infinity >>> 0) === 0); 105 | assert(((-Infinity) >>> 0) === 0); 106 | assert(((4294967296 * 3 - 4) >>> 0) === (4294967296 - 4)); 107 | } 108 | 109 | function test_eq() 110 | { 111 | assert(null == undefined); 112 | assert(undefined == null); 113 | assert(true == 1); 114 | assert(0 == false); 115 | assert("" == 0); 116 | assert("123" == 123); 117 | assert("122" != 123); 118 | assert((new Number(1)) == 1); 119 | assert(2 == (new Number(2))); 120 | assert((new String("abc")) == "abc"); 121 | assert({} != "abc"); 122 | } 123 | 124 | function test_inc_dec() 125 | { 126 | var a, r; 127 | 128 | a = 1; 129 | r = a++; 130 | assert(r === 1 && a === 2, true, "++"); 131 | 132 | a = 1; 133 | r = ++a; 134 | assert(r === 2 && a === 2, true, "++"); 135 | 136 | a = 1; 137 | r = a--; 138 | assert(r === 1 && a === 0, true, "--"); 139 | 140 | a = 1; 141 | r = --a; 142 | assert(r === 0 && a === 0, true, "--"); 143 | 144 | a = {x:true}; 145 | a.x++; 146 | assert(a.x, 2, "++"); 147 | 148 | a = {x:true}; 149 | a.x--; 150 | assert(a.x, 0, "--"); 151 | 152 | a = [true]; 153 | a[0]++; 154 | assert(a[0], 2, "++"); 155 | 156 | a = {x:true}; 157 | r = a.x++; 158 | assert(r === 1 && a.x === 2, true, "++"); 159 | 160 | a = {x:true}; 161 | r = a.x--; 162 | assert(r === 1 && a.x === 0, true, "--"); 163 | 164 | a = [true]; 165 | r = a[0]++; 166 | assert(r === 1 && a[0] === 2, true, "++"); 167 | 168 | a = [true]; 169 | r = a[0]--; 170 | assert(r === 1 && a[0] === 0, true, "--"); 171 | } 172 | 173 | function F(x) 174 | { 175 | this.x = x; 176 | } 177 | 178 | function test_op2() 179 | { 180 | var a, b; 181 | a = new Object; 182 | a.x = 1; 183 | assert(a.x, 1, "new"); 184 | b = new F(2); 185 | assert(b.x, 2, "new"); 186 | 187 | a = {x : 2}; 188 | assert(("x" in a), true, "in"); 189 | assert(("y" in a), false, "in"); 190 | 191 | a = {}; 192 | assert((a instanceof Object), true, "instanceof"); 193 | assert((a instanceof String), false, "instanceof"); 194 | 195 | assert((typeof 1), "number", "typeof"); 196 | assert((typeof Object), "function", "typeof"); 197 | assert((typeof null), "object", "typeof"); 198 | assert((typeof unknown_var), "undefined", "typeof"); 199 | 200 | a = {x: 1, y: 1}; 201 | assert((delete a.x), true, "delete"); 202 | assert(("x" in a), false, "delete"); 203 | 204 | a = {x: 1, if: 2}; 205 | assert(a.if === 2); 206 | } 207 | 208 | function test_prototype() 209 | { 210 | function f() { } 211 | assert(f.prototype.constructor, f, "prototype"); 212 | } 213 | 214 | function test_arguments() 215 | { 216 | function f2() { 217 | assert(arguments.length, 2, "arguments"); 218 | assert(arguments[0], 1, "arguments"); 219 | assert(arguments[1], 3, "arguments"); 220 | } 221 | f2(1, 3); 222 | } 223 | 224 | function test_class() 225 | { 226 | var o; 227 | class C { 228 | constructor() { 229 | this.x = 10; 230 | } 231 | f() { 232 | return 1; 233 | } 234 | static F() { 235 | return -1; 236 | } 237 | get y() { 238 | return 12; 239 | } 240 | }; 241 | class D extends C { 242 | constructor() { 243 | super(); 244 | this.z = 20; 245 | } 246 | g() { 247 | return 2; 248 | } 249 | static G() { 250 | return -2; 251 | } 252 | h() { 253 | return super.f(); 254 | } 255 | static H() { 256 | return super["F"](); 257 | } 258 | } 259 | 260 | assert(C.F() === -1); 261 | assert(Object.getOwnPropertyDescriptor(C.prototype, "y").get.name === "get y"); 262 | 263 | o = new C(); 264 | assert(o.f() === 1); 265 | assert(o.x === 10); 266 | 267 | assert(D.F() === -1); 268 | assert(D.G() === -2); 269 | assert(D.H() === -1); 270 | 271 | o = new D(); 272 | assert(o.f() === 1); 273 | assert(o.g() === 2); 274 | assert(o.x === 10); 275 | assert(o.z === 20); 276 | assert(o.h() === 1); 277 | 278 | /* test class name scope */ 279 | var E1 = class E { static F() { return E; } }; 280 | assert(E1 === E1.F()); 281 | }; 282 | 283 | function test_template() 284 | { 285 | var a, b; 286 | b = 123; 287 | a = `abc${b}d`; 288 | assert(a === "abc123d"); 289 | 290 | a = String.raw `abc${b}d`; 291 | assert(a === "abc123d"); 292 | } 293 | 294 | test_op1(); 295 | test_cvt(); 296 | test_eq(); 297 | test_inc_dec(); 298 | test_op2(); 299 | test_prototype(); 300 | test_arguments(); 301 | test_class(); 302 | test_template(); 303 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/tests/test_std.js: -------------------------------------------------------------------------------- 1 | import * as std from "std"; 2 | import * as os from "os"; 3 | 4 | function assert(actual, expected, message) { 5 | if (arguments.length == 1) 6 | expected = true; 7 | 8 | if (actual === expected) 9 | return; 10 | 11 | if (actual !== null && expected !== null 12 | && typeof actual == 'object' && typeof expected == 'object' 13 | && actual.toString() === expected.toString()) 14 | return; 15 | 16 | throw Error("assertion failed: got |" + actual + "|" + 17 | ", expected |" + expected + "|" + 18 | (message ? " (" + message + ")" : "")); 19 | } 20 | 21 | // load more elaborate version of assert if available 22 | try { std.loadScript("test_assert.js"); } catch(e) {} 23 | 24 | /*----------------*/ 25 | 26 | function test_printf() 27 | { 28 | assert(std.sprintf("a=%d s=%s", 123, "abc"), "a=123 s=abc"); 29 | } 30 | 31 | function test_file1() 32 | { 33 | var f, len, str, size, buf, ret, i, str1; 34 | 35 | f = std.tmpfile(); 36 | str = "hello world\n"; 37 | f.puts(str); 38 | 39 | f.seek(0, std.SEEK_SET); 40 | str1 = f.readAsString(); 41 | assert(str1 === str); 42 | 43 | f.seek(0, std.SEEK_END); 44 | size = f.tell(); 45 | assert(size === str.length); 46 | 47 | f.seek(0, std.SEEK_SET); 48 | 49 | buf = new Uint8Array(size); 50 | ret = f.read(buf.buffer, 0, size); 51 | assert(ret === size); 52 | for(i = 0; i < size; i++) 53 | assert(buf[i] === str.charCodeAt(i)); 54 | 55 | f.close(); 56 | } 57 | 58 | function test_file2() 59 | { 60 | var f, str, i, size; 61 | f = std.tmpfile(); 62 | str = "hello world\n"; 63 | size = str.length; 64 | for(i = 0; i < size; i++) 65 | f.putByte(str.charCodeAt(i)); 66 | f.seek(0, std.SEEK_SET); 67 | for(i = 0; i < size; i++) { 68 | assert(str.charCodeAt(i) === f.getByte()); 69 | } 70 | assert(f.getByte() === -1); 71 | f.close(); 72 | } 73 | 74 | function test_getline() 75 | { 76 | var f, line, line_count, lines, i; 77 | 78 | lines = ["hello world", "line 1", "line 2" ]; 79 | f = std.tmpfile(); 80 | for(i = 0; i < lines.length; i++) { 81 | f.puts(lines[i], "\n"); 82 | } 83 | 84 | f.seek(0, std.SEEK_SET); 85 | assert(!f.eof()); 86 | line_count = 0; 87 | for(;;) { 88 | line = f.getline(); 89 | if (line === null) 90 | break; 91 | assert(line == lines[line_count]); 92 | line_count++; 93 | } 94 | assert(f.eof()); 95 | assert(line_count === lines.length); 96 | 97 | f.close(); 98 | } 99 | 100 | function test_os() 101 | { 102 | var fd, fname, buf, buf2, i; 103 | 104 | assert(os.isatty(0)); 105 | 106 | fname = "tmp_file.txt"; 107 | fd = os.open(fname, os.O_RDWR | os.O_CREAT | os.O_TRUNC); 108 | assert(fd >= 0); 109 | 110 | buf = new Uint8Array(10); 111 | for(i = 0; i < buf.length; i++) 112 | buf[i] = i; 113 | assert(os.write(fd, buf.buffer, 0, buf.length) === buf.length); 114 | 115 | assert(os.seek(fd, 0, os.SEEK_SET) === 0); 116 | buf2 = new Uint8Array(buf.length); 117 | assert(os.read(fd, buf2.buffer, 0, buf2.length) === buf2.length); 118 | 119 | for(i = 0; i < buf.length; i++) 120 | assert(buf[i] == buf2[i]); 121 | 122 | assert(os.close(fd) === 0); 123 | 124 | assert(os.remove(fname) === 0); 125 | 126 | fd = os.open(fname, os.O_RDONLY); 127 | assert(fd < 0); 128 | } 129 | 130 | function test_timer() 131 | { 132 | var th, i; 133 | 134 | /* just test that a timer can be inserted and removed */ 135 | th = []; 136 | for(i = 0; i < 3; i++) 137 | th[i] = os.setTimeout(function () { }, 1000); 138 | for(i = 0; i < 3; i++) 139 | os.clearTimeout(th[i]); 140 | } 141 | 142 | test_printf(); 143 | test_file1(); 144 | test_file2(); 145 | test_getline(); 146 | test_os(); 147 | test_timer(); 148 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/unicode_download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | url="ftp://ftp.unicode.org/Public/12.1.0/ucd" 5 | emoji_url="ftp://ftp.unicode.org/Public/emoji/12.0/emoji-data.txt" 6 | 7 | files="CaseFolding.txt DerivedNormalizationProps.txt PropList.txt \ 8 | SpecialCasing.txt CompositionExclusions.txt ScriptExtensions.txt \ 9 | UnicodeData.txt DerivedCoreProperties.txt NormalizationTest.txt Scripts.txt \ 10 | PropertyValueAliases.txt" 11 | 12 | mkdir -p unicode 13 | 14 | for f in $files; do 15 | g="${url}/${f}" 16 | wget $g -O unicode/$f 17 | done 18 | 19 | wget $emoji_url -O unicode/emoji-data.txt 20 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/unicode_gen_def.h: -------------------------------------------------------------------------------- 1 | #ifdef UNICODE_GENERAL_CATEGORY 2 | DEF(Cn, "Unassigned") /* must be zero */ 3 | DEF(Lu, "Uppercase_Letter") 4 | DEF(Ll, "Lowercase_Letter") 5 | DEF(Lt, "Titlecase_Letter") 6 | DEF(Lm, "Modifier_Letter") 7 | DEF(Lo, "Other_Letter") 8 | DEF(Mn, "Nonspacing_Mark") 9 | DEF(Mc, "Spacing_Mark") 10 | DEF(Me, "Enclosing_Mark") 11 | DEF(Nd, "Decimal_Number,digit") 12 | DEF(Nl, "Letter_Number") 13 | DEF(No, "Other_Number") 14 | DEF(Sm, "Math_Symbol") 15 | DEF(Sc, "Currency_Symbol") 16 | DEF(Sk, "Modifier_Symbol") 17 | DEF(So, "Other_Symbol") 18 | DEF(Pc, "Connector_Punctuation") 19 | DEF(Pd, "Dash_Punctuation") 20 | DEF(Ps, "Open_Punctuation") 21 | DEF(Pe, "Close_Punctuation") 22 | DEF(Pi, "Initial_Punctuation") 23 | DEF(Pf, "Final_Punctuation") 24 | DEF(Po, "Other_Punctuation") 25 | DEF(Zs, "Space_Separator") 26 | DEF(Zl, "Line_Separator") 27 | DEF(Zp, "Paragraph_Separator") 28 | DEF(Cc, "Control,cntrl") 29 | DEF(Cf, "Format") 30 | DEF(Cs, "Surrogate") 31 | DEF(Co, "Private_Use") 32 | /* synthetic properties */ 33 | DEF(LC, "Cased_Letter") 34 | DEF(L, "Letter") 35 | DEF(M, "Mark,Combining_Mark") 36 | DEF(N, "Number") 37 | DEF(S, "Symbol") 38 | DEF(P, "Punctuation,punct") 39 | DEF(Z, "Separator") 40 | DEF(C, "Other") 41 | #endif 42 | 43 | #ifdef UNICODE_SCRIPT 44 | /* scripts aliases names in PropertyValueAliases.txt */ 45 | DEF(Unknown, "Zzzz") 46 | DEF(Adlam, "Adlm") 47 | DEF(Ahom, "Ahom") 48 | DEF(Anatolian_Hieroglyphs, "Hluw") 49 | DEF(Arabic, "Arab") 50 | DEF(Armenian, "Armn") 51 | DEF(Avestan, "Avst") 52 | DEF(Balinese, "Bali") 53 | DEF(Bamum, "Bamu") 54 | DEF(Bassa_Vah, "Bass") 55 | DEF(Batak, "Batk") 56 | DEF(Bengali, "Beng") 57 | DEF(Bhaiksuki, "Bhks") 58 | DEF(Bopomofo, "Bopo") 59 | DEF(Brahmi, "Brah") 60 | DEF(Braille, "Brai") 61 | DEF(Buginese, "Bugi") 62 | DEF(Buhid, "Buhd") 63 | DEF(Canadian_Aboriginal, "Cans") 64 | DEF(Carian, "Cari") 65 | DEF(Caucasian_Albanian, "Aghb") 66 | DEF(Chakma, "Cakm") 67 | DEF(Cham, "Cham") 68 | DEF(Cherokee, "Cher") 69 | DEF(Common, "Zyyy") 70 | DEF(Coptic, "Copt,Qaac") 71 | DEF(Cuneiform, "Xsux") 72 | DEF(Cypriot, "Cprt") 73 | DEF(Cyrillic, "Cyrl") 74 | DEF(Deseret, "Dsrt") 75 | DEF(Devanagari, "Deva") 76 | DEF(Dogra, "Dogr") 77 | DEF(Duployan, "Dupl") 78 | DEF(Egyptian_Hieroglyphs, "Egyp") 79 | DEF(Elbasan, "Elba") 80 | DEF(Elymaic, "Elym") 81 | DEF(Ethiopic, "Ethi") 82 | DEF(Georgian, "Geor") 83 | DEF(Glagolitic, "Glag") 84 | DEF(Gothic, "Goth") 85 | DEF(Grantha, "Gran") 86 | DEF(Greek, "Grek") 87 | DEF(Gujarati, "Gujr") 88 | DEF(Gunjala_Gondi, "Gong") 89 | DEF(Gurmukhi, "Guru") 90 | DEF(Han, "Hani") 91 | DEF(Hangul, "Hang") 92 | DEF(Hanifi_Rohingya, "Rohg") 93 | DEF(Hanunoo, "Hano") 94 | DEF(Hatran, "Hatr") 95 | DEF(Hebrew, "Hebr") 96 | DEF(Hiragana, "Hira") 97 | DEF(Imperial_Aramaic, "Armi") 98 | DEF(Inherited, "Zinh,Qaai") 99 | DEF(Inscriptional_Pahlavi, "Phli") 100 | DEF(Inscriptional_Parthian, "Prti") 101 | DEF(Javanese, "Java") 102 | DEF(Kaithi, "Kthi") 103 | DEF(Kannada, "Knda") 104 | DEF(Katakana, "Kana") 105 | DEF(Kayah_Li, "Kali") 106 | DEF(Kharoshthi, "Khar") 107 | DEF(Khmer, "Khmr") 108 | DEF(Khojki, "Khoj") 109 | DEF(Khudawadi, "Sind") 110 | DEF(Lao, "Laoo") 111 | DEF(Latin, "Latn") 112 | DEF(Lepcha, "Lepc") 113 | DEF(Limbu, "Limb") 114 | DEF(Linear_A, "Lina") 115 | DEF(Linear_B, "Linb") 116 | DEF(Lisu, "Lisu") 117 | DEF(Lycian, "Lyci") 118 | DEF(Lydian, "Lydi") 119 | DEF(Makasar, "Maka") 120 | DEF(Mahajani, "Mahj") 121 | DEF(Malayalam, "Mlym") 122 | DEF(Mandaic, "Mand") 123 | DEF(Manichaean, "Mani") 124 | DEF(Marchen, "Marc") 125 | DEF(Masaram_Gondi, "Gonm") 126 | DEF(Medefaidrin, "Medf") 127 | DEF(Meetei_Mayek, "Mtei") 128 | DEF(Mende_Kikakui, "Mend") 129 | DEF(Meroitic_Cursive, "Merc") 130 | DEF(Meroitic_Hieroglyphs, "Mero") 131 | DEF(Miao, "Plrd") 132 | DEF(Modi, "Modi") 133 | DEF(Mongolian, "Mong") 134 | DEF(Mro, "Mroo") 135 | DEF(Multani, "Mult") 136 | DEF(Myanmar, "Mymr") 137 | DEF(Nabataean, "Nbat") 138 | DEF(Nandinagari, "Nand") 139 | DEF(New_Tai_Lue, "Talu") 140 | DEF(Newa, "Newa") 141 | DEF(Nko, "Nkoo") 142 | DEF(Nushu, "Nshu") 143 | DEF(Nyiakeng_Puachue_Hmong, "Hmnp") 144 | DEF(Ogham, "Ogam") 145 | DEF(Ol_Chiki, "Olck") 146 | DEF(Old_Hungarian, "Hung") 147 | DEF(Old_Italic, "Ital") 148 | DEF(Old_North_Arabian, "Narb") 149 | DEF(Old_Permic, "Perm") 150 | DEF(Old_Persian, "Xpeo") 151 | DEF(Old_Sogdian, "Sogo") 152 | DEF(Old_South_Arabian, "Sarb") 153 | DEF(Old_Turkic, "Orkh") 154 | DEF(Oriya, "Orya") 155 | DEF(Osage, "Osge") 156 | DEF(Osmanya, "Osma") 157 | DEF(Pahawh_Hmong, "Hmng") 158 | DEF(Palmyrene, "Palm") 159 | DEF(Pau_Cin_Hau, "Pauc") 160 | DEF(Phags_Pa, "Phag") 161 | DEF(Phoenician, "Phnx") 162 | DEF(Psalter_Pahlavi, "Phlp") 163 | DEF(Rejang, "Rjng") 164 | DEF(Runic, "Runr") 165 | DEF(Samaritan, "Samr") 166 | DEF(Saurashtra, "Saur") 167 | DEF(Sharada, "Shrd") 168 | DEF(Shavian, "Shaw") 169 | DEF(Siddham, "Sidd") 170 | DEF(SignWriting, "Sgnw") 171 | DEF(Sinhala, "Sinh") 172 | DEF(Sogdian, "Sogd") 173 | DEF(Sora_Sompeng, "Sora") 174 | DEF(Soyombo, "Soyo") 175 | DEF(Sundanese, "Sund") 176 | DEF(Syloti_Nagri, "Sylo") 177 | DEF(Syriac, "Syrc") 178 | DEF(Tagalog, "Tglg") 179 | DEF(Tagbanwa, "Tagb") 180 | DEF(Tai_Le, "Tale") 181 | DEF(Tai_Tham, "Lana") 182 | DEF(Tai_Viet, "Tavt") 183 | DEF(Takri, "Takr") 184 | DEF(Tamil, "Taml") 185 | DEF(Tangut, "Tang") 186 | DEF(Telugu, "Telu") 187 | DEF(Thaana, "Thaa") 188 | DEF(Thai, "Thai") 189 | DEF(Tibetan, "Tibt") 190 | DEF(Tifinagh, "Tfng") 191 | DEF(Tirhuta, "Tirh") 192 | DEF(Ugaritic, "Ugar") 193 | DEF(Vai, "Vaii") 194 | DEF(Wancho, "Wcho") 195 | DEF(Warang_Citi, "Wara") 196 | DEF(Yi, "Yiii") 197 | DEF(Zanabazar_Square, "Zanb") 198 | #endif 199 | 200 | #ifdef UNICODE_PROP_LIST 201 | /* Prop list not exported to regexp */ 202 | DEF(Hyphen, "") 203 | DEF(Other_Math, "") 204 | DEF(Other_Alphabetic, "") 205 | DEF(Other_Lowercase, "") 206 | DEF(Other_Uppercase, "") 207 | DEF(Other_Grapheme_Extend, "") 208 | DEF(Other_Default_Ignorable_Code_Point, "") 209 | DEF(Other_ID_Start, "") 210 | DEF(Other_ID_Continue, "") 211 | DEF(Prepended_Concatenation_Mark, "") 212 | /* additional computed properties for smaller tables */ 213 | DEF(ID_Continue1, "") 214 | DEF(XID_Start1, "") 215 | DEF(XID_Continue1, "") 216 | DEF(Changes_When_Titlecased1, "") 217 | DEF(Changes_When_Casefolded1, "") 218 | DEF(Changes_When_NFKC_Casefolded1, "") 219 | 220 | /* Prop list exported to JS */ 221 | DEF(ASCII_Hex_Digit, "AHex") 222 | DEF(Bidi_Control, "Bidi_C") 223 | DEF(Dash, "") 224 | DEF(Deprecated, "Dep") 225 | DEF(Diacritic, "Dia") 226 | DEF(Extender, "Ext") 227 | DEF(Hex_Digit, "Hex") 228 | DEF(IDS_Binary_Operator, "IDSB") 229 | DEF(IDS_Trinary_Operator, "IDST") 230 | DEF(Ideographic, "Ideo") 231 | DEF(Join_Control, "Join_C") 232 | DEF(Logical_Order_Exception, "LOE") 233 | DEF(Noncharacter_Code_Point, "NChar") 234 | DEF(Pattern_Syntax, "Pat_Syn") 235 | DEF(Pattern_White_Space, "Pat_WS") 236 | DEF(Quotation_Mark, "QMark") 237 | DEF(Radical, "") 238 | DEF(Regional_Indicator, "RI") 239 | DEF(Sentence_Terminal, "STerm") 240 | DEF(Soft_Dotted, "SD") 241 | DEF(Terminal_Punctuation, "Term") 242 | DEF(Unified_Ideograph, "UIdeo") 243 | DEF(Variation_Selector, "VS") 244 | DEF(White_Space, "space") 245 | DEF(Bidi_Mirrored, "Bidi_M") 246 | DEF(Emoji, "") 247 | DEF(Emoji_Component, "") 248 | DEF(Emoji_Modifier, "") 249 | DEF(Emoji_Modifier_Base, "") 250 | DEF(Emoji_Presentation, "") 251 | DEF(Extended_Pictographic, "") 252 | DEF(Default_Ignorable_Code_Point, "DI") 253 | DEF(ID_Start, "IDS") 254 | DEF(Case_Ignorable, "CI") 255 | 256 | /* other binary properties */ 257 | DEF(ASCII,"") 258 | DEF(Alphabetic, "Alpha") 259 | DEF(Any, "") 260 | DEF(Assigned,"") 261 | DEF(Cased, "") 262 | DEF(Changes_When_Casefolded, "CWCF") 263 | DEF(Changes_When_Casemapped, "CWCM") 264 | DEF(Changes_When_Lowercased, "CWL") 265 | DEF(Changes_When_NFKC_Casefolded, "CWKCF") 266 | DEF(Changes_When_Titlecased, "CWT") 267 | DEF(Changes_When_Uppercased, "CWU") 268 | DEF(Grapheme_Base, "Gr_Base") 269 | DEF(Grapheme_Extend, "Gr_Ext") 270 | DEF(ID_Continue, "IDC") 271 | DEF(Lowercase, "Lower") 272 | DEF(Math, "") 273 | DEF(Uppercase, "Upper") 274 | DEF(XID_Continue, "XIDC") 275 | DEF(XID_Start, "XIDS") 276 | 277 | /* internal tables with index */ 278 | DEF(Cased1, "") 279 | 280 | #endif 281 | -------------------------------------------------------------------------------- /quickjs-2019-07-28/wrapper-helpers.c: -------------------------------------------------------------------------------- 1 | #include "quickjs.h" 2 | 3 | JSValue Helper_JS_NewFloat64(JSContext *ctx, double d) { 4 | return JS_NewFloat64(ctx, d); 5 | } 6 | 7 | JSValue Helper_JS_NewBool(JSContext *ctx, JS_BOOL val) { 8 | return JS_NewBool(ctx, val); 9 | } 10 | 11 | JSValue Helper_JS_NewNull(void) { 12 | return JS_NULL; 13 | } 14 | 15 | JSValue Helper_JS_NewUndefined(void) { 16 | return JS_UNDEFINED; 17 | } 18 | 19 | JSValue Helper_JS_NewException(void) { 20 | return JS_EXCEPTION; 21 | } 22 | 23 | void Helper_JS_FreeValue(JSContext *ctx, JSValue v) { 24 | return JS_FreeValue(ctx, v); 25 | } 26 | 27 | JSValue Helper_JS_DupValue(JSContext *ctx, JSValueConst v) { 28 | return JS_DupValue(ctx, v); 29 | } 30 | 31 | int Helper_JS_IsInteger(JSValueConst v) { 32 | return JS_IsInteger(v); 33 | } 34 | 35 | int Helper_JS_IsString(JSValueConst v) { 36 | return JS_IsString(v); 37 | } 38 | 39 | int Helper_JS_IsBool(JSValueConst v) { 40 | return JS_IsBool(v); 41 | } 42 | 43 | int Helper_JS_IsSymbol(JSValueConst v) 44 | { 45 | return JS_IsSymbol(v); 46 | } 47 | 48 | int Helper_JS_IsObject(JSValueConst v) 49 | { 50 | return JS_IsObject(v); 51 | } 52 | 53 | int Helper_JS_IsNull(JSValueConst v) 54 | { 55 | return JS_IsNull(v); 56 | } 57 | 58 | int Helper_JS_IsUndefined(JSValueConst v) 59 | { 60 | return JS_IsUndefined(v); 61 | } 62 | 63 | int Helper_JS_IsException(JSValueConst v) 64 | { 65 | return JS_IsException(v); 66 | } 67 | 68 | int Helper_JS_IsUninitialized(JSValueConst v) 69 | { 70 | return JS_IsUndefined(v); 71 | } 72 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_upper_case_globals)] 2 | #![allow(non_camel_case_types)] 3 | #![allow(non_snake_case)] 4 | 5 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 6 | -------------------------------------------------------------------------------- /wrapper.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | JSValue Helper_JS_NewFloat64(JSContext *ctx, double d); 5 | JSValue Helper_JS_NewBool(JSContext *ctx, JS_BOOL d); 6 | JSValue Helper_JS_NewNull(void); 7 | JSValue Helper_JS_NewUndefined(void); 8 | JSValue Helper_JS_NewException(void); 9 | void Helper_JS_FreeValue(JSContext *ctx, JSValue v); 10 | JSValue Helper_JS_DupValue(JSContext *ctx, JSValueConst v); 11 | int Helper_JS_IsInteger(JSValueConst v); 12 | int Helper_JS_IsString(JSValueConst v); 13 | int Helper_JS_IsBool(JSValueConst v); 14 | int Helper_JS_IsUndefined(JSValueConst v); 15 | int Helper_JS_IsNull(JSValueConst v); 16 | int Helper_JS_IsObject(JSValueConst v); 17 | int Helper_JS_IsSymbol(JSValueConst v); 18 | int Helper_JS_IsException(JSValueConst v); 19 | --------------------------------------------------------------------------------