[
  {
    "path": ".gitattributes",
    "content": "# Set the default behavior, in case people don't have core.autocrlf set\n* text=auto\n\n# Require Unix line endings\n* text eol=lf\n"
  },
  {
    "path": ".gitignore",
    "content": ".idea/"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2020 Kenta Iwasaki <kenta@lithdew.net>\nCopyright (c) 2017-2020 Fabrice Bellard\nCopyright (c) 2017-2020 Charlie Gordon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# quickjs\n\n[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](LICENSE)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/lithdew/quickjs)\n[![Discord Chat](https://img.shields.io/discord/697002823123992617)](https://discord.gg/HZEbkeQ)\n\nGo bindings to [QuickJS](https://bellard.org/quickjs/): a fast, small, and embeddable [ES2020](https://tc39.github.io/ecma262/) JavaScript interpreter.\n\nThese bindings are a WIP and do not match full parity with QuickJS' API, though expose just enough features to be usable. The version of QuickJS that these bindings bind to may be located [here](version.h).\n\nThese bindings have been tested to cross-compile and run successfully on Linux, Windows, and Mac using gcc-7 and mingw32 without any addtional compiler or linker flags.\n\n## Usage\n\n```\n$ go get github.com/lithdew/quickjs\n```\n\n## Guidelines\n\n1. Free `quickjs.Runtime` and `quickjs.Context` once you are done using them.\n2. Free `quickjs.Value`'s returned by `Eval()` and `EvalFile()`. All other values do not need to be freed, as they get garbage-collected.\n3. You may access the stacktrace of an error returned by `Eval()` or `EvalFile()` by casting it to a `*quickjs.Error`.\n4. Make new copies of arguments should you want to return them in functions you created.\n5. Make sure to call `runtime.LockOSThread()` to ensure that QuickJS always operates in the exact same thread.\n\n## Example\n\nThe full example code below may be found by clicking [here](examples/main.go). Find more API examples [here](quickjs_test.go).\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\t\"github.com/lithdew/quickjs\"\n\t\"strings\"\n)\n\nfunc check(err error) {\n\tif err != nil {\n\t\tvar evalErr *quickjs.Error\n\t\tif errors.As(err, &evalErr) {\n\t\t\tfmt.Println(evalErr.Cause)\n\t\t\tfmt.Println(evalErr.Stack)\n\t\t}\n\t\tpanic(err)\n\t}\n}\n\nfunc main() {\n\truntime := quickjs.NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\tglobals := context.Globals()\n\n\t// Test evaluating template strings.\n\n\tresult, err := context.Eval(\"`Hello world! 2 ** 8 = ${2 ** 8}.`\")\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.String())\n\tfmt.Println()\n\n\t// Test evaluating numeric expressions.\n\n\tresult, err = context.Eval(`1 + 2 * 100 - 3 + Math.sin(10)`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.Int64())\n\tfmt.Println()\n\n\t// Test evaluating big integer expressions.\n\n\tresult, err = context.Eval(`128n ** 16n`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.BigInt())\n\tfmt.Println()\n\n\t// Test evaluating big decimal expressions.\n\n\tresult, err = context.Eval(`128l ** 12l`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.BigFloat())\n\tfmt.Println()\n\n\t// Test evaluating boolean expressions.\n\n\tresult, err = context.Eval(`false && true`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.Bool())\n\tfmt.Println()\n\n\t// Test setting and calling functions.\n\n\tA := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {\n\t\tfmt.Println(\"A got called!\")\n\t\treturn ctx.Null()\n\t}\n\n\tB := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {\n\t\tfmt.Println(\"B got called!\")\n\t\treturn ctx.Null()\n\t}\n\n\tglobals.Set(\"A\", context.Function(A))\n\tglobals.Set(\"B\", context.Function(B))\n\n\t_, err = context.Eval(`for (let i = 0; i < 10; i++) { if (i % 2 === 0) A(); else B(); }`)\n\tcheck(err)\n\n\tfmt.Println()\n\n\t// Test setting global variables.\n\n\t_, err = context.Eval(`HELLO = \"world\"; TEST = false;`)\n\tcheck(err)\n\n\tnames, err := globals.PropertyNames()\n\tcheck(err)\n\n\tfmt.Println(\"Globals:\")\n\tfor _, name := range names {\n\t\tval := globals.GetByAtom(name.Atom)\n\t\tdefer val.Free()\n\n\t\tfmt.Printf(\"'%s': %s\\n\", name, val)\n\t}\n\tfmt.Println()\n\n\t// Test evaluating arbitrary expressions from flag arguments.\n\n\tflag.Parse()\n\tif flag.NArg() == 0 {\n\t\treturn\n\t}\n\n\tresult, err = context.Eval(strings.Join(flag.Args(), \" \"))\n\tcheck(err)\n\tdefer result.Free()\n\n\tif result.IsObject() {\n\t\tnames, err := result.PropertyNames()\n\t\tcheck(err)\n\n\t\tfmt.Println(\"Object:\")\n\t\tfor _, name := range names {\n\t\t\tval := result.GetByAtom(name.Atom)\n\t\t\tdefer val.Free()\n\n\t\t\tfmt.Printf(\"'%s': %s\\n\", name, val)\n\t\t}\n\t} else {\n\t\tfmt.Println(result.String())\n\t}\n}\n```\n\n```\n$ go run examples/main.go '(() => ({hello: \"world\", test: 2 ** 3}))()'\nHello world! 2 ** 8 = 256.\n\n197\n\n5192296858534827628530496329220096\n\n1.9342813113834066795e+25\n\nfalse\n\nA got called!\nB got called!\nA got called!\nB got called!\nA got called!\nB got called!\nA got called!\nB got called!\nA got called!\nB got called!\n\nGlobals:\n'Object': function Object() {\n    [native code]\n}\n'Function': function Function() {\n    [native code]\n}\n'Error': function Error() {\n    [native code]\n}\n'EvalError': function EvalError() {\n    [native code]\n}\n'RangeError': function RangeError() {\n    [native code]\n}\n'ReferenceError': function ReferenceError() {\n    [native code]\n}\n'SyntaxError': function SyntaxError() {\n    [native code]\n}\n'TypeError': function TypeError() {\n    [native code]\n}\n'URIError': function URIError() {\n    [native code]\n}\n'InternalError': function InternalError() {\n    [native code]\n}\n'AggregateError': function AggregateError() {\n    [native code]\n}\n'Array': function Array() {\n    [native code]\n}\n'parseInt': function parseInt() {\n    [native code]\n}\n'parseFloat': function parseFloat() {\n    [native code]\n}\n'isNaN': function isNaN() {\n    [native code]\n}\n'isFinite': function isFinite() {\n    [native code]\n}\n'decodeURI': function decodeURI() {\n    [native code]\n}\n'decodeURIComponent': function decodeURIComponent() {\n    [native code]\n}\n'encodeURI': function encodeURI() {\n    [native code]\n}\n'encodeURIComponent': function encodeURIComponent() {\n    [native code]\n}\n'escape': function escape() {\n    [native code]\n}\n'unescape': function unescape() {\n    [native code]\n}\n'Infinity': Infinity\n'NaN': NaN\n'undefined': undefined\n'__date_clock': function __date_clock() {\n    [native code]\n}\n'Number': function Number() {\n    [native code]\n}\n'Boolean': function Boolean() {\n    [native code]\n}\n'String': function String() {\n    [native code]\n}\n'Math': [object Math]\n'Reflect': [object Object]\n'Symbol': function Symbol() {\n    [native code]\n}\n'eval': function eval() {\n    [native code]\n}\n'globalThis': [object Object]\n'Date': function Date() {\n    [native code]\n}\n'RegExp': function RegExp() {\n    [native code]\n}\n'JSON': [object JSON]\n'Proxy': function Proxy() {\n    [native code]\n}\n'Map': function Map() {\n    [native code]\n}\n'Set': function Set() {\n    [native code]\n}\n'WeakMap': function WeakMap() {\n    [native code]\n}\n'WeakSet': function WeakSet() {\n    [native code]\n}\n'ArrayBuffer': function ArrayBuffer() {\n    [native code]\n}\n'SharedArrayBuffer': function SharedArrayBuffer() {\n    [native code]\n}\n'Uint8ClampedArray': function Uint8ClampedArray() {\n    [native code]\n}\n'Int8Array': function Int8Array() {\n    [native code]\n}\n'Uint8Array': function Uint8Array() {\n    [native code]\n}\n'Int16Array': function Int16Array() {\n    [native code]\n}\n'Uint16Array': function Uint16Array() {\n    [native code]\n}\n'Int32Array': function Int32Array() {\n    [native code]\n}\n'Uint32Array': function Uint32Array() {\n    [native code]\n}\n'BigInt64Array': function BigInt64Array() {\n    [native code]\n}\n'BigUint64Array': function BigUint64Array() {\n    [native code]\n}\n'Float32Array': function Float32Array() {\n    [native code]\n}\n'Float64Array': function Float64Array() {\n    [native code]\n}\n'DataView': function DataView() {\n    [native code]\n}\n'Atomics': [object Atomics]\n'Promise': function Promise() {\n    [native code]\n}\n'BigInt': function BigInt() {\n    [native code]\n}\n'BigFloat': function BigFloat() {\n    [native code]\n}\n'BigFloatEnv': function BigFloatEnv() {\n    [native code]\n}\n'BigDecimal': function BigDecimal() {\n    [native code]\n}\n'Operators': function Operators() {\n    [native code]\n}\n'A': function() { return proxy.call(this, id, ...arguments); }\n'B': function() { return proxy.call(this, id, ...arguments); }\n'HELLO': world\n'TEST': false\n\nObject:\n'hello': world\n'test': 8\n```\n\n## License\n\nQuickJS is released under the MIT license.\n\nQuickJS bindings are copyright Kenta Iwasaki, with code copyright Fabrice Bellard and Charlie Gordon.\n\n"
  },
  {
    "path": "bridge.c",
    "content": "#include \"_cgo_export.h\"\n\nJSValue InvokeProxy(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {\n\t return proxy(ctx, this_val, argc, argv);\n}"
  },
  {
    "path": "bridge.h",
    "content": "#include \"stdlib.h\"\n#include \"quickjs.h\"\n\nextern JSValue InvokeProxy(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);\n\nstatic JSValue JS_NewNull() { return JS_NULL; }\nstatic JSValue JS_NewUndefined() { return JS_UNDEFINED; }\nstatic JSValue JS_NewUninitialized() { return JS_UNINITIALIZED; }\n\nstatic JSValue ThrowSyntaxError(JSContext *ctx, const char *fmt) { return JS_ThrowSyntaxError(ctx, \"%s\", fmt); }\nstatic JSValue ThrowTypeError(JSContext *ctx, const char *fmt) { return JS_ThrowTypeError(ctx, \"%s\", fmt); }\nstatic JSValue ThrowReferenceError(JSContext *ctx, const char *fmt) { return JS_ThrowReferenceError(ctx, \"%s\", fmt); }\nstatic JSValue ThrowRangeError(JSContext *ctx, const char *fmt) { return JS_ThrowRangeError(ctx, \"%s\", fmt); }\nstatic JSValue ThrowInternalError(JSContext *ctx, const char *fmt) { return JS_ThrowInternalError(ctx, \"%s\", fmt); }"
  },
  {
    "path": "cutils.c",
    "content": "/*\n * C utilities\n * \n * Copyright (c) 2017 Fabrice Bellard\n * Copyright (c) 2018 Charlie Gordon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <stdarg.h>\n#include <string.h>\n\n#include \"cutils.h\"\n\nvoid pstrcpy(char *buf, int buf_size, const char *str)\n{\n    int c;\n    char *q = buf;\n\n    if (buf_size <= 0)\n        return;\n\n    for(;;) {\n        c = *str++;\n        if (c == 0 || q >= buf + buf_size - 1)\n            break;\n        *q++ = c;\n    }\n    *q = '\\0';\n}\n\n/* strcat and truncate. */\nchar *pstrcat(char *buf, int buf_size, const char *s)\n{\n    int len;\n    len = strlen(buf);\n    if (len < buf_size)\n        pstrcpy(buf + len, buf_size - len, s);\n    return buf;\n}\n\nint strstart(const char *str, const char *val, const char **ptr)\n{\n    const char *p, *q;\n    p = str;\n    q = val;\n    while (*q != '\\0') {\n        if (*p != *q)\n            return 0;\n        p++;\n        q++;\n    }\n    if (ptr)\n        *ptr = p;\n    return 1;\n}\n\nint has_suffix(const char *str, const char *suffix)\n{\n    size_t len = strlen(str);\n    size_t slen = strlen(suffix);\n    return (len >= slen && !memcmp(str + len - slen, suffix, slen));\n}\n\n/* Dynamic buffer package */\n\nstatic void *dbuf_default_realloc(void *opaque, void *ptr, size_t size)\n{\n    return realloc(ptr, size);\n}\n\nvoid dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func)\n{\n    memset(s, 0, sizeof(*s));\n    if (!realloc_func)\n        realloc_func = dbuf_default_realloc;\n    s->opaque = opaque;\n    s->realloc_func = realloc_func;\n}\n\nvoid dbuf_init(DynBuf *s)\n{\n    dbuf_init2(s, NULL, NULL);\n}\n\n/* return < 0 if error */\nint dbuf_realloc(DynBuf *s, size_t new_size)\n{\n    size_t size;\n    uint8_t *new_buf;\n    if (new_size > s->allocated_size) {\n        if (s->error)\n            return -1;\n        size = s->allocated_size * 3 / 2;\n        if (size > new_size)\n            new_size = size;\n        new_buf = s->realloc_func(s->opaque, s->buf, new_size);\n        if (!new_buf) {\n            s->error = TRUE;\n            return -1;\n        }\n        s->buf = new_buf;\n        s->allocated_size = new_size;\n    }\n    return 0;\n}\n\nint dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len)\n{\n    size_t end;\n    end = offset + len;\n    if (dbuf_realloc(s, end))\n        return -1;\n    memcpy(s->buf + offset, data, len);\n    if (end > s->size)\n        s->size = end;\n    return 0;\n}\n\nint dbuf_put(DynBuf *s, const uint8_t *data, size_t len)\n{\n    if (unlikely((s->size + len) > s->allocated_size)) {\n        if (dbuf_realloc(s, s->size + len))\n            return -1;\n    }\n    memcpy(s->buf + s->size, data, len);\n    s->size += len;\n    return 0;\n}\n\nint dbuf_put_self(DynBuf *s, size_t offset, size_t len)\n{\n    if (unlikely((s->size + len) > s->allocated_size)) {\n        if (dbuf_realloc(s, s->size + len))\n            return -1;\n    }\n    memcpy(s->buf + s->size, s->buf + offset, len);\n    s->size += len;\n    return 0;\n}\n\nint dbuf_putc(DynBuf *s, uint8_t c)\n{\n    return dbuf_put(s, &c, 1);\n}\n\nint dbuf_putstr(DynBuf *s, const char *str)\n{\n    return dbuf_put(s, (const uint8_t *)str, strlen(str));\n}\n\nint __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,\n                                                      const char *fmt, ...)\n{\n    va_list ap;\n    char buf[128];\n    int len;\n    \n    va_start(ap, fmt);\n    len = vsnprintf(buf, sizeof(buf), fmt, ap);\n    va_end(ap);\n    if (len < sizeof(buf)) {\n        /* fast case */\n        return dbuf_put(s, (uint8_t *)buf, len);\n    } else {\n        if (dbuf_realloc(s, s->size + len + 1))\n            return -1;\n        va_start(ap, fmt);\n        vsnprintf((char *)(s->buf + s->size), s->allocated_size - s->size,\n                  fmt, ap);\n        va_end(ap);\n        s->size += len;\n    }\n    return 0;\n}\n\nvoid dbuf_free(DynBuf *s)\n{\n    /* we test s->buf as a fail safe to avoid crashing if dbuf_free()\n       is called twice */\n    if (s->buf) {\n        s->realloc_func(s->opaque, s->buf, 0);\n    }\n    memset(s, 0, sizeof(*s));\n}\n\n/* Note: at most 31 bits are encoded. At most UTF8_CHAR_LEN_MAX bytes\n   are output. */\nint unicode_to_utf8(uint8_t *buf, unsigned int c)\n{\n    uint8_t *q = buf;\n\n    if (c < 0x80) {\n        *q++ = c;\n    } else {\n        if (c < 0x800) {\n            *q++ = (c >> 6) | 0xc0;\n        } else {\n            if (c < 0x10000) {\n                *q++ = (c >> 12) | 0xe0;\n            } else {\n                if (c < 0x00200000) {\n                    *q++ = (c >> 18) | 0xf0;\n                } else {\n                    if (c < 0x04000000) {\n                        *q++ = (c >> 24) | 0xf8;\n                    } else if (c < 0x80000000) {\n                        *q++ = (c >> 30) | 0xfc;\n                        *q++ = ((c >> 24) & 0x3f) | 0x80;\n                    } else {\n                        return 0;\n                    }\n                    *q++ = ((c >> 18) & 0x3f) | 0x80;\n                }\n                *q++ = ((c >> 12) & 0x3f) | 0x80;\n            }\n            *q++ = ((c >> 6) & 0x3f) | 0x80;\n        }\n        *q++ = (c & 0x3f) | 0x80;\n    }\n    return q - buf;\n}\n\nstatic const unsigned int utf8_min_code[5] = {\n    0x80, 0x800, 0x10000, 0x00200000, 0x04000000,\n};\n\nstatic const unsigned char utf8_first_code_mask[5] = {\n    0x1f, 0xf, 0x7, 0x3, 0x1,\n};\n\n/* return -1 if error. *pp is not updated in this case. max_len must\n   be >= 1. The maximum length for a UTF8 byte sequence is 6 bytes. */\nint unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp)\n{\n    int l, c, b, i;\n\n    c = *p++;\n    if (c < 0x80) {\n        *pp = p;\n        return c;\n    }\n    switch(c) {\n    case 0xc0 ... 0xdf:\n        l = 1;\n        break;\n    case 0xe0 ... 0xef:\n        l = 2;\n        break;\n    case 0xf0 ... 0xf7:\n        l = 3;\n        break;\n    case 0xf8 ... 0xfb:\n        l = 4;\n        break;\n    case 0xfc ... 0xfd:\n        l = 5;\n        break;\n    default:\n        return -1;\n    }\n    /* check that we have enough characters */\n    if (l > (max_len - 1))\n        return -1;\n    c &= utf8_first_code_mask[l - 1];\n    for(i = 0; i < l; i++) {\n        b = *p++;\n        if (b < 0x80 || b >= 0xc0)\n            return -1;\n        c = (c << 6) | (b & 0x3f);\n    }\n    if (c < utf8_min_code[l - 1])\n        return -1;\n    *pp = p;\n    return c;\n}\n\n#if 0\n\n#if defined(EMSCRIPTEN) || defined(__ANDROID__)\n\nstatic void *rqsort_arg;\nstatic int (*rqsort_cmp)(const void *, const void *, void *);\n\nstatic int rqsort_cmp2(const void *p1, const void *p2)\n{\n    return rqsort_cmp(p1, p2, rqsort_arg);\n}\n\n/* not reentrant, but not needed with emscripten */\nvoid rqsort(void *base, size_t nmemb, size_t size,\n            int (*cmp)(const void *, const void *, void *),\n            void *arg)\n{\n    rqsort_arg = arg;\n    rqsort_cmp = cmp;\n    qsort(base, nmemb, size, rqsort_cmp2);\n}\n\n#endif\n\n#else\n\ntypedef void (*exchange_f)(void *a, void *b, size_t size);\ntypedef int (*cmp_f)(const void *, const void *, void *opaque);\n\nstatic void exchange_bytes(void *a, void *b, size_t size) {\n    uint8_t *ap = (uint8_t *)a;\n    uint8_t *bp = (uint8_t *)b;\n\n    while (size-- != 0) {\n        uint8_t t = *ap;\n        *ap++ = *bp;\n        *bp++ = t;\n    }\n}\n\nstatic void exchange_one_byte(void *a, void *b, size_t size) {\n    uint8_t *ap = (uint8_t *)a;\n    uint8_t *bp = (uint8_t *)b;\n    uint8_t t = *ap;\n    *ap = *bp;\n    *bp = t;\n}\n\nstatic void exchange_int16s(void *a, void *b, size_t size) {\n    uint16_t *ap = (uint16_t *)a;\n    uint16_t *bp = (uint16_t *)b;\n\n    for (size /= sizeof(uint16_t); size-- != 0;) {\n        uint16_t t = *ap;\n        *ap++ = *bp;\n        *bp++ = t;\n    }\n}\n\nstatic void exchange_one_int16(void *a, void *b, size_t size) {\n    uint16_t *ap = (uint16_t *)a;\n    uint16_t *bp = (uint16_t *)b;\n    uint16_t t = *ap;\n    *ap = *bp;\n    *bp = t;\n}\n\nstatic void exchange_int32s(void *a, void *b, size_t size) {\n    uint32_t *ap = (uint32_t *)a;\n    uint32_t *bp = (uint32_t *)b;\n\n    for (size /= sizeof(uint32_t); size-- != 0;) {\n        uint32_t t = *ap;\n        *ap++ = *bp;\n        *bp++ = t;\n    }\n}\n\nstatic void exchange_one_int32(void *a, void *b, size_t size) {\n    uint32_t *ap = (uint32_t *)a;\n    uint32_t *bp = (uint32_t *)b;\n    uint32_t t = *ap;\n    *ap = *bp;\n    *bp = t;\n}\n\nstatic void exchange_int64s(void *a, void *b, size_t size) {\n    uint64_t *ap = (uint64_t *)a;\n    uint64_t *bp = (uint64_t *)b;\n\n    for (size /= sizeof(uint64_t); size-- != 0;) {\n        uint64_t t = *ap;\n        *ap++ = *bp;\n        *bp++ = t;\n    }\n}\n\nstatic void exchange_one_int64(void *a, void *b, size_t size) {\n    uint64_t *ap = (uint64_t *)a;\n    uint64_t *bp = (uint64_t *)b;\n    uint64_t t = *ap;\n    *ap = *bp;\n    *bp = t;\n}\n\nstatic void exchange_int128s(void *a, void *b, size_t size) {\n    uint64_t *ap = (uint64_t *)a;\n    uint64_t *bp = (uint64_t *)b;\n\n    for (size /= sizeof(uint64_t) * 2; size-- != 0; ap += 2, bp += 2) {\n        uint64_t t = ap[0];\n        uint64_t u = ap[1];\n        ap[0] = bp[0];\n        ap[1] = bp[1];\n        bp[0] = t;\n        bp[1] = u;\n    }\n}\n\nstatic void exchange_one_int128(void *a, void *b, size_t size) {\n    uint64_t *ap = (uint64_t *)a;\n    uint64_t *bp = (uint64_t *)b;\n    uint64_t t = ap[0];\n    uint64_t u = ap[1];\n    ap[0] = bp[0];\n    ap[1] = bp[1];\n    bp[0] = t;\n    bp[1] = u;\n}\n\nstatic inline exchange_f exchange_func(const void *base, size_t size) {\n    switch (((uintptr_t)base | (uintptr_t)size) & 15) {\n    case 0:\n        if (size == sizeof(uint64_t) * 2)\n            return exchange_one_int128;\n        else\n            return exchange_int128s;\n    case 8:\n        if (size == sizeof(uint64_t))\n            return exchange_one_int64;\n        else\n            return exchange_int64s;\n    case 4:\n    case 12:\n        if (size == sizeof(uint32_t))\n            return exchange_one_int32;\n        else\n            return exchange_int32s;\n    case 2:\n    case 6:\n    case 10:\n    case 14:\n        if (size == sizeof(uint16_t))\n            return exchange_one_int16;\n        else\n            return exchange_int16s;\n    default:\n        if (size == 1)\n            return exchange_one_byte;\n        else\n            return exchange_bytes;\n    }\n}\n\nstatic void heapsortx(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)\n{\n    uint8_t *basep = (uint8_t *)base;\n    size_t i, n, c, r;\n    exchange_f swap = exchange_func(base, size);\n\n    if (nmemb > 1) {\n        i = (nmemb / 2) * size;\n        n = nmemb * size;\n\n        while (i > 0) {\n            i -= size;\n            for (r = i; (c = r * 2 + size) < n; r = c) {\n                if (c < n - size && cmp(basep + c, basep + c + size, opaque) <= 0)\n                    c += size;\n                if (cmp(basep + r, basep + c, opaque) > 0)\n                    break;\n                swap(basep + r, basep + c, size);\n            }\n        }\n        for (i = n - size; i > 0; i -= size) {\n            swap(basep, basep + i, size);\n\n            for (r = 0; (c = r * 2 + size) < i; r = c) {\n                if (c < i - size && cmp(basep + c, basep + c + size, opaque) <= 0)\n                    c += size;\n                if (cmp(basep + r, basep + c, opaque) > 0)\n                    break;\n                swap(basep + r, basep + c, size);\n            }\n        }\n    }\n}\n\nstatic inline void *med3(void *a, void *b, void *c, cmp_f cmp, void *opaque)\n{\n    return cmp(a, b, opaque) < 0 ?\n        (cmp(b, c, opaque) < 0 ? b : (cmp(a, c, opaque) < 0 ? c : a )) :\n        (cmp(b, c, opaque) > 0 ? b : (cmp(a, c, opaque) < 0 ? a : c ));\n}\n\n/* pointer based version with local stack and insertion sort threshhold */\nvoid rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)\n{\n    struct { uint8_t *base; size_t count; int depth; } stack[50], *sp = stack;\n    uint8_t *ptr, *pi, *pj, *plt, *pgt, *top, *m;\n    size_t m4, i, lt, gt, span, span2;\n    int c, depth;\n    exchange_f swap = exchange_func(base, size);\n    exchange_f swap_block = exchange_func(base, size | 128);\n\n    if (nmemb < 2 || size <= 0)\n        return;\n\n    sp->base = (uint8_t *)base;\n    sp->count = nmemb;\n    sp->depth = 0;\n    sp++;\n\n    while (sp > stack) {\n        sp--;\n        ptr = sp->base;\n        nmemb = sp->count;\n        depth = sp->depth;\n\n        while (nmemb > 6) {\n            if (++depth > 50) {\n                /* depth check to ensure worst case logarithmic time */\n                heapsortx(ptr, nmemb, size, cmp, opaque);\n                nmemb = 0;\n                break;\n            }\n            /* select median of 3 from 1/4, 1/2, 3/4 positions */\n            /* should use median of 5 or 9? */\n            m4 = (nmemb >> 2) * size;\n            m = med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque);\n            swap(ptr, m, size);  /* move the pivot to the start or the array */\n            i = lt = 1;\n            pi = plt = ptr + size;\n            gt = nmemb;\n            pj = pgt = top = ptr + nmemb * size;\n            for (;;) {\n                while (pi < pj && (c = cmp(ptr, pi, opaque)) >= 0) {\n                    if (c == 0) {\n                        swap(plt, pi, size);\n                        lt++;\n                        plt += size;\n                    }\n                    i++;\n                    pi += size;\n                }\n                while (pi < (pj -= size) && (c = cmp(ptr, pj, opaque)) <= 0) {\n                    if (c == 0) {\n                        gt--;\n                        pgt -= size;\n                        swap(pgt, pj, size);\n                    }\n                }\n                if (pi >= pj)\n                    break;\n                swap(pi, pj, size);\n                i++;\n                pi += size;\n            }\n            /* array has 4 parts:\n             * from 0 to lt excluded: elements identical to pivot\n             * from lt to pi excluded: elements smaller than pivot\n             * from pi to gt excluded: elements greater than pivot\n             * from gt to n excluded: elements identical to pivot\n             */\n            /* move elements identical to pivot in the middle of the array: */\n            /* swap values in ranges [0..lt[ and [i-lt..i[\n               swapping the smallest span between lt and i-lt is sufficient\n             */\n            span = plt - ptr;\n            span2 = pi - plt;\n            lt = i - lt;\n            if (span > span2)\n                span = span2;\n            swap_block(ptr, pi - span, span);\n            /* swap values in ranges [gt..top[ and [i..top-(top-gt)[\n               swapping the smallest span between top-gt and gt-i is sufficient\n             */\n            span = top - pgt;\n            span2 = pgt - pi;\n            pgt = top - span2;\n            gt = nmemb - (gt - i);\n            if (span > span2)\n                span = span2;\n            swap_block(pi, top - span, span);\n\n            /* now array has 3 parts:\n             * from 0 to lt excluded: elements smaller than pivot\n             * from lt to gt excluded: elements identical to pivot\n             * from gt to n excluded: elements greater than pivot\n             */\n            /* stack the larger segment and keep processing the smaller one\n               to minimize stack use for pathological distributions */\n            if (lt > nmemb - gt) {\n                sp->base = ptr;\n                sp->count = lt;\n                sp->depth = depth;\n                sp++;\n                ptr = pgt;\n                nmemb -= gt;\n            } else {\n                sp->base = pgt;\n                sp->count = nmemb - gt;\n                sp->depth = depth;\n                sp++;\n                nmemb = lt;\n            }\n        }\n        /* Use insertion sort for small fragments */\n        for (pi = ptr + size, top = ptr + nmemb * size; pi < top; pi += size) {\n            for (pj = pi; pj > ptr && cmp(pj - size, pj, opaque) > 0; pj -= size)\n                swap(pj, pj - size, size);\n        }\n    }\n}\n\n#endif\n"
  },
  {
    "path": "cutils.h",
    "content": "/*\n * C utilities\n * \n * Copyright (c) 2017 Fabrice Bellard\n * Copyright (c) 2018 Charlie Gordon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#ifndef CUTILS_H\n#define CUTILS_H\n\n#include <stdlib.h>\n#include <inttypes.h>\n\n/* set if CPU is big endian */\n#undef WORDS_BIGENDIAN\n\n#define likely(x)       __builtin_expect(!!(x), 1)\n#define unlikely(x)     __builtin_expect(!!(x), 0)\n#define force_inline inline __attribute__((always_inline))\n#define no_inline __attribute__((noinline))\n#define __maybe_unused __attribute__((unused))\n\n#define xglue(x, y) x ## y\n#define glue(x, y) xglue(x, y)\n#define stringify(s)    tostring(s)\n#define tostring(s)     #s\n\n#ifndef offsetof\n#define offsetof(type, field) ((size_t) &((type *)0)->field)\n#endif\n#ifndef countof\n#define countof(x) (sizeof(x) / sizeof((x)[0]))\n#endif\n\ntypedef int BOOL;\n\n#ifndef FALSE\nenum {\n    FALSE = 0,\n    TRUE = 1,\n};\n#endif\n\nvoid pstrcpy(char *buf, int buf_size, const char *str);\nchar *pstrcat(char *buf, int buf_size, const char *s);\nint strstart(const char *str, const char *val, const char **ptr);\nint has_suffix(const char *str, const char *suffix);\n\nstatic inline int max_int(int a, int b)\n{\n    if (a > b)\n        return a;\n    else\n        return b;\n}\n\nstatic inline int min_int(int a, int b)\n{\n    if (a < b)\n        return a;\n    else\n        return b;\n}\n\nstatic inline uint32_t max_uint32(uint32_t a, uint32_t b)\n{\n    if (a > b)\n        return a;\n    else\n        return b;\n}\n\nstatic inline uint32_t min_uint32(uint32_t a, uint32_t b)\n{\n    if (a < b)\n        return a;\n    else\n        return b;\n}\n\nstatic inline int64_t max_int64(int64_t a, int64_t b)\n{\n    if (a > b)\n        return a;\n    else\n        return b;\n}\n\nstatic inline int64_t min_int64(int64_t a, int64_t b)\n{\n    if (a < b)\n        return a;\n    else\n        return b;\n}\n\n/* WARNING: undefined if a = 0 */\nstatic inline int clz32(unsigned int a)\n{\n    return __builtin_clz(a);\n}\n\n/* WARNING: undefined if a = 0 */\nstatic inline int clz64(uint64_t a)\n{\n    return __builtin_clzll(a);\n}\n\n/* WARNING: undefined if a = 0 */\nstatic inline int ctz32(unsigned int a)\n{\n    return __builtin_ctz(a);\n}\n\n/* WARNING: undefined if a = 0 */\nstatic inline int ctz64(uint64_t a)\n{\n    return __builtin_ctzll(a);\n}\n\nstruct __attribute__((packed)) packed_u64 {\n    uint64_t v;\n};\n\nstruct __attribute__((packed)) packed_u32 {\n    uint32_t v;\n};\n\nstruct __attribute__((packed)) packed_u16 {\n    uint16_t v;\n};\n\nstatic inline uint64_t get_u64(const uint8_t *tab)\n{\n    return ((const struct packed_u64 *)tab)->v;\n}\n\nstatic inline int64_t get_i64(const uint8_t *tab)\n{\n    return (int64_t)((const struct packed_u64 *)tab)->v;\n}\n\nstatic inline void put_u64(uint8_t *tab, uint64_t val)\n{\n    ((struct packed_u64 *)tab)->v = val;\n}\n\nstatic inline uint32_t get_u32(const uint8_t *tab)\n{\n    return ((const struct packed_u32 *)tab)->v;\n}\n\nstatic inline int32_t get_i32(const uint8_t *tab)\n{\n    return (int32_t)((const struct packed_u32 *)tab)->v;\n}\n\nstatic inline void put_u32(uint8_t *tab, uint32_t val)\n{\n    ((struct packed_u32 *)tab)->v = val;\n}\n\nstatic inline uint32_t get_u16(const uint8_t *tab)\n{\n    return ((const struct packed_u16 *)tab)->v;\n}\n\nstatic inline int32_t get_i16(const uint8_t *tab)\n{\n    return (int16_t)((const struct packed_u16 *)tab)->v;\n}\n\nstatic inline void put_u16(uint8_t *tab, uint16_t val)\n{\n    ((struct packed_u16 *)tab)->v = val;\n}\n\nstatic inline uint32_t get_u8(const uint8_t *tab)\n{\n    return *tab;\n}\n\nstatic inline int32_t get_i8(const uint8_t *tab)\n{\n    return (int8_t)*tab;\n}\n\nstatic inline void put_u8(uint8_t *tab, uint8_t val)\n{\n    *tab = val;\n}\n\nstatic inline uint16_t bswap16(uint16_t x)\n{\n    return (x >> 8) | (x << 8);\n}\n\nstatic inline uint32_t bswap32(uint32_t v)\n{\n    return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >>  8) |\n        ((v & 0x0000ff00) <<  8) | ((v & 0x000000ff) << 24);\n}\n\nstatic inline uint64_t bswap64(uint64_t v)\n{\n    return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) | \n        ((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) | \n        ((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) | \n        ((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) | \n        ((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) | \n        ((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) | \n        ((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) | \n        ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));\n}\n\n/* XXX: should take an extra argument to pass slack information to the caller */\ntypedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);\n\ntypedef struct DynBuf {\n    uint8_t *buf;\n    size_t size;\n    size_t allocated_size;\n    BOOL error; /* true if a memory allocation error occurred */\n    DynBufReallocFunc *realloc_func;\n    void *opaque; /* for realloc_func */\n} DynBuf;\n\nvoid dbuf_init(DynBuf *s);\nvoid dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);\nint dbuf_realloc(DynBuf *s, size_t new_size);\nint dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len);\nint dbuf_put(DynBuf *s, const uint8_t *data, size_t len);\nint dbuf_put_self(DynBuf *s, size_t offset, size_t len);\nint dbuf_putc(DynBuf *s, uint8_t c);\nint dbuf_putstr(DynBuf *s, const char *str);\nstatic inline int dbuf_put_u16(DynBuf *s, uint16_t val)\n{\n    return dbuf_put(s, (uint8_t *)&val, 2);\n}\nstatic inline int dbuf_put_u32(DynBuf *s, uint32_t val)\n{\n    return dbuf_put(s, (uint8_t *)&val, 4);\n}\nstatic inline int dbuf_put_u64(DynBuf *s, uint64_t val)\n{\n    return dbuf_put(s, (uint8_t *)&val, 8);\n}\nint __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,\n                                                      const char *fmt, ...);\nvoid dbuf_free(DynBuf *s);\nstatic inline BOOL dbuf_error(DynBuf *s) {\n    return s->error;\n}\nstatic inline void dbuf_set_error(DynBuf *s)\n{\n    s->error = TRUE;\n}\n\n#define UTF8_CHAR_LEN_MAX 6\n\nint unicode_to_utf8(uint8_t *buf, unsigned int c);\nint unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp);\n\nstatic inline int from_hex(int c)\n{\n    if (c >= '0' && c <= '9')\n        return c - '0';\n    else if (c >= 'A' && c <= 'F')\n        return c - 'A' + 10;\n    else if (c >= 'a' && c <= 'f')\n        return c - 'a' + 10;\n    else\n        return -1;\n}\n\nvoid rqsort(void *base, size_t nmemb, size_t size,\n            int (*cmp)(const void *, const void *, void *),\n            void *arg);\n\n#endif  /* CUTILS_H */\n"
  },
  {
    "path": "examples/main.go",
    "content": "package main\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\t\"github.com/lithdew/quickjs\"\n\t\"strings\"\n)\n\nfunc check(err error) {\n\tif err != nil {\n\t\tvar evalErr *quickjs.Error\n\t\tif errors.As(err, &evalErr) {\n\t\t\tfmt.Println(evalErr.Cause)\n\t\t\tfmt.Println(evalErr.Stack)\n\t\t}\n\t\tpanic(err)\n\t}\n}\n\nfunc main() {\n\truntime := quickjs.NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\tglobals := context.Globals()\n\n\t// Test evaluating template strings.\n\n\tresult, err := context.Eval(\"`Hello world! 2 ** 8 = ${2 ** 8}.`\")\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.String())\n\tfmt.Println()\n\n\t// Test evaluating numeric expressions.\n\n\tresult, err = context.Eval(`1 + 2 * 100 - 3 + Math.sin(10)`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.Int64())\n\tfmt.Println()\n\n\t// Test evaluating big integer expressions.\n\n\tresult, err = context.Eval(`128n ** 16n`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.BigInt())\n\tfmt.Println()\n\n\t// Test evaluating big decimal expressions.\n\n\tresult, err = context.Eval(`128l ** 12l`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.BigFloat())\n\tfmt.Println()\n\n\t// Test evaluating boolean expressions.\n\n\tresult, err = context.Eval(`false && true`)\n\tcheck(err)\n\tdefer result.Free()\n\n\tfmt.Println(result.Bool())\n\tfmt.Println()\n\n\t// Test setting and calling functions.\n\n\tA := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {\n\t\tfmt.Println(\"A got called!\")\n\t\treturn ctx.Null()\n\t}\n\n\tB := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {\n\t\tfmt.Println(\"B got called!\")\n\t\treturn ctx.Null()\n\t}\n\n\tglobals.Set(\"A\", context.Function(A))\n\tglobals.Set(\"B\", context.Function(B))\n\n\t_, err = context.Eval(`for (let i = 0; i < 10; i++) { if (i % 2 === 0) A(); else B(); }`)\n\tcheck(err)\n\n\tfmt.Println()\n\n\t// Test setting global variables.\n\n\t_, err = context.Eval(`HELLO = \"world\"; TEST = false;`)\n\tcheck(err)\n\n\tnames, err := globals.PropertyNames()\n\tcheck(err)\n\n\tfmt.Println(\"Globals:\")\n\tfor _, name := range names {\n\t\tval := globals.GetByAtom(name.Atom)\n\t\tdefer val.Free()\n\n\t\tfmt.Printf(\"'%s': %s\\n\", name, val)\n\t}\n\tfmt.Println()\n\n\t// Test evaluating arbitrary expressions from flag arguments.\n\n\tflag.Parse()\n\tif flag.NArg() == 0 {\n\t\treturn\n\t}\n\n\tresult, err = context.Eval(strings.Join(flag.Args(), \" \"))\n\tcheck(err)\n\tdefer result.Free()\n\n\tif result.IsObject() {\n\t\tnames, err := result.PropertyNames()\n\t\tcheck(err)\n\n\t\tfmt.Println(\"Object:\")\n\t\tfor _, name := range names {\n\t\t\tval := result.GetByAtom(name.Atom)\n\t\t\tdefer val.Free()\n\n\t\t\tfmt.Printf(\"'%s': %s\\n\", name, val)\n\t\t}\n\t} else {\n\t\tfmt.Println(result.String())\n\t}\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/lithdew/quickjs\n\ngo 1.14\n\nrequire github.com/stretchr/testify v1.6.1\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=\ngithub.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=\ngithub.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=\ngithub.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=\ngithub.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=\ngithub.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=\ngithub.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=\ngopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=\ngopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\n"
  },
  {
    "path": "libbf.c",
    "content": "/*\n * Tiny arbitrary precision floating point library\n * \n * Copyright (c) 2017-2020 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <inttypes.h>\n#include <math.h>\n#include <string.h>\n#include <assert.h>\n\n#ifdef __AVX2__\n#include <immintrin.h>\n#endif\n\n#include \"cutils.h\"\n#include \"libbf.h\"\n\n/* enable it to check the multiplication result */\n//#define USE_MUL_CHECK\n/* enable it to use FFT/NTT multiplication */\n#define USE_FFT_MUL\n/* enable decimal floating point support */\n#define USE_BF_DEC\n\n//#define inline __attribute__((always_inline))\n\n#ifdef __AVX2__\n#define FFT_MUL_THRESHOLD 100 /* in limbs of the smallest factor */\n#else\n#define FFT_MUL_THRESHOLD 100 /* in limbs of the smallest factor */\n#endif\n\n/* XXX: adjust */\n#define DIVNORM_LARGE_THRESHOLD 50\n#define UDIV1NORM_THRESHOLD 3\n\n#if LIMB_BITS == 64\n#define FMT_LIMB1 \"%\" PRIx64 \n#define FMT_LIMB \"%016\" PRIx64 \n#define PRId_LIMB PRId64\n#define PRIu_LIMB PRIu64\n\n#else\n\n#define FMT_LIMB1 \"%x\"\n#define FMT_LIMB \"%08x\"\n#define PRId_LIMB \"d\"\n#define PRIu_LIMB \"u\"\n\n#endif\n\ntypedef intptr_t mp_size_t;\n\ntypedef int bf_op2_func_t(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n                          bf_flags_t flags);\n\n#ifdef USE_FFT_MUL\n\n#define FFT_MUL_R_OVERLAP_A (1 << 0)\n#define FFT_MUL_R_OVERLAP_B (1 << 1)\n#define FFT_MUL_R_NORESIZE  (1 << 2)\n\nstatic no_inline int fft_mul(bf_context_t *s,\n                             bf_t *res, limb_t *a_tab, limb_t a_len,\n                             limb_t *b_tab, limb_t b_len, int mul_flags);\nstatic void fft_clear_cache(bf_context_t *s);\n#endif\n#ifdef USE_BF_DEC\nstatic limb_t get_digit(const limb_t *tab, limb_t len, slimb_t pos);\n#endif\n\n\n/* could leading zeros */\nstatic inline int clz(limb_t a)\n{\n    if (a == 0) {\n        return LIMB_BITS;\n    } else {\n#if LIMB_BITS == 64\n        return clz64(a);\n#else\n        return clz32(a);\n#endif\n    }\n}\n\nstatic inline int ctz(limb_t a)\n{\n    if (a == 0) {\n        return LIMB_BITS;\n    } else {\n#if LIMB_BITS == 64\n        return ctz64(a);\n#else\n        return ctz32(a);\n#endif\n    }\n}\n\nstatic inline int ceil_log2(limb_t a)\n{\n    if (a <= 1)\n        return 0;\n    else\n        return LIMB_BITS - clz(a - 1);\n}\n\n/* b must be >= 1 */\nstatic inline slimb_t ceil_div(slimb_t a, slimb_t b)\n{\n    if (a >= 0)\n        return (a + b - 1) / b;\n    else\n        return a / b;\n}\n\n/* b must be >= 1 */\nstatic inline slimb_t floor_div(slimb_t a, slimb_t b)\n{\n    if (a >= 0) {\n        return a / b;\n    } else {\n        return (a - b + 1) / b;\n    }\n}\n\n/* return r = a modulo b (0 <= r <= b - 1. b must be >= 1 */\nstatic inline limb_t smod(slimb_t a, slimb_t b)\n{\n    a = a % (slimb_t)b;\n    if (a < 0)\n        a += b;\n    return a;\n}\n\n/* signed addition with saturation */\nstatic inline slimb_t sat_add(slimb_t a, slimb_t b)\n{\n    slimb_t r;\n    r = a + b;\n    /* overflow ? */\n    if (((a ^ r) & (b ^ r)) < 0)\n        r = (a >> (LIMB_BITS - 1)) ^ (((limb_t)1 << (LIMB_BITS - 1)) - 1);\n    return r;\n}\n\n#define malloc(s) malloc_is_forbidden(s)\n#define free(p) free_is_forbidden(p)\n#define realloc(p, s) realloc_is_forbidden(p, s)\n\nvoid bf_context_init(bf_context_t *s, bf_realloc_func_t *realloc_func,\n                     void *realloc_opaque)\n{\n    memset(s, 0, sizeof(*s));\n    s->realloc_func = realloc_func;\n    s->realloc_opaque = realloc_opaque;\n}\n\nvoid bf_context_end(bf_context_t *s)\n{\n    bf_clear_cache(s);\n}\n\nvoid bf_init(bf_context_t *s, bf_t *r)\n{\n    r->ctx = s;\n    r->sign = 0;\n    r->expn = BF_EXP_ZERO;\n    r->len = 0;\n    r->tab = NULL;\n}\n\n/* return 0 if OK, -1 if alloc error */\nint bf_resize(bf_t *r, limb_t len)\n{\n    limb_t *tab;\n    \n    if (len != r->len) {\n        tab = bf_realloc(r->ctx, r->tab, len * sizeof(limb_t));\n        if (!tab && len != 0)\n            return -1;\n        r->tab = tab;\n        r->len = len;\n    }\n    return 0;\n}\n\n/* return 0 or BF_ST_MEM_ERROR */\nint bf_set_ui(bf_t *r, uint64_t a)\n{\n    r->sign = 0;\n    if (a == 0) {\n        r->expn = BF_EXP_ZERO;\n        bf_resize(r, 0); /* cannot fail */\n    } \n#if LIMB_BITS == 32\n    else if (a <= 0xffffffff)\n#else\n    else\n#endif\n    {\n        int shift;\n        if (bf_resize(r, 1))\n            goto fail;\n        shift = clz(a);\n        r->tab[0] = a << shift;\n        r->expn = LIMB_BITS - shift;\n    }\n#if LIMB_BITS == 32\n    else {\n        uint32_t a1, a0;\n        int shift;\n        if (bf_resize(r, 2))\n            goto fail;\n        a0 = a;\n        a1 = a >> 32;\n        shift = clz(a1);\n        r->tab[0] = a0 << shift;\n        r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift));\n        r->expn = 2 * LIMB_BITS - shift;\n    }\n#endif\n    return 0;\n fail:\n    bf_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\n/* return 0 or BF_ST_MEM_ERROR */\nint bf_set_si(bf_t *r, int64_t a)\n{\n    int ret;\n\n    if (a < 0) {\n        ret = bf_set_ui(r, -a);\n        r->sign = 1;\n    } else {\n        ret = bf_set_ui(r, a);\n    }\n    return ret;\n}\n\nvoid bf_set_nan(bf_t *r)\n{\n    bf_resize(r, 0); /* cannot fail */\n    r->expn = BF_EXP_NAN;\n    r->sign = 0;\n}\n\nvoid bf_set_zero(bf_t *r, int is_neg)\n{\n    bf_resize(r, 0); /* cannot fail */\n    r->expn = BF_EXP_ZERO;\n    r->sign = is_neg;\n}\n\nvoid bf_set_inf(bf_t *r, int is_neg)\n{\n    bf_resize(r, 0); /* cannot fail */\n    r->expn = BF_EXP_INF;\n    r->sign = is_neg;\n}\n\n/* return 0 or BF_ST_MEM_ERROR */\nint bf_set(bf_t *r, const bf_t *a)\n{\n    if (r == a)\n        return 0;\n    if (bf_resize(r, a->len)) {\n        bf_set_nan(r);\n        return BF_ST_MEM_ERROR;\n    }\n    r->sign = a->sign;\n    r->expn = a->expn;\n    memcpy(r->tab, a->tab, a->len * sizeof(limb_t));\n    return 0;\n}\n\n/* equivalent to bf_set(r, a); bf_delete(a) */\nvoid bf_move(bf_t *r, bf_t *a)\n{\n    bf_context_t *s = r->ctx;\n    if (r == a)\n        return;\n    bf_free(s, r->tab);\n    *r = *a;\n}\n\nstatic limb_t get_limbz(const bf_t *a, limb_t idx)\n{\n    if (idx >= a->len)\n        return 0;\n    else\n        return a->tab[idx];\n}\n\n/* get LIMB_BITS at bit position 'pos' in tab */\nstatic inline limb_t get_bits(const limb_t *tab, limb_t len, slimb_t pos)\n{\n    limb_t i, a0, a1;\n    int p;\n\n    i = pos >> LIMB_LOG2_BITS;\n    p = pos & (LIMB_BITS - 1);\n    if (i < len)\n        a0 = tab[i];\n    else\n        a0 = 0;\n    if (p == 0) {\n        return a0;\n    } else {\n        i++;\n        if (i < len)\n            a1 = tab[i];\n        else\n            a1 = 0;\n        return (a0 >> p) | (a1 << (LIMB_BITS - p));\n    }\n}\n\nstatic inline limb_t get_bit(const limb_t *tab, limb_t len, slimb_t pos)\n{\n    slimb_t i;\n    i = pos >> LIMB_LOG2_BITS;\n    if (i < 0 || i >= len)\n        return 0;\n    return (tab[i] >> (pos & (LIMB_BITS - 1))) & 1;\n}\n\nstatic inline limb_t limb_mask(int start, int last)\n{\n    limb_t v;\n    int n;\n    n = last - start + 1;\n    if (n == LIMB_BITS)\n        v = -1;\n    else\n        v = (((limb_t)1 << n) - 1) << start;\n    return v;\n}\n\nstatic limb_t mp_scan_nz(const limb_t *tab, mp_size_t n)\n{\n    mp_size_t i;\n    for(i = 0; i < n; i++) {\n        if (tab[i] != 0)\n            return 1;\n    }\n    return 0;\n}\n\n/* return != 0 if one bit between 0 and bit_pos inclusive is not zero. */\nstatic inline limb_t scan_bit_nz(const bf_t *r, slimb_t bit_pos)\n{\n    slimb_t pos;\n    limb_t v;\n    \n    pos = bit_pos >> LIMB_LOG2_BITS;\n    if (pos < 0)\n        return 0;\n    v = r->tab[pos] & limb_mask(0, bit_pos & (LIMB_BITS - 1));\n    if (v != 0)\n        return 1;\n    pos--;\n    while (pos >= 0) {\n        if (r->tab[pos] != 0)\n            return 1;\n        pos--;\n    }\n    return 0;\n}\n\n/* return the addend for rounding. Note that prec can be <= 0 (for\n   BF_FLAG_RADPNT_PREC) */\nstatic int bf_get_rnd_add(int *pret, const bf_t *r, limb_t l,\n                          slimb_t prec, int rnd_mode)\n{\n    int add_one, inexact;\n    limb_t bit1, bit0;\n    \n    if (rnd_mode == BF_RNDF) {\n        bit0 = 1; /* faithful rounding does not honor the INEXACT flag */\n    } else {\n        /* starting limb for bit 'prec + 1' */\n        bit0 = scan_bit_nz(r, l * LIMB_BITS - 1 - bf_max(0, prec + 1));\n    }\n\n    /* get the bit at 'prec' */\n    bit1 = get_bit(r->tab, l, l * LIMB_BITS - 1 - prec);\n    inexact = (bit1 | bit0) != 0;\n    \n    add_one = 0;\n    switch(rnd_mode) {\n    case BF_RNDZ:\n        break;\n    case BF_RNDN:\n        if (bit1) {\n            if (bit0) {\n                add_one = 1;\n            } else {\n                /* round to even */\n                add_one =\n                    get_bit(r->tab, l, l * LIMB_BITS - 1 - (prec - 1));\n            }\n        }\n        break;\n    case BF_RNDD:\n    case BF_RNDU:\n        if (r->sign == (rnd_mode == BF_RNDD))\n            add_one = inexact;\n        break;\n    case BF_RNDA:\n        add_one = inexact;\n        break;\n    case BF_RNDNA:\n    case BF_RNDF:\n        add_one = bit1;\n        break;\n    default:\n        abort();\n    }\n    \n    if (inexact)\n        *pret |= BF_ST_INEXACT;\n    return add_one;\n}\n\nstatic int bf_set_overflow(bf_t *r, int sign, limb_t prec, bf_flags_t flags)\n{\n    slimb_t i, l, e_max;\n    int rnd_mode;\n    \n    rnd_mode = flags & BF_RND_MASK;\n    if (prec == BF_PREC_INF ||\n        rnd_mode == BF_RNDN ||\n        rnd_mode == BF_RNDNA ||\n        rnd_mode == BF_RNDA ||\n        (rnd_mode == BF_RNDD && sign == 1) ||\n        (rnd_mode == BF_RNDU && sign == 0)) {\n        bf_set_inf(r, sign);\n    } else {\n        /* set to maximum finite number */\n        l = (prec + LIMB_BITS - 1) / LIMB_BITS;\n        if (bf_resize(r, l)) {\n            bf_set_nan(r);\n            return BF_ST_MEM_ERROR;\n        }\n        r->tab[0] = limb_mask((-prec) & (LIMB_BITS - 1),\n                              LIMB_BITS - 1);\n        for(i = 1; i < l; i++)\n            r->tab[i] = (limb_t)-1;\n        e_max = (limb_t)1 << (bf_get_exp_bits(flags) - 1);\n        r->expn = e_max;\n        r->sign = sign;\n    }\n    return BF_ST_OVERFLOW | BF_ST_INEXACT;\n}\n\n/* round to prec1 bits assuming 'r' is non zero and finite. 'r' is\n   assumed to have length 'l' (1 <= l <= r->len). Note: 'prec1' can be\n   infinite (BF_PREC_INF). 'ret' is 0 or BF_ST_INEXACT if the result\n   is known to be inexact. Can fail with BF_ST_MEM_ERROR in case of\n   overflow not returning infinity. */\nstatic int __bf_round(bf_t *r, limb_t prec1, bf_flags_t flags, limb_t l,\n                      int ret)\n{\n    limb_t v, a;\n    int shift, add_one, rnd_mode;\n    slimb_t i, bit_pos, pos, e_min, e_max, e_range, prec;\n\n    /* e_min and e_max are computed to match the IEEE 754 conventions */\n    e_range = (limb_t)1 << (bf_get_exp_bits(flags) - 1);\n    e_min = -e_range + 3;\n    e_max = e_range;\n    \n    if (flags & BF_FLAG_RADPNT_PREC) {\n        /* 'prec' is the precision after the radix point */\n        if (prec1 != BF_PREC_INF)\n            prec = r->expn + prec1;\n        else\n            prec = prec1;\n    } else if (unlikely(r->expn < e_min) && (flags & BF_FLAG_SUBNORMAL)) {\n        /* restrict the precision in case of potentially subnormal\n           result */\n        assert(prec1 != BF_PREC_INF);\n        prec = prec1 - (e_min - r->expn);\n    } else {\n        prec = prec1;\n    }\n\n    /* round to prec bits */\n    rnd_mode = flags & BF_RND_MASK;\n    add_one = bf_get_rnd_add(&ret, r, l, prec, rnd_mode);\n    \n    if (prec <= 0) {\n        if (add_one) {\n            bf_resize(r, 1); /* cannot fail */\n            r->tab[0] = (limb_t)1 << (LIMB_BITS - 1);\n            r->expn += 1 - prec;\n            ret |= BF_ST_UNDERFLOW | BF_ST_INEXACT;\n            return ret;\n        } else {\n            goto underflow;\n        }\n    } else if (add_one) {\n        limb_t carry;\n        \n        /* add one starting at digit 'prec - 1' */\n        bit_pos = l * LIMB_BITS - 1 - (prec - 1);\n        pos = bit_pos >> LIMB_LOG2_BITS;\n        carry = (limb_t)1 << (bit_pos & (LIMB_BITS - 1));\n        \n        for(i = pos; i < l; i++) {\n            v = r->tab[i] + carry;\n            carry = (v < carry);\n            r->tab[i] = v;\n            if (carry == 0)\n                break;\n        }\n        if (carry) {\n            /* shift right by one digit */\n            v = 1;\n            for(i = l - 1; i >= pos; i--) {\n                a = r->tab[i];\n                r->tab[i] = (a >> 1) | (v << (LIMB_BITS - 1));\n                v = a;\n            }\n            r->expn++;\n        }\n    }\n    \n    /* check underflow */\n    if (unlikely(r->expn < e_min)) {\n        if (flags & BF_FLAG_SUBNORMAL) {\n            /* if inexact, also set the underflow flag */\n            if (ret & BF_ST_INEXACT)\n                ret |= BF_ST_UNDERFLOW;\n        } else {\n        underflow:\n            ret |= BF_ST_UNDERFLOW | BF_ST_INEXACT;\n            bf_set_zero(r, r->sign);\n            return ret;\n        }\n    }\n    \n    /* check overflow */\n    if (unlikely(r->expn > e_max))\n        return bf_set_overflow(r, r->sign, prec1, flags);\n    \n    /* keep the bits starting at 'prec - 1' */\n    bit_pos = l * LIMB_BITS - 1 - (prec - 1);\n    i = bit_pos >> LIMB_LOG2_BITS;\n    if (i >= 0) {\n        shift = bit_pos & (LIMB_BITS - 1);\n        if (shift != 0)\n            r->tab[i] &= limb_mask(shift, LIMB_BITS - 1);\n    } else {\n        i = 0;\n    }\n    /* remove trailing zeros */\n    while (r->tab[i] == 0)\n        i++;\n    if (i > 0) {\n        l -= i;\n        memmove(r->tab, r->tab + i, l * sizeof(limb_t));\n    }\n    bf_resize(r, l); /* cannot fail */\n    return ret;\n}\n\n/* 'r' must be a finite number. */\nint bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags)\n{\n    limb_t l, v, a;\n    int shift, ret;\n    slimb_t i;\n    \n    //    bf_print_str(\"bf_renorm\", r);\n    l = r->len;\n    while (l > 0 && r->tab[l - 1] == 0)\n        l--;\n    if (l == 0) {\n        /* zero */\n        r->expn = BF_EXP_ZERO;\n        bf_resize(r, 0); /* cannot fail */\n        ret = 0;\n    } else {\n        r->expn -= (r->len - l) * LIMB_BITS;\n        /* shift to have the MSB set to '1' */\n        v = r->tab[l - 1];\n        shift = clz(v);\n        if (shift != 0) {\n            v = 0;\n            for(i = 0; i < l; i++) {\n                a = r->tab[i];\n                r->tab[i] = (a << shift) | (v >> (LIMB_BITS - shift));\n                v = a;\n            }\n            r->expn -= shift;\n        }\n        ret = __bf_round(r, prec1, flags, l, 0);\n    }\n    //    bf_print_str(\"r_final\", r);\n    return ret;\n}\n\n/* return true if rounding can be done at precision 'prec' assuming\n   the exact result r is such that |r-a| <= 2^(EXP(a)-k). */\n/* XXX: check the case where the exponent would be incremented by the\n   rounding */\nint bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k)\n{\n    BOOL is_rndn;\n    slimb_t bit_pos, n;\n    limb_t bit;\n    \n    if (a->expn == BF_EXP_INF || a->expn == BF_EXP_NAN)\n        return FALSE;\n    if (rnd_mode == BF_RNDF) {\n        return (k >= (prec + 1));\n    }\n    if (a->expn == BF_EXP_ZERO)\n        return FALSE;\n    is_rndn = (rnd_mode == BF_RNDN || rnd_mode == BF_RNDNA);\n    if (k < (prec + 2))\n        return FALSE;\n    bit_pos = a->len * LIMB_BITS - 1 - prec;\n    n = k - prec;\n    /* bit pattern for RNDN or RNDNA: 0111.. or 1000...\n       for other rounding modes: 000... or 111... \n    */\n    bit = get_bit(a->tab, a->len, bit_pos);\n    bit_pos--;\n    n--;\n    bit ^= is_rndn;\n    /* XXX: slow, but a few iterations on average */\n    while (n != 0) {\n        if (get_bit(a->tab, a->len, bit_pos) != bit)\n            return TRUE;\n        bit_pos--;\n        n--;\n    }\n    return FALSE;\n}\n\n/* Cannot fail with BF_ST_MEM_ERROR. */\nint bf_round(bf_t *r, limb_t prec, bf_flags_t flags)\n{\n    if (r->len == 0)\n        return 0;\n    return __bf_round(r, prec, flags, r->len, 0);\n}\n\n/* for debugging */\nstatic __maybe_unused void dump_limbs(const char *str, const limb_t *tab, limb_t n)\n{\n    limb_t i;\n    printf(\"%s: len=%\" PRId_LIMB \"\\n\", str, n);\n    for(i = 0; i < n; i++) {\n        printf(\"%\" PRId_LIMB \": \" FMT_LIMB \"\\n\",\n               i, tab[i]);\n    }\n}\n\nvoid mp_print_str(const char *str, const limb_t *tab, limb_t n)\n{\n    slimb_t i;\n    printf(\"%s= 0x\", str);\n    for(i = n - 1; i >= 0; i--) {\n        if (i != (n - 1))\n            printf(\"_\");\n        printf(FMT_LIMB, tab[i]);\n    }\n    printf(\"\\n\");\n}\n\nstatic __maybe_unused void mp_print_str_h(const char *str,\n                                          const limb_t *tab, limb_t n,\n                                          limb_t high)\n{\n    slimb_t i;\n    printf(\"%s= 0x\", str);\n    printf(FMT_LIMB, high);\n    for(i = n - 1; i >= 0; i--) {\n        printf(\"_\");\n        printf(FMT_LIMB, tab[i]);\n    }\n    printf(\"\\n\");\n}\n\n/* for debugging */\nvoid bf_print_str(const char *str, const bf_t *a)\n{\n    slimb_t i;\n    printf(\"%s=\", str);\n\n    if (a->expn == BF_EXP_NAN) {\n        printf(\"NaN\");\n    } else {\n        if (a->sign)\n            putchar('-');\n        if (a->expn == BF_EXP_ZERO) {\n            putchar('0');\n        } else if (a->expn == BF_EXP_INF) {\n            printf(\"Inf\");\n        } else {\n            printf(\"0x0.\");\n            for(i = a->len - 1; i >= 0; i--)\n                printf(FMT_LIMB, a->tab[i]);\n            printf(\"p%\" PRId_LIMB, a->expn);\n        }\n    }\n    printf(\"\\n\");\n}\n\n/* compare the absolute value of 'a' and 'b'. Return < 0 if a < b, 0\n   if a = b and > 0 otherwise. */\nint bf_cmpu(const bf_t *a, const bf_t *b)\n{\n    slimb_t i;\n    limb_t len, v1, v2;\n    \n    if (a->expn != b->expn) {\n        if (a->expn < b->expn)\n            return -1;\n        else\n            return 1;\n    }\n    len = bf_max(a->len, b->len);\n    for(i = len - 1; i >= 0; i--) {\n        v1 = get_limbz(a, a->len - len + i);\n        v2 = get_limbz(b, b->len - len + i);\n        if (v1 != v2) {\n            if (v1 < v2)\n                return -1;\n            else\n                return 1;\n        }\n    }\n    return 0;\n}\n\n/* Full order: -0 < 0, NaN == NaN and NaN is larger than all other numbers */\nint bf_cmp_full(const bf_t *a, const bf_t *b)\n{\n    int res;\n    \n    if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n        if (a->expn == b->expn)\n            res = 0;\n        else if (a->expn == BF_EXP_NAN)\n            res = 1;\n        else\n            res = -1;\n    } else if (a->sign != b->sign) {\n        res = 1 - 2 * a->sign;\n    } else {\n        res = bf_cmpu(a, b);\n        if (a->sign)\n            res = -res;\n    }\n    return res;\n}\n\n/* Standard floating point comparison: return 2 if one of the operands\n   is NaN (unordered) or -1, 0, 1 depending on the ordering assuming\n   -0 == +0 */\nint bf_cmp(const bf_t *a, const bf_t *b)\n{\n    int res;\n    \n    if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n        res = 2;\n    } else if (a->sign != b->sign) {\n        if (a->expn == BF_EXP_ZERO && b->expn == BF_EXP_ZERO)\n            res = 0;\n        else\n            res = 1 - 2 * a->sign;\n    } else {\n        res = bf_cmpu(a, b);\n        if (a->sign)\n            res = -res;\n    }\n    return res;\n}\n\n/* Compute the number of bits 'n' matching the pattern:\n   a= X1000..0\n   b= X0111..1\n              \n   When computing a-b, the result will have at least n leading zero\n   bits.\n\n   Precondition: a > b and a.expn - b.expn = 0 or 1\n*/\nstatic limb_t count_cancelled_bits(const bf_t *a, const bf_t *b)\n{\n    slimb_t bit_offset, b_offset, n;\n    int p, p1;\n    limb_t v1, v2, mask;\n\n    bit_offset = a->len * LIMB_BITS - 1;\n    b_offset = (b->len - a->len) * LIMB_BITS - (LIMB_BITS - 1) +\n        a->expn - b->expn;\n    n = 0;\n\n    /* first search the equals bits */\n    for(;;) {\n        v1 = get_limbz(a, bit_offset >> LIMB_LOG2_BITS);\n        v2 = get_bits(b->tab, b->len, bit_offset + b_offset);\n        //        printf(\"v1=\" FMT_LIMB \" v2=\" FMT_LIMB \"\\n\", v1, v2);\n        if (v1 != v2)\n            break;\n        n += LIMB_BITS;\n        bit_offset -= LIMB_BITS;\n    }\n    /* find the position of the first different bit */\n    p = clz(v1 ^ v2) + 1;\n    n += p;\n    /* then search for '0' in a and '1' in b */\n    p = LIMB_BITS - p;\n    if (p > 0) {\n        /* search in the trailing p bits of v1 and v2 */\n        mask = limb_mask(0, p - 1);\n        p1 = bf_min(clz(v1 & mask), clz((~v2) & mask)) - (LIMB_BITS - p);\n        n += p1;\n        if (p1 != p)\n            goto done;\n    }\n    bit_offset -= LIMB_BITS;\n    for(;;) {\n        v1 = get_limbz(a, bit_offset >> LIMB_LOG2_BITS);\n        v2 = get_bits(b->tab, b->len, bit_offset + b_offset);\n        //        printf(\"v1=\" FMT_LIMB \" v2=\" FMT_LIMB \"\\n\", v1, v2);\n        if (v1 != 0 || v2 != -1) {\n            /* different: count the matching bits */\n            p1 = bf_min(clz(v1), clz(~v2));\n            n += p1;\n            break;\n        }\n        n += LIMB_BITS;\n        bit_offset -= LIMB_BITS;\n    }\n done:\n    return n;\n}\n\nstatic int bf_add_internal(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n                           bf_flags_t flags, int b_neg)\n{\n    const bf_t *tmp;\n    int is_sub, ret, cmp_res, a_sign, b_sign;\n\n    a_sign = a->sign;\n    b_sign = b->sign ^ b_neg;\n    is_sub = a_sign ^ b_sign;\n    cmp_res = bf_cmpu(a, b);\n    if (cmp_res < 0) {\n        tmp = a;\n        a = b;\n        b = tmp;\n        a_sign = b_sign; /* b_sign is never used later */\n    }\n    /* abs(a) >= abs(b) */\n    if (cmp_res == 0 && is_sub && a->expn < BF_EXP_INF) {\n        /* zero result */\n        bf_set_zero(r, (flags & BF_RND_MASK) == BF_RNDD);\n        ret = 0;\n    } else if (a->len == 0 || b->len == 0) {\n        ret = 0;\n        if (a->expn >= BF_EXP_INF) {\n            if (a->expn == BF_EXP_NAN) {\n                /* at least one operand is NaN */\n                bf_set_nan(r);\n            } else if (b->expn == BF_EXP_INF && is_sub) {\n                /* infinities with different signs */\n                bf_set_nan(r);\n                ret = BF_ST_INVALID_OP;\n            } else {\n                bf_set_inf(r, a_sign);\n            }\n        } else {\n            /* at least one zero and not subtract */\n            bf_set(r, a);\n            r->sign = a_sign;\n            goto renorm;\n        }\n    } else {\n        slimb_t d, a_offset, b_bit_offset, i, cancelled_bits;\n        limb_t carry, v1, v2, u, r_len, carry1, precl, tot_len, z, sub_mask;\n\n        r->sign = a_sign;\n        r->expn = a->expn;\n        d = a->expn - b->expn;\n        /* must add more precision for the leading cancelled bits in\n           subtraction */\n        if (is_sub) {\n            if (d <= 1)\n                cancelled_bits = count_cancelled_bits(a, b);\n            else\n                cancelled_bits = 1;\n        } else {\n            cancelled_bits = 0;\n        }\n        \n        /* add two extra bits for rounding */\n        precl = (cancelled_bits + prec + 2 + LIMB_BITS - 1) / LIMB_BITS;\n        tot_len = bf_max(a->len, b->len + (d + LIMB_BITS - 1) / LIMB_BITS);\n        r_len = bf_min(precl, tot_len);\n        if (bf_resize(r, r_len))\n            goto fail;\n        a_offset = a->len - r_len;\n        b_bit_offset = (b->len - r_len) * LIMB_BITS + d;\n\n        /* compute the bits before for the rounding */\n        carry = is_sub;\n        z = 0;\n        sub_mask = -is_sub;\n        i = r_len - tot_len;\n        while (i < 0) {\n            slimb_t ap, bp;\n            BOOL inflag;\n            \n            ap = a_offset + i;\n            bp = b_bit_offset + i * LIMB_BITS;\n            inflag = FALSE;\n            if (ap >= 0 && ap < a->len) {\n                v1 = a->tab[ap];\n                inflag = TRUE;\n            } else {\n                v1 = 0;\n            }\n            if (bp + LIMB_BITS > 0 && bp < (slimb_t)(b->len * LIMB_BITS)) {\n                v2 = get_bits(b->tab, b->len, bp);\n                inflag = TRUE;\n            } else {\n                v2 = 0;\n            }\n            if (!inflag) {\n                /* outside 'a' and 'b': go directly to the next value\n                   inside a or b so that the running time does not\n                   depend on the exponent difference */\n                i = 0;\n                if (ap < 0)\n                    i = bf_min(i, -a_offset);\n                /* b_bit_offset + i * LIMB_BITS + LIMB_BITS >= 1\n                   equivalent to \n                   i >= ceil(-b_bit_offset + 1 - LIMB_BITS) / LIMB_BITS)\n                */\n                if (bp + LIMB_BITS <= 0)\n                    i = bf_min(i, (-b_bit_offset) >> LIMB_LOG2_BITS);\n            } else {\n                i++;\n            }\n            v2 ^= sub_mask;\n            u = v1 + v2;\n            carry1 = u < v1;\n            u += carry;\n            carry = (u < carry) | carry1;\n            z |= u;\n        }\n        /* and the result */\n        for(i = 0; i < r_len; i++) {\n            v1 = get_limbz(a, a_offset + i);\n            v2 = get_bits(b->tab, b->len, b_bit_offset + i * LIMB_BITS);\n            v2 ^= sub_mask;\n            u = v1 + v2;\n            carry1 = u < v1;\n            u += carry;\n            carry = (u < carry) | carry1;\n            r->tab[i] = u;\n        }\n        /* set the extra bits for the rounding */\n        r->tab[0] |= (z != 0);\n\n        /* carry is only possible in add case */\n        if (!is_sub && carry) {\n            if (bf_resize(r, r_len + 1))\n                goto fail;\n            r->tab[r_len] = 1;\n            r->expn += LIMB_BITS;\n        }\n    renorm:\n        ret = bf_normalize_and_round(r, prec, flags);\n    }\n    return ret;\n fail:\n    bf_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nstatic int __bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n                     bf_flags_t flags)\n{\n    return bf_add_internal(r, a, b, prec, flags, 0);\n}\n\nstatic int __bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n                     bf_flags_t flags)\n{\n    return bf_add_internal(r, a, b, prec, flags, 1);\n}\n\nlimb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2, \n              limb_t n, limb_t carry)\n{\n    slimb_t i;\n    limb_t k, a, v, k1;\n    \n    k = carry;\n    for(i=0;i<n;i++) {\n        v = op1[i];\n        a = v + op2[i];\n        k1 = a < v;\n        a = a + k;\n        k = (a < k) | k1;\n        res[i] = a;\n    }\n    return k;\n}\n\nlimb_t mp_add_ui(limb_t *tab, limb_t b, size_t n)\n{\n    size_t i;\n    limb_t k, a;\n\n    k=b;\n    for(i=0;i<n;i++) {\n        if (k == 0)\n            break;\n        a = tab[i] + k;\n        k = (a < k);\n        tab[i] = a;\n    }\n    return k;\n}\n\nlimb_t mp_sub(limb_t *res, const limb_t *op1, const limb_t *op2, \n              mp_size_t n, limb_t carry)\n{\n    int i;\n    limb_t k, a, v, k1;\n    \n    k = carry;\n    for(i=0;i<n;i++) {\n        v = op1[i];\n        a = v - op2[i];\n        k1 = a > v;\n        v = a - k;\n        k = (v > a) | k1;\n        res[i] = v;\n    }\n    return k;\n}\n\n/* compute 0 - op2 */\nstatic limb_t mp_neg(limb_t *res, const limb_t *op2, mp_size_t n, limb_t carry)\n{\n    int i;\n    limb_t k, a, v, k1;\n    \n    k = carry;\n    for(i=0;i<n;i++) {\n        v = 0;\n        a = v - op2[i];\n        k1 = a > v;\n        v = a - k;\n        k = (v > a) | k1;\n        res[i] = v;\n    }\n    return k;\n}\n\nlimb_t mp_sub_ui(limb_t *tab, limb_t b, mp_size_t n)\n{\n    mp_size_t i;\n    limb_t k, a, v;\n    \n    k=b;\n    for(i=0;i<n;i++) {\n        v = tab[i];\n        a = v - k;\n        k = a > v;\n        tab[i] = a;\n        if (k == 0)\n            break;\n    }\n    return k;\n}\n\n/* r = (a + high*B^n) >> shift. Return the remainder r (0 <= r < 2^shift). \n   1 <= shift <= LIMB_BITS - 1 */\nstatic limb_t mp_shr(limb_t *tab_r, const limb_t *tab, mp_size_t n, \n                     int shift, limb_t high)\n{\n    mp_size_t i;\n    limb_t l, a;\n\n    assert(shift >= 1 && shift < LIMB_BITS);\n    l = high;\n    for(i = n - 1; i >= 0; i--) {\n        a = tab[i];\n        tab_r[i] = (a >> shift) | (l << (LIMB_BITS - shift));\n        l = a;\n    }\n    return l & (((limb_t)1 << shift) - 1);\n}\n\n/* tabr[] = taba[] * b + l. Return the high carry */\nstatic limb_t mp_mul1(limb_t *tabr, const limb_t *taba, limb_t n, \n                      limb_t b, limb_t l)\n{\n    limb_t i;\n    dlimb_t t;\n\n    for(i = 0; i < n; i++) {\n        t = (dlimb_t)taba[i] * (dlimb_t)b + l;\n        tabr[i] = t;\n        l = t >> LIMB_BITS;\n    }\n    return l;\n}\n\n/* tabr[] += taba[] * b, return the high word. */\nstatic limb_t mp_add_mul1(limb_t *tabr, const limb_t *taba, limb_t n,\n                          limb_t b)\n{\n    limb_t i, l;\n    dlimb_t t;\n    \n    l = 0;\n    for(i = 0; i < n; i++) {\n        t = (dlimb_t)taba[i] * (dlimb_t)b + l + tabr[i];\n        tabr[i] = t;\n        l = t >> LIMB_BITS;\n    }\n    return l;\n}\n\n/* size of the result : op1_size + op2_size. */\nstatic void mp_mul_basecase(limb_t *result, \n                            const limb_t *op1, limb_t op1_size, \n                            const limb_t *op2, limb_t op2_size) \n{\n    limb_t i, r;\n    \n    result[op1_size] = mp_mul1(result, op1, op1_size, op2[0], 0);\n    for(i=1;i<op2_size;i++) {\n        r = mp_add_mul1(result + i, op1, op1_size, op2[i]);\n        result[i + op1_size] = r;\n    }\n}\n\n/* return 0 if OK, -1 if memory error */\n/* XXX: change API so that result can be allocated */\nint mp_mul(bf_context_t *s, limb_t *result, \n           const limb_t *op1, limb_t op1_size, \n           const limb_t *op2, limb_t op2_size) \n{\n#ifdef USE_FFT_MUL\n    if (unlikely(bf_min(op1_size, op2_size) >= FFT_MUL_THRESHOLD)) {\n        bf_t r_s, *r = &r_s;\n        r->tab = result;\n        /* XXX: optimize memory usage in API */\n        if (fft_mul(s, r, (limb_t *)op1, op1_size,\n                    (limb_t *)op2, op2_size, FFT_MUL_R_NORESIZE))\n            return -1;\n    } else\n#endif\n    {\n        mp_mul_basecase(result, op1, op1_size, op2, op2_size);\n    }\n    return 0;\n}\n\n/* tabr[] -= taba[] * b. Return the value to substract to the high\n   word. */\nstatic limb_t mp_sub_mul1(limb_t *tabr, const limb_t *taba, limb_t n,\n                          limb_t b)\n{\n    limb_t i, l;\n    dlimb_t t;\n    \n    l = 0;\n    for(i = 0; i < n; i++) {\n        t = tabr[i] - (dlimb_t)taba[i] * (dlimb_t)b - l;\n        tabr[i] = t;\n        l = -(t >> LIMB_BITS);\n    }\n    return l;\n}\n\n/* WARNING: d must be >= 2^(LIMB_BITS-1) */\nstatic inline limb_t udiv1norm_init(limb_t d)\n{\n    limb_t a0, a1;\n    a1 = -d - 1;\n    a0 = -1;\n    return (((dlimb_t)a1 << LIMB_BITS) | a0) / d;\n}\n\n/* return the quotient and the remainder in '*pr'of 'a1*2^LIMB_BITS+a0\n   / d' with 0 <= a1 < d. */\nstatic inline limb_t udiv1norm(limb_t *pr, limb_t a1, limb_t a0,\n                                limb_t d, limb_t d_inv)\n{\n    limb_t n1m, n_adj, q, r, ah;\n    dlimb_t a;\n    n1m = ((slimb_t)a0 >> (LIMB_BITS - 1));\n    n_adj = a0 + (n1m & d);\n    a = (dlimb_t)d_inv * (a1 - n1m) + n_adj;\n    q = (a >> LIMB_BITS) + a1;\n    /* compute a - q * r and update q so that the remainder is\\\n       between 0 and d - 1 */\n    a = ((dlimb_t)a1 << LIMB_BITS) | a0;\n    a = a - (dlimb_t)q * d - d;\n    ah = a >> LIMB_BITS;\n    q += 1 + ah;\n    r = (limb_t)a + (ah & d);\n    *pr = r;\n    return q;\n}\n\n/* b must be >= 1 << (LIMB_BITS - 1) */\nstatic limb_t mp_div1norm(limb_t *tabr, const limb_t *taba, limb_t n,\n                          limb_t b, limb_t r)\n{\n    slimb_t i;\n\n    if (n >= UDIV1NORM_THRESHOLD) {\n        limb_t b_inv;\n        b_inv = udiv1norm_init(b);\n        for(i = n - 1; i >= 0; i--) {\n            tabr[i] = udiv1norm(&r, r, taba[i], b, b_inv);\n        }\n    } else {\n        dlimb_t a1;\n        for(i = n - 1; i >= 0; i--) {\n            a1 = ((dlimb_t)r << LIMB_BITS) | taba[i];\n            tabr[i] = a1 / b;\n            r = a1 % b;\n        }\n    }\n    return r;\n}\n\nstatic int mp_divnorm_large(bf_context_t *s, \n                            limb_t *tabq, limb_t *taba, limb_t na, \n                            const limb_t *tabb, limb_t nb);\n\n/* base case division: divides taba[0..na-1] by tabb[0..nb-1]. tabb[nb\n   - 1] must be >= 1 << (LIMB_BITS - 1). na - nb must be >= 0. 'taba'\n   is modified and contains the remainder (nb limbs). tabq[0..na-nb]\n   contains the quotient with tabq[na - nb] <= 1. */\nstatic int mp_divnorm(bf_context_t *s, limb_t *tabq, limb_t *taba, limb_t na, \n                      const limb_t *tabb, limb_t nb)\n{\n    limb_t r, a, c, q, v, b1, b1_inv, n, dummy_r;\n    slimb_t i, j;\n\n    b1 = tabb[nb - 1];\n    if (nb == 1) {\n        taba[0] = mp_div1norm(tabq, taba, na, b1, 0);\n        return 0;\n    }\n    n = na - nb;\n    if (bf_min(n, nb) >= DIVNORM_LARGE_THRESHOLD) {\n        return mp_divnorm_large(s, tabq, taba, na, tabb, nb);\n    }\n    \n    if (n >= UDIV1NORM_THRESHOLD)\n        b1_inv = udiv1norm_init(b1);\n    else\n        b1_inv = 0;\n\n    /* first iteration: the quotient is only 0 or 1 */\n    q = 1;\n    for(j = nb - 1; j >= 0; j--) {\n        if (taba[n + j] != tabb[j]) {\n            if (taba[n + j] < tabb[j])\n                q = 0;\n            break;\n        }\n    }\n    tabq[n] = q;\n    if (q) {\n        mp_sub(taba + n, taba + n, tabb, nb, 0);\n    }\n    \n    for(i = n - 1; i >= 0; i--) {\n        if (unlikely(taba[i + nb] >= b1)) {\n            q = -1;\n        } else if (b1_inv) {\n            q = udiv1norm(&dummy_r, taba[i + nb], taba[i + nb - 1], b1, b1_inv);\n        } else {\n            dlimb_t al;\n            al = ((dlimb_t)taba[i + nb] << LIMB_BITS) | taba[i + nb - 1];\n            q = al / b1;\n            r = al % b1;\n        }\n        r = mp_sub_mul1(taba + i, tabb, nb, q);\n\n        v = taba[i + nb];\n        a = v - r;\n        c = (a > v);\n        taba[i + nb] = a;\n\n        if (c != 0) {\n            /* negative result */\n            for(;;) {\n                q--;\n                c = mp_add(taba + i, taba + i, tabb, nb, 0);\n                /* propagate carry and test if positive result */\n                if (c != 0) {\n                    if (++taba[i + nb] == 0) {\n                        break;\n                    }\n                }\n            }\n        }\n        tabq[i] = q;\n    }\n    return 0;\n}\n\n/* compute r=B^(2*n)/a such as a*r < B^(2*n) < a*r + 2 with n >= 1. 'a'\n   has n limbs with a[n-1] >= B/2 and 'r' has n+1 limbs with r[n] = 1.\n   \n   See Modern Computer Arithmetic by Richard P. Brent and Paul\n   Zimmermann, algorithm 3.5 */\nint mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n)\n{\n    mp_size_t l, h, k, i;\n    limb_t *tabxh, *tabt, c, *tabu;\n    \n    if (n <= 2) {\n        /* return ceil(B^(2*n)/a) - 1 */\n        /* XXX: could avoid allocation */\n        tabu = bf_malloc(s, sizeof(limb_t) * (2 * n + 1));\n        tabt = bf_malloc(s, sizeof(limb_t) * (n + 2));\n        if (!tabt || !tabu)\n            goto fail;\n        for(i = 0; i < 2 * n; i++)\n            tabu[i] = 0;\n        tabu[2 * n] = 1;\n        if (mp_divnorm(s, tabt, tabu, 2 * n + 1, taba, n))\n            goto fail;\n        for(i = 0; i < n + 1; i++)\n            tabr[i] = tabt[i];\n        if (mp_scan_nz(tabu, n) == 0) {\n            /* only happens for a=B^n/2 */\n            mp_sub_ui(tabr, 1, n + 1);\n        }\n    } else {\n        l = (n - 1) / 2;\n        h = n - l;\n        /* n=2p  -> l=p-1, h = p + 1, k = p + 3\n           n=2p+1-> l=p,  h = p + 1; k = p + 2\n        */\n        tabt = bf_malloc(s, sizeof(limb_t) * (n + h + 1));\n        tabu = bf_malloc(s, sizeof(limb_t) * (n + 2 * h - l + 2));\n        if (!tabt || !tabu)\n            goto fail;\n        tabxh = tabr + l;\n        if (mp_recip(s, tabxh, taba + l, h))\n            goto fail;\n        if (mp_mul(s, tabt, taba, n, tabxh, h + 1)) /* n + h + 1 limbs */\n            goto fail;\n        while (tabt[n + h] != 0) {\n            mp_sub_ui(tabxh, 1, h + 1);\n            c = mp_sub(tabt, tabt, taba, n, 0);\n            mp_sub_ui(tabt + n, c, h + 1);\n        }\n        /* T = B^(n+h) - T */\n        mp_neg(tabt, tabt, n + h + 1, 0);\n        tabt[n + h]++;\n        if (mp_mul(s, tabu, tabt + l, n + h + 1 - l, tabxh, h + 1))\n            goto fail;\n        /* n + 2*h - l + 2 limbs */\n        k = 2 * h - l;\n        for(i = 0; i < l; i++)\n            tabr[i] = tabu[i + k];\n        mp_add(tabr + l, tabr + l, tabu + 2 * h, h, 0);\n    }\n    bf_free(s, tabt);\n    bf_free(s, tabu);\n    return 0;\n fail:\n    bf_free(s, tabt);\n    bf_free(s, tabu);\n    return -1;\n}\n\n/* return -1, 0 or 1 */\nstatic int mp_cmp(const limb_t *taba, const limb_t *tabb, mp_size_t n)\n{\n    mp_size_t i;\n    for(i = n - 1; i >= 0; i--) {\n        if (taba[i] != tabb[i]) {\n            if (taba[i] < tabb[i])\n                return -1;\n            else\n                return 1;\n        }\n    }\n    return 0;\n}\n\n//#define DEBUG_DIVNORM_LARGE\n//#define DEBUG_DIVNORM_LARGE2\n\n/* subquadratic divnorm */\nstatic int mp_divnorm_large(bf_context_t *s, \n                            limb_t *tabq, limb_t *taba, limb_t na, \n                            const limb_t *tabb, limb_t nb)\n{\n    limb_t *tabb_inv, nq, *tabt, i, n;\n    nq = na - nb;\n#ifdef DEBUG_DIVNORM_LARGE\n    printf(\"na=%d nb=%d nq=%d\\n\", (int)na, (int)nb, (int)nq);\n    mp_print_str(\"a\", taba, na);\n    mp_print_str(\"b\", tabb, nb);\n#endif\n    assert(nq >= 1);\n    n = nq;\n    if (nq < nb)\n        n++; \n    tabb_inv = bf_malloc(s, sizeof(limb_t) * (n + 1));\n    tabt = bf_malloc(s, sizeof(limb_t) * 2 * (n + 1));\n    if (!tabb_inv || !tabt)\n        goto fail;\n\n    if (n >= nb) {\n        for(i = 0; i < n - nb; i++)\n            tabt[i] = 0;\n        for(i = 0; i < nb; i++)\n            tabt[i + n - nb] = tabb[i];\n    } else {\n        /* truncate B: need to increment it so that the approximate\n           inverse is smaller that the exact inverse */\n        for(i = 0; i < n; i++)\n            tabt[i] = tabb[i + nb - n];\n        if (mp_add_ui(tabt, 1, n)) {\n            /* tabt = B^n : tabb_inv = B^n */\n            memset(tabb_inv, 0, n * sizeof(limb_t));\n            tabb_inv[n] = 1;\n            goto recip_done;\n        }\n    }\n    if (mp_recip(s, tabb_inv, tabt, n))\n        goto fail;\n recip_done:\n    /* Q=A*B^-1 */\n    if (mp_mul(s, tabt, tabb_inv, n + 1, taba + na - (n + 1), n + 1))\n        goto fail;\n    \n    for(i = 0; i < nq + 1; i++)\n        tabq[i] = tabt[i + 2 * (n + 1) - (nq + 1)];\n#ifdef DEBUG_DIVNORM_LARGE\n    mp_print_str(\"q\", tabq, nq + 1);\n#endif\n\n    bf_free(s, tabt);\n    bf_free(s, tabb_inv);\n    tabb_inv = NULL;\n    \n    /* R=A-B*Q */\n    tabt = bf_malloc(s, sizeof(limb_t) * (na + 1));\n    if (!tabt)\n        goto fail;\n    if (mp_mul(s, tabt, tabq, nq + 1, tabb, nb))\n        goto fail;\n    /* we add one more limb for the result */\n    mp_sub(taba, taba, tabt, nb + 1, 0);\n    bf_free(s, tabt);\n    /* the approximated quotient is smaller than than the exact one,\n       hence we may have to increment it */\n#ifdef DEBUG_DIVNORM_LARGE2\n    int cnt = 0;\n    static int cnt_max;\n#endif\n    for(;;) {\n        if (taba[nb] == 0 && mp_cmp(taba, tabb, nb) < 0)\n            break;\n        taba[nb] -= mp_sub(taba, taba, tabb, nb, 0);\n        mp_add_ui(tabq, 1, nq + 1);\n#ifdef DEBUG_DIVNORM_LARGE2\n        cnt++;\n#endif\n    }\n#ifdef DEBUG_DIVNORM_LARGE2\n    if (cnt > cnt_max) {\n        cnt_max = cnt;\n        printf(\"\\ncnt=%d nq=%d nb=%d\\n\", cnt_max, (int)nq, (int)nb);\n    }\n#endif\n    return 0;\n fail:\n    bf_free(s, tabb_inv);\n    bf_free(s, tabt);\n    return -1;\n}\n\nint bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n           bf_flags_t flags)\n{\n    int ret, r_sign;\n\n    if (a->len < b->len) {\n        const bf_t *tmp = a;\n        a = b;\n        b = tmp;\n    }\n    r_sign = a->sign ^ b->sign;\n    /* here b->len <= a->len */\n    if (b->len == 0) {\n        if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            ret = 0;\n        } else if (a->expn == BF_EXP_INF || b->expn == BF_EXP_INF) {\n            if ((a->expn == BF_EXP_INF && b->expn == BF_EXP_ZERO) ||\n                (a->expn == BF_EXP_ZERO && b->expn == BF_EXP_INF)) {\n                bf_set_nan(r);\n                ret = BF_ST_INVALID_OP;\n            } else {\n                bf_set_inf(r, r_sign);\n                ret = 0;\n            }\n        } else {\n            bf_set_zero(r, r_sign);\n            ret = 0;\n        }\n    } else {\n        bf_t tmp, *r1 = NULL;\n        limb_t a_len, b_len, precl;\n        limb_t *a_tab, *b_tab;\n            \n        a_len = a->len;\n        b_len = b->len;\n        \n        if ((flags & BF_RND_MASK) == BF_RNDF) {\n            /* faithful rounding does not require using the full inputs */\n            precl = (prec + 2 + LIMB_BITS - 1) / LIMB_BITS;\n            a_len = bf_min(a_len, precl);\n            b_len = bf_min(b_len, precl);\n        }\n        a_tab = a->tab + a->len - a_len;\n        b_tab = b->tab + b->len - b_len;\n        \n#ifdef USE_FFT_MUL\n        if (b_len >= FFT_MUL_THRESHOLD) {\n            int mul_flags = 0;\n            if (r == a)\n                mul_flags |= FFT_MUL_R_OVERLAP_A;\n            if (r == b)\n                mul_flags |= FFT_MUL_R_OVERLAP_B;\n            if (fft_mul(r->ctx, r, a_tab, a_len, b_tab, b_len, mul_flags))\n                goto fail;\n        } else\n#endif\n        {\n            if (r == a || r == b) {\n                bf_init(r->ctx, &tmp);\n                r1 = r;\n                r = &tmp;\n            }\n            if (bf_resize(r, a_len + b_len)) {\n            fail:\n                bf_set_nan(r);\n                ret = BF_ST_MEM_ERROR;\n                goto done;\n            }\n            mp_mul_basecase(r->tab, a_tab, a_len, b_tab, b_len);\n        }\n        r->sign = r_sign;\n        r->expn = a->expn + b->expn;\n        ret = bf_normalize_and_round(r, prec, flags);\n    done:\n        if (r == &tmp)\n            bf_move(r1, &tmp);\n    }\n    return ret;\n}\n\n/* multiply 'r' by 2^e */\nint bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags)\n{\n    slimb_t e_max;\n    if (r->len == 0)\n        return 0;\n    e_max = ((limb_t)1 << BF_EXT_EXP_BITS_MAX) - 1;\n    e = bf_max(e, -e_max);\n    e = bf_min(e, e_max);\n    r->expn += e;\n    return __bf_round(r, prec, flags, r->len, 0);\n}\n\n/* Return e such as a=m*2^e with m odd integer. return 0 if a is zero,\n   Infinite or Nan. */\nslimb_t bf_get_exp_min(const bf_t *a)\n{\n    slimb_t i;\n    limb_t v;\n    int k;\n    \n    for(i = 0; i < a->len; i++) {\n        v = a->tab[i];\n        if (v != 0) {\n            k = ctz(v);\n            return a->expn - (a->len - i) * LIMB_BITS + k;\n        }\n    }\n    return 0;\n}\n\n/* a and b must be finite numbers with a >= 0 and b > 0. 'q' is the\n   integer defined as floor(a/b) and r = a - q * b. */\nstatic void bf_tdivremu(bf_t *q, bf_t *r,\n                        const bf_t *a, const bf_t *b)\n{\n    if (bf_cmpu(a, b) < 0) {\n        bf_set_ui(q, 0);\n        bf_set(r, a);\n    } else {\n        bf_div(q, a, b, bf_max(a->expn - b->expn + 1, 2), BF_RNDZ);\n        bf_rint(q, BF_RNDZ);\n        bf_mul(r, q, b, BF_PREC_INF, BF_RNDZ);\n        bf_sub(r, a, r, BF_PREC_INF, BF_RNDZ);\n    }\n}\n\nstatic int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n                    bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    int ret, r_sign;\n    limb_t n, nb, precl;\n    \n    r_sign = a->sign ^ b->sign;\n    if (a->expn >= BF_EXP_INF || b->expn >= BF_EXP_INF) {\n        if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF && b->expn == BF_EXP_INF) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else if (a->expn == BF_EXP_INF) {\n            bf_set_inf(r, r_sign);\n            return 0;\n        } else {\n            bf_set_zero(r, r_sign);\n            return 0;\n        }\n    } else if (a->expn == BF_EXP_ZERO) {\n        if (b->expn == BF_EXP_ZERO) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_set_zero(r, r_sign);\n            return 0;\n        }\n    } else if (b->expn == BF_EXP_ZERO) {\n        bf_set_inf(r, r_sign);\n        return BF_ST_DIVIDE_ZERO;\n    }\n\n    /* number of limbs of the quotient (2 extra bits for rounding) */\n    precl = (prec + 2 + LIMB_BITS - 1) / LIMB_BITS;\n    nb = b->len;\n    n = bf_max(a->len, precl);\n    \n    {\n        limb_t *taba, na;\n        slimb_t d;\n        \n        na = n + nb;\n        taba = bf_malloc(s, (na + 1) * sizeof(limb_t));\n        if (!taba)\n            goto fail;\n        d = na - a->len;\n        memset(taba, 0, d * sizeof(limb_t));\n        memcpy(taba + d, a->tab, a->len * sizeof(limb_t));\n        if (bf_resize(r, n + 1))\n            goto fail1;\n        if (mp_divnorm(s, r->tab, taba, na, b->tab, nb)) {\n        fail1:\n            bf_free(s, taba);\n            goto fail;\n        }\n        /* see if non zero remainder */\n        if (mp_scan_nz(taba, nb))\n            r->tab[0] |= 1;\n        bf_free(r->ctx, taba);\n        r->expn = a->expn - b->expn + LIMB_BITS;\n        r->sign = r_sign;\n        ret = bf_normalize_and_round(r, prec, flags);\n    }\n    return ret;\n fail:\n    bf_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\n/* division and remainder. \n   \n   rnd_mode is the rounding mode for the quotient. The additional\n   rounding mode BF_RND_EUCLIDIAN is supported.\n\n   'q' is an integer. 'r' is rounded with prec and flags (prec can be\n   BF_PREC_INF).\n*/\nint bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,\n              limb_t prec, bf_flags_t flags, int rnd_mode)\n{\n    bf_t a1_s, *a1 = &a1_s;\n    bf_t b1_s, *b1 = &b1_s;\n    int q_sign, ret;\n    BOOL is_ceil, is_rndn;\n    \n    assert(q != a && q != b);\n    assert(r != a && r != b);\n    assert(q != r);\n    \n    if (a->len == 0 || b->len == 0) {\n        bf_set_zero(q, 0);\n        if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF || b->expn == BF_EXP_ZERO) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_set(r, a);\n            return bf_round(r, prec, flags);\n        }\n    }\n\n    q_sign = a->sign ^ b->sign;\n    is_rndn = (rnd_mode == BF_RNDN || rnd_mode == BF_RNDNA);\n    switch(rnd_mode) {\n    default:\n    case BF_RNDZ:\n    case BF_RNDN:\n    case BF_RNDNA:\n        is_ceil = FALSE;\n        break;\n    case BF_RNDD:\n        is_ceil = q_sign;\n        break;\n    case BF_RNDU:\n        is_ceil = q_sign ^ 1;\n        break;\n    case BF_RNDA:\n        is_ceil = TRUE;\n        break;\n    case BF_DIVREM_EUCLIDIAN:\n        is_ceil = a->sign;\n        break;\n    }\n\n    a1->expn = a->expn;\n    a1->tab = a->tab;\n    a1->len = a->len;\n    a1->sign = 0;\n    \n    b1->expn = b->expn;\n    b1->tab = b->tab;\n    b1->len = b->len;\n    b1->sign = 0;\n\n    /* XXX: could improve to avoid having a large 'q' */\n    bf_tdivremu(q, r, a1, b1);\n    if (bf_is_nan(q) || bf_is_nan(r))\n        goto fail;\n\n    if (r->len != 0) {\n        if (is_rndn) {\n            int res;\n            b1->expn--;\n            res = bf_cmpu(r, b1);\n            b1->expn++;\n            if (res > 0 ||\n                (res == 0 &&\n                 (rnd_mode == BF_RNDNA ||\n                  get_bit(q->tab, q->len, q->len * LIMB_BITS - q->expn)))) {\n                goto do_sub_r;\n            }\n        } else if (is_ceil) {\n        do_sub_r:\n            ret = bf_add_si(q, q, 1, BF_PREC_INF, BF_RNDZ);\n            ret |= bf_sub(r, r, b1, BF_PREC_INF, BF_RNDZ);\n            if (ret & BF_ST_MEM_ERROR)\n                goto fail;\n        }\n    }\n\n    r->sign ^= a->sign;\n    q->sign = q_sign;\n    return bf_round(r, prec, flags);\n fail:\n    bf_set_nan(q);\n    bf_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nint bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n           bf_flags_t flags, int rnd_mode)\n{\n    bf_t q_s, *q = &q_s;\n    int ret;\n    \n    bf_init(r->ctx, q);\n    ret = bf_divrem(q, r, a, b, prec, flags, rnd_mode);\n    bf_delete(q);\n    return ret;\n}\n\nstatic inline int bf_get_limb(slimb_t *pres, const bf_t *a, int flags)\n{\n#if LIMB_BITS == 32\n    return bf_get_int32(pres, a, flags);\n#else\n    return bf_get_int64(pres, a, flags);\n#endif\n}\n\nint bf_remquo(slimb_t *pq, bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n              bf_flags_t flags, int rnd_mode)\n{\n    bf_t q_s, *q = &q_s;\n    int ret;\n    \n    bf_init(r->ctx, q);\n    ret = bf_divrem(q, r, a, b, prec, flags, rnd_mode);\n    bf_get_limb(pq, q, BF_GET_INT_MOD);\n    bf_delete(q);\n    return ret;\n}\n\nstatic __maybe_unused inline limb_t mul_mod(limb_t a, limb_t b, limb_t m)\n{\n    dlimb_t t;\n    t = (dlimb_t)a * (dlimb_t)b;\n    return t % m;\n}\n\n#if defined(USE_MUL_CHECK)\nstatic limb_t mp_mod1(const limb_t *tab, limb_t n, limb_t m, limb_t r)\n{\n    slimb_t i;\n    dlimb_t t;\n\n    for(i = n - 1; i >= 0; i--) {\n        t = ((dlimb_t)r << LIMB_BITS) | tab[i];\n        r = t % m;\n    }\n    return r;\n}\n#endif\n\nstatic const uint16_t sqrt_table[192] = {\n128,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,150,151,152,153,154,155,155,156,157,158,159,160,160,161,162,163,163,164,165,166,167,167,168,169,170,170,171,172,173,173,174,175,176,176,177,178,178,179,180,181,181,182,183,183,184,185,185,186,187,187,188,189,189,190,191,192,192,193,193,194,195,195,196,197,197,198,199,199,200,201,201,202,203,203,204,204,205,206,206,207,208,208,209,209,210,211,211,212,212,213,214,214,215,215,216,217,217,218,218,219,219,220,221,221,222,222,223,224,224,225,225,226,226,227,227,228,229,229,230,230,231,231,232,232,233,234,234,235,235,236,236,237,237,238,238,239,240,240,241,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,\n};\n\n/* a >= 2^(LIMB_BITS - 2).  Return (s, r) with s=floor(sqrt(a)) and\n   r=a-s^2. 0 <= r <= 2 * s */\nstatic limb_t mp_sqrtrem1(limb_t *pr, limb_t a)\n{\n    limb_t s1, r1, s, r, q, u, num;\n    \n    /* use a table for the 16 -> 8 bit sqrt */\n    s1 = sqrt_table[(a >> (LIMB_BITS - 8)) - 64];\n    r1 = (a >> (LIMB_BITS - 16)) - s1 * s1;\n    if (r1 > 2 * s1) {\n        r1 -= 2 * s1 + 1;\n        s1++;\n    }\n    \n    /* one iteration to get a 32 -> 16 bit sqrt */\n    num = (r1 << 8) | ((a >> (LIMB_BITS - 32 + 8)) & 0xff);\n    q = num / (2 * s1); /* q <= 2^8 */\n    u = num % (2 * s1);\n    s = (s1 << 8) + q;\n    r = (u << 8) | ((a >> (LIMB_BITS - 32)) & 0xff);\n    r -= q * q;\n    if ((slimb_t)r < 0) {\n        s--;\n        r += 2 * s + 1;\n    }\n\n#if LIMB_BITS == 64\n    s1 = s;\n    r1 = r;\n    /* one more iteration for 64 -> 32 bit sqrt */\n    num = (r1 << 16) | ((a >> (LIMB_BITS - 64 + 16)) & 0xffff);\n    q = num / (2 * s1); /* q <= 2^16 */\n    u = num % (2 * s1);\n    s = (s1 << 16) + q;\n    r = (u << 16) | ((a >> (LIMB_BITS - 64)) & 0xffff);\n    r -= q * q;\n    if ((slimb_t)r < 0) {\n        s--;\n        r += 2 * s + 1;\n    }\n#endif\n    *pr = r;\n    return s;\n}\n\n/* return floor(sqrt(a)) */\nlimb_t bf_isqrt(limb_t a)\n{\n    limb_t s, r;\n    int k;\n\n    if (a == 0)\n        return 0;\n    k = clz(a) & ~1;\n    s = mp_sqrtrem1(&r, a << k);\n    s >>= (k >> 1);\n    return s;\n}\n\nstatic limb_t mp_sqrtrem2(limb_t *tabs, limb_t *taba)\n{\n    limb_t s1, r1, s, q, u, a0, a1;\n    dlimb_t r, num;\n    int l;\n\n    a0 = taba[0];\n    a1 = taba[1];\n    s1 = mp_sqrtrem1(&r1, a1);\n    l = LIMB_BITS / 2;\n    num = ((dlimb_t)r1 << l) | (a0 >> l);\n    q = num / (2 * s1);\n    u = num % (2 * s1);\n    s = (s1 << l) + q;\n    r = ((dlimb_t)u << l) | (a0 & (((limb_t)1 << l) - 1));\n    if (unlikely((q >> l) != 0))\n        r -= (dlimb_t)1 << LIMB_BITS; /* special case when q=2^l */\n    else\n        r -= q * q;\n    if ((slimb_t)(r >> LIMB_BITS) < 0) {\n        s--;\n        r += 2 * (dlimb_t)s + 1;\n    }\n    tabs[0] = s;\n    taba[0] = r;\n    return r >> LIMB_BITS;\n}\n\n//#define DEBUG_SQRTREM\n\n/* tmp_buf must contain (n / 2 + 1 limbs). *prh contains the highest\n   limb of the remainder. */\nstatic int mp_sqrtrem_rec(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n,\n                          limb_t *tmp_buf, limb_t *prh)\n{\n    limb_t l, h, rh, ql, qh, c, i;\n    \n    if (n == 1) {\n        *prh = mp_sqrtrem2(tabs, taba);\n        return 0;\n    }\n#ifdef DEBUG_SQRTREM\n    mp_print_str(\"a\", taba, 2 * n);\n#endif\n    l = n / 2;\n    h = n - l;\n    if (mp_sqrtrem_rec(s, tabs + l, taba + 2 * l, h, tmp_buf, &qh))\n        return -1;\n#ifdef DEBUG_SQRTREM\n    mp_print_str(\"s1\", tabs + l, h);\n    mp_print_str_h(\"r1\", taba + 2 * l, h, qh);\n    mp_print_str_h(\"r2\", taba + l, n, qh);\n#endif\n    \n    /* the remainder is in taba + 2 * l. Its high bit is in qh */\n    if (qh) {\n        mp_sub(taba + 2 * l, taba + 2 * l, tabs + l, h, 0);\n    }\n    /* instead of dividing by 2*s, divide by s (which is normalized)\n       and update q and r */\n    if (mp_divnorm(s, tmp_buf, taba + l, n, tabs + l, h))\n        return -1;\n    qh += tmp_buf[l];\n    for(i = 0; i < l; i++)\n        tabs[i] = tmp_buf[i];\n    ql = mp_shr(tabs, tabs, l, 1, qh & 1);\n    qh = qh >> 1; /* 0 or 1 */\n    if (ql)\n        rh = mp_add(taba + l, taba + l, tabs + l, h, 0);\n    else\n        rh = 0;\n#ifdef DEBUG_SQRTREM\n    mp_print_str_h(\"q\", tabs, l, qh);\n    mp_print_str_h(\"u\", taba + l, h, rh);\n#endif\n    \n    mp_add_ui(tabs + l, qh, h);\n#ifdef DEBUG_SQRTREM\n    mp_print_str_h(\"s2\", tabs, n, sh);\n#endif\n    \n    /* q = qh, tabs[l - 1 ... 0], r = taba[n - 1 ... l] */\n    /* subtract q^2. if qh = 1 then q = B^l, so we can take shortcuts */\n    if (qh) {\n        c = qh;\n    } else {\n        if (mp_mul(s, taba + n, tabs, l, tabs, l))\n            return -1;\n        c = mp_sub(taba, taba, taba + n, 2 * l, 0);\n    }\n    rh -= mp_sub_ui(taba + 2 * l, c, n - 2 * l);\n    if ((slimb_t)rh < 0) {\n        mp_sub_ui(tabs, 1, n);\n        rh += mp_add_mul1(taba, tabs, n, 2);\n        rh += mp_add_ui(taba, 1, n);\n    }\n    *prh = rh;\n    return 0;\n}\n\n/* 'taba' has 2*n limbs with n >= 1 and taba[2*n-1] >= 2 ^ (LIMB_BITS\n   - 2). Return (s, r) with s=floor(sqrt(a)) and r=a-s^2. 0 <= r <= 2\n   * s. tabs has n limbs. r is returned in the lower n limbs of\n   taba. Its r[n] is the returned value of the function. */\n/* Algorithm from the article \"Karatsuba Square Root\" by Paul Zimmermann and\n   inspirated from its GMP implementation */\nint mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n)\n{\n    limb_t tmp_buf1[8];\n    limb_t *tmp_buf;\n    mp_size_t n2;\n    int ret;\n    n2 = n / 2 + 1;\n    if (n2 <= countof(tmp_buf1)) {\n        tmp_buf = tmp_buf1;\n    } else {\n        tmp_buf = bf_malloc(s, sizeof(limb_t) * n2);\n        if (!tmp_buf)\n            return -1;\n    }\n    ret = mp_sqrtrem_rec(s, tabs, taba, n, tmp_buf, taba + n);\n    if (tmp_buf != tmp_buf1)\n        bf_free(s, tmp_buf);\n    return ret;\n}\n\n/* Integer square root with remainder. 'a' must be an integer. r =\n   floor(sqrt(a)) and rem = a - r^2.  BF_ST_INEXACT is set if the result\n   is inexact. 'rem' can be NULL if the remainder is not needed. */\nint bf_sqrtrem(bf_t *r, bf_t *rem1, const bf_t *a)\n{\n    int ret;\n    \n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n        } else if (a->expn == BF_EXP_INF && a->sign) {\n            goto invalid_op;\n        } else {\n            bf_set(r, a);\n        }\n        if (rem1)\n            bf_set_ui(rem1, 0);\n        ret = 0;\n    } else if (a->sign) {\n invalid_op:\n        bf_set_nan(r);\n        if (rem1)\n            bf_set_ui(rem1, 0);\n        ret = BF_ST_INVALID_OP;\n    } else {\n        bf_t rem_s, *rem;\n        \n        bf_sqrt(r, a, (a->expn + 1) / 2, BF_RNDZ);\n        bf_rint(r, BF_RNDZ);\n        /* see if the result is exact by computing the remainder */\n        if (rem1) {\n            rem = rem1;\n        } else {\n            rem = &rem_s;\n            bf_init(r->ctx, rem);\n        }\n        /* XXX: could avoid recomputing the remainder */\n        bf_mul(rem, r, r, BF_PREC_INF, BF_RNDZ);\n        bf_neg(rem);\n        bf_add(rem, rem, a, BF_PREC_INF, BF_RNDZ);\n        if (bf_is_nan(rem)) {\n            ret = BF_ST_MEM_ERROR;\n            goto done;\n        }\n        if (rem->len != 0) {\n            ret = BF_ST_INEXACT;\n        } else {\n            ret = 0;\n        }\n    done:\n        if (!rem1)\n            bf_delete(rem);\n    }\n    return ret;\n}\n\nint bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = a->ctx;\n    int ret;\n\n    assert(r != a);\n\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n        } else if (a->expn == BF_EXP_INF && a->sign) {\n            goto invalid_op;\n        } else {\n            bf_set(r, a);\n        }\n        ret = 0;\n    } else if (a->sign) {\n invalid_op:\n        bf_set_nan(r);\n        ret = BF_ST_INVALID_OP;\n    } else {\n        limb_t *a1;\n        slimb_t n, n1;\n        limb_t res;\n        \n        /* convert the mantissa to an integer with at least 2 *\n           prec + 4 bits */\n        n = (2 * (prec + 2) + 2 * LIMB_BITS - 1) / (2 * LIMB_BITS);\n        if (bf_resize(r, n))\n            goto fail;\n        a1 = bf_malloc(s, sizeof(limb_t) * 2 * n);\n        if (!a1)\n            goto fail;\n        n1 = bf_min(2 * n, a->len);\n        memset(a1, 0, (2 * n - n1) * sizeof(limb_t));\n        memcpy(a1 + 2 * n - n1, a->tab + a->len - n1, n1 * sizeof(limb_t));\n        if (a->expn & 1) {\n            res = mp_shr(a1, a1, 2 * n, 1, 0);\n        } else {\n            res = 0;\n        }\n        if (mp_sqrtrem(s, r->tab, a1, n)) {\n            bf_free(s, a1);\n            goto fail;\n        }\n        if (!res) {\n            res = mp_scan_nz(a1, n + 1);\n        }\n        bf_free(s, a1);\n        if (!res) {\n            res = mp_scan_nz(a->tab, a->len - n1);\n        }\n        if (res != 0)\n            r->tab[0] |= 1;\n        r->sign = 0;\n        r->expn = (a->expn + 1) >> 1;\n        ret = bf_round(r, prec, flags);\n    }\n    return ret;\n fail:\n    bf_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nstatic no_inline int bf_op2(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n                            bf_flags_t flags, bf_op2_func_t *func)\n{\n    bf_t tmp;\n    int ret;\n    \n    if (r == a || r == b) {\n        bf_init(r->ctx, &tmp);\n        ret = func(&tmp, a, b, prec, flags);\n        bf_move(r, &tmp);\n    } else {\n        ret = func(r, a, b, prec, flags);\n    }\n    return ret;\n}\n\nint bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n            bf_flags_t flags)\n{\n    return bf_op2(r, a, b, prec, flags, __bf_add);\n}\n\nint bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n            bf_flags_t flags)\n{\n    return bf_op2(r, a, b, prec, flags, __bf_sub);\n}\n\nint bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n           bf_flags_t flags)\n{\n    return bf_op2(r, a, b, prec, flags, __bf_div);\n}\n\nint bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec,\n               bf_flags_t flags)\n{\n    bf_t b;\n    int ret;\n    bf_init(r->ctx, &b);\n    ret = bf_set_ui(&b, b1);\n    ret |= bf_mul(r, a, &b, prec, flags);\n    bf_delete(&b);\n    return ret;\n}\n\nint bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,\n               bf_flags_t flags)\n{\n    bf_t b;\n    int ret;\n    bf_init(r->ctx, &b);\n    ret = bf_set_si(&b, b1);\n    ret |= bf_mul(r, a, &b, prec, flags);\n    bf_delete(&b);\n    return ret;\n}\n\nint bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,\n              bf_flags_t flags)\n{\n    bf_t b;\n    int ret;\n    \n    bf_init(r->ctx, &b);\n    ret = bf_set_si(&b, b1);\n    ret |= bf_add(r, a, &b, prec, flags);\n    bf_delete(&b);\n    return ret;\n}\n\nstatic int bf_pow_ui(bf_t *r, const bf_t *a, limb_t b, limb_t prec,\n                     bf_flags_t flags)\n{\n    int ret, n_bits, i;\n    \n    assert(r != a);\n    if (b == 0)\n        return bf_set_ui(r, 1);\n    ret = bf_set(r, a);\n    n_bits = LIMB_BITS - clz(b);\n    for(i = n_bits - 2; i >= 0; i--) {\n        ret |= bf_mul(r, r, r, prec, flags);\n        if ((b >> i) & 1)\n            ret |= bf_mul(r, r, a, prec, flags);\n    }\n    return ret;\n}\n\nstatic int bf_pow_ui_ui(bf_t *r, limb_t a1, limb_t b,\n                        limb_t prec, bf_flags_t flags)\n{\n    bf_t a;\n    int ret;\n    \n    if (a1 == 10 && b <= LIMB_DIGITS) {\n        /* use precomputed powers. We do not round at this point\n           because we expect the caller to do it */\n        ret = bf_set_ui(r, mp_pow_dec[b]);\n    } else {\n        bf_init(r->ctx, &a);\n        ret = bf_set_ui(&a, a1);\n        ret |= bf_pow_ui(r, &a, b, prec, flags);\n        bf_delete(&a);\n    }\n    return ret;\n}\n\n/* convert to integer (infinite precision) */\nint bf_rint(bf_t *r, int rnd_mode)\n{\n    return bf_round(r, 0, rnd_mode | BF_FLAG_RADPNT_PREC);\n}\n\n/* logical operations */\n#define BF_LOGIC_OR  0\n#define BF_LOGIC_XOR 1\n#define BF_LOGIC_AND 2\n\nstatic inline limb_t bf_logic_op1(limb_t a, limb_t b, int op)\n{\n    switch(op) {\n    case BF_LOGIC_OR:\n        return a | b;\n    case BF_LOGIC_XOR:\n        return a ^ b;\n    default:\n    case BF_LOGIC_AND:\n        return a & b;\n    }\n}\n\nstatic int bf_logic_op(bf_t *r, const bf_t *a1, const bf_t *b1, int op)\n{\n    bf_t b1_s, a1_s, *a, *b;\n    limb_t a_sign, b_sign, r_sign;\n    slimb_t l, i, a_bit_offset, b_bit_offset;\n    limb_t v1, v2, v1_mask, v2_mask, r_mask;\n    int ret;\n    \n    assert(r != a1 && r != b1);\n\n    if (a1->expn <= 0)\n        a_sign = 0; /* minus zero is considered as positive */\n    else\n        a_sign = a1->sign;\n\n    if (b1->expn <= 0)\n        b_sign = 0; /* minus zero is considered as positive */\n    else\n        b_sign = b1->sign;\n    \n    if (a_sign) {\n        a = &a1_s;\n        bf_init(r->ctx, a);\n        if (bf_add_si(a, a1, 1, BF_PREC_INF, BF_RNDZ)) {\n            b = NULL;\n            goto fail;\n        }\n    } else {\n        a = (bf_t *)a1;\n    }\n\n    if (b_sign) {\n        b = &b1_s;\n        bf_init(r->ctx, b);\n        if (bf_add_si(b, b1, 1, BF_PREC_INF, BF_RNDZ))\n            goto fail;\n    } else {\n        b = (bf_t *)b1;\n    }\n    \n    r_sign = bf_logic_op1(a_sign, b_sign, op);\n    if (op == BF_LOGIC_AND && r_sign == 0) {\n        /* no need to compute extra zeros for and */\n        if (a_sign == 0 && b_sign == 0)\n            l = bf_min(a->expn, b->expn);\n        else if (a_sign == 0)\n            l = a->expn;\n        else\n            l = b->expn;\n    } else {\n        l = bf_max(a->expn, b->expn);\n    }\n    /* Note: a or b can be zero */\n    l = (bf_max(l, 1) + LIMB_BITS - 1) / LIMB_BITS;\n    if (bf_resize(r, l))\n        goto fail;\n    a_bit_offset = a->len * LIMB_BITS - a->expn;\n    b_bit_offset = b->len * LIMB_BITS - b->expn;\n    v1_mask = -a_sign;\n    v2_mask = -b_sign;\n    r_mask = -r_sign;\n    for(i = 0; i < l; i++) {\n        v1 = get_bits(a->tab, a->len, a_bit_offset + i * LIMB_BITS) ^ v1_mask;\n        v2 = get_bits(b->tab, b->len, b_bit_offset + i * LIMB_BITS) ^ v2_mask;\n        r->tab[i] = bf_logic_op1(v1, v2, op) ^ r_mask;\n    }\n    r->expn = l * LIMB_BITS;\n    r->sign = r_sign;\n    bf_normalize_and_round(r, BF_PREC_INF, BF_RNDZ); /* cannot fail */\n    if (r_sign) {\n        if (bf_add_si(r, r, -1, BF_PREC_INF, BF_RNDZ))\n            goto fail;\n    }\n    ret = 0;\n done:\n    if (a == &a1_s)\n        bf_delete(a);\n    if (b == &b1_s)\n        bf_delete(b);\n    return ret;\n fail:\n    bf_set_nan(r);\n    ret = BF_ST_MEM_ERROR;\n    goto done;\n}\n\n/* 'a' and 'b' must be integers. Return 0 or BF_ST_MEM_ERROR. */\nint bf_logic_or(bf_t *r, const bf_t *a, const bf_t *b)\n{\n    return bf_logic_op(r, a, b, BF_LOGIC_OR);\n}\n\n/* 'a' and 'b' must be integers. Return 0 or BF_ST_MEM_ERROR. */\nint bf_logic_xor(bf_t *r, const bf_t *a, const bf_t *b)\n{\n    return bf_logic_op(r, a, b, BF_LOGIC_XOR);\n}\n\n/* 'a' and 'b' must be integers. Return 0 or BF_ST_MEM_ERROR. */\nint bf_logic_and(bf_t *r, const bf_t *a, const bf_t *b)\n{\n    return bf_logic_op(r, a, b, BF_LOGIC_AND);\n}\n\n/* conversion between fixed size types */\n\ntypedef union {\n    double d;\n    uint64_t u;\n} Float64Union;\n\nint bf_get_float64(const bf_t *a, double *pres, bf_rnd_t rnd_mode)\n{\n    Float64Union u;\n    int e, ret;\n    uint64_t m;\n    \n    ret = 0;\n    if (a->expn == BF_EXP_NAN) {\n        u.u = 0x7ff8000000000000; /* quiet nan */\n    } else {\n        bf_t b_s, *b = &b_s;\n        \n        bf_init(a->ctx, b);\n        bf_set(b, a);\n        if (bf_is_finite(b)) {\n            ret = bf_round(b, 53, rnd_mode | BF_FLAG_SUBNORMAL | bf_set_exp_bits(11));\n        }\n        if (b->expn == BF_EXP_INF) {\n            e = (1 << 11) - 1;\n            m = 0;\n        } else if (b->expn == BF_EXP_ZERO) {\n            e = 0;\n            m = 0;\n        } else {\n            e = b->expn + 1023 - 1;\n#if LIMB_BITS == 32\n            if (b->len == 2) {\n                m = ((uint64_t)b->tab[1] << 32) | b->tab[0];\n            } else {\n                m = ((uint64_t)b->tab[0] << 32);\n            }\n#else\n            m = b->tab[0];\n#endif\n            if (e <= 0) {\n                /* subnormal */\n                m = m >> (12 - e);\n                e = 0;\n            } else {\n                m = (m << 1) >> 12;\n            }\n        }\n        u.u = m | ((uint64_t)e << 52) | ((uint64_t)b->sign << 63);\n        bf_delete(b);\n    }\n    *pres = u.d;\n    return ret;\n}\n\nint bf_set_float64(bf_t *a, double d)\n{\n    Float64Union u;\n    uint64_t m;\n    int shift, e, sgn;\n    \n    u.d = d;\n    sgn = u.u >> 63;\n    e = (u.u >> 52) & ((1 << 11) - 1);\n    m = u.u & (((uint64_t)1 << 52) - 1);\n    if (e == ((1 << 11) - 1)) {\n        if (m != 0) {\n            bf_set_nan(a);\n        } else {\n            bf_set_inf(a, sgn);\n        }\n    } else if (e == 0) {\n        if (m == 0) {\n            bf_set_zero(a, sgn);\n        } else {\n            /* subnormal number */\n            m <<= 12;\n            shift = clz64(m);\n            m <<= shift;\n            e = -shift;\n            goto norm;\n        }\n    } else {\n        m = (m << 11) | ((uint64_t)1 << 63);\n    norm:\n        a->expn = e - 1023 + 1;\n#if LIMB_BITS == 32\n        if (bf_resize(a, 2))\n            goto fail;\n        a->tab[0] = m;\n        a->tab[1] = m >> 32;\n#else\n        if (bf_resize(a, 1))\n            goto fail;\n        a->tab[0] = m;\n#endif\n        a->sign = sgn;\n    }\n    return 0;\nfail:\n    bf_set_nan(a);\n    return BF_ST_MEM_ERROR;\n}\n\n/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there\n   is an overflow and 0 otherwise. */\nint bf_get_int32(int *pres, const bf_t *a, int flags)\n{\n    uint32_t v;\n    int ret;\n    if (a->expn >= BF_EXP_INF) {\n        ret = BF_ST_INVALID_OP;\n        if (flags & BF_GET_INT_MOD) {\n            v = 0;\n        } else if (a->expn == BF_EXP_INF) {\n            v = (uint32_t)INT32_MAX + a->sign;\n        } else {\n            v = INT32_MAX;\n        }\n    } else if (a->expn <= 0) {\n        v = 0;\n        ret = 0;\n    } else if (a->expn <= 31) {\n        v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);\n        if (a->sign)\n            v = -v;\n        ret = 0;\n    } else if (!(flags & BF_GET_INT_MOD)) {\n        ret = BF_ST_INVALID_OP;\n        if (a->sign) {\n            v = (uint32_t)INT32_MAX + 1;\n            if (a->expn == 32 && \n                (a->tab[a->len - 1] >> (LIMB_BITS - 32)) == v) {\n                ret = 0;\n            }\n        } else {\n            v = INT32_MAX;\n        }\n    } else {\n        v = get_bits(a->tab, a->len, a->len * LIMB_BITS - a->expn); \n        if (a->sign)\n            v = -v;\n        ret = 0;\n    }\n    *pres = v;\n    return ret;\n}\n\n/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there\n   is an overflow and 0 otherwise. */\nint bf_get_int64(int64_t *pres, const bf_t *a, int flags)\n{\n    uint64_t v;\n    int ret;\n    if (a->expn >= BF_EXP_INF) {\n        ret = BF_ST_INVALID_OP;\n        if (flags & BF_GET_INT_MOD) {\n            v = 0;\n        } else if (a->expn == BF_EXP_INF) {\n            v = (uint64_t)INT64_MAX + a->sign;\n        } else {\n            v = INT64_MAX;\n        }\n    } else if (a->expn <= 0) {\n        v = 0;\n        ret = 0;\n    } else if (a->expn <= 63) {\n#if LIMB_BITS == 32\n        if (a->expn <= 32)\n            v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);\n        else\n            v = (((uint64_t)a->tab[a->len - 1] << 32) |\n                 get_limbz(a, a->len - 2)) >> (64 - a->expn);\n#else\n        v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);\n#endif\n        if (a->sign)\n            v = -v;\n        ret = 0;\n    } else if (!(flags & BF_GET_INT_MOD)) {\n        ret = BF_ST_INVALID_OP;\n        if (a->sign) {\n            uint64_t v1;\n            v = (uint64_t)INT64_MAX + 1;\n            if (a->expn == 64) {\n                v1 = a->tab[a->len - 1];\n#if LIMB_BITS == 32\n                v1 = (v1 << 32) | get_limbz(a, a->len - 2);\n#endif\n                if (v1 == v)\n                    ret = 0;\n            }\n        } else {\n            v = INT64_MAX;\n        }\n    } else {\n        slimb_t bit_pos = a->len * LIMB_BITS - a->expn;\n        v = get_bits(a->tab, a->len, bit_pos); \n#if LIMB_BITS == 32\n        v |= (uint64_t)get_bits(a->tab, a->len, bit_pos + 32) << 32;\n#endif\n        if (a->sign)\n            v = -v;\n        ret = 0;\n    }\n    *pres = v;\n    return ret;\n}\n\n/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there\n   is an overflow and 0 otherwise. */\nint bf_get_uint64(uint64_t *pres, const bf_t *a)\n{\n    uint64_t v;\n    int ret;\n    if (a->expn == BF_EXP_NAN) {\n        goto overflow;\n    } else if (a->expn <= 0) {\n        v = 0;\n        ret = 0;\n    } else if (a->sign) {\n        v = 0;\n        ret = BF_ST_INVALID_OP;\n    } else if (a->expn <= 64) {\n#if LIMB_BITS == 32\n        if (a->expn <= 32)\n            v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);\n        else\n            v = (((uint64_t)a->tab[a->len - 1] << 32) |\n                 get_limbz(a, a->len - 2)) >> (64 - a->expn);\n#else\n        v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);\n#endif\n        ret = 0;\n    } else {\n    overflow:\n        v = UINT64_MAX;\n        ret = BF_ST_INVALID_OP;\n    }\n    *pres = v;\n    return ret;\n}\n\n/* base conversion from radix */\n\nstatic const uint8_t digits_per_limb_table[BF_RADIX_MAX - 1] = {\n#if LIMB_BITS == 32\n32,20,16,13,12,11,10,10, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,\n#else\n64,40,32,27,24,22,21,20,19,18,17,17,16,16,16,15,15,15,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,\n#endif\n};\n\nstatic limb_t get_limb_radix(int radix)\n{\n    int i, k;\n    limb_t radixl;\n    \n    k = digits_per_limb_table[radix - 2];\n    radixl = radix;\n    for(i = 1; i < k; i++)\n        radixl *= radix;\n    return radixl;\n}\n\n/* return != 0 if error */\nstatic int bf_integer_from_radix_rec(bf_t *r, const limb_t *tab,\n                                     limb_t n, int level, limb_t n0,\n                                     limb_t radix, bf_t *pow_tab)\n{\n    int ret;\n    if (n == 1) {\n        ret = bf_set_ui(r, tab[0]);\n    } else {\n        bf_t T_s, *T = &T_s, *B;\n        limb_t n1, n2;\n        \n        n2 = (((n0 * 2) >> (level + 1)) + 1) / 2;\n        n1 = n - n2;\n        //        printf(\"level=%d n0=%ld n1=%ld n2=%ld\\n\", level, n0, n1, n2);\n        B = &pow_tab[level];\n        if (B->len == 0) {\n            ret = bf_pow_ui_ui(B, radix, n2, BF_PREC_INF, BF_RNDZ);\n            if (ret)\n                return ret;\n        }\n        ret = bf_integer_from_radix_rec(r, tab + n2, n1, level + 1, n0,\n                                        radix, pow_tab);\n        if (ret)\n            return ret;\n        ret = bf_mul(r, r, B, BF_PREC_INF, BF_RNDZ);\n        if (ret)\n            return ret;\n        bf_init(r->ctx, T);\n        ret = bf_integer_from_radix_rec(T, tab, n2, level + 1, n0,\n                                        radix, pow_tab);\n        if (!ret)\n            ret = bf_add(r, r, T, BF_PREC_INF, BF_RNDZ);\n        bf_delete(T);\n    }\n    return ret;\n    //    bf_print_str(\"  r=\", r);\n}\n\n/* return 0 if OK != 0 if memory error */\nstatic int bf_integer_from_radix(bf_t *r, const limb_t *tab,\n                                 limb_t n, limb_t radix)\n{\n    bf_context_t *s = r->ctx;\n    int pow_tab_len, i, ret;\n    limb_t radixl;\n    bf_t *pow_tab;\n    \n    radixl = get_limb_radix(radix);\n    pow_tab_len = ceil_log2(n) + 2; /* XXX: check */\n    pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len);\n    if (!pow_tab)\n        return -1;\n    for(i = 0; i < pow_tab_len; i++)\n        bf_init(r->ctx, &pow_tab[i]);\n    ret = bf_integer_from_radix_rec(r, tab, n, 0, n, radixl, pow_tab);\n    for(i = 0; i < pow_tab_len; i++) {\n        bf_delete(&pow_tab[i]);\n    }\n    bf_free(s, pow_tab);\n    return ret;\n}\n\n/* compute and round T * radix^expn. */\nint bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix,\n                     slimb_t expn, limb_t prec, bf_flags_t flags)\n{\n    int ret, expn_sign, overflow;\n    slimb_t e, extra_bits, prec1, ziv_extra_bits;\n    bf_t B_s, *B = &B_s;\n\n    if (T->len == 0) {\n        return bf_set(r, T);\n    } else if (expn == 0) {\n        ret = bf_set(r, T);\n        ret |= bf_round(r, prec, flags);\n        return ret;\n    }\n\n    e = expn;\n    expn_sign = 0;\n    if (e < 0) {\n        e = -e;\n        expn_sign = 1;\n    }\n    bf_init(r->ctx, B);\n    if (prec == BF_PREC_INF) {\n        /* infinite precision: only used if the result is known to be exact */\n        ret = bf_pow_ui_ui(B, radix, e, BF_PREC_INF, BF_RNDN);\n        if (expn_sign) {\n            ret |= bf_div(r, T, B, T->len * LIMB_BITS, BF_RNDN);\n        } else {\n            ret |= bf_mul(r, T, B, BF_PREC_INF, BF_RNDN);\n        }\n    } else {\n        ziv_extra_bits = 16;\n        for(;;) {\n            prec1 = prec + ziv_extra_bits;\n            /* XXX: correct overflow/underflow handling */\n            /* XXX: rigorous error analysis needed */\n            extra_bits = ceil_log2(e) * 2 + 1;\n            ret = bf_pow_ui_ui(B, radix, e, prec1 + extra_bits, BF_RNDN | BF_FLAG_EXT_EXP);\n            overflow = !bf_is_finite(B);\n            /* XXX: if bf_pow_ui_ui returns an exact result, can stop\n               after the next operation */\n            if (expn_sign)\n                ret |= bf_div(r, T, B, prec1 + extra_bits, BF_RNDN | BF_FLAG_EXT_EXP);\n            else\n                ret |= bf_mul(r, T, B, prec1 + extra_bits, BF_RNDN | BF_FLAG_EXT_EXP);\n            if (ret & BF_ST_MEM_ERROR)\n                break;\n            if ((ret & BF_ST_INEXACT) &&\n                !bf_can_round(r, prec, flags & BF_RND_MASK, prec1) &&\n                !overflow) {\n                /* and more precision and retry */\n                ziv_extra_bits = ziv_extra_bits  + (ziv_extra_bits / 2);\n            } else {\n                /* XXX: need to use __bf_round() to pass the inexact\n                   flag for the subnormal case */\n                ret = bf_round(r, prec, flags) | (ret & BF_ST_INEXACT);\n                break;\n            }\n        }\n    }\n    bf_delete(B);\n    return ret;\n}\n\nstatic inline int to_digit(int c)\n{\n    if (c >= '0' && c <= '9')\n        return c - '0';\n    else if (c >= 'A' && c <= 'Z')\n        return c - 'A' + 10;\n    else if (c >= 'a' && c <= 'z')\n        return c - 'a' + 10;\n    else\n        return 36;\n}\n\n/* add a limb at 'pos' and decrement pos. new space is created if\n   needed. Return 0 if OK, -1 if memory error */\nstatic int bf_add_limb(bf_t *a, slimb_t *ppos, limb_t v)\n{\n    slimb_t pos;\n    pos = *ppos;\n    if (unlikely(pos < 0)) {\n        limb_t new_size, d, *new_tab;\n        new_size = bf_max(a->len + 1, a->len * 3 / 2);\n        new_tab = bf_realloc(a->ctx, a->tab, sizeof(limb_t) * new_size);\n        if (!new_tab)\n            return -1;\n        a->tab = new_tab;\n        d = new_size - a->len;\n        memmove(a->tab + d, a->tab, a->len * sizeof(limb_t));\n        a->len = new_size;\n        pos += d;\n    }\n    a->tab[pos--] = v;\n    *ppos = pos;\n    return 0;\n}\n\nstatic int bf_tolower(int c)\n{\n    if (c >= 'A' && c <= 'Z')\n        c = c - 'A' + 'a';\n    return c;\n}\n\nstatic int strcasestart(const char *str, const char *val, const char **ptr)\n{\n    const char *p, *q;\n    p = str;\n    q = val;\n    while (*q != '\\0') {\n        if (bf_tolower(*p) != *q)\n            return 0;\n        p++;\n        q++;\n    }\n    if (ptr)\n        *ptr = p;\n    return 1;\n}\n\nstatic int bf_atof_internal(bf_t *r, slimb_t *pexponent,\n                            const char *str, const char **pnext, int radix,\n                            limb_t prec, bf_flags_t flags, BOOL is_dec)\n{\n    const char *p, *p_start;\n    int is_neg, radix_bits, exp_is_neg, ret, digits_per_limb, shift;\n    limb_t cur_limb;\n    slimb_t pos, expn, int_len, digit_count;\n    BOOL has_decpt, is_bin_exp;\n    bf_t a_s, *a;\n    \n    *pexponent = 0;\n    p = str;\n    if (!(flags & BF_ATOF_NO_NAN_INF) && radix <= 16 &&\n        strcasestart(p, \"nan\", &p)) {\n        bf_set_nan(r);\n        ret = 0;\n        goto done;\n    }\n    is_neg = 0;\n    \n    if (p[0] == '+') {\n        p++;\n        p_start = p;\n    } else if (p[0] == '-') {\n        is_neg = 1;\n        p++;\n        p_start = p;\n    } else {\n        p_start = p;\n    }\n    if (p[0] == '0') {\n        if ((p[1] == 'x' || p[1] == 'X') &&\n            (radix == 0 || radix == 16) &&\n            !(flags & BF_ATOF_NO_HEX)) {\n            radix = 16;\n            p += 2;\n        } else if ((p[1] == 'o' || p[1] == 'O') &&\n                   radix == 0 && (flags & BF_ATOF_BIN_OCT)) {\n            p += 2;\n            radix = 8;\n        } else if ((p[1] == 'b' || p[1] == 'B') &&\n                   radix == 0 && (flags & BF_ATOF_BIN_OCT)) {\n            p += 2;\n            radix = 2;\n        } else {\n            goto no_prefix;\n        }\n        /* there must be a digit after the prefix */\n        if (to_digit((uint8_t)*p) >= radix) {\n            bf_set_nan(r);\n            ret = 0;\n            goto done;\n        }\n    no_prefix: ;\n    } else {\n        if (!(flags & BF_ATOF_NO_NAN_INF) && radix <= 16 &&\n            strcasestart(p, \"inf\", &p)) {\n            bf_set_inf(r, is_neg);\n            ret = 0;\n            goto done;\n        }\n    }\n    \n    if (radix == 0)\n        radix = 10;\n    if (is_dec) {\n        assert(radix == 10);\n        radix_bits = 0;\n        a = r;\n    } else if ((radix & (radix - 1)) != 0) {\n        radix_bits = 0; /* base is not a power of two */\n        a = &a_s;\n        bf_init(r->ctx, a);\n    } else {\n        radix_bits = ceil_log2(radix);\n        a = r;\n    }\n\n    /* skip leading zeros */\n    /* XXX: could also skip zeros after the decimal point */\n    while (*p == '0')\n        p++;\n\n    if (radix_bits) {\n        shift = digits_per_limb = LIMB_BITS;\n    } else {\n        radix_bits = 0;\n        shift = digits_per_limb = digits_per_limb_table[radix - 2];\n    }\n    cur_limb = 0;\n    bf_resize(a, 1);\n    pos = 0;\n    has_decpt = FALSE;\n    int_len = digit_count = 0;\n    for(;;) {\n        limb_t c;\n        if (*p == '.' && (p > p_start || to_digit(p[1]) < radix)) {\n            if (has_decpt)\n                break;\n            has_decpt = TRUE;\n            int_len = digit_count;\n            p++;\n        }\n        c = to_digit(*p);\n        if (c >= radix)\n            break;\n        digit_count++;\n        p++;\n        if (radix_bits) {\n            shift -= radix_bits;\n            if (shift <= 0) {\n                cur_limb |= c >> (-shift);\n                if (bf_add_limb(a, &pos, cur_limb))\n                    goto mem_error;\n                if (shift < 0)\n                    cur_limb = c << (LIMB_BITS + shift);\n                else\n                    cur_limb = 0;\n                shift += LIMB_BITS;\n            } else {\n                cur_limb |= c << shift;\n            }\n        } else {\n            cur_limb = cur_limb * radix + c;\n            shift--;\n            if (shift == 0) {\n                if (bf_add_limb(a, &pos, cur_limb))\n                    goto mem_error;\n                shift = digits_per_limb;\n                cur_limb = 0;\n            }\n        }\n    }\n    if (!has_decpt)\n        int_len = digit_count;\n\n    /* add the last limb and pad with zeros */\n    if (shift != digits_per_limb) {\n        if (radix_bits == 0) {\n            while (shift != 0) {\n                cur_limb *= radix;\n                shift--;\n            }\n        }\n        if (bf_add_limb(a, &pos, cur_limb)) {\n        mem_error:\n            ret = BF_ST_MEM_ERROR;\n            if (!radix_bits)\n                bf_delete(a);\n            bf_set_nan(r);\n            goto done;\n        }\n    }\n            \n    /* reset the next limbs to zero (we prefer to reallocate in the\n       renormalization) */\n    memset(a->tab, 0, (pos + 1) * sizeof(limb_t));\n\n    if (p == p_start) {\n        ret = 0;\n        if (!radix_bits)\n            bf_delete(a);\n        bf_set_nan(r);\n        goto done;\n    }\n\n    /* parse the exponent, if any */\n    expn = 0;\n    is_bin_exp = FALSE;\n    if (((radix == 10 && (*p == 'e' || *p == 'E')) ||\n         (radix != 10 && (*p == '@' ||\n                          (radix_bits && (*p == 'p' || *p == 'P'))))) &&\n        p > p_start) {\n        is_bin_exp = (*p == 'p' || *p == 'P');\n        p++;\n        exp_is_neg = 0;\n        if (*p == '+') {\n            p++;\n        } else if (*p == '-') {\n            exp_is_neg = 1;\n            p++;\n        }\n        for(;;) {\n            int c;\n            c = to_digit(*p);\n            if (c >= 10)\n                break;\n            if (unlikely(expn > ((BF_RAW_EXP_MAX - 2 - 9) / 10))) {\n                /* exponent overflow */\n                if (exp_is_neg) {\n                    bf_set_zero(r, is_neg);\n                    ret = BF_ST_UNDERFLOW | BF_ST_INEXACT;\n                } else {\n                    bf_set_inf(r, is_neg);\n                    ret = BF_ST_OVERFLOW | BF_ST_INEXACT;\n                }\n                goto done;\n            }\n            p++;\n            expn = expn * 10 + c;\n        }\n        if (exp_is_neg)\n            expn = -expn;\n    }\n    if (is_dec) {\n        a->expn = expn + int_len;\n        a->sign = is_neg;\n        ret = bfdec_normalize_and_round((bfdec_t *)a, prec, flags);\n    } else if (radix_bits) {\n        /* XXX: may overflow */\n        if (!is_bin_exp)\n            expn *= radix_bits; \n        a->expn = expn + (int_len * radix_bits);\n        a->sign = is_neg;\n        ret = bf_normalize_and_round(a, prec, flags);\n    } else {\n        limb_t l;\n        pos++;\n        l = a->len - pos; /* number of limbs */\n        if (l == 0) {\n            bf_set_zero(r, is_neg);\n            ret = 0;\n        } else {\n            bf_t T_s, *T = &T_s;\n\n            expn -= l * digits_per_limb - int_len;\n            bf_init(r->ctx, T);\n            if (bf_integer_from_radix(T, a->tab + pos, l, radix)) {\n                bf_set_nan(r);\n                ret = BF_ST_MEM_ERROR;\n            } else {\n                T->sign = is_neg;\n                if (flags & BF_ATOF_EXPONENT) {\n                    /* return the exponent */\n                    *pexponent = expn;\n                    ret = bf_set(r, T);\n                } else {\n                    ret = bf_mul_pow_radix(r, T, radix, expn, prec, flags);\n                }\n            }\n            bf_delete(T);\n        }\n        bf_delete(a);\n    }\n done:\n    if (pnext)\n        *pnext = p;\n    return ret;\n}\n\n/* \n   Return (status, n, exp). 'status' is the floating point status. 'n'\n   is the parsed number. \n\n   If (flags & BF_ATOF_EXPONENT) and if the radix is not a power of\n   two, the parsed number is equal to r *\n   (*pexponent)^radix. Otherwise *pexponent = 0.\n*/\nint bf_atof2(bf_t *r, slimb_t *pexponent,\n             const char *str, const char **pnext, int radix,\n             limb_t prec, bf_flags_t flags)\n{\n    return bf_atof_internal(r, pexponent, str, pnext, radix, prec, flags,\n                            FALSE);\n}\n\nint bf_atof(bf_t *r, const char *str, const char **pnext, int radix,\n            limb_t prec, bf_flags_t flags)\n{\n    slimb_t dummy_exp;\n    return bf_atof_internal(r, &dummy_exp, str, pnext, radix, prec, flags, FALSE);\n}\n\n/* base conversion to radix */\n\n#if LIMB_BITS == 64\n#define RADIXL_10 UINT64_C(10000000000000000000)\n#else\n#define RADIXL_10 UINT64_C(1000000000)\n#endif\n\nstatic const uint32_t inv_log2_radix[BF_RADIX_MAX - 1][LIMB_BITS / 32 + 1] = {\n#if LIMB_BITS == 32\n{ 0x80000000, 0x00000000,},\n{ 0x50c24e60, 0xd4d4f4a7,},\n{ 0x40000000, 0x00000000,},\n{ 0x372068d2, 0x0a1ee5ca,},\n{ 0x3184648d, 0xb8153e7a,},\n{ 0x2d983275, 0x9d5369c4,},\n{ 0x2aaaaaaa, 0xaaaaaaab,},\n{ 0x28612730, 0x6a6a7a54,},\n{ 0x268826a1, 0x3ef3fde6,},\n{ 0x25001383, 0xbac8a744,},\n{ 0x23b46706, 0x82c0c709,},\n{ 0x229729f1, 0xb2c83ded,},\n{ 0x219e7ffd, 0xa5ad572b,},\n{ 0x20c33b88, 0xda7c29ab,},\n{ 0x20000000, 0x00000000,},\n{ 0x1f50b57e, 0xac5884b3,},\n{ 0x1eb22cc6, 0x8aa6e26f,},\n{ 0x1e21e118, 0x0c5daab2,},\n{ 0x1d9dcd21, 0x439834e4,},\n{ 0x1d244c78, 0x367a0d65,},\n{ 0x1cb40589, 0xac173e0c,},\n{ 0x1c4bd95b, 0xa8d72b0d,},\n{ 0x1bead768, 0x98f8ce4c,},\n{ 0x1b903469, 0x050f72e5,},\n{ 0x1b3b433f, 0x2eb06f15,},\n{ 0x1aeb6f75, 0x9c46fc38,},\n{ 0x1aa038eb, 0x0e3bfd17,},\n{ 0x1a593062, 0xb38d8c56,},\n{ 0x1a15f4c3, 0x2b95a2e6,},\n{ 0x19d630dc, 0xcc7ddef9,},\n{ 0x19999999, 0x9999999a,},\n{ 0x195fec80, 0x8a609431,},\n{ 0x1928ee7b, 0x0b4f22f9,},\n{ 0x18f46acf, 0x8c06e318,},\n{ 0x18c23246, 0xdc0a9f3d,},\n#else\n{ 0x80000000, 0x00000000, 0x00000000,},\n{ 0x50c24e60, 0xd4d4f4a7, 0x021f57bc,},\n{ 0x40000000, 0x00000000, 0x00000000,},\n{ 0x372068d2, 0x0a1ee5ca, 0x19ea911b,},\n{ 0x3184648d, 0xb8153e7a, 0x7fc2d2e1,},\n{ 0x2d983275, 0x9d5369c4, 0x4dec1661,},\n{ 0x2aaaaaaa, 0xaaaaaaaa, 0xaaaaaaab,},\n{ 0x28612730, 0x6a6a7a53, 0x810fabde,},\n{ 0x268826a1, 0x3ef3fde6, 0x23e2566b,},\n{ 0x25001383, 0xbac8a744, 0x385a3349,},\n{ 0x23b46706, 0x82c0c709, 0x3f891718,},\n{ 0x229729f1, 0xb2c83ded, 0x15fba800,},\n{ 0x219e7ffd, 0xa5ad572a, 0xe169744b,},\n{ 0x20c33b88, 0xda7c29aa, 0x9bddee52,},\n{ 0x20000000, 0x00000000, 0x00000000,},\n{ 0x1f50b57e, 0xac5884b3, 0x70e28eee,},\n{ 0x1eb22cc6, 0x8aa6e26f, 0x06d1a2a2,},\n{ 0x1e21e118, 0x0c5daab1, 0x81b4f4bf,},\n{ 0x1d9dcd21, 0x439834e3, 0x81667575,},\n{ 0x1d244c78, 0x367a0d64, 0xc8204d6d,},\n{ 0x1cb40589, 0xac173e0c, 0x3b7b16ba,},\n{ 0x1c4bd95b, 0xa8d72b0d, 0x5879f25a,},\n{ 0x1bead768, 0x98f8ce4c, 0x66cc2858,},\n{ 0x1b903469, 0x050f72e5, 0x0cf5488e,},\n{ 0x1b3b433f, 0x2eb06f14, 0x8c89719c,},\n{ 0x1aeb6f75, 0x9c46fc37, 0xab5fc7e9,},\n{ 0x1aa038eb, 0x0e3bfd17, 0x1bd62080,},\n{ 0x1a593062, 0xb38d8c56, 0x7998ab45,},\n{ 0x1a15f4c3, 0x2b95a2e6, 0x46aed6a0,},\n{ 0x19d630dc, 0xcc7ddef9, 0x5aadd61b,},\n{ 0x19999999, 0x99999999, 0x9999999a,},\n{ 0x195fec80, 0x8a609430, 0xe1106014,},\n{ 0x1928ee7b, 0x0b4f22f9, 0x5f69791d,},\n{ 0x18f46acf, 0x8c06e318, 0x4d2aeb2c,},\n{ 0x18c23246, 0xdc0a9f3d, 0x3fe16970,},\n#endif\n};\n\nstatic const limb_t log2_radix[BF_RADIX_MAX - 1] = {\n#if LIMB_BITS == 32\n0x20000000,\n0x32b80347,\n0x40000000,\n0x4a4d3c26,\n0x52b80347,\n0x59d5d9fd,\n0x60000000,\n0x6570068e,\n0x6a4d3c26,\n0x6eb3a9f0,\n0x72b80347,\n0x766a008e,\n0x79d5d9fd,\n0x7d053f6d,\n0x80000000,\n0x82cc7edf,\n0x8570068e,\n0x87ef05ae,\n0x8a4d3c26,\n0x8c8ddd45,\n0x8eb3a9f0,\n0x90c10501,\n0x92b80347,\n0x949a784c,\n0x966a008e,\n0x982809d6,\n0x99d5d9fd,\n0x9b74948f,\n0x9d053f6d,\n0x9e88c6b3,\n0xa0000000,\n0xa16bad37,\n0xa2cc7edf,\n0xa4231623,\n0xa570068e,\n#else\n0x2000000000000000,\n0x32b803473f7ad0f4,\n0x4000000000000000,\n0x4a4d3c25e68dc57f,\n0x52b803473f7ad0f4,\n0x59d5d9fd5010b366,\n0x6000000000000000,\n0x6570068e7ef5a1e8,\n0x6a4d3c25e68dc57f,\n0x6eb3a9f01975077f,\n0x72b803473f7ad0f4,\n0x766a008e4788cbcd,\n0x79d5d9fd5010b366,\n0x7d053f6d26089673,\n0x8000000000000000,\n0x82cc7edf592262d0,\n0x8570068e7ef5a1e8,\n0x87ef05ae409a0289,\n0x8a4d3c25e68dc57f,\n0x8c8ddd448f8b845a,\n0x8eb3a9f01975077f,\n0x90c10500d63aa659,\n0x92b803473f7ad0f4,\n0x949a784bcd1b8afe,\n0x966a008e4788cbcd,\n0x982809d5be7072dc,\n0x99d5d9fd5010b366,\n0x9b74948f5532da4b,\n0x9d053f6d26089673,\n0x9e88c6b3626a72aa,\n0xa000000000000000,\n0xa16bad3758efd873,\n0xa2cc7edf592262d0,\n0xa4231623369e78e6,\n0xa570068e7ef5a1e8,\n#endif\n};\n\n/* compute floor(a*b) or ceil(a*b) with b = log2(radix) or\n   b=1/log2(radix). For is_inv = 0, strict accuracy is not guaranteed\n   when radix is not a power of two. */\nslimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,\n                          int is_ceil1)\n{\n    int is_neg;\n    limb_t a;\n    BOOL is_ceil;\n\n    is_ceil = is_ceil1;\n    a = a1;\n    if (a1 < 0) {\n        a = -a;\n        is_neg = 1;\n    } else {\n        is_neg = 0;\n    }\n    is_ceil ^= is_neg;\n    if ((radix & (radix - 1)) == 0) {\n        int radix_bits;\n        /* radix is a power of two */\n        radix_bits = ceil_log2(radix);\n        if (is_inv) {\n            if (is_ceil)\n                a += radix_bits - 1;\n            a = a / radix_bits;\n        } else {\n            a = a * radix_bits;\n        }\n    } else {\n        const uint32_t *tab;\n        limb_t b0, b1;\n        dlimb_t t;\n        \n        if (is_inv) {\n            tab = inv_log2_radix[radix - 2];\n#if LIMB_BITS == 32\n            b1 = tab[0];\n            b0 = tab[1];\n#else\n            b1 = ((limb_t)tab[0] << 32) | tab[1];\n            b0 = (limb_t)tab[2] << 32;\n#endif\n            t = (dlimb_t)b0 * (dlimb_t)a;\n            t = (dlimb_t)b1 * (dlimb_t)a + (t >> LIMB_BITS);\n            a = t >> (LIMB_BITS - 1);\n        } else {\n            b0 = log2_radix[radix - 2];\n            t = (dlimb_t)b0 * (dlimb_t)a;\n            a = t >> (LIMB_BITS - 3);\n        }\n        /* a = floor(result) and 'result' cannot be an integer */\n        a += is_ceil;\n    }\n    if (is_neg)\n        a = -a;\n    return a;\n}\n\n/* 'n' is the number of output limbs */\nstatic int bf_integer_to_radix_rec(bf_t *pow_tab,\n                                   limb_t *out, const bf_t *a, limb_t n,\n                                   int level, limb_t n0, limb_t radixl,\n                                   unsigned int radixl_bits)\n{\n    limb_t n1, n2, q_prec;\n    int ret;\n    \n    assert(n >= 1);\n    if (n == 1) {\n        out[0] = get_bits(a->tab, a->len, a->len * LIMB_BITS - a->expn);\n    } else if (n == 2) {\n        dlimb_t t;\n        slimb_t pos;\n        pos = a->len * LIMB_BITS - a->expn;\n        t = ((dlimb_t)get_bits(a->tab, a->len, pos + LIMB_BITS) << LIMB_BITS) |\n            get_bits(a->tab, a->len, pos);\n        if (likely(radixl == RADIXL_10)) {\n            /* use division by a constant when possible */\n            out[0] = t % RADIXL_10;\n            out[1] = t / RADIXL_10;\n        } else {\n            out[0] = t % radixl;\n            out[1] = t / radixl;\n        }\n    } else {\n        bf_t Q, R, *B, *B_inv;\n        int q_add;\n        bf_init(a->ctx, &Q);\n        bf_init(a->ctx, &R);\n        n2 = (((n0 * 2) >> (level + 1)) + 1) / 2;\n        n1 = n - n2;\n        B = &pow_tab[2 * level];\n        B_inv = &pow_tab[2 * level + 1];\n        ret = 0;\n        if (B->len == 0) {\n            /* compute BASE^n2 */\n            ret |= bf_pow_ui_ui(B, radixl, n2, BF_PREC_INF, BF_RNDZ);\n            /* we use enough bits for the maximum possible 'n1' value,\n               i.e. n2 + 1 */\n            ret |= bf_set_ui(&R, 1);\n            ret |= bf_div(B_inv, &R, B, (n2 + 1) * radixl_bits + 2, BF_RNDN);\n        }\n        //        printf(\"%d: n1=% \" PRId64 \" n2=%\" PRId64 \"\\n\", level, n1, n2);\n        q_prec = n1 * radixl_bits;\n        ret |= bf_mul(&Q, a, B_inv, q_prec, BF_RNDN);\n        ret |= bf_rint(&Q, BF_RNDZ);\n        \n        ret |= bf_mul(&R, &Q, B, BF_PREC_INF, BF_RNDZ);\n        ret |= bf_sub(&R, a, &R, BF_PREC_INF, BF_RNDZ);\n\n        if (ret & BF_ST_MEM_ERROR)\n            goto fail;\n        /* adjust if necessary */\n        q_add = 0;\n        while (R.sign && R.len != 0) {\n            if (bf_add(&R, &R, B, BF_PREC_INF, BF_RNDZ))\n                goto fail;\n            q_add--;\n        }\n        while (bf_cmpu(&R, B) >= 0) {\n            if (bf_sub(&R, &R, B, BF_PREC_INF, BF_RNDZ))\n                goto fail;\n            q_add++;\n        }\n        if (q_add != 0) {\n            if (bf_add_si(&Q, &Q, q_add, BF_PREC_INF, BF_RNDZ))\n                goto fail;\n        }\n        if (bf_integer_to_radix_rec(pow_tab, out + n2, &Q, n1, level + 1, n0,\n                                    radixl, radixl_bits))\n            goto fail;\n        if (bf_integer_to_radix_rec(pow_tab, out, &R, n2, level + 1, n0,\n                                    radixl, radixl_bits)) {\n        fail:\n            bf_delete(&Q);\n            bf_delete(&R);\n            return -1;\n        }\n        bf_delete(&Q);\n        bf_delete(&R);\n    }\n    return 0;\n}\n\n/* return 0 if OK != 0 if memory error */\nstatic int bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl)\n{\n    bf_context_t *s = r->ctx;\n    limb_t r_len;\n    bf_t *pow_tab;\n    int i, pow_tab_len, ret;\n    \n    r_len = r->len;\n    pow_tab_len = (ceil_log2(r_len) + 2) * 2; /* XXX: check */\n    pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len);\n    if (!pow_tab)\n        return -1;\n    for(i = 0; i < pow_tab_len; i++)\n        bf_init(r->ctx, &pow_tab[i]);\n\n    ret = bf_integer_to_radix_rec(pow_tab, r->tab, a, r_len, 0, r_len, radixl,\n                                  ceil_log2(radixl));\n\n    for(i = 0; i < pow_tab_len; i++) {\n        bf_delete(&pow_tab[i]);\n    }\n    bf_free(s, pow_tab);\n    return ret;\n}\n\n/* a must be >= 0. 'P' is the wanted number of digits in radix\n   'radix'. 'r' is the mantissa represented as an integer. *pE\n   contains the exponent. Return != 0 if memory error. */\nstatic int bf_convert_to_radix(bf_t *r, slimb_t *pE,\n                               const bf_t *a, int radix,\n                               limb_t P, bf_rnd_t rnd_mode,\n                               BOOL is_fixed_exponent)\n{\n    slimb_t E, e, prec, extra_bits, ziv_extra_bits, prec0;\n    bf_t B_s, *B = &B_s;\n    int e_sign, ret, res;\n    \n    if (a->len == 0) {\n        /* zero case */\n        *pE = 0;\n        return bf_set(r, a);\n    }\n\n    if (is_fixed_exponent) {\n        E = *pE;\n    } else {\n        /* compute the new exponent */\n        E = 1 + bf_mul_log2_radix(a->expn - 1, radix, TRUE, FALSE);\n    }\n    //    bf_print_str(\"a\", a);\n    //    printf(\"E=%ld P=%ld radix=%d\\n\", E, P, radix);\n    \n    for(;;) {\n        e = P - E;\n        e_sign = 0;\n        if (e < 0) {\n            e = -e;\n            e_sign = 1;\n        }\n        /* Note: precision for log2(radix) is not critical here */\n        prec0 = bf_mul_log2_radix(P, radix, FALSE, TRUE);\n        ziv_extra_bits = 16;\n        for(;;) {\n            prec = prec0 + ziv_extra_bits;\n            /* XXX: rigorous error analysis needed */\n            extra_bits = ceil_log2(e) * 2 + 1;\n            ret = bf_pow_ui_ui(r, radix, e, prec + extra_bits,\n                               BF_RNDN | BF_FLAG_EXT_EXP);\n            if (!e_sign)\n                ret |= bf_mul(r, r, a, prec + extra_bits,\n                              BF_RNDN | BF_FLAG_EXT_EXP);\n            else\n                ret |= bf_div(r, a, r, prec + extra_bits,\n                              BF_RNDN | BF_FLAG_EXT_EXP);\n            if (ret & BF_ST_MEM_ERROR)\n                return BF_ST_MEM_ERROR;\n            /* if the result is not exact, check that it can be safely\n               rounded to an integer */\n            if ((ret & BF_ST_INEXACT) &&\n                !bf_can_round(r, r->expn, rnd_mode, prec)) {\n                /* and more precision and retry */\n                ziv_extra_bits = ziv_extra_bits  + (ziv_extra_bits / 2);\n                continue;\n            } else {\n                ret = bf_rint(r, rnd_mode);\n                if (ret & BF_ST_MEM_ERROR)\n                    return BF_ST_MEM_ERROR;\n                break;\n            }\n        }\n        if (is_fixed_exponent)\n            break;\n        /* check that the result is < B^P */\n        /* XXX: do a fast approximate test first ? */\n        bf_init(r->ctx, B);\n        ret = bf_pow_ui_ui(B, radix, P, BF_PREC_INF, BF_RNDZ);\n        if (ret) {\n            bf_delete(B);\n            return ret;\n        }\n        res = bf_cmpu(r, B);\n        bf_delete(B);\n        if (res < 0)\n            break;\n        /* try a larger exponent */\n        E++;\n    }\n    *pE = E;\n    return 0;\n}\n\nstatic void limb_to_a(char *buf, limb_t n, unsigned int radix, int len)\n{\n    int digit, i;\n\n    if (radix == 10) {\n        /* specific case with constant divisor */\n        for(i = len - 1; i >= 0; i--) {\n            digit = (limb_t)n % 10;\n            n = (limb_t)n / 10;\n            buf[i] = digit + '0';\n        }\n    } else {\n        for(i = len - 1; i >= 0; i--) {\n            digit = (limb_t)n % radix;\n            n = (limb_t)n / radix;\n            if (digit < 10)\n                digit += '0';\n            else\n                digit += 'a' - 10;\n            buf[i] = digit;\n        }\n    }\n}\n\n/* for power of 2 radixes */\nstatic void limb_to_a2(char *buf, limb_t n, unsigned int radix_bits, int len)\n{\n    int digit, i;\n    unsigned int mask;\n\n    mask = (1 << radix_bits) - 1;\n    for(i = len - 1; i >= 0; i--) {\n        digit = n & mask;\n        n >>= radix_bits;\n        if (digit < 10)\n            digit += '0';\n        else\n            digit += 'a' - 10;\n        buf[i] = digit;\n    }\n}\n\n/* 'a' must be an integer if the is_dec = FALSE or if the radix is not\n   a power of two. A dot is added before the 'dot_pos' digit. dot_pos\n   = n_digits does not display the dot. 0 <= dot_pos <=\n   n_digits. n_digits >= 1. */\nstatic void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n_digits,\n                          limb_t dot_pos, BOOL is_dec)\n{\n    limb_t i, v, l;\n    slimb_t pos, pos_incr;\n    int digits_per_limb, buf_pos, radix_bits, first_buf_pos;\n    char buf[65];\n    bf_t a_s, *a;\n\n    if (is_dec) {\n        digits_per_limb = LIMB_DIGITS;\n        a = (bf_t *)a1;\n        radix_bits = 0;\n        pos = a->len;\n        pos_incr = 1;\n        first_buf_pos = 0;\n    } else if ((radix & (radix - 1)) == 0) {\n        a = (bf_t *)a1;\n        radix_bits = ceil_log2(radix);\n        digits_per_limb = LIMB_BITS / radix_bits;\n        pos_incr = digits_per_limb * radix_bits;\n        /* digits are aligned relative to the radix point */\n        pos = a->len * LIMB_BITS + smod(-a->expn, radix_bits);\n        first_buf_pos = 0;\n    } else {\n        limb_t n, radixl;\n\n        digits_per_limb = digits_per_limb_table[radix - 2];\n        radixl = get_limb_radix(radix);\n        a = &a_s;\n        bf_init(a1->ctx, a);\n        n = (n_digits + digits_per_limb - 1) / digits_per_limb;\n        if (bf_resize(a, n)) {\n            dbuf_set_error(s);\n            goto done;\n        }\n        if (bf_integer_to_radix(a, a1, radixl)) {\n            dbuf_set_error(s);\n            goto done;\n        }\n        radix_bits = 0;\n        pos = n;\n        pos_incr = 1;\n        first_buf_pos = pos * digits_per_limb - n_digits;\n    }\n    buf_pos = digits_per_limb;\n    i = 0;\n    while (i < n_digits) {\n        if (buf_pos == digits_per_limb) {\n            pos -= pos_incr;\n            if (radix_bits == 0) {\n                v = get_limbz(a, pos);\n                limb_to_a(buf, v, radix, digits_per_limb);\n            } else {\n                v = get_bits(a->tab, a->len, pos);\n                limb_to_a2(buf, v, radix_bits, digits_per_limb);\n            }\n            buf_pos = first_buf_pos;\n            first_buf_pos = 0;\n        }\n        if (i < dot_pos) {\n            l = dot_pos;\n        } else {\n            if (i == dot_pos)\n                dbuf_putc(s, '.');\n            l = n_digits;\n        }\n        l = bf_min(digits_per_limb - buf_pos, l - i);\n        dbuf_put(s, (uint8_t *)(buf + buf_pos), l);\n        buf_pos += l;\n        i += l;\n    }\n done:\n    if (a != a1)\n        bf_delete(a);\n}\n\nstatic void *bf_dbuf_realloc(void *opaque, void *ptr, size_t size)\n{\n    bf_context_t *s = opaque;\n    return bf_realloc(s, ptr, size);\n}\n\n/* return the length in bytes. A trailing '\\0' is added */\nstatic char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,\n                              limb_t prec, bf_flags_t flags, BOOL is_dec)\n{\n    bf_context_t *ctx = a2->ctx;\n    DynBuf s_s, *s = &s_s;\n    int radix_bits;\n    \n    //    bf_print_str(\"ftoa\", a2);\n    //    printf(\"radix=%d\\n\", radix);\n    dbuf_init2(s, ctx, bf_dbuf_realloc);\n    if (a2->expn == BF_EXP_NAN) {\n        dbuf_putstr(s, \"NaN\");\n    } else {\n        if (a2->sign)\n            dbuf_putc(s, '-');\n        if (a2->expn == BF_EXP_INF) {\n            if (flags & BF_FTOA_JS_QUIRKS)\n                dbuf_putstr(s, \"Infinity\");\n            else\n                dbuf_putstr(s, \"Inf\");\n        } else {\n            int fmt, ret;\n            slimb_t n_digits, n, i, n_max, n1;\n            bf_t a1_s, *a1 = &a1_s;\n\n            if ((radix & (radix - 1)) != 0)\n                radix_bits = 0;\n            else\n                radix_bits = ceil_log2(radix);\n\n            fmt = flags & BF_FTOA_FORMAT_MASK;\n            bf_init(ctx, a1);\n            if (fmt == BF_FTOA_FORMAT_FRAC) {\n                if (is_dec || radix_bits != 0) {\n                    if (bf_set(a1, a2))\n                        goto fail1;\n#ifdef USE_BF_DEC\n                    if (is_dec) {\n                        if (bfdec_round((bfdec_t *)a1, prec, (flags & BF_RND_MASK) | BF_FLAG_RADPNT_PREC) & BF_ST_MEM_ERROR)\n                            goto fail1;\n                        n = a1->expn;\n                    } else\n#endif\n                    {\n                        if (bf_round(a1, prec * radix_bits, (flags & BF_RND_MASK) | BF_FLAG_RADPNT_PREC) & BF_ST_MEM_ERROR)\n                            goto fail1;\n                        n = ceil_div(a1->expn, radix_bits);\n                    }\n                    if (flags & BF_FTOA_ADD_PREFIX) {\n                        if (radix == 16)\n                            dbuf_putstr(s, \"0x\");\n                        else if (radix == 8)\n                            dbuf_putstr(s, \"0o\");\n                        else if (radix == 2)\n                            dbuf_putstr(s, \"0b\");\n                    }\n                    if (a1->expn == BF_EXP_ZERO) {\n                        dbuf_putstr(s, \"0\");\n                        if (prec > 0) {\n                            dbuf_putstr(s, \".\");\n                            for(i = 0; i < prec; i++) {\n                                dbuf_putc(s, '0');\n                            }\n                        }\n                    } else {\n                        n_digits = prec + n;\n                        if (n <= 0) {\n                            /* 0.x */\n                            dbuf_putstr(s, \"0.\");\n                            for(i = 0; i < -n; i++) {\n                                dbuf_putc(s, '0');\n                            }\n                            if (n_digits > 0) {\n                                output_digits(s, a1, radix, n_digits, n_digits, is_dec);\n                            }\n                        } else {\n                            output_digits(s, a1, radix, n_digits, n, is_dec);\n                        }\n                    }\n                } else {\n                    size_t pos, start;\n                    bf_t a_s, *a = &a_s;\n\n                    /* make a positive number */\n                    a->tab = a2->tab;\n                    a->len = a2->len;\n                    a->expn = a2->expn;\n                    a->sign = 0;\n                    \n                    /* one more digit for the rounding */\n                    n = 1 + bf_mul_log2_radix(bf_max(a->expn, 0), radix, TRUE, TRUE);\n                    n_digits = n + prec;\n                    n1 = n;\n                    if (bf_convert_to_radix(a1, &n1, a, radix, n_digits,\n                                            flags & BF_RND_MASK, TRUE))\n                        goto fail1;\n                    start = s->size;\n                    output_digits(s, a1, radix, n_digits, n, is_dec);\n                    /* remove leading zeros because we allocated one more digit */\n                    pos = start;\n                    while ((pos + 1) < s->size && s->buf[pos] == '0' &&\n                           s->buf[pos + 1] != '.')\n                        pos++;\n                    if (pos > start) {\n                        memmove(s->buf + start, s->buf + pos, s->size - pos);\n                        s->size -= (pos - start);\n                    }\n                }\n            } else {\n#ifdef USE_BF_DEC\n                if (is_dec) {\n                    if (bf_set(a1, a2))\n                        goto fail1;\n                    if (fmt == BF_FTOA_FORMAT_FIXED) {\n                        n_digits = prec;\n                        n_max = n_digits;\n                        if (bfdec_round((bfdec_t *)a1, prec, (flags & BF_RND_MASK)) & BF_ST_MEM_ERROR)\n                            goto fail1;\n                    } else {\n                        /* prec is ignored */\n                        prec = n_digits = a1->len * LIMB_DIGITS;\n                        /* remove the trailing zero digits */\n                        while (n_digits > 1 &&\n                               get_digit(a1->tab, a1->len, prec - n_digits) == 0) {\n                            n_digits--;\n                        }\n                        n_max = n_digits + 4;\n                    }\n                    n = a1->expn;\n                } else\n#endif\n                if (radix_bits != 0) {\n                    if (bf_set(a1, a2))\n                        goto fail1;\n                    if (fmt == BF_FTOA_FORMAT_FIXED) {\n                        slimb_t prec_bits;\n                        n_digits = prec;\n                        n_max = n_digits;\n                        /* align to the radix point */\n                        prec_bits = prec * radix_bits -\n                            smod(-a1->expn, radix_bits);\n                        if (bf_round(a1, prec_bits,\n                                     (flags & BF_RND_MASK)) & BF_ST_MEM_ERROR)\n                            goto fail1;\n                    } else {\n                        limb_t digit_mask;\n                        slimb_t pos;\n                        /* position of the digit before the most\n                           significant digit in bits */\n                        pos = a1->len * LIMB_BITS +\n                            smod(-a1->expn, radix_bits);\n                        n_digits = ceil_div(pos, radix_bits);\n                        /* remove the trailing zero digits */\n                        digit_mask = ((limb_t)1 << radix_bits) - 1;\n                        while (n_digits > 1 &&\n                               (get_bits(a1->tab, a1->len, pos - n_digits * radix_bits) & digit_mask) == 0) {\n                            n_digits--;\n                        }\n                        n_max = n_digits + 4;\n                    }\n                    n = ceil_div(a1->expn, radix_bits);\n                } else {\n                    bf_t a_s, *a = &a_s;\n                    \n                    /* make a positive number */\n                    a->tab = a2->tab;\n                    a->len = a2->len;\n                    a->expn = a2->expn;\n                    a->sign = 0;\n                    \n                    if (fmt == BF_FTOA_FORMAT_FIXED) {\n                        n_digits = prec;\n                        n_max = n_digits;\n                    } else {\n                        slimb_t n_digits_max, n_digits_min;\n                        \n                        assert(prec != BF_PREC_INF);\n                        n_digits = 1 + bf_mul_log2_radix(prec, radix, TRUE, TRUE);\n                        /* max number of digits for non exponential\n                           notation. The rational is to have the same rule\n                           as JS i.e. n_max = 21 for 64 bit float in base 10. */\n                        n_max = n_digits + 4;\n                        if (fmt == BF_FTOA_FORMAT_FREE_MIN) {\n                            bf_t b_s, *b = &b_s;\n                            \n                            /* find the minimum number of digits by\n                               dichotomy. */\n                            /* XXX: inefficient */\n                            n_digits_max = n_digits;\n                            n_digits_min = 1;\n                            bf_init(ctx, b);\n                            while (n_digits_min < n_digits_max) {\n                                n_digits = (n_digits_min + n_digits_max) / 2;\n                                if (bf_convert_to_radix(a1, &n, a, radix, n_digits,\n                                                        flags & BF_RND_MASK, FALSE)) {\n                                    bf_delete(b);\n                                    goto fail1;\n                                }\n                                /* convert back to a number and compare */\n                                ret = bf_mul_pow_radix(b, a1, radix, n - n_digits,\n                                                       prec,\n                                                       (flags & ~BF_RND_MASK) |\n                                                       BF_RNDN);\n                                if (ret & BF_ST_MEM_ERROR) {\n                                    bf_delete(b);\n                                    goto fail1;\n                                }\n                                if (bf_cmpu(b, a) == 0) {\n                                    n_digits_max = n_digits;\n                                } else {\n                                    n_digits_min = n_digits + 1;\n                                }\n                            }\n                            bf_delete(b);\n                            n_digits = n_digits_max;\n                        }\n                    }\n                    if (bf_convert_to_radix(a1, &n, a, radix, n_digits,\n                                            flags & BF_RND_MASK, FALSE)) {\n                    fail1:\n                        bf_delete(a1);\n                        goto fail;\n                    }\n                }\n                if (a1->expn == BF_EXP_ZERO &&\n                    fmt != BF_FTOA_FORMAT_FIXED &&\n                    !(flags & BF_FTOA_FORCE_EXP)) {\n                    /* just output zero */\n                    dbuf_putstr(s, \"0\");\n                } else {\n                    if (flags & BF_FTOA_ADD_PREFIX) {\n                        if (radix == 16)\n                            dbuf_putstr(s, \"0x\");\n                        else if (radix == 8)\n                            dbuf_putstr(s, \"0o\");\n                        else if (radix == 2)\n                            dbuf_putstr(s, \"0b\");\n                    }\n                    if (a1->expn == BF_EXP_ZERO)\n                        n = 1;\n                    if ((flags & BF_FTOA_FORCE_EXP) ||\n                        n <= -6 || n > n_max) {\n                        const char *fmt;\n                        /* exponential notation */\n                        output_digits(s, a1, radix, n_digits, 1, is_dec);\n                        if (radix_bits != 0 && radix <= 16) {\n                            if (flags & BF_FTOA_JS_QUIRKS)\n                                fmt = \"p%+\" PRId_LIMB;\n                            else\n                                fmt = \"p%\" PRId_LIMB;\n                            dbuf_printf(s, fmt, (n - 1) * radix_bits);\n                        } else {\n                            if (flags & BF_FTOA_JS_QUIRKS)\n                                fmt = \"%c%+\" PRId_LIMB;\n                            else\n                                fmt = \"%c%\" PRId_LIMB;\n                            dbuf_printf(s, fmt,\n                                        radix <= 10 ? 'e' : '@', n - 1);\n                        }\n                    } else if (n <= 0) {\n                        /* 0.x */\n                        dbuf_putstr(s, \"0.\");\n                        for(i = 0; i < -n; i++) {\n                            dbuf_putc(s, '0');\n                        }\n                        output_digits(s, a1, radix, n_digits, n_digits, is_dec);\n                    } else {\n                        if (n_digits <= n) {\n                            /* no dot */\n                            output_digits(s, a1, radix, n_digits, n_digits, is_dec);\n                            for(i = 0; i < (n - n_digits); i++)\n                                dbuf_putc(s, '0');\n                        } else {\n                            output_digits(s, a1, radix, n_digits, n, is_dec);\n                        }\n                    }\n                }\n            }\n            bf_delete(a1);\n        }\n    }\n    dbuf_putc(s, '\\0');\n    if (dbuf_error(s))\n        goto fail;\n    if (plen)\n        *plen = s->size - 1;\n    return (char *)s->buf;\n fail:\n    bf_free(ctx, s->buf);\n    if (plen)\n        *plen = 0;\n    return NULL;\n}\n\nchar *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,\n              bf_flags_t flags)\n{\n    return bf_ftoa_internal(plen, a, radix, prec, flags, FALSE);\n}\n\n/***************************************************************/\n/* transcendental functions */\n\n/* Note: the algorithm is from MPFR */\nstatic void bf_const_log2_rec(bf_t *T, bf_t *P, bf_t *Q, limb_t n1,\n                              limb_t n2, BOOL need_P)\n{\n    bf_context_t *s = T->ctx;\n    if ((n2 - n1) == 1) {\n        if (n1 == 0) {\n            bf_set_ui(P, 3);\n        } else {\n            bf_set_ui(P, n1);\n            P->sign = 1;\n        }\n        bf_set_ui(Q, 2 * n1 + 1);\n        Q->expn += 2;\n        bf_set(T, P);\n    } else {\n        limb_t m;\n        bf_t T1_s, *T1 = &T1_s;\n        bf_t P1_s, *P1 = &P1_s;\n        bf_t Q1_s, *Q1 = &Q1_s;\n        \n        m = n1 + ((n2 - n1) >> 1);\n        bf_const_log2_rec(T, P, Q, n1, m, TRUE);\n        bf_init(s, T1);\n        bf_init(s, P1);\n        bf_init(s, Q1);\n        bf_const_log2_rec(T1, P1, Q1, m, n2, need_P);\n        bf_mul(T, T, Q1, BF_PREC_INF, BF_RNDZ);\n        bf_mul(T1, T1, P, BF_PREC_INF, BF_RNDZ);\n        bf_add(T, T, T1, BF_PREC_INF, BF_RNDZ);\n        if (need_P)\n            bf_mul(P, P, P1, BF_PREC_INF, BF_RNDZ);\n        bf_mul(Q, Q, Q1, BF_PREC_INF, BF_RNDZ);\n        bf_delete(T1);\n        bf_delete(P1);\n        bf_delete(Q1);\n    }\n}\n\n/* compute log(2) with faithful rounding at precision 'prec' */\nstatic void bf_const_log2_internal(bf_t *T, limb_t prec)\n{\n    limb_t w, N;\n    bf_t P_s, *P = &P_s;\n    bf_t Q_s, *Q = &Q_s;\n\n    w = prec + 15;\n    N = w / 3 + 1;\n    bf_init(T->ctx, P);\n    bf_init(T->ctx, Q);\n    bf_const_log2_rec(T, P, Q, 0, N, FALSE);\n    bf_div(T, T, Q, prec, BF_RNDN);\n    bf_delete(P);\n    bf_delete(Q);\n}\n\n/* PI constant */\n\n#define CHUD_A 13591409\n#define CHUD_B 545140134\n#define CHUD_C 640320\n#define CHUD_BITS_PER_TERM 47\n\nstatic void chud_bs(bf_t *P, bf_t *Q, bf_t *G, int64_t a, int64_t b, int need_g,\n                    limb_t prec)\n{\n    bf_context_t *s = P->ctx;\n    int64_t c;\n\n    if (a == (b - 1)) {\n        bf_t T0, T1;\n        \n        bf_init(s, &T0);\n        bf_init(s, &T1);\n        bf_set_ui(G, 2 * b - 1);\n        bf_mul_ui(G, G, 6 * b - 1, prec, BF_RNDN);\n        bf_mul_ui(G, G, 6 * b - 5, prec, BF_RNDN);\n        bf_set_ui(&T0, CHUD_B);\n        bf_mul_ui(&T0, &T0, b, prec, BF_RNDN);\n        bf_set_ui(&T1, CHUD_A);\n        bf_add(&T0, &T0, &T1, prec, BF_RNDN);\n        bf_mul(P, G, &T0, prec, BF_RNDN);\n        P->sign = b & 1;\n\n        bf_set_ui(Q, b);\n        bf_mul_ui(Q, Q, b, prec, BF_RNDN);\n        bf_mul_ui(Q, Q, b, prec, BF_RNDN);\n        bf_mul_ui(Q, Q, (uint64_t)CHUD_C * CHUD_C * CHUD_C / 24, prec, BF_RNDN);\n        bf_delete(&T0);\n        bf_delete(&T1);\n    } else {\n        bf_t P2, Q2, G2;\n        \n        bf_init(s, &P2);\n        bf_init(s, &Q2);\n        bf_init(s, &G2);\n\n        c = (a + b) / 2;\n        chud_bs(P, Q, G, a, c, 1, prec);\n        chud_bs(&P2, &Q2, &G2, c, b, need_g, prec);\n        \n        /* Q = Q1 * Q2 */\n        /* G = G1 * G2 */\n        /* P = P1 * Q2 + P2 * G1 */\n        bf_mul(&P2, &P2, G, prec, BF_RNDN);\n        if (!need_g)\n            bf_set_ui(G, 0);\n        bf_mul(P, P, &Q2, prec, BF_RNDN);\n        bf_add(P, P, &P2, prec, BF_RNDN);\n        bf_delete(&P2);\n\n        bf_mul(Q, Q, &Q2, prec, BF_RNDN);\n        bf_delete(&Q2);\n        if (need_g)\n            bf_mul(G, G, &G2, prec, BF_RNDN);\n        bf_delete(&G2);\n    }\n}\n\n/* compute Pi with faithful rounding at precision 'prec' using the\n   Chudnovsky formula */\nstatic void bf_const_pi_internal(bf_t *Q, limb_t prec)\n{\n    bf_context_t *s = Q->ctx;\n    int64_t n, prec1;\n    bf_t P, G;\n\n    /* number of serie terms */\n    n = prec / CHUD_BITS_PER_TERM + 1;\n    /* XXX: precision analysis */\n    prec1 = prec + 32;\n\n    bf_init(s, &P);\n    bf_init(s, &G);\n\n    chud_bs(&P, Q, &G, 0, n, 0, BF_PREC_INF);\n    \n    bf_mul_ui(&G, Q, CHUD_A, prec1, BF_RNDN);\n    bf_add(&P, &G, &P, prec1, BF_RNDN);\n    bf_div(Q, Q, &P, prec1, BF_RNDF);\n \n    bf_set_ui(&P, CHUD_C);\n    bf_sqrt(&G, &P, prec1, BF_RNDF);\n    bf_mul_ui(&G, &G, (uint64_t)CHUD_C / 12, prec1, BF_RNDF);\n    bf_mul(Q, Q, &G, prec, BF_RNDN);\n    bf_delete(&P);\n    bf_delete(&G);\n}\n\nstatic int bf_const_get(bf_t *T, limb_t prec, bf_flags_t flags,\n                        BFConstCache *c,\n                        void (*func)(bf_t *res, limb_t prec), int sign)\n{\n    limb_t ziv_extra_bits, prec1;\n\n    ziv_extra_bits = 32;\n    for(;;) {\n        prec1 = prec + ziv_extra_bits;\n        if (c->prec < prec1) {\n            if (c->val.len == 0)\n                bf_init(T->ctx, &c->val);\n            func(&c->val, prec1);\n            c->prec = prec1;\n        } else {\n            prec1 = c->prec;\n        }\n        bf_set(T, &c->val);\n        T->sign = sign;\n        if (!bf_can_round(T, prec, flags & BF_RND_MASK, prec1)) {\n            /* and more precision and retry */\n            ziv_extra_bits = ziv_extra_bits  + (ziv_extra_bits / 2);\n        } else {\n            break;\n        }\n    }\n    return bf_round(T, prec, flags);\n}\n\nstatic void bf_const_free(BFConstCache *c)\n{\n    bf_delete(&c->val);\n    memset(c, 0, sizeof(*c));\n}\n\nint bf_const_log2(bf_t *T, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = T->ctx;\n    return bf_const_get(T, prec, flags, &s->log2_cache, bf_const_log2_internal, 0);\n}\n\n/* return rounded pi * (1 - 2 * sign) */\nstatic int bf_const_pi_signed(bf_t *T, int sign, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = T->ctx;\n    return bf_const_get(T, prec, flags, &s->pi_cache, bf_const_pi_internal,\n                        sign);\n}\n\nint bf_const_pi(bf_t *T, limb_t prec, bf_flags_t flags)\n{\n    return bf_const_pi_signed(T, 0, prec, flags);\n}\n\nvoid bf_clear_cache(bf_context_t *s)\n{\n#ifdef USE_FFT_MUL\n    fft_clear_cache(s);\n#endif\n    bf_const_free(&s->log2_cache);\n    bf_const_free(&s->pi_cache);\n}\n\n/* ZivFunc should compute the result 'r' with faithful rounding at\n   precision 'prec'. For efficiency purposes, the final bf_round()\n   does not need to be done in the function. */\ntypedef int ZivFunc(bf_t *r, const bf_t *a, limb_t prec, void *opaque);\n\nstatic int bf_ziv_rounding(bf_t *r, const bf_t *a,\n                           limb_t prec, bf_flags_t flags,\n                           ZivFunc *f, void *opaque)\n{\n    int rnd_mode, ret;\n    slimb_t prec1, ziv_extra_bits;\n    \n    rnd_mode = flags & BF_RND_MASK;\n    if (rnd_mode == BF_RNDF) {\n        /* no need to iterate */\n        f(r, a, prec, opaque);\n        ret = 0;\n    } else {\n        ziv_extra_bits = 32;\n        for(;;) {\n            prec1 = prec + ziv_extra_bits;\n            ret = f(r, a, prec1, opaque);\n            if (ret & (BF_ST_OVERFLOW | BF_ST_UNDERFLOW | BF_ST_MEM_ERROR)) {\n                /* overflow or underflow should never happen because\n                   it indicates the rounding cannot be done correctly,\n                   but we do not catch all the cases */\n                return ret;\n            }\n            /* if the result is exact, we can stop */\n            if (!(ret & BF_ST_INEXACT)) {\n                ret = 0;\n                break;\n            }\n            if (bf_can_round(r, prec, rnd_mode, prec1)) {\n                ret = BF_ST_INEXACT;\n                break;\n            }\n            ziv_extra_bits = ziv_extra_bits * 2;\n            //            printf(\"ziv_extra_bits=%\" PRId64 \"\\n\", (int64_t)ziv_extra_bits);\n        }\n    }\n    if (r->len == 0)\n        return ret;\n    else\n        return __bf_round(r, prec, flags, r->len, ret);\n}\n\n/* add (1 - 2*e_sign) * 2^e */\nstatic int bf_add_epsilon(bf_t *r, const bf_t *a, slimb_t e, int e_sign,\n                          limb_t prec, int flags)\n{\n    bf_t T_s, *T = &T_s;\n    int ret;\n    /* small argument case: result = 1 + epsilon * sign(x) */\n    bf_init(a->ctx, T);\n    bf_set_ui(T, 1);\n    T->sign = e_sign;\n    T->expn += e;\n    ret = bf_add(r, r, T, prec, flags);\n    bf_delete(T);\n    return ret;\n}\n\n/* Compute the exponential using faithful rounding at precision 'prec'.\n   Note: the algorithm is from MPFR */\nstatic int bf_exp_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    slimb_t n, K, l, i, prec1;\n    \n    assert(r != a);\n\n    /* argument reduction:\n       T = a - n*log(2) with 0 <= T < log(2) and n integer.\n    */\n    bf_init(s, T);\n    if (a->expn <= -1) {\n        /* 0 <= abs(a) <= 0.5 */\n        if (a->sign)\n            n = -1;\n        else\n            n = 0;\n    } else {\n        bf_const_log2(T, LIMB_BITS, BF_RNDZ);\n        bf_div(T, a, T, LIMB_BITS, BF_RNDD);\n        bf_get_limb(&n, T, 0);\n    }\n\n    K = bf_isqrt((prec + 1) / 2);\n    l = (prec - 1) / K + 1;\n    /* XXX: precision analysis ? */\n    prec1 = prec + (K + 2 * l + 18) + K + 8;\n    if (a->expn > 0)\n        prec1 += a->expn;\n    //    printf(\"n=%ld K=%ld prec1=%ld\\n\", n, K, prec1);\n\n    bf_const_log2(T, prec1, BF_RNDF);\n    bf_mul_si(T, T, n, prec1, BF_RNDN);\n    bf_sub(T, a, T, prec1, BF_RNDN);\n\n    /* reduce the range of T */\n    bf_mul_2exp(T, -K, BF_PREC_INF, BF_RNDZ);\n    \n    /* Taylor expansion around zero :\n     1 + x + x^2/2 + ... + x^n/n! \n     = (1 + x * (1 + x/2 * (1 + ... (x/n))))\n    */\n    {\n        bf_t U_s, *U = &U_s;\n        \n        bf_init(s, U);\n        bf_set_ui(r, 1);\n        for(i = l ; i >= 1; i--) {\n            bf_set_ui(U, i);\n            bf_div(U, T, U, prec1, BF_RNDN);\n            bf_mul(r, r, U, prec1, BF_RNDN);\n            bf_add_si(r, r, 1, prec1, BF_RNDN);\n        }\n        bf_delete(U);\n    }\n    bf_delete(T);\n    \n    /* undo the range reduction */\n    for(i = 0; i < K; i++) {\n        bf_mul(r, r, r, prec1, BF_RNDN | BF_FLAG_EXT_EXP);\n    }\n\n    /* undo the argument reduction */\n    bf_mul_2exp(r, n, BF_PREC_INF, BF_RNDZ | BF_FLAG_EXT_EXP);\n\n    return BF_ST_INEXACT;\n}\n\n/* crude overflow and underflow tests for exp(a). a_low <= a <= a_high */\nstatic int check_exp_underflow_overflow(bf_context_t *s, bf_t *r,\n                                        const bf_t *a_low, const bf_t *a_high,\n                                        limb_t prec, bf_flags_t flags)\n{\n    bf_t T_s, *T = &T_s;\n    bf_t log2_s, *log2 = &log2_s;\n    slimb_t e_min, e_max;\n    \n    if (a_high->expn <= 0)\n        return 0;\n\n    e_max = (limb_t)1 << (bf_get_exp_bits(flags) - 1);\n    e_min = -e_max + 3;\n    if (flags & BF_FLAG_SUBNORMAL)\n        e_min -= (prec - 1);\n    \n    bf_init(s, T);\n    bf_init(s, log2);\n    bf_const_log2(log2, LIMB_BITS, BF_RNDU);\n    bf_mul_ui(T, log2, e_max, LIMB_BITS, BF_RNDU);\n    /* a_low > e_max * log(2) implies exp(a) > e_max */\n    if (bf_cmp_lt(T, a_low) > 0) {\n        /* overflow */\n        bf_delete(T);\n        bf_delete(log2);\n        return bf_set_overflow(r, 0, prec, flags);\n    }\n    /* a_high < (e_min - 2) * log(2) implies exp(a) < (e_min - 2) */\n    bf_const_log2(log2, LIMB_BITS, BF_RNDD);\n    bf_mul_si(T, log2, e_min - 2, LIMB_BITS, BF_RNDD);\n    if (bf_cmp_lt(a_high, T)) {\n        int rnd_mode = flags & BF_RND_MASK;\n        \n        /* underflow */\n        bf_delete(T);\n        bf_delete(log2);\n        if (rnd_mode == BF_RNDU) {\n            /* set the smallest value */\n            bf_set_ui(r, 1);\n            r->expn = e_min;\n        } else {\n            bf_set_zero(r, 0);\n        }\n        return BF_ST_UNDERFLOW | BF_ST_INEXACT;\n    }\n    bf_delete(log2);\n    bf_delete(T);\n    return 0;\n}\n\nint bf_exp(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    int ret;\n    assert(r != a);\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n        } else if (a->expn == BF_EXP_INF) {\n            if (a->sign)\n                bf_set_zero(r, 0);\n            else\n                bf_set_inf(r, 0);\n        } else {\n            bf_set_ui(r, 1);\n        }\n        return 0;\n    }\n\n    ret = check_exp_underflow_overflow(s, r, a, a, prec, flags);\n    if (ret)\n        return ret;\n    if (a->expn < 0 && (-a->expn) >= (prec + 2)) { \n        /* small argument case: result = 1 + epsilon * sign(x) */\n        bf_set_ui(r, 1);\n        return bf_add_epsilon(r, r, -(prec + 2), a->sign, prec, flags);\n    }\n                         \n    return bf_ziv_rounding(r, a, prec, flags, bf_exp_internal, NULL);\n}\n\nstatic int bf_log_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    bf_t U_s, *U = &U_s;\n    bf_t V_s, *V = &V_s;\n    slimb_t n, prec1, l, i, K;\n    \n    assert(r != a);\n\n    bf_init(s, T);\n    /* argument reduction 1 */\n    /* T=a*2^n with 2/3 <= T <= 4/3 */\n    {\n        bf_t U_s, *U = &U_s;\n        bf_set(T, a);\n        n = T->expn;\n        T->expn = 0;\n        /* U= ~ 2/3 */\n        bf_init(s, U);\n        bf_set_ui(U, 0xaaaaaaaa); \n        U->expn = 0;\n        if (bf_cmp_lt(T, U)) {\n            T->expn++;\n            n--;\n        }\n        bf_delete(U);\n    }\n    //    printf(\"n=%ld\\n\", n);\n    //    bf_print_str(\"T\", T);\n\n    /* XXX: precision analysis */\n    /* number of iterations for argument reduction 2 */\n    K = bf_isqrt((prec + 1) / 2); \n    /* order of Taylor expansion */\n    l = prec / (2 * K) + 1; \n    /* precision of the intermediate computations */\n    prec1 = prec + K + 2 * l + 32;\n\n    bf_init(s, U);\n    bf_init(s, V);\n    \n    /* Note: cancellation occurs here, so we use more precision (XXX:\n       reduce the precision by computing the exact cancellation) */\n    bf_add_si(T, T, -1, BF_PREC_INF, BF_RNDN); \n\n    /* argument reduction 2 */\n    for(i = 0; i < K; i++) {\n        /* T = T / (1 + sqrt(1 + T)) */\n        bf_add_si(U, T, 1, prec1, BF_RNDN);\n        bf_sqrt(V, U, prec1, BF_RNDF);\n        bf_add_si(U, V, 1, prec1, BF_RNDN);\n        bf_div(T, T, U, prec1, BF_RNDN);\n    }\n\n    {\n        bf_t Y_s, *Y = &Y_s;\n        bf_t Y2_s, *Y2 = &Y2_s;\n        bf_init(s, Y);\n        bf_init(s, Y2);\n\n        /* compute ln(1+x) = ln((1+y)/(1-y)) with y=x/(2+x)\n           = y + y^3/3 + ... + y^(2*l + 1) / (2*l+1) \n           with Y=Y^2\n           = y*(1+Y/3+Y^2/5+...) = y*(1+Y*(1/3+Y*(1/5 + ...)))\n        */\n        bf_add_si(Y, T, 2, prec1, BF_RNDN);\n        bf_div(Y, T, Y, prec1, BF_RNDN);\n\n        bf_mul(Y2, Y, Y, prec1, BF_RNDN);\n        bf_set_ui(r, 0);\n        for(i = l; i >= 1; i--) {\n            bf_set_ui(U, 1);\n            bf_set_ui(V, 2 * i + 1);\n            bf_div(U, U, V, prec1, BF_RNDN);\n            bf_add(r, r, U, prec1, BF_RNDN);\n            bf_mul(r, r, Y2, prec1, BF_RNDN);\n        }\n        bf_add_si(r, r, 1, prec1, BF_RNDN);\n        bf_mul(r, r, Y, prec1, BF_RNDN);\n        bf_delete(Y);\n        bf_delete(Y2);\n    }\n    bf_delete(V);\n    bf_delete(U);\n\n    /* multiplication by 2 for the Taylor expansion and undo the\n       argument reduction 2*/\n    bf_mul_2exp(r, K + 1, BF_PREC_INF, BF_RNDZ);\n    \n    /* undo the argument reduction 1 */\n    bf_const_log2(T, prec1, BF_RNDF);\n    bf_mul_si(T, T, n, prec1, BF_RNDN);\n    bf_add(r, r, T, prec1, BF_RNDN);\n    \n    bf_delete(T);\n    return BF_ST_INEXACT;\n}\n\nint bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    \n    assert(r != a);\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF) {\n            if (a->sign) {\n                bf_set_nan(r);\n                return BF_ST_INVALID_OP;\n            } else {\n                bf_set_inf(r, 0);\n                return 0;\n            }\n        } else {\n            bf_set_inf(r, 1);\n            return 0;\n        }\n    }\n    if (a->sign) {\n        bf_set_nan(r);\n        return BF_ST_INVALID_OP;\n    }\n    bf_init(s, T);\n    bf_set_ui(T, 1);\n    if (bf_cmp_eq(a, T)) {\n        bf_set_zero(r, 0);\n        bf_delete(T);\n        return 0;\n    }\n    bf_delete(T);\n\n    return bf_ziv_rounding(r, a, prec, flags, bf_log_internal, NULL);\n}\n\n/* x and y finite and x > 0 */\nstatic int bf_pow_generic(bf_t *r, const bf_t *x, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    const bf_t *y = opaque;\n    bf_t T_s, *T = &T_s;\n    limb_t prec1;\n\n    bf_init(s, T);\n    /* XXX: proof for the added precision */\n    prec1 = prec + 32;\n    bf_log(T, x, prec1, BF_RNDF | BF_FLAG_EXT_EXP);\n    bf_mul(T, T, y, prec1, BF_RNDF | BF_FLAG_EXT_EXP);\n    if (bf_is_nan(T))\n        bf_set_nan(r);\n    else\n        bf_exp_internal(r, T, prec1, NULL); /* no overflow/underlow test needed */\n    bf_delete(T);\n    return BF_ST_INEXACT;\n}\n\n/* x and y finite, x > 0, y integer and y fits on one limb */\nstatic int bf_pow_int(bf_t *r, const bf_t *x, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    const bf_t *y = opaque;\n    bf_t T_s, *T = &T_s;\n    limb_t prec1;\n    int ret;\n    slimb_t y1;\n    \n    bf_get_limb(&y1, y, 0);\n    if (y1 < 0)\n        y1 = -y1;\n    /* XXX: proof for the added precision */\n    prec1 = prec + ceil_log2(y1) * 2 + 8;\n    ret = bf_pow_ui(r, x, y1 < 0 ? -y1 : y1, prec1, BF_RNDN | BF_FLAG_EXT_EXP);\n    if (y->sign) {\n        bf_init(s, T);\n        bf_set_ui(T, 1);\n        ret |= bf_div(r, T, r, prec1, BF_RNDN | BF_FLAG_EXT_EXP);\n        bf_delete(T);\n    }\n    return ret;\n}\n\n/* x must be a finite non zero float. Return TRUE if there is a\n   floating point number r such as x=r^(2^n) and return this floating\n   point number 'r'. Otherwise return FALSE and r is undefined. */\nstatic BOOL check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    slimb_t e, i, er;\n    limb_t v;\n    \n    /* x = m*2^e with m odd integer */\n    e = bf_get_exp_min(x);\n    /* fast check on the exponent */\n    if (n > (LIMB_BITS - 1)) {\n        if (e != 0)\n            return FALSE;\n        er = 0;\n    } else {\n        if ((e & (((limb_t)1 << n) - 1)) != 0)\n            return FALSE;\n        er = e >> n;\n    }\n    /* every perfect odd square = 1 modulo 8 */\n    v = get_bits(x->tab, x->len, x->len * LIMB_BITS - x->expn + e);\n    if ((v & 7) != 1)\n        return FALSE;\n\n    bf_init(s, T);\n    bf_set(T, x);\n    T->expn -= e;\n    for(i = 0; i < n; i++) {\n        if (i != 0)\n            bf_set(T, r);\n        if (bf_sqrtrem(r, NULL, T) != 0)\n            return FALSE;\n    }\n    r->expn += er;\n    return TRUE;\n}\n\n/* prec = BF_PREC_INF is accepted for x and y integers and y >= 0 */\nint bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    bf_t ytmp_s;\n    BOOL y_is_int, y_is_odd;\n    int r_sign, ret, rnd_mode;\n    slimb_t y_emin;\n    \n    if (x->len == 0 || y->len == 0) {\n        if (y->expn == BF_EXP_ZERO) {\n            /* pow(x, 0) = 1 */\n            bf_set_ui(r, 1);\n        } else if (x->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n        } else {\n            int cmp_x_abs_1;\n            bf_set_ui(r, 1);\n            cmp_x_abs_1 = bf_cmpu(x, r);\n            if (cmp_x_abs_1 == 0 && (flags & BF_POW_JS_QUIRKS) &&\n                (y->expn >= BF_EXP_INF)) {\n                bf_set_nan(r);\n            } else if (cmp_x_abs_1 == 0 &&\n                       (!x->sign || y->expn != BF_EXP_NAN)) {\n                /* pow(1, y) = 1 even if y = NaN */\n                /* pow(-1, +/-inf) = 1 */\n            } else if (y->expn == BF_EXP_NAN) {\n                bf_set_nan(r);\n            } else if (y->expn == BF_EXP_INF) {\n                if (y->sign == (cmp_x_abs_1 > 0)) {\n                    bf_set_zero(r, 0);\n                } else {\n                    bf_set_inf(r, 0);\n                }\n            } else {\n                y_emin = bf_get_exp_min(y);\n                y_is_odd = (y_emin == 0);\n                if (y->sign == (x->expn == BF_EXP_ZERO)) {\n                    bf_set_inf(r, y_is_odd & x->sign);\n                    if (y->sign) {\n                        /* pow(0, y) with y < 0 */\n                        return BF_ST_DIVIDE_ZERO;\n                    }\n                } else {\n                    bf_set_zero(r, y_is_odd & x->sign);\n                }\n            }\n        }\n        return 0;\n    }\n    bf_init(s, T);\n    bf_set(T, x);\n    y_emin = bf_get_exp_min(y);\n    y_is_int = (y_emin >= 0);\n    rnd_mode = flags & BF_RND_MASK;\n    if (x->sign) {\n        if (!y_is_int) {\n            bf_set_nan(r);\n            bf_delete(T);\n            return BF_ST_INVALID_OP;\n        }\n        y_is_odd = (y_emin == 0);\n        r_sign = y_is_odd;\n        /* change the directed rounding mode if the sign of the result\n           is changed */\n        if (r_sign && (rnd_mode == BF_RNDD || rnd_mode == BF_RNDU))\n            flags ^= 1;\n        bf_neg(T);\n    } else {\n        r_sign = 0;\n    }\n\n    bf_set_ui(r, 1);\n    if (bf_cmp_eq(T, r)) {\n        /* abs(x) = 1: nothing more to do */\n        ret = 0;\n    } else {\n        /* check the overflow/underflow cases */\n        {\n            bf_t al_s, *al = &al_s;\n            bf_t ah_s, *ah = &ah_s;\n            limb_t precl = LIMB_BITS;\n            \n            bf_init(s, al);\n            bf_init(s, ah);\n            /* compute bounds of log(abs(x)) * y with a low precision */\n            /* XXX: compute bf_log() once */\n            /* XXX: add a fast test before this slow test */\n            bf_log(al, T, precl, BF_RNDD);\n            bf_log(ah, T, precl, BF_RNDU);\n            bf_mul(al, al, y, precl, BF_RNDD ^ y->sign);\n            bf_mul(ah, ah, y, precl, BF_RNDU ^ y->sign);\n            ret = check_exp_underflow_overflow(s, r, al, ah, prec, flags);\n            bf_delete(al);\n            bf_delete(ah);\n            if (ret)\n                goto done;\n        }\n        \n        if (y_is_int) {\n            slimb_t T_bits, e;\n        int_pow:\n            T_bits = T->expn - bf_get_exp_min(T);\n            if (T_bits == 1) {\n                /* pow(2^b, y) = 2^(b*y) */\n                bf_mul_si(T, y, T->expn - 1, LIMB_BITS, BF_RNDZ);\n                bf_get_limb(&e, T, 0);\n                bf_set_ui(r, 1);\n                ret = bf_mul_2exp(r, e, prec, flags);\n            } else if (prec == BF_PREC_INF) {\n                slimb_t y1;\n                /* specific case for infinite precision (integer case) */\n                bf_get_limb(&y1, y, 0);\n                assert(!y->sign);\n                /* x must be an integer, so abs(x) >= 2 */\n                if (y1 >= ((slimb_t)1 << BF_EXP_BITS_MAX)) {\n                    bf_delete(T);\n                    return bf_set_overflow(r, 0, BF_PREC_INF, flags);\n                }\n                ret = bf_pow_ui(r, T, y1, BF_PREC_INF, BF_RNDZ);\n            } else {\n                if (y->expn <= 31) {\n                    /* small enough power: use exponentiation in all cases */\n                } else if (y->sign) {\n                    /* cannot be exact */\n                    goto general_case;\n                } else {\n                    if (rnd_mode == BF_RNDF)\n                        goto general_case; /* no need to track exact results */\n                    /* see if the result has a chance to be exact:\n                       if x=a*2^b (a odd), x^y=a^y*2^(b*y)\n                       x^y needs a precision of at least floor_log2(a)*y bits\n                    */\n                    bf_mul_si(r, y, T_bits - 1, LIMB_BITS, BF_RNDZ);\n                    bf_get_limb(&e, r, 0);\n                    if (prec < e)\n                        goto general_case;\n                }\n                ret = bf_ziv_rounding(r, T, prec, flags, bf_pow_int, (void *)y);\n            }\n        } else {\n            if (rnd_mode != BF_RNDF) {\n                bf_t *y1;\n                if (y_emin < 0 && check_exact_power2n(r, T, -y_emin)) {\n                    /* the problem is reduced to a power to an integer */\n#if 0\n                    printf(\"\\nn=%\" PRId64 \"\\n\", -(int64_t)y_emin);\n                    bf_print_str(\"T\", T);\n                    bf_print_str(\"r\", r);\n#endif\n                    bf_set(T, r);\n                    y1 = &ytmp_s;\n                    y1->tab = y->tab;\n                    y1->len = y->len;\n                    y1->sign = y->sign;\n                    y1->expn = y->expn - y_emin;\n                    y = y1;\n                    goto int_pow;\n                }\n            }\n        general_case:\n            ret = bf_ziv_rounding(r, T, prec, flags, bf_pow_generic, (void *)y);\n        }\n    }\n done:\n    bf_delete(T);\n    r->sign = r_sign;\n    return ret;\n}\n\n/* compute sqrt(-2*x-x^2) to get |sin(x)| from cos(x) - 1. */\nstatic void bf_sqrt_sin(bf_t *r, const bf_t *x, limb_t prec1)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    bf_init(s, T);\n    bf_set(T, x);\n    bf_mul(r, T, T, prec1, BF_RNDN);\n    bf_mul_2exp(T, 1, BF_PREC_INF, BF_RNDZ);\n    bf_add(T, T, r, prec1, BF_RNDN);\n    bf_neg(T);\n    bf_sqrt(r, T, prec1, BF_RNDF);\n    bf_delete(T);\n}\n\nstatic int bf_sincos(bf_t *s, bf_t *c, const bf_t *a, limb_t prec)\n{\n    bf_context_t *s1 = a->ctx;\n    bf_t T_s, *T = &T_s;\n    bf_t U_s, *U = &U_s;\n    bf_t r_s, *r = &r_s;\n    slimb_t K, prec1, i, l, mod, prec2;\n    int is_neg;\n    \n    assert(c != a && s != a);\n\n    bf_init(s1, T);\n    bf_init(s1, U);\n    bf_init(s1, r);\n    \n    /* XXX: precision analysis */\n    K = bf_isqrt(prec / 2);\n    l = prec / (2 * K) + 1;\n    prec1 = prec + 2 * K + l + 8;\n    \n    /* after the modulo reduction, -pi/4 <= T <= pi/4 */\n    if (a->expn <= -1) {\n        /* abs(a) <= 0.25: no modulo reduction needed */\n        bf_set(T, a);\n        mod = 0;\n    } else {\n        slimb_t cancel;\n        cancel = 0;\n        for(;;) {\n            prec2 = prec1 + a->expn + cancel;\n            bf_const_pi(U, prec2, BF_RNDF);\n            bf_mul_2exp(U, -1, BF_PREC_INF, BF_RNDZ);\n            bf_remquo(&mod, T, a, U, prec2, BF_RNDN, BF_RNDN);\n            //            printf(\"T.expn=%ld prec2=%ld\\n\", T->expn, prec2);\n            if (mod == 0 || (T->expn != BF_EXP_ZERO &&\n                             (T->expn + prec2) >= (prec1 - 1)))\n                break;\n            /* increase the number of bits until the precision is good enough */\n            cancel = bf_max(-T->expn, (cancel + 1) * 3 / 2);\n        }\n        mod &= 3;\n    }\n    \n    is_neg = T->sign;\n        \n    /* compute cosm1(x) = cos(x) - 1 */\n    bf_mul(T, T, T, prec1, BF_RNDN);\n    bf_mul_2exp(T, -2 * K, BF_PREC_INF, BF_RNDZ);\n    \n    /* Taylor expansion:\n       -x^2/2 + x^4/4! - x^6/6! + ...\n    */\n    bf_set_ui(r, 1);\n    for(i = l ; i >= 1; i--) {\n        bf_set_ui(U, 2 * i - 1);\n        bf_mul_ui(U, U, 2 * i, BF_PREC_INF, BF_RNDZ);\n        bf_div(U, T, U, prec1, BF_RNDN);\n        bf_mul(r, r, U, prec1, BF_RNDN);\n        bf_neg(r);\n        if (i != 1)\n            bf_add_si(r, r, 1, prec1, BF_RNDN);\n    }\n    bf_delete(U);\n\n    /* undo argument reduction:\n       cosm1(2*x)= 2*(2*cosm1(x)+cosm1(x)^2)\n    */\n    for(i = 0; i < K; i++) {\n        bf_mul(T, r, r, prec1, BF_RNDN);\n        bf_mul_2exp(r, 1, BF_PREC_INF, BF_RNDZ);\n        bf_add(r, r, T, prec1, BF_RNDN);\n        bf_mul_2exp(r, 1, BF_PREC_INF, BF_RNDZ);\n    }\n    bf_delete(T);\n\n    if (c) {\n        if ((mod & 1) == 0) {\n            bf_add_si(c, r, 1, prec1, BF_RNDN);\n        } else {\n            bf_sqrt_sin(c, r, prec1);\n            c->sign = is_neg ^ 1;\n        }\n        c->sign ^= mod >> 1;\n    }\n    if (s) {\n        if ((mod & 1) == 0) {\n            bf_sqrt_sin(s, r, prec1);\n            s->sign = is_neg;\n        } else {\n            bf_add_si(s, r, 1, prec1, BF_RNDN);\n        }\n        s->sign ^= mod >> 1;\n    }\n    bf_delete(r);\n    return BF_ST_INEXACT;\n}\n\nstatic int bf_cos_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)\n{\n    return bf_sincos(NULL, r, a, prec);\n}\n\nint bf_cos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_set_ui(r, 1);\n            return 0;\n        }\n    }\n\n    /* small argument case: result = 1+r(x) with r(x) = -x^2/2 +\n       O(X^4). We assume r(x) < 2^(2*EXP(x) - 1). */\n    if (a->expn < 0) {\n        slimb_t e;\n        e = 2 * a->expn - 1;\n        if (e < -(prec + 2)) {\n            bf_set_ui(r, 1);\n            return bf_add_epsilon(r, r, e, 1, prec, flags);\n        }\n    }\n    \n    return bf_ziv_rounding(r, a, prec, flags, bf_cos_internal, NULL);\n}\n\nstatic int bf_sin_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)\n{\n    return bf_sincos(r, NULL, a, prec);\n}\n\nint bf_sin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_set_zero(r, a->sign);\n            return 0;\n        }\n    }\n\n    /* small argument case: result = x+r(x) with r(x) = -x^3/6 +\n       O(X^5). We assume r(x) < 2^(3*EXP(x) - 2). */\n    if (a->expn < 0) {\n        slimb_t e;\n        e = sat_add(2 * a->expn, a->expn - 2);\n        if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {\n            bf_set(r, a);\n            return bf_add_epsilon(r, r, e, 1 - a->sign, prec, flags);\n        }\n    }\n\n    return bf_ziv_rounding(r, a, prec, flags, bf_sin_internal, NULL);\n}\n\nstatic int bf_tan_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    limb_t prec1;\n    \n    /* XXX: precision analysis */\n    prec1 = prec + 8;\n    bf_init(s, T);\n    bf_sincos(r, T, a, prec1);\n    bf_div(r, r, T, prec1, BF_RNDF);\n    bf_delete(T);\n    return BF_ST_INEXACT;\n}\n\nint bf_tan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    assert(r != a);\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_set_zero(r, a->sign);\n            return 0;\n        }\n    }\n\n    /* small argument case: result = x+r(x) with r(x) = x^3/3 +\n       O(X^5). We assume r(x) < 2^(3*EXP(x) - 1). */\n    if (a->expn < 0) {\n        slimb_t e;\n        e = sat_add(2 * a->expn, a->expn - 1);\n        if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {\n            bf_set(r, a);\n            return bf_add_epsilon(r, r, e, a->sign, prec, flags);\n        }\n    }\n            \n    return bf_ziv_rounding(r, a, prec, flags, bf_tan_internal, NULL);\n}\n\n/* if add_pi2 is true, add pi/2 to the result (used for acos(x) to\n   avoid cancellation) */\nstatic int bf_atan_internal(bf_t *r, const bf_t *a, limb_t prec,\n                            void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    BOOL add_pi2 = (BOOL)(intptr_t)opaque;\n    bf_t T_s, *T = &T_s;\n    bf_t U_s, *U = &U_s;\n    bf_t V_s, *V = &V_s;\n    bf_t X2_s, *X2 = &X2_s;\n    int cmp_1;\n    slimb_t prec1, i, K, l;\n    \n    /* XXX: precision analysis */\n    K = bf_isqrt((prec + 1) / 2);\n    l = prec / (2 * K) + 1;\n    prec1 = prec + K + 2 * l + 32;\n    //    printf(\"prec=%d K=%d l=%d prec1=%d\\n\", (int)prec, (int)K, (int)l, (int)prec1);\n    \n    bf_init(s, T);\n    cmp_1 = (a->expn >= 1); /* a >= 1 */\n    if (cmp_1) {\n        bf_set_ui(T, 1);\n        bf_div(T, T, a, prec1, BF_RNDN);\n    } else {\n        bf_set(T, a);\n    }\n\n    /* abs(T) <= 1 */\n\n    /* argument reduction */\n\n    bf_init(s, U);\n    bf_init(s, V);\n    bf_init(s, X2);\n    for(i = 0; i < K; i++) {\n        /* T = T / (1 + sqrt(1 + T^2)) */\n        bf_mul(U, T, T, prec1, BF_RNDN);\n        bf_add_si(U, U, 1, prec1, BF_RNDN);\n        bf_sqrt(V, U, prec1, BF_RNDN);\n        bf_add_si(V, V, 1, prec1, BF_RNDN);\n        bf_div(T, T, V, prec1, BF_RNDN);\n    }\n\n    /* Taylor series: \n       x - x^3/3 + ... + (-1)^ l * y^(2*l + 1) / (2*l+1) \n    */\n    bf_mul(X2, T, T, prec1, BF_RNDN);\n    bf_set_ui(r, 0);\n    for(i = l; i >= 1; i--) {\n        bf_set_si(U, 1);\n        bf_set_ui(V, 2 * i + 1);\n        bf_div(U, U, V, prec1, BF_RNDN);\n        bf_neg(r);\n        bf_add(r, r, U, prec1, BF_RNDN);\n        bf_mul(r, r, X2, prec1, BF_RNDN);\n    }\n    bf_neg(r);\n    bf_add_si(r, r, 1, prec1, BF_RNDN);\n    bf_mul(r, r, T, prec1, BF_RNDN);\n\n    /* undo the argument reduction */\n    bf_mul_2exp(r, K, BF_PREC_INF, BF_RNDZ);\n    \n    bf_delete(U);\n    bf_delete(V);\n    bf_delete(X2);\n\n    i = add_pi2;\n    if (cmp_1 > 0) {\n        /* undo the inversion : r = sign(a)*PI/2 - r */\n        bf_neg(r);\n        i += 1 - 2 * a->sign;\n    }\n    /* add i*(pi/2) with -1 <= i <= 2 */\n    if (i != 0) {\n        bf_const_pi(T, prec1, BF_RNDF);\n        if (i != 2)\n            bf_mul_2exp(T, -1, BF_PREC_INF, BF_RNDZ);\n        T->sign = (i < 0);\n        bf_add(r, T, r, prec1, BF_RNDN);\n    }\n    \n    bf_delete(T);\n    return BF_ST_INEXACT;\n}\n\nint bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    int res;\n    \n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF)  {\n            /* -PI/2 or PI/2 */\n            bf_const_pi_signed(r, a->sign, prec, flags);\n            bf_mul_2exp(r, -1, BF_PREC_INF, BF_RNDZ);\n            return BF_ST_INEXACT;\n        } else {\n            bf_set_zero(r, a->sign);\n            return 0;\n        }\n    }\n    \n    bf_init(s, T);\n    bf_set_ui(T, 1);\n    res = bf_cmpu(a, T);\n    bf_delete(T);\n    if (res == 0) {\n        /* short cut: abs(a) == 1 -> +/-pi/4 */\n        bf_const_pi_signed(r, a->sign, prec, flags);\n        bf_mul_2exp(r, -2, BF_PREC_INF, BF_RNDZ);\n        return BF_ST_INEXACT;\n    }\n\n    /* small argument case: result = x+r(x) with r(x) = -x^3/3 +\n       O(X^5). We assume r(x) < 2^(3*EXP(x) - 1). */\n    if (a->expn < 0) {\n        slimb_t e;\n        e = sat_add(2 * a->expn, a->expn - 1);\n        if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {\n            bf_set(r, a);\n            return bf_add_epsilon(r, r, e, 1 - a->sign, prec, flags);\n        }\n    }\n    \n    return bf_ziv_rounding(r, a, prec, flags, bf_atan_internal, (void *)FALSE);\n}\n\nstatic int bf_atan2_internal(bf_t *r, const bf_t *y, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    const bf_t *x = opaque;\n    bf_t T_s, *T = &T_s;\n    limb_t prec1;\n    int ret;\n    \n    if (y->expn == BF_EXP_NAN || x->expn == BF_EXP_NAN) {\n        bf_set_nan(r);\n        return 0;\n    }\n\n    /* compute atan(y/x) assumming inf/inf = 1 and 0/0 = 0 */\n    bf_init(s, T);\n    prec1 = prec + 32;\n    if (y->expn == BF_EXP_INF && x->expn == BF_EXP_INF) {\n        bf_set_ui(T, 1);\n        T->sign = y->sign ^ x->sign;\n    } else if (y->expn == BF_EXP_ZERO && x->expn == BF_EXP_ZERO) {\n        bf_set_zero(T, y->sign ^ x->sign);\n    } else {\n        bf_div(T, y, x, prec1, BF_RNDF);\n    }\n    ret = bf_atan(r, T, prec1, BF_RNDF);\n\n    if (x->sign) {\n        /* if x < 0 (it includes -0), return sign(y)*pi + atan(y/x) */\n        bf_const_pi(T, prec1, BF_RNDF);\n        T->sign = y->sign;\n        bf_add(r, r, T, prec1, BF_RNDN);\n        ret |= BF_ST_INEXACT;\n    }\n\n    bf_delete(T);\n    return ret;\n}\n\nint bf_atan2(bf_t *r, const bf_t *y, const bf_t *x,\n             limb_t prec, bf_flags_t flags)\n{\n    return bf_ziv_rounding(r, y, prec, flags, bf_atan2_internal, (void *)x);\n}\n\nstatic int bf_asin_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)\n{\n    bf_context_t *s = r->ctx;\n    BOOL is_acos = (BOOL)(intptr_t)opaque;\n    bf_t T_s, *T = &T_s;\n    limb_t prec1, prec2;\n    \n    /* asin(x) = atan(x/sqrt(1-x^2)) \n       acos(x) = pi/2 - asin(x) */\n    prec1 = prec + 8;\n    /* increase the precision in x^2 to compensate the cancellation in\n       (1-x^2) if x is close to 1 */\n    /* XXX: use less precision when possible */\n    if (a->expn >= 0)\n        prec2 = BF_PREC_INF;\n    else\n        prec2 = prec1;\n    bf_init(s, T);\n    bf_mul(T, a, a, prec2, BF_RNDN);\n    bf_neg(T);\n    bf_add_si(T, T, 1, prec2, BF_RNDN);\n\n    bf_sqrt(r, T, prec1, BF_RNDN);\n    bf_div(T, a, r, prec1, BF_RNDN);\n    if (is_acos)\n        bf_neg(T);\n    bf_atan_internal(r, T, prec1, (void *)(intptr_t)is_acos);\n    bf_delete(T);\n    return BF_ST_INEXACT;\n}\n\nint bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    int res;\n\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_set_zero(r, a->sign);\n            return 0;\n        }\n    }\n    bf_init(s, T);\n    bf_set_ui(T, 1);\n    res = bf_cmpu(a, T);\n    bf_delete(T);\n    if (res > 0) {\n        bf_set_nan(r);\n        return BF_ST_INVALID_OP;\n    }\n    \n    /* small argument case: result = x+r(x) with r(x) = x^3/6 +\n       O(X^5). We assume r(x) < 2^(3*EXP(x) - 2). */\n    if (a->expn < 0) {\n        slimb_t e;\n        e = sat_add(2 * a->expn, a->expn - 2);\n        if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {\n            bf_set(r, a);\n            return bf_add_epsilon(r, r, e, a->sign, prec, flags);\n        }\n    }\n\n    return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)FALSE);\n}\n\nint bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = r->ctx;\n    bf_t T_s, *T = &T_s;\n    int res;\n\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bf_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF) {\n            bf_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bf_const_pi(r, prec, flags);\n            bf_mul_2exp(r, -1, BF_PREC_INF, BF_RNDZ);\n            return BF_ST_INEXACT;\n        }\n    }\n    bf_init(s, T);\n    bf_set_ui(T, 1);\n    res = bf_cmpu(a, T);\n    bf_delete(T);\n    if (res > 0) {\n        bf_set_nan(r);\n        return BF_ST_INVALID_OP;\n    } else if (res == 0 && a->sign == 0) {\n        bf_set_zero(r, 0);\n        return 0;\n    }\n    \n    return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)TRUE);\n}\n\n/***************************************************************/\n/* decimal floating point numbers */\n\n#ifdef USE_BF_DEC\n\n#define adddq(r1, r0, a1, a0)                   \\\n    do {                                        \\\n        limb_t __t = r0;                        \\\n        r0 += (a0);                             \\\n        r1 += (a1) + (r0 < __t);                \\\n    } while (0)\n\n#define subdq(r1, r0, a1, a0)                   \\\n    do {                                        \\\n        limb_t __t = r0;                        \\\n        r0 -= (a0);                             \\\n        r1 -= (a1) + (r0 > __t);                \\\n    } while (0)\n\n#if LIMB_BITS == 64\n\n/* Note: we assume __int128 is available */\n#define muldq(r1, r0, a, b)                     \\\n    do {                                        \\\n        unsigned __int128 __t;                          \\\n        __t = (unsigned __int128)(a) * (unsigned __int128)(b);  \\\n        r0 = __t;                               \\\n        r1 = __t >> 64;                         \\\n    } while (0)\n\n#define divdq(q, r, a1, a0, b)                  \\\n    do {                                        \\\n        unsigned __int128 __t;                  \\\n        limb_t __b = (b);                       \\\n        __t = ((unsigned __int128)(a1) << 64) | (a0);   \\\n        q = __t / __b;                                  \\\n        r = __t % __b;                                  \\\n    } while (0)\n\n#else\n\n#define muldq(r1, r0, a, b)                     \\\n    do {                                        \\\n        uint64_t __t;                          \\\n        __t = (uint64_t)(a) * (uint64_t)(b);  \\\n        r0 = __t;                               \\\n        r1 = __t >> 32;                         \\\n    } while (0)\n\n#define divdq(q, r, a1, a0, b)                  \\\n    do {                                        \\\n        uint64_t __t;                  \\\n        limb_t __b = (b);                       \\\n        __t = ((uint64_t)(a1) << 32) | (a0);   \\\n        q = __t / __b;                                  \\\n        r = __t % __b;                                  \\\n    } while (0)\n\n#endif /* LIMB_BITS != 64 */\n\nstatic inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift)\n{\n    if (shift != 0)\n        low = (low >> shift) | (high << (LIMB_BITS - shift));\n    return low;\n}\n\nstatic inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)\n{\n    if (shift != 0)\n        return (a1 << shift) | (a0 >> (LIMB_BITS - shift));\n    else\n        return a1;\n}\n\n#if LIMB_DIGITS == 19\n\n/* WARNING: hardcoded for b = 1e19. It is assumed that:\n   0 <= a1 < 2^63 */\n#define divdq_base(q, r, a1, a0)\\\ndo {\\\n    uint64_t __a0, __a1, __t0, __t1, __b = BF_DEC_BASE; \\\n    __a0 = a0;\\\n    __a1 = a1;\\\n    __t0 = __a1;\\\n    __t0 = shld(__t0, __a0, 1);\\\n    muldq(q, __t1, __t0, UINT64_C(17014118346046923173)); \\\n    muldq(__t1, __t0, q, __b);\\\n    subdq(__a1, __a0, __t1, __t0);\\\n    subdq(__a1, __a0, 1, __b * 2);    \\\n    __t0 = (slimb_t)__a1 >> 1; \\\n    q += 2 + __t0;\\\n    adddq(__a1, __a0, 0, __b & __t0);\\\n    q += __a1;                  \\\n    __a0 += __b & __a1;           \\\n    r = __a0;\\\n} while(0)\n\n#elif LIMB_DIGITS == 9\n\n/* WARNING: hardcoded for b = 1e9. It is assumed that:\n   0 <= a1 < 2^29 */\n#define divdq_base(q, r, a1, a0)\\\ndo {\\\n    uint32_t __t0, __t1, __b = BF_DEC_BASE; \\\n    __t0 = a1;\\\n    __t1 = a0;\\\n    __t0 = (__t0 << 3) | (__t1 >> (32 - 3));    \\\n    muldq(q, __t1, __t0, 2305843009U);\\\n    r = a0 - q * __b;\\\n    __t1 = (r >= __b);\\\n    q += __t1;\\\n    if (__t1)\\\n        r -= __b;\\\n} while(0)\n\n#endif\n\n/* fast integer division by a fixed constant */\n\ntypedef struct FastDivData {\n    limb_t m1; /* multiplier */\n    int8_t shift1;\n    int8_t shift2;\n} FastDivData;\n\n/* From \"Division by Invariant Integers using Multiplication\" by\n   Torborn Granlund and Peter L. Montgomery */\n/* d must be != 0 */\nstatic inline __maybe_unused void fast_udiv_init(FastDivData *s, limb_t d)\n{\n    int l;\n    limb_t q, r, m1;\n    if (d == 1)\n        l = 0;\n    else\n        l = 64 - clz64(d - 1);\n    divdq(q, r, ((limb_t)1 << l) - d, 0, d);\n    (void)r;\n    m1 = q + 1;\n    //    printf(\"d=%lu l=%d m1=0x%016lx\\n\", d, l, m1);\n    s->m1 = m1;\n    s->shift1 = l;\n    if (s->shift1 > 1)\n        s->shift1 = 1;\n    s->shift2 = l - 1;\n    if (s->shift2 < 0)\n        s->shift2 = 0;\n}\n\nstatic inline limb_t fast_udiv(limb_t a, const FastDivData *s)\n{\n    limb_t t0, t1;\n    muldq(t1, t0, s->m1, a);\n    t0 = (a - t1) >> s->shift1;\n    return (t1 + t0) >> s->shift2;\n}\n\n/* contains 10^i */\nconst limb_t mp_pow_dec[LIMB_DIGITS + 1] = {\n    1U,\n    10U,\n    100U,\n    1000U,\n    10000U,\n    100000U,\n    1000000U,\n    10000000U,\n    100000000U,\n    1000000000U,\n#if LIMB_BITS == 64\n    10000000000U,\n    100000000000U,\n    1000000000000U,\n    10000000000000U,\n    100000000000000U,\n    1000000000000000U,\n    10000000000000000U,\n    100000000000000000U,\n    1000000000000000000U,\n    10000000000000000000U,\n#endif\n};\n\n/* precomputed from fast_udiv_init(10^i) */\nstatic const FastDivData mp_pow_div[LIMB_DIGITS + 1] = {\n#if LIMB_BITS == 32\n    { 0x00000001, 0, 0 },\n    { 0x9999999a, 1, 3 },\n    { 0x47ae147b, 1, 6 },\n    { 0x0624dd30, 1, 9 },\n    { 0xa36e2eb2, 1, 13 },\n    { 0x4f8b588f, 1, 16 },\n    { 0x0c6f7a0c, 1, 19 },\n    { 0xad7f29ac, 1, 23 },\n    { 0x5798ee24, 1, 26 },\n    { 0x12e0be83, 1, 29 },\n#else\n    { 0x0000000000000001, 0, 0 },\n    { 0x999999999999999a, 1, 3 },\n    { 0x47ae147ae147ae15, 1, 6 },\n    { 0x0624dd2f1a9fbe77, 1, 9 },\n    { 0xa36e2eb1c432ca58, 1, 13 },\n    { 0x4f8b588e368f0847, 1, 16 },\n    { 0x0c6f7a0b5ed8d36c, 1, 19 },\n    { 0xad7f29abcaf48579, 1, 23 },\n    { 0x5798ee2308c39dfa, 1, 26 },\n    { 0x12e0be826d694b2f, 1, 29 },\n    { 0xb7cdfd9d7bdbab7e, 1, 33 },\n    { 0x5fd7fe17964955fe, 1, 36 },\n    { 0x19799812dea11198, 1, 39 },\n    { 0xc25c268497681c27, 1, 43 },\n    { 0x6849b86a12b9b01f, 1, 46 },\n    { 0x203af9ee756159b3, 1, 49 },\n    { 0xcd2b297d889bc2b7, 1, 53 },\n    { 0x70ef54646d496893, 1, 56 },\n    { 0x2725dd1d243aba0f, 1, 59 },\n    { 0xd83c94fb6d2ac34d, 1, 63 },\n#endif\n};\n\n/* divide by 10^shift with 0 <= shift <= LIMB_DIGITS */\nstatic inline limb_t fast_shr_dec(limb_t a, int shift)\n{\n    return fast_udiv(a, &mp_pow_div[shift]);\n}\n\n/* division and remainder by 10^shift */\n#define fast_shr_rem_dec(q, r, a, shift) q = fast_shr_dec(a, shift), r = a - q * mp_pow_dec[shift]\n    \nlimb_t mp_add_dec(limb_t *res, const limb_t *op1, const limb_t *op2, \n                  mp_size_t n, limb_t carry)\n{\n    limb_t base = BF_DEC_BASE;\n    mp_size_t i;\n    limb_t k, a, v;\n\n    k=carry;\n    for(i=0;i<n;i++) {\n        /* XXX: reuse the trick in add_mod */\n        v = op1[i];\n        a = v + op2[i] + k - base;\n        k = a <= v;\n        if (!k) \n            a += base;\n        res[i]=a;\n    }\n    return k;\n}\n\nlimb_t mp_add_ui_dec(limb_t *tab, limb_t b, mp_size_t n)\n{\n    limb_t base = BF_DEC_BASE;\n    mp_size_t i;\n    limb_t k, a, v;\n\n    k=b;\n    for(i=0;i<n;i++) {\n        v = tab[i];\n        a = v + k - base;\n        k = a <= v;\n        if (!k) \n            a += base;\n        tab[i] = a;\n        if (k == 0)\n            break;\n    }\n    return k;\n}\n\nlimb_t mp_sub_dec(limb_t *res, const limb_t *op1, const limb_t *op2, \n                  mp_size_t n, limb_t carry)\n{\n    limb_t base = BF_DEC_BASE;\n    mp_size_t i;\n    limb_t k, v, a;\n\n    k=carry;\n    for(i=0;i<n;i++) {\n        v = op1[i];\n        a = v - op2[i] - k;\n        k = a > v;\n        if (k)\n            a += base;\n        res[i] = a;\n    }\n    return k;\n}\n\nlimb_t mp_sub_ui_dec(limb_t *tab, limb_t b, mp_size_t n)\n{\n    limb_t base = BF_DEC_BASE;\n    mp_size_t i;\n    limb_t k, v, a;\n    \n    k=b;\n    for(i=0;i<n;i++) {\n        v = tab[i];\n        a = v - k;\n        k = a > v;\n        if (k)\n            a += base;\n        tab[i]=a;\n        if (k == 0)\n            break;\n    }\n    return k;\n}\n\n/* taba[] = taba[] * b + l. 0 <= b, l <= base - 1. Return the high carry */\nlimb_t mp_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n, \n                   limb_t b, limb_t l)\n{\n    mp_size_t i;\n    limb_t t0, t1, r;\n\n    for(i = 0; i < n; i++) {\n        muldq(t1, t0, taba[i], b);\n        adddq(t1, t0, 0, l);\n        divdq_base(l, r, t1, t0);\n        tabr[i] = r;\n    }\n    return l;\n}\n\n/* tabr[] += taba[] * b. 0 <= b <= base - 1. Return the value to add\n   to the high word */\nlimb_t mp_add_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,\n                       limb_t b)\n{\n    mp_size_t i;\n    limb_t l, t0, t1, r;\n\n    l = 0;\n    for(i = 0; i < n; i++) {\n        muldq(t1, t0, taba[i], b);\n        adddq(t1, t0, 0, l);\n        adddq(t1, t0, 0, tabr[i]);\n        divdq_base(l, r, t1, t0);\n        tabr[i] = r;\n    }\n    return l;\n}\n\n/* tabr[] -= taba[] * b. 0 <= b <= base - 1. Return the value to\n   substract to the high word. */\nlimb_t mp_sub_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,\n                       limb_t b)\n{\n    limb_t base = BF_DEC_BASE;\n    mp_size_t i;\n    limb_t l, t0, t1, r, a, v, c;\n\n    /* XXX: optimize */\n    l = 0;\n    for(i = 0; i < n; i++) {\n        muldq(t1, t0, taba[i], b);\n        adddq(t1, t0, 0, l);\n        divdq_base(l, r, t1, t0);\n        v = tabr[i];\n        a = v - r;\n        c = a > v;\n        if (c)\n            a += base;\n        /* never bigger than base because r = 0 when l = base - 1 */\n        l += c;\n        tabr[i] = a;\n    }\n    return l;\n}\n\n/* size of the result : op1_size + op2_size. */\nvoid mp_mul_basecase_dec(limb_t *result, \n                         const limb_t *op1, mp_size_t op1_size, \n                         const limb_t *op2, mp_size_t op2_size) \n{\n    mp_size_t i;\n    limb_t r;\n    \n    result[op1_size] = mp_mul1_dec(result, op1, op1_size, op2[0], 0);\n\n    for(i=1;i<op2_size;i++) {\n        r = mp_add_mul1_dec(result + i, op1, op1_size, op2[i]);\n        result[i + op1_size] = r;\n    }\n}\n\n/* taba[] = (taba[] + r*base^na) / b. 0 <= b < base. 0 <= r <\n   b. Return the remainder. */\nlimb_t mp_div1_dec(limb_t *tabr, const limb_t *taba, mp_size_t na, \n                   limb_t b, limb_t r)\n{\n    limb_t base = BF_DEC_BASE;\n    mp_size_t i;\n    limb_t t0, t1, q;\n    int shift;\n\n#if (BF_DEC_BASE % 2) == 0\n    if (b == 2) {\n        limb_t base_div2;\n        /* Note: only works if base is even */\n        base_div2 = base >> 1;\n        if (r)\n            r = base_div2;\n        for(i = na - 1; i >= 0; i--) {\n            t0 = taba[i];\n            tabr[i] = (t0 >> 1) + r;\n            r = 0;\n            if (t0 & 1)\n                r = base_div2;\n        }\n        if (r)\n            r = 1;\n    } else \n#endif\n    if (na >= UDIV1NORM_THRESHOLD) {\n        shift = clz(b);\n        if (shift == 0) {\n            /* normalized case: b >= 2^(LIMB_BITS-1) */\n            limb_t b_inv;\n            b_inv = udiv1norm_init(b);\n            for(i = na - 1; i >= 0; i--) {\n                muldq(t1, t0, r, base);\n                adddq(t1, t0, 0, taba[i]);\n                q = udiv1norm(&r, t1, t0, b, b_inv);\n                tabr[i] = q;\n            }\n        } else {\n            limb_t b_inv;\n            b <<= shift;\n            b_inv = udiv1norm_init(b);\n            for(i = na - 1; i >= 0; i--) {\n                muldq(t1, t0, r, base);\n                adddq(t1, t0, 0, taba[i]);\n                t1 = (t1 << shift) | (t0 >> (LIMB_BITS - shift));\n                t0 <<= shift;\n                q = udiv1norm(&r, t1, t0, b, b_inv);\n                r >>= shift;\n                tabr[i] = q;\n            }\n        }\n    } else {\n        for(i = na - 1; i >= 0; i--) {\n            muldq(t1, t0, r, base);\n            adddq(t1, t0, 0, taba[i]);\n            divdq(q, r, t1, t0, b);\n            tabr[i] = q;\n        }\n    }\n    return r;\n}\n\nstatic __maybe_unused void mp_print_str_dec(const char *str,\n                                       const limb_t *tab, slimb_t n)\n{\n    slimb_t i;\n    printf(\"%s=\", str);\n    for(i = n - 1; i >= 0; i--) {\n        if (i != n - 1)\n            printf(\"_\");\n        printf(\"%0*\" PRIu_LIMB, LIMB_DIGITS, tab[i]);\n    }\n    printf(\"\\n\");\n}\n\nstatic __maybe_unused void mp_print_str_h_dec(const char *str,\n                                              const limb_t *tab, slimb_t n,\n                                              limb_t high)\n{\n    slimb_t i;\n    printf(\"%s=\", str);\n    printf(\"%0*\" PRIu_LIMB, LIMB_DIGITS, high);\n    for(i = n - 1; i >= 0; i--) {\n        printf(\"_\");\n        printf(\"%0*\" PRIu_LIMB, LIMB_DIGITS, tab[i]);\n    }\n    printf(\"\\n\");\n}\n\n//#define DEBUG_DIV_SLOW\n\n#define DIV_STATIC_ALLOC_LEN 16\n\n/* return q = a / b and r = a % b. \n\n   taba[na] must be allocated if tabb1[nb - 1] < B / 2.  tabb1[nb - 1]\n   must be != zero. na must be >= nb. 's' can be NULL if tabb1[nb - 1]\n   >= B / 2.\n\n   The remainder is is returned in taba and contains nb libms. tabq\n   contains na - nb + 1 limbs. No overlap is permitted.\n\n   Running time of the standard method: (na - nb + 1) * nb\n   Return 0 if OK, -1 if memory alloc error\n*/\n/* XXX: optimize */\nstatic int mp_div_dec(bf_context_t *s, limb_t *tabq,\n                      limb_t *taba, mp_size_t na, \n                      const limb_t *tabb1, mp_size_t nb)\n{\n    limb_t base = BF_DEC_BASE;\n    limb_t r, mult, t0, t1, a, c, q, v, *tabb;\n    mp_size_t i, j;\n    limb_t static_tabb[DIV_STATIC_ALLOC_LEN];\n    \n#ifdef DEBUG_DIV_SLOW\n    mp_print_str_dec(\"a\", taba, na);\n    mp_print_str_dec(\"b\", tabb1, nb);\n#endif\n\n    /* normalize tabb */\n    r = tabb1[nb - 1];\n    assert(r != 0);\n    i = na - nb;\n    if (r >= BF_DEC_BASE / 2) {\n        mult = 1;\n        tabb = (limb_t *)tabb1;\n        q = 1;\n        for(j = nb - 1; j >= 0; j--) {\n            if (taba[i + j] != tabb[j]) {\n                if (taba[i + j] < tabb[j])\n                    q = 0;\n                break;\n            }\n        }\n        tabq[i] = q;\n        if (q) {\n            mp_sub_dec(taba + i, taba + i, tabb, nb, 0);\n        }\n        i--;\n    } else {\n        mult = base / (r + 1);\n        if (likely(nb <= DIV_STATIC_ALLOC_LEN)) {\n            tabb = static_tabb;\n        } else {\n            tabb = bf_malloc(s, sizeof(limb_t) * nb);\n            if (!tabb)\n                return -1;\n        }\n        mp_mul1_dec(tabb, tabb1, nb, mult, 0);\n        taba[na] = mp_mul1_dec(taba, taba, na, mult, 0);\n    }\n\n#ifdef DEBUG_DIV_SLOW\n    printf(\"mult=\" FMT_LIMB \"\\n\", mult);\n    mp_print_str_dec(\"a_norm\", taba, na + 1);\n    mp_print_str_dec(\"b_norm\", tabb, nb);\n#endif\n\n    for(; i >= 0; i--) {\n        if (unlikely(taba[i + nb] >= tabb[nb - 1])) {\n            /* XXX: check if it is really possible */\n            q = base - 1;\n        } else {\n            muldq(t1, t0, taba[i + nb], base);\n            adddq(t1, t0, 0, taba[i + nb - 1]);\n            divdq(q, r, t1, t0, tabb[nb - 1]);\n        }\n        //        printf(\"i=%d q1=%ld\\n\", i, q);\n\n        r = mp_sub_mul1_dec(taba + i, tabb, nb, q);\n        //        mp_dump(\"r1\", taba + i, nb, bd);\n        //        printf(\"r2=%ld\\n\", r);\n\n        v = taba[i + nb];\n        a = v - r;\n        c = a > v;\n        if (c)\n            a += base;\n        taba[i + nb] = a;\n\n        if (c != 0) {\n            /* negative result */\n            for(;;) {\n                q--;\n                c = mp_add_dec(taba + i, taba + i, tabb, nb, 0);\n                /* propagate carry and test if positive result */\n                if (c != 0) {\n                    if (++taba[i + nb] == base) {\n                        break;\n                    }\n                }\n            }\n        }\n        tabq[i] = q;\n    }\n\n#ifdef DEBUG_DIV_SLOW\n    mp_print_str_dec(\"q\", tabq, na - nb + 1);\n    mp_print_str_dec(\"r\", taba, nb);\n#endif\n\n    /* remove the normalization */\n    if (mult != 1) {\n        mp_div1_dec(taba, taba, nb, mult, 0);\n        if (unlikely(tabb != static_tabb))\n            bf_free(s, tabb);\n    }\n    return 0;\n}\n\n/* divide by 10^shift */\nstatic limb_t mp_shr_dec(limb_t *tab_r, const limb_t *tab, mp_size_t n, \n                         limb_t shift, limb_t high)\n{\n    mp_size_t i;\n    limb_t l, a, q, r;\n\n    assert(shift >= 1 && shift < LIMB_DIGITS);\n    l = high;\n    for(i = n - 1; i >= 0; i--) {\n        a = tab[i];\n        fast_shr_rem_dec(q, r, a, shift);\n        tab_r[i] = q + l * mp_pow_dec[LIMB_DIGITS - shift];\n        l = r;\n    }\n    return l;\n}\n\n/* multiply by 10^shift */\nstatic limb_t mp_shl_dec(limb_t *tab_r, const limb_t *tab, mp_size_t n, \n                         limb_t shift, limb_t low)\n{\n    mp_size_t i;\n    limb_t l, a, q, r;\n\n    assert(shift >= 1 && shift < LIMB_DIGITS);\n    l = low;\n    for(i = 0; i < n; i++) {\n        a = tab[i];\n        fast_shr_rem_dec(q, r, a, LIMB_DIGITS - shift);\n        tab_r[i] = r * mp_pow_dec[shift] + l;\n        l = q;\n    }\n    return l;\n}\n\nstatic limb_t mp_sqrtrem2_dec(limb_t *tabs, limb_t *taba)\n{\n    int k;\n    dlimb_t a, b, r;\n    limb_t taba1[2], s, r0, r1;\n\n    /* convert to binary and normalize */\n    a = (dlimb_t)taba[1] * BF_DEC_BASE + taba[0];\n    k = clz(a >> LIMB_BITS) & ~1;\n    b = a << k;\n    taba1[0] = b;\n    taba1[1] = b >> LIMB_BITS;\n    mp_sqrtrem2(&s, taba1);\n    s >>= (k >> 1);\n    /* convert the remainder back to decimal */\n    r = a - (dlimb_t)s * (dlimb_t)s;\n    divdq_base(r1, r0, r >> LIMB_BITS, r);\n    taba[0] = r0;\n    tabs[0] = s;\n    return r1;\n}\n\n//#define DEBUG_SQRTREM_DEC\n\n/* tmp_buf must contain (n / 2 + 1 limbs) */\nstatic limb_t mp_sqrtrem_rec_dec(limb_t *tabs, limb_t *taba, limb_t n,\n                                 limb_t *tmp_buf)\n{\n    limb_t l, h, rh, ql, qh, c, i;\n    \n    if (n == 1)\n        return mp_sqrtrem2_dec(tabs, taba);\n#ifdef DEBUG_SQRTREM_DEC\n    mp_print_str_dec(\"a\", taba, 2 * n);\n#endif\n    l = n / 2;\n    h = n - l;\n    qh = mp_sqrtrem_rec_dec(tabs + l, taba + 2 * l, h, tmp_buf);\n#ifdef DEBUG_SQRTREM_DEC\n    mp_print_str_dec(\"s1\", tabs + l, h);\n    mp_print_str_h_dec(\"r1\", taba + 2 * l, h, qh);\n    mp_print_str_h_dec(\"r2\", taba + l, n, qh);\n#endif\n    \n    /* the remainder is in taba + 2 * l. Its high bit is in qh */\n    if (qh) {\n        mp_sub_dec(taba + 2 * l, taba + 2 * l, tabs + l, h, 0);\n    }\n    /* instead of dividing by 2*s, divide by s (which is normalized)\n       and update q and r */\n    mp_div_dec(NULL, tmp_buf, taba + l, n, tabs + l, h);\n    qh += tmp_buf[l];\n    for(i = 0; i < l; i++)\n        tabs[i] = tmp_buf[i];\n    ql = mp_div1_dec(tabs, tabs, l, 2, qh & 1);\n    qh = qh >> 1; /* 0 or 1 */\n    if (ql)\n        rh = mp_add_dec(taba + l, taba + l, tabs + l, h, 0);\n    else\n        rh = 0;\n#ifdef DEBUG_SQRTREM_DEC\n    mp_print_str_h_dec(\"q\", tabs, l, qh);\n    mp_print_str_h_dec(\"u\", taba + l, h, rh);\n#endif\n    \n    mp_add_ui_dec(tabs + l, qh, h);\n#ifdef DEBUG_SQRTREM_DEC\n    mp_print_str_dec(\"s2\", tabs, n);\n#endif\n    \n    /* q = qh, tabs[l - 1 ... 0], r = taba[n - 1 ... l] */\n    /* subtract q^2. if qh = 1 then q = B^l, so we can take shortcuts */\n    if (qh) {\n        c = qh;\n    } else {\n        mp_mul_basecase_dec(taba + n, tabs, l, tabs, l);\n        c = mp_sub_dec(taba, taba, taba + n, 2 * l, 0);\n    }\n    rh -= mp_sub_ui_dec(taba + 2 * l, c, n - 2 * l);\n    if ((slimb_t)rh < 0) {\n        mp_sub_ui_dec(tabs, 1, n);\n        rh += mp_add_mul1_dec(taba, tabs, n, 2);\n        rh += mp_add_ui_dec(taba, 1, n);\n    }\n    return rh;\n}\n\n/* 'taba' has 2*n limbs with n >= 1 and taba[2*n-1] >= B/4. Return (s,\n   r) with s=floor(sqrt(a)) and r=a-s^2. 0 <= r <= 2 * s. tabs has n\n   limbs. r is returned in the lower n limbs of taba. Its r[n] is the\n   returned value of the function. */\nint mp_sqrtrem_dec(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n)\n{\n    limb_t tmp_buf1[8];\n    limb_t *tmp_buf;\n    mp_size_t n2;\n    n2 = n / 2 + 1;\n    if (n2 <= countof(tmp_buf1)) {\n        tmp_buf = tmp_buf1;\n    } else {\n        tmp_buf = bf_malloc(s, sizeof(limb_t) * n2);\n        if (!tmp_buf)\n            return -1;\n    }\n    taba[n] = mp_sqrtrem_rec_dec(tabs, taba, n, tmp_buf);\n    if (tmp_buf != tmp_buf1)\n        bf_free(s, tmp_buf);\n    return 0;\n}\n\n/* return the number of leading zero digits, from 0 to LIMB_DIGITS */\nstatic int clz_dec(limb_t a)\n{\n    if (a == 0)\n        return LIMB_DIGITS;\n    switch(LIMB_BITS - 1 - clz(a)) {\n    case 0: /* 1-1 */\n        return LIMB_DIGITS - 1;\n    case 1: /* 2-3 */\n        return LIMB_DIGITS - 1;\n    case 2: /* 4-7 */\n        return LIMB_DIGITS - 1;\n    case 3: /* 8-15 */\n        if (a < 10)\n            return LIMB_DIGITS - 1;\n        else\n            return LIMB_DIGITS - 2;\n    case 4: /* 16-31 */\n        return LIMB_DIGITS - 2;\n    case 5: /* 32-63 */\n        return LIMB_DIGITS - 2;\n    case 6: /* 64-127 */\n        if (a < 100)\n            return LIMB_DIGITS - 2;\n        else\n            return LIMB_DIGITS - 3;\n    case 7: /* 128-255 */\n        return LIMB_DIGITS - 3;\n    case 8: /* 256-511 */\n        return LIMB_DIGITS - 3;\n    case 9: /* 512-1023 */\n        if (a < 1000)\n            return LIMB_DIGITS - 3;\n        else\n            return LIMB_DIGITS - 4;\n    case 10: /* 1024-2047 */\n        return LIMB_DIGITS - 4;\n    case 11: /* 2048-4095 */\n        return LIMB_DIGITS - 4;\n    case 12: /* 4096-8191 */\n        return LIMB_DIGITS - 4;\n    case 13: /* 8192-16383 */\n        if (a < 10000)\n            return LIMB_DIGITS - 4;\n        else\n            return LIMB_DIGITS - 5;\n    case 14: /* 16384-32767 */\n        return LIMB_DIGITS - 5;\n    case 15: /* 32768-65535 */\n        return LIMB_DIGITS - 5;\n    case 16: /* 65536-131071 */\n        if (a < 100000)\n            return LIMB_DIGITS - 5;\n        else\n            return LIMB_DIGITS - 6;\n    case 17: /* 131072-262143 */\n        return LIMB_DIGITS - 6;\n    case 18: /* 262144-524287 */\n        return LIMB_DIGITS - 6;\n    case 19: /* 524288-1048575 */\n        if (a < 1000000)\n            return LIMB_DIGITS - 6;\n        else\n            return LIMB_DIGITS - 7;\n    case 20: /* 1048576-2097151 */\n        return LIMB_DIGITS - 7;\n    case 21: /* 2097152-4194303 */\n        return LIMB_DIGITS - 7;\n    case 22: /* 4194304-8388607 */\n        return LIMB_DIGITS - 7;\n    case 23: /* 8388608-16777215 */\n        if (a < 10000000)\n            return LIMB_DIGITS - 7;\n        else\n            return LIMB_DIGITS - 8;\n    case 24: /* 16777216-33554431 */\n        return LIMB_DIGITS - 8;\n    case 25: /* 33554432-67108863 */\n        return LIMB_DIGITS - 8;\n    case 26: /* 67108864-134217727 */\n        if (a < 100000000)\n            return LIMB_DIGITS - 8;\n        else\n            return LIMB_DIGITS - 9;\n#if LIMB_BITS == 64\n    case 27: /* 134217728-268435455 */\n        return LIMB_DIGITS - 9;\n    case 28: /* 268435456-536870911 */\n        return LIMB_DIGITS - 9;\n    case 29: /* 536870912-1073741823 */\n        if (a < 1000000000)\n            return LIMB_DIGITS - 9;\n        else\n            return LIMB_DIGITS - 10;\n    case 30: /* 1073741824-2147483647 */\n        return LIMB_DIGITS - 10;\n    case 31: /* 2147483648-4294967295 */\n        return LIMB_DIGITS - 10;\n    case 32: /* 4294967296-8589934591 */\n        return LIMB_DIGITS - 10;\n    case 33: /* 8589934592-17179869183 */\n        if (a < 10000000000)\n            return LIMB_DIGITS - 10;\n        else\n            return LIMB_DIGITS - 11;\n    case 34: /* 17179869184-34359738367 */\n        return LIMB_DIGITS - 11;\n    case 35: /* 34359738368-68719476735 */\n        return LIMB_DIGITS - 11;\n    case 36: /* 68719476736-137438953471 */\n        if (a < 100000000000)\n            return LIMB_DIGITS - 11;\n        else\n            return LIMB_DIGITS - 12;\n    case 37: /* 137438953472-274877906943 */\n        return LIMB_DIGITS - 12;\n    case 38: /* 274877906944-549755813887 */\n        return LIMB_DIGITS - 12;\n    case 39: /* 549755813888-1099511627775 */\n        if (a < 1000000000000)\n            return LIMB_DIGITS - 12;\n        else\n            return LIMB_DIGITS - 13;\n    case 40: /* 1099511627776-2199023255551 */\n        return LIMB_DIGITS - 13;\n    case 41: /* 2199023255552-4398046511103 */\n        return LIMB_DIGITS - 13;\n    case 42: /* 4398046511104-8796093022207 */\n        return LIMB_DIGITS - 13;\n    case 43: /* 8796093022208-17592186044415 */\n        if (a < 10000000000000)\n            return LIMB_DIGITS - 13;\n        else\n            return LIMB_DIGITS - 14;\n    case 44: /* 17592186044416-35184372088831 */\n        return LIMB_DIGITS - 14;\n    case 45: /* 35184372088832-70368744177663 */\n        return LIMB_DIGITS - 14;\n    case 46: /* 70368744177664-140737488355327 */\n        if (a < 100000000000000)\n            return LIMB_DIGITS - 14;\n        else\n            return LIMB_DIGITS - 15;\n    case 47: /* 140737488355328-281474976710655 */\n        return LIMB_DIGITS - 15;\n    case 48: /* 281474976710656-562949953421311 */\n        return LIMB_DIGITS - 15;\n    case 49: /* 562949953421312-1125899906842623 */\n        if (a < 1000000000000000)\n            return LIMB_DIGITS - 15;\n        else\n            return LIMB_DIGITS - 16;\n    case 50: /* 1125899906842624-2251799813685247 */\n        return LIMB_DIGITS - 16;\n    case 51: /* 2251799813685248-4503599627370495 */\n        return LIMB_DIGITS - 16;\n    case 52: /* 4503599627370496-9007199254740991 */\n        return LIMB_DIGITS - 16;\n    case 53: /* 9007199254740992-18014398509481983 */\n        if (a < 10000000000000000)\n            return LIMB_DIGITS - 16;\n        else\n            return LIMB_DIGITS - 17;\n    case 54: /* 18014398509481984-36028797018963967 */\n        return LIMB_DIGITS - 17;\n    case 55: /* 36028797018963968-72057594037927935 */\n        return LIMB_DIGITS - 17;\n    case 56: /* 72057594037927936-144115188075855871 */\n        if (a < 100000000000000000)\n            return LIMB_DIGITS - 17;\n        else\n            return LIMB_DIGITS - 18;\n    case 57: /* 144115188075855872-288230376151711743 */\n        return LIMB_DIGITS - 18;\n    case 58: /* 288230376151711744-576460752303423487 */\n        return LIMB_DIGITS - 18;\n    case 59: /* 576460752303423488-1152921504606846975 */\n        if (a < 1000000000000000000)\n            return LIMB_DIGITS - 18;\n        else\n            return LIMB_DIGITS - 19;\n#endif\n    default:\n        return 0;\n    }\n}\n\n/* for debugging */\nvoid bfdec_print_str(const char *str, const bfdec_t *a)\n{\n    slimb_t i;\n    printf(\"%s=\", str);\n\n    if (a->expn == BF_EXP_NAN) {\n        printf(\"NaN\");\n    } else {\n        if (a->sign)\n            putchar('-');\n        if (a->expn == BF_EXP_ZERO) {\n            putchar('0');\n        } else if (a->expn == BF_EXP_INF) {\n            printf(\"Inf\");\n        } else {\n            printf(\"0.\");\n            for(i = a->len - 1; i >= 0; i--)\n                printf(\"%0*\" PRIu_LIMB, LIMB_DIGITS, a->tab[i]);\n            printf(\"e%\" PRId_LIMB, a->expn);\n        }\n    }\n    printf(\"\\n\");\n}\n\n/* return != 0 if one digit between 0 and bit_pos inclusive is not zero. */\nstatic inline limb_t scan_digit_nz(const bfdec_t *r, slimb_t bit_pos)\n{\n    slimb_t pos;\n    limb_t v, q;\n    int shift;\n\n    if (bit_pos < 0)\n        return 0;\n    pos = (limb_t)bit_pos / LIMB_DIGITS;\n    shift = (limb_t)bit_pos % LIMB_DIGITS;\n    fast_shr_rem_dec(q, v, r->tab[pos], shift + 1);\n    (void)q;\n    if (v != 0)\n        return 1;\n    pos--;\n    while (pos >= 0) {\n        if (r->tab[pos] != 0)\n            return 1;\n        pos--;\n    }\n    return 0;\n}\n\nstatic limb_t get_digit(const limb_t *tab, limb_t len, slimb_t pos)\n{\n    slimb_t i;\n    int shift;\n    i = floor_div(pos, LIMB_DIGITS);\n    if (i < 0 || i >= len)\n        return 0;\n    shift = pos - i * LIMB_DIGITS;\n    return fast_shr_dec(tab[i], shift) % 10;\n}\n\n#if 0\nstatic limb_t get_digits(const limb_t *tab, limb_t len, slimb_t pos)\n{\n    limb_t a0, a1;\n    int shift;\n    slimb_t i;\n    \n    i = floor_div(pos, LIMB_DIGITS);\n    shift = pos - i * LIMB_DIGITS;\n    if (i >= 0 && i < len)\n        a0 = tab[i];\n    else\n        a0 = 0;\n    if (shift == 0) {\n        return a0;\n    } else {\n        i++;\n        if (i >= 0 && i < len)\n            a1 = tab[i];\n        else\n            a1 = 0;\n        return fast_shr_dec(a0, shift) +\n            fast_urem(a1, &mp_pow_div[LIMB_DIGITS - shift]) *\n            mp_pow_dec[shift];\n    }\n}\n#endif\n\n/* return the addend for rounding. Note that prec can be <= 0 for bf_rint() */\nstatic int bfdec_get_rnd_add(int *pret, const bfdec_t *r, limb_t l,\n                             slimb_t prec, int rnd_mode)\n{\n    int add_one, inexact;\n    limb_t digit1, digit0;\n    \n    //    bfdec_print_str(\"get_rnd_add\", r);\n    if (rnd_mode == BF_RNDF) {\n        digit0 = 1; /* faithful rounding does not honor the INEXACT flag */\n    } else {\n        /* starting limb for bit 'prec + 1' */\n        digit0 = scan_digit_nz(r, l * LIMB_DIGITS - 1 - bf_max(0, prec + 1));\n    }\n\n    /* get the digit at 'prec' */\n    digit1 = get_digit(r->tab, l, l * LIMB_DIGITS - 1 - prec);\n    inexact = (digit1 | digit0) != 0;\n    \n    add_one = 0;\n    switch(rnd_mode) {\n    case BF_RNDZ:\n        break;\n    case BF_RNDN:\n        if (digit1 == 5) {\n            if (digit0) {\n                add_one = 1;\n            } else {\n                /* round to even */\n                add_one =\n                    get_digit(r->tab, l, l * LIMB_DIGITS - 1 - (prec - 1)) & 1;\n            }\n        } else if (digit1 > 5) {\n            add_one = 1;\n        }\n        break;\n    case BF_RNDD:\n    case BF_RNDU:\n        if (r->sign == (rnd_mode == BF_RNDD))\n            add_one = inexact;\n        break;\n    case BF_RNDNA:\n    case BF_RNDF:\n        add_one = (digit1 >= 5);\n        break;\n    case BF_RNDA:\n        add_one = inexact;\n        break;\n    default:\n        abort();\n    }\n    \n    if (inexact)\n        *pret |= BF_ST_INEXACT;\n    return add_one;\n}\n\n/* round to prec1 bits assuming 'r' is non zero and finite. 'r' is\n   assumed to have length 'l' (1 <= l <= r->len). prec1 can be\n   BF_PREC_INF. BF_FLAG_SUBNORMAL is not supported. Cannot fail with\n   BF_ST_MEM_ERROR.\n */\nstatic int __bfdec_round(bfdec_t *r, limb_t prec1, bf_flags_t flags, limb_t l)\n{\n    int shift, add_one, rnd_mode, ret;\n    slimb_t i, bit_pos, pos, e_min, e_max, e_range, prec;\n\n    /* XXX: align to IEEE 754 2008 for decimal numbers ? */\n    e_range = (limb_t)1 << (bf_get_exp_bits(flags) - 1);\n    e_min = -e_range + 3;\n    e_max = e_range;\n    \n    if (flags & BF_FLAG_RADPNT_PREC) {\n        /* 'prec' is the precision after the decimal point */\n        if (prec1 != BF_PREC_INF)\n            prec = r->expn + prec1;\n        else\n            prec = prec1;\n    } else if (unlikely(r->expn < e_min) && (flags & BF_FLAG_SUBNORMAL)) {\n        /* restrict the precision in case of potentially subnormal\n           result */\n        assert(prec1 != BF_PREC_INF);\n        prec = prec1 - (e_min - r->expn);\n    } else {\n        prec = prec1;\n    }\n    \n    /* round to prec bits */\n    rnd_mode = flags & BF_RND_MASK;\n    ret = 0;\n    add_one = bfdec_get_rnd_add(&ret, r, l, prec, rnd_mode);\n    \n    if (prec <= 0) {\n        if (add_one) {\n            bfdec_resize(r, 1); /* cannot fail because r is non zero */\n            r->tab[0] = BF_DEC_BASE / 10;\n            r->expn += 1 - prec;\n            ret |= BF_ST_UNDERFLOW | BF_ST_INEXACT;\n            return ret;\n        } else {\n            goto underflow;\n        }\n    } else if (add_one) {\n        limb_t carry;\n        \n        /* add one starting at digit 'prec - 1' */\n        bit_pos = l * LIMB_DIGITS - 1 - (prec - 1);\n        pos = bit_pos / LIMB_DIGITS;\n        carry = mp_pow_dec[bit_pos % LIMB_DIGITS];\n        carry = mp_add_ui_dec(r->tab + pos, carry, l - pos);\n        if (carry) {\n            /* shift right by one digit */\n            mp_shr_dec(r->tab + pos, r->tab + pos, l - pos, 1, 1);\n            r->expn++;\n        }\n    }\n    \n    /* check underflow */\n    if (unlikely(r->expn < e_min)) {\n        if (flags & BF_FLAG_SUBNORMAL) {\n            /* if inexact, also set the underflow flag */\n            if (ret & BF_ST_INEXACT)\n                ret |= BF_ST_UNDERFLOW;\n        } else {\n        underflow:\n            bfdec_set_zero(r, r->sign);\n            ret |= BF_ST_UNDERFLOW | BF_ST_INEXACT;\n            return ret;\n        }\n    }\n    \n    /* check overflow */\n    if (unlikely(r->expn > e_max)) {\n        bfdec_set_inf(r, r->sign);\n        ret |= BF_ST_OVERFLOW | BF_ST_INEXACT;\n        return ret;\n    }\n    \n    /* keep the bits starting at 'prec - 1' */\n    bit_pos = l * LIMB_DIGITS - 1 - (prec - 1);\n    i = floor_div(bit_pos, LIMB_DIGITS);\n    if (i >= 0) {\n        shift = smod(bit_pos, LIMB_DIGITS);\n        if (shift != 0) {\n            r->tab[i] = fast_shr_dec(r->tab[i], shift) *\n                mp_pow_dec[shift];\n        }\n    } else {\n        i = 0;\n    }\n    /* remove trailing zeros */\n    while (r->tab[i] == 0)\n        i++;\n    if (i > 0) {\n        l -= i;\n        memmove(r->tab, r->tab + i, l * sizeof(limb_t));\n    }\n    bfdec_resize(r, l); /* cannot fail */\n    return ret;\n}\n\n/* Cannot fail with BF_ST_MEM_ERROR. */\nint bfdec_round(bfdec_t *r, limb_t prec, bf_flags_t flags)\n{\n    if (r->len == 0)\n        return 0;\n    return __bfdec_round(r, prec, flags, r->len);\n}\n\n/* 'r' must be a finite number. Cannot fail with BF_ST_MEM_ERROR.  */\nint bfdec_normalize_and_round(bfdec_t *r, limb_t prec1, bf_flags_t flags)\n{\n    limb_t l, v;\n    int shift, ret;\n    \n    //    bfdec_print_str(\"bf_renorm\", r);\n    l = r->len;\n    while (l > 0 && r->tab[l - 1] == 0)\n        l--;\n    if (l == 0) {\n        /* zero */\n        r->expn = BF_EXP_ZERO;\n        bfdec_resize(r, 0); /* cannot fail */\n        ret = 0;\n    } else {\n        r->expn -= (r->len - l) * LIMB_DIGITS;\n        /* shift to have the MSB set to '1' */\n        v = r->tab[l - 1];\n        shift = clz_dec(v);\n        if (shift != 0) {\n            mp_shl_dec(r->tab, r->tab, l, shift, 0);\n            r->expn -= shift;\n        }\n        ret = __bfdec_round(r, prec1, flags, l);\n    }\n    //    bf_print_str(\"r_final\", r);\n    return ret;\n}\n\nint bfdec_set_ui(bfdec_t *r, uint64_t v)\n{\n#if LIMB_BITS == 32\n    if (v >= BF_DEC_BASE * BF_DEC_BASE) {\n        if (bfdec_resize(r, 3))\n            goto fail;\n        r->tab[0] = v % BF_DEC_BASE;\n        v /= BF_DEC_BASE;\n        r->tab[1] = v % BF_DEC_BASE;\n        r->tab[2] = v / BF_DEC_BASE;\n        r->expn = 3 * LIMB_DIGITS;\n    } else\n#endif\n    if (v >= BF_DEC_BASE) {\n        if (bfdec_resize(r, 2))\n            goto fail;\n        r->tab[0] = v % BF_DEC_BASE;\n        r->tab[1] = v / BF_DEC_BASE;\n        r->expn = 2 * LIMB_DIGITS;\n    } else {\n        if (bfdec_resize(r, 1))\n            goto fail;\n        r->tab[0] = v;\n        r->expn = LIMB_DIGITS;\n    }\n    r->sign = 0;\n    return bfdec_normalize_and_round(r, BF_PREC_INF, 0);\n fail:\n    bfdec_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nint bfdec_set_si(bfdec_t *r, int64_t v)\n{\n    int ret;\n    if (v < 0) {\n        ret = bfdec_set_ui(r, -v);\n        r->sign = 1;\n    } else {\n        ret = bfdec_set_ui(r, v);\n    }\n    return ret;\n}\n\nstatic int bfdec_add_internal(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, bf_flags_t flags, int b_neg)\n{\n    bf_context_t *s = r->ctx;\n    int is_sub, cmp_res, a_sign, b_sign, ret;\n\n    a_sign = a->sign;\n    b_sign = b->sign ^ b_neg;\n    is_sub = a_sign ^ b_sign;\n    cmp_res = bfdec_cmpu(a, b);\n    if (cmp_res < 0) {\n        const bfdec_t *tmp;\n        tmp = a;\n        a = b;\n        b = tmp;\n        a_sign = b_sign; /* b_sign is never used later */\n    }\n    /* abs(a) >= abs(b) */\n    if (cmp_res == 0 && is_sub && a->expn < BF_EXP_INF) {\n        /* zero result */\n        bfdec_set_zero(r, (flags & BF_RND_MASK) == BF_RNDD);\n        ret = 0;\n    } else if (a->len == 0 || b->len == 0) {\n        ret = 0;\n        if (a->expn >= BF_EXP_INF) {\n            if (a->expn == BF_EXP_NAN) {\n                /* at least one operand is NaN */\n                bfdec_set_nan(r);\n                ret = 0;\n            } else if (b->expn == BF_EXP_INF && is_sub) {\n                /* infinities with different signs */\n                bfdec_set_nan(r);\n                ret = BF_ST_INVALID_OP;\n            } else {\n                bfdec_set_inf(r, a_sign);\n            }\n        } else {\n            /* at least one zero and not subtract */\n            if (bfdec_set(r, a))\n                return BF_ST_MEM_ERROR;\n            r->sign = a_sign;\n            goto renorm;\n        }\n    } else {\n        slimb_t d, a_offset, b_offset, i, r_len;\n        limb_t carry;\n        limb_t *b1_tab;\n        int b_shift;\n        mp_size_t b1_len;\n        \n        d = a->expn - b->expn;\n\n        /* XXX: not efficient in time and memory if the precision is\n           not infinite */\n        r_len = bf_max(a->len, b->len + (d + LIMB_DIGITS - 1) / LIMB_DIGITS);\n        if (bfdec_resize(r, r_len))\n            goto fail;\n        r->sign = a_sign;\n        r->expn = a->expn;\n\n        a_offset = r_len - a->len;\n        for(i = 0; i < a_offset; i++)\n            r->tab[i] = 0;\n        for(i = 0; i < a->len; i++)\n            r->tab[a_offset + i] = a->tab[i];\n        \n        b_shift = d % LIMB_DIGITS;\n        if (b_shift == 0) {\n            b1_len = b->len;\n            b1_tab = (limb_t *)b->tab;\n        } else {\n            b1_len = b->len + 1;\n            b1_tab = bf_malloc(s, sizeof(limb_t) * b1_len);\n            if (!b1_tab)\n                goto fail;\n            b1_tab[0] = mp_shr_dec(b1_tab + 1, b->tab, b->len, b_shift, 0) *\n                mp_pow_dec[LIMB_DIGITS - b_shift];\n        }\n        b_offset = r_len - (b->len + (d + LIMB_DIGITS - 1) / LIMB_DIGITS);\n        \n        if (is_sub) {\n            carry = mp_sub_dec(r->tab + b_offset, r->tab + b_offset,\n                               b1_tab, b1_len, 0);\n            if (carry != 0) {\n                carry = mp_sub_ui_dec(r->tab + b_offset + b1_len, carry,\n                                      r_len - (b_offset + b1_len));\n                assert(carry == 0);\n            }\n        } else {\n            carry = mp_add_dec(r->tab + b_offset, r->tab + b_offset,\n                               b1_tab, b1_len, 0);\n            if (carry != 0) {\n                carry = mp_add_ui_dec(r->tab + b_offset + b1_len, carry,\n                                      r_len - (b_offset + b1_len));\n            }\n            if (carry != 0) {\n                if (bfdec_resize(r, r_len + 1)) {\n                    if (b_shift != 0)\n                        bf_free(s, b1_tab);\n                    goto fail;\n                }\n                r->tab[r_len] = 1;\n                r->expn += LIMB_DIGITS;\n            }\n        }\n        if (b_shift != 0)\n            bf_free(s, b1_tab);\n    renorm:\n        ret = bfdec_normalize_and_round(r, prec, flags);\n    }\n    return ret;\n fail:\n    bfdec_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nstatic int __bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n                     bf_flags_t flags)\n{\n    return bfdec_add_internal(r, a, b, prec, flags, 0);\n}\n\nstatic int __bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n                     bf_flags_t flags)\n{\n    return bfdec_add_internal(r, a, b, prec, flags, 1);\n}\n\nint bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags)\n{\n    return bf_op2((bf_t *)r, (bf_t *)a, (bf_t *)b, prec, flags,\n                  (bf_op2_func_t *)__bfdec_add);\n}\n\nint bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags)\n{\n    return bf_op2((bf_t *)r, (bf_t *)a, (bf_t *)b, prec, flags,\n                  (bf_op2_func_t *)__bfdec_sub);\n}\n\nint bfdec_mul(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags)\n{\n    int ret, r_sign;\n\n    if (a->len < b->len) {\n        const bfdec_t *tmp = a;\n        a = b;\n        b = tmp;\n    }\n    r_sign = a->sign ^ b->sign;\n    /* here b->len <= a->len */\n    if (b->len == 0) {\n        if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n            bfdec_set_nan(r);\n            ret = 0;\n        } else if (a->expn == BF_EXP_INF || b->expn == BF_EXP_INF) {\n            if ((a->expn == BF_EXP_INF && b->expn == BF_EXP_ZERO) ||\n                (a->expn == BF_EXP_ZERO && b->expn == BF_EXP_INF)) {\n                bfdec_set_nan(r);\n                ret = BF_ST_INVALID_OP;\n            } else {\n                bfdec_set_inf(r, r_sign);\n                ret = 0;\n            }\n        } else {\n            bfdec_set_zero(r, r_sign);\n            ret = 0;\n        }\n    } else {\n        bfdec_t tmp, *r1 = NULL;\n        limb_t a_len, b_len;\n        limb_t *a_tab, *b_tab;\n            \n        a_len = a->len;\n        b_len = b->len;\n        a_tab = a->tab;\n        b_tab = b->tab;\n        \n        if (r == a || r == b) {\n            bfdec_init(r->ctx, &tmp);\n            r1 = r;\n            r = &tmp;\n        }\n        if (bfdec_resize(r, a_len + b_len)) {\n            bfdec_set_nan(r);\n            ret = BF_ST_MEM_ERROR;\n            goto done;\n        }\n        mp_mul_basecase_dec(r->tab, a_tab, a_len, b_tab, b_len);\n        r->sign = r_sign;\n        r->expn = a->expn + b->expn;\n        ret = bfdec_normalize_and_round(r, prec, flags);\n    done:\n        if (r == &tmp)\n            bfdec_move(r1, &tmp);\n    }\n    return ret;\n}\n\nint bfdec_mul_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec,\n                 bf_flags_t flags)\n{\n    bfdec_t b;\n    int ret;\n    bfdec_init(r->ctx, &b);\n    ret = bfdec_set_si(&b, b1);\n    ret |= bfdec_mul(r, a, &b, prec, flags);\n    bfdec_delete(&b);\n    return ret;\n}\n\nint bfdec_add_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec,\n                 bf_flags_t flags)\n{\n    bfdec_t b;\n    int ret;\n    \n    bfdec_init(r->ctx, &b);\n    ret = bfdec_set_si(&b, b1);\n    ret |= bfdec_add(r, a, &b, prec, flags);\n    bfdec_delete(&b);\n    return ret;\n}\n\nstatic int __bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b,\n                       limb_t prec, bf_flags_t flags)\n{\n    int ret, r_sign;\n    limb_t n, nb, precl;\n    \n    r_sign = a->sign ^ b->sign;\n    if (a->expn >= BF_EXP_INF || b->expn >= BF_EXP_INF) {\n        if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n            bfdec_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF && b->expn == BF_EXP_INF) {\n            bfdec_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else if (a->expn == BF_EXP_INF) {\n            bfdec_set_inf(r, r_sign);\n            return 0;\n        } else {\n            bfdec_set_zero(r, r_sign);\n            return 0;\n        }\n    } else if (a->expn == BF_EXP_ZERO) {\n        if (b->expn == BF_EXP_ZERO) {\n            bfdec_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bfdec_set_zero(r, r_sign);\n            return 0;\n        }\n    } else if (b->expn == BF_EXP_ZERO) {\n        bfdec_set_inf(r, r_sign);\n        return BF_ST_DIVIDE_ZERO;\n    }\n\n    nb = b->len;\n    if (prec == BF_PREC_INF) {\n        /* infinite precision: return BF_ST_INVALID_OP if not an exact\n           result */\n        /* XXX: check */\n        precl = nb + 1;\n    } else if (flags & BF_FLAG_RADPNT_PREC) {\n        /* number of digits after the decimal point */\n        /* XXX: check (2 extra digits for rounding + 2 digits) */\n        precl = (bf_max(a->expn - b->expn, 0) + 2 +\n                 prec + 2 + LIMB_DIGITS - 1) / LIMB_DIGITS;\n    } else {\n        /* number of limbs of the quotient (2 extra digits for rounding) */\n        precl = (prec + 2 + LIMB_DIGITS - 1) / LIMB_DIGITS;\n    }\n    n = bf_max(a->len, precl);\n    \n    {\n        limb_t *taba, na, i;\n        slimb_t d;\n        \n        na = n + nb;\n        taba = bf_malloc(r->ctx, (na + 1) * sizeof(limb_t));\n        if (!taba)\n            goto fail;\n        d = na - a->len;\n        memset(taba, 0, d * sizeof(limb_t));\n        memcpy(taba + d, a->tab, a->len * sizeof(limb_t));\n        if (bfdec_resize(r, n + 1))\n            goto fail1;\n        if (mp_div_dec(r->ctx, r->tab, taba, na, b->tab, nb)) {\n        fail1:\n            bf_free(r->ctx, taba);\n            goto fail;\n        }\n        /* see if non zero remainder */\n        for(i = 0; i < nb; i++) {\n            if (taba[i] != 0)\n                break;\n        }\n        bf_free(r->ctx, taba);\n        if (i != nb) {\n            if (prec == BF_PREC_INF) {\n                bfdec_set_nan(r);\n                return BF_ST_INVALID_OP;\n            } else {\n                r->tab[0] |= 1;\n            }\n        }\n        r->expn = a->expn - b->expn + LIMB_DIGITS;\n        r->sign = r_sign;\n        ret = bfdec_normalize_and_round(r, prec, flags);\n    }\n    return ret;\n fail:\n    bfdec_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nint bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags)\n{\n    return bf_op2((bf_t *)r, (bf_t *)a, (bf_t *)b, prec, flags,\n                  (bf_op2_func_t *)__bfdec_div);\n}\n\n/* a and b must be finite numbers with a >= 0 and b > 0. 'q' is the\n   integer defined as floor(a/b) and r = a - q * b. */\nstatic void bfdec_tdivremu(bf_context_t *s, bfdec_t *q, bfdec_t *r,\n                           const bfdec_t *a, const bfdec_t *b)\n{\n    if (bfdec_cmpu(a, b) < 0) {\n        bfdec_set_ui(q, 0);\n        bfdec_set(r, a);\n    } else {\n        bfdec_div(q, a, b, 0, BF_RNDZ | BF_FLAG_RADPNT_PREC);\n        bfdec_mul(r, q, b, BF_PREC_INF, BF_RNDZ);\n        bfdec_sub(r, a, r, BF_PREC_INF, BF_RNDZ);\n    }\n}\n\n/* division and remainder. \n   \n   rnd_mode is the rounding mode for the quotient. The additional\n   rounding mode BF_RND_EUCLIDIAN is supported.\n\n   'q' is an integer. 'r' is rounded with prec and flags (prec can be\n   BF_PREC_INF).\n*/\nint bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b,\n                 limb_t prec, bf_flags_t flags, int rnd_mode)\n{\n    bf_context_t *s = q->ctx;\n    bfdec_t a1_s, *a1 = &a1_s;\n    bfdec_t b1_s, *b1 = &b1_s;\n    bfdec_t r1_s, *r1 = &r1_s;\n    int q_sign, res;\n    BOOL is_ceil, is_rndn;\n    \n    assert(q != a && q != b);\n    assert(r != a && r != b);\n    assert(q != r);\n    \n    if (a->len == 0 || b->len == 0) {\n        bfdec_set_zero(q, 0);\n        if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {\n            bfdec_set_nan(r);\n            return 0;\n        } else if (a->expn == BF_EXP_INF || b->expn == BF_EXP_ZERO) {\n            bfdec_set_nan(r);\n            return BF_ST_INVALID_OP;\n        } else {\n            bfdec_set(r, a);\n            return bfdec_round(r, prec, flags);\n        }\n    }\n\n    q_sign = a->sign ^ b->sign;\n    is_rndn = (rnd_mode == BF_RNDN || rnd_mode == BF_RNDNA);\n    switch(rnd_mode) {\n    default:\n    case BF_RNDZ:\n    case BF_RNDN:\n    case BF_RNDNA:\n        is_ceil = FALSE;\n        break;\n    case BF_RNDD:\n        is_ceil = q_sign;\n        break;\n    case BF_RNDU:\n        is_ceil = q_sign ^ 1;\n        break;\n    case BF_RNDA:\n        is_ceil = TRUE;\n        break;\n    case BF_DIVREM_EUCLIDIAN:\n        is_ceil = a->sign;\n        break;\n    }\n\n    a1->expn = a->expn;\n    a1->tab = a->tab;\n    a1->len = a->len;\n    a1->sign = 0;\n    \n    b1->expn = b->expn;\n    b1->tab = b->tab;\n    b1->len = b->len;\n    b1->sign = 0;\n\n    //    bfdec_print_str(\"a1\", a1);\n    //    bfdec_print_str(\"b1\", b1);\n    /* XXX: could improve to avoid having a large 'q' */\n    bfdec_tdivremu(s, q, r, a1, b1);\n    if (bfdec_is_nan(q) || bfdec_is_nan(r))\n        goto fail;\n    //    bfdec_print_str(\"q\", q);\n    //    bfdec_print_str(\"r\", r);\n    \n    if (r->len != 0) {\n        if (is_rndn) {\n            bfdec_init(s, r1);\n            if (bfdec_set(r1, r))\n                goto fail;\n            if (bfdec_mul_si(r1, r1, 2, BF_PREC_INF, BF_RNDZ)) {\n                bfdec_delete(r1);\n                goto fail;\n            }\n            res = bfdec_cmpu(r1, b);\n            bfdec_delete(r1);\n            if (res > 0 ||\n                (res == 0 &&\n                 (rnd_mode == BF_RNDNA ||\n                  (get_digit(q->tab, q->len, q->len * LIMB_DIGITS - q->expn) & 1) != 0))) {\n                goto do_sub_r;\n            }\n        } else if (is_ceil) {\n        do_sub_r:\n            res = bfdec_add_si(q, q, 1, BF_PREC_INF, BF_RNDZ);\n            res |= bfdec_sub(r, r, b1, BF_PREC_INF, BF_RNDZ);\n            if (res & BF_ST_MEM_ERROR)\n                goto fail;\n        }\n    }\n\n    r->sign ^= a->sign;\n    q->sign = q_sign;\n    return bfdec_round(r, prec, flags);\n fail:\n    bfdec_set_nan(q);\n    bfdec_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\nint bfdec_rem(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags, int rnd_mode)\n{\n    bfdec_t q_s, *q = &q_s;\n    int ret;\n    \n    bfdec_init(r->ctx, q);\n    ret = bfdec_divrem(q, r, a, b, prec, flags, rnd_mode);\n    bfdec_delete(q);\n    return ret;\n}\n\n/* convert to integer (infinite precision) */\nint bfdec_rint(bfdec_t *r, int rnd_mode)\n{\n    return bfdec_round(r, 0, rnd_mode | BF_FLAG_RADPNT_PREC);\n}\n\nint bfdec_sqrt(bfdec_t *r, const bfdec_t *a, limb_t prec, bf_flags_t flags)\n{\n    bf_context_t *s = a->ctx;\n    int ret, k;\n    limb_t *a1, v;\n    slimb_t n, n1, prec1;\n    limb_t res;\n\n    assert(r != a);\n\n    if (a->len == 0) {\n        if (a->expn == BF_EXP_NAN) {\n            bfdec_set_nan(r);\n        } else if (a->expn == BF_EXP_INF && a->sign) {\n            goto invalid_op;\n        } else {\n            bfdec_set(r, a);\n        }\n        ret = 0;\n    } else if (a->sign || prec == BF_PREC_INF) {\n invalid_op:\n        bfdec_set_nan(r);\n        ret = BF_ST_INVALID_OP;\n    } else {\n        if (flags & BF_FLAG_RADPNT_PREC) {\n            prec1 = bf_max(floor_div(a->expn + 1, 2) + prec, 1);\n        } else {\n            prec1 = prec;\n        }\n        /* convert the mantissa to an integer with at least 2 *\n           prec + 4 digits */\n        n = (2 * (prec1 + 2) + 2 * LIMB_DIGITS - 1) / (2 * LIMB_DIGITS);\n        if (bfdec_resize(r, n))\n            goto fail;\n        a1 = bf_malloc(s, sizeof(limb_t) * 2 * n);\n        if (!a1)\n            goto fail;\n        n1 = bf_min(2 * n, a->len);\n        memset(a1, 0, (2 * n - n1) * sizeof(limb_t));\n        memcpy(a1 + 2 * n - n1, a->tab + a->len - n1, n1 * sizeof(limb_t));\n        if (a->expn & 1) {\n            res = mp_shr_dec(a1, a1, 2 * n, 1, 0);\n        } else {\n            res = 0;\n        }\n        /* normalize so that a1 >= B^(2*n)/4. Not need for n = 1\n           because mp_sqrtrem2_dec already does it */\n        k = 0;\n        if (n > 1) {\n            v = a1[2 * n - 1];\n            while (v < BF_DEC_BASE / 4) {\n                k++;\n                v *= 4;\n            }\n            if (k != 0)\n                mp_mul1_dec(a1, a1, 2 * n, 1 << (2 * k), 0);\n        }\n        if (mp_sqrtrem_dec(s, r->tab, a1, n)) {\n            bf_free(s, a1);\n            goto fail;\n        }\n        if (k != 0)\n            mp_div1_dec(r->tab, r->tab, n, 1 << k, 0);\n        if (!res) {\n            res = mp_scan_nz(a1, n + 1);\n        }\n        bf_free(s, a1);\n        if (!res) {\n            res = mp_scan_nz(a->tab, a->len - n1);\n        }\n        if (res != 0)\n            r->tab[0] |= 1;\n        r->sign = 0;\n        r->expn = (a->expn + 1) >> 1;\n        ret = bfdec_round(r, prec, flags);\n    }\n    return ret;\n fail:\n    bfdec_set_nan(r);\n    return BF_ST_MEM_ERROR;\n}\n\n/* The rounding mode is always BF_RNDZ. Return BF_ST_OVERFLOW if there\n   is an overflow and 0 otherwise. No memory error is possible. */\nint bfdec_get_int32(int *pres, const bfdec_t *a)\n{\n    uint32_t v;\n    int ret;\n    if (a->expn >= BF_EXP_INF) {\n        ret = 0;\n        if (a->expn == BF_EXP_INF) {\n            v = (uint32_t)INT32_MAX + a->sign;\n             /* XXX: return overflow ? */\n        } else {\n            v = INT32_MAX;\n        }\n    } else if (a->expn <= 0) {\n        v = 0;\n        ret = 0;\n    } else if (a->expn <= 9) {\n        v = fast_shr_dec(a->tab[a->len - 1], LIMB_DIGITS - a->expn);\n        if (a->sign)\n            v = -v;\n        ret = 0;\n    } else if (a->expn == 10) {\n        uint64_t v1;\n        uint32_t v_max;\n#if LIMB_BITS == 64\n        v1 = fast_shr_dec(a->tab[a->len - 1], LIMB_DIGITS - a->expn);\n#else\n        v1 = (uint64_t)a->tab[a->len - 1] * 10 +\n            get_digit(a->tab, a->len, (a->len - 1) * LIMB_DIGITS - 1);\n#endif\n        v_max = (uint32_t)INT32_MAX + a->sign;\n        if (v1 > v_max) {\n            v = v_max;\n            ret = BF_ST_OVERFLOW;\n        } else {\n            v = v1;\n            if (a->sign)\n                v = -v;\n            ret = 0;\n        }\n    } else {\n        v = (uint32_t)INT32_MAX + a->sign;\n        ret = BF_ST_OVERFLOW;\n    }\n    *pres = v;\n    return ret;\n}\n\n/* power to an integer with infinite precision */\nint bfdec_pow_ui(bfdec_t *r, const bfdec_t *a, limb_t b)\n{\n    int ret, n_bits, i;\n    \n    assert(r != a);\n    if (b == 0)\n        return bfdec_set_ui(r, 1);\n    ret = bfdec_set(r, a);\n    n_bits = LIMB_BITS - clz(b);\n    for(i = n_bits - 2; i >= 0; i--) {\n        ret |= bfdec_mul(r, r, r, BF_PREC_INF, BF_RNDZ);\n        if ((b >> i) & 1)\n            ret |= bfdec_mul(r, r, a, BF_PREC_INF, BF_RNDZ);\n    }\n    return ret;\n}\n\nchar *bfdec_ftoa(size_t *plen, const bfdec_t *a, limb_t prec, bf_flags_t flags)\n{\n    return bf_ftoa_internal(plen, (const bf_t *)a, 10, prec, flags, TRUE);\n}\n\nint bfdec_atof(bfdec_t *r, const char *str, const char **pnext,\n               limb_t prec, bf_flags_t flags)\n{\n    slimb_t dummy_exp;\n    return bf_atof_internal((bf_t *)r, &dummy_exp, str, pnext, 10, prec,\n                            flags, TRUE);\n}\n\n#endif /* USE_BF_DEC */\n\n#ifdef USE_FFT_MUL\n/***************************************************************/\n/* Integer multiplication with FFT */\n\n/* or LIMB_BITS at bit position 'pos' in tab */\nstatic inline void put_bits(limb_t *tab, limb_t len, slimb_t pos, limb_t val)\n{\n    limb_t i;\n    int p;\n\n    i = pos >> LIMB_LOG2_BITS;\n    p = pos & (LIMB_BITS - 1);\n    if (i < len)\n        tab[i] |= val << p;\n    if (p != 0) {\n        i++;\n        if (i < len) {\n            tab[i] |= val >> (LIMB_BITS - p);\n        }\n    }\n}\n\n#if defined(__AVX2__)\n\ntypedef double NTTLimb;\n\n/* we must have: modulo >= 1 << NTT_MOD_LOG2_MIN */\n#define NTT_MOD_LOG2_MIN 50\n#define NTT_MOD_LOG2_MAX 51\n#define NB_MODS 5\n#define NTT_PROOT_2EXP 39\nstatic const int ntt_int_bits[NB_MODS] = { 254, 203, 152, 101, 50, };\n\nstatic const limb_t ntt_mods[NB_MODS] = { 0x00073a8000000001, 0x0007858000000001, 0x0007a38000000001, 0x0007a68000000001, 0x0007fd8000000001,\n};\n\nstatic const limb_t ntt_proot[2][NB_MODS] = {\n    { 0x00056198d44332c8, 0x0002eb5d640aad39, 0x00047e31eaa35fd0, 0x0005271ac118a150, 0x00075e0ce8442bd5, },\n    { 0x000461169761bcc5, 0x0002dac3cb2da688, 0x0004abc97751e3bf, 0x000656778fc8c485, 0x0000dc6469c269fa, },\n};\n\nstatic const limb_t ntt_mods_cr[NB_MODS * (NB_MODS - 1) / 2] = {\n 0x00020e4da740da8e, 0x0004c3dc09c09c1d, 0x000063bd097b4271, 0x000799d8f18f18fd,\n 0x0005384222222264, 0x000572b07c1f07fe, 0x00035cd08888889a,\n 0x00066015555557e3, 0x000725960b60b623,\n 0x0002fc1fa1d6ce12,\n};\n\n#else\n\ntypedef limb_t NTTLimb;\n\n#if LIMB_BITS == 64\n\n#define NTT_MOD_LOG2_MIN 61\n#define NTT_MOD_LOG2_MAX 62\n#define NB_MODS 5\n#define NTT_PROOT_2EXP 51\nstatic const int ntt_int_bits[NB_MODS] = { 307, 246, 185, 123, 61, };\n\nstatic const limb_t ntt_mods[NB_MODS] = { 0x28d8000000000001, 0x2a88000000000001, 0x2ed8000000000001, 0x3508000000000001, 0x3aa8000000000001,\n};\n\nstatic const limb_t ntt_proot[2][NB_MODS] = {\n    { 0x1b8ea61034a2bea7, 0x21a9762de58206fb, 0x02ca782f0756a8ea, 0x278384537a3e50a1, 0x106e13fee74ce0ab, },\n    { 0x233513af133e13b8, 0x1d13140d1c6f75f1, 0x12cde57f97e3eeda, 0x0d6149e23cbe654f, 0x36cd204f522a1379, },\n};\n\nstatic const limb_t ntt_mods_cr[NB_MODS * (NB_MODS - 1) / 2] = {\n 0x08a9ed097b425eea, 0x18a44aaaaaaaaab3, 0x2493f57f57f57f5d, 0x126b8d0649a7f8d4,\n 0x09d80ed7303b5ccc, 0x25b8bcf3cf3cf3d5, 0x2ce6ce63398ce638,\n 0x0e31fad40a57eb59, 0x02a3529fd4a7f52f,\n 0x3a5493e93e93e94a,\n};\n\n#elif LIMB_BITS == 32\n\n/* we must have: modulo >= 1 << NTT_MOD_LOG2_MIN */\n#define NTT_MOD_LOG2_MIN 29\n#define NTT_MOD_LOG2_MAX 30\n#define NB_MODS 5\n#define NTT_PROOT_2EXP 20\nstatic const int ntt_int_bits[NB_MODS] = { 148, 119, 89, 59, 29, };\n\nstatic const limb_t ntt_mods[NB_MODS] = { 0x0000000032b00001, 0x0000000033700001, 0x0000000036d00001, 0x0000000037300001, 0x000000003e500001,\n};\n\nstatic const limb_t ntt_proot[2][NB_MODS] = {\n    { 0x0000000032525f31, 0x0000000005eb3b37, 0x00000000246eda9f, 0x0000000035f25901, 0x00000000022f5768, },\n    { 0x00000000051eba1a, 0x00000000107be10e, 0x000000001cd574e0, 0x00000000053806e6, 0x000000002cd6bf98, },\n};\n\nstatic const limb_t ntt_mods_cr[NB_MODS * (NB_MODS - 1) / 2] = {\n 0x000000000449559a, 0x000000001eba6ca9, 0x000000002ec18e46, 0x000000000860160b,\n 0x000000000d321307, 0x000000000bf51120, 0x000000000f662938,\n 0x000000000932ab3e, 0x000000002f40eef8,\n 0x000000002e760905,\n};\n\n#endif /* LIMB_BITS */\n\n#endif /* !AVX2 */\n\n#if defined(__AVX2__)\n#define NTT_TRIG_K_MAX 18\n#else\n#define NTT_TRIG_K_MAX 19\n#endif\n\ntypedef struct BFNTTState {\n    bf_context_t *ctx;\n    \n    /* used for mul_mod_fast() */\n    limb_t ntt_mods_div[NB_MODS];\n\n    limb_t ntt_proot_pow[NB_MODS][2][NTT_PROOT_2EXP + 1];\n    limb_t ntt_proot_pow_inv[NB_MODS][2][NTT_PROOT_2EXP + 1];\n    NTTLimb *ntt_trig[NB_MODS][2][NTT_TRIG_K_MAX + 1];\n    /* 1/2^n mod m */\n    limb_t ntt_len_inv[NB_MODS][NTT_PROOT_2EXP + 1][2];\n#if defined(__AVX2__)\n    __m256d ntt_mods_cr_vec[NB_MODS * (NB_MODS - 1) / 2];\n    __m256d ntt_mods_vec[NB_MODS];\n    __m256d ntt_mods_inv_vec[NB_MODS];\n#else\n    limb_t ntt_mods_cr_inv[NB_MODS * (NB_MODS - 1) / 2];\n#endif\n} BFNTTState;\n\nstatic NTTLimb *get_trig(BFNTTState *s, int k, int inverse, int m_idx);\n\n/* add modulo with up to (LIMB_BITS-1) bit modulo */\nstatic inline limb_t add_mod(limb_t a, limb_t b, limb_t m)\n{\n    limb_t r;\n    r = a + b;\n    if (r >= m)\n        r -= m;\n    return r;\n}\n\n/* sub modulo with up to LIMB_BITS bit modulo */\nstatic inline limb_t sub_mod(limb_t a, limb_t b, limb_t m)\n{\n    limb_t r;\n    r = a - b;\n    if (r > a)\n        r += m;\n    return r;\n}\n\n/* return (r0+r1*B) mod m \n   precondition: 0 <= r0+r1*B < 2^(64+NTT_MOD_LOG2_MIN) \n*/\nstatic inline limb_t mod_fast(dlimb_t r, \n                                limb_t m, limb_t m_inv)\n{\n    limb_t a1, q, t0, r1, r0;\n    \n    a1 = r >> NTT_MOD_LOG2_MIN;\n    \n    q = ((dlimb_t)a1 * m_inv) >> LIMB_BITS;\n    r = r - (dlimb_t)q * m - m * 2;\n    r1 = r >> LIMB_BITS;\n    t0 = (slimb_t)r1 >> 1;\n    r += m & t0;\n    r0 = r;\n    r1 = r >> LIMB_BITS;\n    r0 += m & r1;\n    return r0;\n}\n\n/* faster version using precomputed modulo inverse. \n   precondition: 0 <= a * b < 2^(64+NTT_MOD_LOG2_MIN) */\nstatic inline limb_t mul_mod_fast(limb_t a, limb_t b, \n                                    limb_t m, limb_t m_inv)\n{\n    dlimb_t r;\n    r = (dlimb_t)a * (dlimb_t)b;\n    return mod_fast(r, m, m_inv);\n}\n\nstatic inline limb_t init_mul_mod_fast(limb_t m)\n{\n    dlimb_t t;\n    assert(m < (limb_t)1 << NTT_MOD_LOG2_MAX);\n    assert(m >= (limb_t)1 << NTT_MOD_LOG2_MIN);\n    t = (dlimb_t)1 << (LIMB_BITS + NTT_MOD_LOG2_MIN);\n    return t / m;\n}\n\n/* Faster version used when the multiplier is constant. 0 <= a < 2^64,\n   0 <= b < m. */\nstatic inline limb_t mul_mod_fast2(limb_t a, limb_t b, \n                                     limb_t m, limb_t b_inv)\n{\n    limb_t r, q;\n\n    q = ((dlimb_t)a * (dlimb_t)b_inv) >> LIMB_BITS;\n    r = a * b - q * m;\n    if (r >= m)\n        r -= m;\n    return r;\n}\n\n/* Faster version used when the multiplier is constant. 0 <= a < 2^64,\n   0 <= b < m. Let r = a * b mod m. The return value is 'r' or 'r +\n   m'. */\nstatic inline limb_t mul_mod_fast3(limb_t a, limb_t b, \n                                     limb_t m, limb_t b_inv)\n{\n    limb_t r, q;\n\n    q = ((dlimb_t)a * (dlimb_t)b_inv) >> LIMB_BITS;\n    r = a * b - q * m;\n    return r;\n}\n\nstatic inline limb_t init_mul_mod_fast2(limb_t b, limb_t m)\n{\n    return ((dlimb_t)b << LIMB_BITS) / m;\n}\n\n#ifdef __AVX2__\n\nstatic inline limb_t ntt_limb_to_int(NTTLimb a, limb_t m)\n{\n    slimb_t v;\n    v = a;\n    if (v < 0)\n        v += m;\n    if (v >= m)\n        v -= m;\n    return v;\n}\n\nstatic inline NTTLimb int_to_ntt_limb(limb_t a, limb_t m)\n{\n    return (slimb_t)a;\n}\n\nstatic inline NTTLimb int_to_ntt_limb2(limb_t a, limb_t m)\n{\n    if (a >= (m / 2))\n        a -= m;\n    return (slimb_t)a;\n}\n\n/* return r + m if r < 0 otherwise r. */\nstatic inline __m256d ntt_mod1(__m256d r, __m256d m)\n{\n    return _mm256_blendv_pd(r, r + m, r);\n}\n\n/* input: abs(r) < 2 * m. Output: abs(r) < m */\nstatic inline __m256d ntt_mod(__m256d r, __m256d mf, __m256d m2f)\n{\n    return _mm256_blendv_pd(r, r + m2f, r) - mf;\n}\n\n/* input: abs(a*b) < 2 * m^2, output: abs(r) < m */\nstatic inline __m256d ntt_mul_mod(__m256d a, __m256d b, __m256d mf,\n                                  __m256d m_inv)\n{\n    __m256d r, q, ab1, ab0, qm0, qm1;\n    ab1 = a * b;\n    q = _mm256_round_pd(ab1 * m_inv, 0); /* round to nearest */\n    qm1 = q * mf;\n    qm0 = _mm256_fmsub_pd(q, mf, qm1); /* low part */\n    ab0 = _mm256_fmsub_pd(a, b, ab1); /* low part */\n    r = (ab1 - qm1) + (ab0 - qm0);\n    return r;\n}\n\nstatic void *bf_aligned_malloc(bf_context_t *s, size_t size, size_t align)\n{\n    void *ptr;\n    void **ptr1;\n    ptr = bf_malloc(s, size + sizeof(void *) + align - 1);\n    if (!ptr)\n        return NULL;\n    ptr1 = (void **)(((uintptr_t)ptr + sizeof(void *) + align - 1) &\n                     ~(align - 1));\n    ptr1[-1] = ptr;\n    return ptr1;\n}\n\nstatic void bf_aligned_free(bf_context_t *s, void *ptr)\n{\n    if (!ptr)\n        return;\n    bf_free(s, ((void **)ptr)[-1]);\n}\n\nstatic void *ntt_malloc(BFNTTState *s, size_t size)\n{\n    return bf_aligned_malloc(s->ctx, size, 64);\n}\n\nstatic void ntt_free(BFNTTState *s, void *ptr)\n{\n    bf_aligned_free(s->ctx, ptr);\n}\n\nstatic no_inline int ntt_fft(BFNTTState *s,\n                             NTTLimb *out_buf, NTTLimb *in_buf,\n                             NTTLimb *tmp_buf, int fft_len_log2,\n                             int inverse, int m_idx)\n{\n    limb_t nb_blocks, fft_per_block, p, k, n, stride_in, i, j;\n    NTTLimb *tab_in, *tab_out, *tmp, *trig;\n    __m256d m_inv, mf, m2f, c, a0, a1, b0, b1;\n    limb_t m;\n    int l;\n    \n    m = ntt_mods[m_idx];\n    \n    m_inv = _mm256_set1_pd(1.0 / (double)m);\n    mf = _mm256_set1_pd(m);\n    m2f = _mm256_set1_pd(m * 2);\n\n    n = (limb_t)1 << fft_len_log2;\n    assert(n >= 8);\n    stride_in = n / 2;\n\n    tab_in = in_buf;\n    tab_out = tmp_buf;\n    trig = get_trig(s, fft_len_log2, inverse, m_idx);\n    if (!trig)\n        return -1;\n    p = 0;\n    for(k = 0; k < stride_in; k += 4) {\n        a0 = _mm256_load_pd(&tab_in[k]);\n        a1 = _mm256_load_pd(&tab_in[k + stride_in]);\n        c = _mm256_load_pd(trig);\n        trig += 4;\n        b0 = ntt_mod(a0 + a1, mf, m2f);\n        b1 = ntt_mul_mod(a0 - a1, c, mf, m_inv);\n        a0 = _mm256_permute2f128_pd(b0, b1, 0x20);\n        a1 = _mm256_permute2f128_pd(b0, b1, 0x31);\n        a0 = _mm256_permute4x64_pd(a0, 0xd8);\n        a1 = _mm256_permute4x64_pd(a1, 0xd8);\n        _mm256_store_pd(&tab_out[p], a0);\n        _mm256_store_pd(&tab_out[p + 4], a1);\n        p += 2 * 4;\n    }\n    tmp = tab_in;\n    tab_in = tab_out;\n    tab_out = tmp;\n\n    trig = get_trig(s, fft_len_log2 - 1, inverse, m_idx);\n    if (!trig)\n        return -1;\n    p = 0;\n    for(k = 0; k < stride_in; k += 4) {\n        a0 = _mm256_load_pd(&tab_in[k]);\n        a1 = _mm256_load_pd(&tab_in[k + stride_in]);\n        c = _mm256_setr_pd(trig[0], trig[0], trig[1], trig[1]);\n        trig += 2;\n        b0 = ntt_mod(a0 + a1, mf, m2f);\n        b1 = ntt_mul_mod(a0 - a1, c, mf, m_inv);\n        a0 = _mm256_permute2f128_pd(b0, b1, 0x20);\n        a1 = _mm256_permute2f128_pd(b0, b1, 0x31);\n        _mm256_store_pd(&tab_out[p], a0);\n        _mm256_store_pd(&tab_out[p + 4], a1);\n        p += 2 * 4;\n    }\n    tmp = tab_in;\n    tab_in = tab_out;\n    tab_out = tmp;\n    \n    nb_blocks = n / 4;\n    fft_per_block = 4;\n\n    l = fft_len_log2 - 2;\n    while (nb_blocks != 2) {\n        nb_blocks >>= 1;\n        p = 0;\n        k = 0;\n        trig = get_trig(s, l, inverse, m_idx);\n        if (!trig)\n            return -1;\n        for(i = 0; i < nb_blocks; i++) {\n            c = _mm256_set1_pd(trig[0]);\n            trig++;\n            for(j = 0; j < fft_per_block; j += 4) {\n                a0 = _mm256_load_pd(&tab_in[k + j]);\n                a1 = _mm256_load_pd(&tab_in[k + j + stride_in]);\n                b0 = ntt_mod(a0 + a1, mf, m2f);\n                b1 = ntt_mul_mod(a0 - a1, c, mf, m_inv);\n                _mm256_store_pd(&tab_out[p + j], b0);\n                _mm256_store_pd(&tab_out[p + j + fft_per_block], b1);\n            }\n            k += fft_per_block;\n            p += 2 * fft_per_block;\n        }\n        fft_per_block <<= 1;\n        l--;\n        tmp = tab_in;\n        tab_in = tab_out;\n        tab_out = tmp;\n    }\n\n    tab_out = out_buf;\n    for(k = 0; k < stride_in; k += 4) {\n        a0 = _mm256_load_pd(&tab_in[k]);\n        a1 = _mm256_load_pd(&tab_in[k + stride_in]);\n        b0 = ntt_mod(a0 + a1, mf, m2f);\n        b1 = ntt_mod(a0 - a1, mf, m2f);\n        _mm256_store_pd(&tab_out[k], b0);\n        _mm256_store_pd(&tab_out[k + stride_in], b1);\n    }\n    return 0;\n}\n\nstatic void ntt_vec_mul(BFNTTState *s,\n                        NTTLimb *tab1, NTTLimb *tab2, limb_t fft_len_log2,\n                        int k_tot, int m_idx)\n{\n    limb_t i, c_inv, n, m;\n    __m256d m_inv, mf, a, b, c;\n    \n    m = ntt_mods[m_idx];\n    c_inv = s->ntt_len_inv[m_idx][k_tot][0];\n    m_inv = _mm256_set1_pd(1.0 / (double)m);\n    mf = _mm256_set1_pd(m);\n    c = _mm256_set1_pd(int_to_ntt_limb(c_inv, m));\n    n = (limb_t)1 << fft_len_log2;\n    for(i = 0; i < n; i += 4) {\n        a = _mm256_load_pd(&tab1[i]);\n        b = _mm256_load_pd(&tab2[i]);\n        a = ntt_mul_mod(a, b, mf, m_inv);\n        a = ntt_mul_mod(a, c, mf, m_inv);\n        _mm256_store_pd(&tab1[i], a);\n    }\n}\n\nstatic no_inline void mul_trig(NTTLimb *buf,\n                               limb_t n, limb_t c1, limb_t m, limb_t m_inv1)\n{\n    limb_t i, c2, c3, c4;\n    __m256d c, c_mul, a0, mf, m_inv;\n    assert(n >= 2);\n    \n    mf = _mm256_set1_pd(m);\n    m_inv = _mm256_set1_pd(1.0 / (double)m);\n\n    c2 = mul_mod_fast(c1, c1, m, m_inv1);\n    c3 = mul_mod_fast(c2, c1, m, m_inv1);\n    c4 = mul_mod_fast(c2, c2, m, m_inv1);\n    c = _mm256_setr_pd(1, int_to_ntt_limb(c1, m),\n                       int_to_ntt_limb(c2, m), int_to_ntt_limb(c3, m));\n    c_mul = _mm256_set1_pd(int_to_ntt_limb(c4, m));\n    for(i = 0; i < n; i += 4) {\n        a0 = _mm256_load_pd(&buf[i]);\n        a0 = ntt_mul_mod(a0, c, mf, m_inv);\n        _mm256_store_pd(&buf[i], a0);\n        c = ntt_mul_mod(c, c_mul, mf, m_inv);\n    }\n}\n\n#else\n\nstatic void *ntt_malloc(BFNTTState *s, size_t size)\n{\n    return bf_malloc(s->ctx, size);\n}\n\nstatic void ntt_free(BFNTTState *s, void *ptr)\n{\n    bf_free(s->ctx, ptr);\n}\n\nstatic inline limb_t ntt_limb_to_int(NTTLimb a, limb_t m)\n{\n    if (a >= m)\n        a -= m;\n    return a;\n}\n\nstatic inline NTTLimb int_to_ntt_limb(slimb_t a, limb_t m)\n{\n    return a;\n}\n\nstatic no_inline int ntt_fft(BFNTTState *s, NTTLimb *out_buf, NTTLimb *in_buf,\n                             NTTLimb *tmp_buf, int fft_len_log2,\n                             int inverse, int m_idx)\n{\n    limb_t nb_blocks, fft_per_block, p, k, n, stride_in, i, j, m, m2;\n    NTTLimb *tab_in, *tab_out, *tmp, a0, a1, b0, b1, c, *trig, c_inv;\n    int l;\n    \n    m = ntt_mods[m_idx];\n    m2 = 2 * m;\n    n = (limb_t)1 << fft_len_log2;\n    nb_blocks = n;\n    fft_per_block = 1;\n    stride_in = n / 2;\n    tab_in = in_buf;\n    tab_out = tmp_buf;\n    l = fft_len_log2;\n    while (nb_blocks != 2) {\n        nb_blocks >>= 1;\n        p = 0;\n        k = 0;\n        trig = get_trig(s, l, inverse, m_idx);\n        if (!trig)\n            return -1;\n        for(i = 0; i < nb_blocks; i++) {\n            c = trig[0];\n            c_inv = trig[1];\n            trig += 2;\n            for(j = 0; j < fft_per_block; j++) {\n                a0 = tab_in[k + j];\n                a1 = tab_in[k + j + stride_in];\n                b0 = add_mod(a0, a1, m2);\n                b1 = a0 - a1 + m2;\n                b1 = mul_mod_fast3(b1, c, m, c_inv);\n                tab_out[p + j] = b0;\n                tab_out[p + j + fft_per_block] = b1;\n            }\n            k += fft_per_block;\n            p += 2 * fft_per_block;\n        }\n        fft_per_block <<= 1;\n        l--;\n        tmp = tab_in;\n        tab_in = tab_out;\n        tab_out = tmp;\n    }\n    /* no twiddle in last step */\n    tab_out = out_buf; \n    for(k = 0; k < stride_in; k++) {\n        a0 = tab_in[k];\n        a1 = tab_in[k + stride_in];\n        b0 = add_mod(a0, a1, m2);\n        b1 = sub_mod(a0, a1, m2);\n        tab_out[k] = b0;\n        tab_out[k + stride_in] = b1;\n    }\n    return 0;\n}\n\nstatic void ntt_vec_mul(BFNTTState *s,\n                        NTTLimb *tab1, NTTLimb *tab2, int fft_len_log2,\n                        int k_tot, int m_idx)\n{\n    limb_t i, norm, norm_inv, a, n, m, m_inv;\n    \n    m = ntt_mods[m_idx];\n    m_inv = s->ntt_mods_div[m_idx];\n    norm = s->ntt_len_inv[m_idx][k_tot][0];\n    norm_inv = s->ntt_len_inv[m_idx][k_tot][1];\n    n = (limb_t)1 << fft_len_log2;\n    for(i = 0; i < n; i++) {\n        a = tab1[i];\n        /* need to reduce the range so that the product is <\n           2^(LIMB_BITS+NTT_MOD_LOG2_MIN) */\n        if (a >= m)\n            a -= m;\n        a = mul_mod_fast(a, tab2[i], m, m_inv);\n        a = mul_mod_fast3(a, norm, m, norm_inv);\n        tab1[i] = a;\n    }\n}\n\nstatic no_inline void mul_trig(NTTLimb *buf,\n                               limb_t n, limb_t c_mul, limb_t m, limb_t m_inv)\n{\n    limb_t i, c0, c_mul_inv;\n    \n    c0 = 1;\n    c_mul_inv = init_mul_mod_fast2(c_mul, m);\n    for(i = 0; i < n; i++) {\n        buf[i] = mul_mod_fast(buf[i], c0, m, m_inv);\n        c0 = mul_mod_fast2(c0, c_mul, m, c_mul_inv);\n    }\n}\n\n#endif /* !AVX2 */\n\nstatic no_inline NTTLimb *get_trig(BFNTTState *s,\n                                   int k, int inverse, int m_idx)\n{\n    NTTLimb *tab;\n    limb_t i, n2, c, c_mul, m, c_mul_inv;\n    \n    if (k > NTT_TRIG_K_MAX)\n        return NULL;\n\n    tab = s->ntt_trig[m_idx][inverse][k];\n    if (tab)\n        return tab;\n    n2 = (limb_t)1 << (k - 1);\n    m = ntt_mods[m_idx];\n#ifdef __AVX2__\n    tab = ntt_malloc(s, sizeof(NTTLimb) * n2);\n#else\n    tab = ntt_malloc(s, sizeof(NTTLimb) * n2 * 2);\n#endif\n    if (!tab)\n        return NULL;\n    c = 1;\n    c_mul = s->ntt_proot_pow[m_idx][inverse][k];\n    c_mul_inv = s->ntt_proot_pow_inv[m_idx][inverse][k];\n    for(i = 0; i < n2; i++) {\n#ifdef __AVX2__\n        tab[i] = int_to_ntt_limb2(c, m);\n#else\n        tab[2 * i] = int_to_ntt_limb(c, m);\n        tab[2 * i + 1] = init_mul_mod_fast2(c, m);\n#endif\n        c = mul_mod_fast2(c, c_mul, m, c_mul_inv);\n    }\n    s->ntt_trig[m_idx][inverse][k] = tab;\n    return tab;\n}\n\nvoid fft_clear_cache(bf_context_t *s1)\n{\n    int m_idx, inverse, k;\n    BFNTTState *s = s1->ntt_state;\n    if (s) {\n        for(m_idx = 0; m_idx < NB_MODS; m_idx++) {\n            for(inverse = 0; inverse < 2; inverse++) {\n                for(k = 0; k < NTT_TRIG_K_MAX + 1; k++) {\n                    if (s->ntt_trig[m_idx][inverse][k]) {\n                        ntt_free(s, s->ntt_trig[m_idx][inverse][k]);\n                        s->ntt_trig[m_idx][inverse][k] = NULL;\n                    }\n                }\n            }\n        }\n#if defined(__AVX2__)\n        bf_aligned_free(s1, s);\n#else\n        bf_free(s1, s);\n#endif\n        s1->ntt_state = NULL;\n    }\n}\n\n#define STRIP_LEN 16\n\n/* dst = buf1, src = buf2 */\nstatic int ntt_fft_partial(BFNTTState *s, NTTLimb *buf1,\n                           int k1, int k2, limb_t n1, limb_t n2, int inverse,\n                           limb_t m_idx)\n{\n    limb_t i, j, c_mul, c0, m, m_inv, strip_len, l;\n    NTTLimb *buf2, *buf3;\n    \n    buf2 = NULL;\n    buf3 = ntt_malloc(s, sizeof(NTTLimb) * n1);\n    if (!buf3)\n        goto fail;\n    if (k2 == 0) {\n        if (ntt_fft(s, buf1, buf1, buf3, k1, inverse, m_idx))\n            goto fail;\n    } else {\n        strip_len = STRIP_LEN;\n        buf2 = ntt_malloc(s, sizeof(NTTLimb) * n1 * strip_len);\n        if (!buf2)\n            goto fail;\n        m = ntt_mods[m_idx];\n        m_inv = s->ntt_mods_div[m_idx];\n        c0 = s->ntt_proot_pow[m_idx][inverse][k1 + k2];\n        c_mul = 1;\n        assert((n2 % strip_len) == 0);\n        for(j = 0; j < n2; j += strip_len) {\n            for(i = 0; i < n1; i++) {\n                for(l = 0; l < strip_len; l++) {\n                    buf2[i + l * n1] = buf1[i * n2 + (j + l)];\n                }\n            }\n            for(l = 0; l < strip_len; l++) {\n                if (inverse)\n                    mul_trig(buf2 + l * n1, n1, c_mul, m, m_inv);\n                if (ntt_fft(s, buf2 + l * n1, buf2 + l * n1, buf3, k1, inverse, m_idx))\n                    goto fail;\n                if (!inverse)\n                    mul_trig(buf2 + l * n1, n1, c_mul, m, m_inv);\n                c_mul = mul_mod_fast(c_mul, c0, m, m_inv);\n            }\n            \n            for(i = 0; i < n1; i++) {\n                for(l = 0; l < strip_len; l++) {\n                    buf1[i * n2 + (j + l)] = buf2[i + l *n1];\n                }\n            }\n        }\n        ntt_free(s, buf2);\n    }\n    ntt_free(s, buf3);\n    return 0;\n fail:\n    ntt_free(s, buf2);\n    ntt_free(s, buf3);\n    return -1;\n}\n\n\n/* dst = buf1, src = buf2, tmp = buf3 */\nstatic int ntt_conv(BFNTTState *s, NTTLimb *buf1, NTTLimb *buf2,\n                    int k, int k_tot, limb_t m_idx)\n{\n    limb_t n1, n2, i;\n    int k1, k2;\n    \n    if (k <= NTT_TRIG_K_MAX) {\n        k1 = k;\n    } else {\n        /* recursive split of the FFT */\n        k1 = bf_min(k / 2, NTT_TRIG_K_MAX);\n    }\n    k2 = k - k1;\n    n1 = (limb_t)1 << k1;\n    n2 = (limb_t)1 << k2;\n    \n    if (ntt_fft_partial(s, buf1, k1, k2, n1, n2, 0, m_idx))\n        return -1;\n    if (ntt_fft_partial(s, buf2, k1, k2, n1, n2, 0, m_idx))\n        return -1;\n    if (k2 == 0) {\n        ntt_vec_mul(s, buf1, buf2, k, k_tot, m_idx);\n    } else {\n        for(i = 0; i < n1; i++) {\n            ntt_conv(s, buf1 + i * n2, buf2 + i * n2, k2, k_tot, m_idx);\n        }\n    }\n    if (ntt_fft_partial(s, buf1, k1, k2, n1, n2, 1, m_idx))\n        return -1;\n    return 0;\n}\n\n\nstatic no_inline void limb_to_ntt(BFNTTState *s,\n                                  NTTLimb *tabr, limb_t fft_len,\n                                  const limb_t *taba, limb_t a_len, int dpl,\n                                  int first_m_idx, int nb_mods)\n{\n    slimb_t i, n;\n    dlimb_t a, b;\n    int j, shift;\n    limb_t base_mask1, a0, a1, a2, r, m, m_inv;\n    \n#if 0\n    for(i = 0; i < a_len; i++) {\n        printf(\"%\" PRId64 \": \" FMT_LIMB \"\\n\",\n               (int64_t)i, taba[i]);\n    }\n#endif   \n    memset(tabr, 0, sizeof(NTTLimb) * fft_len * nb_mods);\n    shift = dpl & (LIMB_BITS - 1);\n    if (shift == 0)\n        base_mask1 = -1;\n    else\n        base_mask1 = ((limb_t)1 << shift) - 1;\n    n = bf_min(fft_len, (a_len * LIMB_BITS + dpl - 1) / dpl);\n    for(i = 0; i < n; i++) {\n        a0 = get_bits(taba, a_len, i * dpl);\n        if (dpl <= LIMB_BITS) {\n            a0 &= base_mask1;\n            a = a0;\n        } else {\n            a1 = get_bits(taba, a_len, i * dpl + LIMB_BITS);\n            if (dpl <= (LIMB_BITS + NTT_MOD_LOG2_MIN)) {\n                a = a0 | ((dlimb_t)(a1 & base_mask1) << LIMB_BITS);\n            } else {\n                if (dpl > 2 * LIMB_BITS) {\n                    a2 = get_bits(taba, a_len, i * dpl + LIMB_BITS * 2) &\n                        base_mask1;\n                } else {\n                    a1 &= base_mask1;\n                    a2 = 0;\n                }\n                //            printf(\"a=0x%016lx%016lx%016lx\\n\", a2, a1, a0);\n                a = (a0 >> (LIMB_BITS - NTT_MOD_LOG2_MAX + NTT_MOD_LOG2_MIN)) |\n                    ((dlimb_t)a1 << (NTT_MOD_LOG2_MAX - NTT_MOD_LOG2_MIN)) |\n                    ((dlimb_t)a2 << (LIMB_BITS + NTT_MOD_LOG2_MAX - NTT_MOD_LOG2_MIN));\n                a0 &= ((limb_t)1 << (LIMB_BITS - NTT_MOD_LOG2_MAX + NTT_MOD_LOG2_MIN)) - 1;\n            }\n        }\n        for(j = 0; j < nb_mods; j++) {\n            m = ntt_mods[first_m_idx + j];\n            m_inv = s->ntt_mods_div[first_m_idx + j];\n            r = mod_fast(a, m, m_inv);\n            if (dpl > (LIMB_BITS + NTT_MOD_LOG2_MIN)) {\n                b = ((dlimb_t)r << (LIMB_BITS - NTT_MOD_LOG2_MAX + NTT_MOD_LOG2_MIN)) | a0;\n                r = mod_fast(b, m, m_inv);\n            }\n            tabr[i + j * fft_len] = int_to_ntt_limb(r, m);\n        }\n    }\n}\n\n#if defined(__AVX2__)\n\n#define VEC_LEN 4\n\ntypedef union {\n    __m256d v;\n    double d[4];\n} VecUnion;\n\nstatic no_inline void ntt_to_limb(BFNTTState *s, limb_t *tabr, limb_t r_len,\n                                  const NTTLimb *buf, int fft_len_log2, int dpl,\n                                  int nb_mods)\n{\n    const limb_t *mods = ntt_mods + NB_MODS - nb_mods;\n    const __m256d *mods_cr_vec, *mf, *m_inv;\n    VecUnion y[NB_MODS];\n    limb_t u[NB_MODS], carry[NB_MODS], fft_len, base_mask1, r;\n    slimb_t i, len, pos;\n    int j, k, l, shift, n_limb1, p;\n    dlimb_t t;\n        \n    j = NB_MODS * (NB_MODS - 1) / 2 - nb_mods * (nb_mods - 1) / 2;\n    mods_cr_vec = s->ntt_mods_cr_vec + j;\n    mf = s->ntt_mods_vec + NB_MODS - nb_mods;\n    m_inv = s->ntt_mods_inv_vec + NB_MODS - nb_mods;\n        \n    shift = dpl & (LIMB_BITS - 1);\n    if (shift == 0)\n        base_mask1 = -1;\n    else\n        base_mask1 = ((limb_t)1 << shift) - 1;\n    n_limb1 = ((unsigned)dpl - 1) / LIMB_BITS;\n    for(j = 0; j < NB_MODS; j++) \n        carry[j] = 0;\n    for(j = 0; j < NB_MODS; j++) \n        u[j] = 0; /* avoid warnings */\n    memset(tabr, 0, sizeof(limb_t) * r_len);\n    fft_len = (limb_t)1 << fft_len_log2;\n    len = bf_min(fft_len, (r_len * LIMB_BITS + dpl - 1) / dpl);\n    len = (len + VEC_LEN - 1) & ~(VEC_LEN - 1);\n    i = 0;\n    while (i < len) {\n        for(j = 0; j < nb_mods; j++)\n            y[j].v = *(__m256d *)&buf[i + fft_len * j];\n\n        /* Chinese remainder to get mixed radix representation */\n        l = 0;\n        for(j = 0; j < nb_mods - 1; j++) {\n            y[j].v = ntt_mod1(y[j].v, mf[j]);\n            for(k = j + 1; k < nb_mods; k++) {\n                y[k].v = ntt_mul_mod(y[k].v - y[j].v,\n                                     mods_cr_vec[l], mf[k], m_inv[k]);\n                l++;\n            }\n        }\n        y[j].v = ntt_mod1(y[j].v, mf[j]);\n        \n        for(p = 0; p < VEC_LEN; p++) {\n            /* back to normal representation */\n            u[0] = (int64_t)y[nb_mods - 1].d[p];\n            l = 1;\n            for(j = nb_mods - 2; j >= 1; j--) {\n                r = (int64_t)y[j].d[p];\n                for(k = 0; k < l; k++) {\n                    t = (dlimb_t)u[k] * mods[j] + r;\n                    r = t >> LIMB_BITS;\n                    u[k] = t;\n                }\n                u[l] = r;\n                l++;\n            }\n            /* XXX: for nb_mods = 5, l should be 4 */\n            \n            /* last step adds the carry */\n            r = (int64_t)y[0].d[p];\n            for(k = 0; k < l; k++) {\n                t = (dlimb_t)u[k] * mods[j] + r + carry[k];\n                r = t >> LIMB_BITS;\n                u[k] = t;\n            }\n            u[l] = r + carry[l];\n\n#if 0\n            printf(\"%\" PRId64 \": \", i);\n            for(j = nb_mods - 1; j >= 0; j--) {\n                printf(\" %019\" PRIu64, u[j]);\n            }\n            printf(\"\\n\");\n#endif\n            \n            /* write the digits */\n            pos = i * dpl;\n            for(j = 0; j < n_limb1; j++) {\n                put_bits(tabr, r_len, pos, u[j]);\n                pos += LIMB_BITS;\n            }\n            put_bits(tabr, r_len, pos, u[n_limb1] & base_mask1);\n            /* shift by dpl digits and set the carry */\n            if (shift == 0) {\n                for(j = n_limb1 + 1; j < nb_mods; j++)\n                    carry[j - (n_limb1 + 1)] = u[j];\n            } else {\n                for(j = n_limb1; j < nb_mods - 1; j++) {\n                    carry[j - n_limb1] = (u[j] >> shift) |\n                        (u[j + 1] << (LIMB_BITS - shift));\n                }\n                carry[nb_mods - 1 - n_limb1] = u[nb_mods - 1] >> shift;\n            }\n            i++;\n        }\n    }\n}\n#else\nstatic no_inline void ntt_to_limb(BFNTTState *s, limb_t *tabr, limb_t r_len,\n                                  const NTTLimb *buf, int fft_len_log2, int dpl,\n                                  int nb_mods)\n{\n    const limb_t *mods = ntt_mods + NB_MODS - nb_mods;\n    const limb_t *mods_cr, *mods_cr_inv;\n    limb_t y[NB_MODS], u[NB_MODS], carry[NB_MODS], fft_len, base_mask1, r;\n    slimb_t i, len, pos;\n    int j, k, l, shift, n_limb1;\n    dlimb_t t;\n        \n    j = NB_MODS * (NB_MODS - 1) / 2 - nb_mods * (nb_mods - 1) / 2;\n    mods_cr = ntt_mods_cr + j;\n    mods_cr_inv = s->ntt_mods_cr_inv + j;\n\n    shift = dpl & (LIMB_BITS - 1);\n    if (shift == 0)\n        base_mask1 = -1;\n    else\n        base_mask1 = ((limb_t)1 << shift) - 1;\n    n_limb1 = ((unsigned)dpl - 1) / LIMB_BITS;\n    for(j = 0; j < NB_MODS; j++) \n        carry[j] = 0;\n    for(j = 0; j < NB_MODS; j++) \n        u[j] = 0; /* avoid warnings */\n    memset(tabr, 0, sizeof(limb_t) * r_len);\n    fft_len = (limb_t)1 << fft_len_log2;\n    len = bf_min(fft_len, (r_len * LIMB_BITS + dpl - 1) / dpl);\n    for(i = 0; i < len; i++) {\n        for(j = 0; j < nb_mods; j++)  {\n            y[j] = ntt_limb_to_int(buf[i + fft_len * j], mods[j]);\n        }\n\n        /* Chinese remainder to get mixed radix representation */\n        l = 0;\n        for(j = 0; j < nb_mods - 1; j++) {\n            for(k = j + 1; k < nb_mods; k++) {\n                limb_t m;\n                m = mods[k];\n                /* Note: there is no overflow in the sub_mod() because\n                   the modulos are sorted by increasing order */\n                y[k] = mul_mod_fast2(y[k] - y[j] + m, \n                                     mods_cr[l], m, mods_cr_inv[l]);\n                l++;\n            }\n        }\n        \n        /* back to normal representation */\n        u[0] = y[nb_mods - 1];\n        l = 1;\n        for(j = nb_mods - 2; j >= 1; j--) {\n            r = y[j];\n            for(k = 0; k < l; k++) {\n                t = (dlimb_t)u[k] * mods[j] + r;\n                r = t >> LIMB_BITS;\n                u[k] = t;\n            }\n            u[l] = r;\n            l++;\n        }\n        \n        /* last step adds the carry */\n        r = y[0];\n        for(k = 0; k < l; k++) {\n            t = (dlimb_t)u[k] * mods[j] + r + carry[k];\n            r = t >> LIMB_BITS;\n            u[k] = t;\n        }\n        u[l] = r + carry[l];\n\n#if 0\n        printf(\"%\" PRId64 \": \", (int64_t)i);\n        for(j = nb_mods - 1; j >= 0; j--) {\n            printf(\" \" FMT_LIMB, u[j]);\n        }\n        printf(\"\\n\");\n#endif\n        \n        /* write the digits */\n        pos = i * dpl;\n        for(j = 0; j < n_limb1; j++) {\n            put_bits(tabr, r_len, pos, u[j]);\n            pos += LIMB_BITS;\n        }\n        put_bits(tabr, r_len, pos, u[n_limb1] & base_mask1);\n        /* shift by dpl digits and set the carry */\n        if (shift == 0) {\n            for(j = n_limb1 + 1; j < nb_mods; j++)\n                carry[j - (n_limb1 + 1)] = u[j];\n        } else {\n            for(j = n_limb1; j < nb_mods - 1; j++) {\n                carry[j - n_limb1] = (u[j] >> shift) |\n                    (u[j + 1] << (LIMB_BITS - shift));\n            }\n            carry[nb_mods - 1 - n_limb1] = u[nb_mods - 1] >> shift;\n        }\n    }\n}\n#endif\n\nstatic int ntt_static_init(bf_context_t *s1)\n{\n    BFNTTState *s;\n    int inverse, i, j, k, l;\n    limb_t c, c_inv, c_inv2, m, m_inv;\n\n    if (s1->ntt_state)\n        return 0;\n#if defined(__AVX2__)\n    s = bf_aligned_malloc(s1, sizeof(*s), 64);\n#else\n    s = bf_malloc(s1, sizeof(*s));\n#endif\n    if (!s)\n        return -1;\n    memset(s, 0, sizeof(*s));\n    s1->ntt_state = s;\n    s->ctx = s1;\n    \n    for(j = 0; j < NB_MODS; j++) {\n        m = ntt_mods[j];\n        m_inv = init_mul_mod_fast(m);\n        s->ntt_mods_div[j] = m_inv;\n#if defined(__AVX2__)\n        s->ntt_mods_vec[j] = _mm256_set1_pd(m);\n        s->ntt_mods_inv_vec[j] = _mm256_set1_pd(1.0 / (double)m);\n#endif\n        c_inv2 = (m + 1) / 2; /* 1/2 */\n        c_inv = 1;\n        for(i = 0; i <= NTT_PROOT_2EXP; i++) {\n            s->ntt_len_inv[j][i][0] = c_inv;\n            s->ntt_len_inv[j][i][1] = init_mul_mod_fast2(c_inv, m);\n            c_inv = mul_mod_fast(c_inv, c_inv2, m, m_inv);\n        }\n\n        for(inverse = 0; inverse < 2; inverse++) {\n            c = ntt_proot[inverse][j];\n            for(i = 0; i < NTT_PROOT_2EXP; i++) {\n                s->ntt_proot_pow[j][inverse][NTT_PROOT_2EXP - i] = c;\n                s->ntt_proot_pow_inv[j][inverse][NTT_PROOT_2EXP - i] =\n                    init_mul_mod_fast2(c, m);\n                c = mul_mod_fast(c, c, m, m_inv);\n            }\n        }\n    }\n\n    l = 0;\n    for(j = 0; j < NB_MODS - 1; j++) {\n        for(k = j + 1; k < NB_MODS; k++) {\n#if defined(__AVX2__)\n            s->ntt_mods_cr_vec[l] = _mm256_set1_pd(int_to_ntt_limb2(ntt_mods_cr[l],\n                                                                    ntt_mods[k]));\n#else\n            s->ntt_mods_cr_inv[l] = init_mul_mod_fast2(ntt_mods_cr[l],\n                                                       ntt_mods[k]);\n#endif\n            l++;\n        }\n    }\n    return 0;\n}\n\nint bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len)\n{\n    int dpl, fft_len_log2, n_bits, nb_mods, dpl_found, fft_len_log2_found;\n    int int_bits, nb_mods_found;\n    limb_t cost, min_cost;\n    \n    min_cost = -1;\n    dpl_found = 0;\n    nb_mods_found = 4;\n    fft_len_log2_found = 0;\n    for(nb_mods = 3; nb_mods <= NB_MODS; nb_mods++) {\n        int_bits = ntt_int_bits[NB_MODS - nb_mods];\n        dpl = bf_min((int_bits - 4) / 2,\n                     2 * LIMB_BITS + 2 * NTT_MOD_LOG2_MIN - NTT_MOD_LOG2_MAX);\n        for(;;) {\n            fft_len_log2 = ceil_log2((len * LIMB_BITS + dpl - 1) / dpl);\n            if (fft_len_log2 > NTT_PROOT_2EXP)\n                goto next;\n            n_bits = fft_len_log2 + 2 * dpl;\n            if (n_bits <= int_bits) {\n                cost = ((limb_t)(fft_len_log2 + 1) << fft_len_log2) * nb_mods;\n                //                printf(\"n=%d dpl=%d: cost=%\" PRId64 \"\\n\", nb_mods, dpl, (int64_t)cost);\n                if (cost < min_cost) {\n                    min_cost = cost;\n                    dpl_found = dpl;\n                    nb_mods_found = nb_mods;\n                    fft_len_log2_found = fft_len_log2;\n                }\n                break;\n            }\n            dpl--;\n            if (dpl == 0)\n                break;\n        }\n    next: ;\n    }\n    if (!dpl_found)\n        abort();\n    /* limit dpl if possible to reduce fixed cost of limb/NTT conversion */\n    if (dpl_found > (LIMB_BITS + NTT_MOD_LOG2_MIN) &&\n        ((limb_t)(LIMB_BITS + NTT_MOD_LOG2_MIN) << fft_len_log2_found) >=\n        len * LIMB_BITS) {\n        dpl_found = LIMB_BITS + NTT_MOD_LOG2_MIN;\n    }\n    *pnb_mods = nb_mods_found;\n    *pdpl = dpl_found;\n    return fft_len_log2_found;\n}\n\n/* return 0 if OK, -1 if memory error */\nstatic no_inline int fft_mul(bf_context_t *s1,\n                             bf_t *res, limb_t *a_tab, limb_t a_len,\n                             limb_t *b_tab, limb_t b_len, int mul_flags)\n{\n    BFNTTState *s;\n    int dpl, fft_len_log2, j, nb_mods, reduced_mem;\n    slimb_t len, fft_len;\n    NTTLimb *buf1, *buf2, *ptr;\n#if defined(USE_MUL_CHECK)\n    limb_t ha, hb, hr, h_ref;\n#endif\n    \n    if (ntt_static_init(s1))\n        return -1;\n    s = s1->ntt_state;\n    \n    /* find the optimal number of digits per limb (dpl) */\n    len = a_len + b_len;\n    fft_len_log2 = bf_get_fft_size(&dpl, &nb_mods, len);\n    fft_len = (uint64_t)1 << fft_len_log2;\n    //    printf(\"len=%\" PRId64 \" fft_len_log2=%d dpl=%d\\n\", len, fft_len_log2, dpl);\n#if defined(USE_MUL_CHECK)\n    ha = mp_mod1(a_tab, a_len, BF_CHKSUM_MOD, 0);\n    hb = mp_mod1(b_tab, b_len, BF_CHKSUM_MOD, 0);\n#endif\n    if ((mul_flags & (FFT_MUL_R_OVERLAP_A | FFT_MUL_R_OVERLAP_B)) == 0) {\n        if (!(mul_flags & FFT_MUL_R_NORESIZE))\n            bf_resize(res, 0);\n    } else if (mul_flags & FFT_MUL_R_OVERLAP_B) {\n        limb_t *tmp_tab, tmp_len;\n        /* it is better to free 'b' first */\n        tmp_tab = a_tab;\n        a_tab = b_tab;\n        b_tab = tmp_tab;\n        tmp_len = a_len;\n        a_len = b_len;\n        b_len = tmp_len;\n    }\n    buf1 = ntt_malloc(s, sizeof(NTTLimb) * fft_len * nb_mods);\n    if (!buf1)\n        return -1;\n    limb_to_ntt(s, buf1, fft_len, a_tab, a_len, dpl,\n                NB_MODS - nb_mods, nb_mods);\n    if ((mul_flags & (FFT_MUL_R_OVERLAP_A | FFT_MUL_R_OVERLAP_B)) == \n        FFT_MUL_R_OVERLAP_A) {\n        if (!(mul_flags & FFT_MUL_R_NORESIZE))\n            bf_resize(res, 0);\n    }\n    reduced_mem = (fft_len_log2 >= 14);\n    if (!reduced_mem) {\n        buf2 = ntt_malloc(s, sizeof(NTTLimb) * fft_len * nb_mods);\n        if (!buf2)\n            goto fail;\n        limb_to_ntt(s, buf2, fft_len, b_tab, b_len, dpl,\n                    NB_MODS - nb_mods, nb_mods);\n        if (!(mul_flags & FFT_MUL_R_NORESIZE))\n            bf_resize(res, 0); /* in case res == b */\n    } else {\n        buf2 = ntt_malloc(s, sizeof(NTTLimb) * fft_len);\n        if (!buf2)\n            goto fail;\n    }\n    for(j = 0; j < nb_mods; j++) {\n        if (reduced_mem) {\n            limb_to_ntt(s, buf2, fft_len, b_tab, b_len, dpl,\n                        NB_MODS - nb_mods + j, 1);\n            ptr = buf2;\n        } else {\n            ptr = buf2 + fft_len * j;\n        }\n        if (ntt_conv(s, buf1 + fft_len * j, ptr,\n                     fft_len_log2, fft_len_log2, j + NB_MODS - nb_mods))\n            goto fail;\n    }\n    if (!(mul_flags & FFT_MUL_R_NORESIZE))\n        bf_resize(res, 0); /* in case res == b and reduced mem */\n    ntt_free(s, buf2);\n    buf2 = NULL;\n    if (!(mul_flags & FFT_MUL_R_NORESIZE)) {\n        if (bf_resize(res, len))\n            goto fail;\n    }\n    ntt_to_limb(s, res->tab, len, buf1, fft_len_log2, dpl, nb_mods);\n    ntt_free(s, buf1);\n#if defined(USE_MUL_CHECK)\n    hr = mp_mod1(res->tab, len, BF_CHKSUM_MOD, 0);\n    h_ref = mul_mod(ha, hb, BF_CHKSUM_MOD);\n    if (hr != h_ref) {\n        printf(\"ntt_mul_error: len=%\" PRId_LIMB \" fft_len_log2=%d dpl=%d nb_mods=%d\\n\",\n               len, fft_len_log2, dpl, nb_mods);\n        //        printf(\"ha=0x\" FMT_LIMB\" hb=0x\" FMT_LIMB \" hr=0x\" FMT_LIMB \" expected=0x\" FMT_LIMB \"\\n\", ha, hb, hr, h_ref);\n        exit(1);\n    }\n#endif    \n    return 0;\n fail:\n    ntt_free(s, buf1);\n    ntt_free(s, buf2);\n    return -1;\n}\n\n#else /* USE_FFT_MUL */\n\nint bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len)\n{\n    return 0;\n}\n\n#endif /* !USE_FFT_MUL */\n"
  },
  {
    "path": "libbf.h",
    "content": "/*\n * Tiny arbitrary precision floating point library\n * \n * Copyright (c) 2017-2020 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#ifndef LIBBF_H\n#define LIBBF_H\n\n#include <stddef.h>\n#include <stdint.h>\n\n#if defined(__x86_64__)\n#define LIMB_LOG2_BITS 6\n#else\n#define LIMB_LOG2_BITS 5\n#endif\n\n#define LIMB_BITS (1 << LIMB_LOG2_BITS)\n\n#if LIMB_BITS == 64\ntypedef __int128 int128_t;\ntypedef unsigned __int128 uint128_t;\ntypedef int64_t slimb_t;\ntypedef uint64_t limb_t;\ntypedef uint128_t dlimb_t;\n#define BF_RAW_EXP_MIN INT64_MIN\n#define BF_RAW_EXP_MAX INT64_MAX\n\n#define LIMB_DIGITS 19\n#define BF_DEC_BASE UINT64_C(10000000000000000000)\n\n#else\n\ntypedef int32_t slimb_t;\ntypedef uint32_t limb_t;\ntypedef uint64_t dlimb_t;\n#define BF_RAW_EXP_MIN INT32_MIN\n#define BF_RAW_EXP_MAX INT32_MAX\n\n#define LIMB_DIGITS 9\n#define BF_DEC_BASE 1000000000U\n\n#endif\n\n/* in bits */\n/* minimum number of bits for the exponent */\n#define BF_EXP_BITS_MIN 3\n/* maximum number of bits for the exponent */\n#define BF_EXP_BITS_MAX (LIMB_BITS - 3)\n/* extended range for exponent, used internally */\n#define BF_EXT_EXP_BITS_MAX (BF_EXP_BITS_MAX + 1)\n/* minimum possible precision */\n#define BF_PREC_MIN 2\n/* minimum possible precision */\n#define BF_PREC_MAX (((limb_t)1 << (LIMB_BITS - 2)) - 2)\n/* some operations support infinite precision */\n#define BF_PREC_INF (BF_PREC_MAX + 1) /* infinite precision */\n\n#if LIMB_BITS == 64\n#define BF_CHKSUM_MOD (UINT64_C(975620677) * UINT64_C(9795002197))\n#else\n#define BF_CHKSUM_MOD 975620677U\n#endif\n\n#define BF_EXP_ZERO BF_RAW_EXP_MIN\n#define BF_EXP_INF (BF_RAW_EXP_MAX - 1)\n#define BF_EXP_NAN BF_RAW_EXP_MAX\n\n/* +/-zero is represented with expn = BF_EXP_ZERO and len = 0,\n   +/-infinity is represented with expn = BF_EXP_INF and len = 0,\n   NaN is represented with expn = BF_EXP_NAN and len = 0 (sign is ignored)\n */\ntypedef struct {\n    struct bf_context_t *ctx;\n    int sign;\n    slimb_t expn;\n    limb_t len;\n    limb_t *tab;\n} bf_t;\n\ntypedef struct {\n    /* must be kept identical to bf_t */\n    struct bf_context_t *ctx;\n    int sign;\n    slimb_t expn;\n    limb_t len;\n    limb_t *tab;\n} bfdec_t;\n\ntypedef enum {\n    BF_RNDN, /* round to nearest, ties to even */\n    BF_RNDZ, /* round to zero */\n    BF_RNDD, /* round to -inf (the code relies on (BF_RNDD xor BF_RNDU) = 1) */\n    BF_RNDU, /* round to +inf */\n    BF_RNDNA, /* round to nearest, ties away from zero */\n    BF_RNDA, /* round away from zero */\n    BF_RNDF, /* faithful rounding (nondeterministic, either RNDD or RNDU,\n                inexact flag is always set)  */\n} bf_rnd_t;\n\n/* allow subnormal numbers. Only available if the number of exponent\n   bits is <= BF_EXP_BITS_USER_MAX and prec != BF_PREC_INF. */\n#define BF_FLAG_SUBNORMAL (1 << 3)\n/* 'prec' is the precision after the radix point instead of the whole\n   mantissa. Can only be used with bf_round() and\n   bfdec_[add|sub|mul|div|sqrt|round](). */\n#define BF_FLAG_RADPNT_PREC (1 << 4)\n\n#define BF_RND_MASK 0x7\n#define BF_EXP_BITS_SHIFT 5\n#define BF_EXP_BITS_MASK 0x3f\n\n/* shortcut for bf_set_exp_bits(BF_EXT_EXP_BITS_MAX) */\n#define BF_FLAG_EXT_EXP (BF_EXP_BITS_MASK << BF_EXP_BITS_SHIFT)\n\n/* contains the rounding mode and number of exponents bits */\ntypedef uint32_t bf_flags_t;\n\ntypedef void *bf_realloc_func_t(void *opaque, void *ptr, size_t size);\n\ntypedef struct {\n    bf_t val;\n    limb_t prec;\n} BFConstCache;\n\ntypedef struct bf_context_t {\n    void *realloc_opaque;\n    bf_realloc_func_t *realloc_func;\n    BFConstCache log2_cache;\n    BFConstCache pi_cache;\n    struct BFNTTState *ntt_state;\n} bf_context_t;\n\nstatic inline int bf_get_exp_bits(bf_flags_t flags)\n{\n    int e;\n    e = (flags >> BF_EXP_BITS_SHIFT) & BF_EXP_BITS_MASK;\n    if (e == BF_EXP_BITS_MASK)\n        return BF_EXP_BITS_MAX + 1;\n    else\n        return BF_EXP_BITS_MAX - e;\n}\n\nstatic inline bf_flags_t bf_set_exp_bits(int n)\n{\n    return ((BF_EXP_BITS_MAX - n) & BF_EXP_BITS_MASK) << BF_EXP_BITS_SHIFT;\n}\n\n/* returned status */\n#define BF_ST_INVALID_OP  (1 << 0)\n#define BF_ST_DIVIDE_ZERO (1 << 1)\n#define BF_ST_OVERFLOW    (1 << 2)\n#define BF_ST_UNDERFLOW   (1 << 3)\n#define BF_ST_INEXACT     (1 << 4)\n/* indicate that a memory allocation error occured. NaN is returned */\n#define BF_ST_MEM_ERROR   (1 << 5) \n\n#define BF_RADIX_MAX 36 /* maximum radix for bf_atof() and bf_ftoa() */\n\nstatic inline slimb_t bf_max(slimb_t a, slimb_t b)\n{\n    if (a > b)\n        return a;\n    else\n        return b;\n}\n\nstatic inline slimb_t bf_min(slimb_t a, slimb_t b)\n{\n    if (a < b)\n        return a;\n    else\n        return b;\n}\n\nvoid bf_context_init(bf_context_t *s, bf_realloc_func_t *realloc_func,\n                     void *realloc_opaque);\nvoid bf_context_end(bf_context_t *s);\n/* free memory allocated for the bf cache data */\nvoid bf_clear_cache(bf_context_t *s);\n\nstatic inline void *bf_realloc(bf_context_t *s, void *ptr, size_t size)\n{\n    return s->realloc_func(s->realloc_opaque, ptr, size);\n}\n\n/* 'size' must be != 0 */\nstatic inline void *bf_malloc(bf_context_t *s, size_t size)\n{\n    return bf_realloc(s, NULL, size);\n}\n\nstatic inline void bf_free(bf_context_t *s, void *ptr)\n{\n    /* must test ptr otherwise equivalent to malloc(0) */\n    if (ptr)\n        bf_realloc(s, ptr, 0);\n}\n\nvoid bf_init(bf_context_t *s, bf_t *r);\n\nstatic inline void bf_delete(bf_t *r)\n{\n    bf_context_t *s = r->ctx;\n    /* we accept to delete a zeroed bf_t structure */\n    if (s && r->tab) {\n        bf_realloc(s, r->tab, 0);\n    }\n}\n\nstatic inline void bf_neg(bf_t *r)\n{\n    r->sign ^= 1;\n}\n\nstatic inline int bf_is_finite(const bf_t *a)\n{\n    return (a->expn < BF_EXP_INF);\n}\n\nstatic inline int bf_is_nan(const bf_t *a)\n{\n    return (a->expn == BF_EXP_NAN);\n}\n\nstatic inline int bf_is_zero(const bf_t *a)\n{\n    return (a->expn == BF_EXP_ZERO);\n}\n\nstatic inline void bf_memcpy(bf_t *r, const bf_t *a)\n{\n    *r = *a;\n}\n\nint bf_set_ui(bf_t *r, uint64_t a);\nint bf_set_si(bf_t *r, int64_t a);\nvoid bf_set_nan(bf_t *r);\nvoid bf_set_zero(bf_t *r, int is_neg);\nvoid bf_set_inf(bf_t *r, int is_neg);\nint bf_set(bf_t *r, const bf_t *a);\nvoid bf_move(bf_t *r, bf_t *a);\nint bf_get_float64(const bf_t *a, double *pres, bf_rnd_t rnd_mode);\nint bf_set_float64(bf_t *a, double d);\n\nint bf_cmpu(const bf_t *a, const bf_t *b);\nint bf_cmp_full(const bf_t *a, const bf_t *b);\nint bf_cmp(const bf_t *a, const bf_t *b);\nstatic inline int bf_cmp_eq(const bf_t *a, const bf_t *b)\n{\n    return bf_cmp(a, b) == 0;\n}\n\nstatic inline int bf_cmp_le(const bf_t *a, const bf_t *b)\n{\n    return bf_cmp(a, b) <= 0;\n}\n\nstatic inline int bf_cmp_lt(const bf_t *a, const bf_t *b)\n{\n    return bf_cmp(a, b) < 0;\n}\n\nint bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);\nint bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);\nint bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, bf_flags_t flags);\nint bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);\nint bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec, bf_flags_t flags);\nint bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, \n              bf_flags_t flags);\nint bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags);\nint bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags);\n#define BF_DIVREM_EUCLIDIAN BF_RNDF\nint bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,\n              limb_t prec, bf_flags_t flags, int rnd_mode);\nint bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n           bf_flags_t flags, int rnd_mode);\nint bf_remquo(slimb_t *pq, bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,\n              bf_flags_t flags, int rnd_mode);\n/* round to integer with infinite precision */\nint bf_rint(bf_t *r, int rnd_mode);\nint bf_round(bf_t *r, limb_t prec, bf_flags_t flags);\nint bf_sqrtrem(bf_t *r, bf_t *rem1, const bf_t *a);\nint bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nslimb_t bf_get_exp_min(const bf_t *a);\nint bf_logic_or(bf_t *r, const bf_t *a, const bf_t *b);\nint bf_logic_xor(bf_t *r, const bf_t *a, const bf_t *b);\nint bf_logic_and(bf_t *r, const bf_t *a, const bf_t *b);\n\n/* additional flags for bf_atof */\n/* do not accept hex radix prefix (0x or 0X) if radix = 0 or radix = 16 */\n#define BF_ATOF_NO_HEX       (1 << 16)\n/* accept binary (0b or 0B) or octal (0o or 0O) radix prefix if radix = 0 */\n#define BF_ATOF_BIN_OCT      (1 << 17)\n/* Do not parse NaN or Inf */\n#define BF_ATOF_NO_NAN_INF   (1 << 18)\n/* return the exponent separately */\n#define BF_ATOF_EXPONENT       (1 << 19)\n\nint bf_atof(bf_t *a, const char *str, const char **pnext, int radix,\n            limb_t prec, bf_flags_t flags);\n/* this version accepts prec = BF_PREC_INF and returns the radix\n   exponent */\nint bf_atof2(bf_t *r, slimb_t *pexponent,\n             const char *str, const char **pnext, int radix,\n             limb_t prec, bf_flags_t flags);\nint bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix,\n                     slimb_t expn, limb_t prec, bf_flags_t flags);\n\n\n/* Conversion of floating point number to string. Return a null\n   terminated string or NULL if memory error. *plen contains its\n   length if plen != NULL.  The exponent letter is \"e\" for base 10,\n   \"p\" for bases 2, 8, 16 with a binary exponent and \"@\" for the other\n   bases. */\n\n#define BF_FTOA_FORMAT_MASK (3 << 16)\n\n/* fixed format: prec significant digits rounded with (flags &\n   BF_RND_MASK). Exponential notation is used if too many zeros are\n   needed.*/\n#define BF_FTOA_FORMAT_FIXED (0 << 16)\n/* fractional format: prec digits after the decimal point rounded with\n   (flags & BF_RND_MASK) */\n#define BF_FTOA_FORMAT_FRAC  (1 << 16)\n/* free format: \n   \n   For binary radices with bf_ftoa() and for bfdec_ftoa(): use the minimum\n   number of digits to represent 'a'. The precision and the rounding\n   mode are ignored.\n   \n   For the non binary radices with bf_ftoa(): use as many digits as\n   necessary so that bf_atof() return the same number when using\n   precision 'prec', rounding to nearest and the subnormal\n   configuration of 'flags'. The result is meaningful only if 'a' is\n   already rounded to 'prec' bits. If the subnormal flag is set, the\n   exponent in 'flags' must also be set to the desired exponent range.\n*/\n#define BF_FTOA_FORMAT_FREE  (2 << 16)\n/* same as BF_FTOA_FORMAT_FREE but uses the minimum number of digits\n   (takes more computation time). Identical to BF_FTOA_FORMAT_FREE for\n   binary radices with bf_ftoa() and for bfdec_ftoa(). */\n#define BF_FTOA_FORMAT_FREE_MIN (3 << 16)\n\n/* force exponential notation for fixed or free format */\n#define BF_FTOA_FORCE_EXP    (1 << 20)\n/* add 0x prefix for base 16, 0o prefix for base 8 or 0b prefix for\n   base 2 if non zero value */\n#define BF_FTOA_ADD_PREFIX   (1 << 21)\n/* return \"Infinity\" instead of \"Inf\" and add a \"+\" for positive\n   exponents */\n#define BF_FTOA_JS_QUIRKS    (1 << 22)\n\nchar *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,\n              bf_flags_t flags);\n\n/* modulo 2^n instead of saturation. NaN and infinity return 0 */\n#define BF_GET_INT_MOD (1 << 0) \nint bf_get_int32(int *pres, const bf_t *a, int flags);\nint bf_get_int64(int64_t *pres, const bf_t *a, int flags);\nint bf_get_uint64(uint64_t *pres, const bf_t *a);\n\n/* the following functions are exported for testing only. */\nvoid mp_print_str(const char *str, const limb_t *tab, limb_t n);\nvoid bf_print_str(const char *str, const bf_t *a);\nint bf_resize(bf_t *r, limb_t len);\nint bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len);\nint bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags);\nint bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k);\nslimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,\n                          int is_ceil1);\nint mp_mul(bf_context_t *s, limb_t *result, \n           const limb_t *op1, limb_t op1_size, \n           const limb_t *op2, limb_t op2_size);\nlimb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2, \n              limb_t n, limb_t carry);\nlimb_t mp_add_ui(limb_t *tab, limb_t b, size_t n);\nint mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n);\nint mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n);\nlimb_t bf_isqrt(limb_t a);\n\n/* transcendental functions */\nint bf_const_log2(bf_t *T, limb_t prec, bf_flags_t flags);\nint bf_const_pi(bf_t *T, limb_t prec, bf_flags_t flags);\nint bf_exp(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nint bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\n#define BF_POW_JS_QUIRKS (1 << 16) /* (+/-1)^(+/-Inf) = NaN, 1^NaN = NaN */\nint bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_t flags);\nint bf_cos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nint bf_sin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nint bf_tan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nint bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nint bf_atan2(bf_t *r, const bf_t *y, const bf_t *x,\n             limb_t prec, bf_flags_t flags);\nint bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\nint bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags);\n\n/* decimal floating point */\n\nstatic inline void bfdec_init(bf_context_t *s, bfdec_t *r)\n{\n    bf_init(s, (bf_t *)r);\n}\nstatic inline void bfdec_delete(bfdec_t *r)\n{\n    bf_delete((bf_t *)r);\n}\n\nstatic inline void bfdec_neg(bfdec_t *r)\n{\n    r->sign ^= 1;\n}\n\nstatic inline int bfdec_is_finite(const bfdec_t *a)\n{\n    return (a->expn < BF_EXP_INF);\n}\n\nstatic inline int bfdec_is_nan(const bfdec_t *a)\n{\n    return (a->expn == BF_EXP_NAN);\n}\n\nstatic inline int bfdec_is_zero(const bfdec_t *a)\n{\n    return (a->expn == BF_EXP_ZERO);\n}\n\nstatic inline void bfdec_memcpy(bfdec_t *r, const bfdec_t *a)\n{\n    bf_memcpy((bf_t *)r, (const bf_t *)a);\n}\n\nint bfdec_set_ui(bfdec_t *r, uint64_t a);\nint bfdec_set_si(bfdec_t *r, int64_t a);\n\nstatic inline void bfdec_set_nan(bfdec_t *r)\n{\n    bf_set_nan((bf_t *)r);\n}\nstatic inline void bfdec_set_zero(bfdec_t *r, int is_neg)\n{\n    bf_set_zero((bf_t *)r, is_neg);\n}\nstatic inline void bfdec_set_inf(bfdec_t *r, int is_neg)\n{\n    bf_set_inf((bf_t *)r, is_neg);\n}\nstatic inline int bfdec_set(bfdec_t *r, const bfdec_t *a)\n{\n    return bf_set((bf_t *)r, (bf_t *)a);\n}\nstatic inline void bfdec_move(bfdec_t *r, bfdec_t *a)\n{\n    bf_move((bf_t *)r, (bf_t *)a);\n}\nstatic inline int bfdec_cmpu(const bfdec_t *a, const bfdec_t *b)\n{\n    return bf_cmpu((const bf_t *)a, (const bf_t *)b);\n}\nstatic inline int bfdec_cmp_full(const bfdec_t *a, const bfdec_t *b)\n{\n    return bf_cmp_full((const bf_t *)a, (const bf_t *)b);\n}\nstatic inline int bfdec_cmp(const bfdec_t *a, const bfdec_t *b)\n{\n    return bf_cmp((const bf_t *)a, (const bf_t *)b);\n}\nstatic inline int bfdec_cmp_eq(const bfdec_t *a, const bfdec_t *b)\n{\n    return bfdec_cmp(a, b) == 0;\n}\nstatic inline int bfdec_cmp_le(const bfdec_t *a, const bfdec_t *b)\n{\n    return bfdec_cmp(a, b) <= 0;\n}\nstatic inline int bfdec_cmp_lt(const bfdec_t *a, const bfdec_t *b)\n{\n    return bfdec_cmp(a, b) < 0;\n}\n\nint bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags);\nint bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags);\nint bfdec_add_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec,\n                 bf_flags_t flags);\nint bfdec_mul(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags);\nint bfdec_mul_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec,\n                 bf_flags_t flags);\nint bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags);\nint bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b,\n                 limb_t prec, bf_flags_t flags, int rnd_mode);\nint bfdec_rem(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,\n              bf_flags_t flags, int rnd_mode);\nint bfdec_rint(bfdec_t *r, int rnd_mode);\nint bfdec_sqrt(bfdec_t *r, const bfdec_t *a, limb_t prec, bf_flags_t flags);\nint bfdec_round(bfdec_t *r, limb_t prec, bf_flags_t flags);\nint bfdec_get_int32(int *pres, const bfdec_t *a);\nint bfdec_pow_ui(bfdec_t *r, const bfdec_t *a, limb_t b);\n\nchar *bfdec_ftoa(size_t *plen, const bfdec_t *a, limb_t prec, bf_flags_t flags);\nint bfdec_atof(bfdec_t *r, const char *str, const char **pnext,\n               limb_t prec, bf_flags_t flags);\n\n/* the following functions are exported for testing only. */\nextern const limb_t mp_pow_dec[LIMB_DIGITS + 1];\nvoid bfdec_print_str(const char *str, const bfdec_t *a);\nstatic inline int bfdec_resize(bfdec_t *r, limb_t len)\n{\n    return bf_resize((bf_t *)r, len);\n}\nint bfdec_normalize_and_round(bfdec_t *r, limb_t prec1, bf_flags_t flags);\n\n#endif /* LIBBF_H */\n"
  },
  {
    "path": "libregexp-opcode.h",
    "content": "/*\n * Regular Expression Engine\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n#ifdef DEF\n\nDEF(invalid, 1) /* never used */\nDEF(char, 3)\nDEF(char32, 5)\nDEF(dot, 1)\nDEF(any, 1) /* same as dot but match any character including line terminator */\nDEF(line_start, 1)\nDEF(line_end, 1)\nDEF(goto, 5)\nDEF(split_goto_first, 5)\nDEF(split_next_first, 5)\nDEF(match, 1)\nDEF(save_start, 2) /* save start position */\nDEF(save_end, 2) /* save end position, must come after saved_start */\nDEF(save_reset, 3) /* reset save positions */\nDEF(loop, 5) /* decrement the top the stack and goto if != 0 */\nDEF(push_i32, 5) /* push integer on the stack */\nDEF(drop, 1)\nDEF(word_boundary, 1)\nDEF(not_word_boundary, 1)\nDEF(back_reference, 2)\nDEF(backward_back_reference, 2) /* must come after back_reference */\nDEF(range, 3) /* variable length */\nDEF(range32, 3) /* variable length */\nDEF(lookahead, 5)\nDEF(negative_lookahead, 5)\nDEF(push_char_pos, 1) /* push the character position on the stack */\nDEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character\n position */\nDEF(prev, 1) /* go to the previous char */\nDEF(simple_greedy_quant, 17)\n\n#endif /* DEF */\n"
  },
  {
    "path": "libregexp.c",
    "content": "/*\n * Regular Expression Engine\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <stdarg.h>\n#include <inttypes.h>\n#include <string.h>\n#include <assert.h>\n\n#include \"cutils.h\"\n#include \"libregexp.h\"\n\n/*\n  TODO:\n\n  - Add full unicode canonicalize rules for character ranges (not\n    really useful but needed for exact \"ignorecase\" compatibility).\n\n  - Add a lock step execution mode (=linear time execution guaranteed)\n    when the regular expression is \"simple\" i.e. no backreference nor\n    complicated lookahead. The opcodes are designed for this execution\n    model.\n*/\n\n#if defined(TEST)\n#define DUMP_REOP\n#endif\n\ntypedef enum {\n#define DEF(id, size) REOP_ ## id,\n#include \"libregexp-opcode.h\"\n#undef DEF\n    REOP_COUNT,\n} REOPCodeEnum;\n\n#define CAPTURE_COUNT_MAX 255\n#define STACK_SIZE_MAX 255\n\n/* unicode code points */\n#define CP_LS   0x2028\n#define CP_PS   0x2029\n\n#define TMP_BUF_SIZE 128\n\ntypedef struct {\n    DynBuf byte_code;\n    const uint8_t *buf_ptr;\n    const uint8_t *buf_end;\n    const uint8_t *buf_start;\n    int re_flags;\n    BOOL is_utf16;\n    BOOL ignore_case;\n    BOOL dotall;\n    int capture_count;\n    int total_capture_count; /* -1 = not computed yet */\n    int has_named_captures; /* -1 = don't know, 0 = no, 1 = yes */\n    void *mem_opaque;\n    DynBuf group_names;\n    union {\n        char error_msg[TMP_BUF_SIZE];\n        char tmp_buf[TMP_BUF_SIZE];\n    } u;\n} REParseState;\n\ntypedef struct {\n#ifdef DUMP_REOP\n    const char *name;\n#endif\n    uint8_t size;\n} REOpCode;\n\nstatic const REOpCode reopcode_info[REOP_COUNT] = {\n#ifdef DUMP_REOP\n#define DEF(id, size) { #id, size },\n#else\n#define DEF(id, size) { size },\n#endif\n#include \"libregexp-opcode.h\"\n#undef DEF\n};\n\n#define RE_HEADER_FLAGS         0\n#define RE_HEADER_CAPTURE_COUNT 1\n#define RE_HEADER_STACK_SIZE    2\n\n#define RE_HEADER_LEN 7\n\nstatic inline int is_digit(int c) {\n    return c >= '0' && c <= '9';\n}\n\n/* insert 'len' bytes at position 'pos'. Return < 0 if error. */\nstatic int dbuf_insert(DynBuf *s, int pos, int len)\n{\n    if (dbuf_realloc(s, s->size + len))\n        return -1;\n    memmove(s->buf + pos + len, s->buf + pos, s->size - pos);\n    s->size += len;\n    return 0;\n}\n\n/* canonicalize with the specific JS regexp rules */\nstatic uint32_t lre_canonicalize(uint32_t c, BOOL is_utf16)\n{\n    uint32_t res[LRE_CC_RES_LEN_MAX];\n    int len;\n    if (is_utf16) {\n        if (likely(c < 128)) {\n            if (c >= 'A' && c <= 'Z')\n                c = c - 'A' + 'a';\n        } else {\n            lre_case_conv(res, c, 2);\n            c = res[0];\n        }\n    } else {\n        if (likely(c < 128)) {\n            if (c >= 'a' && c <= 'z')\n                c = c - 'a' + 'A';\n        } else {\n            /* legacy regexp: to upper case if single char >= 128 */\n            len = lre_case_conv(res, c, FALSE);\n            if (len == 1 && res[0] >= 128)\n                c = res[0];\n        }\n    }\n    return c;\n}\n\nstatic const uint16_t char_range_d[] = {\n    1,\n    0x0030, 0x0039 + 1,\n};\n\n/* code point ranges for Zs,Zl or Zp property */\nstatic const uint16_t char_range_s[] = {\n    10,\n    0x0009, 0x000D + 1,\n    0x0020, 0x0020 + 1,\n    0x00A0, 0x00A0 + 1,\n    0x1680, 0x1680 + 1,\n    0x2000, 0x200A + 1,\n    /* 2028;LINE SEPARATOR;Zl;0;WS;;;;;N;;;;; */\n    /* 2029;PARAGRAPH SEPARATOR;Zp;0;B;;;;;N;;;;; */\n    0x2028, 0x2029 + 1,\n    0x202F, 0x202F + 1,\n    0x205F, 0x205F + 1,\n    0x3000, 0x3000 + 1,\n    /* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;; */\n    0xFEFF, 0xFEFF + 1,\n};\n\nBOOL lre_is_space(int c)\n{\n    int i, n, low, high;\n    n = (countof(char_range_s) - 1) / 2;\n    for(i = 0; i < n; i++) {\n        low = char_range_s[2 * i + 1];\n        if (c < low)\n            return FALSE;\n        high = char_range_s[2 * i + 2];\n        if (c < high)\n            return TRUE;\n    }\n    return FALSE;\n}\n\nuint32_t const lre_id_start_table_ascii[4] = {\n    /* $ A-Z _ a-z */\n    0x00000000, 0x00000010, 0x87FFFFFE, 0x07FFFFFE\n};\n\nuint32_t const lre_id_continue_table_ascii[4] = {\n    /* $ 0-9 A-Z _ a-z */\n    0x00000000, 0x03FF0010, 0x87FFFFFE, 0x07FFFFFE\n};\n\n\nstatic const uint16_t char_range_w[] = {\n    4,\n    0x0030, 0x0039 + 1,\n    0x0041, 0x005A + 1,\n    0x005F, 0x005F + 1,\n    0x0061, 0x007A + 1,\n};\n\n#define CLASS_RANGE_BASE 0x40000000\n\ntypedef enum {\n    CHAR_RANGE_d,\n    CHAR_RANGE_D,\n    CHAR_RANGE_s,\n    CHAR_RANGE_S,\n    CHAR_RANGE_w,\n    CHAR_RANGE_W,\n} CharRangeEnum;\n\nstatic const uint16_t *char_range_table[] = {\n    char_range_d,\n    char_range_s,\n    char_range_w,\n};\n\nstatic int cr_init_char_range(REParseState *s, CharRange *cr, uint32_t c)\n{\n    BOOL invert;\n    const uint16_t *c_pt;\n    int len, i;\n    \n    invert = c & 1;\n    c_pt = char_range_table[c >> 1];\n    len = *c_pt++;\n    cr_init(cr, s->mem_opaque, lre_realloc);\n    for(i = 0; i < len * 2; i++) {\n        if (cr_add_point(cr, c_pt[i]))\n            goto fail;\n    }\n    if (invert) {\n        if (cr_invert(cr))\n            goto fail;\n    }\n    return 0;\n fail:\n    cr_free(cr);\n    return -1;\n}\n\nstatic int cr_canonicalize(CharRange *cr)\n{\n    CharRange a;\n    uint32_t pt[2];\n    int i, ret;\n\n    cr_init(&a, cr->mem_opaque, lre_realloc);\n    pt[0] = 'a';\n    pt[1] = 'z' + 1;\n    ret = cr_op(&a, cr->points, cr->len, pt, 2, CR_OP_INTER);\n    if (ret)\n        goto fail;\n    /* convert to upper case */\n    /* XXX: the generic unicode case would be much more complicated\n       and not really useful */\n    for(i = 0; i < a.len; i++) {\n        a.points[i] += 'A' - 'a';\n    }\n    /* Note: for simplicity we keep the lower case ranges */\n    ret = cr_union1(cr, a.points, a.len);\n fail:\n    cr_free(&a);\n    return ret;\n}\n\n#ifdef DUMP_REOP\nstatic __maybe_unused void lre_dump_bytecode(const uint8_t *buf,\n                                                     int buf_len)\n{\n    int pos, len, opcode, bc_len, re_flags, i;\n    uint32_t val;\n    \n    assert(buf_len >= RE_HEADER_LEN);\n\n    re_flags=  buf[0];\n    bc_len = get_u32(buf + 3);\n    assert(bc_len + RE_HEADER_LEN <= buf_len);\n    printf(\"flags: 0x%x capture_count=%d stack_size=%d\\n\",\n           re_flags, buf[1], buf[2]);\n    if (re_flags & LRE_FLAG_NAMED_GROUPS) {\n        const char *p;\n        p = (char *)buf + RE_HEADER_LEN + bc_len;\n        printf(\"named groups: \");\n        for(i = 1; i < buf[1]; i++) {\n            if (i != 1)\n                printf(\",\");\n            printf(\"<%s>\", p);\n            p += strlen(p) + 1;\n        }\n        printf(\"\\n\");\n        assert(p == (char *)(buf + buf_len));\n    }\n    printf(\"bytecode_len=%d\\n\", bc_len);\n\n    buf += RE_HEADER_LEN;\n    pos = 0;\n    while (pos < bc_len) {\n        printf(\"%5u: \", pos);\n        opcode = buf[pos];\n        len = reopcode_info[opcode].size;\n        if (opcode >= REOP_COUNT) {\n            printf(\" invalid opcode=0x%02x\\n\", opcode);\n            break;\n        }\n        if ((pos + len) > bc_len) {\n            printf(\" buffer overflow (opcode=0x%02x)\\n\", opcode);\n            break;\n        }\n        printf(\"%s\", reopcode_info[opcode].name);\n        switch(opcode) {\n        case REOP_char:\n            val = get_u16(buf + pos + 1);\n            if (val >= ' ' && val <= 126)\n                printf(\" '%c'\", val);\n            else\n                printf(\" 0x%04x\", val);\n            break;\n        case REOP_char32:\n            val = get_u32(buf + pos + 1);\n            if (val >= ' ' && val <= 126)\n                printf(\" '%c'\", val);\n            else\n                printf(\" 0x%08x\", val);\n            break;\n        case REOP_goto:\n        case REOP_split_goto_first:\n        case REOP_split_next_first:\n        case REOP_loop:\n        case REOP_lookahead:\n        case REOP_negative_lookahead:\n        case REOP_bne_char_pos:\n            val = get_u32(buf + pos + 1);\n            val += (pos + 5);\n            printf(\" %u\", val);\n            break;\n        case REOP_simple_greedy_quant:\n            printf(\" %u %u %u %u\",\n                   get_u32(buf + pos + 1) + (pos + 17),\n                   get_u32(buf + pos + 1 + 4),\n                   get_u32(buf + pos + 1 + 8),\n                   get_u32(buf + pos + 1 + 12));\n            break;\n        case REOP_save_start:\n        case REOP_save_end:\n        case REOP_back_reference:\n        case REOP_backward_back_reference:\n            printf(\" %u\", buf[pos + 1]);\n            break;\n        case REOP_save_reset:\n            printf(\" %u %u\", buf[pos + 1], buf[pos + 2]);\n            break;\n        case REOP_push_i32:\n            val = get_u32(buf + pos + 1);\n            printf(\" %d\", val);\n            break;\n        case REOP_range:\n            {\n                int n, i;\n                n = get_u16(buf + pos + 1);\n                len += n * 4;\n                for(i = 0; i < n * 2; i++) {\n                    val = get_u16(buf + pos + 3 + i * 2);\n                    printf(\" 0x%04x\", val);\n                }\n            }\n            break;\n        case REOP_range32:\n            {\n                int n, i;\n                n = get_u16(buf + pos + 1);\n                len += n * 8;\n                for(i = 0; i < n * 2; i++) {\n                    val = get_u32(buf + pos + 3 + i * 4);\n                    printf(\" 0x%08x\", val);\n                }\n            }\n            break;\n        default:\n            break;\n        }\n        printf(\"\\n\");\n        pos += len;\n    }\n}\n#endif\n\nstatic void re_emit_op(REParseState *s, int op)\n{\n    dbuf_putc(&s->byte_code, op);\n}\n\n/* return the offset of the u32 value */\nstatic int re_emit_op_u32(REParseState *s, int op, uint32_t val)\n{\n    int pos;\n    dbuf_putc(&s->byte_code, op);\n    pos = s->byte_code.size;\n    dbuf_put_u32(&s->byte_code, val);\n    return pos;\n}\n\nstatic int re_emit_goto(REParseState *s, int op, uint32_t val)\n{\n    int pos;\n    dbuf_putc(&s->byte_code, op);\n    pos = s->byte_code.size;\n    dbuf_put_u32(&s->byte_code, val - (pos + 4));\n    return pos;\n}\n\nstatic void re_emit_op_u8(REParseState *s, int op, uint32_t val)\n{\n    dbuf_putc(&s->byte_code, op);\n    dbuf_putc(&s->byte_code, val);\n}\n\nstatic void re_emit_op_u16(REParseState *s, int op, uint32_t val)\n{\n    dbuf_putc(&s->byte_code, op);\n    dbuf_put_u16(&s->byte_code, val);\n}\n\nstatic int __attribute__((format(printf, 2, 3))) re_parse_error(REParseState *s, const char *fmt, ...)\n{\n    va_list ap;\n    va_start(ap, fmt);\n    vsnprintf(s->u.error_msg, sizeof(s->u.error_msg), fmt, ap);\n    va_end(ap);\n    return -1;\n}\n\nstatic int re_parse_out_of_memory(REParseState *s)\n{\n    return re_parse_error(s, \"out of memory\");\n}\n\n/* If allow_overflow is false, return -1 in case of\n   overflow. Otherwise return INT32_MAX. */\nstatic int parse_digits(const uint8_t **pp, BOOL allow_overflow)\n{\n    const uint8_t *p;\n    uint64_t v;\n    int c;\n    \n    p = *pp;\n    v = 0;\n    for(;;) {\n        c = *p;\n        if (c < '0' || c > '9')\n            break;\n        v = v * 10 + c - '0';\n        if (v >= INT32_MAX) {\n            if (allow_overflow)\n                v = INT32_MAX;\n            else\n                return -1;\n        }\n        p++;\n    }\n    *pp = p;\n    return v;\n}\n\nstatic int re_parse_expect(REParseState *s, const uint8_t **pp, int c)\n{\n    const uint8_t *p;\n    p = *pp;\n    if (*p != c)\n        return re_parse_error(s, \"expecting '%c'\", c);\n    p++;\n    *pp = p;\n    return 0;\n}\n\n/* Parse an escape sequence, *pp points after the '\\':\n   allow_utf16 value:\n   0 : no UTF-16 escapes allowed\n   1 : UTF-16 escapes allowed\n   2 : UTF-16 escapes allowed and escapes of surrogate pairs are\n   converted to a unicode character (unicode regexp case).\n\n   Return the unicode char and update *pp if recognized,\n   return -1 if malformed escape,\n   return -2 otherwise. */\nint lre_parse_escape(const uint8_t **pp, int allow_utf16)\n{\n    const uint8_t *p;\n    uint32_t c;\n\n    p = *pp;\n    c = *p++;\n    switch(c) {\n    case 'b':\n        c = '\\b';\n        break;\n    case 'f':\n        c = '\\f';\n        break;\n    case 'n':\n        c = '\\n';\n        break;\n    case 'r':\n        c = '\\r';\n        break;\n    case 't':\n        c = '\\t';\n        break;\n    case 'v':\n        c = '\\v';\n        break;\n    case 'x':\n    case 'u':\n        {\n            int h, n, i;\n            uint32_t c1;\n            \n            if (*p == '{' && allow_utf16) {\n                p++;\n                c = 0;\n                for(;;) {\n                    h = from_hex(*p++);\n                    if (h < 0)\n                        return -1;\n                    c = (c << 4) | h;\n                    if (c > 0x10FFFF)\n                        return -1;\n                    if (*p == '}')\n                        break;\n                }\n                p++;\n            } else {\n                if (c == 'x') {\n                    n = 2;\n                } else {\n                    n = 4;\n                }\n\n                c = 0;\n                for(i = 0; i < n; i++) {\n                    h = from_hex(*p++);\n                    if (h < 0) {\n                        return -1;\n                    }\n                    c = (c << 4) | h;\n                }\n                if (c >= 0xd800 && c < 0xdc00 &&\n                    allow_utf16 == 2 && p[0] == '\\\\' && p[1] == 'u') {\n                    /* convert an escaped surrogate pair into a\n                       unicode char */\n                    c1 = 0;\n                    for(i = 0; i < 4; i++) {\n                        h = from_hex(p[2 + i]);\n                        if (h < 0)\n                            break;\n                        c1 = (c1 << 4) | h;\n                    }\n                    if (i == 4 && c1 >= 0xdc00 && c1 < 0xe000) {\n                        p += 6;\n                        c = (((c & 0x3ff) << 10) | (c1 & 0x3ff)) + 0x10000;\n                    }\n                }\n            }\n        }\n        break;\n    case '0' ... '7':\n        c -= '0';\n        if (allow_utf16 == 2) {\n            /* only accept \\0 not followed by digit */\n            if (c != 0 || is_digit(*p))\n                return -1;\n        } else {\n            /* parse a legacy octal sequence */\n            uint32_t v;\n            v = *p - '0';\n            if (v > 7)\n                break;\n            c = (c << 3) | v;\n            p++;\n            if (c >= 32)\n                break;\n            v = *p - '0';\n            if (v > 7)\n                break;\n            c = (c << 3) | v;\n            p++;\n        }\n        break;\n    default:\n        return -2;\n    }\n    *pp = p;\n    return c;\n}\n\n#ifdef CONFIG_ALL_UNICODE\n/* XXX: we use the same chars for name and value */\nstatic BOOL is_unicode_char(int c)\n{\n    return ((c >= '0' && c <= '9') ||\n            (c >= 'A' && c <= 'Z') ||\n            (c >= 'a' && c <= 'z') ||\n            (c == '_'));\n}\n\nstatic int parse_unicode_property(REParseState *s, CharRange *cr,\n                                  const uint8_t **pp, BOOL is_inv)\n{\n    const uint8_t *p;\n    char name[64], value[64];\n    char *q;\n    BOOL script_ext;\n    int ret;\n\n    p = *pp;\n    if (*p != '{')\n        return re_parse_error(s, \"expecting '{' after \\\\p\");\n    p++;\n    q = name;\n    while (is_unicode_char(*p)) {\n        if ((q - name) > sizeof(name) - 1)\n            goto unknown_property_name;\n        *q++ = *p++;\n    }\n    *q = '\\0';\n    q = value;\n    if (*p == '=') {\n        p++;\n        while (is_unicode_char(*p)) {\n            if ((q - value) > sizeof(value) - 1)\n                return re_parse_error(s, \"unknown unicode property value\");\n            *q++ = *p++;\n        }\n    }\n    *q = '\\0';\n    if (*p != '}')\n        return re_parse_error(s, \"expecting '}'\");\n    p++;\n    //    printf(\"name=%s value=%s\\n\", name, value);\n\n    if (!strcmp(name, \"Script\") || !strcmp(name, \"sc\")) {\n        script_ext = FALSE;\n        goto do_script;\n    } else if (!strcmp(name, \"Script_Extensions\") || !strcmp(name, \"scx\")) {\n        script_ext = TRUE;\n    do_script:\n        cr_init(cr, s->mem_opaque, lre_realloc);\n        ret = unicode_script(cr, value, script_ext);\n        if (ret) {\n            cr_free(cr);\n            if (ret == -2)\n                return re_parse_error(s, \"unknown unicode script\");\n            else\n                goto out_of_memory;\n        }\n    } else if (!strcmp(name, \"General_Category\") || !strcmp(name, \"gc\")) {\n        cr_init(cr, s->mem_opaque, lre_realloc);\n        ret = unicode_general_category(cr, value);\n        if (ret) {\n            cr_free(cr);\n            if (ret == -2)\n                return re_parse_error(s, \"unknown unicode general category\");\n            else\n                goto out_of_memory;\n        }\n    } else if (value[0] == '\\0') {\n        cr_init(cr, s->mem_opaque, lre_realloc);\n        ret = unicode_general_category(cr, name);\n        if (ret == -1) {\n            cr_free(cr);\n            goto out_of_memory;\n        }\n        if (ret < 0) {\n            ret = unicode_prop(cr, name);\n            if (ret) {\n                cr_free(cr);\n                if (ret == -2)\n                    goto unknown_property_name;\n                else\n                    goto out_of_memory;\n            }\n        }\n    } else {\n    unknown_property_name:\n        return re_parse_error(s, \"unknown unicode property name\");\n    }\n\n    if (is_inv) {\n        if (cr_invert(cr)) {\n            cr_free(cr);\n            return -1;\n        }\n    }\n    *pp = p;\n    return 0;\n out_of_memory:\n    return re_parse_out_of_memory(s);\n}\n#endif /* CONFIG_ALL_UNICODE */\n\n/* return -1 if error otherwise the character or a class range\n   (CLASS_RANGE_BASE). In case of class range, 'cr' is\n   initialized. Otherwise, it is ignored. */\nstatic int get_class_atom(REParseState *s, CharRange *cr,\n                          const uint8_t **pp, BOOL inclass)\n{\n    const uint8_t *p;\n    uint32_t c;\n    int ret;\n    \n    p = *pp;\n\n    c = *p;\n    switch(c) {\n    case '\\\\':\n        p++;\n        if (p >= s->buf_end)\n            goto unexpected_end;\n        c = *p++;\n        switch(c) {\n        case 'd':\n            c = CHAR_RANGE_d;\n            goto class_range;\n        case 'D':\n            c = CHAR_RANGE_D;\n            goto class_range;\n        case 's':\n            c = CHAR_RANGE_s;\n            goto class_range;\n        case 'S':\n            c = CHAR_RANGE_S;\n            goto class_range;\n        case 'w':\n            c = CHAR_RANGE_w;\n            goto class_range;\n        case 'W':\n            c = CHAR_RANGE_W;\n        class_range:\n            if (cr_init_char_range(s, cr, c))\n                return -1;\n            c = CLASS_RANGE_BASE;\n            break;\n        case 'c':\n            c = *p;\n            if ((c >= 'a' && c <= 'z') ||\n                (c >= 'A' && c <= 'Z') ||\n                (((c >= '0' && c <= '9') || c == '_') &&\n                 inclass && !s->is_utf16)) {   /* Annex B.1.4 */\n                c &= 0x1f;\n                p++;\n            } else if (s->is_utf16) {\n                goto invalid_escape;\n            } else {\n                /* otherwise return '\\' and 'c' */\n                p--;\n                c = '\\\\';\n            }\n            break;\n#ifdef CONFIG_ALL_UNICODE\n        case 'p':\n        case 'P':\n            if (s->is_utf16) {\n                if (parse_unicode_property(s, cr, &p, (c == 'P')))\n                    return -1;\n                c = CLASS_RANGE_BASE;\n                break;\n            }\n            /* fall thru */\n#endif\n        default:\n            p--;\n            ret = lre_parse_escape(&p, s->is_utf16 * 2);\n            if (ret >= 0) {\n                c = ret;\n            } else {\n                if (ret == -2 && *p != '\\0' && strchr(\"^$\\\\.*+?()[]{}|/\", *p)) {\n                    /* always valid to escape these characters */\n                    goto normal_char;\n                } else if (s->is_utf16) {\n                invalid_escape:\n                    return re_parse_error(s, \"invalid escape sequence in regular expression\");\n                } else {\n                    /* just ignore the '\\' */\n                    goto normal_char;\n                }\n            }\n            break;\n        }\n        break;\n    case '\\0':\n        if (p >= s->buf_end) {\n        unexpected_end:\n            return re_parse_error(s, \"unexpected end\");\n        }\n        /* fall thru */\n    default:\n    normal_char:\n        /* normal char */\n        if (c >= 128) {\n            c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n            if ((unsigned)c > 0xffff && !s->is_utf16) {\n                /* XXX: should handle non BMP-1 code points */\n                return re_parse_error(s, \"malformed unicode char\");\n            }\n        } else {\n            p++;\n        }\n        break;\n    }\n    *pp = p;\n    return c;\n}\n\nstatic int re_emit_range(REParseState *s, const CharRange *cr)\n{\n    int len, i;\n    uint32_t high;\n    \n    len = (unsigned)cr->len / 2;\n    if (len >= 65535)\n        return re_parse_error(s, \"too many ranges\");\n    if (len == 0) {\n        /* not sure it can really happen. Emit a match that is always\n           false */\n        re_emit_op_u32(s, REOP_char32, -1);\n    } else {\n        high = cr->points[cr->len - 1];\n        if (high == UINT32_MAX)\n            high = cr->points[cr->len - 2];\n        if (high <= 0xffff) {\n            /* can use 16 bit ranges with the conversion that 0xffff =\n               infinity */\n            re_emit_op_u16(s, REOP_range, len);\n            for(i = 0; i < cr->len; i += 2) {\n                dbuf_put_u16(&s->byte_code, cr->points[i]);\n                high = cr->points[i + 1] - 1;\n                if (high == UINT32_MAX - 1)\n                    high = 0xffff;\n                dbuf_put_u16(&s->byte_code, high);\n            }\n        } else {\n            re_emit_op_u16(s, REOP_range32, len);\n            for(i = 0; i < cr->len; i += 2) {\n                dbuf_put_u32(&s->byte_code, cr->points[i]);\n                dbuf_put_u32(&s->byte_code, cr->points[i + 1] - 1);\n            }\n        }\n    }\n    return 0;\n}\n\nstatic int re_parse_char_class(REParseState *s, const uint8_t **pp)\n{\n    const uint8_t *p;\n    uint32_t c1, c2;\n    CharRange cr_s, *cr = &cr_s;\n    CharRange cr1_s, *cr1 = &cr1_s;\n    BOOL invert;\n    \n    cr_init(cr, s->mem_opaque, lre_realloc);\n    p = *pp;\n    p++;    /* skip '[' */\n    invert = FALSE;\n    if (*p == '^') {\n        p++;\n        invert = TRUE;\n    }\n    for(;;) {\n        if (*p == ']')\n            break;\n        c1 = get_class_atom(s, cr1, &p, TRUE);\n        if ((int)c1 < 0)\n            goto fail;\n        if (*p == '-' && p[1] != ']') {\n            const uint8_t *p0 = p + 1;\n            if (c1 >= CLASS_RANGE_BASE) {\n                if (s->is_utf16) {\n                    cr_free(cr1);\n                    goto invalid_class_range;\n                }\n                /* Annex B: match '-' character */\n                goto class_atom;\n            }\n            c2 = get_class_atom(s, cr1, &p0, TRUE);\n            if ((int)c2 < 0)\n                goto fail;\n            if (c2 >= CLASS_RANGE_BASE) {\n                cr_free(cr1);\n                if (s->is_utf16) {\n                    goto invalid_class_range;\n                }\n                /* Annex B: match '-' character */\n                goto class_atom;\n            }\n            p = p0;\n            if (c2 < c1) {\n            invalid_class_range:\n                re_parse_error(s, \"invalid class range\");\n                goto fail;\n            }\n            if (cr_union_interval(cr, c1, c2))\n                goto memory_error;\n        } else {\n        class_atom:\n            if (c1 >= CLASS_RANGE_BASE) {\n                int ret;\n                ret = cr_union1(cr, cr1->points, cr1->len);\n                cr_free(cr1);\n                if (ret)\n                    goto memory_error;\n            } else {\n                if (cr_union_interval(cr, c1, c1))\n                    goto memory_error;\n            }\n        }\n    }\n    if (s->ignore_case) {\n        if (cr_canonicalize(cr))\n            goto memory_error;\n    }\n    if (invert) {\n        if (cr_invert(cr))\n            goto memory_error;\n    }\n    if (re_emit_range(s, cr))\n        goto fail;\n    cr_free(cr);\n    p++;    /* skip ']' */\n    *pp = p;\n    return 0;\n memory_error:\n    re_parse_out_of_memory(s);\n fail:\n    cr_free(cr);\n    return -1;\n}\n\n/* Return:\n   1 if the opcodes in bc_buf[] always advance the character pointer.\n   0 if the character pointer may not be advanced.\n   -1 if the code may depend on side effects of its previous execution (backreference)\n*/\nstatic int re_check_advance(const uint8_t *bc_buf, int bc_buf_len)\n{\n    int pos, opcode, ret, len, i;\n    uint32_t val, last;\n    BOOL has_back_reference;\n    uint8_t capture_bitmap[CAPTURE_COUNT_MAX];\n    \n    ret = -2; /* not known yet */\n    pos = 0;\n    has_back_reference = FALSE;\n    memset(capture_bitmap, 0, sizeof(capture_bitmap));\n    \n    while (pos < bc_buf_len) {\n        opcode = bc_buf[pos];\n        len = reopcode_info[opcode].size;\n        switch(opcode) {\n        case REOP_range:\n            val = get_u16(bc_buf + pos + 1);\n            len += val * 4;\n            goto simple_char;\n        case REOP_range32:\n            val = get_u16(bc_buf + pos + 1);\n            len += val * 8;\n            goto simple_char;\n        case REOP_char:\n        case REOP_char32:\n        case REOP_dot:\n        case REOP_any:\n        simple_char:\n            if (ret == -2)\n                ret = 1;\n            break;\n        case REOP_line_start:\n        case REOP_line_end:\n        case REOP_push_i32:\n        case REOP_push_char_pos:\n        case REOP_drop:\n        case REOP_word_boundary:\n        case REOP_not_word_boundary:\n        case REOP_prev:\n            /* no effect */\n            break;\n        case REOP_save_start:\n        case REOP_save_end:\n            val = bc_buf[pos + 1];\n            capture_bitmap[val] |= 1;\n            break;\n        case REOP_save_reset:\n            {\n                val = bc_buf[pos + 1];\n                last = bc_buf[pos + 2];\n                while (val < last)\n                    capture_bitmap[val++] |= 1;\n            }\n            break;\n        case REOP_back_reference:\n        case REOP_backward_back_reference:\n            val = bc_buf[pos + 1];\n            capture_bitmap[val] |= 2;\n            has_back_reference = TRUE;\n            break;\n        default:\n            /* safe behvior: we cannot predict the outcome */\n            if (ret == -2)\n                ret = 0;\n            break;\n        }\n        pos += len;\n    }\n    if (has_back_reference) {\n        /* check if there is back reference which references a capture\n           made in the some code */\n        for(i = 0; i < CAPTURE_COUNT_MAX; i++) {\n            if (capture_bitmap[i] == 3)\n                return -1;\n        }\n    }\n    if (ret == -2)\n        ret = 0;\n    return ret;\n}\n\n/* return -1 if a simple quantifier cannot be used. Otherwise return\n   the number of characters in the atom. */\nstatic int re_is_simple_quantifier(const uint8_t *bc_buf, int bc_buf_len)\n{\n    int pos, opcode, len, count;\n    uint32_t val;\n    \n    count = 0;\n    pos = 0;\n    while (pos < bc_buf_len) {\n        opcode = bc_buf[pos];\n        len = reopcode_info[opcode].size;\n        switch(opcode) {\n        case REOP_range:\n            val = get_u16(bc_buf + pos + 1);\n            len += val * 4;\n            goto simple_char;\n        case REOP_range32:\n            val = get_u16(bc_buf + pos + 1);\n            len += val * 8;\n            goto simple_char;\n        case REOP_char:\n        case REOP_char32:\n        case REOP_dot:\n        case REOP_any:\n        simple_char:\n            count++;\n            break;\n        case REOP_line_start:\n        case REOP_line_end:\n        case REOP_word_boundary:\n        case REOP_not_word_boundary:\n            break;\n        default:\n            return -1;\n        }\n        pos += len;\n    }\n    return count;\n}\n\n/* '*pp' is the first char after '<' */\nstatic int re_parse_group_name(char *buf, int buf_size,\n                               const uint8_t **pp, BOOL is_utf16)\n{\n    const uint8_t *p;\n    uint32_t c;\n    char *q;\n\n    p = *pp;\n    q = buf;\n    for(;;) {\n        c = *p;\n        if (c == '\\\\') {\n            p++;\n            if (*p != 'u')\n                return -1;\n            c = lre_parse_escape(&p, is_utf16 * 2);\n        } else if (c == '>') {\n            break;\n        } else if (c >= 128) {\n            c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n        } else {\n            p++;\n        }\n        if (c > 0x10FFFF)\n            return -1;\n        if (q == buf) {\n            if (!lre_js_is_ident_first(c))\n                return -1;\n        } else {\n            if (!lre_js_is_ident_next(c))\n                return -1;\n        }\n        if ((q - buf + UTF8_CHAR_LEN_MAX + 1) > buf_size)\n            return -1;\n        if (c < 128) {\n            *q++ = c;\n        } else {\n            q += unicode_to_utf8((uint8_t*)q, c);\n        }\n    }\n    if (q == buf)\n        return -1;\n    *q = '\\0';\n    p++;\n    *pp = p;\n    return 0;\n}\n\n/* if capture_name = NULL: return the number of captures + 1.\n   Otherwise, return the capture index corresponding to capture_name\n   or -1 if none */\nstatic int re_parse_captures(REParseState *s, int *phas_named_captures,\n                             const char *capture_name)\n{\n    const uint8_t *p;\n    int capture_index;\n    char name[TMP_BUF_SIZE];\n\n    capture_index = 1;\n    *phas_named_captures = 0;\n    for (p = s->buf_start; p < s->buf_end; p++) {\n        switch (*p) {\n        case '(':\n            if (p[1] == '?') {\n                if (p[2] == '<' && p[3] != '=' && p[3] != '!') {\n                    *phas_named_captures = 1;\n                    /* potential named capture */\n                    if (capture_name) {\n                        p += 3;\n                        if (re_parse_group_name(name, sizeof(name), &p,\n                                                s->is_utf16) == 0) {\n                            if (!strcmp(name, capture_name))\n                                return capture_index;\n                        }\n                    }\n                    capture_index++;\n                }\n            } else {\n                capture_index++;\n            }\n            break;\n        case '\\\\':\n            p++;\n            break;\n        case '[':\n            for (p += 1 + (*p == ']'); p < s->buf_end && *p != ']'; p++) {\n                if (*p == '\\\\')\n                    p++;\n            }\n            break;\n        }\n    }\n    if (capture_name)\n        return -1;\n    else\n        return capture_index;\n}\n\nstatic int re_count_captures(REParseState *s)\n{\n    if (s->total_capture_count < 0) {\n        s->total_capture_count = re_parse_captures(s, &s->has_named_captures,\n                                                   NULL);\n    }\n    return s->total_capture_count;\n}\n\nstatic BOOL re_has_named_captures(REParseState *s)\n{\n    if (s->has_named_captures < 0)\n        re_count_captures(s);\n    return s->has_named_captures;\n}\n\nstatic int find_group_name(REParseState *s, const char *name)\n{\n    const char *p, *buf_end;\n    size_t len, name_len;\n    int capture_index;\n    \n    name_len = strlen(name);\n    p = (char *)s->group_names.buf;\n    buf_end = (char *)s->group_names.buf + s->group_names.size;\n    capture_index = 1;\n    while (p < buf_end) {\n        len = strlen(p);\n        if (len == name_len && memcmp(name, p, name_len) == 0)\n            return capture_index;\n        p += len + 1;\n        capture_index++;\n    }\n    return -1;\n}\n\nstatic int re_parse_disjunction(REParseState *s, BOOL is_backward_dir);\n\nstatic int re_parse_term(REParseState *s, BOOL is_backward_dir)\n{\n    const uint8_t *p;\n    int c, last_atom_start, quant_min, quant_max, last_capture_count;\n    BOOL greedy, add_zero_advance_check, is_neg, is_backward_lookahead;\n    CharRange cr_s, *cr = &cr_s;\n    \n    last_atom_start = -1;\n    last_capture_count = 0;\n    p = s->buf_ptr;\n    c = *p;\n    switch(c) {\n    case '^':\n        p++;\n        re_emit_op(s, REOP_line_start);\n        break;\n    case '$':\n        p++;\n        re_emit_op(s, REOP_line_end);\n        break;\n    case '.':\n        p++;\n        last_atom_start = s->byte_code.size;\n        last_capture_count = s->capture_count;\n        if (is_backward_dir)\n            re_emit_op(s, REOP_prev);\n        re_emit_op(s, s->dotall ? REOP_any : REOP_dot);\n        if (is_backward_dir)\n            re_emit_op(s, REOP_prev);\n        break;\n    case '{':\n        if (s->is_utf16) {\n            return re_parse_error(s, \"syntax error\");\n        } else if (!is_digit(p[1])) {\n            /* Annex B: we accept '{' not followed by digits as a\n               normal atom */\n            goto parse_class_atom;\n        } else {\n            const uint8_t *p1 = p + 1;\n            /* Annex B: error if it is like a repetition count */\n            parse_digits(&p1, TRUE);\n            if (*p1 == ',') {\n                p1++;\n                if (is_digit(*p1)) {\n                    parse_digits(&p1, TRUE);\n                }\n            }\n            if (*p1 != '}') {\n                goto parse_class_atom;\n            }\n        }\n        /* fall thru */\n    case '*':\n    case '+':\n    case '?':\n        return re_parse_error(s, \"nothing to repeat\");\n    case '(':\n        if (p[1] == '?') {\n            if (p[2] == ':') {\n                p += 3;\n                last_atom_start = s->byte_code.size;\n                last_capture_count = s->capture_count;\n                s->buf_ptr = p;\n                if (re_parse_disjunction(s, is_backward_dir))\n                    return -1;\n                p = s->buf_ptr;\n                if (re_parse_expect(s, &p, ')'))\n                    return -1;\n            } else if ((p[2] == '=' || p[2] == '!')) {\n                is_neg = (p[2] == '!');\n                is_backward_lookahead = FALSE;\n                p += 3;\n                goto lookahead;\n            } else if (p[2] == '<' &&\n                       (p[3] == '=' || p[3] == '!')) {\n                int pos;\n                is_neg = (p[3] == '!');\n                is_backward_lookahead = TRUE;\n                p += 4;\n                /* lookahead */\n            lookahead:\n                /* Annex B allows lookahead to be used as an atom for\n                   the quantifiers */\n                if (!s->is_utf16 && !is_backward_lookahead)  {\n                    last_atom_start = s->byte_code.size;\n                    last_capture_count = s->capture_count;\n                }\n                pos = re_emit_op_u32(s, REOP_lookahead + is_neg, 0);\n                s->buf_ptr = p;\n                if (re_parse_disjunction(s, is_backward_lookahead))\n                    return -1;\n                p = s->buf_ptr;\n                if (re_parse_expect(s, &p, ')'))\n                    return -1;\n                re_emit_op(s, REOP_match);\n                /* jump after the 'match' after the lookahead is successful */\n                if (dbuf_error(&s->byte_code))\n                    return -1;\n                put_u32(s->byte_code.buf + pos, s->byte_code.size - (pos + 4));\n            } else if (p[2] == '<') {\n                p += 3;\n                if (re_parse_group_name(s->u.tmp_buf, sizeof(s->u.tmp_buf),\n                                        &p, s->is_utf16)) {\n                    return re_parse_error(s, \"invalid group name\");\n                }\n                if (find_group_name(s, s->u.tmp_buf) > 0) {\n                    return re_parse_error(s, \"duplicate group name\");\n                }\n                /* group name with a trailing zero */\n                dbuf_put(&s->group_names, (uint8_t *)s->u.tmp_buf,\n                         strlen(s->u.tmp_buf) + 1);\n                s->has_named_captures = 1;\n                goto parse_capture;\n            } else {\n                return re_parse_error(s, \"invalid group\");\n            }\n        } else {\n            int capture_index;\n            p++;\n            /* capture without group name */\n            dbuf_putc(&s->group_names, 0);\n        parse_capture:\n            if (s->capture_count >= CAPTURE_COUNT_MAX)\n                return re_parse_error(s, \"too many captures\");\n            last_atom_start = s->byte_code.size;\n            last_capture_count = s->capture_count;\n            capture_index = s->capture_count++;\n            re_emit_op_u8(s, REOP_save_start + is_backward_dir,\n                          capture_index);\n            \n            s->buf_ptr = p;\n            if (re_parse_disjunction(s, is_backward_dir))\n                return -1;\n            p = s->buf_ptr;\n            \n            re_emit_op_u8(s, REOP_save_start + 1 - is_backward_dir,\n                          capture_index);\n            \n            if (re_parse_expect(s, &p, ')'))\n                return -1;\n        }\n        break;\n    case '\\\\':\n        switch(p[1]) {\n        case 'b':\n        case 'B':\n            re_emit_op(s, REOP_word_boundary + (p[1] != 'b'));\n            p += 2;\n            break;\n        case 'k':\n            {\n                const uint8_t *p1;\n                int dummy_res;\n                \n                p1 = p;\n                if (p1[2] != '<') {\n                    /* annex B: we tolerate invalid group names in non\n                       unicode mode if there is no named capture\n                       definition */\n                    if (s->is_utf16 || re_has_named_captures(s))\n                        return re_parse_error(s, \"expecting group name\");\n                    else\n                        goto parse_class_atom;\n                }\n                p1 += 3;\n                if (re_parse_group_name(s->u.tmp_buf, sizeof(s->u.tmp_buf),\n                                        &p1, s->is_utf16)) {\n                    if (s->is_utf16 || re_has_named_captures(s))\n                        return re_parse_error(s, \"invalid group name\");\n                    else\n                        goto parse_class_atom;\n                }\n                c = find_group_name(s, s->u.tmp_buf);\n                if (c < 0) {\n                    /* no capture name parsed before, try to look\n                       after (inefficient, but hopefully not common */\n                    c = re_parse_captures(s, &dummy_res, s->u.tmp_buf);\n                    if (c < 0) {\n                        if (s->is_utf16 || re_has_named_captures(s))\n                            return re_parse_error(s, \"group name not defined\");\n                        else\n                            goto parse_class_atom;\n                    }\n                }\n                p = p1;\n            }\n            goto emit_back_reference;\n        case '0':\n            p += 2;\n            c = 0;\n            if (s->is_utf16) {\n                if (is_digit(*p)) {\n                    return re_parse_error(s, \"invalid decimal escape in regular expression\");\n                }\n            } else {\n                /* Annex B.1.4: accept legacy octal */\n                if (*p >= '0' && *p <= '7') {\n                    c = *p++ - '0';\n                    if (*p >= '0' && *p <= '7') {\n                        c = (c << 3) + *p++ - '0';\n                    }\n                }\n            }\n            goto normal_char;\n        case '1' ... '9':\n            {\n                const uint8_t *q = ++p;\n                \n                c = parse_digits(&p, FALSE);\n                if (c < 0 || (c >= s->capture_count && c >= re_count_captures(s))) {\n                    if (!s->is_utf16) {\n                        /* Annex B.1.4: accept legacy octal */\n                        p = q;\n                        if (*p <= '7') {\n                            c = 0;\n                            if (*p <= '3')\n                                c = *p++ - '0';\n                            if (*p >= '0' && *p <= '7') {\n                                c = (c << 3) + *p++ - '0';\n                                if (*p >= '0' && *p <= '7') {\n                                    c = (c << 3) + *p++ - '0';\n                                }\n                            }\n                        } else {\n                            c = *p++;\n                        }\n                        goto normal_char;\n                    }\n                    return re_parse_error(s, \"back reference out of range in reguar expression\");\n                }\n            emit_back_reference:\n                last_atom_start = s->byte_code.size;\n                last_capture_count = s->capture_count;\n                re_emit_op_u8(s, REOP_back_reference + is_backward_dir, c);\n            }\n            break;\n        default:\n            goto parse_class_atom;\n        }\n        break;\n    case '[':\n        last_atom_start = s->byte_code.size;\n        last_capture_count = s->capture_count;\n        if (is_backward_dir)\n            re_emit_op(s, REOP_prev);\n        if (re_parse_char_class(s, &p))\n            return -1;\n        if (is_backward_dir)\n            re_emit_op(s, REOP_prev);\n        break;\n    case ']':\n    case '}':\n        if (s->is_utf16)\n            return re_parse_error(s, \"syntax error\");\n        goto parse_class_atom;\n    default:\n    parse_class_atom:\n        c = get_class_atom(s, cr, &p, FALSE);\n        if ((int)c < 0)\n            return -1;\n    normal_char:\n        last_atom_start = s->byte_code.size;\n        last_capture_count = s->capture_count;\n        if (is_backward_dir)\n            re_emit_op(s, REOP_prev);\n        if (c >= CLASS_RANGE_BASE) {\n            int ret;\n            /* Note: canonicalization is not needed */\n            ret = re_emit_range(s, cr);\n            cr_free(cr);\n            if (ret)\n                return -1;\n        } else {\n            if (s->ignore_case)\n                c = lre_canonicalize(c, s->is_utf16);\n            if (c <= 0xffff)\n                re_emit_op_u16(s, REOP_char, c);\n            else\n                re_emit_op_u32(s, REOP_char32, c);\n        }\n        if (is_backward_dir)\n            re_emit_op(s, REOP_prev);\n        break;\n    }\n\n    /* quantifier */\n    if (last_atom_start >= 0) {\n        c = *p;\n        switch(c) {\n        case '*':\n            p++;\n            quant_min = 0;\n            quant_max = INT32_MAX;\n            goto quantifier;\n        case '+':\n            p++;\n            quant_min = 1;\n            quant_max = INT32_MAX;\n            goto quantifier;\n        case '?':\n            p++;\n            quant_min = 0;\n            quant_max = 1;\n            goto quantifier;\n        case '{':\n            {\n                const uint8_t *p1 = p;\n                /* As an extension (see ES6 annex B), we accept '{' not\n                   followed by digits as a normal atom */\n                if (!is_digit(p[1])) {\n                    if (s->is_utf16)\n                        goto invalid_quant_count;\n                    break;\n                }\n                p++;\n                quant_min = parse_digits(&p, TRUE);\n                quant_max = quant_min;\n                if (*p == ',') {\n                    p++;\n                    if (is_digit(*p)) {\n                        quant_max = parse_digits(&p, TRUE);\n                        if (quant_max < quant_min) {\n                        invalid_quant_count:\n                            return re_parse_error(s, \"invalid repetition count\");\n                        }\n                    } else {\n                        quant_max = INT32_MAX; /* infinity */\n                    }\n                }\n                if (*p != '}' && !s->is_utf16) {\n                    /* Annex B: normal atom if invalid '{' syntax */\n                    p = p1;\n                    break;\n                }\n                if (re_parse_expect(s, &p, '}'))\n                    return -1;\n            }\n        quantifier:\n            greedy = TRUE;\n            if (*p == '?') {\n                p++;\n                greedy = FALSE;\n            }\n            if (last_atom_start < 0) {\n                return re_parse_error(s, \"nothing to repeat\");\n            }\n            if (greedy) {\n                int len, pos;\n                \n                if (quant_max > 0) {\n                    /* specific optimization for simple quantifiers */\n                    if (dbuf_error(&s->byte_code))\n                        goto out_of_memory;\n                    len = re_is_simple_quantifier(s->byte_code.buf + last_atom_start,\n                                                 s->byte_code.size - last_atom_start);\n                    if (len > 0) {\n                        re_emit_op(s, REOP_match);\n                        \n                        if (dbuf_insert(&s->byte_code, last_atom_start, 17))\n                            goto out_of_memory;\n                        pos = last_atom_start;\n                        s->byte_code.buf[pos++] = REOP_simple_greedy_quant;\n                        put_u32(&s->byte_code.buf[pos],\n                                s->byte_code.size - last_atom_start - 17);\n                        pos += 4;\n                        put_u32(&s->byte_code.buf[pos], quant_min);\n                        pos += 4;\n                        put_u32(&s->byte_code.buf[pos], quant_max);\n                        pos += 4;\n                        put_u32(&s->byte_code.buf[pos], len);\n                        pos += 4;\n                        goto done;\n                    }\n                }\n                \n                if (dbuf_error(&s->byte_code))\n                    goto out_of_memory;\n                add_zero_advance_check = (re_check_advance(s->byte_code.buf + last_atom_start,\n                                                           s->byte_code.size - last_atom_start) == 0);\n            } else {\n                add_zero_advance_check = FALSE;\n            }\n            \n            {\n                int len, pos;\n                len = s->byte_code.size - last_atom_start;\n                if (quant_min == 0) {\n                    /* need to reset the capture in case the atom is\n                       not executed */\n                    if (last_capture_count != s->capture_count) {\n                        if (dbuf_insert(&s->byte_code, last_atom_start, 3))\n                            goto out_of_memory;\n                        s->byte_code.buf[last_atom_start++] = REOP_save_reset;\n                        s->byte_code.buf[last_atom_start++] = last_capture_count;\n                        s->byte_code.buf[last_atom_start++] = s->capture_count - 1;\n                    }\n                    if (quant_max == 0) {\n                        s->byte_code.size = last_atom_start;\n                    } else if (quant_max == 1) {\n                        if (dbuf_insert(&s->byte_code, last_atom_start, 5))\n                            goto out_of_memory;\n                        s->byte_code.buf[last_atom_start] = REOP_split_goto_first +\n                            greedy;\n                        put_u32(s->byte_code.buf + last_atom_start + 1, len);\n                    } else if (quant_max == INT32_MAX) {\n                        if (dbuf_insert(&s->byte_code, last_atom_start, 5 + add_zero_advance_check))\n                            goto out_of_memory;\n                        s->byte_code.buf[last_atom_start] = REOP_split_goto_first +\n                            greedy;\n                        put_u32(s->byte_code.buf + last_atom_start + 1,\n                                len + 5 + add_zero_advance_check);\n                        if (add_zero_advance_check) {\n                            /* avoid infinite loop by stoping the\n                               recursion if no advance was made in the\n                               atom (only works if the atom has no\n                               side effect) */\n                            s->byte_code.buf[last_atom_start + 1 + 4] = REOP_push_char_pos;\n                            re_emit_goto(s, REOP_bne_char_pos, last_atom_start); \n                        } else {\n                            re_emit_goto(s, REOP_goto, last_atom_start);\n                        }\n                    } else {\n                        if (dbuf_insert(&s->byte_code, last_atom_start, 10))\n                            goto out_of_memory;\n                        pos = last_atom_start;\n                        s->byte_code.buf[pos++] = REOP_push_i32;\n                        put_u32(s->byte_code.buf + pos, quant_max);\n                        pos += 4;\n                        s->byte_code.buf[pos++] = REOP_split_goto_first + greedy;\n                        put_u32(s->byte_code.buf + pos, len + 5);\n                        re_emit_goto(s, REOP_loop, last_atom_start + 5);\n                        re_emit_op(s, REOP_drop);\n                    }\n                } else if (quant_min == 1 && quant_max == INT32_MAX &&\n                           !add_zero_advance_check) {\n                    re_emit_goto(s, REOP_split_next_first - greedy,\n                                 last_atom_start);\n                } else {\n                    if (quant_min == 1) {\n                        /* nothing to add */\n                    } else {\n                        if (dbuf_insert(&s->byte_code, last_atom_start, 5))\n                            goto out_of_memory;\n                        s->byte_code.buf[last_atom_start] = REOP_push_i32;\n                        put_u32(s->byte_code.buf + last_atom_start + 1,\n                                quant_min);\n                        last_atom_start += 5;\n                        re_emit_goto(s, REOP_loop, last_atom_start);\n                        re_emit_op(s, REOP_drop);\n                    }\n                    if (quant_max == INT32_MAX) {\n                        pos = s->byte_code.size;\n                        re_emit_op_u32(s, REOP_split_goto_first + greedy,\n                                       len + 5 + add_zero_advance_check);\n                        if (add_zero_advance_check)\n                            re_emit_op(s, REOP_push_char_pos);\n                        /* copy the atom */\n                        dbuf_put_self(&s->byte_code, last_atom_start, len);\n                        if (add_zero_advance_check)\n                            re_emit_goto(s, REOP_bne_char_pos, pos);\n                        else\n                            re_emit_goto(s, REOP_goto, pos);\n                    } else if (quant_max > quant_min) {\n                        re_emit_op_u32(s, REOP_push_i32, quant_max - quant_min);\n                        pos = s->byte_code.size;\n                        re_emit_op_u32(s, REOP_split_goto_first + greedy, len + 5);\n                        /* copy the atom */\n                        dbuf_put_self(&s->byte_code, last_atom_start, len);\n                        \n                        re_emit_goto(s, REOP_loop, pos);\n                        re_emit_op(s, REOP_drop);\n                    }\n                }\n                last_atom_start = -1;\n            }\n            break;\n        default:\n            break;\n        }\n    }\n done:\n    s->buf_ptr = p;\n    return 0;\n out_of_memory:\n    return re_parse_out_of_memory(s);\n}\n\nstatic int re_parse_alternative(REParseState *s, BOOL is_backward_dir)\n{\n    const uint8_t *p;\n    int ret;\n    size_t start, term_start, end, term_size;\n\n    start = s->byte_code.size;\n    for(;;) {\n        p = s->buf_ptr;\n        if (p >= s->buf_end)\n            break;\n        if (*p == '|' || *p == ')')\n            break;\n        term_start = s->byte_code.size;\n        ret = re_parse_term(s, is_backward_dir);\n        if (ret)\n            return ret;\n        if (is_backward_dir) {\n            /* reverse the order of the terms (XXX: inefficient, but\n               speed is not really critical here) */\n            end = s->byte_code.size;\n            term_size = end - term_start;\n            if (dbuf_realloc(&s->byte_code, end + term_size))\n                return -1;\n            memmove(s->byte_code.buf + start + term_size,\n                    s->byte_code.buf + start,\n                    end - start);\n            memcpy(s->byte_code.buf + start, s->byte_code.buf + end,\n                   term_size);\n        }\n    }\n    return 0;\n}\n    \nstatic int re_parse_disjunction(REParseState *s, BOOL is_backward_dir)\n{\n    int start, len, pos;\n\n    start = s->byte_code.size;\n    if (re_parse_alternative(s, is_backward_dir))\n        return -1;\n    while (*s->buf_ptr == '|') {\n        s->buf_ptr++;\n\n        len = s->byte_code.size - start;\n\n        /* insert a split before the first alternative */\n        if (dbuf_insert(&s->byte_code, start, 5)) {\n            return re_parse_out_of_memory(s);\n        }\n        s->byte_code.buf[start] = REOP_split_next_first;\n        put_u32(s->byte_code.buf + start + 1, len + 5);\n\n        pos = re_emit_op_u32(s, REOP_goto, 0);\n\n        if (re_parse_alternative(s, is_backward_dir))\n            return -1;\n        \n        /* patch the goto */\n        len = s->byte_code.size - (pos + 4);\n        put_u32(s->byte_code.buf + pos, len);\n    }\n    return 0;\n}\n\n/* the control flow is recursive so the analysis can be linear */\nstatic int compute_stack_size(const uint8_t *bc_buf, int bc_buf_len)\n{\n    int stack_size, stack_size_max, pos, opcode, len;\n    uint32_t val;\n    \n    stack_size = 0;\n    stack_size_max = 0;\n    bc_buf += RE_HEADER_LEN;\n    bc_buf_len -= RE_HEADER_LEN;\n    pos = 0;\n    while (pos < bc_buf_len) {\n        opcode = bc_buf[pos];\n        len = reopcode_info[opcode].size;\n        assert(opcode < REOP_COUNT);\n        assert((pos + len) <= bc_buf_len);\n        switch(opcode) {\n        case REOP_push_i32:\n        case REOP_push_char_pos:\n            stack_size++;\n            if (stack_size > stack_size_max) {\n                if (stack_size > STACK_SIZE_MAX)\n                    return -1;\n                stack_size_max = stack_size;\n            }\n            break;\n        case REOP_drop:\n        case REOP_bne_char_pos:\n            assert(stack_size > 0);\n            stack_size--;\n            break;\n        case REOP_range:\n            val = get_u16(bc_buf + pos + 1);\n            len += val * 4;\n            break;\n        case REOP_range32:\n            val = get_u16(bc_buf + pos + 1);\n            len += val * 8;\n            break;\n        }\n        pos += len;\n    }\n    return stack_size_max;\n}\n\n/* 'buf' must be a zero terminated UTF-8 string of length buf_len.\n   Return NULL if error and allocate an error message in *perror_msg,\n   otherwise the compiled bytecode and its length in plen.\n*/\nuint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,\n                     const char *buf, size_t buf_len, int re_flags,\n                     void *opaque)\n{\n    REParseState s_s, *s = &s_s;\n    int stack_size;\n    BOOL is_sticky;\n    \n    memset(s, 0, sizeof(*s));\n    s->mem_opaque = opaque;\n    s->buf_ptr = (const uint8_t *)buf;\n    s->buf_end = s->buf_ptr + buf_len;\n    s->buf_start = s->buf_ptr;\n    s->re_flags = re_flags;\n    s->is_utf16 = ((re_flags & LRE_FLAG_UTF16) != 0);\n    is_sticky = ((re_flags & LRE_FLAG_STICKY) != 0);\n    s->ignore_case = ((re_flags & LRE_FLAG_IGNORECASE) != 0);\n    s->dotall = ((re_flags & LRE_FLAG_DOTALL) != 0);\n    s->capture_count = 1;\n    s->total_capture_count = -1;\n    s->has_named_captures = -1;\n    \n    dbuf_init2(&s->byte_code, opaque, lre_realloc);\n    dbuf_init2(&s->group_names, opaque, lre_realloc);\n\n    dbuf_putc(&s->byte_code, re_flags); /* first element is the flags */\n    dbuf_putc(&s->byte_code, 0); /* second element is the number of captures */\n    dbuf_putc(&s->byte_code, 0); /* stack size */\n    dbuf_put_u32(&s->byte_code, 0); /* bytecode length */\n    \n    if (!is_sticky) {\n        /* iterate thru all positions (about the same as .*?( ... ) )\n           .  We do it without an explicit loop so that lock step\n           thread execution will be possible in an optimized\n           implementation */\n        re_emit_op_u32(s, REOP_split_goto_first, 1 + 5);\n        re_emit_op(s, REOP_any);\n        re_emit_op_u32(s, REOP_goto, -(5 + 1 + 5));\n    }\n    re_emit_op_u8(s, REOP_save_start, 0);\n\n    if (re_parse_disjunction(s, FALSE)) {\n    error:\n        dbuf_free(&s->byte_code);\n        dbuf_free(&s->group_names);\n        pstrcpy(error_msg, error_msg_size, s->u.error_msg);\n        *plen = 0;\n        return NULL;\n    }\n\n    re_emit_op_u8(s, REOP_save_end, 0);\n    \n    re_emit_op(s, REOP_match);\n\n    if (*s->buf_ptr != '\\0') {\n        re_parse_error(s, \"extraneous characters at the end\");\n        goto error;\n    }\n\n    if (dbuf_error(&s->byte_code)) {\n        re_parse_out_of_memory(s);\n        goto error;\n    }\n    \n    stack_size = compute_stack_size(s->byte_code.buf, s->byte_code.size);\n    if (stack_size < 0) {\n        re_parse_error(s, \"too many imbricated quantifiers\");\n        goto error;\n    }\n    \n    s->byte_code.buf[RE_HEADER_CAPTURE_COUNT] = s->capture_count;\n    s->byte_code.buf[RE_HEADER_STACK_SIZE] = stack_size;\n    put_u32(s->byte_code.buf + 3, s->byte_code.size - RE_HEADER_LEN);\n\n    /* add the named groups if needed */\n    if (s->group_names.size > (s->capture_count - 1)) {\n        dbuf_put(&s->byte_code, s->group_names.buf, s->group_names.size);\n        s->byte_code.buf[RE_HEADER_FLAGS] |= LRE_FLAG_NAMED_GROUPS;\n    }\n    dbuf_free(&s->group_names);\n    \n#ifdef DUMP_REOP\n    lre_dump_bytecode(s->byte_code.buf, s->byte_code.size);\n#endif\n    \n    error_msg[0] = '\\0';\n    *plen = s->byte_code.size;\n    return s->byte_code.buf;\n}\n\nstatic BOOL is_line_terminator(uint32_t c)\n{\n    return (c == '\\n' || c == '\\r' || c == CP_LS || c == CP_PS);\n}\n\nstatic BOOL is_word_char(uint32_t c)\n{\n    return ((c >= '0' && c <= '9') ||\n            (c >= 'a' && c <= 'z') ||\n            (c >= 'A' && c <= 'Z') ||\n            (c == '_'));\n}\n\n#define GET_CHAR(c, cptr, cbuf_end)                                     \\\n    do {                                                                \\\n        if (cbuf_type == 0) {                                           \\\n            c = *cptr++;                                                \\\n        } else {                                                        \\\n            uint32_t __c1;                                              \\\n            c = *(uint16_t *)cptr;                                      \\\n            cptr += 2;                                                  \\\n            if (c >= 0xd800 && c < 0xdc00 &&                            \\\n                cbuf_type == 2 && cptr < cbuf_end) {                    \\\n                __c1 = *(uint16_t *)cptr;                               \\\n                if (__c1 >= 0xdc00 && __c1 < 0xe000) {                  \\\n                    c = (((c & 0x3ff) << 10) | (__c1 & 0x3ff)) + 0x10000; \\\n                    cptr += 2;                                          \\\n                }                                                       \\\n            }                                                           \\\n        }                                                               \\\n    } while (0)\n\n#define PEEK_CHAR(c, cptr, cbuf_end)             \\\n    do {                                         \\\n        if (cbuf_type == 0) {                    \\\n            c = cptr[0];                         \\\n        } else {                                 \\\n            uint32_t __c1;                                              \\\n            c = ((uint16_t *)cptr)[0];                                  \\\n            if (c >= 0xd800 && c < 0xdc00 &&                            \\\n                cbuf_type == 2 && (cptr + 2) < cbuf_end) {              \\\n                __c1 = ((uint16_t *)cptr)[1];                           \\\n                if (__c1 >= 0xdc00 && __c1 < 0xe000) {                  \\\n                    c = (((c & 0x3ff) << 10) | (__c1 & 0x3ff)) + 0x10000; \\\n                }                                                       \\\n            }                                                           \\\n        }                                        \\\n    } while (0)\n\n#define PEEK_PREV_CHAR(c, cptr, cbuf_start)                 \\\n    do {                                         \\\n        if (cbuf_type == 0) {                    \\\n            c = cptr[-1];                        \\\n        } else {                                 \\\n            uint32_t __c1;                                              \\\n            c = ((uint16_t *)cptr)[-1];                                 \\\n            if (c >= 0xdc00 && c < 0xe000 &&                            \\\n                cbuf_type == 2 && (cptr - 4) >= cbuf_start) {              \\\n                __c1 = ((uint16_t *)cptr)[-2];                          \\\n                if (__c1 >= 0xd800 && __c1 < 0xdc00 ) {                 \\\n                    c = (((__c1 & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000; \\\n                }                                                       \\\n            }                                                           \\\n        }                                                               \\\n    } while (0)\n\n#define GET_PREV_CHAR(c, cptr, cbuf_start)       \\\n    do {                                         \\\n        if (cbuf_type == 0) {                    \\\n            cptr--;                              \\\n            c = cptr[0];                         \\\n        } else {                                 \\\n            uint32_t __c1;                                              \\\n            cptr -= 2;                                                  \\\n            c = ((uint16_t *)cptr)[0];                                 \\\n            if (c >= 0xdc00 && c < 0xe000 &&                            \\\n                cbuf_type == 2 && cptr > cbuf_start) {                  \\\n                __c1 = ((uint16_t *)cptr)[-1];                          \\\n                if (__c1 >= 0xd800 && __c1 < 0xdc00 ) {                 \\\n                    cptr -= 2;                                          \\\n                    c = (((__c1 & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000; \\\n                }                                                       \\\n            }                                                           \\\n        }                                                               \\\n    } while (0)\n\n#define PREV_CHAR(cptr, cbuf_start)       \\\n    do {                                  \\\n        if (cbuf_type == 0) {             \\\n            cptr--;                       \\\n        } else {                          \\\n            cptr -= 2;                          \\\n            if (cbuf_type == 2) {                                       \\\n                c = ((uint16_t *)cptr)[0];                              \\\n                if (c >= 0xdc00 && c < 0xe000 && cptr > cbuf_start) {   \\\n                    c = ((uint16_t *)cptr)[-1];                         \\\n                    if (c >= 0xd800 && c < 0xdc00)                      \\\n                        cptr -= 2;                                      \\\n                }                                                       \\\n            }                                                           \\\n        }                                                               \\\n    } while (0)\n\ntypedef uintptr_t StackInt;\n\ntypedef enum {\n    RE_EXEC_STATE_SPLIT,\n    RE_EXEC_STATE_LOOKAHEAD,\n    RE_EXEC_STATE_NEGATIVE_LOOKAHEAD,\n    RE_EXEC_STATE_GREEDY_QUANT,\n} REExecStateEnum;\n\ntypedef struct REExecState {\n    REExecStateEnum type : 8;\n    uint8_t stack_len;\n    size_t count; /* only used for RE_EXEC_STATE_GREEDY_QUANT */\n    const uint8_t *cptr;\n    const uint8_t *pc;\n    void *buf[0];\n} REExecState;\n\ntypedef struct {\n    const uint8_t *cbuf;\n    const uint8_t *cbuf_end;\n    /* 0 = 8 bit chars, 1 = 16 bit chars, 2 = 16 bit chars, UTF-16 */\n    int cbuf_type; \n    int capture_count;\n    int stack_size_max;\n    BOOL multi_line;\n    BOOL ignore_case;\n    BOOL is_utf16;\n    void *opaque; /* used for stack overflow check */\n\n    size_t state_size;\n    uint8_t *state_stack;\n    size_t state_stack_size;\n    size_t state_stack_len;\n} REExecContext;\n\nstatic int push_state(REExecContext *s,\n                      uint8_t **capture,\n                      StackInt *stack, size_t stack_len,\n                      const uint8_t *pc, const uint8_t *cptr,\n                      REExecStateEnum type, size_t count)\n{\n    REExecState *rs;\n    uint8_t *new_stack;\n    size_t new_size, i, n;\n    StackInt *stack_buf;\n\n    if (unlikely((s->state_stack_len + 1) > s->state_stack_size)) {\n        /* reallocate the stack */\n        new_size = s->state_stack_size * 3 / 2;\n        if (new_size < 8)\n            new_size = 8;\n        new_stack = lre_realloc(s->opaque, s->state_stack, new_size * s->state_size);\n        if (!new_stack)\n            return -1;\n        s->state_stack_size = new_size;\n        s->state_stack = new_stack;\n    }\n    rs = (REExecState *)(s->state_stack + s->state_stack_len * s->state_size);\n    s->state_stack_len++;\n    rs->type = type;\n    rs->count = count;\n    rs->stack_len = stack_len;\n    rs->cptr = cptr;\n    rs->pc = pc;\n    n = 2 * s->capture_count;\n    for(i = 0; i < n; i++)\n        rs->buf[i] = capture[i];\n    stack_buf = (StackInt *)(rs->buf + n);\n    for(i = 0; i < stack_len; i++)\n        stack_buf[i] = stack[i];\n    return 0;\n}\n\n/* return 1 if match, 0 if not match or -1 if error. */\nstatic intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture,\n                                   StackInt *stack, int stack_len,\n                                   const uint8_t *pc, const uint8_t *cptr,\n                                   BOOL no_recurse)\n{\n    int opcode, ret;\n    int cbuf_type;\n    uint32_t val, c;\n    const uint8_t *cbuf_end;\n    \n    cbuf_type = s->cbuf_type;\n    cbuf_end = s->cbuf_end;\n\n    for(;;) {\n        //        printf(\"top=%p: pc=%d\\n\", th_list.top, (int)(pc - (bc_buf + RE_HEADER_LEN)));\n        opcode = *pc++;\n        switch(opcode) {\n        case REOP_match:\n            {\n                REExecState *rs;\n                if (no_recurse)\n                    return (intptr_t)cptr;\n                ret = 1;\n                goto recurse;\n            no_match:\n                if (no_recurse)\n                    return 0;\n                ret = 0;\n            recurse:\n                for(;;) {\n                    if (s->state_stack_len == 0)\n                        return ret;\n                    rs = (REExecState *)(s->state_stack +\n                                         (s->state_stack_len - 1) * s->state_size);\n                    if (rs->type == RE_EXEC_STATE_SPLIT) {\n                        if (!ret) {\n                        pop_state:\n                            memcpy(capture, rs->buf,\n                                   sizeof(capture[0]) * 2 * s->capture_count);\n                        pop_state1:\n                            pc = rs->pc;\n                            cptr = rs->cptr;\n                            stack_len = rs->stack_len;\n                            memcpy(stack, rs->buf + 2 * s->capture_count,\n                                   stack_len * sizeof(stack[0]));\n                            s->state_stack_len--;\n                            break;\n                        }\n                    } else if (rs->type == RE_EXEC_STATE_GREEDY_QUANT) {\n                        if (!ret) {\n                            uint32_t char_count, i;\n                            memcpy(capture, rs->buf,\n                                   sizeof(capture[0]) * 2 * s->capture_count);\n                            stack_len = rs->stack_len;\n                            memcpy(stack, rs->buf + 2 * s->capture_count,\n                                   stack_len * sizeof(stack[0]));\n                            pc = rs->pc;\n                            cptr = rs->cptr;\n                            /* go backward */\n                            char_count = get_u32(pc + 12);\n                            for(i = 0; i < char_count; i++) {\n                                PREV_CHAR(cptr, s->cbuf);\n                            }\n                            pc = (pc + 16) + (int)get_u32(pc);\n                            rs->cptr = cptr;\n                            rs->count--;\n                            if (rs->count == 0) {\n                                s->state_stack_len--;\n                            }\n                            break;\n                        }\n                    } else {\n                        ret = ((rs->type == RE_EXEC_STATE_LOOKAHEAD && ret) ||\n                               (rs->type == RE_EXEC_STATE_NEGATIVE_LOOKAHEAD && !ret));\n                        if (ret) {\n                            /* keep the capture in case of positive lookahead */\n                            if (rs->type == RE_EXEC_STATE_LOOKAHEAD)\n                                goto pop_state1;\n                            else\n                                goto pop_state;\n                        }\n                    }\n                    s->state_stack_len--;\n                }\n            }\n            break;\n        case REOP_char32:\n            val = get_u32(pc);\n            pc += 4;\n            goto test_char;\n        case REOP_char:\n            val = get_u16(pc);\n            pc += 2;\n        test_char:\n            if (cptr >= cbuf_end)\n                goto no_match;\n            GET_CHAR(c, cptr, cbuf_end);\n            if (s->ignore_case) {\n                c = lre_canonicalize(c, s->is_utf16);\n            }\n            if (val != c)\n                goto no_match;\n            break;\n        case REOP_split_goto_first:\n        case REOP_split_next_first:\n            {\n                const uint8_t *pc1;\n                \n                val = get_u32(pc);\n                pc += 4;\n                if (opcode == REOP_split_next_first) {\n                    pc1 = pc + (int)val;\n                } else {\n                    pc1 = pc;\n                    pc = pc + (int)val;\n                }\n                ret = push_state(s, capture, stack, stack_len,\n                                 pc1, cptr, RE_EXEC_STATE_SPLIT, 0);\n                if (ret < 0)\n                    return -1;\n                break;\n            }\n        case REOP_lookahead:\n        case REOP_negative_lookahead:\n            val = get_u32(pc);\n            pc += 4;\n            ret = push_state(s, capture, stack, stack_len,\n                             pc + (int)val, cptr,\n                             RE_EXEC_STATE_LOOKAHEAD + opcode - REOP_lookahead,\n                             0);\n            if (ret < 0)\n                return -1;\n            break;\n            \n        case REOP_goto:\n            val = get_u32(pc);\n            pc += 4 + (int)val;\n            break;\n        case REOP_line_start:\n            if (cptr == s->cbuf)\n                break;\n            if (!s->multi_line)\n                goto no_match;\n            PEEK_PREV_CHAR(c, cptr, s->cbuf);\n            if (!is_line_terminator(c))\n                goto no_match;\n            break;\n        case REOP_line_end:\n            if (cptr == cbuf_end)\n                break;\n            if (!s->multi_line)\n                goto no_match;\n            PEEK_CHAR(c, cptr, cbuf_end);\n            if (!is_line_terminator(c))\n                goto no_match;\n            break;\n        case REOP_dot:\n            if (cptr == cbuf_end)\n                goto no_match;\n            GET_CHAR(c, cptr, cbuf_end);\n            if (is_line_terminator(c))\n                goto no_match;\n            break;\n        case REOP_any:\n            if (cptr == cbuf_end)\n                goto no_match;\n            GET_CHAR(c, cptr, cbuf_end);\n            break;\n        case REOP_save_start:\n        case REOP_save_end:\n            val = *pc++;\n            assert(val < s->capture_count);\n            capture[2 * val + opcode - REOP_save_start] = (uint8_t *)cptr;\n            break;\n        case REOP_save_reset:\n            {\n                uint32_t val2;\n                val = pc[0];\n                val2 = pc[1];\n                pc += 2;\n                assert(val2 < s->capture_count);\n                while (val <= val2) {\n                    capture[2 * val] = NULL;\n                    capture[2 * val + 1] = NULL;\n                    val++;\n                }\n            }\n            break;\n        case REOP_push_i32:\n            val = get_u32(pc);\n            pc += 4;\n            stack[stack_len++] = val;\n            break;\n        case REOP_drop:\n            stack_len--;\n            break;\n        case REOP_loop:\n            val = get_u32(pc);\n            pc += 4;\n            if (--stack[stack_len - 1] != 0) {\n                pc += (int)val;\n            }\n            break;\n        case REOP_push_char_pos:\n            stack[stack_len++] = (uintptr_t)cptr;\n            break;\n        case REOP_bne_char_pos:\n            val = get_u32(pc);\n            pc += 4;\n            if (stack[--stack_len] != (uintptr_t)cptr)\n                pc += (int)val;\n            break;\n        case REOP_word_boundary:\n        case REOP_not_word_boundary:\n            {\n                BOOL v1, v2;\n                /* char before */\n                if (cptr == s->cbuf) {\n                    v1 = FALSE;\n                } else {\n                    PEEK_PREV_CHAR(c, cptr, s->cbuf);\n                    v1 = is_word_char(c);\n                }\n                /* current char */\n                if (cptr >= cbuf_end) {\n                    v2 = FALSE;\n                } else {\n                    PEEK_CHAR(c, cptr, cbuf_end);\n                    v2 = is_word_char(c);\n                }\n                if (v1 ^ v2 ^ (REOP_not_word_boundary - opcode))\n                    goto no_match;\n            }\n            break;\n        case REOP_back_reference:\n        case REOP_backward_back_reference:\n            {\n                const uint8_t *cptr1, *cptr1_end, *cptr1_start;\n                uint32_t c1, c2;\n                \n                val = *pc++;\n                if (val >= s->capture_count)\n                    goto no_match;\n                cptr1_start = capture[2 * val];\n                cptr1_end = capture[2 * val + 1];\n                if (!cptr1_start || !cptr1_end)\n                    break;\n                if (opcode == REOP_back_reference) {\n                    cptr1 = cptr1_start;\n                    while (cptr1 < cptr1_end) {\n                        if (cptr >= cbuf_end)\n                            goto no_match;\n                        GET_CHAR(c1, cptr1, cptr1_end);\n                        GET_CHAR(c2, cptr, cbuf_end);\n                        if (s->ignore_case) {\n                            c1 = lre_canonicalize(c1, s->is_utf16);\n                            c2 = lre_canonicalize(c2, s->is_utf16);\n                        }\n                        if (c1 != c2)\n                            goto no_match;\n                    }\n                } else {\n                    cptr1 = cptr1_end;\n                    while (cptr1 > cptr1_start) {\n                        if (cptr == s->cbuf)\n                            goto no_match;\n                        GET_PREV_CHAR(c1, cptr1, cptr1_start);\n                        GET_PREV_CHAR(c2, cptr, s->cbuf);\n                        if (s->ignore_case) {\n                            c1 = lre_canonicalize(c1, s->is_utf16);\n                            c2 = lre_canonicalize(c2, s->is_utf16);\n                        }\n                        if (c1 != c2)\n                            goto no_match;\n                    }\n                }\n            }\n            break;\n        case REOP_range:\n            {\n                int n;\n                uint32_t low, high, idx_min, idx_max, idx;\n                \n                n = get_u16(pc); /* n must be >= 1 */\n                pc += 2;\n                if (cptr >= cbuf_end)\n                    goto no_match;\n                GET_CHAR(c, cptr, cbuf_end);\n                if (s->ignore_case) {\n                    c = lre_canonicalize(c, s->is_utf16);\n                }\n                idx_min = 0;\n                low = get_u16(pc + 0 * 4);\n                if (c < low)\n                    goto no_match;\n                idx_max = n - 1;\n                high = get_u16(pc + idx_max * 4 + 2);\n                /* 0xffff in for last value means +infinity */\n                if (unlikely(c >= 0xffff) && high == 0xffff)\n                    goto range_match;\n                if (c > high)\n                    goto no_match;\n                while (idx_min <= idx_max) {\n                    idx = (idx_min + idx_max) / 2;\n                    low = get_u16(pc + idx * 4);\n                    high = get_u16(pc + idx * 4 + 2);\n                    if (c < low)\n                        idx_max = idx - 1;\n                    else if (c > high)\n                        idx_min = idx + 1;\n                    else\n                        goto range_match;\n                }\n                goto no_match;\n            range_match:\n                pc += 4 * n;\n            }\n            break;\n        case REOP_range32:\n            {\n                int n;\n                uint32_t low, high, idx_min, idx_max, idx;\n                \n                n = get_u16(pc); /* n must be >= 1 */\n                pc += 2;\n                if (cptr >= cbuf_end)\n                    goto no_match;\n                GET_CHAR(c, cptr, cbuf_end);\n                if (s->ignore_case) {\n                    c = lre_canonicalize(c, s->is_utf16);\n                }\n                idx_min = 0;\n                low = get_u32(pc + 0 * 8);\n                if (c < low)\n                    goto no_match;\n                idx_max = n - 1;\n                high = get_u32(pc + idx_max * 8 + 4);\n                if (c > high)\n                    goto no_match;\n                while (idx_min <= idx_max) {\n                    idx = (idx_min + idx_max) / 2;\n                    low = get_u32(pc + idx * 8);\n                    high = get_u32(pc + idx * 8 + 4);\n                    if (c < low)\n                        idx_max = idx - 1;\n                    else if (c > high)\n                        idx_min = idx + 1;\n                    else\n                        goto range32_match;\n                }\n                goto no_match;\n            range32_match:\n                pc += 8 * n;\n            }\n            break;\n        case REOP_prev:\n            /* go to the previous char */\n            if (cptr == s->cbuf)\n                goto no_match;\n            PREV_CHAR(cptr, s->cbuf);\n            break;\n        case REOP_simple_greedy_quant:\n            {\n                uint32_t next_pos, quant_min, quant_max;\n                size_t q;\n                intptr_t res;\n                const uint8_t *pc1;\n                \n                next_pos = get_u32(pc);\n                quant_min = get_u32(pc + 4);\n                quant_max = get_u32(pc + 8);\n                pc += 16;\n                pc1 = pc;\n                pc += (int)next_pos;\n                \n                q = 0;\n                for(;;) {\n                    res = lre_exec_backtrack(s, capture, stack, stack_len,\n                                             pc1, cptr, TRUE);\n                    if (res == -1)\n                        return res;\n                    if (!res)\n                        break;\n                    cptr = (uint8_t *)res;\n                    q++;\n                    if (q >= quant_max && quant_max != INT32_MAX)\n                        break;\n                }\n                if (q < quant_min)\n                    goto no_match;\n                if (q > quant_min) {\n                    /* will examine all matches down to quant_min */\n                    ret = push_state(s, capture, stack, stack_len,\n                                     pc1 - 16, cptr,\n                                     RE_EXEC_STATE_GREEDY_QUANT,\n                                     q - quant_min);\n                    if (ret < 0)\n                        return -1;\n                }\n            }\n            break;\n        default:\n            abort();\n        }\n    }\n}\n\n/* Return 1 if match, 0 if not match or -1 if error. cindex is the\n   starting position of the match and must be such as 0 <= cindex <=\n   clen. */\nint lre_exec(uint8_t **capture,\n             const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen,\n             int cbuf_type, void *opaque)\n{\n    REExecContext s_s, *s = &s_s;\n    int re_flags, i, alloca_size, ret;\n    StackInt *stack_buf;\n    \n    re_flags = bc_buf[RE_HEADER_FLAGS];\n    s->multi_line = (re_flags & LRE_FLAG_MULTILINE) != 0;\n    s->ignore_case = (re_flags & LRE_FLAG_IGNORECASE) != 0;\n    s->is_utf16 = (re_flags & LRE_FLAG_UTF16) != 0;\n    s->capture_count = bc_buf[RE_HEADER_CAPTURE_COUNT];\n    s->stack_size_max = bc_buf[RE_HEADER_STACK_SIZE];\n    s->cbuf = cbuf;\n    s->cbuf_end = cbuf + (clen << cbuf_type);\n    s->cbuf_type = cbuf_type;\n    if (s->cbuf_type == 1 && s->is_utf16)\n        s->cbuf_type = 2;\n    s->opaque = opaque;\n\n    s->state_size = sizeof(REExecState) +\n        s->capture_count * sizeof(capture[0]) * 2 +\n        s->stack_size_max * sizeof(stack_buf[0]);\n    s->state_stack = NULL;\n    s->state_stack_len = 0;\n    s->state_stack_size = 0;\n    \n    for(i = 0; i < s->capture_count * 2; i++)\n        capture[i] = NULL;\n    alloca_size = s->stack_size_max * sizeof(stack_buf[0]);\n    stack_buf = alloca(alloca_size);\n    ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN,\n                             cbuf + (cindex << cbuf_type), FALSE);\n    lre_realloc(s->opaque, s->state_stack, 0);\n    return ret;\n}\n\nint lre_get_capture_count(const uint8_t *bc_buf)\n{\n    return bc_buf[RE_HEADER_CAPTURE_COUNT];\n}\n\nint lre_get_flags(const uint8_t *bc_buf)\n{\n    return bc_buf[RE_HEADER_FLAGS];\n}\n\n#ifdef TEST\n\nBOOL lre_check_stack_overflow(void *opaque, size_t alloca_size)\n{\n    return FALSE;\n}\n\nvoid *lre_realloc(void *opaque, void *ptr, size_t size)\n{\n    return realloc(ptr, size);\n}\n\nint main(int argc, char **argv)\n{\n    int len, ret, i;\n    uint8_t *bc;\n    char error_msg[64];\n    uint8_t *capture[CAPTURE_COUNT_MAX * 2];\n    const char *input;\n    int input_len, capture_count;\n    \n    if (argc < 3) {\n        printf(\"usage: %s regexp input\\n\", argv[0]);\n        exit(1);\n    }\n    bc = lre_compile(&len, error_msg, sizeof(error_msg), argv[1],\n                     strlen(argv[1]), 0, NULL);\n    if (!bc) {\n        fprintf(stderr, \"error: %s\\n\", error_msg);\n        exit(1);\n    }\n\n    input = argv[2];\n    input_len = strlen(input);\n    \n    ret = lre_exec(capture, bc, (uint8_t *)input, 0, input_len, 0, NULL);\n    printf(\"ret=%d\\n\", ret);\n    if (ret == 1) {\n        capture_count = lre_get_capture_count(bc);\n        for(i = 0; i < 2 * capture_count; i++) {\n            uint8_t *ptr;\n            ptr = capture[i];\n            printf(\"%d: \", i);\n            if (!ptr)\n                printf(\"<nil>\");\n            else\n                printf(\"%u\", (int)(ptr - (uint8_t *)input));\n            printf(\"\\n\");\n        }\n    }\n    return 0;\n}\n#endif\n"
  },
  {
    "path": "libregexp.h",
    "content": "/*\n * Regular Expression Engine\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#ifndef LIBREGEXP_H\n#define LIBREGEXP_H\n\n#include <stddef.h>\n\n#include \"libunicode.h\"\n\n#define LRE_BOOL  int       /* for documentation purposes */\n\n#define LRE_FLAG_GLOBAL     (1 << 0)\n#define LRE_FLAG_IGNORECASE (1 << 1)\n#define LRE_FLAG_MULTILINE  (1 << 2)\n#define LRE_FLAG_DOTALL     (1 << 3)\n#define LRE_FLAG_UTF16      (1 << 4)\n#define LRE_FLAG_STICKY     (1 << 5)\n\n#define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */\n\nuint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size,\n                     const char *buf, size_t buf_len, int re_flags,\n                     void *opaque);\nint lre_get_capture_count(const uint8_t *bc_buf);\nint lre_get_flags(const uint8_t *bc_buf);\nint lre_exec(uint8_t **capture,\n             const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen,\n             int cbuf_type, void *opaque);\n\nint lre_parse_escape(const uint8_t **pp, int allow_utf16);\nLRE_BOOL lre_is_space(int c);\n\n/* must be provided by the user */\nLRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size); \nvoid *lre_realloc(void *opaque, void *ptr, size_t size);\n\n/* JS identifier test */\nextern uint32_t const lre_id_start_table_ascii[4];\nextern uint32_t const lre_id_continue_table_ascii[4];\n\nstatic inline int lre_js_is_ident_first(int c)\n{\n    if ((uint32_t)c < 128) {\n        return (lre_id_start_table_ascii[c >> 5] >> (c & 31)) & 1;\n    } else {\n#ifdef CONFIG_ALL_UNICODE\n        return lre_is_id_start(c);\n#else\n        return !lre_is_space(c);\n#endif\n    }\n}\n\nstatic inline int lre_js_is_ident_next(int c)\n{\n    if ((uint32_t)c < 128) {\n        return (lre_id_continue_table_ascii[c >> 5] >> (c & 31)) & 1;\n    } else {\n        /* ZWNJ and ZWJ are accepted in identifiers */\n#ifdef CONFIG_ALL_UNICODE\n        return lre_is_id_continue(c) || c == 0x200C || c == 0x200D;\n#else\n        return !lre_is_space(c) || c == 0x200C || c == 0x200D;\n#endif\n    }\n}\n\n#undef LRE_BOOL\n\n#endif /* LIBREGEXP_H */\n"
  },
  {
    "path": "libunicode-table.h",
    "content": "/* Compressed unicode tables */\n/* Automatically generated file - do not edit */\n\n#include <stdint.h>\n\nstatic const uint32_t case_conv_table1[361] = {\n    0x00209a30, 0x00309a00, 0x005a8173, 0x00601730,\n    0x006c0730, 0x006f81b3, 0x00701700, 0x007c0700,\n    0x007f8100, 0x00803040, 0x009801c3, 0x00988190,\n    0x00990640, 0x009c9040, 0x00a481b4, 0x00a52e40,\n    0x00bc0130, 0x00bc8640, 0x00bf8170, 0x00c00100,\n    0x00c08130, 0x00c10440, 0x00c30130, 0x00c38240,\n    0x00c48230, 0x00c58240, 0x00c70130, 0x00c78130,\n    0x00c80130, 0x00c88240, 0x00c98130, 0x00ca0130,\n    0x00ca8100, 0x00cb0130, 0x00cb8130, 0x00cc0240,\n    0x00cd0100, 0x00ce0130, 0x00ce8130, 0x00cf0100,\n    0x00cf8130, 0x00d00640, 0x00d30130, 0x00d38240,\n    0x00d48130, 0x00d60240, 0x00d70130, 0x00d78240,\n    0x00d88230, 0x00d98440, 0x00db8130, 0x00dc0240,\n    0x00de0240, 0x00df8100, 0x00e20350, 0x00e38350,\n    0x00e50350, 0x00e69040, 0x00ee8100, 0x00ef1240,\n    0x00f801b4, 0x00f88350, 0x00fa0240, 0x00fb0130,\n    0x00fb8130, 0x00fc2840, 0x01100130, 0x01111240,\n    0x011d0131, 0x011d8240, 0x011e8130, 0x011f0131,\n    0x011f8201, 0x01208240, 0x01218130, 0x01220130,\n    0x01228130, 0x01230a40, 0x01280101, 0x01288101,\n    0x01290101, 0x01298100, 0x012a0100, 0x012b0200,\n    0x012c8100, 0x012d8100, 0x012e0101, 0x01300100,\n    0x01308101, 0x01318100, 0x01328101, 0x01330101,\n    0x01340100, 0x01348100, 0x01350101, 0x01358101,\n    0x01360101, 0x01378100, 0x01388101, 0x01390100,\n    0x013a8100, 0x013e8101, 0x01400100, 0x01410101,\n    0x01418100, 0x01438101, 0x01440100, 0x01448100,\n    0x01450200, 0x01460100, 0x01490100, 0x014e8101,\n    0x014f0101, 0x01a28173, 0x01b80440, 0x01bb0240,\n    0x01bd8300, 0x01bf8130, 0x01c30130, 0x01c40330,\n    0x01c60130, 0x01c70230, 0x01c801d0, 0x01c89130,\n    0x01d18930, 0x01d60100, 0x01d68300, 0x01d801d3,\n    0x01d89100, 0x01e10173, 0x01e18900, 0x01e60100,\n    0x01e68200, 0x01e78130, 0x01e80173, 0x01e88173,\n    0x01ea8173, 0x01eb0173, 0x01eb8100, 0x01ec1840,\n    0x01f80173, 0x01f88173, 0x01f90100, 0x01f98100,\n    0x01fa01a0, 0x01fa8173, 0x01fb8240, 0x01fc8130,\n    0x01fd0240, 0x01fe8330, 0x02001030, 0x02082030,\n    0x02182000, 0x02281000, 0x02302240, 0x02453640,\n    0x02600130, 0x02608e40, 0x02678100, 0x02686040,\n    0x0298a630, 0x02b0a600, 0x02c381b5, 0x08502631,\n    0x08638131, 0x08668131, 0x08682b00, 0x087e8300,\n    0x09d05011, 0x09f80610, 0x09fc0620, 0x0e400174,\n    0x0e408174, 0x0e410174, 0x0e418174, 0x0e420174,\n    0x0e428174, 0x0e430174, 0x0e438180, 0x0e440180,\n    0x0e482b30, 0x0e5e8330, 0x0ebc8101, 0x0ebe8101,\n    0x0ec70101, 0x0f007e40, 0x0f3f1840, 0x0f4b01b5,\n    0x0f4b81b6, 0x0f4c01b6, 0x0f4c81b6, 0x0f4d01b7,\n    0x0f4d8180, 0x0f4f0130, 0x0f506040, 0x0f800800,\n    0x0f840830, 0x0f880600, 0x0f8c0630, 0x0f900800,\n    0x0f940830, 0x0f980800, 0x0f9c0830, 0x0fa00600,\n    0x0fa40630, 0x0fa801b0, 0x0fa88100, 0x0fa901d3,\n    0x0fa98100, 0x0faa01d3, 0x0faa8100, 0x0fab01d3,\n    0x0fab8100, 0x0fac8130, 0x0fad8130, 0x0fae8130,\n    0x0faf8130, 0x0fb00800, 0x0fb40830, 0x0fb80200,\n    0x0fb90400, 0x0fbb0200, 0x0fbc0201, 0x0fbd0201,\n    0x0fbe0201, 0x0fc008b7, 0x0fc40867, 0x0fc808b8,\n    0x0fcc0868, 0x0fd008b8, 0x0fd40868, 0x0fd80200,\n    0x0fd901b9, 0x0fd981b1, 0x0fda01b9, 0x0fdb01b1,\n    0x0fdb81d7, 0x0fdc0230, 0x0fdd0230, 0x0fde0161,\n    0x0fdf0173, 0x0fe101b9, 0x0fe181b2, 0x0fe201ba,\n    0x0fe301b2, 0x0fe381d8, 0x0fe40430, 0x0fe60162,\n    0x0fe80200, 0x0fe901d0, 0x0fe981d0, 0x0feb01b0,\n    0x0feb81d0, 0x0fec0230, 0x0fed0230, 0x0ff00201,\n    0x0ff101d3, 0x0ff181d3, 0x0ff201ba, 0x0ff28101,\n    0x0ff301b0, 0x0ff381d3, 0x0ff40230, 0x0ff50230,\n    0x0ff60131, 0x0ff901ba, 0x0ff981b2, 0x0ffa01bb,\n    0x0ffb01b2, 0x0ffb81d9, 0x0ffc0230, 0x0ffd0230,\n    0x0ffe0162, 0x109301a0, 0x109501a0, 0x109581a0,\n    0x10990131, 0x10a70101, 0x10b01031, 0x10b81001,\n    0x10c18240, 0x125b1a31, 0x12681a01, 0x16002f31,\n    0x16182f01, 0x16300240, 0x16310130, 0x16318130,\n    0x16320130, 0x16328100, 0x16330100, 0x16338640,\n    0x16368130, 0x16370130, 0x16378130, 0x16380130,\n    0x16390240, 0x163a8240, 0x163f0230, 0x16406440,\n    0x16758440, 0x16790240, 0x16802600, 0x16938100,\n    0x16968100, 0x53202e40, 0x53401c40, 0x53910e40,\n    0x53993e40, 0x53bc8440, 0x53be8130, 0x53bf0a40,\n    0x53c58240, 0x53c68130, 0x53c80440, 0x53ca0101,\n    0x53cb1440, 0x53d50130, 0x53d58130, 0x53d60130,\n    0x53d68130, 0x53d70130, 0x53d80130, 0x53d88130,\n    0x53d90130, 0x53d98131, 0x53da0c40, 0x53e10240,\n    0x53e20131, 0x53e28130, 0x53e30130, 0x53e38440,\n    0x53fa8240, 0x55a98101, 0x55b85020, 0x7d8001b2,\n    0x7d8081b2, 0x7d8101b2, 0x7d8181da, 0x7d8201da,\n    0x7d8281b3, 0x7d8301b3, 0x7d8981bb, 0x7d8a01bb,\n    0x7d8a81bb, 0x7d8b01bc, 0x7d8b81bb, 0x7f909a31,\n    0x7fa09a01, 0x82002831, 0x82142801, 0x82582431,\n    0x826c2401, 0x86403331, 0x86603301, 0x8c502031,\n    0x8c602001, 0xb7202031, 0xb7302001, 0xf4802231,\n    0xf4912201,\n};\n\nstatic const uint8_t case_conv_table2[361] = {\n    0x01, 0x00, 0x9c, 0x06, 0x07, 0x4d, 0x03, 0x04,\n    0x10, 0x00, 0x8f, 0x0b, 0x00, 0x00, 0x11, 0x00,\n    0x08, 0x00, 0x53, 0x4a, 0x51, 0x00, 0x52, 0x00,\n    0x53, 0x00, 0x3a, 0x54, 0x55, 0x00, 0x57, 0x59,\n    0x3f, 0x5d, 0x5c, 0x00, 0x46, 0x61, 0x63, 0x42,\n    0x64, 0x00, 0x66, 0x00, 0x68, 0x00, 0x6a, 0x00,\n    0x6c, 0x00, 0x6e, 0x00, 0x00, 0x40, 0x00, 0x00,\n    0x00, 0x00, 0x1a, 0x00, 0x93, 0x00, 0x00, 0x20,\n    0x35, 0x00, 0x27, 0x00, 0x21, 0x00, 0x24, 0x22,\n    0x2a, 0x00, 0x13, 0x6b, 0x6d, 0x00, 0x26, 0x24,\n    0x27, 0x14, 0x16, 0x18, 0x1b, 0x1c, 0x3e, 0x1e,\n    0x3f, 0x1f, 0x39, 0x3d, 0x22, 0x21, 0x41, 0x1e,\n    0x40, 0x25, 0x25, 0x26, 0x28, 0x20, 0x2a, 0x49,\n    0x2c, 0x43, 0x2e, 0x4b, 0x30, 0x4c, 0x32, 0x44,\n    0x42, 0x99, 0x00, 0x00, 0x95, 0x8f, 0x7d, 0x7e,\n    0x83, 0x84, 0x12, 0x80, 0x82, 0x76, 0x77, 0x12,\n    0x7b, 0xa3, 0x7c, 0x78, 0x79, 0x8a, 0x92, 0x98,\n    0xa6, 0xa0, 0x85, 0x00, 0x9a, 0xa1, 0x93, 0x75,\n    0x33, 0x95, 0x00, 0x8e, 0x00, 0x74, 0x99, 0x98,\n    0x97, 0x96, 0x00, 0x00, 0x9e, 0x00, 0x9c, 0x00,\n    0xa1, 0xa0, 0x15, 0x2e, 0x2f, 0x30, 0xb4, 0xb5,\n    0x4e, 0xaa, 0xa9, 0x12, 0x14, 0x1e, 0x21, 0x22,\n    0x22, 0x2a, 0x34, 0x35, 0xa6, 0xa7, 0x36, 0x1f,\n    0x4a, 0x00, 0x00, 0x97, 0x01, 0x5a, 0xda, 0x1d,\n    0x36, 0x05, 0x00, 0xc4, 0xc3, 0xc6, 0xc5, 0xc8,\n    0xc7, 0xca, 0xc9, 0xcc, 0xcb, 0xc4, 0xd5, 0x45,\n    0xd6, 0x42, 0xd7, 0x46, 0xd8, 0xce, 0xd0, 0xd2,\n    0xd4, 0xda, 0xd9, 0xee, 0xf6, 0xfe, 0x0e, 0x07,\n    0x0f, 0x80, 0x9f, 0x00, 0x21, 0x80, 0xa3, 0xed,\n    0x00, 0xc0, 0x40, 0xc6, 0x60, 0xe7, 0xdb, 0xe6,\n    0x99, 0xc0, 0x00, 0x00, 0x06, 0x60, 0xdc, 0x29,\n    0xfd, 0x15, 0x12, 0x06, 0x16, 0xf8, 0xdd, 0x06,\n    0x15, 0x12, 0x84, 0x08, 0xc6, 0x16, 0xff, 0xdf,\n    0x03, 0xc0, 0x40, 0x00, 0x46, 0x60, 0xde, 0xe0,\n    0x6d, 0x37, 0x38, 0x39, 0x15, 0x14, 0x17, 0x16,\n    0x00, 0x1a, 0x19, 0x1c, 0x1b, 0x00, 0x5f, 0xb7,\n    0x65, 0x44, 0x47, 0x00, 0x4f, 0x62, 0x4e, 0x50,\n    0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0xa3, 0xa4,\n    0xa5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb6, 0x00,\n    0x00, 0x5a, 0x00, 0x48, 0x00, 0x5b, 0x56, 0x58,\n    0x60, 0x5e, 0x70, 0x69, 0x6f, 0x4d, 0x00, 0x00,\n    0x3b, 0x67, 0xb8, 0x00, 0x00, 0x45, 0xa8, 0x8a,\n    0x8b, 0x8c, 0xab, 0xac, 0x58, 0x58, 0xaf, 0x94,\n    0xb0, 0x6f, 0xb2, 0x5c, 0x5b, 0x5e, 0x5d, 0x60,\n    0x5f, 0x62, 0x61, 0x64, 0x63, 0x66, 0x65, 0x68,\n    0x67,\n};\n\nstatic const uint16_t case_conv_ext[58] = {\n    0x0399, 0x0308, 0x0301, 0x03a5, 0x0313, 0x0300, 0x0342, 0x0391,\n    0x0397, 0x03a9, 0x0046, 0x0049, 0x004c, 0x0053, 0x0069, 0x0307,\n    0x02bc, 0x004e, 0x004a, 0x030c, 0x0535, 0x0552, 0x0048, 0x0331,\n    0x0054, 0x0057, 0x030a, 0x0059, 0x0041, 0x02be, 0x1f08, 0x1f80,\n    0x1f28, 0x1f90, 0x1f68, 0x1fa0, 0x1fba, 0x0386, 0x1fb3, 0x1fca,\n    0x0389, 0x1fc3, 0x03a1, 0x1ffa, 0x038f, 0x1ff3, 0x0544, 0x0546,\n    0x053b, 0x054e, 0x053d, 0x03b8, 0x0462, 0xa64a, 0x1e60, 0x03c9,\n    0x006b, 0x00e5,\n};\n\nstatic const uint8_t unicode_prop_Cased1_table[172] = {\n    0x40, 0xa9, 0x80, 0x8e, 0x80, 0xfc, 0x80, 0xd3,\n    0x80, 0x8c, 0x80, 0x8d, 0x81, 0x8d, 0x02, 0x80,\n    0xe1, 0x80, 0x91, 0x85, 0x9a, 0x01, 0x00, 0x01,\n    0x11, 0x00, 0x01, 0x04, 0x08, 0x01, 0x08, 0x30,\n    0x08, 0x01, 0x15, 0x20, 0x00, 0x39, 0x99, 0x31,\n    0x9d, 0x84, 0x40, 0x94, 0x80, 0xd6, 0x82, 0xa6,\n    0x80, 0x41, 0x62, 0x80, 0xa6, 0x80, 0x57, 0x76,\n    0xf8, 0x02, 0x80, 0x8f, 0x80, 0xb0, 0x40, 0xdb,\n    0x08, 0x80, 0x41, 0xd0, 0x80, 0x8c, 0x80, 0x8f,\n    0x8c, 0xe4, 0x03, 0x01, 0x89, 0x00, 0x14, 0x28,\n    0x10, 0x11, 0x02, 0x01, 0x18, 0x0b, 0x24, 0x4b,\n    0x26, 0x01, 0x01, 0x86, 0xe5, 0x80, 0x60, 0x79,\n    0xb6, 0x81, 0x40, 0x91, 0x81, 0xbd, 0x88, 0x94,\n    0x05, 0x80, 0x98, 0x80, 0xc7, 0x82, 0x43, 0x34,\n    0xa2, 0x06, 0x80, 0x8c, 0x61, 0x28, 0x96, 0xd4,\n    0x80, 0xc6, 0x01, 0x08, 0x09, 0x0b, 0x80, 0x8b,\n    0x00, 0x06, 0x80, 0xc0, 0x03, 0x0f, 0x06, 0x80,\n    0x9b, 0x03, 0x04, 0x00, 0x16, 0x80, 0x41, 0x53,\n    0x81, 0x98, 0x80, 0x98, 0x80, 0x9e, 0x80, 0x98,\n    0x80, 0x9e, 0x80, 0x98, 0x80, 0x9e, 0x80, 0x98,\n    0x80, 0x9e, 0x80, 0x98, 0x07, 0x59, 0x63, 0x99,\n    0x85, 0x99, 0x85, 0x99,\n};\n\nstatic const uint8_t unicode_prop_Cased1_index[18] = {\n    0xb9, 0x02, 0xe0, 0xa0, 0x1e, 0x40, 0x9e, 0xa6,\n    0x40, 0xba, 0xd4, 0x01, 0x89, 0xd7, 0x01, 0x8a,\n    0xf1, 0x01,\n};\n\nstatic const uint8_t unicode_prop_Case_Ignorable_table[692] = {\n    0xa6, 0x05, 0x80, 0x8a, 0x80, 0xa2, 0x00, 0x80,\n    0xc6, 0x03, 0x00, 0x03, 0x01, 0x81, 0x41, 0xf6,\n    0x40, 0xbf, 0x19, 0x18, 0x88, 0x08, 0x80, 0x40,\n    0xfa, 0x86, 0x40, 0xce, 0x04, 0x80, 0xb0, 0xac,\n    0x00, 0x01, 0x01, 0x00, 0xab, 0x80, 0x8a, 0x85,\n    0x89, 0x8a, 0x00, 0xa2, 0x80, 0x89, 0x94, 0x8f,\n    0x80, 0xe4, 0x38, 0x89, 0x03, 0xa0, 0x00, 0x80,\n    0x9d, 0x9a, 0xda, 0x8a, 0xb9, 0x8a, 0x18, 0x08,\n    0x97, 0x97, 0xaa, 0x82, 0xf6, 0xaf, 0xb6, 0x00,\n    0x03, 0x3b, 0x02, 0x86, 0x89, 0x81, 0x8c, 0x80,\n    0x8e, 0x80, 0xb9, 0x03, 0x1f, 0x80, 0x93, 0x81,\n    0x99, 0x01, 0x81, 0xb8, 0x03, 0x0b, 0x09, 0x12,\n    0x80, 0x9d, 0x0a, 0x80, 0x8a, 0x81, 0xb8, 0x03,\n    0x20, 0x0b, 0x80, 0x93, 0x81, 0x95, 0x28, 0x80,\n    0xb9, 0x01, 0x00, 0x1f, 0x06, 0x81, 0x8a, 0x81,\n    0x9d, 0x80, 0xbc, 0x80, 0x8b, 0x80, 0xb1, 0x02,\n    0x80, 0xb8, 0x14, 0x10, 0x1e, 0x81, 0x8a, 0x81,\n    0x9c, 0x80, 0xb9, 0x01, 0x05, 0x04, 0x81, 0x93,\n    0x81, 0x9b, 0x81, 0xb8, 0x0b, 0x1f, 0x80, 0x93,\n    0x81, 0x9c, 0x80, 0xc7, 0x06, 0x10, 0x80, 0xd9,\n    0x01, 0x86, 0x8a, 0x88, 0xe1, 0x01, 0x88, 0x88,\n    0x00, 0x85, 0xc9, 0x81, 0x9a, 0x00, 0x00, 0x80,\n    0xb6, 0x8d, 0x04, 0x01, 0x84, 0x8a, 0x80, 0xa3,\n    0x88, 0x80, 0xe5, 0x18, 0x28, 0x09, 0x81, 0x98,\n    0x0b, 0x82, 0x8f, 0x83, 0x8c, 0x01, 0x0d, 0x80,\n    0x8e, 0x80, 0xdd, 0x80, 0x42, 0x5f, 0x82, 0x43,\n    0xb1, 0x82, 0x9c, 0x82, 0x9c, 0x81, 0x9d, 0x81,\n    0xbf, 0x08, 0x37, 0x01, 0x8a, 0x10, 0x20, 0xac,\n    0x83, 0xb3, 0x80, 0xc0, 0x81, 0xa1, 0x80, 0xf5,\n    0x13, 0x81, 0x88, 0x05, 0x82, 0x40, 0xda, 0x09,\n    0x80, 0xb9, 0x00, 0x30, 0x00, 0x01, 0x3d, 0x89,\n    0x08, 0xa6, 0x07, 0x90, 0xbe, 0x83, 0xaf, 0x00,\n    0x20, 0x04, 0x80, 0xa7, 0x88, 0x8b, 0x81, 0x9f,\n    0x19, 0x08, 0x82, 0xb7, 0x00, 0x0a, 0x00, 0x82,\n    0xb9, 0x39, 0x81, 0xbf, 0x85, 0xd1, 0x10, 0x8c,\n    0x06, 0x18, 0x28, 0x11, 0xb1, 0xbe, 0x8c, 0x80,\n    0xa1, 0xde, 0x04, 0x41, 0xbc, 0x00, 0x82, 0x8a,\n    0x82, 0x8c, 0x82, 0x8c, 0x82, 0x8c, 0x81, 0x8b,\n    0x27, 0x81, 0x89, 0x01, 0x01, 0x84, 0xb0, 0x20,\n    0x89, 0x00, 0x8c, 0x80, 0x8f, 0x8c, 0xb2, 0xa0,\n    0x4b, 0x8a, 0x81, 0xf0, 0x82, 0xfc, 0x80, 0x8e,\n    0x80, 0xdf, 0x9f, 0xae, 0x80, 0x41, 0xd4, 0x80,\n    0xa3, 0x1a, 0x24, 0x80, 0xdc, 0x85, 0xdc, 0x82,\n    0x60, 0x6f, 0x15, 0x80, 0x44, 0xe1, 0x85, 0x41,\n    0x0d, 0x80, 0xe1, 0x18, 0x89, 0x00, 0x9b, 0x83,\n    0xcf, 0x81, 0x8d, 0xa1, 0xcd, 0x80, 0x96, 0x82,\n    0xec, 0x0f, 0x02, 0x03, 0x80, 0x98, 0x0c, 0x80,\n    0x40, 0x96, 0x81, 0x99, 0x91, 0x8c, 0x80, 0xa5,\n    0x87, 0x98, 0x8a, 0xad, 0x82, 0xaf, 0x01, 0x19,\n    0x81, 0x90, 0x80, 0x94, 0x81, 0xc1, 0x29, 0x09,\n    0x81, 0x8b, 0x07, 0x80, 0xa2, 0x80, 0x8a, 0x80,\n    0xb2, 0x00, 0x11, 0x0c, 0x08, 0x80, 0x9a, 0x80,\n    0x8d, 0x0c, 0x08, 0x80, 0xe3, 0x84, 0x88, 0x82,\n    0xf8, 0x01, 0x03, 0x80, 0x60, 0x4f, 0x2f, 0x80,\n    0x40, 0x92, 0x8f, 0x42, 0x3d, 0x8f, 0x10, 0x8b,\n    0x8f, 0xa1, 0x01, 0x80, 0x40, 0xa8, 0x06, 0x05,\n    0x80, 0x8a, 0x80, 0xa2, 0x00, 0x80, 0xae, 0x80,\n    0xac, 0x81, 0xc2, 0x80, 0x94, 0x82, 0x42, 0x00,\n    0x80, 0x40, 0xe1, 0x80, 0x40, 0x94, 0x84, 0x46,\n    0x85, 0x10, 0x0c, 0x83, 0xa7, 0x13, 0x80, 0x40,\n    0xa4, 0x81, 0x42, 0x3c, 0x83, 0x41, 0x82, 0x81,\n    0x40, 0x98, 0x8a, 0x40, 0xaf, 0x80, 0xb5, 0x8e,\n    0xb7, 0x82, 0xb0, 0x19, 0x09, 0x80, 0x8e, 0x80,\n    0xb1, 0x82, 0xa3, 0x20, 0x87, 0xbd, 0x80, 0x8b,\n    0x81, 0xb3, 0x88, 0x89, 0x19, 0x80, 0xde, 0x11,\n    0x00, 0x0d, 0x80, 0x40, 0x9f, 0x02, 0x87, 0x94,\n    0x81, 0xb8, 0x0a, 0x80, 0xa4, 0x32, 0x84, 0x40,\n    0xc2, 0x39, 0x10, 0x80, 0x96, 0x80, 0xd3, 0x28,\n    0x03, 0x08, 0x81, 0x40, 0xed, 0x1d, 0x08, 0x81,\n    0x9a, 0x81, 0xd4, 0x39, 0x00, 0x81, 0xe9, 0x00,\n    0x01, 0x28, 0x80, 0xe4, 0x11, 0x18, 0x84, 0x41,\n    0x02, 0x88, 0x01, 0x40, 0xff, 0x08, 0x03, 0x80,\n    0x40, 0x8f, 0x19, 0x0b, 0x80, 0x9f, 0x89, 0xa7,\n    0x29, 0x1f, 0x80, 0x88, 0x29, 0x82, 0xad, 0x8c,\n    0x01, 0x41, 0x95, 0x30, 0x28, 0x80, 0xd1, 0x95,\n    0x0e, 0x01, 0x01, 0xf9, 0x2a, 0x00, 0x08, 0x30,\n    0x80, 0xc7, 0x0a, 0x00, 0x80, 0x41, 0x5a, 0x81,\n    0x55, 0x3a, 0x88, 0x60, 0x36, 0xb6, 0x84, 0xba,\n    0x86, 0x88, 0x83, 0x44, 0x0a, 0x80, 0xbe, 0x90,\n    0xbf, 0x08, 0x81, 0x60, 0x4c, 0xb7, 0x08, 0x83,\n    0x54, 0xc2, 0x82, 0x88, 0x8f, 0x0e, 0x9d, 0x83,\n    0x40, 0x93, 0x82, 0x47, 0xba, 0xb6, 0x83, 0xb1,\n    0x38, 0x8d, 0x80, 0x95, 0x20, 0x8e, 0x45, 0x4f,\n    0x30, 0x90, 0x0e, 0x01, 0x04, 0x41, 0x04, 0x8d,\n    0x41, 0xad, 0x83, 0x45, 0xdf, 0x86, 0xec, 0x87,\n    0x4a, 0xae, 0x84, 0x6c, 0x0c, 0x00, 0x80, 0x9d,\n    0xdf, 0xff, 0x40, 0xef,\n};\n\nstatic const uint8_t unicode_prop_Case_Ignorable_index[66] = {\n    0xbe, 0x05, 0x00, 0xfe, 0x07, 0x00, 0x52, 0x0a,\n    0x20, 0x05, 0x0c, 0x20, 0x3b, 0x0e, 0x40, 0x61,\n    0x10, 0x40, 0x0f, 0x18, 0x20, 0x43, 0x1b, 0x60,\n    0x79, 0x1d, 0x00, 0xf1, 0x20, 0x00, 0x0d, 0xa6,\n    0x40, 0x2e, 0xa9, 0x20, 0xde, 0xaa, 0x00, 0x0f,\n    0xff, 0x20, 0xe7, 0x0a, 0x41, 0x82, 0x11, 0x21,\n    0xc4, 0x14, 0x61, 0x44, 0x19, 0x01, 0x48, 0x1d,\n    0x21, 0xa4, 0xbc, 0x01, 0x3e, 0xe1, 0x01, 0xf0,\n    0x01, 0x0e,\n};\n\nstatic const uint8_t unicode_prop_ID_Start_table[1045] = {\n    0xc0, 0x99, 0x85, 0x99, 0xae, 0x80, 0x89, 0x03,\n    0x04, 0x96, 0x80, 0x9e, 0x80, 0x41, 0xc9, 0x83,\n    0x8b, 0x8d, 0x26, 0x00, 0x80, 0x40, 0x80, 0x20,\n    0x09, 0x18, 0x05, 0x00, 0x10, 0x00, 0x93, 0x80,\n    0xd2, 0x80, 0x40, 0x8a, 0x87, 0x40, 0xa5, 0x80,\n    0xa5, 0x08, 0x85, 0xa8, 0xc6, 0x9a, 0x1b, 0xac,\n    0xaa, 0xa2, 0x08, 0xe2, 0x00, 0x8e, 0x0e, 0x81,\n    0x89, 0x11, 0x80, 0x8f, 0x00, 0x9d, 0x9c, 0xd8,\n    0x8a, 0x80, 0x97, 0xa0, 0x88, 0x0b, 0x04, 0x95,\n    0x18, 0x88, 0x02, 0x80, 0x96, 0x98, 0x86, 0x8a,\n    0xb4, 0x94, 0x80, 0x91, 0xbb, 0xb5, 0x10, 0x91,\n    0x06, 0x89, 0x8e, 0x8f, 0x1f, 0x09, 0x81, 0x95,\n    0x06, 0x00, 0x13, 0x10, 0x8f, 0x80, 0x8c, 0x08,\n    0x82, 0x8d, 0x81, 0x89, 0x07, 0x2b, 0x09, 0x95,\n    0x06, 0x01, 0x01, 0x01, 0x9e, 0x18, 0x80, 0x92,\n    0x82, 0x8f, 0x88, 0x02, 0x80, 0x95, 0x06, 0x01,\n    0x04, 0x10, 0x91, 0x80, 0x8e, 0x81, 0x96, 0x80,\n    0x8a, 0x39, 0x09, 0x95, 0x06, 0x01, 0x04, 0x10,\n    0x9d, 0x08, 0x82, 0x8e, 0x80, 0x90, 0x00, 0x2a,\n    0x10, 0x1a, 0x08, 0x00, 0x0a, 0x0a, 0x12, 0x8b,\n    0x95, 0x80, 0xb3, 0x38, 0x10, 0x96, 0x80, 0x8f,\n    0x10, 0x99, 0x14, 0x81, 0x9d, 0x03, 0x38, 0x10,\n    0x96, 0x80, 0x89, 0x04, 0x10, 0x9f, 0x00, 0x81,\n    0x8e, 0x81, 0x90, 0x88, 0x02, 0x80, 0xa8, 0x08,\n    0x8f, 0x04, 0x17, 0x82, 0x97, 0x2c, 0x91, 0x82,\n    0x97, 0x80, 0x88, 0x00, 0x0e, 0xb9, 0xaf, 0x01,\n    0x8b, 0x86, 0xb9, 0x08, 0x00, 0x20, 0x97, 0x00,\n    0x80, 0x89, 0x01, 0x88, 0x01, 0x20, 0x80, 0x94,\n    0x83, 0x9f, 0x80, 0xbe, 0x38, 0xa3, 0x9a, 0x84,\n    0xf2, 0xaa, 0x93, 0x80, 0x8f, 0x2b, 0x1a, 0x02,\n    0x0e, 0x13, 0x8c, 0x8b, 0x80, 0x90, 0xa5, 0x00,\n    0x20, 0x81, 0xaa, 0x80, 0x41, 0x4c, 0x03, 0x0e,\n    0x00, 0x03, 0x81, 0xa8, 0x03, 0x81, 0xa0, 0x03,\n    0x0e, 0x00, 0x03, 0x81, 0x8e, 0x80, 0xb8, 0x03,\n    0x81, 0xc2, 0xa4, 0x8f, 0x8f, 0xd5, 0x0d, 0x82,\n    0x42, 0x6b, 0x81, 0x90, 0x80, 0x99, 0x84, 0xca,\n    0x82, 0x8a, 0x86, 0x8c, 0x03, 0x8d, 0x91, 0x8d,\n    0x91, 0x8d, 0x8c, 0x02, 0x8e, 0xb3, 0xa2, 0x03,\n    0x80, 0xc2, 0xd8, 0x86, 0xa8, 0x00, 0x84, 0xc5,\n    0x89, 0x9e, 0xb0, 0x9d, 0x0c, 0x8a, 0xab, 0x83,\n    0x99, 0xb5, 0x96, 0x88, 0xb4, 0xd1, 0x80, 0xdc,\n    0xae, 0x90, 0x86, 0xb6, 0x9d, 0x8c, 0x81, 0x89,\n    0xab, 0x99, 0xa3, 0xa8, 0x82, 0x89, 0xa3, 0x81,\n    0x88, 0x86, 0xaa, 0x0a, 0xa8, 0x18, 0x28, 0x0a,\n    0x04, 0x40, 0xbf, 0xbf, 0x41, 0x15, 0x0d, 0x81,\n    0xa5, 0x0d, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x9e,\n    0x81, 0xb4, 0x06, 0x00, 0x12, 0x06, 0x13, 0x0d,\n    0x83, 0x8c, 0x22, 0x06, 0xf3, 0x80, 0x8c, 0x80,\n    0x8f, 0x8c, 0xe4, 0x03, 0x01, 0x89, 0x00, 0x0d,\n    0x28, 0x00, 0x00, 0x80, 0x8f, 0x0b, 0x24, 0x18,\n    0x90, 0xa8, 0x4a, 0x76, 0xae, 0x80, 0xae, 0x80,\n    0x40, 0x84, 0x2b, 0x11, 0x8b, 0xa5, 0x00, 0x20,\n    0x81, 0xb7, 0x30, 0x8f, 0x96, 0x88, 0x30, 0x30,\n    0x30, 0x30, 0x30, 0x30, 0x30, 0x86, 0x42, 0x25,\n    0x82, 0x98, 0x88, 0x34, 0x0c, 0x83, 0xd5, 0x1c,\n    0x80, 0xd9, 0x03, 0x84, 0xaa, 0x80, 0xdd, 0x90,\n    0x9f, 0xaf, 0x8f, 0x41, 0xff, 0x59, 0xbf, 0xbf,\n    0x60, 0x51, 0xfc, 0x82, 0x44, 0x8c, 0xc2, 0xad,\n    0x81, 0x41, 0x0c, 0x82, 0x8f, 0x89, 0x81, 0x93,\n    0xae, 0x8f, 0x9e, 0x81, 0xcf, 0xa6, 0x88, 0x81,\n    0xe6, 0x81, 0xb4, 0x81, 0x88, 0xa9, 0x8c, 0x02,\n    0x03, 0x80, 0x96, 0x9c, 0xb3, 0x8d, 0xb1, 0xbd,\n    0x2a, 0x00, 0x81, 0x8a, 0x9b, 0x89, 0x96, 0x98,\n    0x9c, 0x86, 0xae, 0x9b, 0x80, 0x8f, 0x20, 0x89,\n    0x89, 0x20, 0xa8, 0x96, 0x10, 0x87, 0x93, 0x96,\n    0x10, 0x82, 0xb1, 0x00, 0x11, 0x0c, 0x08, 0x00,\n    0x97, 0x11, 0x8a, 0x32, 0x8b, 0x29, 0x29, 0x85,\n    0x88, 0x30, 0x30, 0xaa, 0x80, 0x8d, 0x85, 0xf2,\n    0x9c, 0x60, 0x2b, 0xa3, 0x8b, 0x96, 0x83, 0xb0,\n    0x60, 0x21, 0x03, 0x41, 0x6d, 0x81, 0xe9, 0xa5,\n    0x86, 0x8b, 0x24, 0x00, 0x89, 0x80, 0x8c, 0x04,\n    0x00, 0x01, 0x01, 0x80, 0xeb, 0xa0, 0x41, 0x6a,\n    0x91, 0xbf, 0x81, 0xb5, 0xa7, 0x8b, 0xf3, 0x20,\n    0x40, 0x86, 0xa3, 0x99, 0x85, 0x99, 0x8a, 0xd8,\n    0x15, 0x0d, 0x0d, 0x0a, 0xa2, 0x8b, 0x80, 0x99,\n    0x80, 0x92, 0x01, 0x80, 0x8e, 0x81, 0x8d, 0xa1,\n    0xfa, 0xc4, 0xb4, 0x41, 0x0a, 0x9c, 0x82, 0xb0,\n    0xae, 0x9f, 0x8c, 0x9d, 0x84, 0xa5, 0x89, 0x9d,\n    0x81, 0xa3, 0x1f, 0x04, 0xa9, 0x40, 0x9d, 0x91,\n    0xa3, 0x83, 0xa3, 0x83, 0xa7, 0x87, 0xb3, 0x40,\n    0x9b, 0x41, 0x36, 0x88, 0x95, 0x89, 0x87, 0x40,\n    0x97, 0x29, 0x00, 0xab, 0x01, 0x10, 0x81, 0x96,\n    0x89, 0x96, 0x88, 0x9e, 0xc0, 0x92, 0x01, 0x89,\n    0x95, 0x89, 0x99, 0xc5, 0xb7, 0x29, 0xbf, 0x80,\n    0x8e, 0x18, 0x10, 0x9c, 0xa9, 0x9c, 0x82, 0x9c,\n    0xa2, 0x38, 0x9b, 0x9a, 0xb5, 0x89, 0x95, 0x89,\n    0x92, 0x8c, 0x91, 0xed, 0xc8, 0xb6, 0xb2, 0x8c,\n    0xb2, 0x8c, 0xa3, 0x41, 0x5b, 0xa9, 0x29, 0xcd,\n    0x9c, 0x89, 0x07, 0x95, 0xe9, 0x94, 0x9a, 0x96,\n    0x8b, 0xb4, 0xca, 0xac, 0x9f, 0x98, 0x99, 0xa3,\n    0x9c, 0x01, 0x07, 0xa2, 0x10, 0x8b, 0xaf, 0x8d,\n    0x83, 0x94, 0x00, 0x80, 0xa2, 0x91, 0x80, 0x98,\n    0xd3, 0x30, 0x00, 0x18, 0x8e, 0x80, 0x89, 0x86,\n    0xae, 0xa5, 0x39, 0x09, 0x95, 0x06, 0x01, 0x04,\n    0x10, 0x91, 0x80, 0x8b, 0x84, 0x40, 0x9d, 0xb4,\n    0x91, 0x83, 0x93, 0x82, 0x9d, 0xaf, 0x93, 0x08,\n    0x80, 0x40, 0xb7, 0xae, 0xa8, 0x83, 0xa3, 0xaf,\n    0x93, 0x80, 0xba, 0xaa, 0x8c, 0x80, 0xc6, 0x9a,\n    0x40, 0xe4, 0xab, 0xf3, 0xbf, 0x9e, 0x39, 0x01,\n    0x38, 0x08, 0x97, 0x8e, 0x00, 0x80, 0xdd, 0x39,\n    0xa6, 0x8f, 0x00, 0x80, 0x9b, 0x80, 0x89, 0xa7,\n    0x30, 0x94, 0x80, 0x8a, 0xad, 0x92, 0x80, 0xa1,\n    0xb8, 0x41, 0x06, 0x88, 0x80, 0xa4, 0x90, 0x80,\n    0xb0, 0x9d, 0xef, 0x30, 0x08, 0xa5, 0x94, 0x80,\n    0x98, 0x28, 0x08, 0x9f, 0x8d, 0x80, 0x41, 0x46,\n    0x92, 0x40, 0xbc, 0x80, 0xce, 0x43, 0x99, 0xe5,\n    0xee, 0x90, 0x40, 0xc3, 0x4a, 0xbb, 0x44, 0x2e,\n    0x4f, 0xd0, 0x42, 0x46, 0x60, 0x21, 0xb8, 0x42,\n    0x38, 0x86, 0x9e, 0xf0, 0x9d, 0x91, 0xaf, 0x8f,\n    0x83, 0x9e, 0x94, 0x84, 0x92, 0x42, 0xaf, 0xbf,\n    0xff, 0xca, 0x20, 0xc1, 0x8c, 0xbf, 0x08, 0x80,\n    0x9b, 0x57, 0xf7, 0x87, 0x44, 0xd5, 0xa9, 0x88,\n    0x60, 0x22, 0xf6, 0x41, 0x1e, 0xb0, 0x82, 0x90,\n    0x1f, 0x41, 0x8b, 0x49, 0x03, 0xea, 0x84, 0x8c,\n    0x82, 0x88, 0x86, 0x89, 0x57, 0x65, 0xd4, 0x80,\n    0xc6, 0x01, 0x08, 0x09, 0x0b, 0x80, 0x8b, 0x00,\n    0x06, 0x80, 0xc0, 0x03, 0x0f, 0x06, 0x80, 0x9b,\n    0x03, 0x04, 0x00, 0x16, 0x80, 0x41, 0x53, 0x81,\n    0x98, 0x80, 0x98, 0x80, 0x9e, 0x80, 0x98, 0x80,\n    0x9e, 0x80, 0x98, 0x80, 0x9e, 0x80, 0x98, 0x80,\n    0x9e, 0x80, 0x98, 0x07, 0x49, 0x33, 0xac, 0x89,\n    0x86, 0x8f, 0x80, 0x41, 0x70, 0xab, 0x45, 0x13,\n    0x40, 0xc4, 0xba, 0xc3, 0x30, 0x44, 0xb3, 0x18,\n    0x9a, 0x01, 0x00, 0x08, 0x80, 0x89, 0x03, 0x00,\n    0x00, 0x28, 0x18, 0x00, 0x00, 0x02, 0x01, 0x00,\n    0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b,\n    0x06, 0x03, 0x03, 0x00, 0x80, 0x89, 0x80, 0x90,\n    0x22, 0x04, 0x80, 0x90, 0x51, 0x43, 0x60, 0xa6,\n    0xdd, 0xa1, 0x50, 0x34, 0x8a, 0x40, 0xdd, 0x81,\n    0x56, 0x81, 0x8d, 0x5d, 0x30, 0x4c, 0x1e, 0x42,\n    0x1d, 0x45, 0xe1, 0x53, 0x4a,\n};\n\nstatic const uint8_t unicode_prop_ID_Start_index[99] = {\n    0xf6, 0x03, 0x20, 0xa6, 0x07, 0x00, 0xa9, 0x09,\n    0x00, 0xb4, 0x0a, 0x00, 0xba, 0x0b, 0x00, 0x3e,\n    0x0d, 0x00, 0xe0, 0x0e, 0x20, 0x57, 0x12, 0x00,\n    0xeb, 0x16, 0x00, 0xca, 0x19, 0x20, 0xc0, 0x1d,\n    0x60, 0x80, 0x20, 0x00, 0x2e, 0x2d, 0x00, 0xc0,\n    0x31, 0x20, 0x89, 0xa7, 0x20, 0xf0, 0xa9, 0x00,\n    0xe3, 0xab, 0x00, 0x3e, 0xfd, 0x00, 0xfb, 0x00,\n    0x21, 0x37, 0x07, 0x61, 0x01, 0x0a, 0x01, 0x1d,\n    0x0f, 0x21, 0x2c, 0x12, 0x01, 0xc8, 0x14, 0x21,\n    0xd1, 0x19, 0x21, 0x47, 0x1d, 0x01, 0x39, 0x6a,\n    0x21, 0x09, 0x8d, 0x01, 0xbc, 0xd4, 0x01, 0xa9,\n    0xd7, 0x21, 0x3a, 0xee, 0x01, 0xde, 0xa6, 0x22,\n    0x4b, 0x13, 0x03,\n};\n\nstatic const uint8_t unicode_prop_ID_Continue1_table[626] = {\n    0xaf, 0x89, 0xa4, 0x80, 0xd6, 0x80, 0x42, 0x47,\n    0xef, 0x96, 0x80, 0x40, 0xfa, 0x84, 0x41, 0x08,\n    0xac, 0x00, 0x01, 0x01, 0x00, 0xc7, 0x8a, 0xaf,\n    0x9e, 0x28, 0xe4, 0x31, 0x29, 0x08, 0x19, 0x89,\n    0x96, 0x80, 0x9d, 0x9a, 0xda, 0x8a, 0x8e, 0x89,\n    0xa0, 0x88, 0x88, 0x80, 0x97, 0x18, 0x88, 0x02,\n    0x04, 0xaa, 0x82, 0xf6, 0x8e, 0x80, 0xa0, 0xb5,\n    0x10, 0x91, 0x06, 0x89, 0x09, 0x89, 0x90, 0x82,\n    0xb7, 0x00, 0x31, 0x09, 0x82, 0x88, 0x80, 0x89,\n    0x09, 0x89, 0x8d, 0x01, 0x82, 0xb7, 0x00, 0x23,\n    0x09, 0x12, 0x80, 0x93, 0x8b, 0x10, 0x8a, 0x82,\n    0xb7, 0x00, 0x38, 0x10, 0x82, 0x93, 0x09, 0x89,\n    0x89, 0x28, 0x82, 0xb7, 0x00, 0x31, 0x09, 0x16,\n    0x82, 0x89, 0x09, 0x89, 0x91, 0x80, 0xba, 0x22,\n    0x10, 0x83, 0x88, 0x80, 0x8d, 0x89, 0x8f, 0x84,\n    0xb8, 0x30, 0x10, 0x1e, 0x81, 0x8a, 0x09, 0x89,\n    0x90, 0x82, 0xb7, 0x00, 0x30, 0x10, 0x1e, 0x81,\n    0x8a, 0x09, 0x89, 0x8f, 0x83, 0xb6, 0x08, 0x30,\n    0x10, 0x83, 0x88, 0x80, 0x89, 0x09, 0x89, 0x90,\n    0x82, 0xc5, 0x03, 0x28, 0x00, 0x3d, 0x89, 0x09,\n    0xbc, 0x01, 0x86, 0x8b, 0x38, 0x89, 0xd6, 0x01,\n    0x88, 0x8a, 0x29, 0x89, 0xbd, 0x0d, 0x89, 0x8a,\n    0x00, 0x00, 0x03, 0x81, 0xb0, 0x93, 0x01, 0x84,\n    0x8a, 0x80, 0xa3, 0x88, 0x80, 0xe3, 0x93, 0x80,\n    0x89, 0x8b, 0x1b, 0x10, 0x11, 0x32, 0x83, 0x8c,\n    0x8b, 0x80, 0x8e, 0x42, 0xbe, 0x82, 0x88, 0x88,\n    0x43, 0x9f, 0x82, 0x9c, 0x82, 0x9c, 0x81, 0x9d,\n    0x81, 0xbf, 0x9f, 0x88, 0x01, 0x89, 0xa0, 0x11,\n    0x89, 0x40, 0x8e, 0x80, 0xf5, 0x8b, 0x83, 0x8b,\n    0x89, 0x89, 0xff, 0x8a, 0xbb, 0x84, 0xb8, 0x89,\n    0x80, 0x9c, 0x81, 0x8a, 0x85, 0x89, 0x95, 0x8d,\n    0x01, 0xbe, 0x84, 0xae, 0x90, 0x8a, 0x89, 0x90,\n    0x88, 0x8b, 0x82, 0x9d, 0x8c, 0x81, 0x89, 0xab,\n    0x8d, 0xaf, 0x93, 0x87, 0x89, 0x85, 0x89, 0xf5,\n    0x10, 0x94, 0x18, 0x28, 0x0a, 0x40, 0xc5, 0xb9,\n    0x04, 0x42, 0x3e, 0x81, 0x92, 0x80, 0xfa, 0x8c,\n    0x18, 0x82, 0x8b, 0x4b, 0xfd, 0x82, 0x40, 0x8c,\n    0x80, 0xdf, 0x9f, 0x42, 0x29, 0x85, 0xe8, 0x81,\n    0x60, 0x75, 0x84, 0x89, 0xc4, 0x03, 0x89, 0x9f,\n    0x81, 0xcf, 0x81, 0x41, 0x0f, 0x02, 0x03, 0x80,\n    0x96, 0x23, 0x80, 0xd2, 0x81, 0xb1, 0x91, 0x89,\n    0x89, 0x85, 0x91, 0x8c, 0x8a, 0x9b, 0x87, 0x98,\n    0x8c, 0xab, 0x83, 0xae, 0x8d, 0x8e, 0x89, 0x8a,\n    0x80, 0x89, 0x89, 0xae, 0x8d, 0x8b, 0x07, 0x09,\n    0x89, 0xa0, 0x82, 0xb1, 0x00, 0x11, 0x0c, 0x08,\n    0x80, 0xa8, 0x24, 0x81, 0x40, 0xeb, 0x38, 0x09,\n    0x89, 0x60, 0x4f, 0x23, 0x80, 0x42, 0xe0, 0x8f,\n    0x8f, 0x8f, 0x11, 0x97, 0x82, 0x40, 0xbf, 0x89,\n    0xa4, 0x80, 0x42, 0xbc, 0x80, 0x40, 0xe1, 0x80,\n    0x40, 0x94, 0x84, 0x41, 0x24, 0x89, 0x45, 0x56,\n    0x10, 0x0c, 0x83, 0xa7, 0x13, 0x80, 0x40, 0xa4,\n    0x81, 0x42, 0x3c, 0x1f, 0x89, 0x41, 0x70, 0x81,\n    0x40, 0x98, 0x8a, 0x40, 0xae, 0x82, 0xb4, 0x8e,\n    0x9e, 0x89, 0x8e, 0x83, 0xac, 0x8a, 0xb4, 0x89,\n    0x2a, 0xa3, 0x8d, 0x80, 0x89, 0x21, 0xab, 0x80,\n    0x8b, 0x82, 0xaf, 0x8d, 0x3b, 0x80, 0x8b, 0xd1,\n    0x8b, 0x28, 0x40, 0x9f, 0x8b, 0x84, 0x89, 0x2b,\n    0xb6, 0x08, 0x31, 0x09, 0x82, 0x88, 0x80, 0x89,\n    0x09, 0x32, 0x84, 0x40, 0xbf, 0x91, 0x88, 0x89,\n    0x18, 0xd0, 0x93, 0x8b, 0x89, 0x40, 0xd4, 0x31,\n    0x88, 0x9a, 0x81, 0xd1, 0x90, 0x8e, 0x89, 0xd0,\n    0x8c, 0x87, 0x89, 0xd2, 0x8e, 0x83, 0x89, 0x40,\n    0xf1, 0x8e, 0x40, 0xa4, 0x89, 0xc5, 0x28, 0x09,\n    0x18, 0x00, 0x81, 0x8b, 0x89, 0xf6, 0x31, 0x32,\n    0x80, 0x9b, 0x89, 0xa7, 0x30, 0x1f, 0x80, 0x88,\n    0x8a, 0xad, 0x8f, 0x41, 0x94, 0x38, 0x87, 0x8f,\n    0x89, 0xb7, 0x95, 0x80, 0x8d, 0xf9, 0x2a, 0x00,\n    0x08, 0x30, 0x07, 0x89, 0xaf, 0x20, 0x08, 0x27,\n    0x89, 0x41, 0x48, 0x83, 0x60, 0x4b, 0x68, 0x89,\n    0x40, 0x85, 0x84, 0xba, 0x86, 0x98, 0x89, 0x43,\n    0xf4, 0x00, 0xb6, 0x33, 0xd0, 0x80, 0x8a, 0x81,\n    0x60, 0x4c, 0xaa, 0x81, 0x54, 0xc5, 0x22, 0x2f,\n    0x39, 0x86, 0x9d, 0x83, 0x40, 0x93, 0x82, 0x45,\n    0x88, 0xb1, 0x41, 0xff, 0xb6, 0x83, 0xb1, 0x38,\n    0x8d, 0x80, 0x95, 0x20, 0x8e, 0x45, 0x4f, 0x30,\n    0x90, 0x0e, 0x01, 0x04, 0x41, 0x04, 0x86, 0x88,\n    0x89, 0x41, 0xa1, 0x8d, 0x45, 0xd5, 0x86, 0xec,\n    0x34, 0x89, 0x52, 0x95, 0x89, 0x6c, 0x05, 0x05,\n    0x40, 0xef,\n};\n\nstatic const uint8_t unicode_prop_ID_Continue1_index[60] = {\n    0xfa, 0x06, 0x00, 0x84, 0x09, 0x00, 0xf0, 0x0a,\n    0x00, 0x70, 0x0c, 0x00, 0xf4, 0x0d, 0x00, 0x4a,\n    0x10, 0x20, 0x1a, 0x18, 0x20, 0x74, 0x1b, 0x20,\n    0xdd, 0x20, 0x00, 0x0c, 0xa8, 0x00, 0x5a, 0xaa,\n    0x20, 0x1a, 0xff, 0x00, 0xad, 0x0e, 0x01, 0x38,\n    0x12, 0x21, 0xc1, 0x15, 0x21, 0xe5, 0x19, 0x21,\n    0xaa, 0x1d, 0x21, 0x8c, 0xd1, 0x41, 0x4a, 0xe1,\n    0x21, 0xf0, 0x01, 0x0e,\n};\n\n#ifdef CONFIG_ALL_UNICODE\n\nstatic const uint8_t unicode_cc_table[851] = {\n    0xb2, 0xcf, 0xd4, 0x00, 0xe8, 0x03, 0xdc, 0x00,\n    0xe8, 0x00, 0xd8, 0x04, 0xdc, 0x01, 0xca, 0x03,\n    0xdc, 0x01, 0xca, 0x0a, 0xdc, 0x04, 0x01, 0x03,\n    0xdc, 0xc7, 0x00, 0xf0, 0xc0, 0x02, 0xdc, 0xc2,\n    0x01, 0xdc, 0x80, 0xc2, 0x03, 0xdc, 0xc0, 0x00,\n    0xe8, 0x01, 0xdc, 0xc0, 0x41, 0xe9, 0x00, 0xea,\n    0x41, 0xe9, 0x00, 0xea, 0x00, 0xe9, 0xcc, 0xb0,\n    0xe2, 0xc4, 0xb0, 0xd8, 0x00, 0xdc, 0xc3, 0x00,\n    0xdc, 0xc2, 0x00, 0xde, 0x00, 0xdc, 0xc5, 0x05,\n    0xdc, 0xc1, 0x00, 0xdc, 0xc1, 0x00, 0xde, 0x00,\n    0xe4, 0xc0, 0x49, 0x0a, 0x43, 0x13, 0x80, 0x00,\n    0x17, 0x80, 0x41, 0x18, 0x80, 0xc0, 0x00, 0xdc,\n    0x80, 0x00, 0x12, 0xb0, 0x17, 0xc7, 0x42, 0x1e,\n    0xaf, 0x47, 0x1b, 0xc1, 0x01, 0xdc, 0xc4, 0x00,\n    0xdc, 0xc1, 0x00, 0xdc, 0x8f, 0x00, 0x23, 0xb0,\n    0x34, 0xc6, 0x81, 0xc3, 0x00, 0xdc, 0xc0, 0x81,\n    0xc1, 0x80, 0x00, 0xdc, 0xc1, 0x00, 0xdc, 0xa2,\n    0x00, 0x24, 0x9d, 0xc0, 0x00, 0xdc, 0xc1, 0x00,\n    0xdc, 0xc1, 0x02, 0xdc, 0xc0, 0x01, 0xdc, 0xc0,\n    0x00, 0xdc, 0xc2, 0x00, 0xdc, 0xc0, 0x00, 0xdc,\n    0xc0, 0x00, 0xdc, 0xc0, 0x00, 0xdc, 0xc1, 0xb0,\n    0x6f, 0xc6, 0x00, 0xdc, 0xc0, 0x88, 0x00, 0xdc,\n    0x97, 0xc3, 0x80, 0xc8, 0x80, 0xc2, 0x80, 0xc4,\n    0xaa, 0x02, 0xdc, 0xb0, 0x46, 0x00, 0xdc, 0xcd,\n    0x80, 0x00, 0xdc, 0xc1, 0x00, 0xdc, 0xc1, 0x00,\n    0xdc, 0xc2, 0x02, 0xdc, 0x42, 0x1b, 0xc2, 0x00,\n    0xdc, 0xc1, 0x01, 0xdc, 0xc4, 0xb0, 0x0b, 0x00,\n    0x07, 0x8f, 0x00, 0x09, 0x82, 0xc0, 0x00, 0xdc,\n    0xc1, 0xb0, 0x36, 0x00, 0x07, 0x8f, 0x00, 0x09,\n    0xaf, 0xc0, 0xb0, 0x0c, 0x00, 0x07, 0x8f, 0x00,\n    0x09, 0xb0, 0x3d, 0x00, 0x07, 0x8f, 0x00, 0x09,\n    0xb0, 0x3d, 0x00, 0x07, 0x8f, 0x00, 0x09, 0xb0,\n    0x4e, 0x00, 0x09, 0xb0, 0x4e, 0x00, 0x09, 0x86,\n    0x00, 0x54, 0x00, 0x5b, 0xb0, 0x34, 0x00, 0x07,\n    0x8f, 0x00, 0x09, 0xb0, 0x3c, 0x01, 0x09, 0x8f,\n    0x00, 0x09, 0xb0, 0x4b, 0x00, 0x09, 0xb0, 0x3c,\n    0x01, 0x67, 0x00, 0x09, 0x8c, 0x03, 0x6b, 0xb0,\n    0x3b, 0x01, 0x76, 0x00, 0x09, 0x8c, 0x03, 0x7a,\n    0xb0, 0x1b, 0x01, 0xdc, 0x9a, 0x00, 0xdc, 0x80,\n    0x00, 0xdc, 0x80, 0x00, 0xd8, 0xb0, 0x06, 0x41,\n    0x81, 0x80, 0x00, 0x84, 0x84, 0x03, 0x82, 0x81,\n    0x00, 0x82, 0x80, 0xc1, 0x00, 0x09, 0x80, 0xc1,\n    0xb0, 0x0d, 0x00, 0xdc, 0xb0, 0x3f, 0x00, 0x07,\n    0x80, 0x01, 0x09, 0xb0, 0x21, 0x00, 0xdc, 0xb2,\n    0x9e, 0xc2, 0xb3, 0x83, 0x00, 0x09, 0x9e, 0x00,\n    0x09, 0xb0, 0x6c, 0x00, 0x09, 0x89, 0xc0, 0xb0,\n    0x9a, 0x00, 0xe4, 0xb0, 0x5e, 0x00, 0xde, 0xc0,\n    0x00, 0xdc, 0xb0, 0xaa, 0xc0, 0x00, 0xdc, 0xb0,\n    0x16, 0x00, 0x09, 0x93, 0xc7, 0x81, 0x00, 0xdc,\n    0xaf, 0xc4, 0x05, 0xdc, 0xc1, 0x00, 0xdc, 0x80,\n    0x01, 0xdc, 0xb0, 0x42, 0x00, 0x07, 0x8e, 0x00,\n    0x09, 0xa5, 0xc0, 0x00, 0xdc, 0xc6, 0xb0, 0x05,\n    0x01, 0x09, 0xb0, 0x09, 0x00, 0x07, 0x8a, 0x01,\n    0x09, 0xb0, 0x12, 0x00, 0x07, 0xb0, 0x67, 0xc2,\n    0x41, 0x00, 0x04, 0xdc, 0xc1, 0x03, 0xdc, 0xc0,\n    0x41, 0x00, 0x05, 0x01, 0x83, 0x00, 0xdc, 0x85,\n    0xc0, 0x82, 0xc1, 0xb0, 0x95, 0xc1, 0x00, 0xdc,\n    0xc6, 0x00, 0xdc, 0xc1, 0x00, 0xea, 0x00, 0xd6,\n    0x00, 0xdc, 0x00, 0xca, 0xe4, 0x00, 0xe8, 0x01,\n    0xe4, 0x00, 0xdc, 0x80, 0xc0, 0x00, 0xe9, 0x00,\n    0xdc, 0xc0, 0x00, 0xdc, 0xb2, 0x9f, 0xc1, 0x01,\n    0x01, 0xc3, 0x02, 0x01, 0xc1, 0x83, 0xc0, 0x82,\n    0x01, 0x01, 0xc0, 0x00, 0xdc, 0xc0, 0x01, 0x01,\n    0x03, 0xdc, 0xc0, 0xb8, 0x03, 0xcd, 0xc2, 0xb0,\n    0x5c, 0x00, 0x09, 0xb0, 0x2f, 0xdf, 0xb1, 0xf9,\n    0x00, 0xda, 0x00, 0xe4, 0x00, 0xe8, 0x00, 0xde,\n    0x01, 0xe0, 0xb0, 0x38, 0x01, 0x08, 0xb8, 0x6d,\n    0xa3, 0xc0, 0x83, 0xc9, 0x9f, 0xc1, 0xb0, 0x1f,\n    0xc1, 0xb0, 0xe3, 0x00, 0x09, 0xa4, 0x00, 0x09,\n    0xb0, 0x66, 0x00, 0x09, 0x9a, 0xd1, 0xb0, 0x08,\n    0x02, 0xdc, 0xa4, 0x00, 0x09, 0xb0, 0x2e, 0x00,\n    0x07, 0x8b, 0x00, 0x09, 0xb0, 0xbe, 0xc0, 0x80,\n    0xc1, 0x00, 0xdc, 0x81, 0xc1, 0x84, 0xc1, 0x80,\n    0xc0, 0xb0, 0x03, 0x00, 0x09, 0xb0, 0xc5, 0x00,\n    0x09, 0xb8, 0x46, 0xff, 0x00, 0x1a, 0xb2, 0xd0,\n    0xc6, 0x06, 0xdc, 0xc1, 0xb3, 0x9c, 0x00, 0xdc,\n    0xb0, 0xb1, 0x00, 0xdc, 0xb0, 0x64, 0xc4, 0xb6,\n    0x61, 0x00, 0xdc, 0x80, 0xc0, 0xa7, 0xc0, 0x00,\n    0x01, 0x00, 0xdc, 0x83, 0x00, 0x09, 0xb0, 0x74,\n    0xc0, 0x00, 0xdc, 0xb2, 0x0c, 0xc3, 0xb1, 0x52,\n    0xc1, 0xb0, 0x68, 0x01, 0xdc, 0xc2, 0x00, 0xdc,\n    0xc0, 0x03, 0xdc, 0xb0, 0xc4, 0x00, 0x09, 0xb0,\n    0x07, 0x00, 0x09, 0xb0, 0x08, 0x00, 0x09, 0x00,\n    0x07, 0xb0, 0x14, 0xc2, 0xaf, 0x01, 0x09, 0xb0,\n    0x0d, 0x00, 0x07, 0xb0, 0x1b, 0x00, 0x09, 0x88,\n    0x00, 0x07, 0xb0, 0x39, 0x00, 0x09, 0x00, 0x07,\n    0xb0, 0x81, 0x00, 0x07, 0x00, 0x09, 0xb0, 0x1f,\n    0x01, 0x07, 0x8f, 0x00, 0x09, 0x97, 0xc6, 0x82,\n    0xc4, 0xb0, 0x9c, 0x00, 0x09, 0x82, 0x00, 0x07,\n    0x96, 0xc0, 0xb0, 0x32, 0x00, 0x09, 0x00, 0x07,\n    0xb0, 0xca, 0x00, 0x09, 0x00, 0x07, 0xb0, 0x4d,\n    0x00, 0x09, 0xb0, 0x45, 0x00, 0x09, 0x00, 0x07,\n    0xb0, 0x42, 0x00, 0x09, 0xb0, 0xdc, 0x00, 0x09,\n    0x00, 0x07, 0xb0, 0xd1, 0x01, 0x09, 0x83, 0x00,\n    0x07, 0xb0, 0x6b, 0x00, 0x09, 0xb0, 0x22, 0x00,\n    0x09, 0x91, 0x00, 0x09, 0xb0, 0x20, 0x00, 0x09,\n    0xb1, 0x74, 0x00, 0x09, 0xb0, 0xd1, 0x00, 0x07,\n    0x80, 0x01, 0x09, 0xb0, 0x20, 0x00, 0x09, 0xb8,\n    0x45, 0x27, 0x04, 0x01, 0xb0, 0x0a, 0xc6, 0xb4,\n    0x88, 0x01, 0x06, 0xb8, 0x44, 0x7b, 0x00, 0x01,\n    0xb8, 0x0c, 0x95, 0x01, 0xd8, 0x02, 0x01, 0x82,\n    0x00, 0xe2, 0x04, 0xd8, 0x87, 0x07, 0xdc, 0x81,\n    0xc4, 0x01, 0xdc, 0x9d, 0xc3, 0xb0, 0x63, 0xc2,\n    0xb8, 0x05, 0x8a, 0xc6, 0x80, 0xd0, 0x81, 0xc6,\n    0x80, 0xc1, 0x80, 0xc4, 0xb0, 0xd4, 0xc6, 0xb1,\n    0x84, 0xc3, 0xb5, 0xaf, 0x06, 0xdc, 0xb0, 0x3c,\n    0xc5, 0x00, 0x07,\n};\n\nstatic const uint8_t unicode_cc_index[81] = {\n    0x4d, 0x03, 0x00, 0x97, 0x05, 0x20, 0xc6, 0x05,\n    0x00, 0xe7, 0x06, 0x00, 0x45, 0x07, 0x00, 0xe2,\n    0x08, 0x00, 0x53, 0x09, 0x00, 0xcd, 0x0b, 0x20,\n    0x38, 0x0e, 0x00, 0x73, 0x0f, 0x20, 0x5d, 0x13,\n    0x20, 0x60, 0x1a, 0x20, 0xaa, 0x1b, 0x00, 0xf4,\n    0x1c, 0x00, 0xfe, 0x1d, 0x20, 0x7f, 0x2d, 0x20,\n    0xf0, 0xa6, 0x00, 0xb2, 0xaa, 0x00, 0xfe, 0x01,\n    0x01, 0xab, 0x0e, 0x01, 0x73, 0x11, 0x21, 0x70,\n    0x13, 0x01, 0xb8, 0x16, 0x01, 0x9a, 0x1a, 0x01,\n    0x9f, 0xbc, 0x01, 0x22, 0xe0, 0x01, 0x4b, 0xe9,\n    0x01,\n};\n\nstatic const uint32_t unicode_decomp_table1[690] = {\n    0x00280081, 0x002a0097, 0x002a8081, 0x002bc097,\n    0x002c8115, 0x002d0097, 0x002d4081, 0x002e0097,\n    0x002e4115, 0x002f0199, 0x00302016, 0x00400842,\n    0x00448a42, 0x004a0442, 0x004c0096, 0x004c8117,\n    0x004d0242, 0x004e4342, 0x004fc12f, 0x0050c342,\n    0x005240bf, 0x00530342, 0x00550942, 0x005a0842,\n    0x005e0096, 0x005e4342, 0x005fc081, 0x00680142,\n    0x006bc142, 0x00710185, 0x0071c317, 0x00734844,\n    0x00778344, 0x00798342, 0x007b02be, 0x007c4197,\n    0x007d0142, 0x007e0444, 0x00800e42, 0x00878142,\n    0x00898744, 0x00ac0483, 0x00b60317, 0x00b80283,\n    0x00d00214, 0x00d10096, 0x00dd0080, 0x00de8097,\n    0x00df8080, 0x00e10097, 0x00e1413e, 0x00e1c080,\n    0x00e204be, 0x00ea83ae, 0x00f282ae, 0x00f401ad,\n    0x00f4c12e, 0x00f54103, 0x00fc0303, 0x00fe4081,\n    0x0100023e, 0x0101c0be, 0x010301be, 0x010640be,\n    0x010e40be, 0x0114023e, 0x0115c0be, 0x011701be,\n    0x011d8144, 0x01304144, 0x01340244, 0x01358144,\n    0x01368344, 0x01388344, 0x013a8644, 0x013e0144,\n    0x0161c085, 0x018882ae, 0x019d422f, 0x01b00184,\n    0x01b4c084, 0x024a4084, 0x024c4084, 0x024d0084,\n    0x0256042e, 0x0272c12e, 0x02770120, 0x0277c084,\n    0x028cc084, 0x028d8084, 0x029641ae, 0x02978084,\n    0x02d20084, 0x02d2c12e, 0x02d70120, 0x02e50084,\n    0x02f281ae, 0x03120084, 0x03300084, 0x0331c122,\n    0x0332812e, 0x035281ae, 0x03768084, 0x037701ae,\n    0x038cc085, 0x03acc085, 0x03b7012f, 0x03c30081,\n    0x03d0c084, 0x03d34084, 0x03d48084, 0x03d5c084,\n    0x03d70084, 0x03da4084, 0x03dcc084, 0x03dd412e,\n    0x03ddc085, 0x03de0084, 0x03de4085, 0x03e04084,\n    0x03e4c084, 0x03e74084, 0x03e88084, 0x03e9c084,\n    0x03eb0084, 0x03ee4084, 0x04098084, 0x043f0081,\n    0x06c18484, 0x06c48084, 0x06cec184, 0x06d00120,\n    0x06d0c084, 0x074b0383, 0x074cc41f, 0x074f1783,\n    0x075e0081, 0x0766d283, 0x07801d44, 0x078e8942,\n    0x07931844, 0x079f0d42, 0x07a58216, 0x07a68085,\n    0x07a6c0be, 0x07a80d44, 0x07aea044, 0x07c00122,\n    0x07c08344, 0x07c20122, 0x07c28344, 0x07c40122,\n    0x07c48244, 0x07c60122, 0x07c68244, 0x07c8113e,\n    0x07d08244, 0x07d20122, 0x07d28244, 0x07d40122,\n    0x07d48344, 0x07d64c3e, 0x07dc4080, 0x07dc80be,\n    0x07dcc080, 0x07dd00be, 0x07dd4080, 0x07dd80be,\n    0x07ddc080, 0x07de00be, 0x07de4080, 0x07de80be,\n    0x07dec080, 0x07df00be, 0x07df4080, 0x07e00820,\n    0x07e40820, 0x07e80820, 0x07ec05be, 0x07eec080,\n    0x07ef00be, 0x07ef4097, 0x07ef8080, 0x07efc117,\n    0x07f0443e, 0x07f24080, 0x07f280be, 0x07f2c080,\n    0x07f303be, 0x07f4c080, 0x07f582ae, 0x07f6c080,\n    0x07f7433e, 0x07f8c080, 0x07f903ae, 0x07fac080,\n    0x07fb013e, 0x07fb8102, 0x07fc83be, 0x07fe4080,\n    0x07fe80be, 0x07fec080, 0x07ff00be, 0x07ff4080,\n    0x07ff8097, 0x0800011e, 0x08008495, 0x08044081,\n    0x0805c097, 0x08090081, 0x08094097, 0x08098099,\n    0x080bc081, 0x080cc085, 0x080d00b1, 0x080d8085,\n    0x080dc0b1, 0x080f0197, 0x0811c197, 0x0815c0b3,\n    0x0817c081, 0x081c0595, 0x081ec081, 0x081f0215,\n    0x0820051f, 0x08228583, 0x08254415, 0x082a0097,\n    0x08400119, 0x08408081, 0x0840c0bf, 0x08414119,\n    0x0841c081, 0x084240bf, 0x0842852d, 0x08454081,\n    0x08458097, 0x08464295, 0x08480097, 0x08484099,\n    0x08488097, 0x08490081, 0x08498080, 0x084a0081,\n    0x084a8102, 0x084b0495, 0x084d421f, 0x084e4081,\n    0x084ec099, 0x084f0283, 0x08514295, 0x08540119,\n    0x0854809b, 0x0854c619, 0x0857c097, 0x08580081,\n    0x08584097, 0x08588099, 0x0858c097, 0x08590081,\n    0x08594097, 0x08598099, 0x0859c09b, 0x085a0097,\n    0x085a4081, 0x085a8097, 0x085ac099, 0x085b0295,\n    0x085c4097, 0x085c8099, 0x085cc097, 0x085d0081,\n    0x085d4097, 0x085d8099, 0x085dc09b, 0x085e0097,\n    0x085e4081, 0x085e8097, 0x085ec099, 0x085f0215,\n    0x08624099, 0x0866813e, 0x086b80be, 0x087341be,\n    0x088100be, 0x088240be, 0x088300be, 0x088901be,\n    0x088b0085, 0x088b40b1, 0x088bc085, 0x088c00b1,\n    0x089040be, 0x089100be, 0x0891c1be, 0x089801be,\n    0x089b42be, 0x089d0144, 0x089e0144, 0x08a00144,\n    0x08a10144, 0x08a20144, 0x08ab023e, 0x08b80244,\n    0x08ba8220, 0x08ca411e, 0x0918049f, 0x091a4523,\n    0x091cc097, 0x091d04a5, 0x091f452b, 0x0921c09b,\n    0x092204a1, 0x09244525, 0x0926c099, 0x09270d25,\n    0x092d8d1f, 0x09340d1f, 0x093a8081, 0x0a8300b3,\n    0x0a9d0099, 0x0a9d4097, 0x0a9d8099, 0x0ab700be,\n    0x0b1f0115, 0x0b5bc081, 0x0ba7c081, 0x0bbcc081,\n    0x0bc004ad, 0x0bc244ad, 0x0bc484ad, 0x0bc6f383,\n    0x0be0852d, 0x0be31d03, 0x0bf1882d, 0x0c000081,\n    0x0c0d8283, 0x0c130b84, 0x0c194284, 0x0c1c0122,\n    0x0c1cc122, 0x0c1d8122, 0x0c1e4122, 0x0c1f0122,\n    0x0c250084, 0x0c26c123, 0x0c278084, 0x0c27c085,\n    0x0c2b0b84, 0x0c314284, 0x0c340122, 0x0c34c122,\n    0x0c358122, 0x0c364122, 0x0c370122, 0x0c3d0084,\n    0x0c3dc220, 0x0c3f8084, 0x0c3fc085, 0x0c4c4a2d,\n    0x0c51451f, 0x0c53ca9f, 0x0c5915ad, 0x0c648703,\n    0x0c800741, 0x0c838089, 0x0c83c129, 0x0c8441a9,\n    0x0c850089, 0x0c854129, 0x0c85c2a9, 0x0c870089,\n    0x0c87408f, 0x0c87808d, 0x0c881241, 0x0c910203,\n    0x0c940099, 0x0c9444a3, 0x0c968323, 0x0c98072d,\n    0x0c9b84af, 0x0c9dc2a1, 0x0c9f00b5, 0x0c9f40b3,\n    0x0c9f8085, 0x0ca01883, 0x0cac4223, 0x0cad4523,\n    0x0cafc097, 0x0cb004a1, 0x0cb241a5, 0x0cb30097,\n    0x0cb34099, 0x0cb38097, 0x0cb3c099, 0x0cb417ad,\n    0x0cbfc085, 0x0cc001b3, 0x0cc0c0b1, 0x0cc100b3,\n    0x0cc14131, 0x0cc1c0b5, 0x0cc200b3, 0x0cc241b1,\n    0x0cc30133, 0x0cc38131, 0x0cc40085, 0x0cc440b1,\n    0x0cc48133, 0x0cc50085, 0x0cc540b5, 0x0cc580b7,\n    0x0cc5c0b5, 0x0cc600b1, 0x0cc64135, 0x0cc6c0b3,\n    0x0cc701b1, 0x0cc7c0b3, 0x0cc800b5, 0x0cc840b3,\n    0x0cc881b1, 0x0cc9422f, 0x0cca4131, 0x0ccac0b5,\n    0x0ccb00b1, 0x0ccb40b3, 0x0ccb80b5, 0x0ccbc0b1,\n    0x0ccc012f, 0x0ccc80b5, 0x0cccc0b3, 0x0ccd00b5,\n    0x0ccd40b1, 0x0ccd80b5, 0x0ccdc085, 0x0cce02b1,\n    0x0ccf40b3, 0x0ccf80b1, 0x0ccfc085, 0x0cd001b1,\n    0x0cd0c0b3, 0x0cd101b1, 0x0cd1c0b5, 0x0cd200b3,\n    0x0cd24085, 0x0cd280b5, 0x0cd2c085, 0x0cd30133,\n    0x0cd381b1, 0x0cd440b3, 0x0cd48085, 0x0cd4c0b1,\n    0x0cd500b3, 0x0cd54085, 0x0cd580b5, 0x0cd5c0b1,\n    0x0cd60521, 0x0cd88525, 0x0cdb02a5, 0x0cdc4099,\n    0x0cdc8117, 0x0cdd0099, 0x0cdd4197, 0x0cde0127,\n    0x0cde8285, 0x0cdfc089, 0x0ce0043f, 0x0ce20099,\n    0x0ce2409b, 0x0ce283bf, 0x0ce44219, 0x0ce54205,\n    0x0ce6433f, 0x0ce7c131, 0x0ce84085, 0x0ce881b1,\n    0x0ce94085, 0x0ce98107, 0x0cea0089, 0x0cea4097,\n    0x0cea8219, 0x0ceb809d, 0x0cebc08d, 0x0cec083f,\n    0x0cf00105, 0x0cf0809b, 0x0cf0c197, 0x0cf1809b,\n    0x0cf1c099, 0x0cf20517, 0x0cf48099, 0x0cf4c117,\n    0x0cf54119, 0x0cf5c097, 0x0cf6009b, 0x0cf64099,\n    0x0cf68217, 0x0cf78119, 0x0cf804a1, 0x0cfa4525,\n    0x0cfcc525, 0x0cff4125, 0x0cffc099, 0x29a70103,\n    0x29dc0081, 0x29fe0103, 0x2ad70203, 0x2ada4081,\n    0x3e401482, 0x3e4a7f82, 0x3e6a3f82, 0x3e8aa102,\n    0x3e9b0110, 0x3e9c2f82, 0x3eb3c590, 0x3ec00197,\n    0x3ec0c119, 0x3ec1413f, 0x3ec4c2af, 0x3ec74184,\n    0x3ec804ad, 0x3eca4081, 0x3eca8304, 0x3ecc03a0,\n    0x3ece02a0, 0x3ecf8084, 0x3ed00120, 0x3ed0c120,\n    0x3ed184ae, 0x3ed3c085, 0x3ed4312d, 0x3ef4cbad,\n    0x3efa892f, 0x3eff022d, 0x3f002f2f, 0x3f1782a5,\n    0x3f18c0b1, 0x3f1907af, 0x3f1cffaf, 0x3f3c81a5,\n    0x3f3d64af, 0x3f542031, 0x3f649b31, 0x3f7c0131,\n    0x3f7c83b3, 0x3f7e40b1, 0x3f7e80bd, 0x3f7ec0bb,\n    0x3f7f00b3, 0x3f840503, 0x3f8c01ad, 0x3f8cc315,\n    0x3f8e462d, 0x3f91cc03, 0x3f97c695, 0x3f9c01af,\n    0x3f9d0085, 0x3f9d852f, 0x3fa03aad, 0x3fbd442f,\n    0x3fc06f1f, 0x3fd7c11f, 0x3fd85fad, 0x3fe80081,\n    0x3fe84f1f, 0x3ff0831f, 0x3ff2831f, 0x3ff4831f,\n    0x3ff6819f, 0x3ff80783, 0x44268192, 0x442ac092,\n    0x444b8112, 0x44d2c112, 0x452ec212, 0x456e8112,\n    0x464e0092, 0x74578392, 0x746ec312, 0x75000d1f,\n    0x75068d1f, 0x750d0d1f, 0x7513839f, 0x7515891f,\n    0x751a0d1f, 0x75208d1f, 0x75271015, 0x752f439f,\n    0x7531459f, 0x75340d1f, 0x753a8d1f, 0x75410395,\n    0x7543441f, 0x7545839f, 0x75478d1f, 0x754e0795,\n    0x7552839f, 0x75548d1f, 0x755b0d1f, 0x75618d1f,\n    0x75680d1f, 0x756e8d1f, 0x75750d1f, 0x757b8d1f,\n    0x75820d1f, 0x75888d1f, 0x758f0d1f, 0x75958d1f,\n    0x759c0d1f, 0x75a28d1f, 0x75a90103, 0x75aa089f,\n    0x75ae4081, 0x75ae839f, 0x75b04081, 0x75b08c9f,\n    0x75b6c081, 0x75b7032d, 0x75b8889f, 0x75bcc081,\n    0x75bd039f, 0x75bec081, 0x75bf0c9f, 0x75c54081,\n    0x75c5832d, 0x75c7089f, 0x75cb4081, 0x75cb839f,\n    0x75cd4081, 0x75cd8c9f, 0x75d3c081, 0x75d4032d,\n    0x75d5889f, 0x75d9c081, 0x75da039f, 0x75dbc081,\n    0x75dc0c9f, 0x75e24081, 0x75e2832d, 0x75e4089f,\n    0x75e84081, 0x75e8839f, 0x75ea4081, 0x75ea8c9f,\n    0x75f0c081, 0x75f1042d, 0x75f3851f, 0x75f6051f,\n    0x75f8851f, 0x75fb051f, 0x75fd851f, 0x7b80022d,\n    0x7b814dad, 0x7b884203, 0x7b89c081, 0x7b8a452d,\n    0x7b8d0403, 0x7b908081, 0x7b91dc03, 0x7ba0052d,\n    0x7ba2c8ad, 0x7ba84483, 0x7baac8ad, 0x7c400097,\n    0x7c404521, 0x7c440d25, 0x7c4a8087, 0x7c4ac115,\n    0x7c4b4117, 0x7c4c0d1f, 0x7c528217, 0x7c538099,\n    0x7c53c097, 0x7c5a8197, 0x7c640097, 0x7c80012f,\n    0x7c808081, 0x7c841603, 0x7c9004c1, 0x7c940103,\n    0x7efc051f, 0xbe0001ac, 0xbe00d110, 0xbe0947ac,\n    0xbe0d3910, 0xbe29872c, 0xbe2d022c, 0xbe2e3790,\n    0xbe49ff90, 0xbe69bc10,\n};\n\nstatic const uint16_t unicode_decomp_table2[690] = {\n    0x0020, 0x0000, 0x0061, 0x0002, 0x0004, 0x0006, 0x03bc, 0x0008,\n    0x000a, 0x000c, 0x0015, 0x0095, 0x00a5, 0x00b9, 0x00c1, 0x00c3,\n    0x00c7, 0x00cb, 0x00d1, 0x00d7, 0x00dd, 0x00e0, 0x00e6, 0x00f8,\n    0x0108, 0x010a, 0x0073, 0x0110, 0x0112, 0x0114, 0x0120, 0x012c,\n    0x0144, 0x014d, 0x0153, 0x0162, 0x0168, 0x016a, 0x0176, 0x0192,\n    0x0194, 0x01a9, 0x01bb, 0x01c7, 0x01d1, 0x01d5, 0x02b9, 0x01d7,\n    0x003b, 0x01d9, 0x01db, 0x00b7, 0x01e1, 0x01fc, 0x020c, 0x0218,\n    0x021d, 0x0223, 0x0227, 0x03a3, 0x0233, 0x023f, 0x0242, 0x024b,\n    0x024e, 0x0251, 0x025d, 0x0260, 0x0269, 0x026c, 0x026f, 0x0275,\n    0x0278, 0x0281, 0x028a, 0x029c, 0x029f, 0x02a3, 0x02af, 0x02b9,\n    0x02c5, 0x02c9, 0x02cd, 0x02d1, 0x02d5, 0x02e7, 0x02ed, 0x02f1,\n    0x02f5, 0x02f9, 0x02fd, 0x0305, 0x0309, 0x030d, 0x0313, 0x0317,\n    0x031b, 0x0323, 0x0327, 0x032b, 0x032f, 0x0335, 0x033d, 0x0341,\n    0x0349, 0x034d, 0x0351, 0x0f0b, 0x0357, 0x035b, 0x035f, 0x0363,\n    0x0367, 0x036b, 0x036f, 0x0373, 0x0379, 0x037d, 0x0381, 0x0385,\n    0x0389, 0x038d, 0x0391, 0x0395, 0x0399, 0x039d, 0x03a1, 0x10dc,\n    0x03a5, 0x03c9, 0x03cd, 0x03d9, 0x03dd, 0x03e1, 0x03ef, 0x03f1,\n    0x043d, 0x044f, 0x0499, 0x04f0, 0x0502, 0x054a, 0x0564, 0x056c,\n    0x0570, 0x0573, 0x059a, 0x05fa, 0x05fe, 0x0607, 0x060b, 0x0614,\n    0x0618, 0x061e, 0x0622, 0x0628, 0x068e, 0x0694, 0x0698, 0x069e,\n    0x06a2, 0x06ab, 0x03ac, 0x06f3, 0x03ad, 0x06f6, 0x03ae, 0x06f9,\n    0x03af, 0x06fc, 0x03cc, 0x06ff, 0x03cd, 0x0702, 0x03ce, 0x0705,\n    0x0709, 0x070d, 0x0711, 0x0386, 0x0732, 0x0735, 0x03b9, 0x0737,\n    0x073b, 0x0388, 0x0753, 0x0389, 0x0756, 0x0390, 0x076b, 0x038a,\n    0x0777, 0x03b0, 0x0789, 0x038e, 0x0799, 0x079f, 0x07a3, 0x038c,\n    0x07b8, 0x038f, 0x07bb, 0x00b4, 0x07be, 0x07c0, 0x07c2, 0x2010,\n    0x07cb, 0x002e, 0x07cd, 0x07cf, 0x0020, 0x07d2, 0x07d6, 0x07db,\n    0x07df, 0x07e4, 0x07ea, 0x07f0, 0x0020, 0x07f6, 0x2212, 0x0801,\n    0x0805, 0x0807, 0x081d, 0x0825, 0x0827, 0x0043, 0x082d, 0x0830,\n    0x0190, 0x0836, 0x0839, 0x004e, 0x0845, 0x0847, 0x084c, 0x084e,\n    0x0851, 0x005a, 0x03a9, 0x005a, 0x0853, 0x0857, 0x0860, 0x0069,\n    0x0862, 0x0865, 0x086f, 0x0874, 0x087a, 0x087e, 0x08a2, 0x0049,\n    0x08a4, 0x08a6, 0x08a9, 0x0056, 0x08ab, 0x08ad, 0x08b0, 0x08b4,\n    0x0058, 0x08b6, 0x08b8, 0x08bb, 0x08c0, 0x08c2, 0x08c5, 0x0076,\n    0x08c7, 0x08c9, 0x08cc, 0x08d0, 0x0078, 0x08d2, 0x08d4, 0x08d7,\n    0x08db, 0x08de, 0x08e4, 0x08e7, 0x08f0, 0x08f3, 0x08f6, 0x08f9,\n    0x0902, 0x0906, 0x090b, 0x090f, 0x0914, 0x0917, 0x091a, 0x0923,\n    0x092c, 0x093b, 0x093e, 0x0941, 0x0944, 0x0947, 0x094a, 0x0956,\n    0x095c, 0x0960, 0x0962, 0x0964, 0x0968, 0x096a, 0x0970, 0x0978,\n    0x097c, 0x0980, 0x0986, 0x0989, 0x098f, 0x0991, 0x0030, 0x0993,\n    0x0999, 0x099c, 0x099e, 0x09a1, 0x09a4, 0x2d61, 0x6bcd, 0x9f9f,\n    0x09a6, 0x09b1, 0x09bc, 0x09c7, 0x0a95, 0x0aa1, 0x0b15, 0x0020,\n    0x0b27, 0x0b31, 0x0b8d, 0x0ba1, 0x0ba5, 0x0ba9, 0x0bad, 0x0bb1,\n    0x0bb5, 0x0bb9, 0x0bbd, 0x0bc1, 0x0bc5, 0x0c21, 0x0c35, 0x0c39,\n    0x0c3d, 0x0c41, 0x0c45, 0x0c49, 0x0c4d, 0x0c51, 0x0c55, 0x0c59,\n    0x0c6f, 0x0c71, 0x0c73, 0x0ca0, 0x0cbc, 0x0cdc, 0x0ce4, 0x0cec,\n    0x0cf4, 0x0cfc, 0x0d04, 0x0d0c, 0x0d14, 0x0d22, 0x0d2e, 0x0d7a,\n    0x0d82, 0x0d85, 0x0d89, 0x0d8d, 0x0d9d, 0x0db1, 0x0db5, 0x0dbc,\n    0x0dc2, 0x0dc6, 0x0e28, 0x0e2c, 0x0e30, 0x0e32, 0x0e36, 0x0e3c,\n    0x0e3e, 0x0e41, 0x0e43, 0x0e46, 0x0e77, 0x0e7b, 0x0e89, 0x0e8e,\n    0x0e94, 0x0e9c, 0x0ea3, 0x0ea9, 0x0eb4, 0x0ebe, 0x0ec6, 0x0eca,\n    0x0ecf, 0x0ed9, 0x0edd, 0x0ee4, 0x0eec, 0x0ef3, 0x0ef8, 0x0f04,\n    0x0f0a, 0x0f15, 0x0f1b, 0x0f22, 0x0f28, 0x0f33, 0x0f3d, 0x0f45,\n    0x0f4c, 0x0f51, 0x0f57, 0x0f5e, 0x0f63, 0x0f69, 0x0f70, 0x0f76,\n    0x0f7d, 0x0f82, 0x0f89, 0x0f8d, 0x0f9e, 0x0fa4, 0x0fa9, 0x0fad,\n    0x0fb8, 0x0fbe, 0x0fc9, 0x0fd0, 0x0fd6, 0x0fda, 0x0fe1, 0x0fe5,\n    0x0fef, 0x0ffa, 0x1000, 0x1004, 0x1009, 0x100f, 0x1013, 0x101a,\n    0x101f, 0x1023, 0x1029, 0x102f, 0x1032, 0x1036, 0x1039, 0x103f,\n    0x1045, 0x1059, 0x1061, 0x1079, 0x107c, 0x1080, 0x1095, 0x10a1,\n    0x10b1, 0x10c3, 0x10cb, 0x10cf, 0x10da, 0x10de, 0x10ea, 0x10f2,\n    0x10f4, 0x1100, 0x1105, 0x1111, 0x1141, 0x1149, 0x114d, 0x1153,\n    0x1157, 0x115a, 0x116e, 0x1171, 0x1175, 0x117b, 0x117d, 0x1181,\n    0x1184, 0x118c, 0x1192, 0x1196, 0x119c, 0x11a2, 0x11a8, 0x11ab,\n    0xa76f, 0x11af, 0x11b3, 0x028d, 0x11bb, 0x120d, 0x130b, 0x1409,\n    0x148d, 0x1492, 0x1550, 0x1569, 0x156f, 0x1575, 0x157b, 0x1587,\n    0x1593, 0x002b, 0x159e, 0x15b6, 0x15ba, 0x15be, 0x15c2, 0x15c6,\n    0x15ca, 0x15de, 0x15e2, 0x1646, 0x165f, 0x1685, 0x168b, 0x1749,\n    0x174f, 0x1754, 0x1774, 0x1874, 0x187a, 0x190e, 0x19d0, 0x1a74,\n    0x1a7c, 0x1a9a, 0x1a9f, 0x1ab3, 0x1abd, 0x1ac3, 0x1ad7, 0x1adc,\n    0x1ae2, 0x1af0, 0x1b20, 0x1b2d, 0x1b35, 0x1b39, 0x1b4f, 0x1bc6,\n    0x1bd8, 0x1bda, 0x1bdc, 0x3164, 0x1c1d, 0x1c1f, 0x1c21, 0x1c23,\n    0x1c25, 0x1c27, 0x1c45, 0x1c53, 0x1c58, 0x1c61, 0x1c6a, 0x1c7c,\n    0x1c85, 0x1c8a, 0x1caa, 0x1cc5, 0x1cc7, 0x1cc9, 0x1ccb, 0x1ccd,\n    0x1ccf, 0x1cd1, 0x1cd3, 0x1cf3, 0x1cf5, 0x1cf7, 0x1cf9, 0x1cfb,\n    0x1d02, 0x1d04, 0x1d06, 0x1d08, 0x1d17, 0x1d19, 0x1d1b, 0x1d1d,\n    0x1d1f, 0x1d21, 0x1d23, 0x1d25, 0x1d27, 0x1d29, 0x1d2b, 0x1d2d,\n    0x1d2f, 0x1d31, 0x1d33, 0x1d37, 0x03f4, 0x1d39, 0x2207, 0x1d3b,\n    0x2202, 0x1d3d, 0x1d45, 0x03f4, 0x1d47, 0x2207, 0x1d49, 0x2202,\n    0x1d4b, 0x1d53, 0x03f4, 0x1d55, 0x2207, 0x1d57, 0x2202, 0x1d59,\n    0x1d61, 0x03f4, 0x1d63, 0x2207, 0x1d65, 0x2202, 0x1d67, 0x1d6f,\n    0x03f4, 0x1d71, 0x2207, 0x1d73, 0x2202, 0x1d75, 0x1d7f, 0x1d81,\n    0x1d83, 0x1d85, 0x1d87, 0x1d89, 0x1d8f, 0x1dac, 0x062d, 0x1db4,\n    0x1dc0, 0x062c, 0x1dd0, 0x1e40, 0x1e4c, 0x1e5f, 0x1e71, 0x1e84,\n    0x1e86, 0x1e8a, 0x1e90, 0x1e96, 0x1e98, 0x1e9c, 0x1e9e, 0x1ea6,\n    0x1ea9, 0x1eab, 0x1eb1, 0x1eb3, 0x30b5, 0x1eb9, 0x1f11, 0x1f27,\n    0x1f2b, 0x1f2d, 0x1f32, 0x1f7f, 0x1f90, 0x2091, 0x20a1, 0x20a7,\n    0x21a1, 0x22bf,\n};\n\nstatic const uint8_t unicode_decomp_data[9165] = {\n    0x20, 0x88, 0x20, 0x84, 0x32, 0x33, 0x20, 0x81,\n    0x20, 0xa7, 0x31, 0x6f, 0x31, 0xd0, 0x34, 0x31,\n    0xd0, 0x32, 0x33, 0xd0, 0x34, 0x41, 0x80, 0x41,\n    0x81, 0x41, 0x82, 0x41, 0x83, 0x41, 0x88, 0x41,\n    0x8a, 0x00, 0x00, 0x43, 0xa7, 0x45, 0x80, 0x45,\n    0x81, 0x45, 0x82, 0x45, 0x88, 0x49, 0x80, 0x49,\n    0x81, 0x49, 0x82, 0x49, 0x88, 0x00, 0x00, 0x4e,\n    0x83, 0x4f, 0x80, 0x4f, 0x81, 0x4f, 0x82, 0x4f,\n    0x83, 0x4f, 0x88, 0x00, 0x00, 0x00, 0x00, 0x55,\n    0x80, 0x55, 0x81, 0x55, 0x82, 0x55, 0x88, 0x59,\n    0x81, 0x00, 0x00, 0x00, 0x00, 0x61, 0x80, 0x61,\n    0x81, 0x61, 0x82, 0x61, 0x83, 0x61, 0x88, 0x61,\n    0x8a, 0x00, 0x00, 0x63, 0xa7, 0x65, 0x80, 0x65,\n    0x81, 0x65, 0x82, 0x65, 0x88, 0x69, 0x80, 0x69,\n    0x81, 0x69, 0x82, 0x69, 0x88, 0x00, 0x00, 0x6e,\n    0x83, 0x6f, 0x80, 0x6f, 0x81, 0x6f, 0x82, 0x6f,\n    0x83, 0x6f, 0x88, 0x00, 0x00, 0x00, 0x00, 0x75,\n    0x80, 0x75, 0x81, 0x75, 0x82, 0x75, 0x88, 0x79,\n    0x81, 0x00, 0x00, 0x79, 0x88, 0x41, 0x84, 0x41,\n    0x86, 0x41, 0xa8, 0x43, 0x81, 0x43, 0x82, 0x43,\n    0x87, 0x43, 0x8c, 0x44, 0x8c, 0x45, 0x84, 0x45,\n    0x86, 0x45, 0x87, 0x45, 0xa8, 0x45, 0x8c, 0x47,\n    0x82, 0x47, 0x86, 0x47, 0x87, 0x47, 0xa7, 0x48,\n    0x82, 0x49, 0x83, 0x49, 0x84, 0x49, 0x86, 0x49,\n    0xa8, 0x49, 0x87, 0x49, 0x4a, 0x69, 0x6a, 0x4a,\n    0x82, 0x4b, 0xa7, 0x4c, 0x81, 0x4c, 0xa7, 0x4c,\n    0x8c, 0x4c, 0x00, 0x00, 0x6b, 0x20, 0x6b, 0x4e,\n    0x81, 0x4e, 0xa7, 0x4e, 0x8c, 0xbc, 0x02, 0x6e,\n    0x4f, 0x84, 0x4f, 0x86, 0x4f, 0x8b, 0x52, 0x81,\n    0x52, 0xa7, 0x52, 0x8c, 0x53, 0x81, 0x53, 0x82,\n    0x53, 0xa7, 0x53, 0x8c, 0x54, 0xa7, 0x54, 0x8c,\n    0x55, 0x83, 0x55, 0x84, 0x55, 0x86, 0x55, 0x8a,\n    0x55, 0x8b, 0x55, 0xa8, 0x57, 0x82, 0x59, 0x82,\n    0x59, 0x88, 0x5a, 0x81, 0x5a, 0x87, 0x5a, 0x8c,\n    0x4f, 0x9b, 0x55, 0x9b, 0x44, 0x00, 0x7d, 0x01,\n    0x44, 0x00, 0x7e, 0x01, 0x64, 0x00, 0x7e, 0x01,\n    0x4c, 0x4a, 0x4c, 0x6a, 0x6c, 0x6a, 0x4e, 0x4a,\n    0x4e, 0x6a, 0x6e, 0x6a, 0x41, 0x00, 0x8c, 0x49,\n    0x00, 0x8c, 0x4f, 0x00, 0x8c, 0x55, 0x00, 0x8c,\n    0xdc, 0x00, 0x84, 0xdc, 0x00, 0x81, 0xdc, 0x00,\n    0x8c, 0xdc, 0x00, 0x80, 0xc4, 0x00, 0x84, 0x26,\n    0x02, 0x84, 0xc6, 0x00, 0x84, 0x47, 0x8c, 0x4b,\n    0x8c, 0x4f, 0xa8, 0xea, 0x01, 0x84, 0xeb, 0x01,\n    0x84, 0xb7, 0x01, 0x8c, 0x92, 0x02, 0x8c, 0x6a,\n    0x00, 0x8c, 0x44, 0x5a, 0x44, 0x7a, 0x64, 0x7a,\n    0x47, 0x81, 0x4e, 0x00, 0x80, 0xc5, 0x00, 0x81,\n    0xc6, 0x00, 0x81, 0xd8, 0x00, 0x81, 0x41, 0x8f,\n    0x41, 0x91, 0x45, 0x8f, 0x45, 0x91, 0x49, 0x8f,\n    0x49, 0x91, 0x4f, 0x8f, 0x4f, 0x91, 0x52, 0x8f,\n    0x52, 0x91, 0x55, 0x8f, 0x55, 0x91, 0x53, 0xa6,\n    0x54, 0xa6, 0x48, 0x8c, 0x41, 0x00, 0x87, 0x45,\n    0x00, 0xa7, 0xd6, 0x00, 0x84, 0xd5, 0x00, 0x84,\n    0x4f, 0x00, 0x87, 0x2e, 0x02, 0x84, 0x59, 0x00,\n    0x84, 0x68, 0x00, 0x66, 0x02, 0x6a, 0x00, 0x72,\n    0x00, 0x79, 0x02, 0x7b, 0x02, 0x81, 0x02, 0x77,\n    0x00, 0x79, 0x00, 0x20, 0x86, 0x20, 0x87, 0x20,\n    0x8a, 0x20, 0xa8, 0x20, 0x83, 0x20, 0x8b, 0x63,\n    0x02, 0x6c, 0x00, 0x73, 0x00, 0x78, 0x00, 0x95,\n    0x02, 0x80, 0x81, 0x00, 0x93, 0x88, 0x81, 0x20,\n    0xc5, 0x20, 0x81, 0xa8, 0x00, 0x81, 0x91, 0x03,\n    0x81, 0x95, 0x03, 0x81, 0x97, 0x03, 0x81, 0x99,\n    0x03, 0x81, 0x00, 0x00, 0x00, 0x9f, 0x03, 0x81,\n    0x00, 0x00, 0x00, 0xa5, 0x03, 0x81, 0xa9, 0x03,\n    0x81, 0xca, 0x03, 0x81, 0x01, 0x03, 0x98, 0x07,\n    0xa4, 0x07, 0xb0, 0x00, 0xb4, 0x00, 0xb6, 0x00,\n    0xb8, 0x00, 0xca, 0x00, 0x01, 0x03, 0xb8, 0x07,\n    0xc4, 0x07, 0xbe, 0x00, 0xc4, 0x00, 0xc8, 0x00,\n    0xa5, 0x03, 0x0d, 0x13, 0x00, 0x01, 0x03, 0xd1,\n    0x00, 0xd1, 0x07, 0xc6, 0x03, 0xc0, 0x03, 0xba,\n    0x03, 0xc1, 0x03, 0xc2, 0x03, 0x00, 0x00, 0x98,\n    0x03, 0xb5, 0x03, 0x15, 0x04, 0x80, 0x15, 0x04,\n    0x88, 0x00, 0x00, 0x00, 0x13, 0x04, 0x81, 0x06,\n    0x04, 0x88, 0x1a, 0x04, 0x81, 0x18, 0x04, 0x80,\n    0x23, 0x04, 0x86, 0x18, 0x04, 0x86, 0x38, 0x04,\n    0x86, 0x35, 0x04, 0x80, 0x35, 0x04, 0x88, 0x00,\n    0x00, 0x00, 0x33, 0x04, 0x81, 0x56, 0x04, 0x88,\n    0x3a, 0x04, 0x81, 0x38, 0x04, 0x80, 0x43, 0x04,\n    0x86, 0x74, 0x04, 0x8f, 0x16, 0x04, 0x86, 0x10,\n    0x04, 0x86, 0x10, 0x04, 0x88, 0x15, 0x04, 0x86,\n    0xd8, 0x04, 0x88, 0x16, 0x04, 0x88, 0x17, 0x04,\n    0x88, 0x18, 0x04, 0x84, 0x18, 0x04, 0x88, 0x1e,\n    0x04, 0x88, 0xe8, 0x04, 0x88, 0x2d, 0x04, 0x88,\n    0x23, 0x04, 0x84, 0x23, 0x04, 0x88, 0x23, 0x04,\n    0x8b, 0x27, 0x04, 0x88, 0x2b, 0x04, 0x88, 0x65,\n    0x05, 0x82, 0x05, 0x27, 0x06, 0x00, 0x2c, 0x00,\n    0x2d, 0x21, 0x2d, 0x00, 0x2e, 0x23, 0x2d, 0x27,\n    0x06, 0x00, 0x4d, 0x21, 0x4d, 0xa0, 0x4d, 0x23,\n    0x4d, 0xd5, 0x06, 0x54, 0x06, 0x00, 0x00, 0x00,\n    0x00, 0xc1, 0x06, 0x54, 0x06, 0xd2, 0x06, 0x54,\n    0x06, 0x28, 0x09, 0x3c, 0x09, 0x30, 0x09, 0x3c,\n    0x09, 0x33, 0x09, 0x3c, 0x09, 0x15, 0x09, 0x00,\n    0x27, 0x01, 0x27, 0x02, 0x27, 0x07, 0x27, 0x0c,\n    0x27, 0x0d, 0x27, 0x16, 0x27, 0x1a, 0x27, 0xbe,\n    0x09, 0x09, 0x00, 0x09, 0x19, 0xa1, 0x09, 0xbc,\n    0x09, 0xaf, 0x09, 0xbc, 0x09, 0x32, 0x0a, 0x3c,\n    0x0a, 0x38, 0x0a, 0x3c, 0x0a, 0x16, 0x0a, 0x00,\n    0x26, 0x01, 0x26, 0x06, 0x26, 0x2b, 0x0a, 0x3c,\n    0x0a, 0x47, 0x0b, 0x56, 0x0b, 0x3e, 0x0b, 0x09,\n    0x00, 0x09, 0x19, 0x21, 0x0b, 0x3c, 0x0b, 0x92,\n    0x0b, 0xd7, 0x0b, 0xbe, 0x0b, 0x08, 0x00, 0x09,\n    0x00, 0x08, 0x19, 0x46, 0x0c, 0x56, 0x0c, 0xbf,\n    0x0c, 0xd5, 0x0c, 0xc6, 0x0c, 0xd5, 0x0c, 0xc2,\n    0x0c, 0x04, 0x00, 0x08, 0x13, 0x3e, 0x0d, 0x08,\n    0x00, 0x09, 0x00, 0x08, 0x19, 0xd9, 0x0d, 0xca,\n    0x0d, 0xca, 0x0d, 0x0f, 0x05, 0x12, 0x00, 0x0f,\n    0x15, 0x4d, 0x0e, 0x32, 0x0e, 0xcd, 0x0e, 0xb2,\n    0x0e, 0x99, 0x0e, 0x12, 0x00, 0x12, 0x08, 0x42,\n    0x0f, 0xb7, 0x0f, 0x4c, 0x0f, 0xb7, 0x0f, 0x51,\n    0x0f, 0xb7, 0x0f, 0x56, 0x0f, 0xb7, 0x0f, 0x5b,\n    0x0f, 0xb7, 0x0f, 0x40, 0x0f, 0xb5, 0x0f, 0x71,\n    0x0f, 0x72, 0x0f, 0x71, 0x0f, 0x00, 0x03, 0x41,\n    0x0f, 0xb2, 0x0f, 0x81, 0x0f, 0xb3, 0x0f, 0x80,\n    0x0f, 0xb3, 0x0f, 0x81, 0x0f, 0x71, 0x0f, 0x80,\n    0x0f, 0x92, 0x0f, 0xb7, 0x0f, 0x9c, 0x0f, 0xb7,\n    0x0f, 0xa1, 0x0f, 0xb7, 0x0f, 0xa6, 0x0f, 0xb7,\n    0x0f, 0xab, 0x0f, 0xb7, 0x0f, 0x90, 0x0f, 0xb5,\n    0x0f, 0x25, 0x10, 0x2e, 0x10, 0x05, 0x1b, 0x35,\n    0x1b, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1b, 0x35,\n    0x1b, 0x00, 0x00, 0x00, 0x00, 0x09, 0x1b, 0x35,\n    0x1b, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x1b, 0x35,\n    0x1b, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x1b, 0x35,\n    0x1b, 0x11, 0x1b, 0x35, 0x1b, 0x3a, 0x1b, 0x35,\n    0x1b, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x1b, 0x35,\n    0x1b, 0x3e, 0x1b, 0x35, 0x1b, 0x42, 0x1b, 0x35,\n    0x1b, 0x41, 0x00, 0xc6, 0x00, 0x42, 0x00, 0x00,\n    0x00, 0x44, 0x00, 0x45, 0x00, 0x8e, 0x01, 0x47,\n    0x00, 0x4f, 0x00, 0x22, 0x02, 0x50, 0x00, 0x52,\n    0x00, 0x54, 0x00, 0x55, 0x00, 0x57, 0x00, 0x61,\n    0x00, 0x50, 0x02, 0x51, 0x02, 0x02, 0x1d, 0x62,\n    0x00, 0x64, 0x00, 0x65, 0x00, 0x59, 0x02, 0x5b,\n    0x02, 0x5c, 0x02, 0x67, 0x00, 0x00, 0x00, 0x6b,\n    0x00, 0x6d, 0x00, 0x4b, 0x01, 0x6f, 0x00, 0x54,\n    0x02, 0x16, 0x1d, 0x17, 0x1d, 0x70, 0x00, 0x74,\n    0x00, 0x75, 0x00, 0x1d, 0x1d, 0x6f, 0x02, 0x76,\n    0x00, 0x25, 0x1d, 0xb2, 0x03, 0xb3, 0x03, 0xb4,\n    0x03, 0xc6, 0x03, 0xc7, 0x03, 0x69, 0x00, 0x72,\n    0x00, 0x75, 0x00, 0x76, 0x00, 0xb2, 0x03, 0xb3,\n    0x03, 0xc1, 0x03, 0xc6, 0x03, 0xc7, 0x03, 0x52,\n    0x02, 0x63, 0x00, 0x55, 0x02, 0xf0, 0x00, 0x5c,\n    0x02, 0x66, 0x00, 0x5f, 0x02, 0x61, 0x02, 0x65,\n    0x02, 0x68, 0x02, 0x69, 0x02, 0x6a, 0x02, 0x7b,\n    0x1d, 0x9d, 0x02, 0x6d, 0x02, 0x85, 0x1d, 0x9f,\n    0x02, 0x71, 0x02, 0x70, 0x02, 0x72, 0x02, 0x73,\n    0x02, 0x74, 0x02, 0x75, 0x02, 0x78, 0x02, 0x82,\n    0x02, 0x83, 0x02, 0xab, 0x01, 0x89, 0x02, 0x8a,\n    0x02, 0x1c, 0x1d, 0x8b, 0x02, 0x8c, 0x02, 0x7a,\n    0x00, 0x90, 0x02, 0x91, 0x02, 0x92, 0x02, 0xb8,\n    0x03, 0x41, 0x00, 0xa5, 0x42, 0x00, 0x87, 0x42,\n    0x00, 0xa3, 0x42, 0x00, 0xb1, 0xc7, 0x00, 0x81,\n    0x44, 0x00, 0x87, 0x44, 0x00, 0xa3, 0x44, 0x00,\n    0xb1, 0x44, 0x00, 0xa7, 0x44, 0x00, 0xad, 0x12,\n    0x01, 0x80, 0x12, 0x01, 0x81, 0x45, 0x00, 0xad,\n    0x45, 0x00, 0xb0, 0x28, 0x02, 0x86, 0x46, 0x00,\n    0x87, 0x47, 0x00, 0x84, 0x48, 0x00, 0x87, 0x48,\n    0x00, 0xa3, 0x48, 0x00, 0x88, 0x48, 0x00, 0xa7,\n    0x48, 0x00, 0xae, 0x49, 0x00, 0xb0, 0xcf, 0x00,\n    0x81, 0x4b, 0x00, 0x81, 0x4b, 0x00, 0xa3, 0x4b,\n    0x00, 0xb1, 0x4c, 0x00, 0xa3, 0x36, 0x1e, 0x84,\n    0x4c, 0xb1, 0x4c, 0xad, 0x4d, 0x81, 0x4d, 0x87,\n    0x4d, 0xa3, 0x4e, 0x87, 0x4e, 0xa3, 0x4e, 0xb1,\n    0x4e, 0xad, 0xd5, 0x00, 0x81, 0xd5, 0x00, 0x88,\n    0x4c, 0x01, 0x80, 0x4c, 0x01, 0x81, 0x50, 0x00,\n    0x81, 0x50, 0x00, 0x87, 0x52, 0x00, 0x87, 0x52,\n    0x00, 0xa3, 0x5a, 0x1e, 0x84, 0x52, 0x00, 0xb1,\n    0x53, 0x00, 0x87, 0x53, 0x00, 0xa3, 0x5a, 0x01,\n    0x87, 0x60, 0x01, 0x87, 0x62, 0x1e, 0x87, 0x54,\n    0x00, 0x87, 0x54, 0x00, 0xa3, 0x54, 0x00, 0xb1,\n    0x54, 0x00, 0xad, 0x55, 0x00, 0xa4, 0x55, 0x00,\n    0xb0, 0x55, 0x00, 0xad, 0x68, 0x01, 0x81, 0x6a,\n    0x01, 0x88, 0x56, 0x83, 0x56, 0xa3, 0x57, 0x80,\n    0x57, 0x81, 0x57, 0x88, 0x57, 0x87, 0x57, 0xa3,\n    0x58, 0x87, 0x58, 0x88, 0x59, 0x87, 0x5a, 0x82,\n    0x5a, 0xa3, 0x5a, 0xb1, 0x68, 0xb1, 0x74, 0x88,\n    0x77, 0x8a, 0x79, 0x8a, 0x61, 0x00, 0xbe, 0x02,\n    0x7f, 0x01, 0x87, 0x41, 0x00, 0xa3, 0x41, 0x00,\n    0x89, 0xc2, 0x00, 0x81, 0xc2, 0x00, 0x80, 0xc2,\n    0x00, 0x89, 0xc2, 0x00, 0x83, 0xa0, 0x1e, 0x82,\n    0x02, 0x01, 0x81, 0x02, 0x01, 0x80, 0x02, 0x01,\n    0x89, 0x02, 0x01, 0x83, 0xa0, 0x1e, 0x86, 0x45,\n    0x00, 0xa3, 0x45, 0x00, 0x89, 0x45, 0x00, 0x83,\n    0xca, 0x00, 0x81, 0xca, 0x00, 0x80, 0xca, 0x00,\n    0x89, 0xca, 0x00, 0x83, 0xb8, 0x1e, 0x82, 0x49,\n    0x00, 0x89, 0x49, 0x00, 0xa3, 0x4f, 0x00, 0xa3,\n    0x4f, 0x00, 0x89, 0xd4, 0x00, 0x81, 0xd4, 0x00,\n    0x80, 0xd4, 0x00, 0x89, 0xd4, 0x00, 0x83, 0xcc,\n    0x1e, 0x82, 0xa0, 0x01, 0x81, 0xa0, 0x01, 0x80,\n    0xa0, 0x01, 0x89, 0xa0, 0x01, 0x83, 0xa0, 0x01,\n    0xa3, 0x55, 0x00, 0xa3, 0x55, 0x00, 0x89, 0xaf,\n    0x01, 0x81, 0xaf, 0x01, 0x80, 0xaf, 0x01, 0x89,\n    0xaf, 0x01, 0x83, 0xaf, 0x01, 0xa3, 0x59, 0x00,\n    0x80, 0x59, 0x00, 0xa3, 0x59, 0x00, 0x89, 0x59,\n    0x00, 0x83, 0xb1, 0x03, 0x13, 0x03, 0x00, 0x1f,\n    0x80, 0x00, 0x1f, 0x81, 0x00, 0x1f, 0xc2, 0x91,\n    0x03, 0x13, 0x03, 0x08, 0x1f, 0x80, 0x08, 0x1f,\n    0x81, 0x08, 0x1f, 0xc2, 0xb5, 0x03, 0x13, 0x03,\n    0x10, 0x1f, 0x80, 0x10, 0x1f, 0x81, 0x95, 0x03,\n    0x13, 0x03, 0x18, 0x1f, 0x80, 0x18, 0x1f, 0x81,\n    0xb7, 0x03, 0x93, 0xb7, 0x03, 0x94, 0x20, 0x1f,\n    0x80, 0x21, 0x1f, 0x80, 0x20, 0x1f, 0x81, 0x21,\n    0x1f, 0x81, 0x20, 0x1f, 0xc2, 0x21, 0x1f, 0xc2,\n    0x97, 0x03, 0x93, 0x97, 0x03, 0x94, 0x28, 0x1f,\n    0x80, 0x29, 0x1f, 0x80, 0x28, 0x1f, 0x81, 0x29,\n    0x1f, 0x81, 0x28, 0x1f, 0xc2, 0x29, 0x1f, 0xc2,\n    0xb9, 0x03, 0x93, 0xb9, 0x03, 0x94, 0x30, 0x1f,\n    0x80, 0x31, 0x1f, 0x80, 0x30, 0x1f, 0x81, 0x31,\n    0x1f, 0x81, 0x30, 0x1f, 0xc2, 0x31, 0x1f, 0xc2,\n    0x99, 0x03, 0x93, 0x99, 0x03, 0x94, 0x38, 0x1f,\n    0x80, 0x39, 0x1f, 0x80, 0x38, 0x1f, 0x81, 0x39,\n    0x1f, 0x81, 0x38, 0x1f, 0xc2, 0x39, 0x1f, 0xc2,\n    0xbf, 0x03, 0x93, 0xbf, 0x03, 0x94, 0x40, 0x1f,\n    0x80, 0x40, 0x1f, 0x81, 0x9f, 0x03, 0x13, 0x03,\n    0x48, 0x1f, 0x80, 0x48, 0x1f, 0x81, 0xc5, 0x03,\n    0x13, 0x03, 0x50, 0x1f, 0x80, 0x50, 0x1f, 0x81,\n    0x50, 0x1f, 0xc2, 0xa5, 0x03, 0x94, 0x00, 0x00,\n    0x00, 0x59, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x59,\n    0x1f, 0x81, 0x00, 0x00, 0x00, 0x59, 0x1f, 0xc2,\n    0xc9, 0x03, 0x93, 0xc9, 0x03, 0x94, 0x60, 0x1f,\n    0x80, 0x61, 0x1f, 0x80, 0x60, 0x1f, 0x81, 0x61,\n    0x1f, 0x81, 0x60, 0x1f, 0xc2, 0x61, 0x1f, 0xc2,\n    0xa9, 0x03, 0x93, 0xa9, 0x03, 0x94, 0x68, 0x1f,\n    0x80, 0x69, 0x1f, 0x80, 0x68, 0x1f, 0x81, 0x69,\n    0x1f, 0x81, 0x68, 0x1f, 0xc2, 0x69, 0x1f, 0xc2,\n    0xb1, 0x03, 0x80, 0xb5, 0x03, 0x80, 0xb7, 0x03,\n    0x80, 0xb9, 0x03, 0x80, 0xbf, 0x03, 0x80, 0xc5,\n    0x03, 0x80, 0xc9, 0x03, 0x80, 0x00, 0x1f, 0x45,\n    0x03, 0x20, 0x1f, 0x45, 0x03, 0x60, 0x1f, 0x45,\n    0x03, 0xb1, 0x03, 0x86, 0xb1, 0x03, 0x84, 0x70,\n    0x1f, 0xc5, 0xb1, 0x03, 0xc5, 0xac, 0x03, 0xc5,\n    0x00, 0x00, 0x00, 0xb1, 0x03, 0xc2, 0xb6, 0x1f,\n    0xc5, 0x91, 0x03, 0x86, 0x91, 0x03, 0x84, 0x91,\n    0x03, 0x80, 0x91, 0x03, 0xc5, 0x20, 0x93, 0x20,\n    0x93, 0x20, 0xc2, 0xa8, 0x00, 0xc2, 0x74, 0x1f,\n    0xc5, 0xb7, 0x03, 0xc5, 0xae, 0x03, 0xc5, 0x00,\n    0x00, 0x00, 0xb7, 0x03, 0xc2, 0xc6, 0x1f, 0xc5,\n    0x95, 0x03, 0x80, 0x97, 0x03, 0x80, 0x97, 0x03,\n    0xc5, 0xbf, 0x1f, 0x80, 0xbf, 0x1f, 0x81, 0xbf,\n    0x1f, 0xc2, 0xb9, 0x03, 0x86, 0xb9, 0x03, 0x84,\n    0xca, 0x03, 0x80, 0x00, 0x03, 0xb9, 0x42, 0xca,\n    0x42, 0x99, 0x06, 0x99, 0x04, 0x99, 0x00, 0xfe,\n    0x1f, 0x80, 0xfe, 0x1f, 0x81, 0xfe, 0x1f, 0xc2,\n    0xc5, 0x03, 0x86, 0xc5, 0x03, 0x84, 0xcb, 0x03,\n    0x80, 0x00, 0x03, 0xc1, 0x13, 0xc1, 0x14, 0xc5,\n    0x42, 0xcb, 0x42, 0xa5, 0x06, 0xa5, 0x04, 0xa5,\n    0x00, 0xa1, 0x03, 0x94, 0xa8, 0x00, 0x80, 0x85,\n    0x03, 0x60, 0x00, 0x7c, 0x1f, 0xc5, 0xc9, 0x03,\n    0xc5, 0xce, 0x03, 0xc5, 0x00, 0x00, 0x00, 0xc9,\n    0x03, 0xc2, 0xf6, 0x1f, 0xc5, 0x9f, 0x03, 0x80,\n    0xa9, 0x03, 0x80, 0xa9, 0x03, 0xc5, 0x20, 0x94,\n    0x02, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,\n    0x20, 0x20, 0x20, 0x20, 0xb3, 0x2e, 0x2e, 0x2e,\n    0x2e, 0x2e, 0x32, 0x20, 0x32, 0x20, 0x32, 0x20,\n    0x00, 0x00, 0x00, 0x35, 0x20, 0x35, 0x20, 0x35,\n    0x20, 0x00, 0x00, 0x00, 0x21, 0x21, 0x00, 0x00,\n    0x20, 0x85, 0x3f, 0x3f, 0x3f, 0x21, 0x21, 0x3f,\n    0x32, 0x20, 0x00, 0x00, 0x00, 0x00, 0x30, 0x69,\n    0x00, 0x00, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,\n    0x2b, 0x3d, 0x28, 0x29, 0x6e, 0x30, 0x00, 0x2b,\n    0x00, 0x12, 0x22, 0x3d, 0x00, 0x28, 0x00, 0x29,\n    0x00, 0x00, 0x00, 0x61, 0x00, 0x65, 0x00, 0x6f,\n    0x00, 0x78, 0x00, 0x59, 0x02, 0x68, 0x6b, 0x6c,\n    0x6d, 0x6e, 0x70, 0x73, 0x74, 0x52, 0x73, 0x61,\n    0x2f, 0x63, 0x61, 0x2f, 0x73, 0xb0, 0x00, 0x43,\n    0x63, 0x2f, 0x6f, 0x63, 0x2f, 0x75, 0xb0, 0x00,\n    0x46, 0x48, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20,\n    0xdf, 0x01, 0x01, 0x04, 0x24, 0x4e, 0x6f, 0x50,\n    0x51, 0x52, 0x52, 0x52, 0x53, 0x4d, 0x54, 0x45,\n    0x4c, 0x54, 0x4d, 0x4b, 0x00, 0xc5, 0x00, 0x42,\n    0x43, 0x00, 0x65, 0x45, 0x46, 0x00, 0x4d, 0x6f,\n    0xd0, 0x05, 0x46, 0x41, 0x58, 0xc0, 0x03, 0xb3,\n    0x03, 0x93, 0x03, 0xa0, 0x03, 0x11, 0x22, 0x44,\n    0x64, 0x65, 0x69, 0x6a, 0x31, 0xd0, 0x37, 0x31,\n    0xd0, 0x39, 0x31, 0xd0, 0x31, 0x30, 0x31, 0xd0,\n    0x33, 0x32, 0xd0, 0x33, 0x31, 0xd0, 0x35, 0x32,\n    0xd0, 0x35, 0x33, 0xd0, 0x35, 0x34, 0xd0, 0x35,\n    0x31, 0xd0, 0x36, 0x35, 0xd0, 0x36, 0x31, 0xd0,\n    0x38, 0x33, 0xd0, 0x38, 0x35, 0xd0, 0x38, 0x37,\n    0xd0, 0x38, 0x31, 0xd0, 0x49, 0x49, 0x49, 0x49,\n    0x49, 0x49, 0x56, 0x56, 0x49, 0x56, 0x49, 0x49,\n    0x56, 0x49, 0x49, 0x49, 0x49, 0x58, 0x58, 0x49,\n    0x58, 0x49, 0x49, 0x4c, 0x43, 0x44, 0x4d, 0x69,\n    0x69, 0x69, 0x69, 0x69, 0x69, 0x69, 0x76, 0x76,\n    0x69, 0x76, 0x69, 0x69, 0x76, 0x69, 0x69, 0x69,\n    0x69, 0x78, 0x78, 0x69, 0x78, 0x69, 0x69, 0x6c,\n    0x63, 0x64, 0x6d, 0x30, 0xd0, 0x33, 0x90, 0x21,\n    0xb8, 0x92, 0x21, 0xb8, 0x94, 0x21, 0xb8, 0xd0,\n    0x21, 0xb8, 0xd4, 0x21, 0xb8, 0xd2, 0x21, 0xb8,\n    0x03, 0x22, 0xb8, 0x08, 0x22, 0xb8, 0x0b, 0x22,\n    0xb8, 0x23, 0x22, 0xb8, 0x00, 0x00, 0x00, 0x25,\n    0x22, 0xb8, 0x2b, 0x22, 0x2b, 0x22, 0x2b, 0x22,\n    0x00, 0x00, 0x00, 0x2e, 0x22, 0x2e, 0x22, 0x2e,\n    0x22, 0x00, 0x00, 0x00, 0x3c, 0x22, 0xb8, 0x43,\n    0x22, 0xb8, 0x45, 0x22, 0xb8, 0x00, 0x00, 0x00,\n    0x48, 0x22, 0xb8, 0x3d, 0x00, 0xb8, 0x00, 0x00,\n    0x00, 0x61, 0x22, 0xb8, 0x4d, 0x22, 0xb8, 0x3c,\n    0x00, 0xb8, 0x3e, 0x00, 0xb8, 0x64, 0x22, 0xb8,\n    0x65, 0x22, 0xb8, 0x72, 0x22, 0xb8, 0x76, 0x22,\n    0xb8, 0x7a, 0x22, 0xb8, 0x82, 0x22, 0xb8, 0x86,\n    0x22, 0xb8, 0xa2, 0x22, 0xb8, 0xa8, 0x22, 0xb8,\n    0xa9, 0x22, 0xb8, 0xab, 0x22, 0xb8, 0x7c, 0x22,\n    0xb8, 0x91, 0x22, 0xb8, 0xb2, 0x22, 0x38, 0x03,\n    0x08, 0x30, 0x31, 0x00, 0x31, 0x00, 0x30, 0x00,\n    0x32, 0x30, 0x28, 0x00, 0x31, 0x00, 0x29, 0x00,\n    0x28, 0x00, 0x31, 0x00, 0x30, 0x00, 0x29, 0x00,\n    0x28, 0x32, 0x30, 0x29, 0x31, 0x00, 0x2e, 0x00,\n    0x31, 0x00, 0x30, 0x00, 0x2e, 0x00, 0x32, 0x30,\n    0x2e, 0x28, 0x00, 0x61, 0x00, 0x29, 0x00, 0x41,\n    0x00, 0x61, 0x00, 0x2b, 0x22, 0x00, 0x00, 0x00,\n    0x00, 0x3a, 0x3a, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d,\n    0x3d, 0xdd, 0x2a, 0xb8, 0x6a, 0x56, 0x00, 0x4e,\n    0x00, 0x28, 0x36, 0x3f, 0x59, 0x85, 0x8c, 0xa0,\n    0xba, 0x3f, 0x51, 0x00, 0x26, 0x2c, 0x43, 0x57,\n    0x6c, 0xa1, 0xb6, 0xc1, 0x9b, 0x52, 0x00, 0x5e,\n    0x7a, 0x7f, 0x9d, 0xa6, 0xc1, 0xce, 0xe7, 0xb6,\n    0x53, 0xc8, 0x53, 0xe3, 0x53, 0xd7, 0x56, 0x1f,\n    0x57, 0xeb, 0x58, 0x02, 0x59, 0x0a, 0x59, 0x15,\n    0x59, 0x27, 0x59, 0x73, 0x59, 0x50, 0x5b, 0x80,\n    0x5b, 0xf8, 0x5b, 0x0f, 0x5c, 0x22, 0x5c, 0x38,\n    0x5c, 0x6e, 0x5c, 0x71, 0x5c, 0xdb, 0x5d, 0xe5,\n    0x5d, 0xf1, 0x5d, 0xfe, 0x5d, 0x72, 0x5e, 0x7a,\n    0x5e, 0x7f, 0x5e, 0xf4, 0x5e, 0xfe, 0x5e, 0x0b,\n    0x5f, 0x13, 0x5f, 0x50, 0x5f, 0x61, 0x5f, 0x73,\n    0x5f, 0xc3, 0x5f, 0x08, 0x62, 0x36, 0x62, 0x4b,\n    0x62, 0x2f, 0x65, 0x34, 0x65, 0x87, 0x65, 0x97,\n    0x65, 0xa4, 0x65, 0xb9, 0x65, 0xe0, 0x65, 0xe5,\n    0x65, 0xf0, 0x66, 0x08, 0x67, 0x28, 0x67, 0x20,\n    0x6b, 0x62, 0x6b, 0x79, 0x6b, 0xb3, 0x6b, 0xcb,\n    0x6b, 0xd4, 0x6b, 0xdb, 0x6b, 0x0f, 0x6c, 0x14,\n    0x6c, 0x34, 0x6c, 0x6b, 0x70, 0x2a, 0x72, 0x36,\n    0x72, 0x3b, 0x72, 0x3f, 0x72, 0x47, 0x72, 0x59,\n    0x72, 0x5b, 0x72, 0xac, 0x72, 0x84, 0x73, 0x89,\n    0x73, 0xdc, 0x74, 0xe6, 0x74, 0x18, 0x75, 0x1f,\n    0x75, 0x28, 0x75, 0x30, 0x75, 0x8b, 0x75, 0x92,\n    0x75, 0x76, 0x76, 0x7d, 0x76, 0xae, 0x76, 0xbf,\n    0x76, 0xee, 0x76, 0xdb, 0x77, 0xe2, 0x77, 0xf3,\n    0x77, 0x3a, 0x79, 0xb8, 0x79, 0xbe, 0x79, 0x74,\n    0x7a, 0xcb, 0x7a, 0xf9, 0x7a, 0x73, 0x7c, 0xf8,\n    0x7c, 0x36, 0x7f, 0x51, 0x7f, 0x8a, 0x7f, 0xbd,\n    0x7f, 0x01, 0x80, 0x0c, 0x80, 0x12, 0x80, 0x33,\n    0x80, 0x7f, 0x80, 0x89, 0x80, 0xe3, 0x81, 0x00,\n    0x07, 0x10, 0x19, 0x29, 0x38, 0x3c, 0x8b, 0x8f,\n    0x95, 0x4d, 0x86, 0x6b, 0x86, 0x40, 0x88, 0x4c,\n    0x88, 0x63, 0x88, 0x7e, 0x89, 0x8b, 0x89, 0xd2,\n    0x89, 0x00, 0x8a, 0x37, 0x8c, 0x46, 0x8c, 0x55,\n    0x8c, 0x78, 0x8c, 0x9d, 0x8c, 0x64, 0x8d, 0x70,\n    0x8d, 0xb3, 0x8d, 0xab, 0x8e, 0xca, 0x8e, 0x9b,\n    0x8f, 0xb0, 0x8f, 0xb5, 0x8f, 0x91, 0x90, 0x49,\n    0x91, 0xc6, 0x91, 0xcc, 0x91, 0xd1, 0x91, 0x77,\n    0x95, 0x80, 0x95, 0x1c, 0x96, 0xb6, 0x96, 0xb9,\n    0x96, 0xe8, 0x96, 0x51, 0x97, 0x5e, 0x97, 0x62,\n    0x97, 0x69, 0x97, 0xcb, 0x97, 0xed, 0x97, 0xf3,\n    0x97, 0x01, 0x98, 0xa8, 0x98, 0xdb, 0x98, 0xdf,\n    0x98, 0x96, 0x99, 0x99, 0x99, 0xac, 0x99, 0xa8,\n    0x9a, 0xd8, 0x9a, 0xdf, 0x9a, 0x25, 0x9b, 0x2f,\n    0x9b, 0x32, 0x9b, 0x3c, 0x9b, 0x5a, 0x9b, 0xe5,\n    0x9c, 0x75, 0x9e, 0x7f, 0x9e, 0xa5, 0x9e, 0x00,\n    0x16, 0x1e, 0x28, 0x2c, 0x54, 0x58, 0x69, 0x6e,\n    0x7b, 0x96, 0xa5, 0xad, 0xe8, 0xf7, 0xfb, 0x12,\n    0x30, 0x00, 0x00, 0x41, 0x53, 0x44, 0x53, 0x45,\n    0x53, 0x4b, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x4d, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x4f, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x51, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x53, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x55, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x57, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x59, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x5b, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x5d, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x5f, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0x61, 0x30, 0x99, 0x30, 0x64, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0x66, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0x68, 0x30, 0x99,\n    0x30, 0x6f, 0x30, 0x99, 0x30, 0x72, 0x30, 0x99,\n    0x30, 0x75, 0x30, 0x99, 0x30, 0x78, 0x30, 0x99,\n    0x30, 0x7b, 0x30, 0x99, 0x30, 0x46, 0x30, 0x99,\n    0x30, 0x20, 0x00, 0x99, 0x30, 0x9d, 0x30, 0x99,\n    0x30, 0x88, 0x30, 0x8a, 0x30, 0xab, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xad, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xaf, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xb3, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xb5, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xbf, 0x30, 0x99,\n    0x30, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x30, 0x99,\n    0x30, 0xc4, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0xc6, 0x30, 0x99, 0x30, 0x00, 0x00, 0x00,\n    0x00, 0xc8, 0x30, 0x99, 0x30, 0xcf, 0x30, 0x99,\n    0x30, 0xd2, 0x30, 0x99, 0x30, 0xd5, 0x30, 0x99,\n    0x30, 0xd8, 0x30, 0x99, 0x30, 0xdb, 0x30, 0x99,\n    0x30, 0xa6, 0x30, 0x99, 0x30, 0xef, 0x30, 0x99,\n    0x30, 0xfd, 0x30, 0x99, 0x30, 0xb3, 0x30, 0xc8,\n    0x30, 0x00, 0x11, 0x00, 0x01, 0xaa, 0x02, 0xac,\n    0xad, 0x03, 0x04, 0x05, 0xb0, 0xb1, 0xb2, 0xb3,\n    0xb4, 0xb5, 0x1a, 0x06, 0x07, 0x08, 0x21, 0x09,\n    0x11, 0x61, 0x11, 0x14, 0x11, 0x4c, 0x00, 0x01,\n    0xb3, 0xb4, 0xb8, 0xba, 0xbf, 0xc3, 0xc5, 0x08,\n    0xc9, 0xcb, 0x09, 0x0a, 0x0c, 0x0e, 0x0f, 0x13,\n    0x15, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1e, 0x22,\n    0x2c, 0x33, 0x38, 0xdd, 0xde, 0x43, 0x44, 0x45,\n    0x70, 0x71, 0x74, 0x7d, 0x7e, 0x80, 0x8a, 0x8d,\n    0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e, 0xdb, 0x56,\n    0x0a, 0x4e, 0x2d, 0x4e, 0x0b, 0x4e, 0x32, 0x75,\n    0x59, 0x4e, 0x19, 0x4e, 0x01, 0x4e, 0x29, 0x59,\n    0x30, 0x57, 0xba, 0x4e, 0x28, 0x00, 0x29, 0x00,\n    0x00, 0x11, 0x02, 0x11, 0x03, 0x11, 0x05, 0x11,\n    0x06, 0x11, 0x07, 0x11, 0x09, 0x11, 0x0b, 0x11,\n    0x0c, 0x11, 0x0e, 0x11, 0x0f, 0x11, 0x10, 0x11,\n    0x11, 0x11, 0x12, 0x11, 0x28, 0x00, 0x00, 0x11,\n    0x61, 0x11, 0x29, 0x00, 0x28, 0x00, 0x02, 0x11,\n    0x61, 0x11, 0x29, 0x00, 0x28, 0x00, 0x05, 0x11,\n    0x61, 0x11, 0x29, 0x00, 0x28, 0x00, 0x09, 0x11,\n    0x61, 0x11, 0x29, 0x00, 0x28, 0x00, 0x0b, 0x11,\n    0x61, 0x11, 0x29, 0x00, 0x28, 0x00, 0x0e, 0x11,\n    0x61, 0x11, 0x29, 0x00, 0x28, 0x00, 0x0c, 0x11,\n    0x6e, 0x11, 0x29, 0x00, 0x28, 0x00, 0x0b, 0x11,\n    0x69, 0x11, 0x0c, 0x11, 0x65, 0x11, 0xab, 0x11,\n    0x29, 0x00, 0x28, 0x00, 0x0b, 0x11, 0x69, 0x11,\n    0x12, 0x11, 0x6e, 0x11, 0x29, 0x00, 0x28, 0x00,\n    0x29, 0x00, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e,\n    0xdb, 0x56, 0x94, 0x4e, 0x6d, 0x51, 0x03, 0x4e,\n    0x6b, 0x51, 0x5d, 0x4e, 0x41, 0x53, 0x08, 0x67,\n    0x6b, 0x70, 0x34, 0x6c, 0x28, 0x67, 0xd1, 0x91,\n    0x1f, 0x57, 0xe5, 0x65, 0x2a, 0x68, 0x09, 0x67,\n    0x3e, 0x79, 0x0d, 0x54, 0x79, 0x72, 0xa1, 0x8c,\n    0x5d, 0x79, 0xb4, 0x52, 0xe3, 0x4e, 0x7c, 0x54,\n    0x66, 0x5b, 0xe3, 0x76, 0x01, 0x4f, 0xc7, 0x8c,\n    0x54, 0x53, 0x6d, 0x79, 0x11, 0x4f, 0xea, 0x81,\n    0xf3, 0x81, 0x4f, 0x55, 0x7c, 0x5e, 0x87, 0x65,\n    0x8f, 0x7b, 0x50, 0x54, 0x45, 0x32, 0x00, 0x31,\n    0x00, 0x33, 0x00, 0x30, 0x00, 0x00, 0x11, 0x00,\n    0x02, 0x03, 0x05, 0x06, 0x07, 0x09, 0x0b, 0x0c,\n    0x0e, 0x0f, 0x10, 0x11, 0x12, 0x00, 0x11, 0x00,\n    0x61, 0x02, 0x61, 0x03, 0x61, 0x05, 0x61, 0x06,\n    0x61, 0x07, 0x61, 0x09, 0x61, 0x0b, 0x61, 0x0c,\n    0x61, 0x0e, 0x11, 0x61, 0x11, 0x00, 0x11, 0x0e,\n    0x61, 0xb7, 0x00, 0x69, 0x0b, 0x11, 0x01, 0x63,\n    0x00, 0x69, 0x0b, 0x11, 0x6e, 0x11, 0x00, 0x4e,\n    0x8c, 0x4e, 0x09, 0x4e, 0xdb, 0x56, 0x94, 0x4e,\n    0x6d, 0x51, 0x03, 0x4e, 0x6b, 0x51, 0x5d, 0x4e,\n    0x41, 0x53, 0x08, 0x67, 0x6b, 0x70, 0x34, 0x6c,\n    0x28, 0x67, 0xd1, 0x91, 0x1f, 0x57, 0xe5, 0x65,\n    0x2a, 0x68, 0x09, 0x67, 0x3e, 0x79, 0x0d, 0x54,\n    0x79, 0x72, 0xa1, 0x8c, 0x5d, 0x79, 0xb4, 0x52,\n    0xd8, 0x79, 0x37, 0x75, 0x73, 0x59, 0x69, 0x90,\n    0x2a, 0x51, 0x70, 0x53, 0xe8, 0x6c, 0x05, 0x98,\n    0x11, 0x4f, 0x99, 0x51, 0x63, 0x6b, 0x0a, 0x4e,\n    0x2d, 0x4e, 0x0b, 0x4e, 0xe6, 0x5d, 0xf3, 0x53,\n    0x3b, 0x53, 0x97, 0x5b, 0x66, 0x5b, 0xe3, 0x76,\n    0x01, 0x4f, 0xc7, 0x8c, 0x54, 0x53, 0x1c, 0x59,\n    0x33, 0x00, 0x36, 0x00, 0x34, 0x00, 0x30, 0x00,\n    0x35, 0x30, 0x31, 0x00, 0x08, 0x67, 0x31, 0x00,\n    0x30, 0x00, 0x08, 0x67, 0x48, 0x67, 0x65, 0x72,\n    0x67, 0x65, 0x56, 0x4c, 0x54, 0x44, 0xa2, 0x30,\n    0x00, 0x02, 0x04, 0x06, 0x08, 0x09, 0x0b, 0x0d,\n    0x0f, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1b, 0x1d,\n    0x1f, 0x22, 0x24, 0x26, 0x28, 0x29, 0x2a, 0x2b,\n    0x2c, 0x2d, 0x30, 0x33, 0x36, 0x39, 0x3c, 0x3d,\n    0x3e, 0x3f, 0x40, 0x42, 0x44, 0x46, 0x47, 0x48,\n    0x49, 0x4a, 0x4b, 0x4d, 0x4e, 0x4f, 0x50, 0xe4,\n    0x4e, 0x8c, 0x54, 0xa1, 0x30, 0x01, 0x30, 0x5b,\n    0x27, 0x01, 0x4a, 0x34, 0x00, 0x01, 0x52, 0x39,\n    0x01, 0xa2, 0x30, 0x00, 0x5a, 0x49, 0xa4, 0x30,\n    0x00, 0x27, 0x4f, 0x0c, 0xa4, 0x30, 0x00, 0x4f,\n    0x1d, 0x02, 0x05, 0x4f, 0xa8, 0x30, 0x00, 0x11,\n    0x07, 0x54, 0x21, 0xa8, 0x30, 0x00, 0x54, 0x03,\n    0x54, 0xa4, 0x30, 0x06, 0x4f, 0x15, 0x06, 0x58,\n    0x3c, 0x07, 0x00, 0x46, 0xab, 0x30, 0x00, 0x3e,\n    0x18, 0x1d, 0x00, 0x42, 0x3f, 0x51, 0xac, 0x30,\n    0x00, 0x41, 0x47, 0x00, 0x47, 0x32, 0xae, 0x30,\n    0xac, 0x30, 0xae, 0x30, 0x00, 0x1d, 0x4e, 0xad,\n    0x30, 0x00, 0x38, 0x3d, 0x4f, 0x01, 0x3e, 0x13,\n    0x4f, 0xad, 0x30, 0xed, 0x30, 0xad, 0x30, 0x00,\n    0x40, 0x03, 0x3c, 0x33, 0xad, 0x30, 0x00, 0x40,\n    0x34, 0x4f, 0x1b, 0x3e, 0xad, 0x30, 0x00, 0x40,\n    0x42, 0x16, 0x1b, 0xb0, 0x30, 0x00, 0x39, 0x30,\n    0xa4, 0x30, 0x0c, 0x45, 0x3c, 0x24, 0x4f, 0x0b,\n    0x47, 0x18, 0x00, 0x49, 0xaf, 0x30, 0x00, 0x3e,\n    0x4d, 0x1e, 0xb1, 0x30, 0x00, 0x4b, 0x08, 0x02,\n    0x3a, 0x19, 0x02, 0x4b, 0x2c, 0xa4, 0x30, 0x11,\n    0x00, 0x0b, 0x47, 0xb5, 0x30, 0x00, 0x3e, 0x0c,\n    0x47, 0x2b, 0xb0, 0x30, 0x07, 0x3a, 0x43, 0x00,\n    0xb9, 0x30, 0x02, 0x3a, 0x08, 0x02, 0x3a, 0x0f,\n    0x07, 0x43, 0x00, 0xb7, 0x30, 0x10, 0x00, 0x12,\n    0x34, 0x11, 0x3c, 0x13, 0x17, 0xa4, 0x30, 0x2a,\n    0x1f, 0x24, 0x2b, 0x00, 0x20, 0xbb, 0x30, 0x16,\n    0x41, 0x00, 0x38, 0x0d, 0xc4, 0x30, 0x0d, 0x38,\n    0x00, 0xd0, 0x30, 0x00, 0x2c, 0x1c, 0x1b, 0xa2,\n    0x30, 0x32, 0x00, 0x17, 0x26, 0x49, 0xaf, 0x30,\n    0x25, 0x00, 0x3c, 0xb3, 0x30, 0x21, 0x00, 0x20,\n    0x38, 0xa1, 0x30, 0x34, 0x00, 0x48, 0x22, 0x28,\n    0xa3, 0x30, 0x32, 0x00, 0x59, 0x25, 0xa7, 0x30,\n    0x2f, 0x1c, 0x10, 0x00, 0x44, 0xd5, 0x30, 0x00,\n    0x14, 0x1e, 0xaf, 0x30, 0x29, 0x00, 0x10, 0x4d,\n    0x3c, 0xda, 0x30, 0xbd, 0x30, 0xb8, 0x30, 0x22,\n    0x13, 0x1a, 0x20, 0x33, 0x0c, 0x22, 0x3b, 0x01,\n    0x22, 0x44, 0x00, 0x21, 0x44, 0x07, 0xa4, 0x30,\n    0x39, 0x00, 0x4f, 0x24, 0xc8, 0x30, 0x14, 0x23,\n    0x00, 0xdb, 0x30, 0xf3, 0x30, 0xc9, 0x30, 0x14,\n    0x2a, 0x00, 0x12, 0x33, 0x22, 0x12, 0x33, 0x2a,\n    0xa4, 0x30, 0x3a, 0x00, 0x0b, 0x49, 0xa4, 0x30,\n    0x3a, 0x00, 0x47, 0x3a, 0x1f, 0x2b, 0x3a, 0x47,\n    0x0b, 0xb7, 0x30, 0x27, 0x3c, 0x00, 0x30, 0x3c,\n    0xaf, 0x30, 0x30, 0x00, 0x3e, 0x44, 0xdf, 0x30,\n    0xea, 0x30, 0xd0, 0x30, 0x0f, 0x1a, 0x00, 0x2c,\n    0x1b, 0xe1, 0x30, 0xac, 0x30, 0xac, 0x30, 0x35,\n    0x00, 0x1c, 0x47, 0x35, 0x50, 0x1c, 0x3f, 0xa2,\n    0x30, 0x42, 0x5a, 0x27, 0x42, 0x5a, 0x49, 0x44,\n    0x00, 0x51, 0xc3, 0x30, 0x27, 0x00, 0x05, 0x28,\n    0xea, 0x30, 0xe9, 0x30, 0xd4, 0x30, 0x17, 0x00,\n    0x28, 0xd6, 0x30, 0x15, 0x26, 0x00, 0x15, 0xec,\n    0x30, 0xe0, 0x30, 0xb2, 0x30, 0x3a, 0x41, 0x16,\n    0x00, 0x41, 0xc3, 0x30, 0x2c, 0x00, 0x05, 0x30,\n    0x00, 0xb9, 0x70, 0x31, 0x00, 0x30, 0x00, 0xb9,\n    0x70, 0x32, 0x00, 0x30, 0x00, 0xb9, 0x70, 0x68,\n    0x50, 0x61, 0x64, 0x61, 0x41, 0x55, 0x62, 0x61,\n    0x72, 0x6f, 0x56, 0x70, 0x63, 0x64, 0x6d, 0x64,\n    0x00, 0x6d, 0x00, 0xb2, 0x00, 0x49, 0x00, 0x55,\n    0x00, 0x73, 0x5e, 0x10, 0x62, 0x2d, 0x66, 0x8c,\n    0x54, 0x27, 0x59, 0x63, 0x6b, 0x0e, 0x66, 0xbb,\n    0x6c, 0x2a, 0x68, 0x0f, 0x5f, 0x1a, 0x4f, 0x3e,\n    0x79, 0x70, 0x00, 0x41, 0x6e, 0x00, 0x41, 0xbc,\n    0x03, 0x41, 0x6d, 0x00, 0x41, 0x6b, 0x00, 0x41,\n    0x4b, 0x00, 0x42, 0x4d, 0x00, 0x42, 0x47, 0x00,\n    0x42, 0x63, 0x61, 0x6c, 0x6b, 0x63, 0x61, 0x6c,\n    0x70, 0x00, 0x46, 0x6e, 0x00, 0x46, 0xbc, 0x03,\n    0x46, 0xbc, 0x03, 0x67, 0x6d, 0x00, 0x67, 0x6b,\n    0x00, 0x67, 0x48, 0x00, 0x7a, 0x6b, 0x48, 0x7a,\n    0x4d, 0x48, 0x7a, 0x47, 0x48, 0x7a, 0x54, 0x48,\n    0x7a, 0xbc, 0x03, 0x13, 0x21, 0x6d, 0x00, 0x13,\n    0x21, 0x64, 0x00, 0x13, 0x21, 0x6b, 0x00, 0x13,\n    0x21, 0x66, 0x00, 0x6d, 0x6e, 0x00, 0x6d, 0xbc,\n    0x03, 0x6d, 0x6d, 0x00, 0x6d, 0x63, 0x00, 0x6d,\n    0x6b, 0x00, 0x6d, 0x63, 0x00, 0x0a, 0x0a, 0x4f,\n    0x00, 0x0a, 0x4f, 0x6d, 0x00, 0xb2, 0x00, 0x63,\n    0x00, 0x08, 0x0a, 0x4f, 0x0a, 0x0a, 0x50, 0x00,\n    0x0a, 0x50, 0x6d, 0x00, 0xb3, 0x00, 0x6b, 0x00,\n    0x6d, 0x00, 0xb3, 0x00, 0x6d, 0x00, 0x15, 0x22,\n    0x73, 0x00, 0x6d, 0x00, 0x15, 0x22, 0x73, 0x00,\n    0xb2, 0x00, 0x50, 0x61, 0x6b, 0x50, 0x61, 0x4d,\n    0x50, 0x61, 0x47, 0x50, 0x61, 0x72, 0x61, 0x64,\n    0x72, 0x61, 0x64, 0xd1, 0x73, 0x72, 0x00, 0x61,\n    0x00, 0x64, 0x00, 0x15, 0x22, 0x73, 0x00, 0xb2,\n    0x00, 0x70, 0x00, 0x73, 0x6e, 0x00, 0x73, 0xbc,\n    0x03, 0x73, 0x6d, 0x00, 0x73, 0x70, 0x00, 0x56,\n    0x6e, 0x00, 0x56, 0xbc, 0x03, 0x56, 0x6d, 0x00,\n    0x56, 0x6b, 0x00, 0x56, 0x4d, 0x00, 0x56, 0x70,\n    0x00, 0x57, 0x6e, 0x00, 0x57, 0xbc, 0x03, 0x57,\n    0x6d, 0x00, 0x57, 0x6b, 0x00, 0x57, 0x4d, 0x00,\n    0x57, 0x6b, 0x00, 0xa9, 0x03, 0x4d, 0x00, 0xa9,\n    0x03, 0x61, 0x2e, 0x6d, 0x2e, 0x42, 0x71, 0x63,\n    0x63, 0x63, 0x64, 0x43, 0xd1, 0x6b, 0x67, 0x43,\n    0x6f, 0x2e, 0x64, 0x42, 0x47, 0x79, 0x68, 0x61,\n    0x48, 0x50, 0x69, 0x6e, 0x4b, 0x4b, 0x4b, 0x4d,\n    0x6b, 0x74, 0x6c, 0x6d, 0x6c, 0x6e, 0x6c, 0x6f,\n    0x67, 0x6c, 0x78, 0x6d, 0x62, 0x6d, 0x69, 0x6c,\n    0x6d, 0x6f, 0x6c, 0x50, 0x48, 0x70, 0x2e, 0x6d,\n    0x2e, 0x50, 0x50, 0x4d, 0x50, 0x52, 0x73, 0x72,\n    0x53, 0x76, 0x57, 0x62, 0x56, 0xd1, 0x6d, 0x41,\n    0xd1, 0x6d, 0x31, 0x00, 0xe5, 0x65, 0x31, 0x00,\n    0x30, 0x00, 0xe5, 0x65, 0x32, 0x00, 0x30, 0x00,\n    0xe5, 0x65, 0x33, 0x00, 0x30, 0x00, 0xe5, 0x65,\n    0x67, 0x61, 0x6c, 0x4a, 0x04, 0x4c, 0x04, 0x26,\n    0x01, 0x53, 0x01, 0x27, 0xa7, 0x37, 0xab, 0x6b,\n    0x02, 0x52, 0xab, 0x48, 0x8c, 0xf4, 0x66, 0xca,\n    0x8e, 0xc8, 0x8c, 0xd1, 0x6e, 0x32, 0x4e, 0xe5,\n    0x53, 0x9c, 0x9f, 0x9c, 0x9f, 0x51, 0x59, 0xd1,\n    0x91, 0x87, 0x55, 0x48, 0x59, 0xf6, 0x61, 0x69,\n    0x76, 0x85, 0x7f, 0x3f, 0x86, 0xba, 0x87, 0xf8,\n    0x88, 0x8f, 0x90, 0x02, 0x6a, 0x1b, 0x6d, 0xd9,\n    0x70, 0xde, 0x73, 0x3d, 0x84, 0x6a, 0x91, 0xf1,\n    0x99, 0x82, 0x4e, 0x75, 0x53, 0x04, 0x6b, 0x1b,\n    0x72, 0x2d, 0x86, 0x1e, 0x9e, 0x50, 0x5d, 0xeb,\n    0x6f, 0xcd, 0x85, 0x64, 0x89, 0xc9, 0x62, 0xd8,\n    0x81, 0x1f, 0x88, 0xca, 0x5e, 0x17, 0x67, 0x6a,\n    0x6d, 0xfc, 0x72, 0xce, 0x90, 0x86, 0x4f, 0xb7,\n    0x51, 0xde, 0x52, 0xc4, 0x64, 0xd3, 0x6a, 0x10,\n    0x72, 0xe7, 0x76, 0x01, 0x80, 0x06, 0x86, 0x5c,\n    0x86, 0xef, 0x8d, 0x32, 0x97, 0x6f, 0x9b, 0xfa,\n    0x9d, 0x8c, 0x78, 0x7f, 0x79, 0xa0, 0x7d, 0xc9,\n    0x83, 0x04, 0x93, 0x7f, 0x9e, 0xd6, 0x8a, 0xdf,\n    0x58, 0x04, 0x5f, 0x60, 0x7c, 0x7e, 0x80, 0x62,\n    0x72, 0xca, 0x78, 0xc2, 0x8c, 0xf7, 0x96, 0xd8,\n    0x58, 0x62, 0x5c, 0x13, 0x6a, 0xda, 0x6d, 0x0f,\n    0x6f, 0x2f, 0x7d, 0x37, 0x7e, 0x4b, 0x96, 0xd2,\n    0x52, 0x8b, 0x80, 0xdc, 0x51, 0xcc, 0x51, 0x1c,\n    0x7a, 0xbe, 0x7d, 0xf1, 0x83, 0x75, 0x96, 0x80,\n    0x8b, 0xcf, 0x62, 0x02, 0x6a, 0xfe, 0x8a, 0x39,\n    0x4e, 0xe7, 0x5b, 0x12, 0x60, 0x87, 0x73, 0x70,\n    0x75, 0x17, 0x53, 0xfb, 0x78, 0xbf, 0x4f, 0xa9,\n    0x5f, 0x0d, 0x4e, 0xcc, 0x6c, 0x78, 0x65, 0x22,\n    0x7d, 0xc3, 0x53, 0x5e, 0x58, 0x01, 0x77, 0x49,\n    0x84, 0xaa, 0x8a, 0xba, 0x6b, 0xb0, 0x8f, 0x88,\n    0x6c, 0xfe, 0x62, 0xe5, 0x82, 0xa0, 0x63, 0x65,\n    0x75, 0xae, 0x4e, 0x69, 0x51, 0xc9, 0x51, 0x81,\n    0x68, 0xe7, 0x7c, 0x6f, 0x82, 0xd2, 0x8a, 0xcf,\n    0x91, 0xf5, 0x52, 0x42, 0x54, 0x73, 0x59, 0xec,\n    0x5e, 0xc5, 0x65, 0xfe, 0x6f, 0x2a, 0x79, 0xad,\n    0x95, 0x6a, 0x9a, 0x97, 0x9e, 0xce, 0x9e, 0x9b,\n    0x52, 0xc6, 0x66, 0x77, 0x6b, 0x62, 0x8f, 0x74,\n    0x5e, 0x90, 0x61, 0x00, 0x62, 0x9a, 0x64, 0x23,\n    0x6f, 0x49, 0x71, 0x89, 0x74, 0xca, 0x79, 0xf4,\n    0x7d, 0x6f, 0x80, 0x26, 0x8f, 0xee, 0x84, 0x23,\n    0x90, 0x4a, 0x93, 0x17, 0x52, 0xa3, 0x52, 0xbd,\n    0x54, 0xc8, 0x70, 0xc2, 0x88, 0xaa, 0x8a, 0xc9,\n    0x5e, 0xf5, 0x5f, 0x7b, 0x63, 0xae, 0x6b, 0x3e,\n    0x7c, 0x75, 0x73, 0xe4, 0x4e, 0xf9, 0x56, 0xe7,\n    0x5b, 0xba, 0x5d, 0x1c, 0x60, 0xb2, 0x73, 0x69,\n    0x74, 0x9a, 0x7f, 0x46, 0x80, 0x34, 0x92, 0xf6,\n    0x96, 0x48, 0x97, 0x18, 0x98, 0x8b, 0x4f, 0xae,\n    0x79, 0xb4, 0x91, 0xb8, 0x96, 0xe1, 0x60, 0x86,\n    0x4e, 0xda, 0x50, 0xee, 0x5b, 0x3f, 0x5c, 0x99,\n    0x65, 0x02, 0x6a, 0xce, 0x71, 0x42, 0x76, 0xfc,\n    0x84, 0x7c, 0x90, 0x8d, 0x9f, 0x88, 0x66, 0x2e,\n    0x96, 0x89, 0x52, 0x7b, 0x67, 0xf3, 0x67, 0x41,\n    0x6d, 0x9c, 0x6e, 0x09, 0x74, 0x59, 0x75, 0x6b,\n    0x78, 0x10, 0x7d, 0x5e, 0x98, 0x6d, 0x51, 0x2e,\n    0x62, 0x78, 0x96, 0x2b, 0x50, 0x19, 0x5d, 0xea,\n    0x6d, 0x2a, 0x8f, 0x8b, 0x5f, 0x44, 0x61, 0x17,\n    0x68, 0x87, 0x73, 0x86, 0x96, 0x29, 0x52, 0x0f,\n    0x54, 0x65, 0x5c, 0x13, 0x66, 0x4e, 0x67, 0xa8,\n    0x68, 0xe5, 0x6c, 0x06, 0x74, 0xe2, 0x75, 0x79,\n    0x7f, 0xcf, 0x88, 0xe1, 0x88, 0xcc, 0x91, 0xe2,\n    0x96, 0x3f, 0x53, 0xba, 0x6e, 0x1d, 0x54, 0xd0,\n    0x71, 0x98, 0x74, 0xfa, 0x85, 0xa3, 0x96, 0x57,\n    0x9c, 0x9f, 0x9e, 0x97, 0x67, 0xcb, 0x6d, 0xe8,\n    0x81, 0xcb, 0x7a, 0x20, 0x7b, 0x92, 0x7c, 0xc0,\n    0x72, 0x99, 0x70, 0x58, 0x8b, 0xc0, 0x4e, 0x36,\n    0x83, 0x3a, 0x52, 0x07, 0x52, 0xa6, 0x5e, 0xd3,\n    0x62, 0xd6, 0x7c, 0x85, 0x5b, 0x1e, 0x6d, 0xb4,\n    0x66, 0x3b, 0x8f, 0x4c, 0x88, 0x4d, 0x96, 0x8b,\n    0x89, 0xd3, 0x5e, 0x40, 0x51, 0xc0, 0x55, 0x00,\n    0x00, 0x00, 0x00, 0x5a, 0x58, 0x00, 0x00, 0x74,\n    0x66, 0x00, 0x00, 0x00, 0x00, 0xde, 0x51, 0x2a,\n    0x73, 0xca, 0x76, 0x3c, 0x79, 0x5e, 0x79, 0x65,\n    0x79, 0x8f, 0x79, 0x56, 0x97, 0xbe, 0x7c, 0xbd,\n    0x7f, 0x00, 0x00, 0x12, 0x86, 0x00, 0x00, 0xf8,\n    0x8a, 0x00, 0x00, 0x00, 0x00, 0x38, 0x90, 0xfd,\n    0x90, 0xef, 0x98, 0xfc, 0x98, 0x28, 0x99, 0xb4,\n    0x9d, 0xde, 0x90, 0xb7, 0x96, 0xae, 0x4f, 0xe7,\n    0x50, 0x4d, 0x51, 0xc9, 0x52, 0xe4, 0x52, 0x51,\n    0x53, 0x9d, 0x55, 0x06, 0x56, 0x68, 0x56, 0x40,\n    0x58, 0xa8, 0x58, 0x64, 0x5c, 0x6e, 0x5c, 0x94,\n    0x60, 0x68, 0x61, 0x8e, 0x61, 0xf2, 0x61, 0x4f,\n    0x65, 0xe2, 0x65, 0x91, 0x66, 0x85, 0x68, 0x77,\n    0x6d, 0x1a, 0x6e, 0x22, 0x6f, 0x6e, 0x71, 0x2b,\n    0x72, 0x22, 0x74, 0x91, 0x78, 0x3e, 0x79, 0x49,\n    0x79, 0x48, 0x79, 0x50, 0x79, 0x56, 0x79, 0x5d,\n    0x79, 0x8d, 0x79, 0x8e, 0x79, 0x40, 0x7a, 0x81,\n    0x7a, 0xc0, 0x7b, 0xf4, 0x7d, 0x09, 0x7e, 0x41,\n    0x7e, 0x72, 0x7f, 0x05, 0x80, 0xed, 0x81, 0x79,\n    0x82, 0x79, 0x82, 0x57, 0x84, 0x10, 0x89, 0x96,\n    0x89, 0x01, 0x8b, 0x39, 0x8b, 0xd3, 0x8c, 0x08,\n    0x8d, 0xb6, 0x8f, 0x38, 0x90, 0xe3, 0x96, 0xff,\n    0x97, 0x3b, 0x98, 0x75, 0x60, 0xee, 0x42, 0x18,\n    0x82, 0x02, 0x26, 0x4e, 0xb5, 0x51, 0x68, 0x51,\n    0x80, 0x4f, 0x45, 0x51, 0x80, 0x51, 0xc7, 0x52,\n    0xfa, 0x52, 0x9d, 0x55, 0x55, 0x55, 0x99, 0x55,\n    0xe2, 0x55, 0x5a, 0x58, 0xb3, 0x58, 0x44, 0x59,\n    0x54, 0x59, 0x62, 0x5a, 0x28, 0x5b, 0xd2, 0x5e,\n    0xd9, 0x5e, 0x69, 0x5f, 0xad, 0x5f, 0xd8, 0x60,\n    0x4e, 0x61, 0x08, 0x61, 0x8e, 0x61, 0x60, 0x61,\n    0xf2, 0x61, 0x34, 0x62, 0xc4, 0x63, 0x1c, 0x64,\n    0x52, 0x64, 0x56, 0x65, 0x74, 0x66, 0x17, 0x67,\n    0x1b, 0x67, 0x56, 0x67, 0x79, 0x6b, 0xba, 0x6b,\n    0x41, 0x6d, 0xdb, 0x6e, 0xcb, 0x6e, 0x22, 0x6f,\n    0x1e, 0x70, 0x6e, 0x71, 0xa7, 0x77, 0x35, 0x72,\n    0xaf, 0x72, 0x2a, 0x73, 0x71, 0x74, 0x06, 0x75,\n    0x3b, 0x75, 0x1d, 0x76, 0x1f, 0x76, 0xca, 0x76,\n    0xdb, 0x76, 0xf4, 0x76, 0x4a, 0x77, 0x40, 0x77,\n    0xcc, 0x78, 0xb1, 0x7a, 0xc0, 0x7b, 0x7b, 0x7c,\n    0x5b, 0x7d, 0xf4, 0x7d, 0x3e, 0x7f, 0x05, 0x80,\n    0x52, 0x83, 0xef, 0x83, 0x79, 0x87, 0x41, 0x89,\n    0x86, 0x89, 0x96, 0x89, 0xbf, 0x8a, 0xf8, 0x8a,\n    0xcb, 0x8a, 0x01, 0x8b, 0xfe, 0x8a, 0xed, 0x8a,\n    0x39, 0x8b, 0x8a, 0x8b, 0x08, 0x8d, 0x38, 0x8f,\n    0x72, 0x90, 0x99, 0x91, 0x76, 0x92, 0x7c, 0x96,\n    0xe3, 0x96, 0x56, 0x97, 0xdb, 0x97, 0xff, 0x97,\n    0x0b, 0x98, 0x3b, 0x98, 0x12, 0x9b, 0x9c, 0x9f,\n    0x4a, 0x28, 0x44, 0x28, 0xd5, 0x33, 0x9d, 0x3b,\n    0x18, 0x40, 0x39, 0x40, 0x49, 0x52, 0xd0, 0x5c,\n    0xd3, 0x7e, 0x43, 0x9f, 0x8e, 0x9f, 0x2a, 0xa0,\n    0x02, 0x66, 0x66, 0x66, 0x69, 0x66, 0x6c, 0x66,\n    0x66, 0x69, 0x66, 0x66, 0x6c, 0x7f, 0x01, 0x74,\n    0x73, 0x00, 0x74, 0x65, 0x05, 0x0f, 0x11, 0x0f,\n    0x00, 0x0f, 0x06, 0x19, 0x11, 0x0f, 0x08, 0xd9,\n    0x05, 0xb4, 0x05, 0x00, 0x00, 0x00, 0x00, 0xf2,\n    0x05, 0xb7, 0x05, 0xd0, 0x05, 0x12, 0x00, 0x03,\n    0x04, 0x0b, 0x0c, 0x0d, 0x18, 0x1a, 0xe9, 0x05,\n    0xc1, 0x05, 0xe9, 0x05, 0xc2, 0x05, 0x49, 0xfb,\n    0xc1, 0x05, 0x49, 0xfb, 0xc2, 0x05, 0xd0, 0x05,\n    0xb7, 0x05, 0xd0, 0x05, 0xb8, 0x05, 0xd0, 0x05,\n    0xbc, 0x05, 0xd8, 0x05, 0xbc, 0x05, 0xde, 0x05,\n    0xbc, 0x05, 0xe0, 0x05, 0xbc, 0x05, 0xe3, 0x05,\n    0xbc, 0x05, 0xb9, 0x05, 0x2d, 0x03, 0x2e, 0x03,\n    0x2f, 0x03, 0x30, 0x03, 0x31, 0x03, 0x1c, 0x00,\n    0x18, 0x06, 0x22, 0x06, 0x2b, 0x06, 0xd0, 0x05,\n    0xdc, 0x05, 0x71, 0x06, 0x00, 0x00, 0x0a, 0x0a,\n    0x0a, 0x0a, 0x0d, 0x0d, 0x0d, 0x0d, 0x0f, 0x0f,\n    0x0f, 0x0f, 0x09, 0x09, 0x09, 0x09, 0x0e, 0x0e,\n    0x0e, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x33, 0x33,\n    0x33, 0x33, 0x35, 0x35, 0x35, 0x35, 0x13, 0x13,\n    0x13, 0x13, 0x12, 0x12, 0x12, 0x12, 0x15, 0x15,\n    0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x1c, 0x1c,\n    0x1b, 0x1b, 0x1d, 0x1d, 0x17, 0x17, 0x27, 0x27,\n    0x20, 0x20, 0x38, 0x38, 0x38, 0x38, 0x3e, 0x3e,\n    0x3e, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x40, 0x40,\n    0x40, 0x40, 0x49, 0x49, 0x4a, 0x4a, 0x4a, 0x4a,\n    0x4f, 0x4f, 0x50, 0x50, 0x50, 0x50, 0x4d, 0x4d,\n    0x4d, 0x4d, 0x61, 0x61, 0x62, 0x62, 0x49, 0x06,\n    0x64, 0x64, 0x64, 0x64, 0x7e, 0x7e, 0x7d, 0x7d,\n    0x7f, 0x7f, 0x2e, 0x82, 0x82, 0x7c, 0x7c, 0x80,\n    0x80, 0x87, 0x87, 0x87, 0x87, 0x00, 0x00, 0x26,\n    0x06, 0x00, 0x01, 0x00, 0x01, 0x00, 0xaf, 0x00,\n    0xaf, 0x00, 0x22, 0x00, 0x22, 0x00, 0xa1, 0x00,\n    0xa1, 0x00, 0xa0, 0x00, 0xa0, 0x00, 0xa2, 0x00,\n    0xa2, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00,\n    0x23, 0x00, 0x23, 0x00, 0x23, 0xcc, 0x06, 0x00,\n    0x00, 0x00, 0x00, 0x26, 0x06, 0x00, 0x06, 0x00,\n    0x07, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x24, 0x02,\n    0x06, 0x02, 0x07, 0x02, 0x08, 0x02, 0x1f, 0x02,\n    0x23, 0x02, 0x24, 0x04, 0x06, 0x04, 0x07, 0x04,\n    0x08, 0x04, 0x1f, 0x04, 0x23, 0x04, 0x24, 0x05,\n    0x06, 0x05, 0x1f, 0x05, 0x23, 0x05, 0x24, 0x06,\n    0x07, 0x06, 0x1f, 0x07, 0x06, 0x07, 0x1f, 0x08,\n    0x06, 0x08, 0x07, 0x08, 0x1f, 0x0d, 0x06, 0x0d,\n    0x07, 0x0d, 0x08, 0x0d, 0x1f, 0x0f, 0x07, 0x0f,\n    0x1f, 0x10, 0x06, 0x10, 0x07, 0x10, 0x08, 0x10,\n    0x1f, 0x11, 0x07, 0x11, 0x1f, 0x12, 0x1f, 0x13,\n    0x06, 0x13, 0x1f, 0x14, 0x06, 0x14, 0x1f, 0x1b,\n    0x06, 0x1b, 0x07, 0x1b, 0x08, 0x1b, 0x1f, 0x1b,\n    0x23, 0x1b, 0x24, 0x1c, 0x07, 0x1c, 0x1f, 0x1c,\n    0x23, 0x1c, 0x24, 0x1d, 0x01, 0x1d, 0x06, 0x1d,\n    0x07, 0x1d, 0x08, 0x1d, 0x1e, 0x1d, 0x1f, 0x1d,\n    0x23, 0x1d, 0x24, 0x1e, 0x06, 0x1e, 0x07, 0x1e,\n    0x08, 0x1e, 0x1f, 0x1e, 0x23, 0x1e, 0x24, 0x1f,\n    0x06, 0x1f, 0x07, 0x1f, 0x08, 0x1f, 0x1f, 0x1f,\n    0x23, 0x1f, 0x24, 0x20, 0x06, 0x20, 0x07, 0x20,\n    0x08, 0x20, 0x1f, 0x20, 0x23, 0x20, 0x24, 0x21,\n    0x06, 0x21, 0x1f, 0x21, 0x23, 0x21, 0x24, 0x24,\n    0x06, 0x24, 0x07, 0x24, 0x08, 0x24, 0x1f, 0x24,\n    0x23, 0x24, 0x24, 0x0a, 0x4a, 0x0b, 0x4a, 0x23,\n    0x4a, 0x20, 0x00, 0x4c, 0x06, 0x51, 0x06, 0x51,\n    0x06, 0xff, 0x00, 0x1f, 0x26, 0x06, 0x00, 0x0b,\n    0x00, 0x0c, 0x00, 0x1f, 0x00, 0x20, 0x00, 0x23,\n    0x00, 0x24, 0x02, 0x0b, 0x02, 0x0c, 0x02, 0x1f,\n    0x02, 0x20, 0x02, 0x23, 0x02, 0x24, 0x04, 0x0b,\n    0x04, 0x0c, 0x04, 0x1f, 0x26, 0x06, 0x04, 0x20,\n    0x04, 0x23, 0x04, 0x24, 0x05, 0x0b, 0x05, 0x0c,\n    0x05, 0x1f, 0x05, 0x20, 0x05, 0x23, 0x05, 0x24,\n    0x1b, 0x23, 0x1b, 0x24, 0x1c, 0x23, 0x1c, 0x24,\n    0x1d, 0x01, 0x1d, 0x1e, 0x1d, 0x1f, 0x1d, 0x23,\n    0x1d, 0x24, 0x1e, 0x1f, 0x1e, 0x23, 0x1e, 0x24,\n    0x1f, 0x01, 0x1f, 0x1f, 0x20, 0x0b, 0x20, 0x0c,\n    0x20, 0x1f, 0x20, 0x20, 0x20, 0x23, 0x20, 0x24,\n    0x23, 0x4a, 0x24, 0x0b, 0x24, 0x0c, 0x24, 0x1f,\n    0x24, 0x20, 0x24, 0x23, 0x24, 0x24, 0x00, 0x06,\n    0x00, 0x07, 0x00, 0x08, 0x00, 0x1f, 0x00, 0x21,\n    0x02, 0x06, 0x02, 0x07, 0x02, 0x08, 0x02, 0x1f,\n    0x02, 0x21, 0x04, 0x06, 0x04, 0x07, 0x04, 0x08,\n    0x04, 0x1f, 0x04, 0x21, 0x05, 0x1f, 0x06, 0x07,\n    0x06, 0x1f, 0x07, 0x06, 0x07, 0x1f, 0x08, 0x06,\n    0x08, 0x1f, 0x0d, 0x06, 0x0d, 0x07, 0x0d, 0x08,\n    0x0d, 0x1f, 0x0f, 0x07, 0x0f, 0x08, 0x0f, 0x1f,\n    0x10, 0x06, 0x10, 0x07, 0x10, 0x08, 0x10, 0x1f,\n    0x11, 0x07, 0x12, 0x1f, 0x13, 0x06, 0x13, 0x1f,\n    0x14, 0x06, 0x14, 0x1f, 0x1b, 0x06, 0x1b, 0x07,\n    0x1b, 0x08, 0x1b, 0x1f, 0x1c, 0x07, 0x1c, 0x1f,\n    0x1d, 0x06, 0x1d, 0x07, 0x1d, 0x08, 0x1d, 0x1e,\n    0x1d, 0x1f, 0x1e, 0x06, 0x1e, 0x07, 0x1e, 0x08,\n    0x1e, 0x1f, 0x1e, 0x21, 0x1f, 0x06, 0x1f, 0x07,\n    0x1f, 0x08, 0x1f, 0x1f, 0x20, 0x06, 0x20, 0x07,\n    0x20, 0x08, 0x20, 0x1f, 0x20, 0x21, 0x21, 0x06,\n    0x21, 0x1f, 0x21, 0x4a, 0x24, 0x06, 0x24, 0x07,\n    0x24, 0x08, 0x24, 0x1f, 0x24, 0x21, 0x00, 0x1f,\n    0x00, 0x21, 0x02, 0x1f, 0x02, 0x21, 0x04, 0x1f,\n    0x04, 0x21, 0x05, 0x1f, 0x05, 0x21, 0x0d, 0x1f,\n    0x0d, 0x21, 0x0e, 0x1f, 0x0e, 0x21, 0x1d, 0x1e,\n    0x1d, 0x1f, 0x1e, 0x1f, 0x20, 0x1f, 0x20, 0x21,\n    0x24, 0x1f, 0x24, 0x21, 0x40, 0x06, 0x4e, 0x06,\n    0x51, 0x06, 0x27, 0x06, 0x10, 0x22, 0x10, 0x23,\n    0x12, 0x22, 0x12, 0x23, 0x13, 0x22, 0x13, 0x23,\n    0x0c, 0x22, 0x0c, 0x23, 0x0d, 0x22, 0x0d, 0x23,\n    0x06, 0x22, 0x06, 0x23, 0x05, 0x22, 0x05, 0x23,\n    0x07, 0x22, 0x07, 0x23, 0x0e, 0x22, 0x0e, 0x23,\n    0x0f, 0x22, 0x0f, 0x23, 0x0d, 0x05, 0x0d, 0x06,\n    0x0d, 0x07, 0x0d, 0x1e, 0x0d, 0x0a, 0x0c, 0x0a,\n    0x0e, 0x0a, 0x0f, 0x0a, 0x10, 0x22, 0x10, 0x23,\n    0x12, 0x22, 0x12, 0x23, 0x13, 0x22, 0x13, 0x23,\n    0x0c, 0x22, 0x0c, 0x23, 0x0d, 0x22, 0x0d, 0x23,\n    0x06, 0x22, 0x06, 0x23, 0x05, 0x22, 0x05, 0x23,\n    0x07, 0x22, 0x07, 0x23, 0x0e, 0x22, 0x0e, 0x23,\n    0x0f, 0x22, 0x0f, 0x23, 0x0d, 0x05, 0x0d, 0x06,\n    0x0d, 0x07, 0x0d, 0x1e, 0x0d, 0x0a, 0x0c, 0x0a,\n    0x0e, 0x0a, 0x0f, 0x0a, 0x0d, 0x05, 0x0d, 0x06,\n    0x0d, 0x07, 0x0d, 0x1e, 0x0c, 0x20, 0x0d, 0x20,\n    0x10, 0x1e, 0x0c, 0x05, 0x0c, 0x06, 0x0c, 0x07,\n    0x0d, 0x05, 0x0d, 0x06, 0x0d, 0x07, 0x10, 0x1e,\n    0x11, 0x1e, 0x00, 0x24, 0x00, 0x24, 0x2a, 0x06,\n    0x00, 0x02, 0x1b, 0x00, 0x03, 0x02, 0x00, 0x03,\n    0x02, 0x00, 0x03, 0x1b, 0x00, 0x04, 0x1b, 0x00,\n    0x1b, 0x02, 0x00, 0x1b, 0x03, 0x00, 0x1b, 0x04,\n    0x02, 0x1b, 0x03, 0x02, 0x1b, 0x03, 0x03, 0x1b,\n    0x20, 0x03, 0x1b, 0x1f, 0x09, 0x03, 0x02, 0x09,\n    0x02, 0x03, 0x09, 0x02, 0x1f, 0x09, 0x1b, 0x03,\n    0x09, 0x1b, 0x03, 0x09, 0x1b, 0x02, 0x09, 0x1b,\n    0x1b, 0x09, 0x1b, 0x1b, 0x0b, 0x03, 0x03, 0x0b,\n    0x03, 0x03, 0x0b, 0x1b, 0x1b, 0x0a, 0x03, 0x1b,\n    0x0a, 0x03, 0x1b, 0x0a, 0x02, 0x20, 0x0a, 0x1b,\n    0x04, 0x0a, 0x1b, 0x04, 0x0a, 0x1b, 0x1b, 0x0a,\n    0x1b, 0x1b, 0x0c, 0x03, 0x1f, 0x0c, 0x04, 0x1b,\n    0x0c, 0x04, 0x1b, 0x0d, 0x1b, 0x03, 0x0d, 0x1b,\n    0x03, 0x0d, 0x1b, 0x1b, 0x0d, 0x1b, 0x20, 0x0f,\n    0x02, 0x1b, 0x0f, 0x1b, 0x1b, 0x0f, 0x1b, 0x1b,\n    0x0f, 0x1b, 0x1f, 0x10, 0x1b, 0x1b, 0x10, 0x1b,\n    0x20, 0x10, 0x1b, 0x1f, 0x17, 0x04, 0x1b, 0x17,\n    0x04, 0x1b, 0x18, 0x1b, 0x03, 0x18, 0x1b, 0x1b,\n    0x1a, 0x03, 0x1b, 0x1a, 0x03, 0x20, 0x1a, 0x03,\n    0x1f, 0x1a, 0x02, 0x02, 0x1a, 0x02, 0x02, 0x1a,\n    0x04, 0x1b, 0x1a, 0x04, 0x1b, 0x1a, 0x1b, 0x03,\n    0x1a, 0x1b, 0x03, 0x1b, 0x03, 0x02, 0x1b, 0x03,\n    0x1b, 0x1b, 0x03, 0x20, 0x1b, 0x02, 0x03, 0x1b,\n    0x02, 0x1b, 0x1b, 0x04, 0x02, 0x1b, 0x04, 0x1b,\n    0x28, 0x06, 0x1d, 0x04, 0x06, 0x1f, 0x1d, 0x04,\n    0x1f, 0x1d, 0x1d, 0x1e, 0x05, 0x1d, 0x1e, 0x05,\n    0x21, 0x1e, 0x04, 0x1d, 0x1e, 0x04, 0x1d, 0x1e,\n    0x04, 0x21, 0x1e, 0x1d, 0x22, 0x1e, 0x1d, 0x21,\n    0x22, 0x1d, 0x1d, 0x22, 0x1d, 0x1d, 0x00, 0x06,\n    0x22, 0x02, 0x04, 0x22, 0x02, 0x04, 0x21, 0x02,\n    0x06, 0x22, 0x02, 0x06, 0x21, 0x02, 0x1d, 0x22,\n    0x02, 0x1d, 0x21, 0x04, 0x1d, 0x22, 0x04, 0x05,\n    0x21, 0x04, 0x1d, 0x21, 0x0b, 0x06, 0x21, 0x0d,\n    0x05, 0x22, 0x0c, 0x05, 0x22, 0x0e, 0x05, 0x22,\n    0x1c, 0x04, 0x22, 0x1c, 0x1d, 0x22, 0x22, 0x05,\n    0x22, 0x22, 0x04, 0x22, 0x22, 0x1d, 0x22, 0x1d,\n    0x1d, 0x22, 0x1a, 0x1d, 0x22, 0x1e, 0x05, 0x22,\n    0x1a, 0x1d, 0x05, 0x1c, 0x05, 0x1d, 0x11, 0x1d,\n    0x22, 0x1b, 0x1d, 0x22, 0x1e, 0x04, 0x05, 0x1d,\n    0x06, 0x22, 0x1c, 0x04, 0x1d, 0x1b, 0x1d, 0x1d,\n    0x1c, 0x04, 0x1d, 0x1e, 0x04, 0x05, 0x04, 0x05,\n    0x22, 0x05, 0x04, 0x22, 0x1d, 0x04, 0x22, 0x19,\n    0x1d, 0x22, 0x00, 0x05, 0x22, 0x1b, 0x1d, 0x1d,\n    0x11, 0x04, 0x1d, 0x0d, 0x1d, 0x1d, 0x0b, 0x06,\n    0x22, 0x1e, 0x04, 0x22, 0x35, 0x06, 0x00, 0x0f,\n    0x9d, 0x0d, 0x0f, 0x9d, 0x27, 0x06, 0x00, 0x1d,\n    0x1d, 0x20, 0x00, 0x1c, 0x01, 0x0a, 0x1e, 0x06,\n    0x1e, 0x08, 0x0e, 0x1d, 0x12, 0x1e, 0x0a, 0x0c,\n    0x21, 0x1d, 0x12, 0x1d, 0x23, 0x20, 0x21, 0x0c,\n    0x1d, 0x1e, 0x35, 0x06, 0x00, 0x0f, 0x14, 0x27,\n    0x06, 0x0e, 0x1d, 0x22, 0xff, 0x00, 0x1d, 0x1d,\n    0x20, 0xff, 0x12, 0x1d, 0x23, 0x20, 0xff, 0x21,\n    0x0c, 0x1d, 0x1e, 0x27, 0x06, 0x05, 0x1d, 0xff,\n    0x05, 0x1d, 0x00, 0x1d, 0x20, 0x27, 0x06, 0x0a,\n    0xa5, 0x00, 0x1d, 0x2c, 0x00, 0x01, 0x30, 0x02,\n    0x30, 0x3a, 0x00, 0x3b, 0x00, 0x21, 0x00, 0x3f,\n    0x00, 0x16, 0x30, 0x17, 0x30, 0x26, 0x20, 0x13,\n    0x20, 0x12, 0x01, 0x00, 0x5f, 0x5f, 0x28, 0x29,\n    0x7b, 0x7d, 0x08, 0x30, 0x0c, 0x0d, 0x08, 0x09,\n    0x02, 0x03, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07,\n    0x5b, 0x00, 0x5d, 0x00, 0x3e, 0x20, 0x3e, 0x20,\n    0x3e, 0x20, 0x3e, 0x20, 0x5f, 0x00, 0x5f, 0x00,\n    0x5f, 0x00, 0x2c, 0x00, 0x01, 0x30, 0x2e, 0x00,\n    0x00, 0x00, 0x3b, 0x00, 0x3a, 0x00, 0x3f, 0x00,\n    0x21, 0x00, 0x14, 0x20, 0x28, 0x00, 0x29, 0x00,\n    0x7b, 0x00, 0x7d, 0x00, 0x14, 0x30, 0x15, 0x30,\n    0x23, 0x26, 0x2a, 0x2b, 0x2d, 0x3c, 0x3e, 0x3d,\n    0x00, 0x5c, 0x24, 0x25, 0x40, 0x40, 0x06, 0xff,\n    0x0b, 0x00, 0x0b, 0xff, 0x0c, 0x20, 0x00, 0x4d,\n    0x06, 0x40, 0x06, 0xff, 0x0e, 0x00, 0x0e, 0xff,\n    0x0f, 0x00, 0x0f, 0xff, 0x10, 0x00, 0x10, 0xff,\n    0x11, 0x00, 0x11, 0xff, 0x12, 0x00, 0x12, 0x21,\n    0x06, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03,\n    0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06,\n    0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x09, 0x09,\n    0x09, 0x09, 0x0a, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b,\n    0x0b, 0x0b, 0x0c, 0x0c, 0x0c, 0x0c, 0x0d, 0x0d,\n    0x0d, 0x0d, 0x0e, 0x0e, 0x0f, 0x0f, 0x10, 0x10,\n    0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13,\n    0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15,\n    0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17,\n    0x17, 0x17, 0x18, 0x18, 0x18, 0x18, 0x19, 0x19,\n    0x19, 0x19, 0x20, 0x20, 0x20, 0x20, 0x21, 0x21,\n    0x21, 0x21, 0x22, 0x22, 0x22, 0x22, 0x23, 0x23,\n    0x23, 0x23, 0x24, 0x24, 0x24, 0x24, 0x25, 0x25,\n    0x25, 0x25, 0x26, 0x26, 0x26, 0x26, 0x27, 0x27,\n    0x28, 0x28, 0x29, 0x29, 0x29, 0x29, 0x22, 0x06,\n    0x22, 0x00, 0x22, 0x00, 0x22, 0x01, 0x22, 0x01,\n    0x22, 0x03, 0x22, 0x03, 0x22, 0x05, 0x22, 0x05,\n    0x21, 0x00, 0x85, 0x29, 0x01, 0x30, 0x01, 0x0b,\n    0x0c, 0x00, 0xfa, 0xf1, 0xa0, 0xa2, 0xa4, 0xa6,\n    0xa8, 0xe2, 0xe4, 0xe6, 0xc2, 0xfb, 0xa1, 0xa3,\n    0xa5, 0xa7, 0xa9, 0xaa, 0xac, 0xae, 0xb0, 0xb2,\n    0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe, 0xc0, 0xc3,\n    0xc5, 0xc7, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,\n    0xd1, 0xd4, 0xd7, 0xda, 0xdd, 0xde, 0xdf, 0xe0,\n    0xe1, 0xe3, 0xe5, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,\n    0xec, 0xee, 0xf2, 0x98, 0x99, 0x31, 0x31, 0x4f,\n    0x31, 0x55, 0x31, 0x5b, 0x31, 0x61, 0x31, 0xa2,\n    0x00, 0xa3, 0x00, 0xac, 0x00, 0xaf, 0x00, 0xa6,\n    0x00, 0xa5, 0x00, 0xa9, 0x20, 0x00, 0x00, 0x02,\n    0x25, 0x90, 0x21, 0x91, 0x21, 0x92, 0x21, 0x93,\n    0x21, 0xa0, 0x25, 0xcb, 0x25, 0x99, 0x10, 0xba,\n    0x10, 0x00, 0x00, 0x00, 0x00, 0x9b, 0x10, 0xba,\n    0x10, 0x05, 0x05, 0xa5, 0x10, 0xba, 0x10, 0x05,\n    0x31, 0x11, 0x27, 0x11, 0x32, 0x11, 0x27, 0x11,\n    0x55, 0x47, 0x13, 0x3e, 0x13, 0x47, 0x13, 0x57,\n    0x13, 0x55, 0xb9, 0x14, 0xba, 0x14, 0xb9, 0x14,\n    0xb0, 0x14, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x14,\n    0xbd, 0x14, 0x55, 0x50, 0xb8, 0x15, 0xaf, 0x15,\n    0xb9, 0x15, 0xaf, 0x15, 0x55, 0x35, 0x19, 0x30,\n    0x19, 0x05, 0x57, 0xd1, 0x65, 0xd1, 0x58, 0xd1,\n    0x65, 0xd1, 0x5f, 0xd1, 0x6e, 0xd1, 0x5f, 0xd1,\n    0x6f, 0xd1, 0x5f, 0xd1, 0x70, 0xd1, 0x5f, 0xd1,\n    0x71, 0xd1, 0x5f, 0xd1, 0x72, 0xd1, 0x55, 0x55,\n    0x55, 0x05, 0xb9, 0xd1, 0x65, 0xd1, 0xba, 0xd1,\n    0x65, 0xd1, 0xbb, 0xd1, 0x6e, 0xd1, 0xbc, 0xd1,\n    0x6e, 0xd1, 0xbb, 0xd1, 0x6f, 0xd1, 0xbc, 0xd1,\n    0x6f, 0xd1, 0x55, 0x55, 0x55, 0x41, 0x00, 0x61,\n    0x00, 0x41, 0x00, 0x61, 0x00, 0x69, 0x00, 0x41,\n    0x00, 0x61, 0x00, 0x41, 0x00, 0x43, 0x44, 0x00,\n    0x00, 0x47, 0x00, 0x00, 0x4a, 0x4b, 0x00, 0x00,\n    0x4e, 0x4f, 0x50, 0x51, 0x00, 0x53, 0x54, 0x55,\n    0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63,\n    0x64, 0x00, 0x66, 0x68, 0x00, 0x70, 0x00, 0x41,\n    0x00, 0x61, 0x00, 0x41, 0x42, 0x00, 0x44, 0x45,\n    0x46, 0x47, 0x4a, 0x00, 0x53, 0x00, 0x61, 0x00,\n    0x41, 0x42, 0x00, 0x44, 0x45, 0x46, 0x47, 0x00,\n    0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x4f, 0x53,\n    0x00, 0x61, 0x00, 0x41, 0x00, 0x61, 0x00, 0x41,\n    0x00, 0x61, 0x00, 0x41, 0x00, 0x61, 0x00, 0x41,\n    0x00, 0x61, 0x00, 0x41, 0x00, 0x61, 0x00, 0x41,\n    0x00, 0x61, 0x00, 0x31, 0x01, 0x37, 0x02, 0x91,\n    0x03, 0xa3, 0x03, 0xb1, 0x03, 0xd1, 0x03, 0x24,\n    0x00, 0x1f, 0x04, 0x20, 0x05, 0x91, 0x03, 0xa3,\n    0x03, 0xb1, 0x03, 0xd1, 0x03, 0x24, 0x00, 0x1f,\n    0x04, 0x20, 0x05, 0x91, 0x03, 0xa3, 0x03, 0xb1,\n    0x03, 0xd1, 0x03, 0x24, 0x00, 0x1f, 0x04, 0x20,\n    0x05, 0x91, 0x03, 0xa3, 0x03, 0xb1, 0x03, 0xd1,\n    0x03, 0x24, 0x00, 0x1f, 0x04, 0x20, 0x05, 0x91,\n    0x03, 0xa3, 0x03, 0xb1, 0x03, 0xd1, 0x03, 0x24,\n    0x00, 0x1f, 0x04, 0x20, 0x05, 0x0b, 0x0c, 0x30,\n    0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30,\n    0x00, 0x27, 0x06, 0x00, 0x01, 0x05, 0x08, 0x2a,\n    0x06, 0x1e, 0x08, 0x03, 0x0d, 0x20, 0x19, 0x1a,\n    0x1b, 0x1c, 0x09, 0x0f, 0x17, 0x0b, 0x18, 0x07,\n    0x0a, 0x00, 0x01, 0x04, 0x06, 0x0c, 0x0e, 0x10,\n    0x44, 0x90, 0x77, 0x45, 0x28, 0x06, 0x2c, 0x06,\n    0x00, 0x00, 0x47, 0x06, 0x33, 0x06, 0x17, 0x10,\n    0x11, 0x12, 0x13, 0x00, 0x06, 0x0e, 0x02, 0x0f,\n    0x34, 0x06, 0x2a, 0x06, 0x2b, 0x06, 0x2e, 0x06,\n    0x00, 0x00, 0x36, 0x06, 0x00, 0x00, 0x3a, 0x06,\n    0x2d, 0x06, 0x00, 0x00, 0x4a, 0x06, 0x00, 0x00,\n    0x44, 0x06, 0x00, 0x00, 0x46, 0x06, 0x33, 0x06,\n    0x39, 0x06, 0x00, 0x00, 0x35, 0x06, 0x42, 0x06,\n    0x00, 0x00, 0x34, 0x06, 0x00, 0x00, 0x00, 0x00,\n    0x2e, 0x06, 0x00, 0x00, 0x36, 0x06, 0x00, 0x00,\n    0x3a, 0x06, 0x00, 0x00, 0xba, 0x06, 0x00, 0x00,\n    0x6f, 0x06, 0x00, 0x00, 0x28, 0x06, 0x2c, 0x06,\n    0x00, 0x00, 0x47, 0x06, 0x00, 0x00, 0x00, 0x00,\n    0x2d, 0x06, 0x37, 0x06, 0x4a, 0x06, 0x43, 0x06,\n    0x00, 0x00, 0x45, 0x06, 0x46, 0x06, 0x33, 0x06,\n    0x39, 0x06, 0x41, 0x06, 0x35, 0x06, 0x42, 0x06,\n    0x00, 0x00, 0x34, 0x06, 0x2a, 0x06, 0x2b, 0x06,\n    0x2e, 0x06, 0x00, 0x00, 0x36, 0x06, 0x38, 0x06,\n    0x3a, 0x06, 0x6e, 0x06, 0x00, 0x00, 0xa1, 0x06,\n    0x27, 0x06, 0x00, 0x01, 0x05, 0x08, 0x20, 0x21,\n    0x0b, 0x06, 0x10, 0x23, 0x2a, 0x06, 0x1a, 0x1b,\n    0x1c, 0x09, 0x0f, 0x17, 0x0b, 0x18, 0x07, 0x0a,\n    0x00, 0x01, 0x04, 0x06, 0x0c, 0x0e, 0x10, 0x28,\n    0x06, 0x2c, 0x06, 0x2f, 0x06, 0x00, 0x00, 0x48,\n    0x06, 0x32, 0x06, 0x2d, 0x06, 0x37, 0x06, 0x4a,\n    0x06, 0x2a, 0x06, 0x1a, 0x1b, 0x1c, 0x09, 0x0f,\n    0x17, 0x0b, 0x18, 0x07, 0x0a, 0x00, 0x01, 0x04,\n    0x06, 0x0c, 0x0e, 0x10, 0x30, 0x2e, 0x30, 0x00,\n    0x2c, 0x00, 0x28, 0x00, 0x41, 0x00, 0x29, 0x00,\n    0x14, 0x30, 0x53, 0x00, 0x15, 0x30, 0x43, 0x52,\n    0x43, 0x44, 0x57, 0x5a, 0x41, 0x00, 0x48, 0x56,\n    0x4d, 0x56, 0x53, 0x44, 0x53, 0x53, 0x50, 0x50,\n    0x56, 0x57, 0x43, 0x4d, 0x43, 0x4d, 0x44, 0x4d,\n    0x52, 0x44, 0x4a, 0x4b, 0x30, 0x30, 0x00, 0x68,\n    0x68, 0x4b, 0x62, 0x57, 0x5b, 0xcc, 0x53, 0xc7,\n    0x30, 0x8c, 0x4e, 0x1a, 0x59, 0xe3, 0x89, 0x29,\n    0x59, 0xa4, 0x4e, 0x20, 0x66, 0x21, 0x71, 0x99,\n    0x65, 0x4d, 0x52, 0x8c, 0x5f, 0x8d, 0x51, 0xb0,\n    0x65, 0x1d, 0x52, 0x42, 0x7d, 0x1f, 0x75, 0xa9,\n    0x8c, 0xf0, 0x58, 0x39, 0x54, 0x14, 0x6f, 0x95,\n    0x62, 0x55, 0x63, 0x00, 0x4e, 0x09, 0x4e, 0x4a,\n    0x90, 0xe6, 0x5d, 0x2d, 0x4e, 0xf3, 0x53, 0x07,\n    0x63, 0x70, 0x8d, 0x53, 0x62, 0x81, 0x79, 0x7a,\n    0x7a, 0x08, 0x54, 0x80, 0x6e, 0x09, 0x67, 0x08,\n    0x67, 0x33, 0x75, 0x72, 0x52, 0xb6, 0x55, 0x4d,\n    0x91, 0x14, 0x30, 0x15, 0x30, 0x2c, 0x67, 0x09,\n    0x4e, 0x8c, 0x4e, 0x89, 0x5b, 0xb9, 0x70, 0x53,\n    0x62, 0xd7, 0x76, 0xdd, 0x52, 0x57, 0x65, 0x97,\n    0x5f, 0xef, 0x53, 0x30, 0x00, 0x38, 0x4e, 0x05,\n    0x00, 0x09, 0x22, 0x01, 0x60, 0x4f, 0xae, 0x4f,\n    0xbb, 0x4f, 0x02, 0x50, 0x7a, 0x50, 0x99, 0x50,\n    0xe7, 0x50, 0xcf, 0x50, 0x9e, 0x34, 0x3a, 0x06,\n    0x4d, 0x51, 0x54, 0x51, 0x64, 0x51, 0x77, 0x51,\n    0x1c, 0x05, 0xb9, 0x34, 0x67, 0x51, 0x8d, 0x51,\n    0x4b, 0x05, 0x97, 0x51, 0xa4, 0x51, 0xcc, 0x4e,\n    0xac, 0x51, 0xb5, 0x51, 0xdf, 0x91, 0xf5, 0x51,\n    0x03, 0x52, 0xdf, 0x34, 0x3b, 0x52, 0x46, 0x52,\n    0x72, 0x52, 0x77, 0x52, 0x15, 0x35, 0x02, 0x00,\n    0x20, 0x80, 0x80, 0x00, 0x08, 0x00, 0x00, 0xc7,\n    0x52, 0x00, 0x02, 0x1d, 0x33, 0x3e, 0x3f, 0x50,\n    0x82, 0x8a, 0x93, 0xac, 0xb6, 0xb8, 0xb8, 0xb8,\n    0x2c, 0x0a, 0x70, 0x70, 0xca, 0x53, 0xdf, 0x53,\n    0x63, 0x0b, 0xeb, 0x53, 0xf1, 0x53, 0x06, 0x54,\n    0x9e, 0x54, 0x38, 0x54, 0x48, 0x54, 0x68, 0x54,\n    0xa2, 0x54, 0xf6, 0x54, 0x10, 0x55, 0x53, 0x55,\n    0x63, 0x55, 0x84, 0x55, 0x84, 0x55, 0x99, 0x55,\n    0xab, 0x55, 0xb3, 0x55, 0xc2, 0x55, 0x16, 0x57,\n    0x06, 0x56, 0x17, 0x57, 0x51, 0x56, 0x74, 0x56,\n    0x07, 0x52, 0xee, 0x58, 0xce, 0x57, 0xf4, 0x57,\n    0x0d, 0x58, 0x8b, 0x57, 0x32, 0x58, 0x31, 0x58,\n    0xac, 0x58, 0xe4, 0x14, 0xf2, 0x58, 0xf7, 0x58,\n    0x06, 0x59, 0x1a, 0x59, 0x22, 0x59, 0x62, 0x59,\n    0xa8, 0x16, 0xea, 0x16, 0xec, 0x59, 0x1b, 0x5a,\n    0x27, 0x5a, 0xd8, 0x59, 0x66, 0x5a, 0xee, 0x36,\n    0xfc, 0x36, 0x08, 0x5b, 0x3e, 0x5b, 0x3e, 0x5b,\n    0xc8, 0x19, 0xc3, 0x5b, 0xd8, 0x5b, 0xe7, 0x5b,\n    0xf3, 0x5b, 0x18, 0x1b, 0xff, 0x5b, 0x06, 0x5c,\n    0x53, 0x5f, 0x22, 0x5c, 0x81, 0x37, 0x60, 0x5c,\n    0x6e, 0x5c, 0xc0, 0x5c, 0x8d, 0x5c, 0xe4, 0x1d,\n    0x43, 0x5d, 0xe6, 0x1d, 0x6e, 0x5d, 0x6b, 0x5d,\n    0x7c, 0x5d, 0xe1, 0x5d, 0xe2, 0x5d, 0x2f, 0x38,\n    0xfd, 0x5d, 0x28, 0x5e, 0x3d, 0x5e, 0x69, 0x5e,\n    0x62, 0x38, 0x83, 0x21, 0x7c, 0x38, 0xb0, 0x5e,\n    0xb3, 0x5e, 0xb6, 0x5e, 0xca, 0x5e, 0x92, 0xa3,\n    0xfe, 0x5e, 0x31, 0x23, 0x31, 0x23, 0x01, 0x82,\n    0x22, 0x5f, 0x22, 0x5f, 0xc7, 0x38, 0xb8, 0x32,\n    0xda, 0x61, 0x62, 0x5f, 0x6b, 0x5f, 0xe3, 0x38,\n    0x9a, 0x5f, 0xcd, 0x5f, 0xd7, 0x5f, 0xf9, 0x5f,\n    0x81, 0x60, 0x3a, 0x39, 0x1c, 0x39, 0x94, 0x60,\n    0xd4, 0x26, 0xc7, 0x60, 0x02, 0x02, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0a,\n    0x00, 0x00, 0x02, 0x08, 0x00, 0x80, 0x08, 0x00,\n    0x00, 0x08, 0x80, 0x28, 0x80, 0x02, 0x00, 0x00,\n    0x02, 0x48, 0x61, 0x00, 0x04, 0x06, 0x04, 0x32,\n    0x46, 0x6a, 0x5c, 0x67, 0x96, 0xaa, 0xae, 0xc8,\n    0xd3, 0x5d, 0x62, 0x00, 0x54, 0x77, 0xf3, 0x0c,\n    0x2b, 0x3d, 0x63, 0xfc, 0x62, 0x68, 0x63, 0x83,\n    0x63, 0xe4, 0x63, 0xf1, 0x2b, 0x22, 0x64, 0xc5,\n    0x63, 0xa9, 0x63, 0x2e, 0x3a, 0x69, 0x64, 0x7e,\n    0x64, 0x9d, 0x64, 0x77, 0x64, 0x6c, 0x3a, 0x4f,\n    0x65, 0x6c, 0x65, 0x0a, 0x30, 0xe3, 0x65, 0xf8,\n    0x66, 0x49, 0x66, 0x19, 0x3b, 0x91, 0x66, 0x08,\n    0x3b, 0xe4, 0x3a, 0x92, 0x51, 0x95, 0x51, 0x00,\n    0x67, 0x9c, 0x66, 0xad, 0x80, 0xd9, 0x43, 0x17,\n    0x67, 0x1b, 0x67, 0x21, 0x67, 0x5e, 0x67, 0x53,\n    0x67, 0xc3, 0x33, 0x49, 0x3b, 0xfa, 0x67, 0x85,\n    0x67, 0x52, 0x68, 0x85, 0x68, 0x6d, 0x34, 0x8e,\n    0x68, 0x1f, 0x68, 0x14, 0x69, 0x9d, 0x3b, 0x42,\n    0x69, 0xa3, 0x69, 0xea, 0x69, 0xa8, 0x6a, 0xa3,\n    0x36, 0xdb, 0x6a, 0x18, 0x3c, 0x21, 0x6b, 0xa7,\n    0x38, 0x54, 0x6b, 0x4e, 0x3c, 0x72, 0x6b, 0x9f,\n    0x6b, 0xba, 0x6b, 0xbb, 0x6b, 0x8d, 0x3a, 0x0b,\n    0x1d, 0xfa, 0x3a, 0x4e, 0x6c, 0xbc, 0x3c, 0xbf,\n    0x6c, 0xcd, 0x6c, 0x67, 0x6c, 0x16, 0x6d, 0x3e,\n    0x6d, 0x77, 0x6d, 0x41, 0x6d, 0x69, 0x6d, 0x78,\n    0x6d, 0x85, 0x6d, 0x1e, 0x3d, 0x34, 0x6d, 0x2f,\n    0x6e, 0x6e, 0x6e, 0x33, 0x3d, 0xcb, 0x6e, 0xc7,\n    0x6e, 0xd1, 0x3e, 0xf9, 0x6d, 0x6e, 0x6f, 0x5e,\n    0x3f, 0x8e, 0x3f, 0xc6, 0x6f, 0x39, 0x70, 0x1e,\n    0x70, 0x1b, 0x70, 0x96, 0x3d, 0x4a, 0x70, 0x7d,\n    0x70, 0x77, 0x70, 0xad, 0x70, 0x25, 0x05, 0x45,\n    0x71, 0x63, 0x42, 0x9c, 0x71, 0xab, 0x43, 0x28,\n    0x72, 0x35, 0x72, 0x50, 0x72, 0x08, 0x46, 0x80,\n    0x72, 0x95, 0x72, 0x35, 0x47, 0x02, 0x20, 0x00,\n    0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80,\n    0x00, 0x00, 0x02, 0x02, 0x80, 0x8a, 0x00, 0x00,\n    0x20, 0x00, 0x08, 0x0a, 0x00, 0x80, 0x88, 0x80,\n    0x20, 0x14, 0x48, 0x7a, 0x73, 0x8b, 0x73, 0xac,\n    0x3e, 0xa5, 0x73, 0xb8, 0x3e, 0xb8, 0x3e, 0x47,\n    0x74, 0x5c, 0x74, 0x71, 0x74, 0x85, 0x74, 0xca,\n    0x74, 0x1b, 0x3f, 0x24, 0x75, 0x36, 0x4c, 0x3e,\n    0x75, 0x92, 0x4c, 0x70, 0x75, 0x9f, 0x21, 0x10,\n    0x76, 0xa1, 0x4f, 0xb8, 0x4f, 0x44, 0x50, 0xfc,\n    0x3f, 0x08, 0x40, 0xf4, 0x76, 0xf3, 0x50, 0xf2,\n    0x50, 0x19, 0x51, 0x33, 0x51, 0x1e, 0x77, 0x1f,\n    0x77, 0x1f, 0x77, 0x4a, 0x77, 0x39, 0x40, 0x8b,\n    0x77, 0x46, 0x40, 0x96, 0x40, 0x1d, 0x54, 0x4e,\n    0x78, 0x8c, 0x78, 0xcc, 0x78, 0xe3, 0x40, 0x26,\n    0x56, 0x56, 0x79, 0x9a, 0x56, 0xc5, 0x56, 0x8f,\n    0x79, 0xeb, 0x79, 0x2f, 0x41, 0x40, 0x7a, 0x4a,\n    0x7a, 0x4f, 0x7a, 0x7c, 0x59, 0xa7, 0x5a, 0xa7,\n    0x5a, 0xee, 0x7a, 0x02, 0x42, 0xab, 0x5b, 0xc6,\n    0x7b, 0xc9, 0x7b, 0x27, 0x42, 0x80, 0x5c, 0xd2,\n    0x7c, 0xa0, 0x42, 0xe8, 0x7c, 0xe3, 0x7c, 0x00,\n    0x7d, 0x86, 0x5f, 0x63, 0x7d, 0x01, 0x43, 0xc7,\n    0x7d, 0x02, 0x7e, 0x45, 0x7e, 0x34, 0x43, 0x28,\n    0x62, 0x47, 0x62, 0x59, 0x43, 0xd9, 0x62, 0x7a,\n    0x7f, 0x3e, 0x63, 0x95, 0x7f, 0xfa, 0x7f, 0x05,\n    0x80, 0xda, 0x64, 0x23, 0x65, 0x60, 0x80, 0xa8,\n    0x65, 0x70, 0x80, 0x5f, 0x33, 0xd5, 0x43, 0xb2,\n    0x80, 0x03, 0x81, 0x0b, 0x44, 0x3e, 0x81, 0xb5,\n    0x5a, 0xa7, 0x67, 0xb5, 0x67, 0x93, 0x33, 0x9c,\n    0x33, 0x01, 0x82, 0x04, 0x82, 0x9e, 0x8f, 0x6b,\n    0x44, 0x91, 0x82, 0x8b, 0x82, 0x9d, 0x82, 0xb3,\n    0x52, 0xb1, 0x82, 0xb3, 0x82, 0xbd, 0x82, 0xe6,\n    0x82, 0x3c, 0x6b, 0xe5, 0x82, 0x1d, 0x83, 0x63,\n    0x83, 0xad, 0x83, 0x23, 0x83, 0xbd, 0x83, 0xe7,\n    0x83, 0x57, 0x84, 0x53, 0x83, 0xca, 0x83, 0xcc,\n    0x83, 0xdc, 0x83, 0x36, 0x6c, 0x6b, 0x6d, 0x02,\n    0x00, 0x00, 0x20, 0x22, 0x2a, 0xa0, 0x0a, 0x00,\n    0x20, 0x80, 0x28, 0x00, 0xa8, 0x20, 0x20, 0x00,\n    0x02, 0x80, 0x22, 0x02, 0x8a, 0x08, 0x00, 0xaa,\n    0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x28, 0xd5,\n    0x6c, 0x2b, 0x45, 0xf1, 0x84, 0xf3, 0x84, 0x16,\n    0x85, 0xca, 0x73, 0x64, 0x85, 0x2c, 0x6f, 0x5d,\n    0x45, 0x61, 0x45, 0xb1, 0x6f, 0xd2, 0x70, 0x6b,\n    0x45, 0x50, 0x86, 0x5c, 0x86, 0x67, 0x86, 0x69,\n    0x86, 0xa9, 0x86, 0x88, 0x86, 0x0e, 0x87, 0xe2,\n    0x86, 0x79, 0x87, 0x28, 0x87, 0x6b, 0x87, 0x86,\n    0x87, 0xd7, 0x45, 0xe1, 0x87, 0x01, 0x88, 0xf9,\n    0x45, 0x60, 0x88, 0x63, 0x88, 0x67, 0x76, 0xd7,\n    0x88, 0xde, 0x88, 0x35, 0x46, 0xfa, 0x88, 0xbb,\n    0x34, 0xae, 0x78, 0x66, 0x79, 0xbe, 0x46, 0xc7,\n    0x46, 0xa0, 0x8a, 0xed, 0x8a, 0x8a, 0x8b, 0x55,\n    0x8c, 0xa8, 0x7c, 0xab, 0x8c, 0xc1, 0x8c, 0x1b,\n    0x8d, 0x77, 0x8d, 0x2f, 0x7f, 0x04, 0x08, 0xcb,\n    0x8d, 0xbc, 0x8d, 0xf0, 0x8d, 0xde, 0x08, 0xd4,\n    0x8e, 0x38, 0x8f, 0xd2, 0x85, 0xed, 0x85, 0x94,\n    0x90, 0xf1, 0x90, 0x11, 0x91, 0x2e, 0x87, 0x1b,\n    0x91, 0x38, 0x92, 0xd7, 0x92, 0xd8, 0x92, 0x7c,\n    0x92, 0xf9, 0x93, 0x15, 0x94, 0xfa, 0x8b, 0x8b,\n    0x95, 0x95, 0x49, 0xb7, 0x95, 0x77, 0x8d, 0xe6,\n    0x49, 0xc3, 0x96, 0xb2, 0x5d, 0x23, 0x97, 0x45,\n    0x91, 0x1a, 0x92, 0x6e, 0x4a, 0x76, 0x4a, 0xe0,\n    0x97, 0x0a, 0x94, 0xb2, 0x4a, 0x96, 0x94, 0x0b,\n    0x98, 0x0b, 0x98, 0x29, 0x98, 0xb6, 0x95, 0xe2,\n    0x98, 0x33, 0x4b, 0x29, 0x99, 0xa7, 0x99, 0xc2,\n    0x99, 0xfe, 0x99, 0xce, 0x4b, 0x30, 0x9b, 0x12,\n    0x9b, 0x40, 0x9c, 0xfd, 0x9c, 0xce, 0x4c, 0xed,\n    0x4c, 0x67, 0x9d, 0xce, 0xa0, 0xf8, 0x4c, 0x05,\n    0xa1, 0x0e, 0xa2, 0x91, 0xa2, 0xbb, 0x9e, 0x56,\n    0x4d, 0xf9, 0x9e, 0xfe, 0x9e, 0x05, 0x9f, 0x0f,\n    0x9f, 0x16, 0x9f, 0x3b, 0x9f, 0x00, 0xa6, 0x02,\n    0x88, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,\n    0x28, 0x00, 0x08, 0xa0, 0x80, 0xa0, 0x80, 0x00,\n    0x80, 0x80, 0x00, 0x0a, 0x88, 0x80, 0x00, 0x80,\n    0x00, 0x20, 0x2a, 0x00, 0x80,\n};\n\nstatic const uint16_t unicode_comp_table[945] = {\n    0x4a01, 0x49c0, 0x4a02, 0x0280, 0x0281, 0x0282, 0x0283, 0x02c0,\n    0x02c2, 0x0a00, 0x0284, 0x2442, 0x0285, 0x07c0, 0x0980, 0x0982,\n    0x2440, 0x2280, 0x02c4, 0x2282, 0x2284, 0x2286, 0x02c6, 0x02c8,\n    0x02ca, 0x02cc, 0x0287, 0x228a, 0x02ce, 0x228c, 0x2290, 0x2292,\n    0x228e, 0x0288, 0x0289, 0x028a, 0x2482, 0x0300, 0x0302, 0x0304,\n    0x028b, 0x2480, 0x0308, 0x0984, 0x0986, 0x2458, 0x0a02, 0x0306,\n    0x2298, 0x229a, 0x229e, 0x0900, 0x030a, 0x22a0, 0x030c, 0x030e,\n    0x0840, 0x0310, 0x0312, 0x22a2, 0x22a6, 0x09c0, 0x22a4, 0x22a8,\n    0x22aa, 0x028c, 0x028d, 0x028e, 0x0340, 0x0342, 0x0344, 0x0380,\n    0x028f, 0x248e, 0x07c2, 0x0988, 0x098a, 0x2490, 0x0346, 0x22ac,\n    0x0400, 0x22b0, 0x0842, 0x22b2, 0x0402, 0x22b4, 0x0440, 0x0444,\n    0x22b6, 0x0442, 0x22c2, 0x22c0, 0x22c4, 0x22c6, 0x22c8, 0x0940,\n    0x04c0, 0x0291, 0x22ca, 0x04c4, 0x22cc, 0x04c2, 0x22d0, 0x22ce,\n    0x0292, 0x0293, 0x0294, 0x0295, 0x0540, 0x0542, 0x0a08, 0x0296,\n    0x2494, 0x0544, 0x07c4, 0x098c, 0x098e, 0x06c0, 0x2492, 0x0844,\n    0x2308, 0x230a, 0x0580, 0x230c, 0x0584, 0x0990, 0x0992, 0x230e,\n    0x0582, 0x2312, 0x0586, 0x0588, 0x2314, 0x058c, 0x2316, 0x0998,\n    0x058a, 0x231e, 0x0590, 0x2320, 0x099a, 0x058e, 0x2324, 0x2322,\n    0x0299, 0x029a, 0x029b, 0x05c0, 0x05c2, 0x05c4, 0x029c, 0x24ac,\n    0x05c6, 0x05c8, 0x07c6, 0x0994, 0x0996, 0x0700, 0x24aa, 0x2326,\n    0x05ca, 0x232a, 0x2328, 0x2340, 0x2342, 0x2344, 0x2346, 0x05cc,\n    0x234a, 0x2348, 0x234c, 0x234e, 0x2350, 0x24b8, 0x029d, 0x05ce,\n    0x24be, 0x0a0c, 0x2352, 0x0600, 0x24bc, 0x24ba, 0x0640, 0x2354,\n    0x0642, 0x0644, 0x2356, 0x2358, 0x02a0, 0x02a1, 0x02a2, 0x02a3,\n    0x02c1, 0x02c3, 0x0a01, 0x02a4, 0x2443, 0x02a5, 0x07c1, 0x0981,\n    0x0983, 0x2441, 0x2281, 0x02c5, 0x2283, 0x2285, 0x2287, 0x02c7,\n    0x02c9, 0x02cb, 0x02cd, 0x02a7, 0x228b, 0x02cf, 0x228d, 0x2291,\n    0x2293, 0x228f, 0x02a8, 0x02a9, 0x02aa, 0x2483, 0x0301, 0x0303,\n    0x0305, 0x02ab, 0x2481, 0x0309, 0x0985, 0x0987, 0x2459, 0x0a03,\n    0x0307, 0x2299, 0x229b, 0x229f, 0x0901, 0x030b, 0x22a1, 0x030d,\n    0x030f, 0x0841, 0x0311, 0x0313, 0x22a3, 0x22a7, 0x09c1, 0x22a5,\n    0x22a9, 0x22ab, 0x2380, 0x02ac, 0x02ad, 0x02ae, 0x0341, 0x0343,\n    0x0345, 0x02af, 0x248f, 0x07c3, 0x0989, 0x098b, 0x2491, 0x0347,\n    0x22ad, 0x0401, 0x0884, 0x22b1, 0x0843, 0x22b3, 0x0403, 0x22b5,\n    0x0441, 0x0445, 0x22b7, 0x0443, 0x22c3, 0x22c1, 0x22c5, 0x22c7,\n    0x22c9, 0x0941, 0x04c1, 0x02b1, 0x22cb, 0x04c5, 0x22cd, 0x04c3,\n    0x22d1, 0x22cf, 0x02b2, 0x02b3, 0x02b4, 0x02b5, 0x0541, 0x0543,\n    0x0a09, 0x02b6, 0x2495, 0x0545, 0x07c5, 0x098d, 0x098f, 0x06c1,\n    0x2493, 0x0845, 0x2309, 0x230b, 0x0581, 0x230d, 0x0585, 0x0991,\n    0x0993, 0x230f, 0x0583, 0x2313, 0x0587, 0x0589, 0x2315, 0x058d,\n    0x2317, 0x0999, 0x058b, 0x231f, 0x2381, 0x0591, 0x2321, 0x099b,\n    0x058f, 0x2325, 0x2323, 0x02b9, 0x02ba, 0x02bb, 0x05c1, 0x05c3,\n    0x05c5, 0x02bc, 0x24ad, 0x05c7, 0x05c9, 0x07c7, 0x0995, 0x0997,\n    0x0701, 0x24ab, 0x2327, 0x05cb, 0x232b, 0x2329, 0x2341, 0x2343,\n    0x2345, 0x2347, 0x05cd, 0x234b, 0x2349, 0x2382, 0x234d, 0x234f,\n    0x2351, 0x24b9, 0x02bd, 0x05cf, 0x24bf, 0x0a0d, 0x2353, 0x02bf,\n    0x24bd, 0x2383, 0x24bb, 0x0641, 0x2355, 0x0643, 0x0645, 0x2357,\n    0x2359, 0x3101, 0x0c80, 0x2e00, 0x2446, 0x2444, 0x244a, 0x2448,\n    0x0800, 0x0942, 0x0944, 0x0804, 0x2288, 0x2486, 0x2484, 0x248a,\n    0x2488, 0x22ae, 0x2498, 0x2496, 0x249c, 0x249a, 0x2300, 0x0a06,\n    0x2302, 0x0a04, 0x0946, 0x07ce, 0x07ca, 0x07c8, 0x07cc, 0x2447,\n    0x2445, 0x244b, 0x2449, 0x0801, 0x0943, 0x0945, 0x0805, 0x2289,\n    0x2487, 0x2485, 0x248b, 0x2489, 0x22af, 0x2499, 0x2497, 0x249d,\n    0x249b, 0x2301, 0x0a07, 0x2303, 0x0a05, 0x0947, 0x07cf, 0x07cb,\n    0x07c9, 0x07cd, 0x2450, 0x244e, 0x2454, 0x2452, 0x2451, 0x244f,\n    0x2455, 0x2453, 0x2294, 0x2296, 0x2295, 0x2297, 0x2304, 0x2306,\n    0x2305, 0x2307, 0x2318, 0x2319, 0x231a, 0x231b, 0x232c, 0x232d,\n    0x232e, 0x232f, 0x2400, 0x24a2, 0x24a0, 0x24a6, 0x24a4, 0x24a8,\n    0x24a3, 0x24a1, 0x24a7, 0x24a5, 0x24a9, 0x24b0, 0x24ae, 0x24b4,\n    0x24b2, 0x24b6, 0x24b1, 0x24af, 0x24b5, 0x24b3, 0x24b7, 0x0882,\n    0x0880, 0x0881, 0x0802, 0x0803, 0x229c, 0x229d, 0x0a0a, 0x0a0b,\n    0x0883, 0x0b40, 0x2c8a, 0x0c81, 0x2c89, 0x2c88, 0x2540, 0x2541,\n    0x2d00, 0x2e07, 0x0d00, 0x2640, 0x2641, 0x2e80, 0x0d01, 0x26c8,\n    0x26c9, 0x2f00, 0x2f84, 0x0d02, 0x2f83, 0x2f82, 0x0d40, 0x26d8,\n    0x26d9, 0x3186, 0x0d04, 0x2740, 0x2741, 0x3100, 0x3086, 0x0d06,\n    0x3085, 0x3084, 0x0d41, 0x2840, 0x3200, 0x0d07, 0x284f, 0x2850,\n    0x3280, 0x2c84, 0x2e03, 0x2857, 0x0d42, 0x2c81, 0x2c80, 0x24c0,\n    0x24c1, 0x2c86, 0x2c83, 0x28c0, 0x0d43, 0x25c0, 0x25c1, 0x2940,\n    0x0d44, 0x26c0, 0x26c1, 0x2e05, 0x2e02, 0x29c0, 0x0d45, 0x2f05,\n    0x2f04, 0x0d80, 0x26d0, 0x26d1, 0x2f80, 0x2a40, 0x0d82, 0x26e0,\n    0x26e1, 0x3080, 0x3081, 0x2ac0, 0x0d83, 0x3004, 0x3003, 0x0d81,\n    0x27c0, 0x27c1, 0x3082, 0x2b40, 0x0d84, 0x2847, 0x2848, 0x3184,\n    0x3181, 0x2f06, 0x0d08, 0x2f81, 0x3005, 0x0d46, 0x3083, 0x3182,\n    0x0e00, 0x0e01, 0x0f40, 0x1180, 0x1182, 0x0f03, 0x0f00, 0x11c0,\n    0x0f01, 0x1140, 0x1202, 0x1204, 0x0f81, 0x1240, 0x0fc0, 0x1242,\n    0x0f80, 0x1244, 0x1284, 0x0f82, 0x1286, 0x1288, 0x128a, 0x12c0,\n    0x1282, 0x1181, 0x1183, 0x1043, 0x1040, 0x11c1, 0x1041, 0x1141,\n    0x1203, 0x1205, 0x10c1, 0x1241, 0x1000, 0x1243, 0x10c0, 0x1245,\n    0x1285, 0x10c2, 0x1287, 0x1289, 0x128b, 0x12c1, 0x1283, 0x1080,\n    0x1100, 0x1101, 0x1200, 0x1201, 0x1280, 0x1281, 0x1340, 0x1341,\n    0x1343, 0x1342, 0x1344, 0x13c2, 0x1400, 0x13c0, 0x1440, 0x1480,\n    0x14c0, 0x1540, 0x1541, 0x1740, 0x1700, 0x1741, 0x17c0, 0x1800,\n    0x1802, 0x1801, 0x1840, 0x1880, 0x1900, 0x18c0, 0x18c1, 0x1901,\n    0x1940, 0x1942, 0x1941, 0x1980, 0x19c0, 0x19c2, 0x19c1, 0x1c80,\n    0x1cc0, 0x1dc0, 0x1f80, 0x2000, 0x2002, 0x2004, 0x2006, 0x2008,\n    0x2040, 0x2080, 0x2082, 0x20c0, 0x20c1, 0x2100, 0x22b8, 0x22b9,\n    0x2310, 0x2311, 0x231c, 0x231d, 0x244c, 0x2456, 0x244d, 0x2457,\n    0x248c, 0x248d, 0x249e, 0x249f, 0x2500, 0x2502, 0x2504, 0x2bc0,\n    0x2501, 0x2503, 0x2505, 0x2bc1, 0x2bc2, 0x2bc3, 0x2bc4, 0x2bc5,\n    0x2bc6, 0x2bc7, 0x2580, 0x2582, 0x2584, 0x2bc8, 0x2581, 0x2583,\n    0x2585, 0x2bc9, 0x2bca, 0x2bcb, 0x2bcc, 0x2bcd, 0x2bce, 0x2bcf,\n    0x2600, 0x2602, 0x2601, 0x2603, 0x2680, 0x2682, 0x2681, 0x2683,\n    0x26c2, 0x26c4, 0x26c6, 0x2c00, 0x26c3, 0x26c5, 0x26c7, 0x2c01,\n    0x2c02, 0x2c03, 0x2c04, 0x2c05, 0x2c06, 0x2c07, 0x26ca, 0x26cc,\n    0x26ce, 0x2c08, 0x26cb, 0x26cd, 0x26cf, 0x2c09, 0x2c0a, 0x2c0b,\n    0x2c0c, 0x2c0d, 0x2c0e, 0x2c0f, 0x26d2, 0x26d4, 0x26d6, 0x26d3,\n    0x26d5, 0x26d7, 0x26da, 0x26dc, 0x26de, 0x26db, 0x26dd, 0x26df,\n    0x2700, 0x2702, 0x2701, 0x2703, 0x2780, 0x2782, 0x2781, 0x2783,\n    0x2800, 0x2802, 0x2804, 0x2801, 0x2803, 0x2805, 0x2842, 0x2844,\n    0x2846, 0x2849, 0x284b, 0x284d, 0x2c40, 0x284a, 0x284c, 0x284e,\n    0x2c41, 0x2c42, 0x2c43, 0x2c44, 0x2c45, 0x2c46, 0x2c47, 0x2851,\n    0x2853, 0x2855, 0x2c48, 0x2852, 0x2854, 0x2856, 0x2c49, 0x2c4a,\n    0x2c4b, 0x2c4c, 0x2c4d, 0x2c4e, 0x2c4f, 0x2c82, 0x2e01, 0x3180,\n    0x2c87, 0x2f01, 0x2f02, 0x2f03, 0x2e06, 0x3185, 0x3000, 0x3001,\n    0x3002, 0x4640, 0x4641, 0x4680, 0x46c0, 0x46c2, 0x46c1, 0x4700,\n    0x4740, 0x4780, 0x47c0, 0x47c2, 0x4900, 0x4940, 0x4980, 0x4982,\n    0x4a00, 0x49c2, 0x4a03, 0x4a04, 0x4a40, 0x4a41, 0x4a80, 0x4a81,\n    0x4ac0, 0x4ac1, 0x4bc0, 0x4bc1, 0x4b00, 0x4b01, 0x4b40, 0x4b41,\n    0x4bc2, 0x4bc3, 0x4b80, 0x4b81, 0x4b82, 0x4b83, 0x4c00, 0x4c01,\n    0x4c02, 0x4c03, 0x5600, 0x5440, 0x5442, 0x5444, 0x5446, 0x5448,\n    0x544a, 0x544c, 0x544e, 0x5450, 0x5452, 0x5454, 0x5456, 0x5480,\n    0x5482, 0x5484, 0x54c0, 0x54c1, 0x5500, 0x5501, 0x5540, 0x5541,\n    0x5580, 0x5581, 0x55c0, 0x55c1, 0x5680, 0x58c0, 0x5700, 0x5702,\n    0x5704, 0x5706, 0x5708, 0x570a, 0x570c, 0x570e, 0x5710, 0x5712,\n    0x5714, 0x5716, 0x5740, 0x5742, 0x5744, 0x5780, 0x5781, 0x57c0,\n    0x57c1, 0x5800, 0x5801, 0x5840, 0x5841, 0x5880, 0x5881, 0x5900,\n    0x5901, 0x5902, 0x5903, 0x5940, 0x8e80, 0x8e82, 0x8ec0, 0x8f00,\n    0x8f01, 0x8f40, 0x8f41, 0x8f81, 0x8f80, 0x8f83, 0x8fc0, 0x8fc1,\n    0x9000,\n};\n\ntypedef enum {\n    UNICODE_GC_Cn,\n    UNICODE_GC_Lu,\n    UNICODE_GC_Ll,\n    UNICODE_GC_Lt,\n    UNICODE_GC_Lm,\n    UNICODE_GC_Lo,\n    UNICODE_GC_Mn,\n    UNICODE_GC_Mc,\n    UNICODE_GC_Me,\n    UNICODE_GC_Nd,\n    UNICODE_GC_Nl,\n    UNICODE_GC_No,\n    UNICODE_GC_Sm,\n    UNICODE_GC_Sc,\n    UNICODE_GC_Sk,\n    UNICODE_GC_So,\n    UNICODE_GC_Pc,\n    UNICODE_GC_Pd,\n    UNICODE_GC_Ps,\n    UNICODE_GC_Pe,\n    UNICODE_GC_Pi,\n    UNICODE_GC_Pf,\n    UNICODE_GC_Po,\n    UNICODE_GC_Zs,\n    UNICODE_GC_Zl,\n    UNICODE_GC_Zp,\n    UNICODE_GC_Cc,\n    UNICODE_GC_Cf,\n    UNICODE_GC_Cs,\n    UNICODE_GC_Co,\n    UNICODE_GC_LC,\n    UNICODE_GC_L,\n    UNICODE_GC_M,\n    UNICODE_GC_N,\n    UNICODE_GC_S,\n    UNICODE_GC_P,\n    UNICODE_GC_Z,\n    UNICODE_GC_C,\n    UNICODE_GC_COUNT,\n} UnicodeGCEnum;\n\nstatic const char unicode_gc_name_table[] =\n    \"Cn,Unassigned\"            \"\\0\"\n    \"Lu,Uppercase_Letter\"      \"\\0\"\n    \"Ll,Lowercase_Letter\"      \"\\0\"\n    \"Lt,Titlecase_Letter\"      \"\\0\"\n    \"Lm,Modifier_Letter\"       \"\\0\"\n    \"Lo,Other_Letter\"          \"\\0\"\n    \"Mn,Nonspacing_Mark\"       \"\\0\"\n    \"Mc,Spacing_Mark\"          \"\\0\"\n    \"Me,Enclosing_Mark\"        \"\\0\"\n    \"Nd,Decimal_Number,digit\"  \"\\0\"\n    \"Nl,Letter_Number\"         \"\\0\"\n    \"No,Other_Number\"          \"\\0\"\n    \"Sm,Math_Symbol\"           \"\\0\"\n    \"Sc,Currency_Symbol\"       \"\\0\"\n    \"Sk,Modifier_Symbol\"       \"\\0\"\n    \"So,Other_Symbol\"          \"\\0\"\n    \"Pc,Connector_Punctuation\" \"\\0\"\n    \"Pd,Dash_Punctuation\"      \"\\0\"\n    \"Ps,Open_Punctuation\"      \"\\0\"\n    \"Pe,Close_Punctuation\"     \"\\0\"\n    \"Pi,Initial_Punctuation\"   \"\\0\"\n    \"Pf,Final_Punctuation\"     \"\\0\"\n    \"Po,Other_Punctuation\"     \"\\0\"\n    \"Zs,Space_Separator\"       \"\\0\"\n    \"Zl,Line_Separator\"        \"\\0\"\n    \"Zp,Paragraph_Separator\"   \"\\0\"\n    \"Cc,Control,cntrl\"         \"\\0\"\n    \"Cf,Format\"                \"\\0\"\n    \"Cs,Surrogate\"             \"\\0\"\n    \"Co,Private_Use\"           \"\\0\"\n    \"LC,Cased_Letter\"          \"\\0\"\n    \"L,Letter\"                 \"\\0\"\n    \"M,Mark,Combining_Mark\"    \"\\0\"\n    \"N,Number\"                 \"\\0\"\n    \"S,Symbol\"                 \"\\0\"\n    \"P,Punctuation,punct\"      \"\\0\"\n    \"Z,Separator\"              \"\\0\"\n    \"C,Other\"                  \"\\0\"\n;\n\nstatic const uint8_t unicode_gc_table[3790] = {\n    0xfa, 0x18, 0x17, 0x56, 0x0d, 0x56, 0x12, 0x13,\n    0x16, 0x0c, 0x16, 0x11, 0x36, 0xe9, 0x02, 0x36,\n    0x4c, 0x36, 0xe1, 0x12, 0x12, 0x16, 0x13, 0x0e,\n    0x10, 0x0e, 0xe2, 0x12, 0x12, 0x0c, 0x13, 0x0c,\n    0xfa, 0x19, 0x17, 0x16, 0x6d, 0x0f, 0x16, 0x0e,\n    0x0f, 0x05, 0x14, 0x0c, 0x1b, 0x0f, 0x0e, 0x0f,\n    0x0c, 0x2b, 0x0e, 0x02, 0x36, 0x0e, 0x0b, 0x05,\n    0x15, 0x4b, 0x16, 0xe1, 0x0f, 0x0c, 0xc1, 0xe2,\n    0x10, 0x0c, 0xe2, 0x00, 0xff, 0x30, 0x02, 0xff,\n    0x08, 0x02, 0xff, 0x27, 0xbf, 0x22, 0x21, 0x02,\n    0x5f, 0x5f, 0x21, 0x22, 0x61, 0x02, 0x21, 0x02,\n    0x41, 0x42, 0x21, 0x02, 0x21, 0x02, 0x9f, 0x7f,\n    0x02, 0x5f, 0x5f, 0x21, 0x02, 0x5f, 0x3f, 0x02,\n    0x05, 0x3f, 0x22, 0x65, 0x01, 0x03, 0x02, 0x01,\n    0x03, 0x02, 0x01, 0x03, 0x02, 0xff, 0x08, 0x02,\n    0xff, 0x0a, 0x02, 0x01, 0x03, 0x02, 0x5f, 0x21,\n    0x02, 0xff, 0x32, 0xa2, 0x21, 0x02, 0x21, 0x22,\n    0x5f, 0x41, 0x02, 0xff, 0x00, 0xe2, 0x3c, 0x05,\n    0xe2, 0x13, 0xe4, 0x0a, 0x6e, 0xe4, 0x04, 0xee,\n    0x06, 0x84, 0xce, 0x04, 0x0e, 0x04, 0xee, 0x09,\n    0xe6, 0x68, 0x7f, 0x04, 0x0e, 0x3f, 0x20, 0x04,\n    0x42, 0x16, 0x01, 0x60, 0x2e, 0x01, 0x16, 0x41,\n    0x00, 0x01, 0x00, 0x21, 0x02, 0xe1, 0x09, 0x00,\n    0xe1, 0x01, 0xe2, 0x1b, 0x3f, 0x02, 0x41, 0x42,\n    0xff, 0x10, 0x62, 0x3f, 0x0c, 0x5f, 0x3f, 0x02,\n    0xe1, 0x2b, 0xe2, 0x28, 0xff, 0x1a, 0x0f, 0x86,\n    0x28, 0xff, 0x2f, 0xff, 0x06, 0x02, 0xff, 0x58,\n    0x00, 0xe1, 0x1e, 0x20, 0x04, 0xb6, 0xe2, 0x21,\n    0x16, 0x11, 0x20, 0x2f, 0x0d, 0x00, 0xe6, 0x25,\n    0x11, 0x06, 0x16, 0x26, 0x16, 0x26, 0x16, 0x06,\n    0xe0, 0x00, 0xe5, 0x13, 0x60, 0x65, 0x36, 0xe0,\n    0x03, 0xbb, 0x4c, 0x36, 0x0d, 0x36, 0x2f, 0xe6,\n    0x03, 0x16, 0x1b, 0x00, 0x36, 0xe5, 0x18, 0x04,\n    0xe5, 0x02, 0xe6, 0x0d, 0xe9, 0x02, 0x76, 0x25,\n    0x06, 0xe5, 0x5b, 0x16, 0x05, 0xc6, 0x1b, 0x0f,\n    0xa6, 0x24, 0x26, 0x0f, 0x66, 0x25, 0xe9, 0x02,\n    0x45, 0x2f, 0x05, 0xf6, 0x06, 0x00, 0x1b, 0x05,\n    0x06, 0xe5, 0x16, 0xe6, 0x13, 0x20, 0xe5, 0x51,\n    0xe6, 0x03, 0x05, 0xe0, 0x06, 0xe9, 0x02, 0xe5,\n    0x19, 0xe6, 0x01, 0x24, 0x0f, 0x56, 0x04, 0x20,\n    0x06, 0x2d, 0xe5, 0x0e, 0x66, 0x04, 0xe6, 0x01,\n    0x04, 0x46, 0x04, 0x86, 0x20, 0xf6, 0x07, 0x00,\n    0xe5, 0x11, 0x46, 0x20, 0x16, 0x00, 0xe5, 0x03,\n    0xe0, 0x2d, 0xe5, 0x0d, 0x00, 0xe5, 0x0a, 0xe0,\n    0x03, 0xe6, 0x07, 0x1b, 0xe6, 0x18, 0x07, 0xe5,\n    0x2e, 0x06, 0x07, 0x06, 0x05, 0x47, 0xe6, 0x00,\n    0x67, 0x06, 0x27, 0x05, 0xc6, 0xe5, 0x02, 0x26,\n    0x36, 0xe9, 0x02, 0x16, 0x04, 0xe5, 0x07, 0x06,\n    0x27, 0x00, 0xe5, 0x00, 0x20, 0x25, 0x20, 0xe5,\n    0x0e, 0x00, 0xc5, 0x00, 0x05, 0x40, 0x65, 0x20,\n    0x06, 0x05, 0x47, 0x66, 0x20, 0x27, 0x20, 0x27,\n    0x06, 0x05, 0xe0, 0x00, 0x07, 0x60, 0x25, 0x00,\n    0x45, 0x26, 0x20, 0xe9, 0x02, 0x25, 0x2d, 0xab,\n    0x0f, 0x0d, 0x05, 0x16, 0x06, 0x20, 0x26, 0x07,\n    0x00, 0xa5, 0x60, 0x25, 0x20, 0xe5, 0x0e, 0x00,\n    0xc5, 0x00, 0x25, 0x00, 0x25, 0x00, 0x25, 0x20,\n    0x06, 0x00, 0x47, 0x26, 0x60, 0x26, 0x20, 0x46,\n    0x40, 0x06, 0xc0, 0x65, 0x00, 0x05, 0xc0, 0xe9,\n    0x02, 0x26, 0x45, 0x06, 0x16, 0xe0, 0x02, 0x26,\n    0x07, 0x00, 0xe5, 0x01, 0x00, 0x45, 0x00, 0xe5,\n    0x0e, 0x00, 0xc5, 0x00, 0x25, 0x00, 0x85, 0x20,\n    0x06, 0x05, 0x47, 0x86, 0x00, 0x26, 0x07, 0x00,\n    0x27, 0x06, 0x20, 0x05, 0xe0, 0x07, 0x25, 0x26,\n    0x20, 0xe9, 0x02, 0x16, 0x0d, 0xc0, 0x05, 0xa6,\n    0x00, 0x06, 0x27, 0x00, 0xe5, 0x00, 0x20, 0x25,\n    0x20, 0xe5, 0x0e, 0x00, 0xc5, 0x00, 0x25, 0x00,\n    0x85, 0x20, 0x06, 0x05, 0x07, 0x06, 0x07, 0x66,\n    0x20, 0x27, 0x20, 0x27, 0x06, 0xc0, 0x26, 0x07,\n    0x60, 0x25, 0x00, 0x45, 0x26, 0x20, 0xe9, 0x02,\n    0x0f, 0x05, 0xab, 0xe0, 0x02, 0x06, 0x05, 0x00,\n    0xa5, 0x40, 0x45, 0x00, 0x65, 0x40, 0x25, 0x00,\n    0x05, 0x00, 0x25, 0x40, 0x25, 0x40, 0x45, 0x40,\n    0xe5, 0x04, 0x60, 0x27, 0x06, 0x27, 0x40, 0x47,\n    0x00, 0x47, 0x06, 0x20, 0x05, 0xa0, 0x07, 0xe0,\n    0x06, 0xe9, 0x02, 0x4b, 0xaf, 0x0d, 0x0f, 0x80,\n    0x06, 0x47, 0x06, 0xe5, 0x00, 0x00, 0x45, 0x00,\n    0xe5, 0x0f, 0x00, 0xe5, 0x08, 0x40, 0x05, 0x46,\n    0x67, 0x00, 0x46, 0x00, 0x66, 0xc0, 0x26, 0x00,\n    0x45, 0x80, 0x25, 0x26, 0x20, 0xe9, 0x02, 0xc0,\n    0x16, 0xcb, 0x0f, 0x05, 0x06, 0x27, 0x16, 0xe5,\n    0x00, 0x00, 0x45, 0x00, 0xe5, 0x0f, 0x00, 0xe5,\n    0x02, 0x00, 0x85, 0x20, 0x06, 0x05, 0x07, 0x06,\n    0x87, 0x00, 0x06, 0x27, 0x00, 0x27, 0x26, 0xc0,\n    0x27, 0xc0, 0x05, 0x00, 0x25, 0x26, 0x20, 0xe9,\n    0x02, 0x00, 0x25, 0xe0, 0x05, 0x26, 0x27, 0xe5,\n    0x01, 0x00, 0x45, 0x00, 0xe5, 0x21, 0x26, 0x05,\n    0x47, 0x66, 0x00, 0x47, 0x00, 0x47, 0x06, 0x05,\n    0x0f, 0x60, 0x45, 0x07, 0xcb, 0x45, 0x26, 0x20,\n    0xe9, 0x02, 0xeb, 0x01, 0x0f, 0xa5, 0x00, 0x06,\n    0x27, 0x00, 0xe5, 0x0a, 0x40, 0xe5, 0x10, 0x00,\n    0xe5, 0x01, 0x00, 0x05, 0x20, 0xc5, 0x40, 0x06,\n    0x60, 0x47, 0x46, 0x00, 0x06, 0x00, 0xe7, 0x00,\n    0xa0, 0xe9, 0x02, 0x20, 0x27, 0x16, 0xe0, 0x04,\n    0xe5, 0x28, 0x06, 0x25, 0xc6, 0x60, 0x0d, 0xa5,\n    0x04, 0xe6, 0x00, 0x16, 0xe9, 0x02, 0x36, 0xe0,\n    0x1d, 0x25, 0x00, 0x05, 0x00, 0x85, 0x00, 0xe5,\n    0x10, 0x00, 0x05, 0x00, 0xe5, 0x02, 0x06, 0x25,\n    0xe6, 0x01, 0x05, 0x20, 0x85, 0x00, 0x04, 0x00,\n    0xa6, 0x20, 0xe9, 0x02, 0x20, 0x65, 0xe0, 0x18,\n    0x05, 0x4f, 0xf6, 0x07, 0x0f, 0x16, 0x4f, 0x26,\n    0xaf, 0xe9, 0x02, 0xeb, 0x02, 0x0f, 0x06, 0x0f,\n    0x06, 0x0f, 0x06, 0x12, 0x13, 0x12, 0x13, 0x27,\n    0xe5, 0x00, 0x00, 0xe5, 0x1c, 0x60, 0xe6, 0x06,\n    0x07, 0x86, 0x16, 0x26, 0x85, 0xe6, 0x03, 0x00,\n    0xe6, 0x1c, 0x00, 0xef, 0x00, 0x06, 0xaf, 0x00,\n    0x2f, 0x96, 0x6f, 0x36, 0xe0, 0x1d, 0xe5, 0x23,\n    0x27, 0x66, 0x07, 0xa6, 0x07, 0x26, 0x27, 0x26,\n    0x05, 0xe9, 0x02, 0xb6, 0xa5, 0x27, 0x26, 0x65,\n    0x46, 0x05, 0x47, 0x25, 0xc7, 0x45, 0x66, 0xe5,\n    0x05, 0x06, 0x27, 0x26, 0xa7, 0x06, 0x05, 0x07,\n    0xe9, 0x02, 0x47, 0x06, 0x2f, 0xe1, 0x1e, 0x00,\n    0x01, 0x80, 0x01, 0x20, 0xe2, 0x23, 0x16, 0x04,\n    0x42, 0xe5, 0x80, 0xc1, 0x00, 0x65, 0x20, 0xc5,\n    0x00, 0x05, 0x00, 0x65, 0x20, 0xe5, 0x21, 0x00,\n    0x65, 0x20, 0xe5, 0x19, 0x00, 0x65, 0x20, 0xc5,\n    0x00, 0x05, 0x00, 0x65, 0x20, 0xe5, 0x07, 0x00,\n    0xe5, 0x31, 0x00, 0x65, 0x20, 0xe5, 0x3b, 0x20,\n    0x46, 0xf6, 0x01, 0xeb, 0x0c, 0x40, 0xe5, 0x08,\n    0xef, 0x02, 0xa0, 0xe1, 0x4e, 0x20, 0xa2, 0x20,\n    0x11, 0xe5, 0x81, 0xe4, 0x0f, 0x16, 0xe5, 0x09,\n    0x17, 0xe5, 0x12, 0x12, 0x13, 0x40, 0xe5, 0x43,\n    0x56, 0x4a, 0xe5, 0x00, 0xc0, 0xe5, 0x05, 0x00,\n    0x65, 0x46, 0xe0, 0x03, 0xe5, 0x0a, 0x46, 0x36,\n    0xe0, 0x01, 0xe5, 0x0a, 0x26, 0xe0, 0x04, 0xe5,\n    0x05, 0x00, 0x45, 0x00, 0x26, 0xe0, 0x04, 0xe5,\n    0x2c, 0x26, 0x07, 0xc6, 0xe7, 0x00, 0x06, 0x27,\n    0xe6, 0x03, 0x56, 0x04, 0x56, 0x0d, 0x05, 0x06,\n    0x20, 0xe9, 0x02, 0xa0, 0xeb, 0x02, 0xa0, 0xb6,\n    0x11, 0x76, 0x46, 0x1b, 0x00, 0xe9, 0x02, 0xa0,\n    0xe5, 0x1b, 0x04, 0xe5, 0x2d, 0xc0, 0x85, 0x26,\n    0xe5, 0x1a, 0x06, 0x05, 0x80, 0xe5, 0x3e, 0xe0,\n    0x02, 0xe5, 0x17, 0x00, 0x46, 0x67, 0x26, 0x47,\n    0x60, 0x27, 0x06, 0xa7, 0x46, 0x60, 0x0f, 0x40,\n    0x36, 0xe9, 0x02, 0xe5, 0x16, 0x20, 0x85, 0xe0,\n    0x03, 0xe5, 0x24, 0x60, 0xe5, 0x12, 0xa0, 0xe9,\n    0x02, 0x0b, 0x40, 0xef, 0x1a, 0xe5, 0x0f, 0x26,\n    0x27, 0x06, 0x20, 0x36, 0xe5, 0x2d, 0x07, 0x06,\n    0x07, 0xc6, 0x00, 0x06, 0x07, 0x06, 0x27, 0xe6,\n    0x00, 0xa7, 0xe6, 0x02, 0x20, 0x06, 0xe9, 0x02,\n    0xa0, 0xe9, 0x02, 0xa0, 0xd6, 0x04, 0xb6, 0x20,\n    0xe6, 0x06, 0x08, 0x26, 0xe0, 0x37, 0x66, 0x07,\n    0xe5, 0x27, 0x06, 0x07, 0x86, 0x07, 0x06, 0x87,\n    0x06, 0x27, 0xc5, 0x60, 0xe9, 0x02, 0xd6, 0xef,\n    0x02, 0xe6, 0x01, 0xef, 0x01, 0x40, 0x26, 0x07,\n    0xe5, 0x16, 0x07, 0x66, 0x27, 0x26, 0x07, 0x46,\n    0x25, 0xe9, 0x02, 0xe5, 0x24, 0x06, 0x07, 0x26,\n    0x47, 0x06, 0x07, 0x46, 0x27, 0xe0, 0x00, 0x76,\n    0xe5, 0x1c, 0xe7, 0x00, 0xe6, 0x00, 0x27, 0x26,\n    0x40, 0x96, 0xe9, 0x02, 0x40, 0x45, 0xe9, 0x02,\n    0xe5, 0x16, 0xa4, 0x36, 0xe2, 0x01, 0xc0, 0xe1,\n    0x23, 0x20, 0x41, 0xf6, 0x00, 0xe0, 0x00, 0x46,\n    0x16, 0xe6, 0x05, 0x07, 0xc6, 0x65, 0x06, 0xa5,\n    0x06, 0x25, 0x07, 0x26, 0x05, 0x80, 0xe2, 0x24,\n    0xe4, 0x37, 0xe2, 0x05, 0x04, 0xe2, 0x1a, 0xe4,\n    0x1d, 0xe6, 0x32, 0x00, 0x86, 0xff, 0x80, 0x0e,\n    0xe2, 0x00, 0xff, 0x5a, 0xe2, 0x00, 0xe1, 0x00,\n    0xa2, 0x20, 0xa1, 0x20, 0xe2, 0x00, 0xe1, 0x00,\n    0xe2, 0x00, 0xe1, 0x00, 0xa2, 0x20, 0xa1, 0x20,\n    0xe2, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,\n    0x00, 0x3f, 0xc2, 0xe1, 0x00, 0xe2, 0x06, 0x20,\n    0xe2, 0x00, 0xe3, 0x00, 0xe2, 0x00, 0xe3, 0x00,\n    0xe2, 0x00, 0xe3, 0x00, 0x82, 0x00, 0x22, 0x61,\n    0x03, 0x0e, 0x02, 0x4e, 0x42, 0x00, 0x22, 0x61,\n    0x03, 0x4e, 0x62, 0x20, 0x22, 0x61, 0x00, 0x4e,\n    0xe2, 0x00, 0x81, 0x4e, 0x20, 0x42, 0x00, 0x22,\n    0x61, 0x03, 0x2e, 0x00, 0xf7, 0x03, 0x9b, 0xb1,\n    0x36, 0x14, 0x15, 0x12, 0x34, 0x15, 0x12, 0x14,\n    0xf6, 0x00, 0x18, 0x19, 0x9b, 0x17, 0xf6, 0x01,\n    0x14, 0x15, 0x76, 0x30, 0x56, 0x0c, 0x12, 0x13,\n    0xf6, 0x03, 0x0c, 0x16, 0x10, 0xf6, 0x02, 0x17,\n    0x9b, 0x00, 0xfb, 0x02, 0x0b, 0x04, 0x20, 0xab,\n    0x4c, 0x12, 0x13, 0x04, 0xeb, 0x02, 0x4c, 0x12,\n    0x13, 0x00, 0xe4, 0x05, 0x40, 0xed, 0x18, 0xe0,\n    0x08, 0xe6, 0x05, 0x68, 0x06, 0x48, 0xe6, 0x04,\n    0xe0, 0x07, 0x2f, 0x01, 0x6f, 0x01, 0x2f, 0x02,\n    0x41, 0x22, 0x41, 0x02, 0x0f, 0x01, 0x2f, 0x0c,\n    0x81, 0xaf, 0x01, 0x0f, 0x01, 0x0f, 0x01, 0x0f,\n    0x61, 0x0f, 0x02, 0x61, 0x02, 0x65, 0x02, 0x2f,\n    0x22, 0x21, 0x8c, 0x3f, 0x42, 0x0f, 0x0c, 0x2f,\n    0x02, 0x0f, 0xeb, 0x08, 0xea, 0x1b, 0x3f, 0x6a,\n    0x0b, 0x2f, 0x60, 0x8c, 0x8f, 0x2c, 0x6f, 0x0c,\n    0x2f, 0x0c, 0x2f, 0x0c, 0xcf, 0x0c, 0xef, 0x17,\n    0x2c, 0x2f, 0x0c, 0x0f, 0x0c, 0xef, 0x17, 0xec,\n    0x80, 0x84, 0xef, 0x00, 0x12, 0x13, 0x12, 0x13,\n    0xef, 0x0c, 0x2c, 0xcf, 0x12, 0x13, 0xef, 0x49,\n    0x0c, 0xef, 0x16, 0xec, 0x11, 0xef, 0x20, 0xac,\n    0xef, 0x3d, 0xe0, 0x11, 0xef, 0x03, 0xe0, 0x0d,\n    0xeb, 0x34, 0xef, 0x46, 0xeb, 0x0e, 0xef, 0x80,\n    0x2f, 0x0c, 0xef, 0x01, 0x0c, 0xef, 0x2e, 0xec,\n    0x00, 0xef, 0x67, 0x0c, 0xef, 0x80, 0x70, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0xeb, 0x16, 0xef,\n    0x24, 0x8c, 0x12, 0x13, 0xec, 0x17, 0x12, 0x13,\n    0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13,\n    0xec, 0x08, 0xef, 0x80, 0x78, 0xec, 0x7b, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0xec, 0x37, 0x12,\n    0x13, 0x12, 0x13, 0xec, 0x18, 0x12, 0x13, 0xec,\n    0x80, 0x7a, 0xef, 0x28, 0xec, 0x0d, 0x2f, 0xac,\n    0xef, 0x1f, 0x20, 0xef, 0x18, 0x00, 0xef, 0x61,\n    0xe1, 0x27, 0x00, 0xe2, 0x27, 0x00, 0x5f, 0x21,\n    0x22, 0xdf, 0x41, 0x02, 0x3f, 0x02, 0x3f, 0x82,\n    0x24, 0x41, 0x02, 0xff, 0x5a, 0x02, 0xaf, 0x7f,\n    0x46, 0x3f, 0x80, 0x76, 0x0b, 0x36, 0xe2, 0x1e,\n    0x00, 0x02, 0x80, 0x02, 0x20, 0xe5, 0x30, 0xc0,\n    0x04, 0x16, 0xe0, 0x06, 0x06, 0xe5, 0x0f, 0xe0,\n    0x01, 0xc5, 0x00, 0xc5, 0x00, 0xc5, 0x00, 0xc5,\n    0x00, 0xc5, 0x00, 0xc5, 0x00, 0xc5, 0x00, 0xc5,\n    0x00, 0xe6, 0x18, 0x36, 0x14, 0x15, 0x14, 0x15,\n    0x56, 0x14, 0x15, 0x16, 0x14, 0x15, 0xf6, 0x01,\n    0x11, 0x36, 0x11, 0x16, 0x14, 0x15, 0x36, 0x14,\n    0x15, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12,\n    0x13, 0x96, 0x04, 0xf6, 0x02, 0x31, 0x76, 0x11,\n    0x16, 0x12, 0xf6, 0x05, 0x2f, 0x16, 0xe0, 0x25,\n    0xef, 0x12, 0x00, 0xef, 0x51, 0xe0, 0x04, 0xef,\n    0x80, 0x4e, 0xe0, 0x12, 0xef, 0x04, 0x60, 0x17,\n    0x56, 0x0f, 0x04, 0x05, 0x0a, 0x12, 0x13, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x2f,\n    0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13,\n    0x11, 0x12, 0x33, 0x0f, 0xea, 0x01, 0x66, 0x27,\n    0x11, 0x84, 0x2f, 0x4a, 0x04, 0x05, 0x16, 0x2f,\n    0x00, 0xe5, 0x4e, 0x20, 0x26, 0x2e, 0x24, 0x05,\n    0x11, 0xe5, 0x52, 0x16, 0x44, 0x05, 0x80, 0xe5,\n    0x23, 0x00, 0xe5, 0x56, 0x00, 0x2f, 0x6b, 0xef,\n    0x02, 0xe5, 0x18, 0xef, 0x1c, 0xe0, 0x04, 0xe5,\n    0x08, 0xef, 0x17, 0x00, 0xeb, 0x02, 0xef, 0x16,\n    0xeb, 0x00, 0x0f, 0xeb, 0x07, 0xef, 0x18, 0xeb,\n    0x02, 0xef, 0x1f, 0xeb, 0x07, 0xef, 0x80, 0xb8,\n    0xe5, 0x99, 0x38, 0xef, 0x38, 0xe5, 0xc0, 0x11,\n    0x75, 0x40, 0xe5, 0x0d, 0x04, 0xe5, 0x83, 0xef,\n    0x40, 0xef, 0x2f, 0xe0, 0x01, 0xe5, 0x20, 0xa4,\n    0x36, 0xe5, 0x80, 0x84, 0x04, 0x56, 0xe5, 0x08,\n    0xe9, 0x02, 0x25, 0xe0, 0x0c, 0xff, 0x26, 0x05,\n    0x06, 0x48, 0x16, 0xe6, 0x02, 0x16, 0x04, 0xff,\n    0x14, 0x24, 0x26, 0xe5, 0x3e, 0xea, 0x02, 0x26,\n    0xb6, 0xe0, 0x00, 0xee, 0x0f, 0xe4, 0x01, 0x2e,\n    0xff, 0x06, 0x22, 0xff, 0x36, 0x04, 0xe2, 0x00,\n    0x9f, 0xff, 0x02, 0x04, 0x2e, 0x7f, 0x05, 0x7f,\n    0x22, 0xff, 0x0d, 0x61, 0x02, 0x81, 0x02, 0xff,\n    0x02, 0x20, 0x5f, 0x41, 0x02, 0x3f, 0xe0, 0x22,\n    0x3f, 0x05, 0x24, 0x02, 0xc5, 0x06, 0x45, 0x06,\n    0x65, 0x06, 0xe5, 0x0f, 0x27, 0x26, 0x07, 0x6f,\n    0x06, 0x40, 0xab, 0x2f, 0x0d, 0x0f, 0xa0, 0xe5,\n    0x2c, 0x76, 0xe0, 0x00, 0x27, 0xe5, 0x2a, 0xe7,\n    0x08, 0x26, 0xe0, 0x00, 0x36, 0xe9, 0x02, 0xa0,\n    0xe6, 0x0a, 0xa5, 0x56, 0x05, 0x16, 0x25, 0x06,\n    0xe9, 0x02, 0xe5, 0x14, 0xe6, 0x00, 0x36, 0xe5,\n    0x0f, 0xe6, 0x03, 0x27, 0xe0, 0x03, 0x16, 0xe5,\n    0x15, 0x40, 0x46, 0x07, 0xe5, 0x27, 0x06, 0x27,\n    0x66, 0x27, 0x26, 0x47, 0xf6, 0x05, 0x00, 0x04,\n    0xe9, 0x02, 0x60, 0x36, 0x85, 0x06, 0x04, 0xe5,\n    0x01, 0xe9, 0x02, 0x85, 0x00, 0xe5, 0x21, 0xa6,\n    0x27, 0x26, 0x27, 0x26, 0xe0, 0x01, 0x45, 0x06,\n    0xe5, 0x00, 0x06, 0x07, 0x20, 0xe9, 0x02, 0x20,\n    0x76, 0xe5, 0x08, 0x04, 0xa5, 0x4f, 0x05, 0x07,\n    0x06, 0x07, 0xe5, 0x2a, 0x06, 0x05, 0x46, 0x25,\n    0x26, 0x85, 0x26, 0x05, 0x06, 0x05, 0xe0, 0x10,\n    0x25, 0x04, 0x36, 0xe5, 0x03, 0x07, 0x26, 0x27,\n    0x36, 0x05, 0x24, 0x07, 0x06, 0xe0, 0x02, 0xa5,\n    0x20, 0xa5, 0x20, 0xa5, 0xe0, 0x01, 0xc5, 0x00,\n    0xc5, 0x00, 0xe2, 0x23, 0x0e, 0x64, 0xe2, 0x01,\n    0x04, 0x2e, 0x60, 0xe2, 0x48, 0xe5, 0x1b, 0x27,\n    0x06, 0x27, 0x06, 0x27, 0x16, 0x07, 0x06, 0x20,\n    0xe9, 0x02, 0xa0, 0xe5, 0xab, 0x1c, 0xe0, 0x04,\n    0xe5, 0x0f, 0x60, 0xe5, 0x29, 0x60, 0xfc, 0x87,\n    0x78, 0xfd, 0x98, 0x78, 0xe5, 0x80, 0xe6, 0x20,\n    0xe5, 0x62, 0xe0, 0x1e, 0xc2, 0xe0, 0x04, 0x82,\n    0x80, 0x05, 0x06, 0xe5, 0x02, 0x0c, 0xe5, 0x05,\n    0x00, 0x85, 0x00, 0x05, 0x00, 0x25, 0x00, 0x25,\n    0x00, 0xe5, 0x64, 0xee, 0x08, 0xe0, 0x09, 0xe5,\n    0x80, 0xe3, 0x13, 0x12, 0xe0, 0x08, 0xe5, 0x38,\n    0x20, 0xe5, 0x2e, 0xe0, 0x20, 0xe5, 0x04, 0x0d,\n    0x0f, 0x20, 0xe6, 0x08, 0xd6, 0x12, 0x13, 0x16,\n    0xa0, 0xe6, 0x08, 0x16, 0x31, 0x30, 0x12, 0x13,\n    0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x12, 0x13,\n    0x12, 0x13, 0x12, 0x13, 0x12, 0x13, 0x36, 0x12,\n    0x13, 0x76, 0x50, 0x56, 0x00, 0x76, 0x11, 0x12,\n    0x13, 0x12, 0x13, 0x12, 0x13, 0x56, 0x0c, 0x11,\n    0x4c, 0x00, 0x16, 0x0d, 0x36, 0x60, 0x85, 0x00,\n    0xe5, 0x7f, 0x20, 0x1b, 0x00, 0x56, 0x0d, 0x56,\n    0x12, 0x13, 0x16, 0x0c, 0x16, 0x11, 0x36, 0xe9,\n    0x02, 0x36, 0x4c, 0x36, 0xe1, 0x12, 0x12, 0x16,\n    0x13, 0x0e, 0x10, 0x0e, 0xe2, 0x12, 0x12, 0x0c,\n    0x13, 0x0c, 0x12, 0x13, 0x16, 0x12, 0x13, 0x36,\n    0xe5, 0x02, 0x04, 0xe5, 0x25, 0x24, 0xe5, 0x17,\n    0x40, 0xa5, 0x20, 0xa5, 0x20, 0xa5, 0x20, 0x45,\n    0x40, 0x2d, 0x0c, 0x0e, 0x0f, 0x2d, 0x00, 0x0f,\n    0x6c, 0x2f, 0xe0, 0x02, 0x5b, 0x2f, 0x20, 0xe5,\n    0x04, 0x00, 0xe5, 0x12, 0x00, 0xe5, 0x0b, 0x00,\n    0x25, 0x00, 0xe5, 0x07, 0x20, 0xe5, 0x06, 0xe0,\n    0x1a, 0xe5, 0x73, 0x80, 0x56, 0x60, 0xeb, 0x25,\n    0x40, 0xef, 0x01, 0xea, 0x2d, 0x6b, 0xef, 0x09,\n    0x2b, 0x4f, 0x00, 0xef, 0x05, 0x40, 0x0f, 0xe0,\n    0x27, 0xef, 0x25, 0x06, 0xe0, 0x7a, 0xe5, 0x15,\n    0x40, 0xe5, 0x29, 0xe0, 0x07, 0x06, 0xeb, 0x13,\n    0x60, 0xe5, 0x18, 0x6b, 0xe0, 0x01, 0xe5, 0x0c,\n    0x0a, 0xe5, 0x00, 0x0a, 0x80, 0xe5, 0x1e, 0x86,\n    0x80, 0xe5, 0x16, 0x00, 0x16, 0xe5, 0x1c, 0x60,\n    0xe5, 0x00, 0x16, 0x8a, 0xe0, 0x22, 0xe1, 0x20,\n    0xe2, 0x20, 0xe5, 0x46, 0x20, 0xe9, 0x02, 0xa0,\n    0xe1, 0x1c, 0x60, 0xe2, 0x1c, 0x60, 0xe5, 0x20,\n    0xe0, 0x00, 0xe5, 0x2c, 0xe0, 0x03, 0x16, 0xe0,\n    0x80, 0x08, 0xe5, 0x80, 0xaf, 0xe0, 0x01, 0xe5,\n    0x0e, 0xe0, 0x02, 0xe5, 0x00, 0xe0, 0x80, 0x10,\n    0xa5, 0x20, 0x05, 0x00, 0xe5, 0x24, 0x00, 0x25,\n    0x40, 0x05, 0x20, 0xe5, 0x0f, 0x00, 0x16, 0xeb,\n    0x00, 0xe5, 0x0f, 0x2f, 0xcb, 0xe5, 0x17, 0xe0,\n    0x00, 0xeb, 0x01, 0xe0, 0x28, 0xe5, 0x0b, 0x00,\n    0x25, 0x80, 0x8b, 0xe5, 0x0e, 0xab, 0x40, 0x16,\n    0xe5, 0x12, 0x80, 0x16, 0xe0, 0x38, 0xe5, 0x30,\n    0x60, 0x2b, 0x25, 0xeb, 0x08, 0x20, 0xeb, 0x26,\n    0x05, 0x46, 0x00, 0x26, 0x80, 0x66, 0x65, 0x00,\n    0x45, 0x00, 0xe5, 0x15, 0x20, 0x46, 0x60, 0x06,\n    0xeb, 0x01, 0xc0, 0xf6, 0x01, 0xc0, 0xe5, 0x15,\n    0x2b, 0x16, 0xe5, 0x15, 0x4b, 0xe0, 0x18, 0xe5,\n    0x00, 0x0f, 0xe5, 0x14, 0x26, 0x60, 0x8b, 0xd6,\n    0xe0, 0x01, 0xe5, 0x2e, 0x40, 0xd6, 0xe5, 0x0e,\n    0x20, 0xeb, 0x00, 0xe5, 0x0b, 0x80, 0xeb, 0x00,\n    0xe5, 0x0a, 0xc0, 0x76, 0xe0, 0x04, 0xcb, 0xe0,\n    0x48, 0xe5, 0x41, 0xe0, 0x2f, 0xe1, 0x2b, 0xe0,\n    0x05, 0xe2, 0x2b, 0xc0, 0xab, 0xe5, 0x1c, 0x66,\n    0xe0, 0x00, 0xe9, 0x02, 0xe0, 0x80, 0x9e, 0xeb,\n    0x17, 0x00, 0xe5, 0x22, 0x00, 0x26, 0x11, 0x20,\n    0x25, 0xe0, 0x46, 0xe5, 0x15, 0xeb, 0x02, 0x05,\n    0xe0, 0x00, 0xe5, 0x0e, 0xe6, 0x03, 0x6b, 0x96,\n    0xe0, 0x4e, 0xe5, 0x0d, 0xcb, 0xe0, 0x0c, 0xe5,\n    0x0f, 0xe0, 0x01, 0x07, 0x06, 0x07, 0xe5, 0x2d,\n    0xe6, 0x07, 0xd6, 0x60, 0xeb, 0x0c, 0xe9, 0x02,\n    0xe0, 0x07, 0x46, 0x07, 0xe5, 0x25, 0x47, 0x66,\n    0x27, 0x26, 0x36, 0x1b, 0x76, 0xe0, 0x03, 0x1b,\n    0x20, 0xe5, 0x11, 0xc0, 0xe9, 0x02, 0xa0, 0x46,\n    0xe5, 0x1c, 0x86, 0x07, 0xe6, 0x00, 0x00, 0xe9,\n    0x02, 0x76, 0x05, 0x27, 0x05, 0xe0, 0x00, 0xe5,\n    0x1b, 0x06, 0x36, 0x05, 0xe0, 0x01, 0x26, 0x07,\n    0xe5, 0x28, 0x47, 0xe6, 0x01, 0x27, 0x65, 0x76,\n    0x66, 0x16, 0x07, 0x06, 0xe9, 0x02, 0x05, 0x16,\n    0x05, 0x56, 0x00, 0xeb, 0x0c, 0xe0, 0x03, 0xe5,\n    0x0a, 0x00, 0xe5, 0x11, 0x47, 0x46, 0x27, 0x06,\n    0x07, 0x26, 0xb6, 0x06, 0xe0, 0x39, 0xc5, 0x00,\n    0x05, 0x00, 0x65, 0x00, 0xe5, 0x07, 0x00, 0xe5,\n    0x02, 0x16, 0xa0, 0xe5, 0x27, 0x06, 0x47, 0xe6,\n    0x00, 0x80, 0xe9, 0x02, 0xa0, 0x26, 0x27, 0x00,\n    0xe5, 0x00, 0x20, 0x25, 0x20, 0xe5, 0x0e, 0x00,\n    0xc5, 0x00, 0x25, 0x00, 0x85, 0x00, 0x26, 0x05,\n    0x27, 0x06, 0x67, 0x20, 0x27, 0x20, 0x47, 0x20,\n    0x05, 0xa0, 0x07, 0x80, 0x85, 0x27, 0x20, 0xc6,\n    0x40, 0x86, 0xe0, 0x80, 0x03, 0xe5, 0x2d, 0x47,\n    0xe6, 0x00, 0x27, 0x46, 0x07, 0x06, 0x65, 0x96,\n    0xe9, 0x02, 0x36, 0x00, 0x16, 0x06, 0x45, 0xe0,\n    0x16, 0xe5, 0x28, 0x47, 0xa6, 0x07, 0x06, 0x67,\n    0x26, 0x07, 0x26, 0x25, 0x16, 0x05, 0xe0, 0x00,\n    0xe9, 0x02, 0xe0, 0x80, 0x1e, 0xe5, 0x27, 0x47,\n    0x66, 0x20, 0x67, 0x26, 0x07, 0x26, 0xf6, 0x0f,\n    0x65, 0x26, 0xe0, 0x1a, 0xe5, 0x28, 0x47, 0xe6,\n    0x00, 0x27, 0x06, 0x07, 0x26, 0x56, 0x05, 0xe0,\n    0x03, 0xe9, 0x02, 0xa0, 0xf6, 0x05, 0xe0, 0x0b,\n    0xe5, 0x23, 0x06, 0x07, 0x06, 0x27, 0xa6, 0x07,\n    0x06, 0x05, 0xc0, 0xe9, 0x02, 0xe0, 0x2e, 0xe5,\n    0x13, 0x20, 0x46, 0x27, 0x66, 0x07, 0x86, 0x60,\n    0xe9, 0x02, 0x2b, 0x56, 0x0f, 0xe0, 0x80, 0x38,\n    0xe5, 0x24, 0x47, 0xe6, 0x01, 0x07, 0x26, 0x16,\n    0xe0, 0x5c, 0xe1, 0x18, 0xe2, 0x18, 0xe9, 0x02,\n    0xeb, 0x01, 0xe0, 0x04, 0xe5, 0x00, 0x20, 0x05,\n    0x20, 0xe5, 0x00, 0x00, 0x25, 0x00, 0xe5, 0x10,\n    0xa7, 0x00, 0x27, 0x20, 0x26, 0x07, 0x06, 0x05,\n    0x07, 0x05, 0x07, 0x06, 0x56, 0xe0, 0x01, 0xe9,\n    0x02, 0xe0, 0x3e, 0xe5, 0x00, 0x20, 0xe5, 0x1f,\n    0x47, 0x66, 0x20, 0x26, 0x67, 0x06, 0x05, 0x16,\n    0x05, 0x07, 0xe0, 0x13, 0x05, 0xe6, 0x02, 0xe5,\n    0x20, 0xa6, 0x07, 0x05, 0x66, 0xf6, 0x00, 0x06,\n    0xe0, 0x00, 0x05, 0xa6, 0x27, 0x46, 0xe5, 0x26,\n    0xe6, 0x05, 0x07, 0x26, 0x56, 0x05, 0x96, 0xe0,\n    0x15, 0xe5, 0x31, 0xe0, 0x80, 0x7f, 0xe5, 0x01,\n    0x00, 0xe5, 0x1d, 0x07, 0xc6, 0x00, 0xa6, 0x07,\n    0x06, 0x05, 0x96, 0xe0, 0x02, 0xe9, 0x02, 0xeb,\n    0x0b, 0x40, 0x36, 0xe5, 0x16, 0x20, 0xe6, 0x0e,\n    0x00, 0x07, 0xc6, 0x07, 0x26, 0x07, 0x26, 0xe0,\n    0x41, 0xc5, 0x00, 0x25, 0x00, 0xe5, 0x1e, 0xa6,\n    0x40, 0x06, 0x00, 0x26, 0x00, 0xc6, 0x05, 0x06,\n    0xe0, 0x00, 0xe9, 0x02, 0xa0, 0xa5, 0x00, 0x25,\n    0x00, 0xe5, 0x18, 0x87, 0x00, 0x26, 0x00, 0x27,\n    0x06, 0x07, 0x06, 0x05, 0xc0, 0xe9, 0x02, 0xe0,\n    0x80, 0xae, 0xe5, 0x0b, 0x26, 0x27, 0x36, 0xe0,\n    0x80, 0x2f, 0x05, 0xe0, 0x07, 0xeb, 0x0d, 0xef,\n    0x00, 0x6d, 0xef, 0x09, 0xe0, 0x05, 0x16, 0xe5,\n    0x83, 0x12, 0xe0, 0x5e, 0xea, 0x67, 0x00, 0x96,\n    0xe0, 0x03, 0xe5, 0x80, 0x3c, 0xe0, 0x8a, 0x34,\n    0xe5, 0x83, 0xa7, 0x00, 0xfb, 0x01, 0xe0, 0x8f,\n    0x3f, 0xe5, 0x81, 0xbf, 0xe0, 0xa1, 0x31, 0xe5,\n    0x81, 0xb1, 0xc0, 0xe5, 0x17, 0x00, 0xe9, 0x02,\n    0x60, 0x36, 0xe0, 0x58, 0xe5, 0x16, 0x20, 0x86,\n    0x16, 0xe0, 0x02, 0xe5, 0x28, 0xc6, 0x96, 0x6f,\n    0x64, 0x16, 0x0f, 0xe0, 0x02, 0xe9, 0x02, 0x00,\n    0xcb, 0x00, 0xe5, 0x0d, 0x80, 0xe5, 0x0b, 0xe0,\n    0x82, 0x28, 0xe1, 0x18, 0xe2, 0x18, 0xeb, 0x0f,\n    0x76, 0xe0, 0x5d, 0xe5, 0x43, 0x60, 0x06, 0x05,\n    0xe7, 0x2f, 0xc0, 0x66, 0xe4, 0x05, 0xe0, 0x38,\n    0x24, 0x16, 0x04, 0x06, 0xe0, 0x03, 0x27, 0xe0,\n    0x06, 0xe5, 0x97, 0x70, 0xe0, 0x00, 0xe5, 0x84,\n    0x4e, 0xe0, 0x22, 0xe5, 0x01, 0xe0, 0xa2, 0x6f,\n    0xe5, 0x80, 0x97, 0xe0, 0x29, 0x45, 0xe0, 0x09,\n    0x65, 0xe0, 0x00, 0xe5, 0x81, 0x04, 0xe0, 0x88,\n    0x7c, 0xe5, 0x63, 0x80, 0xe5, 0x05, 0x40, 0xe5,\n    0x01, 0xc0, 0xe5, 0x02, 0x20, 0x0f, 0x26, 0x16,\n    0x7b, 0xe0, 0x92, 0xd4, 0xef, 0x80, 0x6e, 0xe0,\n    0x02, 0xef, 0x1f, 0x20, 0xef, 0x34, 0x27, 0x46,\n    0x4f, 0xa7, 0xfb, 0x00, 0xe6, 0x00, 0x2f, 0xc6,\n    0xef, 0x16, 0x66, 0xef, 0x33, 0xe0, 0x0f, 0xef,\n    0x3a, 0x46, 0x0f, 0xe0, 0x80, 0x12, 0xeb, 0x0c,\n    0xe0, 0x04, 0xef, 0x4f, 0xe0, 0x01, 0xeb, 0x11,\n    0xe0, 0x7f, 0xe1, 0x12, 0xe2, 0x12, 0xe1, 0x12,\n    0xc2, 0x00, 0xe2, 0x0a, 0xe1, 0x12, 0xe2, 0x12,\n    0x01, 0x00, 0x21, 0x20, 0x01, 0x20, 0x21, 0x20,\n    0x61, 0x00, 0xe1, 0x00, 0x62, 0x00, 0x02, 0x00,\n    0xc2, 0x00, 0xe2, 0x03, 0xe1, 0x12, 0xe2, 0x12,\n    0x21, 0x00, 0x61, 0x20, 0xe1, 0x00, 0x00, 0xc1,\n    0x00, 0xe2, 0x12, 0x21, 0x00, 0x61, 0x00, 0x81,\n    0x00, 0x01, 0x40, 0xc1, 0x00, 0xe2, 0x12, 0xe1,\n    0x12, 0xe2, 0x12, 0xe1, 0x12, 0xe2, 0x12, 0xe1,\n    0x12, 0xe2, 0x12, 0xe1, 0x12, 0xe2, 0x12, 0xe1,\n    0x12, 0xe2, 0x12, 0xe1, 0x12, 0xe2, 0x14, 0x20,\n    0xe1, 0x11, 0x0c, 0xe2, 0x11, 0x0c, 0xa2, 0xe1,\n    0x11, 0x0c, 0xe2, 0x11, 0x0c, 0xa2, 0xe1, 0x11,\n    0x0c, 0xe2, 0x11, 0x0c, 0xa2, 0xe1, 0x11, 0x0c,\n    0xe2, 0x11, 0x0c, 0xa2, 0xe1, 0x11, 0x0c, 0xe2,\n    0x11, 0x0c, 0xa2, 0x3f, 0x20, 0xe9, 0x2a, 0xef,\n    0x81, 0x78, 0xe6, 0x2f, 0x6f, 0xe6, 0x2a, 0xef,\n    0x00, 0x06, 0xef, 0x06, 0x06, 0x2f, 0x96, 0xe0,\n    0x07, 0x86, 0x00, 0xe6, 0x07, 0xe0, 0x84, 0xc8,\n    0xc6, 0x00, 0xe6, 0x09, 0x20, 0xc6, 0x00, 0x26,\n    0x00, 0x86, 0xe0, 0x80, 0x4d, 0xe5, 0x25, 0x40,\n    0xc6, 0xc4, 0x20, 0xe9, 0x02, 0x60, 0x05, 0x0f,\n    0xe0, 0x80, 0xe8, 0xe5, 0x24, 0x66, 0xe9, 0x02,\n    0x80, 0x0d, 0xe0, 0x84, 0x78, 0xe5, 0x80, 0x3d,\n    0x20, 0xeb, 0x01, 0xc6, 0xe0, 0x21, 0xe1, 0x1a,\n    0xe2, 0x1a, 0xc6, 0x04, 0x60, 0xe9, 0x02, 0x60,\n    0x36, 0xe0, 0x82, 0x89, 0xeb, 0x33, 0x0f, 0x4b,\n    0x0d, 0x6b, 0xe0, 0x44, 0xeb, 0x25, 0x0f, 0xeb,\n    0x07, 0xe0, 0x80, 0x3a, 0x65, 0x00, 0xe5, 0x13,\n    0x00, 0x25, 0x00, 0x05, 0x20, 0x05, 0x00, 0xe5,\n    0x02, 0x00, 0x65, 0x00, 0x05, 0x00, 0x05, 0xa0,\n    0x05, 0x60, 0x05, 0x00, 0x05, 0x00, 0x05, 0x00,\n    0x45, 0x00, 0x25, 0x00, 0x05, 0x20, 0x05, 0x00,\n    0x05, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05, 0x00,\n    0x25, 0x00, 0x05, 0x20, 0x65, 0x00, 0xc5, 0x00,\n    0x65, 0x00, 0x65, 0x00, 0x05, 0x00, 0xe5, 0x02,\n    0x00, 0xe5, 0x09, 0x80, 0x45, 0x00, 0x85, 0x00,\n    0xe5, 0x09, 0xe0, 0x2c, 0x2c, 0xe0, 0x80, 0x86,\n    0xef, 0x24, 0x60, 0xef, 0x5c, 0xe0, 0x04, 0xef,\n    0x07, 0x20, 0xef, 0x07, 0x00, 0xef, 0x07, 0x00,\n    0xef, 0x1d, 0xe0, 0x02, 0xeb, 0x05, 0xef, 0x80,\n    0x19, 0xe0, 0x30, 0xef, 0x15, 0xe0, 0x05, 0xef,\n    0x24, 0x60, 0xef, 0x01, 0xc0, 0x2f, 0xe0, 0x06,\n    0xaf, 0xe0, 0x80, 0x12, 0xef, 0x80, 0x73, 0x8e,\n    0xef, 0x82, 0x50, 0xe0, 0x00, 0xef, 0x05, 0x40,\n    0xef, 0x05, 0x40, 0xef, 0x6c, 0xe0, 0x04, 0xef,\n    0x51, 0xc0, 0xef, 0x04, 0xe0, 0x0c, 0xef, 0x04,\n    0x60, 0xef, 0x30, 0xe0, 0x00, 0xef, 0x02, 0xa0,\n    0xef, 0x20, 0xe0, 0x00, 0xef, 0x16, 0x20, 0x2f,\n    0xe0, 0x46, 0xef, 0x71, 0x00, 0xef, 0x4a, 0x00,\n    0xef, 0x7f, 0xe0, 0x04, 0xef, 0x06, 0x20, 0x8f,\n    0x40, 0x4f, 0x80, 0xcf, 0xe0, 0x01, 0xef, 0x11,\n    0xc0, 0xcf, 0xe0, 0x01, 0x4f, 0xe0, 0x05, 0xcf,\n    0xe0, 0x21, 0xef, 0x80, 0x0b, 0x00, 0xef, 0x2f,\n    0xe0, 0x1d, 0xe9, 0x02, 0xe0, 0x83, 0x7e, 0xe5,\n    0xc0, 0x66, 0x56, 0xe0, 0x1a, 0xe5, 0x8f, 0xad,\n    0xe0, 0x03, 0xe5, 0x80, 0x56, 0x20, 0xe5, 0x95,\n    0xfa, 0xe0, 0x06, 0xe5, 0x9c, 0xa9, 0xe0, 0x8b,\n    0x97, 0xe5, 0x81, 0x96, 0xe0, 0x85, 0x5a, 0xe5,\n    0x92, 0xc3, 0xe0, 0xca, 0xac, 0x2e, 0x1b, 0xe0,\n    0x16, 0xfb, 0x58, 0xe0, 0x78, 0xe6, 0x80, 0x68,\n    0xe0, 0xc0, 0xbd, 0x88, 0xfd, 0xc0, 0xbf, 0x76,\n    0x20, 0xfd, 0xc0, 0xbf, 0x76, 0x20,\n};\n\ntypedef enum {\n    UNICODE_SCRIPT_Unknown,\n    UNICODE_SCRIPT_Adlam,\n    UNICODE_SCRIPT_Ahom,\n    UNICODE_SCRIPT_Anatolian_Hieroglyphs,\n    UNICODE_SCRIPT_Arabic,\n    UNICODE_SCRIPT_Armenian,\n    UNICODE_SCRIPT_Avestan,\n    UNICODE_SCRIPT_Balinese,\n    UNICODE_SCRIPT_Bamum,\n    UNICODE_SCRIPT_Bassa_Vah,\n    UNICODE_SCRIPT_Batak,\n    UNICODE_SCRIPT_Bengali,\n    UNICODE_SCRIPT_Bhaiksuki,\n    UNICODE_SCRIPT_Bopomofo,\n    UNICODE_SCRIPT_Brahmi,\n    UNICODE_SCRIPT_Braille,\n    UNICODE_SCRIPT_Buginese,\n    UNICODE_SCRIPT_Buhid,\n    UNICODE_SCRIPT_Canadian_Aboriginal,\n    UNICODE_SCRIPT_Carian,\n    UNICODE_SCRIPT_Caucasian_Albanian,\n    UNICODE_SCRIPT_Chakma,\n    UNICODE_SCRIPT_Cham,\n    UNICODE_SCRIPT_Cherokee,\n    UNICODE_SCRIPT_Chorasmian,\n    UNICODE_SCRIPT_Common,\n    UNICODE_SCRIPT_Coptic,\n    UNICODE_SCRIPT_Cuneiform,\n    UNICODE_SCRIPT_Cypriot,\n    UNICODE_SCRIPT_Cyrillic,\n    UNICODE_SCRIPT_Deseret,\n    UNICODE_SCRIPT_Devanagari,\n    UNICODE_SCRIPT_Dives_Akuru,\n    UNICODE_SCRIPT_Dogra,\n    UNICODE_SCRIPT_Duployan,\n    UNICODE_SCRIPT_Egyptian_Hieroglyphs,\n    UNICODE_SCRIPT_Elbasan,\n    UNICODE_SCRIPT_Elymaic,\n    UNICODE_SCRIPT_Ethiopic,\n    UNICODE_SCRIPT_Georgian,\n    UNICODE_SCRIPT_Glagolitic,\n    UNICODE_SCRIPT_Gothic,\n    UNICODE_SCRIPT_Grantha,\n    UNICODE_SCRIPT_Greek,\n    UNICODE_SCRIPT_Gujarati,\n    UNICODE_SCRIPT_Gunjala_Gondi,\n    UNICODE_SCRIPT_Gurmukhi,\n    UNICODE_SCRIPT_Han,\n    UNICODE_SCRIPT_Hangul,\n    UNICODE_SCRIPT_Hanifi_Rohingya,\n    UNICODE_SCRIPT_Hanunoo,\n    UNICODE_SCRIPT_Hatran,\n    UNICODE_SCRIPT_Hebrew,\n    UNICODE_SCRIPT_Hiragana,\n    UNICODE_SCRIPT_Imperial_Aramaic,\n    UNICODE_SCRIPT_Inherited,\n    UNICODE_SCRIPT_Inscriptional_Pahlavi,\n    UNICODE_SCRIPT_Inscriptional_Parthian,\n    UNICODE_SCRIPT_Javanese,\n    UNICODE_SCRIPT_Kaithi,\n    UNICODE_SCRIPT_Kannada,\n    UNICODE_SCRIPT_Katakana,\n    UNICODE_SCRIPT_Kayah_Li,\n    UNICODE_SCRIPT_Kharoshthi,\n    UNICODE_SCRIPT_Khmer,\n    UNICODE_SCRIPT_Khojki,\n    UNICODE_SCRIPT_Khitan_Small_Script,\n    UNICODE_SCRIPT_Khudawadi,\n    UNICODE_SCRIPT_Lao,\n    UNICODE_SCRIPT_Latin,\n    UNICODE_SCRIPT_Lepcha,\n    UNICODE_SCRIPT_Limbu,\n    UNICODE_SCRIPT_Linear_A,\n    UNICODE_SCRIPT_Linear_B,\n    UNICODE_SCRIPT_Lisu,\n    UNICODE_SCRIPT_Lycian,\n    UNICODE_SCRIPT_Lydian,\n    UNICODE_SCRIPT_Makasar,\n    UNICODE_SCRIPT_Mahajani,\n    UNICODE_SCRIPT_Malayalam,\n    UNICODE_SCRIPT_Mandaic,\n    UNICODE_SCRIPT_Manichaean,\n    UNICODE_SCRIPT_Marchen,\n    UNICODE_SCRIPT_Masaram_Gondi,\n    UNICODE_SCRIPT_Medefaidrin,\n    UNICODE_SCRIPT_Meetei_Mayek,\n    UNICODE_SCRIPT_Mende_Kikakui,\n    UNICODE_SCRIPT_Meroitic_Cursive,\n    UNICODE_SCRIPT_Meroitic_Hieroglyphs,\n    UNICODE_SCRIPT_Miao,\n    UNICODE_SCRIPT_Modi,\n    UNICODE_SCRIPT_Mongolian,\n    UNICODE_SCRIPT_Mro,\n    UNICODE_SCRIPT_Multani,\n    UNICODE_SCRIPT_Myanmar,\n    UNICODE_SCRIPT_Nabataean,\n    UNICODE_SCRIPT_Nandinagari,\n    UNICODE_SCRIPT_New_Tai_Lue,\n    UNICODE_SCRIPT_Newa,\n    UNICODE_SCRIPT_Nko,\n    UNICODE_SCRIPT_Nushu,\n    UNICODE_SCRIPT_Nyiakeng_Puachue_Hmong,\n    UNICODE_SCRIPT_Ogham,\n    UNICODE_SCRIPT_Ol_Chiki,\n    UNICODE_SCRIPT_Old_Hungarian,\n    UNICODE_SCRIPT_Old_Italic,\n    UNICODE_SCRIPT_Old_North_Arabian,\n    UNICODE_SCRIPT_Old_Permic,\n    UNICODE_SCRIPT_Old_Persian,\n    UNICODE_SCRIPT_Old_Sogdian,\n    UNICODE_SCRIPT_Old_South_Arabian,\n    UNICODE_SCRIPT_Old_Turkic,\n    UNICODE_SCRIPT_Oriya,\n    UNICODE_SCRIPT_Osage,\n    UNICODE_SCRIPT_Osmanya,\n    UNICODE_SCRIPT_Pahawh_Hmong,\n    UNICODE_SCRIPT_Palmyrene,\n    UNICODE_SCRIPT_Pau_Cin_Hau,\n    UNICODE_SCRIPT_Phags_Pa,\n    UNICODE_SCRIPT_Phoenician,\n    UNICODE_SCRIPT_Psalter_Pahlavi,\n    UNICODE_SCRIPT_Rejang,\n    UNICODE_SCRIPT_Runic,\n    UNICODE_SCRIPT_Samaritan,\n    UNICODE_SCRIPT_Saurashtra,\n    UNICODE_SCRIPT_Sharada,\n    UNICODE_SCRIPT_Shavian,\n    UNICODE_SCRIPT_Siddham,\n    UNICODE_SCRIPT_SignWriting,\n    UNICODE_SCRIPT_Sinhala,\n    UNICODE_SCRIPT_Sogdian,\n    UNICODE_SCRIPT_Sora_Sompeng,\n    UNICODE_SCRIPT_Soyombo,\n    UNICODE_SCRIPT_Sundanese,\n    UNICODE_SCRIPT_Syloti_Nagri,\n    UNICODE_SCRIPT_Syriac,\n    UNICODE_SCRIPT_Tagalog,\n    UNICODE_SCRIPT_Tagbanwa,\n    UNICODE_SCRIPT_Tai_Le,\n    UNICODE_SCRIPT_Tai_Tham,\n    UNICODE_SCRIPT_Tai_Viet,\n    UNICODE_SCRIPT_Takri,\n    UNICODE_SCRIPT_Tamil,\n    UNICODE_SCRIPT_Tangut,\n    UNICODE_SCRIPT_Telugu,\n    UNICODE_SCRIPT_Thaana,\n    UNICODE_SCRIPT_Thai,\n    UNICODE_SCRIPT_Tibetan,\n    UNICODE_SCRIPT_Tifinagh,\n    UNICODE_SCRIPT_Tirhuta,\n    UNICODE_SCRIPT_Ugaritic,\n    UNICODE_SCRIPT_Vai,\n    UNICODE_SCRIPT_Wancho,\n    UNICODE_SCRIPT_Warang_Citi,\n    UNICODE_SCRIPT_Yezidi,\n    UNICODE_SCRIPT_Yi,\n    UNICODE_SCRIPT_Zanabazar_Square,\n    UNICODE_SCRIPT_COUNT,\n} UnicodeScriptEnum;\n\nstatic const char unicode_script_name_table[] =\n    \"Adlam,Adlm\"                  \"\\0\"\n    \"Ahom,Ahom\"                   \"\\0\"\n    \"Anatolian_Hieroglyphs,Hluw\"  \"\\0\"\n    \"Arabic,Arab\"                 \"\\0\"\n    \"Armenian,Armn\"               \"\\0\"\n    \"Avestan,Avst\"                \"\\0\"\n    \"Balinese,Bali\"               \"\\0\"\n    \"Bamum,Bamu\"                  \"\\0\"\n    \"Bassa_Vah,Bass\"              \"\\0\"\n    \"Batak,Batk\"                  \"\\0\"\n    \"Bengali,Beng\"                \"\\0\"\n    \"Bhaiksuki,Bhks\"              \"\\0\"\n    \"Bopomofo,Bopo\"               \"\\0\"\n    \"Brahmi,Brah\"                 \"\\0\"\n    \"Braille,Brai\"                \"\\0\"\n    \"Buginese,Bugi\"               \"\\0\"\n    \"Buhid,Buhd\"                  \"\\0\"\n    \"Canadian_Aboriginal,Cans\"    \"\\0\"\n    \"Carian,Cari\"                 \"\\0\"\n    \"Caucasian_Albanian,Aghb\"     \"\\0\"\n    \"Chakma,Cakm\"                 \"\\0\"\n    \"Cham,Cham\"                   \"\\0\"\n    \"Cherokee,Cher\"               \"\\0\"\n    \"Chorasmian,Chrs\"             \"\\0\"\n    \"Common,Zyyy\"                 \"\\0\"\n    \"Coptic,Copt,Qaac\"            \"\\0\"\n    \"Cuneiform,Xsux\"              \"\\0\"\n    \"Cypriot,Cprt\"                \"\\0\"\n    \"Cyrillic,Cyrl\"               \"\\0\"\n    \"Deseret,Dsrt\"                \"\\0\"\n    \"Devanagari,Deva\"             \"\\0\"\n    \"Dives_Akuru,Diak\"            \"\\0\"\n    \"Dogra,Dogr\"                  \"\\0\"\n    \"Duployan,Dupl\"               \"\\0\"\n    \"Egyptian_Hieroglyphs,Egyp\"   \"\\0\"\n    \"Elbasan,Elba\"                \"\\0\"\n    \"Elymaic,Elym\"                \"\\0\"\n    \"Ethiopic,Ethi\"               \"\\0\"\n    \"Georgian,Geor\"               \"\\0\"\n    \"Glagolitic,Glag\"             \"\\0\"\n    \"Gothic,Goth\"                 \"\\0\"\n    \"Grantha,Gran\"                \"\\0\"\n    \"Greek,Grek\"                  \"\\0\"\n    \"Gujarati,Gujr\"               \"\\0\"\n    \"Gunjala_Gondi,Gong\"          \"\\0\"\n    \"Gurmukhi,Guru\"               \"\\0\"\n    \"Han,Hani\"                    \"\\0\"\n    \"Hangul,Hang\"                 \"\\0\"\n    \"Hanifi_Rohingya,Rohg\"        \"\\0\"\n    \"Hanunoo,Hano\"                \"\\0\"\n    \"Hatran,Hatr\"                 \"\\0\"\n    \"Hebrew,Hebr\"                 \"\\0\"\n    \"Hiragana,Hira\"               \"\\0\"\n    \"Imperial_Aramaic,Armi\"       \"\\0\"\n    \"Inherited,Zinh,Qaai\"         \"\\0\"\n    \"Inscriptional_Pahlavi,Phli\"  \"\\0\"\n    \"Inscriptional_Parthian,Prti\" \"\\0\"\n    \"Javanese,Java\"               \"\\0\"\n    \"Kaithi,Kthi\"                 \"\\0\"\n    \"Kannada,Knda\"                \"\\0\"\n    \"Katakana,Kana\"               \"\\0\"\n    \"Kayah_Li,Kali\"               \"\\0\"\n    \"Kharoshthi,Khar\"             \"\\0\"\n    \"Khmer,Khmr\"                  \"\\0\"\n    \"Khojki,Khoj\"                 \"\\0\"\n    \"Khitan_Small_Script,Kits\"    \"\\0\"\n    \"Khudawadi,Sind\"              \"\\0\"\n    \"Lao,Laoo\"                    \"\\0\"\n    \"Latin,Latn\"                  \"\\0\"\n    \"Lepcha,Lepc\"                 \"\\0\"\n    \"Limbu,Limb\"                  \"\\0\"\n    \"Linear_A,Lina\"               \"\\0\"\n    \"Linear_B,Linb\"               \"\\0\"\n    \"Lisu,Lisu\"                   \"\\0\"\n    \"Lycian,Lyci\"                 \"\\0\"\n    \"Lydian,Lydi\"                 \"\\0\"\n    \"Makasar,Maka\"                \"\\0\"\n    \"Mahajani,Mahj\"               \"\\0\"\n    \"Malayalam,Mlym\"              \"\\0\"\n    \"Mandaic,Mand\"                \"\\0\"\n    \"Manichaean,Mani\"             \"\\0\"\n    \"Marchen,Marc\"                \"\\0\"\n    \"Masaram_Gondi,Gonm\"          \"\\0\"\n    \"Medefaidrin,Medf\"            \"\\0\"\n    \"Meetei_Mayek,Mtei\"           \"\\0\"\n    \"Mende_Kikakui,Mend\"          \"\\0\"\n    \"Meroitic_Cursive,Merc\"       \"\\0\"\n    \"Meroitic_Hieroglyphs,Mero\"   \"\\0\"\n    \"Miao,Plrd\"                   \"\\0\"\n    \"Modi,Modi\"                   \"\\0\"\n    \"Mongolian,Mong\"              \"\\0\"\n    \"Mro,Mroo\"                    \"\\0\"\n    \"Multani,Mult\"                \"\\0\"\n    \"Myanmar,Mymr\"                \"\\0\"\n    \"Nabataean,Nbat\"              \"\\0\"\n    \"Nandinagari,Nand\"            \"\\0\"\n    \"New_Tai_Lue,Talu\"            \"\\0\"\n    \"Newa,Newa\"                   \"\\0\"\n    \"Nko,Nkoo\"                    \"\\0\"\n    \"Nushu,Nshu\"                  \"\\0\"\n    \"Nyiakeng_Puachue_Hmong,Hmnp\" \"\\0\"\n    \"Ogham,Ogam\"                  \"\\0\"\n    \"Ol_Chiki,Olck\"               \"\\0\"\n    \"Old_Hungarian,Hung\"          \"\\0\"\n    \"Old_Italic,Ital\"             \"\\0\"\n    \"Old_North_Arabian,Narb\"      \"\\0\"\n    \"Old_Permic,Perm\"             \"\\0\"\n    \"Old_Persian,Xpeo\"            \"\\0\"\n    \"Old_Sogdian,Sogo\"            \"\\0\"\n    \"Old_South_Arabian,Sarb\"      \"\\0\"\n    \"Old_Turkic,Orkh\"             \"\\0\"\n    \"Oriya,Orya\"                  \"\\0\"\n    \"Osage,Osge\"                  \"\\0\"\n    \"Osmanya,Osma\"                \"\\0\"\n    \"Pahawh_Hmong,Hmng\"           \"\\0\"\n    \"Palmyrene,Palm\"              \"\\0\"\n    \"Pau_Cin_Hau,Pauc\"            \"\\0\"\n    \"Phags_Pa,Phag\"               \"\\0\"\n    \"Phoenician,Phnx\"             \"\\0\"\n    \"Psalter_Pahlavi,Phlp\"        \"\\0\"\n    \"Rejang,Rjng\"                 \"\\0\"\n    \"Runic,Runr\"                  \"\\0\"\n    \"Samaritan,Samr\"              \"\\0\"\n    \"Saurashtra,Saur\"             \"\\0\"\n    \"Sharada,Shrd\"                \"\\0\"\n    \"Shavian,Shaw\"                \"\\0\"\n    \"Siddham,Sidd\"                \"\\0\"\n    \"SignWriting,Sgnw\"            \"\\0\"\n    \"Sinhala,Sinh\"                \"\\0\"\n    \"Sogdian,Sogd\"                \"\\0\"\n    \"Sora_Sompeng,Sora\"           \"\\0\"\n    \"Soyombo,Soyo\"                \"\\0\"\n    \"Sundanese,Sund\"              \"\\0\"\n    \"Syloti_Nagri,Sylo\"           \"\\0\"\n    \"Syriac,Syrc\"                 \"\\0\"\n    \"Tagalog,Tglg\"                \"\\0\"\n    \"Tagbanwa,Tagb\"               \"\\0\"\n    \"Tai_Le,Tale\"                 \"\\0\"\n    \"Tai_Tham,Lana\"               \"\\0\"\n    \"Tai_Viet,Tavt\"               \"\\0\"\n    \"Takri,Takr\"                  \"\\0\"\n    \"Tamil,Taml\"                  \"\\0\"\n    \"Tangut,Tang\"                 \"\\0\"\n    \"Telugu,Telu\"                 \"\\0\"\n    \"Thaana,Thaa\"                 \"\\0\"\n    \"Thai,Thai\"                   \"\\0\"\n    \"Tibetan,Tibt\"                \"\\0\"\n    \"Tifinagh,Tfng\"               \"\\0\"\n    \"Tirhuta,Tirh\"                \"\\0\"\n    \"Ugaritic,Ugar\"               \"\\0\"\n    \"Vai,Vaii\"                    \"\\0\"\n    \"Wancho,Wcho\"                 \"\\0\"\n    \"Warang_Citi,Wara\"            \"\\0\"\n    \"Yezidi,Yezi\"                 \"\\0\"\n    \"Yi,Yiii\"                     \"\\0\"\n    \"Zanabazar_Square,Zanb\"       \"\\0\"\n;\n\nstatic const uint8_t unicode_script_table[2609] = {\n    0xc0, 0x19, 0x99, 0x45, 0x85, 0x19, 0x99, 0x45,\n    0xae, 0x19, 0x80, 0x45, 0x8e, 0x19, 0x80, 0x45,\n    0x84, 0x19, 0x96, 0x45, 0x80, 0x19, 0x9e, 0x45,\n    0x80, 0x19, 0xe1, 0x60, 0x45, 0xa6, 0x19, 0x84,\n    0x45, 0x84, 0x19, 0x81, 0x0d, 0x93, 0x19, 0xe0,\n    0x0f, 0x37, 0x83, 0x2b, 0x80, 0x19, 0x82, 0x2b,\n    0x01, 0x83, 0x2b, 0x80, 0x19, 0x80, 0x2b, 0x03,\n    0x80, 0x2b, 0x80, 0x19, 0x80, 0x2b, 0x80, 0x19,\n    0x82, 0x2b, 0x00, 0x80, 0x2b, 0x00, 0x93, 0x2b,\n    0x00, 0xbe, 0x2b, 0x8d, 0x1a, 0x8f, 0x2b, 0xe0,\n    0x24, 0x1d, 0x81, 0x37, 0xe0, 0x48, 0x1d, 0x00,\n    0xa5, 0x05, 0x01, 0xb1, 0x05, 0x01, 0x82, 0x05,\n    0x00, 0xb6, 0x34, 0x07, 0x9a, 0x34, 0x03, 0x85,\n    0x34, 0x0a, 0x84, 0x04, 0x80, 0x19, 0x85, 0x04,\n    0x80, 0x19, 0x8d, 0x04, 0x80, 0x19, 0x80, 0x04,\n    0x00, 0x80, 0x04, 0x80, 0x19, 0x9f, 0x04, 0x80,\n    0x19, 0x89, 0x04, 0x8a, 0x37, 0x99, 0x04, 0x80,\n    0x37, 0xe0, 0x0b, 0x04, 0x80, 0x19, 0xa1, 0x04,\n    0x8d, 0x87, 0x00, 0xbb, 0x87, 0x01, 0x82, 0x87,\n    0xaf, 0x04, 0xb1, 0x91, 0x0d, 0xba, 0x63, 0x01,\n    0x82, 0x63, 0xad, 0x7b, 0x01, 0x8e, 0x7b, 0x00,\n    0x9b, 0x50, 0x01, 0x80, 0x50, 0x00, 0x8a, 0x87,\n    0x34, 0x94, 0x04, 0x00, 0x91, 0x04, 0x0a, 0x8e,\n    0x04, 0x80, 0x19, 0x9c, 0x04, 0xd0, 0x1f, 0x83,\n    0x37, 0x8e, 0x1f, 0x81, 0x19, 0x99, 0x1f, 0x83,\n    0x0b, 0x00, 0x87, 0x0b, 0x01, 0x81, 0x0b, 0x01,\n    0x95, 0x0b, 0x00, 0x86, 0x0b, 0x00, 0x80, 0x0b,\n    0x02, 0x83, 0x0b, 0x01, 0x88, 0x0b, 0x01, 0x81,\n    0x0b, 0x01, 0x83, 0x0b, 0x07, 0x80, 0x0b, 0x03,\n    0x81, 0x0b, 0x00, 0x84, 0x0b, 0x01, 0x98, 0x0b,\n    0x01, 0x82, 0x2e, 0x00, 0x85, 0x2e, 0x03, 0x81,\n    0x2e, 0x01, 0x95, 0x2e, 0x00, 0x86, 0x2e, 0x00,\n    0x81, 0x2e, 0x00, 0x81, 0x2e, 0x00, 0x81, 0x2e,\n    0x01, 0x80, 0x2e, 0x00, 0x84, 0x2e, 0x03, 0x81,\n    0x2e, 0x01, 0x82, 0x2e, 0x02, 0x80, 0x2e, 0x06,\n    0x83, 0x2e, 0x00, 0x80, 0x2e, 0x06, 0x90, 0x2e,\n    0x09, 0x82, 0x2c, 0x00, 0x88, 0x2c, 0x00, 0x82,\n    0x2c, 0x00, 0x95, 0x2c, 0x00, 0x86, 0x2c, 0x00,\n    0x81, 0x2c, 0x00, 0x84, 0x2c, 0x01, 0x89, 0x2c,\n    0x00, 0x82, 0x2c, 0x00, 0x82, 0x2c, 0x01, 0x80,\n    0x2c, 0x0e, 0x83, 0x2c, 0x01, 0x8b, 0x2c, 0x06,\n    0x86, 0x2c, 0x00, 0x82, 0x70, 0x00, 0x87, 0x70,\n    0x01, 0x81, 0x70, 0x01, 0x95, 0x70, 0x00, 0x86,\n    0x70, 0x00, 0x81, 0x70, 0x00, 0x84, 0x70, 0x01,\n    0x88, 0x70, 0x01, 0x81, 0x70, 0x01, 0x82, 0x70,\n    0x06, 0x82, 0x70, 0x03, 0x81, 0x70, 0x00, 0x84,\n    0x70, 0x01, 0x91, 0x70, 0x09, 0x81, 0x8e, 0x00,\n    0x85, 0x8e, 0x02, 0x82, 0x8e, 0x00, 0x83, 0x8e,\n    0x02, 0x81, 0x8e, 0x00, 0x80, 0x8e, 0x00, 0x81,\n    0x8e, 0x02, 0x81, 0x8e, 0x02, 0x82, 0x8e, 0x02,\n    0x8b, 0x8e, 0x03, 0x84, 0x8e, 0x02, 0x82, 0x8e,\n    0x00, 0x83, 0x8e, 0x01, 0x80, 0x8e, 0x05, 0x80,\n    0x8e, 0x0d, 0x94, 0x8e, 0x04, 0x8c, 0x90, 0x00,\n    0x82, 0x90, 0x00, 0x96, 0x90, 0x00, 0x8f, 0x90,\n    0x02, 0x87, 0x90, 0x00, 0x82, 0x90, 0x00, 0x83,\n    0x90, 0x06, 0x81, 0x90, 0x00, 0x82, 0x90, 0x04,\n    0x83, 0x90, 0x01, 0x89, 0x90, 0x06, 0x88, 0x90,\n    0x8c, 0x3c, 0x00, 0x82, 0x3c, 0x00, 0x96, 0x3c,\n    0x00, 0x89, 0x3c, 0x00, 0x84, 0x3c, 0x01, 0x88,\n    0x3c, 0x00, 0x82, 0x3c, 0x00, 0x83, 0x3c, 0x06,\n    0x81, 0x3c, 0x06, 0x80, 0x3c, 0x00, 0x83, 0x3c,\n    0x01, 0x89, 0x3c, 0x00, 0x81, 0x3c, 0x0c, 0x8c,\n    0x4f, 0x00, 0x82, 0x4f, 0x00, 0xb2, 0x4f, 0x00,\n    0x82, 0x4f, 0x00, 0x85, 0x4f, 0x03, 0x8f, 0x4f,\n    0x01, 0x99, 0x4f, 0x00, 0x82, 0x81, 0x00, 0x91,\n    0x81, 0x02, 0x97, 0x81, 0x00, 0x88, 0x81, 0x00,\n    0x80, 0x81, 0x01, 0x86, 0x81, 0x02, 0x80, 0x81,\n    0x03, 0x85, 0x81, 0x00, 0x80, 0x81, 0x00, 0x87,\n    0x81, 0x05, 0x89, 0x81, 0x01, 0x82, 0x81, 0x0b,\n    0xb9, 0x92, 0x03, 0x80, 0x19, 0x9b, 0x92, 0x24,\n    0x81, 0x44, 0x00, 0x80, 0x44, 0x00, 0x84, 0x44,\n    0x00, 0x97, 0x44, 0x00, 0x80, 0x44, 0x00, 0x96,\n    0x44, 0x01, 0x84, 0x44, 0x00, 0x80, 0x44, 0x00,\n    0x85, 0x44, 0x01, 0x89, 0x44, 0x01, 0x83, 0x44,\n    0x1f, 0xc7, 0x93, 0x00, 0xa3, 0x93, 0x03, 0xa6,\n    0x93, 0x00, 0xa3, 0x93, 0x00, 0x8e, 0x93, 0x00,\n    0x86, 0x93, 0x83, 0x19, 0x81, 0x93, 0x24, 0xe0,\n    0x3f, 0x5e, 0xa5, 0x27, 0x00, 0x80, 0x27, 0x04,\n    0x80, 0x27, 0x01, 0xaa, 0x27, 0x80, 0x19, 0x83,\n    0x27, 0xe0, 0x9f, 0x30, 0xc8, 0x26, 0x00, 0x83,\n    0x26, 0x01, 0x86, 0x26, 0x00, 0x80, 0x26, 0x00,\n    0x83, 0x26, 0x01, 0xa8, 0x26, 0x00, 0x83, 0x26,\n    0x01, 0xa0, 0x26, 0x00, 0x83, 0x26, 0x01, 0x86,\n    0x26, 0x00, 0x80, 0x26, 0x00, 0x83, 0x26, 0x01,\n    0x8e, 0x26, 0x00, 0xb8, 0x26, 0x00, 0x83, 0x26,\n    0x01, 0xc2, 0x26, 0x01, 0x9f, 0x26, 0x02, 0x99,\n    0x26, 0x05, 0xd5, 0x17, 0x01, 0x85, 0x17, 0x01,\n    0xe2, 0x1f, 0x12, 0x9c, 0x66, 0x02, 0xca, 0x7a,\n    0x82, 0x19, 0x8a, 0x7a, 0x06, 0x8c, 0x88, 0x00,\n    0x86, 0x88, 0x0a, 0x94, 0x32, 0x81, 0x19, 0x08,\n    0x93, 0x11, 0x0b, 0x8c, 0x89, 0x00, 0x82, 0x89,\n    0x00, 0x81, 0x89, 0x0b, 0xdd, 0x40, 0x01, 0x89,\n    0x40, 0x05, 0x89, 0x40, 0x05, 0x81, 0x5b, 0x81,\n    0x19, 0x80, 0x5b, 0x80, 0x19, 0x88, 0x5b, 0x00,\n    0x89, 0x5b, 0x05, 0xd8, 0x5b, 0x06, 0xaa, 0x5b,\n    0x04, 0xc5, 0x12, 0x09, 0x9e, 0x47, 0x00, 0x8b,\n    0x47, 0x03, 0x8b, 0x47, 0x03, 0x80, 0x47, 0x02,\n    0x8b, 0x47, 0x9d, 0x8a, 0x01, 0x84, 0x8a, 0x0a,\n    0xab, 0x61, 0x03, 0x99, 0x61, 0x05, 0x8a, 0x61,\n    0x02, 0x81, 0x61, 0x9f, 0x40, 0x9b, 0x10, 0x01,\n    0x81, 0x10, 0xbe, 0x8b, 0x00, 0x9c, 0x8b, 0x01,\n    0x8a, 0x8b, 0x05, 0x89, 0x8b, 0x05, 0x8d, 0x8b,\n    0x01, 0x90, 0x37, 0x3e, 0xcb, 0x07, 0x03, 0xac,\n    0x07, 0x02, 0xbf, 0x85, 0xb3, 0x0a, 0x07, 0x83,\n    0x0a, 0xb7, 0x46, 0x02, 0x8e, 0x46, 0x02, 0x82,\n    0x46, 0xaf, 0x67, 0x88, 0x1d, 0x06, 0xaa, 0x27,\n    0x01, 0x82, 0x27, 0x87, 0x85, 0x07, 0x82, 0x37,\n    0x80, 0x19, 0x8c, 0x37, 0x80, 0x19, 0x86, 0x37,\n    0x83, 0x19, 0x80, 0x37, 0x85, 0x19, 0x80, 0x37,\n    0x82, 0x19, 0x81, 0x37, 0x80, 0x19, 0x04, 0xa5,\n    0x45, 0x84, 0x2b, 0x80, 0x1d, 0xb0, 0x45, 0x84,\n    0x2b, 0x83, 0x45, 0x84, 0x2b, 0x8c, 0x45, 0x80,\n    0x1d, 0xc5, 0x45, 0x80, 0x2b, 0xb9, 0x37, 0x00,\n    0x84, 0x37, 0xe0, 0x9f, 0x45, 0x95, 0x2b, 0x01,\n    0x85, 0x2b, 0x01, 0xa5, 0x2b, 0x01, 0x85, 0x2b,\n    0x01, 0x87, 0x2b, 0x00, 0x80, 0x2b, 0x00, 0x80,\n    0x2b, 0x00, 0x80, 0x2b, 0x00, 0x9e, 0x2b, 0x01,\n    0xb4, 0x2b, 0x00, 0x8e, 0x2b, 0x00, 0x8d, 0x2b,\n    0x01, 0x85, 0x2b, 0x00, 0x92, 0x2b, 0x01, 0x82,\n    0x2b, 0x00, 0x88, 0x2b, 0x00, 0x8b, 0x19, 0x81,\n    0x37, 0xd6, 0x19, 0x00, 0x8a, 0x19, 0x80, 0x45,\n    0x01, 0x8a, 0x19, 0x80, 0x45, 0x8e, 0x19, 0x00,\n    0x8c, 0x45, 0x02, 0x9f, 0x19, 0x0f, 0xa0, 0x37,\n    0x0e, 0xa5, 0x19, 0x80, 0x2b, 0x82, 0x19, 0x81,\n    0x45, 0x85, 0x19, 0x80, 0x45, 0x9a, 0x19, 0x80,\n    0x45, 0x90, 0x19, 0xa8, 0x45, 0x82, 0x19, 0x03,\n    0xe2, 0x36, 0x19, 0x18, 0x8a, 0x19, 0x14, 0xe3,\n    0x3f, 0x19, 0xe0, 0x9f, 0x0f, 0xe2, 0x13, 0x19,\n    0x01, 0x9f, 0x19, 0x00, 0xe0, 0x08, 0x19, 0xae,\n    0x28, 0x00, 0xae, 0x28, 0x00, 0x9f, 0x45, 0xe0,\n    0x13, 0x1a, 0x04, 0x86, 0x1a, 0xa5, 0x27, 0x00,\n    0x80, 0x27, 0x04, 0x80, 0x27, 0x01, 0xb7, 0x94,\n    0x06, 0x81, 0x94, 0x0d, 0x80, 0x94, 0x96, 0x26,\n    0x08, 0x86, 0x26, 0x00, 0x86, 0x26, 0x00, 0x86,\n    0x26, 0x00, 0x86, 0x26, 0x00, 0x86, 0x26, 0x00,\n    0x86, 0x26, 0x00, 0x86, 0x26, 0x00, 0x86, 0x26,\n    0x00, 0x9f, 0x1d, 0xd2, 0x19, 0x2c, 0x99, 0x2f,\n    0x00, 0xd8, 0x2f, 0x0b, 0xe0, 0x75, 0x2f, 0x19,\n    0x8b, 0x19, 0x03, 0x84, 0x19, 0x80, 0x2f, 0x80,\n    0x19, 0x80, 0x2f, 0x98, 0x19, 0x88, 0x2f, 0x83,\n    0x37, 0x81, 0x30, 0x87, 0x19, 0x83, 0x2f, 0x83,\n    0x19, 0x00, 0xd5, 0x35, 0x01, 0x81, 0x37, 0x81,\n    0x19, 0x82, 0x35, 0x80, 0x19, 0xd9, 0x3d, 0x81,\n    0x19, 0x82, 0x3d, 0x04, 0xaa, 0x0d, 0x00, 0xdd,\n    0x30, 0x00, 0x8f, 0x19, 0x9f, 0x0d, 0xa3, 0x19,\n    0x0b, 0x8f, 0x3d, 0x9e, 0x30, 0x00, 0xbf, 0x19,\n    0x9e, 0x30, 0xd0, 0x19, 0xae, 0x3d, 0x80, 0x19,\n    0xd7, 0x3d, 0xe0, 0x47, 0x19, 0xf0, 0x09, 0x5f,\n    0x2f, 0xbf, 0x19, 0xf0, 0x41, 0x9c, 0x2f, 0x02,\n    0xe4, 0x2c, 0x9b, 0x02, 0xb6, 0x9b, 0x08, 0xaf,\n    0x4a, 0xe0, 0xcb, 0x97, 0x13, 0xdf, 0x1d, 0xd7,\n    0x08, 0x07, 0xa1, 0x19, 0xe0, 0x05, 0x45, 0x82,\n    0x19, 0xb4, 0x45, 0x01, 0x88, 0x45, 0x29, 0x8a,\n    0x45, 0xac, 0x86, 0x02, 0x89, 0x19, 0x05, 0xb7,\n    0x76, 0x07, 0xc5, 0x7c, 0x07, 0x8b, 0x7c, 0x05,\n    0x9f, 0x1f, 0xad, 0x3e, 0x80, 0x19, 0x80, 0x3e,\n    0xa3, 0x79, 0x0a, 0x80, 0x79, 0x9c, 0x30, 0x02,\n    0xcd, 0x3a, 0x00, 0x80, 0x19, 0x89, 0x3a, 0x03,\n    0x81, 0x3a, 0x9e, 0x5e, 0x00, 0xb6, 0x16, 0x08,\n    0x8d, 0x16, 0x01, 0x89, 0x16, 0x01, 0x83, 0x16,\n    0x9f, 0x5e, 0xc2, 0x8c, 0x17, 0x84, 0x8c, 0x96,\n    0x55, 0x09, 0x85, 0x26, 0x01, 0x85, 0x26, 0x01,\n    0x85, 0x26, 0x08, 0x86, 0x26, 0x00, 0x86, 0x26,\n    0x00, 0xaa, 0x45, 0x80, 0x19, 0x88, 0x45, 0x80,\n    0x2b, 0x83, 0x45, 0x81, 0x19, 0x03, 0xcf, 0x17,\n    0xad, 0x55, 0x01, 0x89, 0x55, 0x05, 0xf0, 0x1b,\n    0x43, 0x30, 0x0b, 0x96, 0x30, 0x03, 0xb0, 0x30,\n    0x70, 0x10, 0xa3, 0xe1, 0x0d, 0x2f, 0x01, 0xe0,\n    0x09, 0x2f, 0x25, 0x86, 0x45, 0x0b, 0x84, 0x05,\n    0x04, 0x99, 0x34, 0x00, 0x84, 0x34, 0x00, 0x80,\n    0x34, 0x00, 0x81, 0x34, 0x00, 0x81, 0x34, 0x00,\n    0x89, 0x34, 0xe0, 0x11, 0x04, 0x10, 0xe1, 0x0a,\n    0x04, 0x81, 0x19, 0x0f, 0xbf, 0x04, 0x01, 0xb5,\n    0x04, 0x27, 0x8d, 0x04, 0x01, 0x8f, 0x37, 0x89,\n    0x19, 0x05, 0x8d, 0x37, 0x81, 0x1d, 0xa2, 0x19,\n    0x00, 0x92, 0x19, 0x00, 0x83, 0x19, 0x03, 0x84,\n    0x04, 0x00, 0xe0, 0x26, 0x04, 0x01, 0x80, 0x19,\n    0x00, 0x9f, 0x19, 0x99, 0x45, 0x85, 0x19, 0x99,\n    0x45, 0x8a, 0x19, 0x89, 0x3d, 0x80, 0x19, 0xac,\n    0x3d, 0x81, 0x19, 0x9e, 0x30, 0x02, 0x85, 0x30,\n    0x01, 0x85, 0x30, 0x01, 0x85, 0x30, 0x01, 0x82,\n    0x30, 0x02, 0x86, 0x19, 0x00, 0x86, 0x19, 0x09,\n    0x84, 0x19, 0x01, 0x8b, 0x49, 0x00, 0x99, 0x49,\n    0x00, 0x92, 0x49, 0x00, 0x81, 0x49, 0x00, 0x8e,\n    0x49, 0x01, 0x8d, 0x49, 0x21, 0xe0, 0x1a, 0x49,\n    0x04, 0x82, 0x19, 0x03, 0xac, 0x19, 0x02, 0x88,\n    0x19, 0xce, 0x2b, 0x00, 0x8c, 0x19, 0x02, 0x80,\n    0x2b, 0x2e, 0xac, 0x19, 0x80, 0x37, 0x60, 0x21,\n    0x9c, 0x4b, 0x02, 0xb0, 0x13, 0x0e, 0x80, 0x37,\n    0x9a, 0x19, 0x03, 0xa3, 0x69, 0x08, 0x82, 0x69,\n    0x9a, 0x29, 0x04, 0xaa, 0x6b, 0x04, 0x9d, 0x96,\n    0x00, 0x80, 0x96, 0xa3, 0x6c, 0x03, 0x8d, 0x6c,\n    0x29, 0xcf, 0x1e, 0xaf, 0x7e, 0x9d, 0x72, 0x01,\n    0x89, 0x72, 0x05, 0xa3, 0x71, 0x03, 0xa3, 0x71,\n    0x03, 0xa7, 0x24, 0x07, 0xb3, 0x14, 0x0a, 0x80,\n    0x14, 0x60, 0x2f, 0xe0, 0xd6, 0x48, 0x08, 0x95,\n    0x48, 0x09, 0x87, 0x48, 0x60, 0x37, 0x85, 0x1c,\n    0x01, 0x80, 0x1c, 0x00, 0xab, 0x1c, 0x00, 0x81,\n    0x1c, 0x02, 0x80, 0x1c, 0x01, 0x80, 0x1c, 0x95,\n    0x36, 0x00, 0x88, 0x36, 0x9f, 0x74, 0x9e, 0x5f,\n    0x07, 0x88, 0x5f, 0x2f, 0x92, 0x33, 0x00, 0x81,\n    0x33, 0x04, 0x84, 0x33, 0x9b, 0x77, 0x02, 0x80,\n    0x77, 0x99, 0x4c, 0x04, 0x80, 0x4c, 0x3f, 0x9f,\n    0x58, 0x97, 0x57, 0x03, 0x93, 0x57, 0x01, 0xad,\n    0x57, 0x83, 0x3f, 0x00, 0x81, 0x3f, 0x04, 0x87,\n    0x3f, 0x00, 0x82, 0x3f, 0x00, 0x9c, 0x3f, 0x01,\n    0x82, 0x3f, 0x03, 0x89, 0x3f, 0x06, 0x88, 0x3f,\n    0x06, 0x9f, 0x6e, 0x9f, 0x6a, 0x1f, 0xa6, 0x51,\n    0x03, 0x8b, 0x51, 0x08, 0xb5, 0x06, 0x02, 0x86,\n    0x06, 0x95, 0x39, 0x01, 0x87, 0x39, 0x92, 0x38,\n    0x04, 0x87, 0x38, 0x91, 0x78, 0x06, 0x83, 0x78,\n    0x0b, 0x86, 0x78, 0x4f, 0xc8, 0x6f, 0x36, 0xb2,\n    0x68, 0x0c, 0xb2, 0x68, 0x06, 0x85, 0x68, 0xa7,\n    0x31, 0x07, 0x89, 0x31, 0x60, 0xc5, 0x9e, 0x04,\n    0x00, 0xa9, 0x9a, 0x00, 0x82, 0x9a, 0x01, 0x81,\n    0x9a, 0x4d, 0xa7, 0x6d, 0x07, 0xa9, 0x82, 0x55,\n    0x9b, 0x18, 0x13, 0x96, 0x25, 0x08, 0xcd, 0x0e,\n    0x03, 0x9d, 0x0e, 0x0e, 0x80, 0x0e, 0xc1, 0x3b,\n    0x0a, 0x80, 0x3b, 0x01, 0x98, 0x83, 0x06, 0x89,\n    0x83, 0x05, 0xb4, 0x15, 0x00, 0x91, 0x15, 0x07,\n    0xa6, 0x4e, 0x08, 0xdf, 0x7d, 0x00, 0x93, 0x81,\n    0x0a, 0x91, 0x41, 0x00, 0xab, 0x41, 0x40, 0x86,\n    0x5d, 0x00, 0x80, 0x5d, 0x00, 0x83, 0x5d, 0x00,\n    0x8e, 0x5d, 0x00, 0x8a, 0x5d, 0x05, 0xba, 0x43,\n    0x04, 0x89, 0x43, 0x05, 0x83, 0x2a, 0x00, 0x87,\n    0x2a, 0x01, 0x81, 0x2a, 0x01, 0x95, 0x2a, 0x00,\n    0x86, 0x2a, 0x00, 0x81, 0x2a, 0x00, 0x84, 0x2a,\n    0x00, 0x80, 0x37, 0x88, 0x2a, 0x01, 0x81, 0x2a,\n    0x01, 0x82, 0x2a, 0x01, 0x80, 0x2a, 0x05, 0x80,\n    0x2a, 0x04, 0x86, 0x2a, 0x01, 0x86, 0x2a, 0x02,\n    0x84, 0x2a, 0x60, 0x2a, 0xdb, 0x62, 0x00, 0x84,\n    0x62, 0x1d, 0xc7, 0x95, 0x07, 0x89, 0x95, 0x60,\n    0x45, 0xb5, 0x7f, 0x01, 0xa5, 0x7f, 0x21, 0xc4,\n    0x5a, 0x0a, 0x89, 0x5a, 0x05, 0x8c, 0x5b, 0x12,\n    0xb8, 0x8d, 0x06, 0x89, 0x8d, 0x35, 0x9a, 0x02,\n    0x01, 0x8e, 0x02, 0x03, 0x8f, 0x02, 0x60, 0x5f,\n    0xbb, 0x21, 0x60, 0x03, 0xd2, 0x99, 0x0b, 0x80,\n    0x99, 0x86, 0x20, 0x01, 0x80, 0x20, 0x01, 0x87,\n    0x20, 0x00, 0x81, 0x20, 0x00, 0x9d, 0x20, 0x00,\n    0x81, 0x20, 0x01, 0x8b, 0x20, 0x08, 0x89, 0x20,\n    0x45, 0x87, 0x60, 0x01, 0xad, 0x60, 0x01, 0x8a,\n    0x60, 0x1a, 0xc7, 0x9c, 0x07, 0xd2, 0x84, 0x1c,\n    0xb8, 0x75, 0x60, 0xa6, 0x88, 0x0c, 0x00, 0xac,\n    0x0c, 0x00, 0x8d, 0x0c, 0x09, 0x9c, 0x0c, 0x02,\n    0x9f, 0x52, 0x01, 0x95, 0x52, 0x00, 0x8d, 0x52,\n    0x48, 0x86, 0x53, 0x00, 0x81, 0x53, 0x00, 0xab,\n    0x53, 0x02, 0x80, 0x53, 0x00, 0x81, 0x53, 0x00,\n    0x88, 0x53, 0x07, 0x89, 0x53, 0x05, 0x85, 0x2d,\n    0x00, 0x81, 0x2d, 0x00, 0xa4, 0x2d, 0x00, 0x81,\n    0x2d, 0x00, 0x85, 0x2d, 0x06, 0x89, 0x2d, 0x60,\n    0xd5, 0x98, 0x4d, 0x60, 0x56, 0x80, 0x4a, 0x0e,\n    0xb1, 0x8e, 0x0c, 0x80, 0x8e, 0xe3, 0x39, 0x1b,\n    0x60, 0x05, 0xe0, 0x0e, 0x1b, 0x00, 0x84, 0x1b,\n    0x0a, 0xe0, 0x63, 0x1b, 0x6a, 0x5b, 0xe3, 0xce,\n    0x23, 0x00, 0x88, 0x23, 0x6f, 0x66, 0xe1, 0xe6,\n    0x03, 0x70, 0x11, 0x58, 0xe1, 0xd8, 0x08, 0x06,\n    0x9e, 0x5c, 0x00, 0x89, 0x5c, 0x03, 0x81, 0x5c,\n    0x5f, 0x9d, 0x09, 0x01, 0x85, 0x09, 0x09, 0xc5,\n    0x73, 0x09, 0x89, 0x73, 0x00, 0x86, 0x73, 0x00,\n    0x94, 0x73, 0x04, 0x92, 0x73, 0x62, 0x4f, 0xda,\n    0x54, 0x60, 0x04, 0xca, 0x59, 0x03, 0xb8, 0x59,\n    0x06, 0x90, 0x59, 0x3f, 0x80, 0x8f, 0x80, 0x64,\n    0x81, 0x19, 0x80, 0x42, 0x0a, 0x81, 0x2f, 0x0d,\n    0xf0, 0x07, 0x97, 0x8f, 0x07, 0xe2, 0x9f, 0x8f,\n    0xe1, 0x75, 0x42, 0x29, 0x88, 0x8f, 0x70, 0x12,\n    0x96, 0x80, 0x3d, 0xe0, 0xbd, 0x35, 0x30, 0x82,\n    0x35, 0x10, 0x83, 0x3d, 0x07, 0xe1, 0x2b, 0x64,\n    0x68, 0xa3, 0xe0, 0x0a, 0x22, 0x04, 0x8c, 0x22,\n    0x02, 0x88, 0x22, 0x06, 0x89, 0x22, 0x01, 0x83,\n    0x22, 0x83, 0x19, 0x70, 0x02, 0xfb, 0xe0, 0x95,\n    0x19, 0x09, 0xa6, 0x19, 0x01, 0xbd, 0x19, 0x82,\n    0x37, 0x90, 0x19, 0x87, 0x37, 0x81, 0x19, 0x86,\n    0x37, 0x9d, 0x19, 0x83, 0x37, 0xba, 0x19, 0x16,\n    0xc5, 0x2b, 0x60, 0x39, 0x93, 0x19, 0x0b, 0xd6,\n    0x19, 0x08, 0x98, 0x19, 0x60, 0x26, 0xd4, 0x19,\n    0x00, 0xc6, 0x19, 0x00, 0x81, 0x19, 0x01, 0x80,\n    0x19, 0x01, 0x81, 0x19, 0x01, 0x83, 0x19, 0x00,\n    0x8b, 0x19, 0x00, 0x80, 0x19, 0x00, 0x86, 0x19,\n    0x00, 0xc0, 0x19, 0x00, 0x83, 0x19, 0x01, 0x87,\n    0x19, 0x00, 0x86, 0x19, 0x00, 0x9b, 0x19, 0x00,\n    0x83, 0x19, 0x00, 0x84, 0x19, 0x00, 0x80, 0x19,\n    0x02, 0x86, 0x19, 0x00, 0xe0, 0xf3, 0x19, 0x01,\n    0xe0, 0xc3, 0x19, 0x01, 0xb1, 0x19, 0xe2, 0x2b,\n    0x80, 0x0e, 0x84, 0x80, 0x00, 0x8e, 0x80, 0x64,\n    0xef, 0x86, 0x28, 0x00, 0x90, 0x28, 0x01, 0x86,\n    0x28, 0x00, 0x81, 0x28, 0x00, 0x84, 0x28, 0x60,\n    0x74, 0xac, 0x65, 0x02, 0x8d, 0x65, 0x01, 0x89,\n    0x65, 0x03, 0x81, 0x65, 0x61, 0x0f, 0xb9, 0x98,\n    0x04, 0x80, 0x98, 0x64, 0x9f, 0xe0, 0x64, 0x56,\n    0x01, 0x8f, 0x56, 0x28, 0xcb, 0x01, 0x03, 0x89,\n    0x01, 0x03, 0x81, 0x01, 0x62, 0xb0, 0xc3, 0x19,\n    0x4b, 0xbc, 0x19, 0x60, 0x61, 0x83, 0x04, 0x00,\n    0x9a, 0x04, 0x00, 0x81, 0x04, 0x00, 0x80, 0x04,\n    0x01, 0x80, 0x04, 0x00, 0x89, 0x04, 0x00, 0x83,\n    0x04, 0x00, 0x80, 0x04, 0x00, 0x80, 0x04, 0x05,\n    0x80, 0x04, 0x03, 0x80, 0x04, 0x00, 0x80, 0x04,\n    0x00, 0x80, 0x04, 0x00, 0x82, 0x04, 0x00, 0x81,\n    0x04, 0x00, 0x80, 0x04, 0x01, 0x80, 0x04, 0x00,\n    0x80, 0x04, 0x00, 0x80, 0x04, 0x00, 0x80, 0x04,\n    0x00, 0x80, 0x04, 0x00, 0x81, 0x04, 0x00, 0x80,\n    0x04, 0x01, 0x83, 0x04, 0x00, 0x86, 0x04, 0x00,\n    0x83, 0x04, 0x00, 0x83, 0x04, 0x00, 0x80, 0x04,\n    0x00, 0x89, 0x04, 0x00, 0x90, 0x04, 0x04, 0x82,\n    0x04, 0x00, 0x84, 0x04, 0x00, 0x90, 0x04, 0x33,\n    0x81, 0x04, 0x60, 0xad, 0xab, 0x19, 0x03, 0xe0,\n    0x03, 0x19, 0x0b, 0x8e, 0x19, 0x01, 0x8e, 0x19,\n    0x00, 0x8e, 0x19, 0x00, 0xa4, 0x19, 0x09, 0xe0,\n    0x4d, 0x19, 0x37, 0x99, 0x19, 0x80, 0x35, 0x81,\n    0x19, 0x0c, 0xab, 0x19, 0x03, 0x88, 0x19, 0x06,\n    0x81, 0x19, 0x0d, 0x85, 0x19, 0x60, 0x39, 0xe3,\n    0x77, 0x19, 0x07, 0x8c, 0x19, 0x02, 0x8c, 0x19,\n    0x02, 0xe0, 0x13, 0x19, 0x0b, 0xd8, 0x19, 0x06,\n    0x8b, 0x19, 0x13, 0x8b, 0x19, 0x03, 0xb7, 0x19,\n    0x07, 0x89, 0x19, 0x05, 0xa7, 0x19, 0x07, 0x9d,\n    0x19, 0x01, 0x81, 0x19, 0x4d, 0xe0, 0x18, 0x19,\n    0x00, 0xd1, 0x19, 0x00, 0xe0, 0x26, 0x19, 0x0b,\n    0x8d, 0x19, 0x01, 0x84, 0x19, 0x02, 0x82, 0x19,\n    0x04, 0x86, 0x19, 0x08, 0x98, 0x19, 0x06, 0x86,\n    0x19, 0x08, 0x82, 0x19, 0x0c, 0x86, 0x19, 0x28,\n    0xe0, 0x32, 0x19, 0x00, 0xb6, 0x19, 0x24, 0x89,\n    0x19, 0x63, 0xa5, 0xf0, 0x96, 0x7d, 0x2f, 0x21,\n    0xef, 0xd4, 0x2f, 0x0a, 0xe0, 0x7d, 0x2f, 0x01,\n    0xf0, 0x06, 0x21, 0x2f, 0x0d, 0xf0, 0x0c, 0xd0,\n    0x2f, 0x6b, 0xbe, 0xe1, 0xbd, 0x2f, 0x65, 0x81,\n    0xf0, 0x02, 0xea, 0x2f, 0x7a, 0xdc, 0x55, 0x80,\n    0x19, 0x1d, 0xdf, 0x19, 0x60, 0x1f, 0xe0, 0x8f,\n    0x37,\n};\n\nstatic const uint8_t unicode_script_ext_table[799] = {\n    0x82, 0xc1, 0x00, 0x00, 0x01, 0x2b, 0x01, 0x00,\n    0x00, 0x01, 0x2b, 0x1c, 0x00, 0x0c, 0x01, 0x45,\n    0x80, 0x92, 0x00, 0x00, 0x02, 0x1d, 0x6b, 0x00,\n    0x02, 0x1d, 0x28, 0x01, 0x02, 0x1d, 0x45, 0x00,\n    0x02, 0x1d, 0x28, 0x81, 0x03, 0x00, 0x00, 0x05,\n    0x04, 0x31, 0x87, 0x91, 0x9a, 0x0d, 0x00, 0x00,\n    0x05, 0x04, 0x31, 0x87, 0x91, 0x9a, 0x00, 0x03,\n    0x04, 0x87, 0x91, 0x01, 0x00, 0x00, 0x05, 0x04,\n    0x31, 0x87, 0x91, 0x9a, 0x1f, 0x00, 0x00, 0x08,\n    0x01, 0x04, 0x50, 0x51, 0x78, 0x31, 0x82, 0x87,\n    0x09, 0x00, 0x0a, 0x02, 0x04, 0x87, 0x09, 0x00,\n    0x09, 0x03, 0x04, 0x91, 0x9a, 0x05, 0x00, 0x00,\n    0x02, 0x04, 0x87, 0x62, 0x00, 0x00, 0x02, 0x04,\n    0x31, 0x81, 0xfb, 0x00, 0x00, 0x0d, 0x0b, 0x1f,\n    0x2a, 0x2c, 0x2e, 0x3c, 0x45, 0x4f, 0x70, 0x7d,\n    0x8e, 0x90, 0x95, 0x00, 0x0c, 0x0b, 0x1f, 0x2a,\n    0x2c, 0x2e, 0x3c, 0x45, 0x4f, 0x70, 0x8e, 0x90,\n    0x95, 0x10, 0x00, 0x00, 0x14, 0x0b, 0x1f, 0x21,\n    0x2d, 0x53, 0x2a, 0x2c, 0x2e, 0x3c, 0x4e, 0x4f,\n    0x60, 0x70, 0x43, 0x81, 0x86, 0x8d, 0x8e, 0x90,\n    0x95, 0x00, 0x15, 0x0b, 0x1f, 0x21, 0x2d, 0x53,\n    0x2a, 0x2c, 0x2e, 0x3c, 0x47, 0x4e, 0x4f, 0x60,\n    0x70, 0x43, 0x81, 0x86, 0x8d, 0x8e, 0x90, 0x95,\n    0x09, 0x04, 0x1f, 0x21, 0x3b, 0x4e, 0x75, 0x00,\n    0x09, 0x03, 0x0b, 0x15, 0x86, 0x75, 0x00, 0x09,\n    0x02, 0x2e, 0x5d, 0x75, 0x00, 0x09, 0x02, 0x2c,\n    0x41, 0x80, 0x75, 0x00, 0x0d, 0x02, 0x2a, 0x8e,\n    0x80, 0x71, 0x00, 0x09, 0x02, 0x3c, 0x60, 0x82,\n    0xcf, 0x00, 0x09, 0x03, 0x15, 0x5e, 0x8a, 0x80,\n    0x30, 0x00, 0x00, 0x02, 0x27, 0x45, 0x85, 0xb8,\n    0x00, 0x01, 0x04, 0x11, 0x32, 0x89, 0x88, 0x80,\n    0x4a, 0x00, 0x01, 0x02, 0x5b, 0x76, 0x00, 0x00,\n    0x00, 0x02, 0x5b, 0x76, 0x84, 0x49, 0x00, 0x00,\n    0x04, 0x0b, 0x1f, 0x2a, 0x3c, 0x00, 0x01, 0x1f,\n    0x00, 0x04, 0x0b, 0x1f, 0x2a, 0x3c, 0x00, 0x02,\n    0x1f, 0x2a, 0x00, 0x01, 0x1f, 0x01, 0x02, 0x0b,\n    0x1f, 0x00, 0x02, 0x1f, 0x7d, 0x00, 0x02, 0x0b,\n    0x1f, 0x00, 0x02, 0x1f, 0x7d, 0x00, 0x06, 0x1f,\n    0x3c, 0x4f, 0x70, 0x8e, 0x90, 0x00, 0x01, 0x1f,\n    0x01, 0x02, 0x1f, 0x7d, 0x01, 0x01, 0x1f, 0x00,\n    0x02, 0x1f, 0x7d, 0x00, 0x02, 0x0b, 0x1f, 0x06,\n    0x01, 0x1f, 0x00, 0x02, 0x1f, 0x60, 0x00, 0x02,\n    0x0b, 0x1f, 0x01, 0x01, 0x1f, 0x00, 0x02, 0x0b,\n    0x1f, 0x03, 0x01, 0x1f, 0x00, 0x08, 0x0b, 0x1f,\n    0x2a, 0x3c, 0x60, 0x70, 0x90, 0x95, 0x00, 0x02,\n    0x1f, 0x2a, 0x00, 0x03, 0x1f, 0x2a, 0x3c, 0x01,\n    0x02, 0x0b, 0x1f, 0x00, 0x01, 0x0b, 0x01, 0x02,\n    0x1f, 0x2a, 0x00, 0x01, 0x60, 0x80, 0x44, 0x00,\n    0x01, 0x01, 0x2b, 0x35, 0x00, 0x00, 0x02, 0x1d,\n    0x87, 0x81, 0xb5, 0x00, 0x00, 0x02, 0x45, 0x5b,\n    0x80, 0x3f, 0x00, 0x00, 0x03, 0x1f, 0x2a, 0x45,\n    0x8c, 0xd1, 0x00, 0x00, 0x02, 0x1d, 0x28, 0x81,\n    0x3c, 0x00, 0x01, 0x06, 0x0d, 0x30, 0x2f, 0x35,\n    0x3d, 0x9b, 0x00, 0x05, 0x0d, 0x30, 0x2f, 0x35,\n    0x3d, 0x01, 0x00, 0x00, 0x01, 0x2f, 0x00, 0x00,\n    0x09, 0x06, 0x0d, 0x30, 0x2f, 0x35, 0x3d, 0x9b,\n    0x00, 0x00, 0x00, 0x05, 0x0d, 0x30, 0x2f, 0x35,\n    0x3d, 0x07, 0x06, 0x0d, 0x30, 0x2f, 0x35, 0x3d,\n    0x9b, 0x03, 0x05, 0x0d, 0x30, 0x2f, 0x35, 0x3d,\n    0x09, 0x00, 0x03, 0x02, 0x0d, 0x2f, 0x01, 0x00,\n    0x00, 0x05, 0x0d, 0x30, 0x2f, 0x35, 0x3d, 0x04,\n    0x02, 0x35, 0x3d, 0x00, 0x00, 0x00, 0x05, 0x0d,\n    0x30, 0x2f, 0x35, 0x3d, 0x03, 0x00, 0x01, 0x03,\n    0x2f, 0x35, 0x3d, 0x01, 0x01, 0x2f, 0x58, 0x00,\n    0x03, 0x02, 0x35, 0x3d, 0x02, 0x00, 0x00, 0x02,\n    0x35, 0x3d, 0x59, 0x00, 0x00, 0x06, 0x0d, 0x30,\n    0x2f, 0x35, 0x3d, 0x9b, 0x00, 0x02, 0x35, 0x3d,\n    0x80, 0x12, 0x00, 0x0f, 0x01, 0x2f, 0x1f, 0x00,\n    0x23, 0x01, 0x2f, 0x3b, 0x00, 0x27, 0x01, 0x2f,\n    0x37, 0x00, 0x30, 0x01, 0x2f, 0x0e, 0x00, 0x0b,\n    0x01, 0x2f, 0x32, 0x00, 0x00, 0x01, 0x2f, 0x57,\n    0x00, 0x18, 0x01, 0x2f, 0x09, 0x00, 0x04, 0x01,\n    0x2f, 0x5f, 0x00, 0x1e, 0x01, 0x2f, 0xc0, 0x31,\n    0xef, 0x00, 0x00, 0x02, 0x1d, 0x28, 0x80, 0x0f,\n    0x00, 0x07, 0x02, 0x2f, 0x45, 0x80, 0xa7, 0x00,\n    0x02, 0x0e, 0x1f, 0x21, 0x2c, 0x2e, 0x41, 0x3c,\n    0x3b, 0x4e, 0x4f, 0x5a, 0x60, 0x43, 0x8d, 0x95,\n    0x02, 0x0d, 0x1f, 0x21, 0x2c, 0x2e, 0x41, 0x3c,\n    0x3b, 0x4e, 0x5a, 0x60, 0x43, 0x8d, 0x95, 0x03,\n    0x0b, 0x1f, 0x21, 0x2c, 0x2e, 0x41, 0x3b, 0x4e,\n    0x5a, 0x43, 0x8d, 0x95, 0x80, 0x36, 0x00, 0x00,\n    0x02, 0x0b, 0x1f, 0x00, 0x00, 0x00, 0x02, 0x1f,\n    0x8e, 0x39, 0x00, 0x00, 0x03, 0x3e, 0x45, 0x5e,\n    0x80, 0x1f, 0x00, 0x00, 0x02, 0x10, 0x3a, 0xc0,\n    0x13, 0xa1, 0x00, 0x00, 0x02, 0x04, 0x91, 0x09,\n    0x00, 0x00, 0x02, 0x04, 0x91, 0x46, 0x00, 0x01,\n    0x05, 0x0d, 0x30, 0x2f, 0x35, 0x3d, 0x80, 0x99,\n    0x00, 0x04, 0x06, 0x0d, 0x30, 0x2f, 0x35, 0x3d,\n    0x9b, 0x09, 0x00, 0x00, 0x02, 0x35, 0x3d, 0x2c,\n    0x00, 0x01, 0x02, 0x35, 0x3d, 0x80, 0xdf, 0x00,\n    0x02, 0x02, 0x1c, 0x49, 0x03, 0x00, 0x2c, 0x03,\n    0x1c, 0x48, 0x49, 0x02, 0x00, 0x08, 0x02, 0x1c,\n    0x49, 0x81, 0x1f, 0x00, 0x1b, 0x02, 0x04, 0x1a,\n    0x8f, 0x84, 0x00, 0x00, 0x02, 0x2a, 0x8e, 0x00,\n    0x00, 0x00, 0x02, 0x2a, 0x8e, 0x36, 0x00, 0x01,\n    0x02, 0x2a, 0x8e, 0x8c, 0x12, 0x00, 0x01, 0x02,\n    0x2a, 0x8e, 0x00, 0x00, 0x00, 0x02, 0x2a, 0x8e,\n    0xc0, 0x5c, 0x4b, 0x00, 0x03, 0x01, 0x22, 0x96,\n    0x3b, 0x00, 0x11, 0x01, 0x2f, 0x9e, 0x5d, 0x00,\n    0x01, 0x01, 0x2f, 0xce, 0xcd, 0x2d, 0x00,\n};\n\nstatic const uint8_t unicode_prop_Hyphen_table[28] = {\n    0xac, 0x80, 0xfe, 0x80, 0x44, 0xdb, 0x80, 0x52,\n    0x7a, 0x80, 0x48, 0x08, 0x81, 0x4e, 0x04, 0x80,\n    0x42, 0xe2, 0x80, 0x60, 0xcd, 0x66, 0x80, 0x40,\n    0xa8, 0x80, 0xd6, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Other_Math_table[200] = {\n    0xdd, 0x80, 0x43, 0x70, 0x11, 0x80, 0x99, 0x09,\n    0x81, 0x5c, 0x1f, 0x80, 0x9a, 0x82, 0x8a, 0x80,\n    0x9f, 0x83, 0x97, 0x81, 0x8d, 0x81, 0xc0, 0x8c,\n    0x18, 0x11, 0x1c, 0x91, 0x03, 0x01, 0x89, 0x00,\n    0x14, 0x28, 0x11, 0x09, 0x02, 0x05, 0x13, 0x24,\n    0xca, 0x21, 0x18, 0x08, 0x08, 0x00, 0x21, 0x0b,\n    0x0b, 0x91, 0x09, 0x00, 0x06, 0x00, 0x29, 0x41,\n    0x21, 0x83, 0x40, 0xa7, 0x08, 0x80, 0x97, 0x80,\n    0x90, 0x80, 0x41, 0xbc, 0x81, 0x8b, 0x88, 0x24,\n    0x21, 0x09, 0x14, 0x8d, 0x00, 0x01, 0x85, 0x97,\n    0x81, 0xb8, 0x00, 0x80, 0x9c, 0x83, 0x88, 0x81,\n    0x41, 0x55, 0x81, 0x9e, 0x89, 0x41, 0x92, 0x95,\n    0xbe, 0x83, 0x9f, 0x81, 0x60, 0xd4, 0x62, 0x00,\n    0x03, 0x80, 0x40, 0xd2, 0x00, 0x80, 0x60, 0xd4,\n    0xc0, 0xd4, 0x80, 0xc6, 0x01, 0x08, 0x09, 0x0b,\n    0x80, 0x8b, 0x00, 0x06, 0x80, 0xc0, 0x03, 0x0f,\n    0x06, 0x80, 0x9b, 0x03, 0x04, 0x00, 0x16, 0x80,\n    0x41, 0x53, 0x81, 0x98, 0x80, 0x98, 0x80, 0x9e,\n    0x80, 0x98, 0x80, 0x9e, 0x80, 0x98, 0x80, 0x9e,\n    0x80, 0x98, 0x80, 0x9e, 0x80, 0x98, 0x07, 0x81,\n    0xb1, 0x55, 0xff, 0x18, 0x9a, 0x01, 0x00, 0x08,\n    0x80, 0x89, 0x03, 0x00, 0x00, 0x28, 0x18, 0x00,\n    0x00, 0x02, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00,\n    0x00, 0x01, 0x00, 0x0b, 0x06, 0x03, 0x03, 0x00,\n    0x80, 0x89, 0x80, 0x90, 0x22, 0x04, 0x80, 0x90,\n};\n\nstatic const uint8_t unicode_prop_Other_Alphabetic_table[411] = {\n    0x43, 0x44, 0x80, 0x42, 0x69, 0x8d, 0x00, 0x01,\n    0x01, 0x00, 0xc7, 0x8a, 0xaf, 0x8c, 0x06, 0x8f,\n    0x80, 0xe4, 0x33, 0x19, 0x0b, 0x80, 0xa2, 0x80,\n    0x9d, 0x8f, 0xe5, 0x8a, 0xe4, 0x0a, 0x88, 0x02,\n    0x03, 0x40, 0xa6, 0x8b, 0x16, 0x85, 0x93, 0xb5,\n    0x09, 0x8e, 0x01, 0x22, 0x89, 0x81, 0x9c, 0x82,\n    0xb9, 0x31, 0x09, 0x81, 0x89, 0x80, 0x89, 0x81,\n    0x9c, 0x82, 0xb9, 0x23, 0x09, 0x0b, 0x80, 0x9d,\n    0x0a, 0x80, 0x8a, 0x82, 0xb9, 0x38, 0x10, 0x81,\n    0x94, 0x81, 0x95, 0x13, 0x82, 0xb9, 0x31, 0x09,\n    0x81, 0x88, 0x81, 0x89, 0x81, 0x9d, 0x80, 0xba,\n    0x22, 0x10, 0x82, 0x89, 0x80, 0xa7, 0x83, 0xb9,\n    0x30, 0x10, 0x17, 0x81, 0x8a, 0x81, 0x9c, 0x82,\n    0xb9, 0x30, 0x10, 0x17, 0x81, 0x8a, 0x81, 0x9b,\n    0x83, 0xb9, 0x30, 0x10, 0x82, 0x89, 0x80, 0x89,\n    0x81, 0x9c, 0x82, 0xca, 0x28, 0x00, 0x87, 0x91,\n    0x81, 0xbc, 0x01, 0x86, 0x91, 0x80, 0xe2, 0x01,\n    0x28, 0x81, 0x8f, 0x80, 0x40, 0xa2, 0x90, 0x8a,\n    0x8a, 0x80, 0xa3, 0xed, 0x8b, 0x00, 0x0b, 0x96,\n    0x1b, 0x10, 0x11, 0x32, 0x83, 0x8c, 0x8b, 0x00,\n    0x89, 0x83, 0x46, 0x73, 0x81, 0x9d, 0x81, 0x9d,\n    0x81, 0x9d, 0x81, 0xc1, 0x92, 0x40, 0xbb, 0x81,\n    0xa1, 0x80, 0xf5, 0x8b, 0x83, 0x88, 0x40, 0xdd,\n    0x84, 0xb8, 0x89, 0x81, 0x93, 0xc9, 0x81, 0xbe,\n    0x84, 0xaf, 0x8e, 0xbb, 0x82, 0x9d, 0x88, 0x09,\n    0xb8, 0x8a, 0xb1, 0x92, 0x41, 0xaf, 0x8d, 0x46,\n    0xc0, 0xb3, 0x48, 0xf5, 0x9f, 0x60, 0x78, 0x73,\n    0x87, 0xa1, 0x81, 0x41, 0x61, 0x07, 0x80, 0x96,\n    0x84, 0xd7, 0x81, 0xb1, 0x8f, 0x00, 0xb8, 0x80,\n    0xa5, 0x84, 0x9b, 0x8b, 0xac, 0x83, 0xaf, 0x8b,\n    0xa4, 0x80, 0xc2, 0x8d, 0x8b, 0x07, 0x81, 0xac,\n    0x82, 0xb1, 0x00, 0x11, 0x0c, 0x80, 0xab, 0x24,\n    0x80, 0x40, 0xec, 0x87, 0x60, 0x4f, 0x32, 0x80,\n    0x48, 0x56, 0x84, 0x46, 0x85, 0x10, 0x0c, 0x83,\n    0x43, 0x13, 0x83, 0x41, 0x82, 0x81, 0x41, 0x52,\n    0x82, 0xb4, 0x8d, 0xbb, 0x80, 0xac, 0x88, 0xc6,\n    0x82, 0xa3, 0x8b, 0x91, 0x81, 0xb8, 0x82, 0xaf,\n    0x8c, 0x8d, 0x81, 0xdb, 0x88, 0x08, 0x28, 0x40,\n    0x9f, 0x89, 0x96, 0x83, 0xb9, 0x31, 0x09, 0x81,\n    0x89, 0x80, 0x89, 0x81, 0x40, 0xd0, 0x8c, 0x02,\n    0xe9, 0x91, 0x40, 0xec, 0x31, 0x86, 0x9c, 0x81,\n    0xd1, 0x8e, 0x00, 0xe9, 0x8a, 0xe6, 0x8d, 0x41,\n    0x00, 0x8c, 0x40, 0xf6, 0x28, 0x09, 0x0a, 0x00,\n    0x80, 0x40, 0x8d, 0x31, 0x2b, 0x80, 0x9b, 0x89,\n    0xa9, 0x20, 0x83, 0x91, 0x8a, 0xad, 0x8d, 0x41,\n    0x96, 0x38, 0x86, 0xd2, 0x95, 0x80, 0x8d, 0xf9,\n    0x2a, 0x00, 0x08, 0x10, 0x02, 0x80, 0xc1, 0x20,\n    0x08, 0x83, 0x41, 0x5b, 0x83, 0x60, 0x50, 0x57,\n    0x00, 0xb6, 0x33, 0xdc, 0x81, 0x60, 0x4c, 0xab,\n    0x80, 0x60, 0x23, 0x60, 0x30, 0x90, 0x0e, 0x01,\n    0x04, 0x49, 0x1b, 0x80, 0x47, 0xe7, 0x99, 0x85,\n    0x99, 0x85, 0x99,\n};\n\nstatic const uint8_t unicode_prop_Other_Lowercase_table[51] = {\n    0x40, 0xa9, 0x80, 0x8e, 0x80, 0x41, 0xf4, 0x88,\n    0x31, 0x9d, 0x84, 0xdf, 0x80, 0xb3, 0x80, 0x59,\n    0xb0, 0xbe, 0x8c, 0x80, 0xa1, 0xa4, 0x42, 0xb0,\n    0x80, 0x8c, 0x80, 0x8f, 0x8c, 0x40, 0xd2, 0x8f,\n    0x43, 0x4f, 0x99, 0x47, 0x91, 0x81, 0x60, 0x7a,\n    0x1d, 0x81, 0x40, 0xd1, 0x80, 0x40, 0x86, 0x81,\n    0x43, 0x61, 0x83,\n};\n\nstatic const uint8_t unicode_prop_Other_Uppercase_table[15] = {\n    0x60, 0x21, 0x5f, 0x8f, 0x43, 0x45, 0x99, 0x61,\n    0xcc, 0x5f, 0x99, 0x85, 0x99, 0x85, 0x99,\n};\n\nstatic const uint8_t unicode_prop_Other_Grapheme_Extend_table[65] = {\n    0x49, 0xbd, 0x80, 0x97, 0x80, 0x41, 0x65, 0x80,\n    0x97, 0x80, 0xe5, 0x80, 0x97, 0x80, 0x40, 0xe9,\n    0x80, 0x91, 0x81, 0xe6, 0x80, 0x97, 0x80, 0xf6,\n    0x80, 0x8e, 0x80, 0x4d, 0x54, 0x80, 0x44, 0xd5,\n    0x80, 0x50, 0x20, 0x81, 0x60, 0xcf, 0x6d, 0x81,\n    0x53, 0x9d, 0x80, 0x97, 0x80, 0x41, 0x57, 0x80,\n    0x8b, 0x80, 0x40, 0xf0, 0x80, 0x43, 0x7f, 0x80,\n    0x60, 0xb8, 0x33, 0x07, 0x84, 0x6c, 0x2e, 0xac,\n    0xdf,\n};\n\nstatic const uint8_t unicode_prop_Other_Default_Ignorable_Code_Point_table[32] = {\n    0x43, 0x4e, 0x80, 0x4e, 0x0e, 0x81, 0x46, 0x52,\n    0x81, 0x48, 0xae, 0x80, 0x50, 0xfd, 0x80, 0x60,\n    0xce, 0x3a, 0x80, 0xce, 0x88, 0x6d, 0x00, 0x06,\n    0x00, 0x9d, 0xdf, 0xff, 0x40, 0xef, 0x4e, 0x0f,\n};\n\nstatic const uint8_t unicode_prop_Other_ID_Start_table[11] = {\n    0x58, 0x84, 0x81, 0x48, 0x90, 0x80, 0x94, 0x80,\n    0x4f, 0x6b, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Other_ID_Continue_table[12] = {\n    0x40, 0xb6, 0x80, 0x42, 0xce, 0x80, 0x4f, 0xe0,\n    0x88, 0x46, 0x67, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Prepended_Concatenation_Mark_table[17] = {\n    0x45, 0xff, 0x85, 0x40, 0xd6, 0x80, 0xb0, 0x80,\n    0x41, 0xd1, 0x80, 0x61, 0x07, 0xd9, 0x80, 0x8e,\n    0x80,\n};\n\nstatic const uint8_t unicode_prop_XID_Start1_table[31] = {\n    0x43, 0x79, 0x80, 0x4a, 0xb7, 0x80, 0xfe, 0x80,\n    0x60, 0x21, 0xe6, 0x81, 0x60, 0xcb, 0xc0, 0x85,\n    0x41, 0x95, 0x81, 0xf3, 0x00, 0x00, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x80, 0x41, 0x1e, 0x81,\n};\n\nstatic const uint8_t unicode_prop_XID_Continue1_table[23] = {\n    0x43, 0x79, 0x80, 0x60, 0x2d, 0x1f, 0x81, 0x60,\n    0xcb, 0xc0, 0x85, 0x41, 0x95, 0x81, 0xf3, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Changes_When_Titlecased1_table[22] = {\n    0x41, 0xc3, 0x08, 0x08, 0x81, 0xa4, 0x81, 0x4e,\n    0xdc, 0xaa, 0x0a, 0x4e, 0x87, 0x3f, 0x3f, 0x87,\n    0x8b, 0x80, 0x8e, 0x80, 0xae, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Changes_When_Casefolded1_table[33] = {\n    0x40, 0xde, 0x80, 0xcf, 0x80, 0x97, 0x80, 0x44,\n    0x3c, 0x80, 0x59, 0x11, 0x80, 0x40, 0xe4, 0x3f,\n    0x3f, 0x87, 0x89, 0x11, 0x05, 0x02, 0x11, 0x80,\n    0xa9, 0x11, 0x80, 0x60, 0xdb, 0x07, 0x86, 0x8b,\n    0x84,\n};\n\nstatic const uint8_t unicode_prop_Changes_When_NFKC_Casefolded1_table[441] = {\n    0x40, 0x9f, 0x06, 0x00, 0x01, 0x00, 0x01, 0x12,\n    0x10, 0x82, 0x9f, 0x80, 0xcf, 0x01, 0x80, 0x8b,\n    0x07, 0x80, 0xfb, 0x01, 0x01, 0x80, 0xa5, 0x80,\n    0x40, 0xbb, 0x88, 0x9e, 0x29, 0x84, 0xda, 0x08,\n    0x81, 0x89, 0x80, 0xa3, 0x04, 0x02, 0x04, 0x08,\n    0x80, 0xc9, 0x82, 0x9c, 0x80, 0x41, 0x93, 0x80,\n    0x40, 0x93, 0x80, 0xd7, 0x83, 0x42, 0xde, 0x87,\n    0xfb, 0x08, 0x80, 0xd2, 0x01, 0x80, 0xa1, 0x11,\n    0x80, 0x40, 0xfc, 0x81, 0x42, 0xd4, 0x80, 0xfe,\n    0x80, 0xa7, 0x81, 0xad, 0x80, 0xb5, 0x80, 0x88,\n    0x03, 0x03, 0x03, 0x80, 0x8b, 0x80, 0x88, 0x00,\n    0x26, 0x80, 0x90, 0x80, 0x88, 0x03, 0x03, 0x03,\n    0x80, 0x8b, 0x80, 0x41, 0x41, 0x80, 0xe1, 0x81,\n    0x46, 0x52, 0x81, 0xd4, 0x83, 0x45, 0x1c, 0x10,\n    0x8a, 0x80, 0x91, 0x80, 0x9b, 0x8c, 0x80, 0xa1,\n    0xa4, 0x40, 0xd9, 0x80, 0x40, 0xd5, 0x00, 0x00,\n    0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x3f, 0x87,\n    0x89, 0x11, 0x04, 0x00, 0x29, 0x04, 0x12, 0x80,\n    0x88, 0x12, 0x80, 0x88, 0x11, 0x11, 0x04, 0x08,\n    0x8f, 0x00, 0x20, 0x8b, 0x12, 0x2a, 0x08, 0x0b,\n    0x00, 0x07, 0x82, 0x8c, 0x06, 0x92, 0x81, 0x9a,\n    0x80, 0x8c, 0x8a, 0x80, 0xd6, 0x18, 0x10, 0x8a,\n    0x01, 0x0c, 0x0a, 0x00, 0x10, 0x11, 0x02, 0x06,\n    0x05, 0x1c, 0x85, 0x8f, 0x8f, 0x8f, 0x88, 0x80,\n    0x40, 0xa1, 0x08, 0x81, 0x40, 0xf7, 0x81, 0x41,\n    0x34, 0xd5, 0x99, 0x9a, 0x45, 0x20, 0x80, 0xe6,\n    0x82, 0xe4, 0x80, 0x41, 0x9e, 0x81, 0x40, 0xf0,\n    0x80, 0x41, 0x2e, 0x80, 0xd2, 0x80, 0x8b, 0x40,\n    0xd5, 0xa9, 0x80, 0xb4, 0x00, 0x82, 0xdf, 0x09,\n    0x80, 0xde, 0x80, 0xb0, 0xdd, 0x82, 0x8d, 0xdf,\n    0x9e, 0x80, 0xa7, 0x87, 0xae, 0x80, 0x41, 0x7f,\n    0x60, 0x72, 0x9b, 0x81, 0x40, 0xd1, 0x80, 0x40,\n    0x86, 0x81, 0x43, 0x61, 0x83, 0x88, 0x80, 0x60,\n    0x4d, 0x95, 0x41, 0x0d, 0x08, 0x00, 0x81, 0x89,\n    0x00, 0x00, 0x09, 0x82, 0xc3, 0x81, 0xe9, 0xa5,\n    0x86, 0x8b, 0x24, 0x00, 0x97, 0x04, 0x00, 0x01,\n    0x01, 0x80, 0xeb, 0xa0, 0x41, 0x6a, 0x91, 0xbf,\n    0x81, 0xb5, 0xa7, 0x8c, 0x82, 0x99, 0x95, 0x94,\n    0x81, 0x8b, 0x80, 0x92, 0x03, 0x1a, 0x00, 0x80,\n    0x40, 0x86, 0x08, 0x80, 0x9f, 0x99, 0x40, 0x83,\n    0x15, 0x0d, 0x0d, 0x0a, 0x16, 0x06, 0x80, 0x88,\n    0x60, 0xbc, 0xa6, 0x83, 0x54, 0xb9, 0x86, 0x8d,\n    0x87, 0xbf, 0x85, 0x42, 0x3e, 0xd4, 0x80, 0xc6,\n    0x01, 0x08, 0x09, 0x0b, 0x80, 0x8b, 0x00, 0x06,\n    0x80, 0xc0, 0x03, 0x0f, 0x06, 0x80, 0x9b, 0x03,\n    0x04, 0x00, 0x16, 0x80, 0x41, 0x53, 0x81, 0x41,\n    0x23, 0x81, 0xb1, 0x55, 0xff, 0x18, 0x9a, 0x01,\n    0x00, 0x08, 0x80, 0x89, 0x03, 0x00, 0x00, 0x28,\n    0x18, 0x00, 0x00, 0x02, 0x01, 0x00, 0x08, 0x00,\n    0x00, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x06, 0x03,\n    0x03, 0x00, 0x80, 0x89, 0x80, 0x90, 0x22, 0x04,\n    0x80, 0x90, 0x42, 0x43, 0x8a, 0x84, 0x9e, 0x80,\n    0x9f, 0x99, 0x82, 0xa2, 0x80, 0xee, 0x82, 0x8c,\n    0xab, 0x83, 0x88, 0x31, 0x49, 0x9d, 0x89, 0x60,\n    0xfc, 0x05, 0x42, 0x1d, 0x6b, 0x05, 0xe1, 0x4f,\n    0xff,\n};\n\nstatic const uint8_t unicode_prop_ASCII_Hex_Digit_table[5] = {\n    0xaf, 0x89, 0x35, 0x99, 0x85,\n};\n\nstatic const uint8_t unicode_prop_Bidi_Control_table[10] = {\n    0x46, 0x1b, 0x80, 0x59, 0xf0, 0x81, 0x99, 0x84,\n    0xb6, 0x83,\n};\n\nstatic const uint8_t unicode_prop_Dash_table[53] = {\n    0xac, 0x80, 0x45, 0x5b, 0x80, 0xb2, 0x80, 0x4e,\n    0x40, 0x80, 0x44, 0x04, 0x80, 0x48, 0x08, 0x85,\n    0xbc, 0x80, 0xa6, 0x80, 0x8e, 0x80, 0x41, 0x85,\n    0x80, 0x4c, 0x03, 0x01, 0x80, 0x9e, 0x0b, 0x80,\n    0x41, 0xda, 0x80, 0x92, 0x80, 0xee, 0x80, 0x60,\n    0xcd, 0x8f, 0x81, 0xa4, 0x80, 0x89, 0x80, 0x40,\n    0xa8, 0x80, 0x4f, 0x9e, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Deprecated_table[23] = {\n    0x41, 0x48, 0x80, 0x45, 0x28, 0x80, 0x49, 0x02,\n    0x00, 0x80, 0x48, 0x28, 0x81, 0x48, 0xc4, 0x85,\n    0x42, 0xb8, 0x81, 0x6d, 0xdc, 0xd5, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Diacritic_table[358] = {\n    0xdd, 0x00, 0x80, 0xc6, 0x05, 0x03, 0x01, 0x81,\n    0x41, 0xf6, 0x40, 0x9e, 0x07, 0x25, 0x90, 0x0b,\n    0x80, 0x88, 0x81, 0x40, 0xfc, 0x84, 0x40, 0xd0,\n    0x80, 0xb6, 0x90, 0x80, 0x9a, 0x00, 0x01, 0x00,\n    0x40, 0x85, 0x3b, 0x81, 0x40, 0x85, 0x0b, 0x0a,\n    0x82, 0xc2, 0x9a, 0xda, 0x8a, 0xb9, 0x8a, 0xa1,\n    0x81, 0x40, 0xc8, 0x9b, 0xbc, 0x80, 0x8f, 0x02,\n    0x83, 0x9b, 0x80, 0xc9, 0x80, 0x8f, 0x80, 0xed,\n    0x80, 0x8f, 0x80, 0xed, 0x80, 0x8f, 0x80, 0xae,\n    0x82, 0xbb, 0x80, 0x8f, 0x06, 0x80, 0xf6, 0x80,\n    0xfe, 0x80, 0xed, 0x80, 0x8f, 0x80, 0xec, 0x81,\n    0x8f, 0x80, 0xfb, 0x80, 0xfb, 0x28, 0x80, 0xea,\n    0x80, 0x8c, 0x84, 0xca, 0x81, 0x9a, 0x00, 0x00,\n    0x03, 0x81, 0xc1, 0x10, 0x81, 0xbd, 0x80, 0xef,\n    0x00, 0x81, 0xa7, 0x0b, 0x84, 0x98, 0x30, 0x80,\n    0x89, 0x81, 0x42, 0xc0, 0x82, 0x44, 0x68, 0x8a,\n    0x88, 0x80, 0x41, 0x5a, 0x82, 0x41, 0x38, 0x39,\n    0x80, 0xaf, 0x8d, 0xf5, 0x80, 0x8e, 0x80, 0xa5,\n    0x88, 0xb5, 0x81, 0x40, 0x89, 0x81, 0xbf, 0x85,\n    0xd1, 0x98, 0x18, 0x28, 0x0a, 0xb1, 0xbe, 0xd8,\n    0x8b, 0xa4, 0x22, 0x82, 0x41, 0xbc, 0x00, 0x82,\n    0x8a, 0x82, 0x8c, 0x82, 0x8c, 0x82, 0x8c, 0x81,\n    0x4c, 0xef, 0x82, 0x41, 0x3c, 0x80, 0x41, 0xf9,\n    0x85, 0xe8, 0x83, 0xde, 0x80, 0x60, 0x75, 0x71,\n    0x80, 0x8b, 0x08, 0x80, 0x9b, 0x81, 0xd1, 0x81,\n    0x8d, 0xa1, 0xe5, 0x82, 0xec, 0x81, 0x40, 0xc9,\n    0x80, 0x9a, 0x91, 0xb8, 0x83, 0xa3, 0x80, 0xde,\n    0x80, 0x8b, 0x80, 0xa3, 0x80, 0x40, 0x94, 0x82,\n    0xc0, 0x83, 0xb2, 0x80, 0xe3, 0x84, 0x88, 0x82,\n    0xff, 0x81, 0x60, 0x4f, 0x2f, 0x80, 0x43, 0x00,\n    0x8f, 0x41, 0x0d, 0x00, 0x80, 0xae, 0x80, 0xac,\n    0x81, 0xc2, 0x80, 0x42, 0xfb, 0x80, 0x48, 0x03,\n    0x81, 0x42, 0x3a, 0x85, 0x42, 0x1d, 0x8a, 0x41,\n    0x67, 0x81, 0xf7, 0x81, 0xbd, 0x80, 0xcb, 0x80,\n    0x88, 0x82, 0xe7, 0x81, 0x40, 0xb1, 0x81, 0xd0,\n    0x80, 0x8f, 0x80, 0x97, 0x32, 0x84, 0x40, 0xcc,\n    0x02, 0x80, 0xfa, 0x81, 0x40, 0xfa, 0x81, 0xfd,\n    0x80, 0xf5, 0x81, 0xf2, 0x80, 0x41, 0x0c, 0x81,\n    0x41, 0x01, 0x0b, 0x80, 0x40, 0x9b, 0x80, 0xd2,\n    0x80, 0x91, 0x80, 0xd0, 0x80, 0x41, 0xa4, 0x80,\n    0x41, 0x01, 0x00, 0x81, 0xd0, 0x80, 0x60, 0x4d,\n    0x57, 0x84, 0xba, 0x86, 0x44, 0x57, 0x90, 0xcf,\n    0x81, 0x60, 0x61, 0x74, 0x12, 0x2f, 0x39, 0x86,\n    0x9d, 0x83, 0x4f, 0x81, 0x86, 0x41, 0xb4, 0x83,\n    0x45, 0xdf, 0x86, 0xec, 0x10, 0x82,\n};\n\nstatic const uint8_t unicode_prop_Extender_table[89] = {\n    0x40, 0xb6, 0x80, 0x42, 0x17, 0x81, 0x43, 0x6d,\n    0x80, 0x41, 0xb8, 0x80, 0x43, 0x59, 0x80, 0x42,\n    0xef, 0x80, 0xfe, 0x80, 0x49, 0x42, 0x80, 0xb7,\n    0x80, 0x42, 0x62, 0x80, 0x41, 0x8d, 0x80, 0xc3,\n    0x80, 0x53, 0x88, 0x80, 0xaa, 0x84, 0xe6, 0x81,\n    0xdc, 0x82, 0x60, 0x6f, 0x15, 0x80, 0x45, 0xf5,\n    0x80, 0x43, 0xc1, 0x80, 0x95, 0x80, 0x40, 0x88,\n    0x80, 0xeb, 0x80, 0x94, 0x81, 0x60, 0x54, 0x7a,\n    0x80, 0x53, 0xeb, 0x80, 0x42, 0x67, 0x82, 0x44,\n    0xce, 0x80, 0x60, 0x50, 0xa8, 0x81, 0x44, 0x9b,\n    0x08, 0x80, 0x60, 0x71, 0x57, 0x81, 0x48, 0x05,\n    0x82,\n};\n\nstatic const uint8_t unicode_prop_Hex_Digit_table[12] = {\n    0xaf, 0x89, 0x35, 0x99, 0x85, 0x60, 0xfe, 0xa8,\n    0x89, 0x35, 0x99, 0x85,\n};\n\nstatic const uint8_t unicode_prop_IDS_Binary_Operator_table[5] = {\n    0x60, 0x2f, 0xef, 0x09, 0x87,\n};\n\nstatic const uint8_t unicode_prop_IDS_Trinary_Operator_table[4] = {\n    0x60, 0x2f, 0xf1, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Ideographic_table[66] = {\n    0x60, 0x30, 0x05, 0x81, 0x98, 0x88, 0x8d, 0x82,\n    0x43, 0xc4, 0x59, 0xbf, 0xbf, 0x60, 0x51, 0xfc,\n    0x60, 0x59, 0x02, 0x41, 0x6d, 0x81, 0xe9, 0x60,\n    0x75, 0x09, 0x80, 0x9a, 0x57, 0xf7, 0x87, 0x44,\n    0xd5, 0xa9, 0x88, 0x60, 0x24, 0x66, 0x41, 0x8b,\n    0x60, 0x4d, 0x03, 0x60, 0xa6, 0xdd, 0xa1, 0x50,\n    0x34, 0x8a, 0x40, 0xdd, 0x81, 0x56, 0x81, 0x8d,\n    0x5d, 0x30, 0x4c, 0x1e, 0x42, 0x1d, 0x45, 0xe1,\n    0x53, 0x4a,\n};\n\nstatic const uint8_t unicode_prop_Join_Control_table[4] = {\n    0x60, 0x20, 0x0b, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Logical_Order_Exception_table[15] = {\n    0x4e, 0x3f, 0x84, 0xfa, 0x84, 0x4a, 0xef, 0x11,\n    0x80, 0x60, 0x90, 0xf9, 0x09, 0x00, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Noncharacter_Code_Point_table[71] = {\n    0x60, 0xfd, 0xcf, 0x9f, 0x42, 0x0d, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81, 0x60,\n    0xff, 0xfd, 0x81, 0x60, 0xff, 0xfd, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Pattern_Syntax_table[58] = {\n    0xa0, 0x8e, 0x89, 0x86, 0x99, 0x18, 0x80, 0x99,\n    0x83, 0xa1, 0x30, 0x00, 0x08, 0x00, 0x0b, 0x03,\n    0x02, 0x80, 0x96, 0x80, 0x9e, 0x80, 0x5f, 0x17,\n    0x97, 0x87, 0x8e, 0x81, 0x92, 0x80, 0x89, 0x41,\n    0x30, 0x42, 0xcf, 0x40, 0x9f, 0x42, 0x75, 0x9d,\n    0x44, 0x6b, 0x41, 0xff, 0xff, 0x41, 0x80, 0x13,\n    0x98, 0x8e, 0x80, 0x60, 0xcd, 0x0c, 0x81, 0x41,\n    0x04, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Pattern_White_Space_table[11] = {\n    0x88, 0x84, 0x91, 0x80, 0xe3, 0x80, 0x5f, 0x87,\n    0x81, 0x97, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Quotation_Mark_table[31] = {\n    0xa1, 0x03, 0x80, 0x40, 0x82, 0x80, 0x8e, 0x80,\n    0x5f, 0x5b, 0x87, 0x98, 0x81, 0x4e, 0x06, 0x80,\n    0x41, 0xc8, 0x83, 0x8c, 0x82, 0x60, 0xce, 0x20,\n    0x83, 0x40, 0xbc, 0x03, 0x80, 0xd9, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Radical_table[9] = {\n    0x60, 0x2e, 0x7f, 0x99, 0x80, 0xd8, 0x8b, 0x40,\n    0xd5,\n};\n\nstatic const uint8_t unicode_prop_Regional_Indicator_table[4] = {\n    0x61, 0xf1, 0xe5, 0x99,\n};\n\nstatic const uint8_t unicode_prop_Sentence_Terminal_table[188] = {\n    0xa0, 0x80, 0x8b, 0x80, 0x8f, 0x80, 0x45, 0x48,\n    0x80, 0x40, 0x93, 0x81, 0x40, 0xb3, 0x80, 0xaa,\n    0x82, 0x40, 0xf5, 0x80, 0xbc, 0x00, 0x02, 0x81,\n    0x41, 0x24, 0x81, 0x46, 0xe3, 0x81, 0x43, 0x15,\n    0x03, 0x81, 0x43, 0x04, 0x80, 0x40, 0xc5, 0x81,\n    0x40, 0xcb, 0x04, 0x80, 0x41, 0x39, 0x81, 0x41,\n    0x61, 0x83, 0x40, 0xad, 0x09, 0x81, 0x40, 0xda,\n    0x81, 0xc0, 0x81, 0x43, 0xbb, 0x81, 0x88, 0x82,\n    0x4d, 0xe3, 0x80, 0x8c, 0x80, 0x41, 0xc4, 0x80,\n    0x60, 0x74, 0xfb, 0x80, 0x41, 0x0d, 0x81, 0x40,\n    0xe2, 0x02, 0x80, 0x41, 0x7d, 0x81, 0xd5, 0x81,\n    0xde, 0x80, 0x40, 0x97, 0x81, 0x40, 0x92, 0x82,\n    0x40, 0x8f, 0x81, 0x40, 0xf8, 0x80, 0x60, 0x52,\n    0x65, 0x02, 0x81, 0x40, 0xa8, 0x80, 0x8b, 0x80,\n    0x8f, 0x80, 0xc0, 0x80, 0x4a, 0xf3, 0x81, 0x44,\n    0xfc, 0x84, 0x40, 0xec, 0x81, 0xf4, 0x83, 0xfe,\n    0x82, 0x40, 0x80, 0x0d, 0x80, 0x8f, 0x81, 0xd7,\n    0x08, 0x81, 0xeb, 0x80, 0x41, 0xa0, 0x81, 0x41,\n    0x74, 0x0c, 0x8e, 0xe8, 0x81, 0x40, 0xf8, 0x82,\n    0x42, 0x04, 0x00, 0x80, 0x40, 0xfa, 0x81, 0xd6,\n    0x81, 0x41, 0xa3, 0x81, 0x42, 0xb3, 0x81, 0x60,\n    0x4b, 0x74, 0x81, 0x40, 0x84, 0x80, 0xc0, 0x81,\n    0x8a, 0x80, 0x43, 0x52, 0x80, 0x60, 0x4e, 0x05,\n    0x80, 0x5d, 0xe7, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Soft_Dotted_table[71] = {\n    0xe8, 0x81, 0x40, 0xc3, 0x80, 0x41, 0x18, 0x80,\n    0x9d, 0x80, 0xb3, 0x80, 0x93, 0x80, 0x41, 0x3f,\n    0x80, 0xe1, 0x00, 0x80, 0x59, 0x08, 0x80, 0xb2,\n    0x80, 0x8c, 0x02, 0x80, 0x40, 0x83, 0x80, 0x40,\n    0x9c, 0x80, 0x41, 0xa4, 0x80, 0x40, 0xd5, 0x81,\n    0x4b, 0x31, 0x80, 0x61, 0xa7, 0xa4, 0x81, 0xb1,\n    0x81, 0xb1, 0x81, 0xb1, 0x81, 0xb1, 0x81, 0xb1,\n    0x81, 0xb1, 0x81, 0xb1, 0x81, 0xb1, 0x81, 0xb1,\n    0x81, 0xb1, 0x81, 0xb1, 0x81, 0xb1, 0x81,\n};\n\nstatic const uint8_t unicode_prop_Terminal_Punctuation_table[241] = {\n    0xa0, 0x80, 0x89, 0x00, 0x80, 0x8a, 0x0a, 0x80,\n    0x43, 0x3d, 0x07, 0x80, 0x42, 0x00, 0x80, 0xb8,\n    0x80, 0xc7, 0x80, 0x8d, 0x01, 0x81, 0x40, 0xb3,\n    0x80, 0xaa, 0x8a, 0x00, 0x40, 0xea, 0x81, 0xb5,\n    0x8e, 0x9e, 0x80, 0x41, 0x04, 0x81, 0x44, 0xf3,\n    0x81, 0x40, 0xab, 0x03, 0x85, 0x41, 0x36, 0x81,\n    0x43, 0x14, 0x87, 0x43, 0x04, 0x80, 0xfb, 0x82,\n    0xc6, 0x81, 0x40, 0x9c, 0x12, 0x80, 0xa6, 0x19,\n    0x81, 0x41, 0x39, 0x81, 0x41, 0x61, 0x83, 0x40,\n    0xad, 0x08, 0x82, 0x40, 0xda, 0x84, 0xbd, 0x81,\n    0x43, 0xbb, 0x81, 0x88, 0x82, 0x4d, 0xe3, 0x80,\n    0x8c, 0x03, 0x80, 0x89, 0x00, 0x81, 0x41, 0xb0,\n    0x81, 0x60, 0x74, 0xfa, 0x81, 0x41, 0x0c, 0x82,\n    0x40, 0xe2, 0x84, 0x41, 0x7d, 0x81, 0xd5, 0x81,\n    0xde, 0x80, 0x40, 0x96, 0x82, 0x40, 0x92, 0x82,\n    0xfe, 0x80, 0x8f, 0x81, 0x40, 0xf8, 0x80, 0x60,\n    0x52, 0x63, 0x10, 0x83, 0x40, 0xa8, 0x80, 0x89,\n    0x00, 0x80, 0x8a, 0x0a, 0x80, 0xc0, 0x01, 0x80,\n    0x44, 0x39, 0x80, 0xaf, 0x80, 0x44, 0x85, 0x80,\n    0x40, 0xc6, 0x80, 0x41, 0x35, 0x81, 0x40, 0x97,\n    0x85, 0xc3, 0x85, 0xd8, 0x83, 0x43, 0xb7, 0x84,\n    0x40, 0xec, 0x86, 0xef, 0x83, 0xfe, 0x82, 0x40,\n    0x80, 0x0d, 0x80, 0x8f, 0x81, 0xd7, 0x84, 0xeb,\n    0x80, 0x41, 0xa0, 0x82, 0x8b, 0x81, 0x41, 0x65,\n    0x1a, 0x8e, 0xe8, 0x81, 0x40, 0xf8, 0x82, 0x42,\n    0x04, 0x00, 0x80, 0x40, 0xfa, 0x81, 0xd6, 0x0b,\n    0x81, 0x41, 0x9d, 0x82, 0xac, 0x80, 0x42, 0x84,\n    0x81, 0x45, 0x76, 0x84, 0x60, 0x45, 0xf8, 0x81,\n    0x40, 0x84, 0x80, 0xc0, 0x82, 0x89, 0x80, 0x43,\n    0x51, 0x81, 0x60, 0x4e, 0x05, 0x80, 0x5d, 0xe6,\n    0x83,\n};\n\nstatic const uint8_t unicode_prop_Unified_Ideograph_table[42] = {\n    0x60, 0x33, 0xff, 0x59, 0xbf, 0xbf, 0x60, 0x51,\n    0xfc, 0x60, 0x5a, 0x10, 0x08, 0x00, 0x81, 0x89,\n    0x00, 0x00, 0x09, 0x82, 0x61, 0x05, 0xd5, 0x60,\n    0xa6, 0xdd, 0xa1, 0x50, 0x34, 0x8a, 0x40, 0xdd,\n    0x81, 0x56, 0x81, 0x8d, 0x5d, 0x30, 0x54, 0x1e,\n    0x53, 0x4a,\n};\n\nstatic const uint8_t unicode_prop_Variation_Selector_table[12] = {\n    0x58, 0x0a, 0x82, 0x60, 0xe5, 0xf1, 0x8f, 0x6d,\n    0x02, 0xef, 0x40, 0xef,\n};\n\nstatic const uint8_t unicode_prop_White_Space_table[22] = {\n    0x88, 0x84, 0x91, 0x80, 0xe3, 0x80, 0x99, 0x80,\n    0x55, 0xde, 0x80, 0x49, 0x7e, 0x8a, 0x9c, 0x0c,\n    0x80, 0xae, 0x80, 0x4f, 0x9f, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Bidi_Mirrored_table[171] = {\n    0xa7, 0x81, 0x91, 0x00, 0x80, 0x9b, 0x00, 0x80,\n    0x9c, 0x00, 0x80, 0xac, 0x80, 0x8e, 0x80, 0x4e,\n    0x7d, 0x83, 0x47, 0x5c, 0x81, 0x49, 0x9b, 0x81,\n    0x89, 0x81, 0xb5, 0x81, 0x8d, 0x81, 0x40, 0xb0,\n    0x80, 0x40, 0xbf, 0x1a, 0x2a, 0x02, 0x0a, 0x18,\n    0x18, 0x00, 0x03, 0x88, 0x20, 0x80, 0x91, 0x23,\n    0x88, 0x08, 0x00, 0x39, 0x9e, 0x0b, 0x20, 0x88,\n    0x09, 0x92, 0x21, 0x88, 0x21, 0x0b, 0x97, 0x81,\n    0x8f, 0x3b, 0x93, 0x0e, 0x81, 0x44, 0x3c, 0x8d,\n    0xc9, 0x01, 0x18, 0x08, 0x14, 0x1c, 0x12, 0x8d,\n    0x41, 0x92, 0x95, 0x0d, 0x80, 0x8d, 0x38, 0x35,\n    0x10, 0x1c, 0x01, 0x0c, 0x18, 0x02, 0x09, 0x89,\n    0x29, 0x81, 0x8b, 0x92, 0x03, 0x08, 0x00, 0x08,\n    0x03, 0x21, 0x2a, 0x97, 0x81, 0x8a, 0x0b, 0x18,\n    0x09, 0x0b, 0xaa, 0x0f, 0x80, 0xa7, 0x20, 0x00,\n    0x14, 0x22, 0x18, 0x14, 0x00, 0x40, 0xff, 0x80,\n    0x42, 0x02, 0x1a, 0x08, 0x81, 0x8d, 0x09, 0x89,\n    0x41, 0xdd, 0x89, 0x0f, 0x60, 0xce, 0x3c, 0x2c,\n    0x81, 0x40, 0xa1, 0x81, 0x91, 0x00, 0x80, 0x9b,\n    0x00, 0x80, 0x9c, 0x00, 0x00, 0x08, 0x81, 0x60,\n    0xd7, 0x76, 0x80, 0xb8, 0x80, 0xb8, 0x80, 0xb8,\n    0x80, 0xb8, 0x80,\n};\n\nstatic const uint8_t unicode_prop_Emoji_table[238] = {\n    0xa2, 0x05, 0x04, 0x89, 0xee, 0x03, 0x80, 0x5f,\n    0x8c, 0x80, 0x8b, 0x80, 0x40, 0xd7, 0x80, 0x95,\n    0x80, 0xd9, 0x85, 0x8e, 0x81, 0x41, 0x6e, 0x81,\n    0x8b, 0x80, 0x40, 0xa5, 0x80, 0x98, 0x8a, 0x1a,\n    0x40, 0xc6, 0x80, 0x40, 0xe6, 0x81, 0x89, 0x80,\n    0x88, 0x80, 0xb9, 0x18, 0x84, 0x88, 0x01, 0x01,\n    0x09, 0x03, 0x01, 0x00, 0x09, 0x02, 0x02, 0x0f,\n    0x14, 0x00, 0x04, 0x8b, 0x8a, 0x09, 0x00, 0x08,\n    0x80, 0x91, 0x01, 0x81, 0x91, 0x28, 0x00, 0x0a,\n    0x0c, 0x01, 0x0b, 0x81, 0x8a, 0x0c, 0x09, 0x04,\n    0x08, 0x00, 0x81, 0x93, 0x0c, 0x28, 0x19, 0x03,\n    0x01, 0x01, 0x28, 0x01, 0x00, 0x00, 0x05, 0x02,\n    0x05, 0x80, 0x89, 0x81, 0x8e, 0x01, 0x03, 0x00,\n    0x03, 0x10, 0x80, 0x8a, 0x81, 0xaf, 0x82, 0x88,\n    0x80, 0x8d, 0x80, 0x8d, 0x80, 0x41, 0x73, 0x81,\n    0x41, 0xce, 0x82, 0x92, 0x81, 0xb2, 0x03, 0x80,\n    0x44, 0xd9, 0x80, 0x8b, 0x80, 0x42, 0x58, 0x00,\n    0x80, 0x61, 0xbd, 0x69, 0x80, 0x40, 0xc9, 0x80,\n    0x40, 0x9f, 0x81, 0x8b, 0x81, 0x8d, 0x01, 0x89,\n    0xca, 0x99, 0x01, 0x96, 0x80, 0x93, 0x01, 0x88,\n    0x94, 0x81, 0x40, 0xad, 0xa1, 0x81, 0xef, 0x09,\n    0x02, 0x81, 0xd2, 0x0a, 0x80, 0x41, 0x06, 0x80,\n    0xbe, 0x8a, 0x28, 0x97, 0x31, 0x0f, 0x8b, 0x01,\n    0x19, 0x03, 0x81, 0x8c, 0x09, 0x07, 0x81, 0x88,\n    0x04, 0x82, 0x8b, 0x17, 0x11, 0x00, 0x03, 0x05,\n    0x02, 0x05, 0xd5, 0xaf, 0xc5, 0x27, 0x0a, 0x3d,\n    0x10, 0x01, 0x10, 0x81, 0x89, 0x40, 0xe2, 0x8b,\n    0x41, 0x1f, 0xae, 0x80, 0x89, 0x80, 0xb1, 0x80,\n    0xd1, 0x80, 0xb2, 0xef, 0x22, 0x14, 0x86, 0x88,\n    0x98, 0x36, 0x88, 0x82, 0x8c, 0x86,\n};\n\nstatic const uint8_t unicode_prop_Emoji_Component_table[28] = {\n    0xa2, 0x05, 0x04, 0x89, 0x5f, 0xd2, 0x80, 0x40,\n    0xd4, 0x80, 0x60, 0xdd, 0x2a, 0x80, 0x60, 0xf3,\n    0xd5, 0x99, 0x41, 0xfa, 0x84, 0x45, 0xaf, 0x83,\n    0x6c, 0x06, 0x6b, 0xdf,\n};\n\nstatic const uint8_t unicode_prop_Emoji_Modifier_table[4] = {\n    0x61, 0xf3, 0xfa, 0x84,\n};\n\nstatic const uint8_t unicode_prop_Emoji_Modifier_Base_table[66] = {\n    0x60, 0x26, 0x1c, 0x80, 0x40, 0xda, 0x80, 0x8f,\n    0x83, 0x61, 0xcc, 0x76, 0x80, 0xbb, 0x11, 0x01,\n    0x82, 0xf4, 0x09, 0x8a, 0x94, 0x92, 0x10, 0x1a,\n    0x02, 0x30, 0x00, 0x97, 0x80, 0x40, 0xc8, 0x0b,\n    0x80, 0x94, 0x03, 0x81, 0x40, 0xad, 0x12, 0x84,\n    0xd2, 0x80, 0x8f, 0x82, 0x88, 0x80, 0x8a, 0x80,\n    0x42, 0x3e, 0x01, 0x07, 0x3d, 0x80, 0x88, 0x89,\n    0x0a, 0xb7, 0x80, 0xbc, 0x08, 0x08, 0x80, 0x90,\n    0x10, 0x8c,\n};\n\nstatic const uint8_t unicode_prop_Emoji_Presentation_table[144] = {\n    0x60, 0x23, 0x19, 0x81, 0x40, 0xcc, 0x1a, 0x01,\n    0x80, 0x42, 0x08, 0x81, 0x94, 0x81, 0xb1, 0x8b,\n    0xaa, 0x80, 0x92, 0x80, 0x8c, 0x07, 0x81, 0x90,\n    0x0c, 0x0f, 0x04, 0x80, 0x94, 0x06, 0x08, 0x03,\n    0x01, 0x06, 0x03, 0x81, 0x9b, 0x80, 0xa2, 0x00,\n    0x03, 0x10, 0x80, 0xbc, 0x82, 0x97, 0x80, 0x8d,\n    0x80, 0x43, 0x5a, 0x81, 0xb2, 0x03, 0x80, 0x61,\n    0xc4, 0xad, 0x80, 0x40, 0xc9, 0x80, 0x40, 0xbd,\n    0x01, 0x89, 0xca, 0x99, 0x00, 0x97, 0x80, 0x93,\n    0x01, 0x20, 0x82, 0x94, 0x81, 0x40, 0xad, 0xa0,\n    0x8b, 0x88, 0x80, 0xc5, 0x80, 0x95, 0x8b, 0xaa,\n    0x1c, 0x8b, 0x90, 0x10, 0x82, 0xc6, 0x00, 0x80,\n    0x40, 0xba, 0x81, 0xbe, 0x8c, 0x18, 0x97, 0x91,\n    0x80, 0x99, 0x81, 0x8c, 0x80, 0xd5, 0xd4, 0xaf,\n    0xc5, 0x28, 0x12, 0x0a, 0x92, 0x0e, 0x88, 0x40,\n    0xe2, 0x8b, 0x41, 0x1f, 0xae, 0x80, 0x89, 0x80,\n    0xb1, 0x80, 0xd1, 0x80, 0xb2, 0xef, 0x22, 0x14,\n    0x86, 0x88, 0x98, 0x36, 0x88, 0x82, 0x8c, 0x86,\n};\n\nstatic const uint8_t unicode_prop_Extended_Pictographic_table[156] = {\n    0x40, 0xa8, 0x03, 0x80, 0x5f, 0x8c, 0x80, 0x8b,\n    0x80, 0x40, 0xd7, 0x80, 0x95, 0x80, 0xd9, 0x85,\n    0x8e, 0x81, 0x41, 0x6e, 0x81, 0x8b, 0x80, 0xde,\n    0x80, 0xc5, 0x80, 0x98, 0x8a, 0x1a, 0x40, 0xc6,\n    0x80, 0x40, 0xe6, 0x81, 0x89, 0x80, 0x88, 0x80,\n    0xb9, 0x18, 0x28, 0x8b, 0x80, 0xf1, 0x89, 0xf5,\n    0x81, 0x8a, 0x00, 0x00, 0x28, 0x10, 0x28, 0x89,\n    0x81, 0x8e, 0x01, 0x03, 0x00, 0x03, 0x10, 0x80,\n    0x8a, 0x84, 0xac, 0x82, 0x88, 0x80, 0x8d, 0x80,\n    0x8d, 0x80, 0x41, 0x73, 0x81, 0x41, 0xce, 0x82,\n    0x92, 0x81, 0xb2, 0x03, 0x80, 0x44, 0xd9, 0x80,\n    0x8b, 0x80, 0x42, 0x58, 0x00, 0x80, 0x61, 0xbd,\n    0x65, 0x40, 0xff, 0x8c, 0x82, 0x9e, 0x80, 0xbb,\n    0x85, 0x8b, 0x81, 0x8d, 0x01, 0x89, 0x91, 0xb8,\n    0x9a, 0x8e, 0x89, 0x80, 0x93, 0x01, 0x88, 0x03,\n    0x88, 0x41, 0xb1, 0x84, 0x41, 0x3d, 0x87, 0x41,\n    0x09, 0xaf, 0xff, 0xf3, 0x8b, 0xd4, 0xaa, 0x8b,\n    0x83, 0xb7, 0x87, 0x89, 0x85, 0xa7, 0x87, 0x9d,\n    0xd1, 0x8b, 0xae, 0x80, 0x89, 0x80, 0x41, 0xb8,\n    0x40, 0xff, 0x43, 0xfd,\n};\n\nstatic const uint8_t unicode_prop_Default_Ignorable_Code_Point_table[51] = {\n    0x40, 0xac, 0x80, 0x42, 0xa0, 0x80, 0x42, 0xcb,\n    0x80, 0x4b, 0x41, 0x81, 0x46, 0x52, 0x81, 0xd4,\n    0x83, 0x47, 0xfb, 0x84, 0x99, 0x84, 0xb0, 0x8f,\n    0x50, 0xf3, 0x80, 0x60, 0xcc, 0x9a, 0x8f, 0x40,\n    0xee, 0x80, 0x40, 0x9f, 0x80, 0xce, 0x88, 0x60,\n    0xbc, 0xa6, 0x83, 0x54, 0xce, 0x87, 0x6c, 0x2e,\n    0x84, 0x4f, 0xff,\n};\n\ntypedef enum {\n    UNICODE_PROP_Hyphen,\n    UNICODE_PROP_Other_Math,\n    UNICODE_PROP_Other_Alphabetic,\n    UNICODE_PROP_Other_Lowercase,\n    UNICODE_PROP_Other_Uppercase,\n    UNICODE_PROP_Other_Grapheme_Extend,\n    UNICODE_PROP_Other_Default_Ignorable_Code_Point,\n    UNICODE_PROP_Other_ID_Start,\n    UNICODE_PROP_Other_ID_Continue,\n    UNICODE_PROP_Prepended_Concatenation_Mark,\n    UNICODE_PROP_ID_Continue1,\n    UNICODE_PROP_XID_Start1,\n    UNICODE_PROP_XID_Continue1,\n    UNICODE_PROP_Changes_When_Titlecased1,\n    UNICODE_PROP_Changes_When_Casefolded1,\n    UNICODE_PROP_Changes_When_NFKC_Casefolded1,\n    UNICODE_PROP_ASCII_Hex_Digit,\n    UNICODE_PROP_Bidi_Control,\n    UNICODE_PROP_Dash,\n    UNICODE_PROP_Deprecated,\n    UNICODE_PROP_Diacritic,\n    UNICODE_PROP_Extender,\n    UNICODE_PROP_Hex_Digit,\n    UNICODE_PROP_IDS_Binary_Operator,\n    UNICODE_PROP_IDS_Trinary_Operator,\n    UNICODE_PROP_Ideographic,\n    UNICODE_PROP_Join_Control,\n    UNICODE_PROP_Logical_Order_Exception,\n    UNICODE_PROP_Noncharacter_Code_Point,\n    UNICODE_PROP_Pattern_Syntax,\n    UNICODE_PROP_Pattern_White_Space,\n    UNICODE_PROP_Quotation_Mark,\n    UNICODE_PROP_Radical,\n    UNICODE_PROP_Regional_Indicator,\n    UNICODE_PROP_Sentence_Terminal,\n    UNICODE_PROP_Soft_Dotted,\n    UNICODE_PROP_Terminal_Punctuation,\n    UNICODE_PROP_Unified_Ideograph,\n    UNICODE_PROP_Variation_Selector,\n    UNICODE_PROP_White_Space,\n    UNICODE_PROP_Bidi_Mirrored,\n    UNICODE_PROP_Emoji,\n    UNICODE_PROP_Emoji_Component,\n    UNICODE_PROP_Emoji_Modifier,\n    UNICODE_PROP_Emoji_Modifier_Base,\n    UNICODE_PROP_Emoji_Presentation,\n    UNICODE_PROP_Extended_Pictographic,\n    UNICODE_PROP_Default_Ignorable_Code_Point,\n    UNICODE_PROP_ID_Start,\n    UNICODE_PROP_Case_Ignorable,\n    UNICODE_PROP_ASCII,\n    UNICODE_PROP_Alphabetic,\n    UNICODE_PROP_Any,\n    UNICODE_PROP_Assigned,\n    UNICODE_PROP_Cased,\n    UNICODE_PROP_Changes_When_Casefolded,\n    UNICODE_PROP_Changes_When_Casemapped,\n    UNICODE_PROP_Changes_When_Lowercased,\n    UNICODE_PROP_Changes_When_NFKC_Casefolded,\n    UNICODE_PROP_Changes_When_Titlecased,\n    UNICODE_PROP_Changes_When_Uppercased,\n    UNICODE_PROP_Grapheme_Base,\n    UNICODE_PROP_Grapheme_Extend,\n    UNICODE_PROP_ID_Continue,\n    UNICODE_PROP_Lowercase,\n    UNICODE_PROP_Math,\n    UNICODE_PROP_Uppercase,\n    UNICODE_PROP_XID_Continue,\n    UNICODE_PROP_XID_Start,\n    UNICODE_PROP_Cased1,\n    UNICODE_PROP_COUNT,\n} UnicodePropertyEnum;\n\nstatic const char unicode_prop_name_table[] =\n    \"ASCII_Hex_Digit,AHex\"               \"\\0\"\n    \"Bidi_Control,Bidi_C\"                \"\\0\"\n    \"Dash\"                               \"\\0\"\n    \"Deprecated,Dep\"                     \"\\0\"\n    \"Diacritic,Dia\"                      \"\\0\"\n    \"Extender,Ext\"                       \"\\0\"\n    \"Hex_Digit,Hex\"                      \"\\0\"\n    \"IDS_Binary_Operator,IDSB\"           \"\\0\"\n    \"IDS_Trinary_Operator,IDST\"          \"\\0\"\n    \"Ideographic,Ideo\"                   \"\\0\"\n    \"Join_Control,Join_C\"                \"\\0\"\n    \"Logical_Order_Exception,LOE\"        \"\\0\"\n    \"Noncharacter_Code_Point,NChar\"      \"\\0\"\n    \"Pattern_Syntax,Pat_Syn\"             \"\\0\"\n    \"Pattern_White_Space,Pat_WS\"         \"\\0\"\n    \"Quotation_Mark,QMark\"               \"\\0\"\n    \"Radical\"                            \"\\0\"\n    \"Regional_Indicator,RI\"              \"\\0\"\n    \"Sentence_Terminal,STerm\"            \"\\0\"\n    \"Soft_Dotted,SD\"                     \"\\0\"\n    \"Terminal_Punctuation,Term\"          \"\\0\"\n    \"Unified_Ideograph,UIdeo\"            \"\\0\"\n    \"Variation_Selector,VS\"              \"\\0\"\n    \"White_Space,space\"                  \"\\0\"\n    \"Bidi_Mirrored,Bidi_M\"               \"\\0\"\n    \"Emoji\"                              \"\\0\"\n    \"Emoji_Component,EComp\"              \"\\0\"\n    \"Emoji_Modifier,EMod\"                \"\\0\"\n    \"Emoji_Modifier_Base,EBase\"          \"\\0\"\n    \"Emoji_Presentation,EPres\"           \"\\0\"\n    \"Extended_Pictographic,ExtPict\"      \"\\0\"\n    \"Default_Ignorable_Code_Point,DI\"    \"\\0\"\n    \"ID_Start,IDS\"                       \"\\0\"\n    \"Case_Ignorable,CI\"                  \"\\0\"\n    \"ASCII\"                              \"\\0\"\n    \"Alphabetic,Alpha\"                   \"\\0\"\n    \"Any\"                                \"\\0\"\n    \"Assigned\"                           \"\\0\"\n    \"Cased\"                              \"\\0\"\n    \"Changes_When_Casefolded,CWCF\"       \"\\0\"\n    \"Changes_When_Casemapped,CWCM\"       \"\\0\"\n    \"Changes_When_Lowercased,CWL\"        \"\\0\"\n    \"Changes_When_NFKC_Casefolded,CWKCF\" \"\\0\"\n    \"Changes_When_Titlecased,CWT\"        \"\\0\"\n    \"Changes_When_Uppercased,CWU\"        \"\\0\"\n    \"Grapheme_Base,Gr_Base\"              \"\\0\"\n    \"Grapheme_Extend,Gr_Ext\"             \"\\0\"\n    \"ID_Continue,IDC\"                    \"\\0\"\n    \"Lowercase,Lower\"                    \"\\0\"\n    \"Math\"                               \"\\0\"\n    \"Uppercase,Upper\"                    \"\\0\"\n    \"XID_Continue,XIDC\"                  \"\\0\"\n    \"XID_Start,XIDS\"                     \"\\0\"\n;\n\nstatic const uint8_t * const unicode_prop_table[] = {\n    unicode_prop_Hyphen_table,\n    unicode_prop_Other_Math_table,\n    unicode_prop_Other_Alphabetic_table,\n    unicode_prop_Other_Lowercase_table,\n    unicode_prop_Other_Uppercase_table,\n    unicode_prop_Other_Grapheme_Extend_table,\n    unicode_prop_Other_Default_Ignorable_Code_Point_table,\n    unicode_prop_Other_ID_Start_table,\n    unicode_prop_Other_ID_Continue_table,\n    unicode_prop_Prepended_Concatenation_Mark_table,\n    unicode_prop_ID_Continue1_table,\n    unicode_prop_XID_Start1_table,\n    unicode_prop_XID_Continue1_table,\n    unicode_prop_Changes_When_Titlecased1_table,\n    unicode_prop_Changes_When_Casefolded1_table,\n    unicode_prop_Changes_When_NFKC_Casefolded1_table,\n    unicode_prop_ASCII_Hex_Digit_table,\n    unicode_prop_Bidi_Control_table,\n    unicode_prop_Dash_table,\n    unicode_prop_Deprecated_table,\n    unicode_prop_Diacritic_table,\n    unicode_prop_Extender_table,\n    unicode_prop_Hex_Digit_table,\n    unicode_prop_IDS_Binary_Operator_table,\n    unicode_prop_IDS_Trinary_Operator_table,\n    unicode_prop_Ideographic_table,\n    unicode_prop_Join_Control_table,\n    unicode_prop_Logical_Order_Exception_table,\n    unicode_prop_Noncharacter_Code_Point_table,\n    unicode_prop_Pattern_Syntax_table,\n    unicode_prop_Pattern_White_Space_table,\n    unicode_prop_Quotation_Mark_table,\n    unicode_prop_Radical_table,\n    unicode_prop_Regional_Indicator_table,\n    unicode_prop_Sentence_Terminal_table,\n    unicode_prop_Soft_Dotted_table,\n    unicode_prop_Terminal_Punctuation_table,\n    unicode_prop_Unified_Ideograph_table,\n    unicode_prop_Variation_Selector_table,\n    unicode_prop_White_Space_table,\n    unicode_prop_Bidi_Mirrored_table,\n    unicode_prop_Emoji_table,\n    unicode_prop_Emoji_Component_table,\n    unicode_prop_Emoji_Modifier_table,\n    unicode_prop_Emoji_Modifier_Base_table,\n    unicode_prop_Emoji_Presentation_table,\n    unicode_prop_Extended_Pictographic_table,\n    unicode_prop_Default_Ignorable_Code_Point_table,\n    unicode_prop_ID_Start_table,\n    unicode_prop_Case_Ignorable_table,\n};\n\nstatic const uint16_t unicode_prop_len_table[] = {\n    countof(unicode_prop_Hyphen_table),\n    countof(unicode_prop_Other_Math_table),\n    countof(unicode_prop_Other_Alphabetic_table),\n    countof(unicode_prop_Other_Lowercase_table),\n    countof(unicode_prop_Other_Uppercase_table),\n    countof(unicode_prop_Other_Grapheme_Extend_table),\n    countof(unicode_prop_Other_Default_Ignorable_Code_Point_table),\n    countof(unicode_prop_Other_ID_Start_table),\n    countof(unicode_prop_Other_ID_Continue_table),\n    countof(unicode_prop_Prepended_Concatenation_Mark_table),\n    countof(unicode_prop_ID_Continue1_table),\n    countof(unicode_prop_XID_Start1_table),\n    countof(unicode_prop_XID_Continue1_table),\n    countof(unicode_prop_Changes_When_Titlecased1_table),\n    countof(unicode_prop_Changes_When_Casefolded1_table),\n    countof(unicode_prop_Changes_When_NFKC_Casefolded1_table),\n    countof(unicode_prop_ASCII_Hex_Digit_table),\n    countof(unicode_prop_Bidi_Control_table),\n    countof(unicode_prop_Dash_table),\n    countof(unicode_prop_Deprecated_table),\n    countof(unicode_prop_Diacritic_table),\n    countof(unicode_prop_Extender_table),\n    countof(unicode_prop_Hex_Digit_table),\n    countof(unicode_prop_IDS_Binary_Operator_table),\n    countof(unicode_prop_IDS_Trinary_Operator_table),\n    countof(unicode_prop_Ideographic_table),\n    countof(unicode_prop_Join_Control_table),\n    countof(unicode_prop_Logical_Order_Exception_table),\n    countof(unicode_prop_Noncharacter_Code_Point_table),\n    countof(unicode_prop_Pattern_Syntax_table),\n    countof(unicode_prop_Pattern_White_Space_table),\n    countof(unicode_prop_Quotation_Mark_table),\n    countof(unicode_prop_Radical_table),\n    countof(unicode_prop_Regional_Indicator_table),\n    countof(unicode_prop_Sentence_Terminal_table),\n    countof(unicode_prop_Soft_Dotted_table),\n    countof(unicode_prop_Terminal_Punctuation_table),\n    countof(unicode_prop_Unified_Ideograph_table),\n    countof(unicode_prop_Variation_Selector_table),\n    countof(unicode_prop_White_Space_table),\n    countof(unicode_prop_Bidi_Mirrored_table),\n    countof(unicode_prop_Emoji_table),\n    countof(unicode_prop_Emoji_Component_table),\n    countof(unicode_prop_Emoji_Modifier_table),\n    countof(unicode_prop_Emoji_Modifier_Base_table),\n    countof(unicode_prop_Emoji_Presentation_table),\n    countof(unicode_prop_Extended_Pictographic_table),\n    countof(unicode_prop_Default_Ignorable_Code_Point_table),\n    countof(unicode_prop_ID_Start_table),\n    countof(unicode_prop_Case_Ignorable_table),\n};\n\n#endif /* CONFIG_ALL_UNICODE */\n"
  },
  {
    "path": "libunicode.c",
    "content": "/*\n * Unicode utilities\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <stdarg.h>\n#include <string.h>\n#include <assert.h>\n\n#include \"cutils.h\"\n#include \"libunicode.h\"\n#include \"libunicode-table.h\"\n\nenum {\n    RUN_TYPE_U,\n    RUN_TYPE_L,\n    RUN_TYPE_UF,\n    RUN_TYPE_LF,\n    RUN_TYPE_UL,\n    RUN_TYPE_LSU,\n    RUN_TYPE_U2L_399_EXT2,\n    RUN_TYPE_UF_D20,\n    RUN_TYPE_UF_D1_EXT,\n    RUN_TYPE_U_EXT,\n    RUN_TYPE_LF_EXT,\n    RUN_TYPE_U_EXT2,\n    RUN_TYPE_L_EXT2,\n    RUN_TYPE_U_EXT3,\n};\n\n/* conv_type:\n   0 = to upper \n   1 = to lower\n   2 = case folding (= to lower with modifications) \n*/\nint lre_case_conv(uint32_t *res, uint32_t c, int conv_type)\n{\n    if (c < 128) {\n        if (conv_type) {\n            if (c >= 'A' && c <= 'Z') {\n                c = c - 'A' + 'a';\n            }\n        } else {\n            if (c >= 'a' && c <= 'z') {\n                c = c - 'a' + 'A';\n            }\n        }\n    } else {\n        uint32_t v, code, data, type, len, a, is_lower;\n        int idx, idx_min, idx_max;\n        \n        is_lower = (conv_type != 0);\n        idx_min = 0;\n        idx_max = countof(case_conv_table1) - 1;\n        while (idx_min <= idx_max) {\n            idx = (unsigned)(idx_max + idx_min) / 2;\n            v = case_conv_table1[idx];\n            code = v >> (32 - 17);\n            len = (v >> (32 - 17 - 7)) & 0x7f;\n            if (c < code) {\n                idx_max = idx - 1;\n            } else if (c >= code + len) {\n                idx_min = idx + 1;\n            } else {\n                type = (v >> (32 - 17 - 7 - 4)) & 0xf;\n                data = ((v & 0xf) << 8) | case_conv_table2[idx];\n                switch(type) {\n                case RUN_TYPE_U:\n                case RUN_TYPE_L:\n                case RUN_TYPE_UF:\n                case RUN_TYPE_LF:\n                    if (conv_type == (type & 1) ||\n                        (type >= RUN_TYPE_UF && conv_type == 2)) {\n                        c = c - code + (case_conv_table1[data] >> (32 - 17));\n                    }\n                    break;\n                case RUN_TYPE_UL:\n                    a = c - code;\n                    if ((a & 1) != (1 - is_lower))\n                        break;\n                    c = (a ^ 1) + code;\n                    break;\n                case RUN_TYPE_LSU:\n                    a = c - code;\n                    if (a == 1) {\n                        c += 2 * is_lower - 1;\n                    } else if (a == (1 - is_lower) * 2) {\n                        c += (2 * is_lower - 1) * 2;\n                    }\n                    break;\n                case RUN_TYPE_U2L_399_EXT2:\n                    if (!is_lower) {\n                        res[0] = c - code + case_conv_ext[data >> 6];\n                        res[1] = 0x399;\n                        return 2;\n                    } else {\n                        c = c - code + case_conv_ext[data & 0x3f];\n                    }\n                    break;\n                case RUN_TYPE_UF_D20:\n                    if (conv_type == 1)\n                        break;\n                    c = data + (conv_type == 2) * 0x20;\n                    break;\n                case RUN_TYPE_UF_D1_EXT:\n                    if (conv_type == 1)\n                        break;\n                    c = case_conv_ext[data] + (conv_type == 2);\n                    break;\n                case RUN_TYPE_U_EXT:\n                case RUN_TYPE_LF_EXT:\n                    if (is_lower != (type - RUN_TYPE_U_EXT))\n                        break;\n                    c = case_conv_ext[data];\n                    break;\n                case RUN_TYPE_U_EXT2:\n                case RUN_TYPE_L_EXT2:\n                    if (conv_type != (type - RUN_TYPE_U_EXT2))\n                        break;\n                    res[0] = c - code + case_conv_ext[data >> 6];\n                    res[1] = case_conv_ext[data & 0x3f];\n                    return 2;\n                default:\n                case RUN_TYPE_U_EXT3:\n                    if (conv_type != 0)\n                        break;\n                    res[0] = case_conv_ext[data >> 8];\n                    res[1] = case_conv_ext[(data >> 4) & 0xf];\n                    res[2] = case_conv_ext[data & 0xf];\n                    return 3;\n                }\n                break;\n            }\n        }\n    }\n    res[0] = c;\n    return 1;\n}\n\nstatic uint32_t get_le24(const uint8_t *ptr)\n{\n#if defined(__x86__) || defined(__x86_64__)\n    return *(uint16_t *)ptr | (ptr[2] << 16);\n#else\n    return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);\n#endif\n}\n\n#define UNICODE_INDEX_BLOCK_LEN 32\n\n/* return -1 if not in table, otherwise the offset in the block */\nstatic int get_index_pos(uint32_t *pcode, uint32_t c,\n                         const uint8_t *index_table, int index_table_len)\n{\n    uint32_t code, v;\n    int idx_min, idx_max, idx;\n\n    idx_min = 0;\n    v = get_le24(index_table);\n    code = v & ((1 << 21) - 1);\n    if (c < code) {\n        *pcode = 0;\n        return 0;\n    }\n    idx_max = index_table_len - 1;\n    code = get_le24(index_table + idx_max * 3);\n    if (c >= code)\n        return -1;\n    /* invariant: tab[idx_min] <= c < tab2[idx_max] */\n    while ((idx_max - idx_min) > 1) {\n        idx = (idx_max + idx_min) / 2;\n        v = get_le24(index_table + idx * 3);\n        code = v & ((1 << 21) - 1);\n        if (c < code) {\n            idx_max = idx;\n        } else {\n            idx_min = idx;\n        }\n    }\n    v = get_le24(index_table + idx_min * 3);\n    *pcode = v & ((1 << 21) - 1);\n    return (idx_min + 1) * UNICODE_INDEX_BLOCK_LEN + (v >> 21);\n}\n\nstatic BOOL lre_is_in_table(uint32_t c, const uint8_t *table,\n                            const uint8_t *index_table, int index_table_len)\n{\n    uint32_t code, b, bit;\n    int pos;\n    const uint8_t *p;\n    \n    pos = get_index_pos(&code, c, index_table, index_table_len);\n    if (pos < 0)\n        return FALSE; /* outside the table */\n    p = table + pos;\n    bit = 0;\n    for(;;) {\n        b = *p++;\n        if (b < 64) {\n            code += (b >> 3) + 1;\n            if (c < code)\n                return bit;\n            bit ^= 1;\n            code += (b & 7) + 1;\n        } else if (b >= 0x80) {\n            code += b - 0x80 + 1;\n        } else if (b < 0x60) {\n            code += (((b - 0x40) << 8) | p[0]) + 1;\n            p++;\n        } else {\n            code += (((b - 0x60) << 16) | (p[0] << 8) | p[1]) + 1;\n            p += 2;\n        }\n        if (c < code)\n            return bit;\n        bit ^= 1;\n    }\n}\n\nBOOL lre_is_cased(uint32_t c)\n{\n    uint32_t v, code, len;\n    int idx, idx_min, idx_max;\n        \n    idx_min = 0;\n    idx_max = countof(case_conv_table1) - 1;\n    while (idx_min <= idx_max) {\n        idx = (unsigned)(idx_max + idx_min) / 2;\n        v = case_conv_table1[idx];\n        code = v >> (32 - 17);\n        len = (v >> (32 - 17 - 7)) & 0x7f;\n        if (c < code) {\n            idx_max = idx - 1;\n        } else if (c >= code + len) {\n            idx_min = idx + 1;\n        } else {\n            return TRUE;\n        }\n    }\n    return lre_is_in_table(c, unicode_prop_Cased1_table,\n                           unicode_prop_Cased1_index,\n                           sizeof(unicode_prop_Cased1_index) / 3);\n}\n\nBOOL lre_is_case_ignorable(uint32_t c)\n{\n    return lre_is_in_table(c, unicode_prop_Case_Ignorable_table,\n                           unicode_prop_Case_Ignorable_index,\n                           sizeof(unicode_prop_Case_Ignorable_index) / 3);\n}\n\n/* character range */\n\nstatic __maybe_unused void cr_dump(CharRange *cr)\n{\n    int i;\n    for(i = 0; i < cr->len; i++)\n        printf(\"%d: 0x%04x\\n\", i, cr->points[i]);\n}\n\nstatic void *cr_default_realloc(void *opaque, void *ptr, size_t size)\n{\n    return realloc(ptr, size);\n}\n\nvoid cr_init(CharRange *cr, void *mem_opaque, DynBufReallocFunc *realloc_func)\n{\n    cr->len = cr->size = 0;\n    cr->points = NULL;\n    cr->mem_opaque = mem_opaque;\n    cr->realloc_func = realloc_func ? realloc_func : cr_default_realloc;\n}\n\nvoid cr_free(CharRange *cr)\n{\n    cr->realloc_func(cr->mem_opaque, cr->points, 0);\n}\n\nint cr_realloc(CharRange *cr, int size)\n{\n    int new_size;\n    uint32_t *new_buf;\n    \n    if (size > cr->size) {\n        new_size = max_int(size, cr->size * 3 / 2);\n        new_buf = cr->realloc_func(cr->mem_opaque, cr->points,\n                                   new_size * sizeof(cr->points[0]));\n        if (!new_buf)\n            return -1;\n        cr->points = new_buf;\n        cr->size = new_size;\n    }\n    return 0;\n}\n\nint cr_copy(CharRange *cr, const CharRange *cr1)\n{\n    if (cr_realloc(cr, cr1->len))\n        return -1;\n    memcpy(cr->points, cr1->points, sizeof(cr->points[0]) * cr1->len);\n    cr->len = cr1->len;\n    return 0;\n}\n\n/* merge consecutive intervals and remove empty intervals */\nstatic void cr_compress(CharRange *cr)\n{\n    int i, j, k, len;\n    uint32_t *pt;\n    \n    pt = cr->points;\n    len = cr->len;\n    i = 0;\n    j = 0;\n    k = 0;\n    while ((i + 1) < len) {\n        if (pt[i] == pt[i + 1]) {\n            /* empty interval */\n            i += 2;\n        } else {\n            j = i;\n            while ((j + 3) < len && pt[j + 1] == pt[j + 2])\n                j += 2;\n            /* just copy */\n            pt[k] = pt[i];\n            pt[k + 1] = pt[j + 1];\n            k += 2;\n            i = j + 2;\n        }\n    }\n    cr->len = k;\n}\n\n/* union or intersection */\nint cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,\n          const uint32_t *b_pt, int b_len, int op)\n{\n    int a_idx, b_idx, is_in;\n    uint32_t v;\n    \n    a_idx = 0;\n    b_idx = 0;\n    for(;;) {\n        /* get one more point from a or b in increasing order */\n        if (a_idx < a_len && b_idx < b_len) {\n            if (a_pt[a_idx] < b_pt[b_idx]) {\n                goto a_add;\n            } else if (a_pt[a_idx] == b_pt[b_idx]) {\n                v = a_pt[a_idx];\n                a_idx++;\n                b_idx++;\n            } else {\n                goto b_add;\n            }\n        } else if (a_idx < a_len) {\n        a_add:\n            v = a_pt[a_idx++];\n        } else if (b_idx < b_len) {\n        b_add:\n            v = b_pt[b_idx++];\n        } else {\n            break;\n        }\n        /* add the point if the in/out status changes */\n        switch(op) {\n        case CR_OP_UNION:\n            is_in = (a_idx & 1) | (b_idx & 1);\n            break;\n        case CR_OP_INTER:\n            is_in = (a_idx & 1) & (b_idx & 1);\n            break;\n        case CR_OP_XOR:\n            is_in = (a_idx & 1) ^ (b_idx & 1);\n            break;\n        default:\n            abort();\n        }\n        if (is_in != (cr->len & 1)) {\n            if (cr_add_point(cr, v))\n                return -1;\n        }\n    }\n    cr_compress(cr);\n    return 0;\n}\n\nint cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len)\n{\n    CharRange a = *cr;\n    int ret;\n    cr->len = 0;\n    cr->size = 0;\n    cr->points = NULL;\n    ret = cr_op(cr, a.points, a.len, b_pt, b_len, CR_OP_UNION);\n    cr_free(&a);\n    return ret;\n}\n\nint cr_invert(CharRange *cr)\n{\n    int len;\n    len = cr->len;\n    if (cr_realloc(cr, len + 2))\n        return -1;\n    memmove(cr->points + 1, cr->points, len * sizeof(cr->points[0]));\n    cr->points[0] = 0;\n    cr->points[len + 1] = UINT32_MAX;\n    cr->len = len + 2;\n    cr_compress(cr);\n    return 0;\n}\n\n#ifdef CONFIG_ALL_UNICODE\n\nBOOL lre_is_id_start(uint32_t c)\n{\n    return lre_is_in_table(c, unicode_prop_ID_Start_table,\n                           unicode_prop_ID_Start_index,\n                           sizeof(unicode_prop_ID_Start_index) / 3);\n}\n\nBOOL lre_is_id_continue(uint32_t c)\n{\n    return lre_is_id_start(c) ||\n        lre_is_in_table(c, unicode_prop_ID_Continue1_table,\n                        unicode_prop_ID_Continue1_index,\n                        sizeof(unicode_prop_ID_Continue1_index) / 3);\n}\n\n#define UNICODE_DECOMP_LEN_MAX 18\n\ntypedef enum {\n    DECOMP_TYPE_C1, /* 16 bit char */\n    DECOMP_TYPE_L1, /* 16 bit char table */\n    DECOMP_TYPE_L2,\n    DECOMP_TYPE_L3,\n    DECOMP_TYPE_L4,\n    DECOMP_TYPE_L5, /* XXX: not used */\n    DECOMP_TYPE_L6, /* XXX: could remove */\n    DECOMP_TYPE_L7, /* XXX: could remove */\n    DECOMP_TYPE_LL1, /* 18 bit char table */\n    DECOMP_TYPE_LL2,\n    DECOMP_TYPE_S1, /* 8 bit char table */\n    DECOMP_TYPE_S2,\n    DECOMP_TYPE_S3,\n    DECOMP_TYPE_S4,\n    DECOMP_TYPE_S5,\n    DECOMP_TYPE_I1, /* increment 16 bit char value */\n    DECOMP_TYPE_I2_0,\n    DECOMP_TYPE_I2_1,\n    DECOMP_TYPE_I3_1,\n    DECOMP_TYPE_I3_2,\n    DECOMP_TYPE_I4_1,\n    DECOMP_TYPE_I4_2,\n    DECOMP_TYPE_B1, /* 16 bit base + 8 bit offset */\n    DECOMP_TYPE_B2,\n    DECOMP_TYPE_B3,\n    DECOMP_TYPE_B4,\n    DECOMP_TYPE_B5,\n    DECOMP_TYPE_B6,\n    DECOMP_TYPE_B7,\n    DECOMP_TYPE_B8,\n    DECOMP_TYPE_B18,\n    DECOMP_TYPE_LS2,\n    DECOMP_TYPE_PAT3,\n    DECOMP_TYPE_S2_UL,\n    DECOMP_TYPE_LS2_UL,\n} DecompTypeEnum;\n\nstatic uint32_t unicode_get_short_code(uint32_t c)\n{\n    static const uint16_t unicode_short_table[2] = { 0x2044, 0x2215 };\n\n    if (c < 0x80)\n        return c;\n    else if (c < 0x80 + 0x50)\n        return c - 0x80 + 0x300;\n    else\n        return unicode_short_table[c - 0x80 - 0x50];\n}\n\nstatic uint32_t unicode_get_lower_simple(uint32_t c)\n{\n    if (c < 0x100 || (c >= 0x410 && c <= 0x42f))\n        c += 0x20;\n    else\n        c++;\n    return c;\n}\n\nstatic uint16_t unicode_get16(const uint8_t *p)\n{\n    return p[0] | (p[1] << 8);\n}\n\nstatic int unicode_decomp_entry(uint32_t *res, uint32_t c,\n                                int idx, uint32_t code, uint32_t len,\n                                uint32_t type)\n{\n    uint32_t c1;\n    int l, i, p;\n    const uint8_t *d;\n\n    if (type == DECOMP_TYPE_C1) {\n        res[0] = unicode_decomp_table2[idx];\n        return 1;\n    } else {\n        d = unicode_decomp_data + unicode_decomp_table2[idx];\n        switch(type) {\n        case DECOMP_TYPE_L1 ... DECOMP_TYPE_L7:\n            l = type - DECOMP_TYPE_L1 + 1;\n            d += (c - code) * l * 2;\n            for(i = 0; i < l; i++) {\n                if ((res[i] = unicode_get16(d + 2 * i)) == 0)\n                    return 0;\n            }\n            return l;\n        case DECOMP_TYPE_LL1 ... DECOMP_TYPE_LL2:\n            {\n                uint32_t k, p;\n                l = type - DECOMP_TYPE_LL1 + 1;\n                k = (c - code) * l;\n                p = len * l * 2;\n                for(i = 0; i < l; i++) {\n                    c1 = unicode_get16(d + 2 * k) |\n                        (((d[p + (k / 4)] >> ((k % 4) * 2)) & 3) << 16);\n                    if (!c1)\n                        return 0;\n                    res[i] = c1;\n                    k++;\n                }\n            }\n            return l;\n        case DECOMP_TYPE_S1 ... DECOMP_TYPE_S5:\n            l = type - DECOMP_TYPE_S1 + 1;\n            d += (c - code) * l;\n            for(i = 0; i < l; i++) {\n                if ((res[i] = unicode_get_short_code(d[i])) == 0)\n                    return 0;\n            }\n            return l;\n        case DECOMP_TYPE_I1:\n            l = 1;\n            p = 0;\n            goto decomp_type_i;\n        case DECOMP_TYPE_I2_0:\n        case DECOMP_TYPE_I2_1:\n        case DECOMP_TYPE_I3_1:\n        case DECOMP_TYPE_I3_2:\n        case DECOMP_TYPE_I4_1:\n        case DECOMP_TYPE_I4_2:\n            l = 2 + ((type - DECOMP_TYPE_I2_0) >> 1);\n            p = ((type - DECOMP_TYPE_I2_0) & 1) + (l > 2);\n        decomp_type_i:\n            for(i = 0; i < l; i++) {\n                c1 = unicode_get16(d + 2 * i);\n                if (i == p)\n                    c1 += c - code;\n                res[i] = c1;\n            }\n            return l;\n        case DECOMP_TYPE_B18:\n            l = 18;\n            goto decomp_type_b;\n        case DECOMP_TYPE_B1 ... DECOMP_TYPE_B8:\n            l = type - DECOMP_TYPE_B1 + 1;\n        decomp_type_b:\n            {\n                uint32_t c_min;\n                c_min = unicode_get16(d);\n                d += 2 + (c - code) * l;\n                for(i = 0; i < l; i++) {\n                    c1 = d[i];\n                    if (c1 == 0xff)\n                        c1 = 0x20;\n                    else\n                        c1 += c_min;\n                    res[i] = c1;\n                }\n            }\n            return l;\n        case DECOMP_TYPE_LS2:\n            d += (c - code) * 3;\n            if (!(res[0] = unicode_get16(d)))\n                return 0;\n            res[1] = unicode_get_short_code(d[2]);\n            return 2;\n        case DECOMP_TYPE_PAT3:\n            res[0] = unicode_get16(d);\n            res[2] = unicode_get16(d + 2);\n            d += 4 + (c - code) * 2;\n            res[1] = unicode_get16(d);\n            return 3;\n        case DECOMP_TYPE_S2_UL:\n        case DECOMP_TYPE_LS2_UL:\n            c1 = c - code;\n            if (type == DECOMP_TYPE_S2_UL) {\n                d += c1 & ~1;\n                c = unicode_get_short_code(*d);\n                d++;\n            } else {\n                d += (c1 >> 1) * 3;\n                c = unicode_get16(d);\n                d += 2;\n            }\n            if (c1 & 1)\n                c = unicode_get_lower_simple(c);\n            res[0] = c;\n            res[1] = unicode_get_short_code(*d);\n            return 2;\n        }\n    }\n    return 0;\n}\n\n\n/* return the length of the decomposition (length <=\n   UNICODE_DECOMP_LEN_MAX) or 0 if no decomposition */\nstatic int unicode_decomp_char(uint32_t *res, uint32_t c, BOOL is_compat1)\n{\n    uint32_t v, type, is_compat, code, len;\n    int idx_min, idx_max, idx;\n    \n    idx_min = 0;\n    idx_max = countof(unicode_decomp_table1) - 1;\n    while (idx_min <= idx_max) {\n        idx = (idx_max + idx_min) / 2;\n        v = unicode_decomp_table1[idx];\n        code = v >> (32 - 18);\n        len = (v >> (32 - 18 - 7)) & 0x7f;\n        //        printf(\"idx=%d code=%05x len=%d\\n\", idx, code, len);\n        if (c < code) {\n            idx_max = idx - 1;\n        } else if (c >= code + len) {\n            idx_min = idx + 1;\n        } else {\n            is_compat = v & 1;\n            if (is_compat1 < is_compat)\n                break;\n            type = (v >> (32 - 18 - 7 - 6)) & 0x3f;\n            return unicode_decomp_entry(res, c, idx, code, len, type);\n        }\n    }\n    return 0;\n}\n\n/* return 0 if no pair found */\nstatic int unicode_compose_pair(uint32_t c0, uint32_t c1)\n{\n    uint32_t code, len, type, v, idx1, d_idx, d_offset, ch;\n    int idx_min, idx_max, idx, d;\n    uint32_t pair[2];\n    \n    idx_min = 0;\n    idx_max = countof(unicode_comp_table) - 1;\n    while (idx_min <= idx_max) {\n        idx = (idx_max + idx_min) / 2;\n        idx1 = unicode_comp_table[idx];\n\n        /* idx1 represent an entry of the decomposition table */\n        d_idx = idx1 >> 6;\n        d_offset = idx1 & 0x3f;\n        v = unicode_decomp_table1[d_idx];\n        code = v >> (32 - 18);\n        len = (v >> (32 - 18 - 7)) & 0x7f;\n        type = (v >> (32 - 18 - 7 - 6)) & 0x3f;\n        ch = code + d_offset;\n        unicode_decomp_entry(pair, ch, d_idx, code, len, type);\n        d = c0 - pair[0];\n        if (d == 0)\n            d = c1 - pair[1];\n        if (d < 0) {\n            idx_max = idx - 1;\n        } else if (d > 0) {\n            idx_min = idx + 1;\n        } else {\n            return ch;\n        }\n    }\n    return 0;\n}\n\n/* return the combining class of character c (between 0 and 255) */\nstatic int unicode_get_cc(uint32_t c)\n{\n    uint32_t code, n, type, cc, c1, b;\n    int pos;\n    const uint8_t *p;\n    \n    pos = get_index_pos(&code, c,\n                        unicode_cc_index, sizeof(unicode_cc_index) / 3);\n    if (pos < 0)\n        return 0;\n    p = unicode_cc_table + pos;\n    for(;;) {\n        b = *p++;\n        type = b >> 6;\n        n = b & 0x3f;\n        if (n < 48) {\n        } else if (n < 56) {\n            n = (n - 48) << 8;\n            n |= *p++;\n            n += 48;\n        } else {\n            n = (n - 56) << 8;\n            n |= *p++ << 8;\n            n |= *p++;\n            n += 48 + (1 << 11);\n        }\n        if (type <= 1)\n            p++;\n        c1 = code + n + 1;\n        if (c < c1) {\n            switch(type) {\n            case 0:\n                cc = p[-1];\n                break;\n            case 1:\n                cc = p[-1] + c - code;\n                break;\n            case 2:\n                cc = 0;\n                break;\n            default:\n            case 3:\n                cc = 230;\n                break;\n            }\n            return cc;\n        }\n        code = c1;\n    }\n}\n\nstatic void sort_cc(int *buf, int len)\n{\n    int i, j, k, cc, cc1, start, ch1;\n    \n    for(i = 0; i < len; i++) {\n        cc = unicode_get_cc(buf[i]);\n        if (cc != 0) {\n            start = i;\n            j = i + 1;\n            while (j < len) {\n                ch1 = buf[j];\n                cc1 = unicode_get_cc(ch1);\n                if (cc1 == 0)\n                    break;\n                k = j - 1;\n                while (k >= start) {\n                    if (unicode_get_cc(buf[k]) <= cc1)\n                        break;\n                    buf[k + 1] = buf[k];\n                    k--;\n                }\n                buf[k + 1] = ch1;\n                j++;\n            }\n#if 0\n            printf(\"cc:\");\n            for(k = start; k < j; k++) {\n                printf(\" %3d\", unicode_get_cc(buf[k]));\n            }\n            printf(\"\\n\");\n#endif\n            i = j;\n        }\n    }\n}\n\nstatic void to_nfd_rec(DynBuf *dbuf,\n                       const int *src, int src_len, int is_compat)\n{\n    uint32_t c, v;\n    int i, l;\n    uint32_t res[UNICODE_DECOMP_LEN_MAX];\n    \n    for(i = 0; i < src_len; i++) {\n        c = src[i];\n        if (c >= 0xac00 && c < 0xd7a4) {\n            /* Hangul decomposition */\n            c -= 0xac00;\n            dbuf_put_u32(dbuf, 0x1100 + c / 588);\n            dbuf_put_u32(dbuf, 0x1161 + (c % 588) / 28);\n            v = c % 28;\n            if (v != 0)\n                dbuf_put_u32(dbuf, 0x11a7 + v);\n        } else {\n            l = unicode_decomp_char(res, c, is_compat);\n            if (l) {\n                to_nfd_rec(dbuf, (int *)res, l, is_compat);\n            } else {\n                dbuf_put_u32(dbuf, c);\n            }\n        }\n    }\n}\n\n/* return 0 if not found */\nstatic int compose_pair(uint32_t c0, uint32_t c1)\n{\n    /* Hangul composition */\n    if (c0 >= 0x1100 && c0 < 0x1100 + 19 &&\n        c1 >= 0x1161 && c1 < 0x1161 + 21) {\n        return 0xac00 + (c0 - 0x1100) * 588 + (c1 - 0x1161) * 28;\n    } else if (c0 >= 0xac00 && c0 < 0xac00 + 11172 &&\n               (c0 - 0xac00) % 28 == 0 &&\n               c1 >= 0x11a7 && c1 < 0x11a7 + 28) {\n        return c0 + c1 - 0x11a7;\n    } else {\n        return unicode_compose_pair(c0, c1);\n    }\n}\n\nint unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,\n                      UnicodeNormalizationEnum n_type,\n                      void *opaque, DynBufReallocFunc *realloc_func)\n{\n    int *buf, buf_len, i, p, starter_pos, cc, last_cc, out_len;\n    BOOL is_compat;\n    DynBuf dbuf_s, *dbuf = &dbuf_s;\n    \n    is_compat = n_type >> 1;\n\n    dbuf_init2(dbuf, opaque, realloc_func);\n    if (dbuf_realloc(dbuf, sizeof(int) * src_len))\n        goto fail;\n\n    /* common case: latin1 is unaffected by NFC */\n    if (n_type == UNICODE_NFC) {\n        for(i = 0; i < src_len; i++) {\n            if (src[i] >= 0x100)\n                goto not_latin1;\n        }\n        buf = (int *)dbuf->buf;\n        memcpy(buf, src, src_len * sizeof(int));\n        *pdst = (uint32_t *)buf;\n        return src_len;\n    not_latin1: ;\n    }\n\n    to_nfd_rec(dbuf, (const int *)src, src_len, is_compat);\n    if (dbuf_error(dbuf)) {\n    fail:\n        *pdst = NULL;\n        return -1;\n    }\n    buf = (int *)dbuf->buf;\n    buf_len = dbuf->size / sizeof(int);\n        \n    sort_cc(buf, buf_len);\n    \n    if (buf_len <= 1 || (n_type & 1) != 0) {\n        /* NFD / NFKD */\n        *pdst = (uint32_t *)buf;\n        return buf_len;\n    }\n    \n    i = 1;\n    out_len = 1;\n    while (i < buf_len) {\n        /* find the starter character and test if it is blocked from\n           the character at 'i' */\n        last_cc = unicode_get_cc(buf[i]);\n        starter_pos = out_len - 1;\n        while (starter_pos >= 0) {\n            cc = unicode_get_cc(buf[starter_pos]);\n            if (cc == 0)\n                break;\n            if (cc >= last_cc)\n                goto next;\n            last_cc = 256;\n            starter_pos--;\n        }\n        if (starter_pos >= 0 &&\n            (p = compose_pair(buf[starter_pos], buf[i])) != 0) {\n            buf[starter_pos] = p;\n            i++;\n        } else {\n        next:\n            buf[out_len++] = buf[i++];\n        }\n    }\n    *pdst = (uint32_t *)buf;\n    return out_len;\n}\n\n/* char ranges for various unicode properties */\n\nstatic int unicode_find_name(const char *name_table, const char *name)\n{\n    const char *p, *r;\n    int pos;\n    size_t name_len, len;\n    \n    p = name_table;\n    pos = 0;\n    name_len = strlen(name);\n    while (*p) {\n        for(;;) {\n            r = strchr(p, ',');\n            if (!r)\n                len = strlen(p);\n            else\n                len = r - p;\n            if (len == name_len && !memcmp(p, name, name_len))\n                return pos;\n            p += len + 1;\n            if (!r)\n                break;\n        }\n        pos++;\n    }\n    return -1;\n}\n\n/* 'cr' must be initialized and empty. Return 0 if OK, -1 if error, -2\n   if not found */\nint unicode_script(CharRange *cr,\n                   const char *script_name, BOOL is_ext)\n{\n    int script_idx;\n    const uint8_t *p, *p_end;\n    uint32_t c, c1, b, n, v, v_len, i, type;\n    CharRange cr1_s, *cr1;\n    CharRange cr2_s, *cr2 = &cr2_s;\n    BOOL is_common;\n    \n    script_idx = unicode_find_name(unicode_script_name_table, script_name);\n    if (script_idx < 0)\n        return -2;\n    /* Note: we remove the \"Unknown\" Script */\n    script_idx += UNICODE_SCRIPT_Unknown + 1;\n        \n    is_common = (script_idx == UNICODE_SCRIPT_Common ||\n                 script_idx == UNICODE_SCRIPT_Inherited);\n    if (is_ext) {\n        cr1 = &cr1_s;\n        cr_init(cr1, cr->mem_opaque, cr->realloc_func);\n        cr_init(cr2, cr->mem_opaque, cr->realloc_func);\n    } else {\n        cr1 = cr;\n    }\n\n    p = unicode_script_table;\n    p_end = unicode_script_table + countof(unicode_script_table);\n    c = 0;\n    while (p < p_end) {\n        b = *p++;\n        type = b >> 7;\n        n = b & 0x7f;\n        if (n < 96) {\n        } else if (n < 112) {\n            n = (n - 96) << 8;\n            n |= *p++;\n            n += 96;\n        } else {\n            n = (n - 112) << 16;\n            n |= *p++ << 8;\n            n |= *p++;\n            n += 96 + (1 << 12);\n        }\n        if (type == 0)\n            v = 0;\n        else\n            v = *p++;\n        c1 = c + n + 1;\n        if (v == script_idx) {\n            if (cr_add_interval(cr1, c, c1))\n                goto fail;\n        }\n        c = c1;\n    }\n\n    if (is_ext) {\n        /* add the script extensions */\n        p = unicode_script_ext_table;\n        p_end = unicode_script_ext_table + countof(unicode_script_ext_table);\n        c = 0;\n        while (p < p_end) {\n            b = *p++;\n            if (b < 128) {\n                n = b;\n            } else if (b < 128 + 64) {\n                n = (b - 128) << 8;\n                n |= *p++;\n                n += 128;\n            } else {\n                n = (b - 128 - 64) << 16;\n                n |= *p++ << 8;\n                n |= *p++;\n                n += 128 + (1 << 14);\n            }\n            c1 = c + n + 1;\n            v_len = *p++;\n            if (is_common) {\n                if (v_len != 0) {\n                    if (cr_add_interval(cr2, c, c1))\n                        goto fail;\n                }\n            } else {\n                for(i = 0; i < v_len; i++) {\n                    if (p[i] == script_idx) {\n                        if (cr_add_interval(cr2, c, c1))\n                            goto fail;\n                        break;\n                    }\n                }\n            }\n            p += v_len;\n            c = c1;\n        }\n        if (is_common) {\n            /* remove all the characters with script extensions */\n            if (cr_invert(cr2))\n                goto fail;\n            if (cr_op(cr, cr1->points, cr1->len, cr2->points, cr2->len,\n                      CR_OP_INTER))\n                goto fail;\n        } else {\n            if (cr_op(cr, cr1->points, cr1->len, cr2->points, cr2->len,\n                      CR_OP_UNION))\n                goto fail;\n        }\n        cr_free(cr1);\n        cr_free(cr2);\n    }\n    return 0;\n fail:\n    if (is_ext) {\n        cr_free(cr1);\n        cr_free(cr2);\n    }\n    goto fail;\n}\n\n#define M(id) (1U << UNICODE_GC_ ## id)\n\nstatic int unicode_general_category1(CharRange *cr, uint32_t gc_mask)\n{\n    const uint8_t *p, *p_end;\n    uint32_t c, c0, b, n, v;\n\n    p = unicode_gc_table;\n    p_end = unicode_gc_table + countof(unicode_gc_table);\n    c = 0;\n    while (p < p_end) {\n        b = *p++;\n        n = b >> 5;\n        v = b & 0x1f;\n        if (n == 7) {\n            n = *p++;\n            if (n < 128) {\n                n += 7;\n            } else if (n < 128 + 64) {\n                n = (n - 128) << 8;\n                n |= *p++;\n                n += 7 + 128;\n            } else {\n                n = (n - 128 - 64) << 16;\n                n |= *p++ << 8;\n                n |= *p++;\n                n += 7 + 128 + (1 << 14);\n            }\n        }\n        c0 = c;\n        c += n + 1;\n        if (v == 31) {\n            /* run of Lu / Ll */\n            b = gc_mask & (M(Lu) | M(Ll));\n            if (b != 0) {\n                if (b == (M(Lu) | M(Ll))) {\n                    goto add_range;\n                } else {\n                    c0 += ((gc_mask & M(Ll)) != 0);\n                    for(; c0 < c; c0 += 2) {\n                        if (cr_add_interval(cr, c0, c0 + 1))\n                            return -1;\n                    }\n                }\n            }\n        } else if ((gc_mask >> v) & 1) {\n        add_range:\n            if (cr_add_interval(cr, c0, c))\n                return -1;\n        }\n    }\n    return 0;\n}\n\nstatic int unicode_prop1(CharRange *cr, int prop_idx)\n{\n    const uint8_t *p, *p_end;\n    uint32_t c, c0, b, bit;\n\n    p = unicode_prop_table[prop_idx];\n    p_end = p + unicode_prop_len_table[prop_idx];\n    c = 0;\n    bit = 0;\n    while (p < p_end) {\n        c0 = c;\n        b = *p++;\n        if (b < 64) {\n            c += (b >> 3) + 1;\n            if (bit)  {\n                if (cr_add_interval(cr, c0, c))\n                    return -1;\n            }\n            bit ^= 1;\n            c0 = c;\n            c += (b & 7) + 1;\n        } else if (b >= 0x80) {\n            c += b - 0x80 + 1;\n        } else if (b < 0x60) {\n            c += (((b - 0x40) << 8) | p[0]) + 1;\n            p++;\n        } else {\n            c += (((b - 0x60) << 16) | (p[0] << 8) | p[1]) + 1;\n            p += 2;\n        }\n        if (bit)  {\n            if (cr_add_interval(cr, c0, c))\n                return -1;\n        }\n        bit ^= 1;\n    }\n    return 0;\n}\n\n#define CASE_U (1 << 0)\n#define CASE_L (1 << 1)\n#define CASE_F (1 << 2)\n\n/* use the case conversion table to generate range of characters.\n   CASE_U: set char if modified by uppercasing,\n   CASE_L: set char if modified by lowercasing,\n   CASE_F: set char if modified by case folding,\n */\nstatic int unicode_case1(CharRange *cr, int case_mask)\n{\n#define MR(x) (1 << RUN_TYPE_ ## x)\n    const uint32_t tab_run_mask[3] = {\n        MR(U) | MR(UF) | MR(UL) | MR(LSU) | MR(U2L_399_EXT2) | MR(UF_D20) |\n        MR(UF_D1_EXT) | MR(U_EXT) | MR(U_EXT2) | MR(U_EXT3),\n\n        MR(L) | MR(LF) | MR(UL) | MR(LSU) | MR(U2L_399_EXT2) | MR(LF_EXT) | MR(L_EXT2),\n\n        MR(UF) | MR(LF) | MR(UL) | MR(LSU) | MR(U2L_399_EXT2) | MR(LF_EXT) | MR(UF_D20) | MR(UF_D1_EXT) | MR(LF_EXT),\n    };\n#undef MR\n    uint32_t mask, v, code, type, len, i, idx;\n\n    if (case_mask == 0)\n        return 0;\n    mask = 0;\n    for(i = 0; i < 3; i++) {\n        if ((case_mask >> i) & 1)\n            mask |= tab_run_mask[i];\n    }\n    for(idx = 0; idx < countof(case_conv_table1); idx++) {\n        v = case_conv_table1[idx];\n        type = (v >> (32 - 17 - 7 - 4)) & 0xf;\n        code = v >> (32 - 17);\n        len = (v >> (32 - 17 - 7)) & 0x7f;\n        if ((mask >> type) & 1) {\n            //            printf(\"%d: type=%d %04x %04x\\n\", idx, type, code, code + len - 1);\n            switch(type) {\n            case RUN_TYPE_UL:\n                if ((case_mask & CASE_U) && (case_mask & (CASE_L | CASE_F)))\n                    goto def_case;\n                code += ((case_mask & CASE_U) != 0);\n                for(i = 0; i < len; i += 2) {\n                    if (cr_add_interval(cr, code + i, code + i + 1))\n                        return -1;\n                }\n                break;\n            case RUN_TYPE_LSU:\n                if ((case_mask & CASE_U) && (case_mask & (CASE_L | CASE_F)))\n                    goto def_case;\n                if (!(case_mask & CASE_U)) {\n                    if (cr_add_interval(cr, code, code + 1))\n                        return -1;\n                }\n                if (cr_add_interval(cr, code + 1, code + 2))\n                    return -1;\n                if (case_mask & CASE_U) {\n                    if (cr_add_interval(cr, code + 2, code + 3))\n                        return -1;\n                }\n                break;\n            default:\n            def_case:\n                if (cr_add_interval(cr, code, code + len))\n                    return -1;\n                break;\n            }\n        }\n    }\n    return 0;\n}\n        \ntypedef enum {\n    POP_GC,\n    POP_PROP,\n    POP_CASE,\n    POP_UNION,\n    POP_INTER,\n    POP_XOR,\n    POP_INVERT,\n    POP_END,\n} PropOPEnum;\n\n#define POP_STACK_LEN_MAX 4\n\nstatic int unicode_prop_ops(CharRange *cr, ...)\n{\n    va_list ap;\n    CharRange stack[POP_STACK_LEN_MAX];\n    int stack_len, op, ret, i;\n    uint32_t a;\n    \n    va_start(ap, cr);\n    stack_len = 0;\n    for(;;) {\n        op = va_arg(ap, int);\n        switch(op) {\n        case POP_GC:\n            assert(stack_len < POP_STACK_LEN_MAX);\n            a = va_arg(ap, int);\n            cr_init(&stack[stack_len++], cr->mem_opaque, cr->realloc_func);\n            if (unicode_general_category1(&stack[stack_len - 1], a))\n                goto fail;\n            break;\n        case POP_PROP:\n            assert(stack_len < POP_STACK_LEN_MAX);\n            a = va_arg(ap, int);\n            cr_init(&stack[stack_len++], cr->mem_opaque, cr->realloc_func);\n            if (unicode_prop1(&stack[stack_len - 1], a))\n                goto fail;\n            break;\n        case POP_CASE:\n            assert(stack_len < POP_STACK_LEN_MAX);\n            a = va_arg(ap, int);\n            cr_init(&stack[stack_len++], cr->mem_opaque, cr->realloc_func);\n            if (unicode_case1(&stack[stack_len - 1], a))\n                goto fail;\n            break;\n        case POP_UNION:\n        case POP_INTER:\n        case POP_XOR:\n            {\n                CharRange *cr1, *cr2, *cr3;\n                assert(stack_len >= 2);\n                assert(stack_len < POP_STACK_LEN_MAX);\n                cr1 = &stack[stack_len - 2];\n                cr2 = &stack[stack_len - 1];\n                cr3 = &stack[stack_len++];\n                cr_init(cr3, cr->mem_opaque, cr->realloc_func);\n                if (cr_op(cr3, cr1->points, cr1->len,\n                          cr2->points, cr2->len, op - POP_UNION + CR_OP_UNION))\n                    goto fail;\n                cr_free(cr1);\n                cr_free(cr2);\n                *cr1 = *cr3;\n                stack_len -= 2;\n            }\n            break;\n        case POP_INVERT:\n            assert(stack_len >= 1);\n            if (cr_invert(&stack[stack_len - 1]))\n                goto fail;\n            break;\n        case POP_END:\n            goto done;\n        default:\n            abort();\n        }\n    }\n done:\n    assert(stack_len == 1);\n    ret = cr_copy(cr, &stack[0]);\n    cr_free(&stack[0]);\n    return ret;\n fail:\n    for(i = 0; i < stack_len; i++)\n        cr_free(&stack[i]);\n    return -1;\n}\n\nstatic const uint32_t unicode_gc_mask_table[] = {\n    M(Lu) | M(Ll) | M(Lt), /* LC */\n    M(Lu) | M(Ll) | M(Lt) | M(Lm) | M(Lo), /* L */\n    M(Mn) | M(Mc) | M(Me), /* M */\n    M(Nd) | M(Nl) | M(No), /* N */\n    M(Sm) | M(Sc) | M(Sk) | M(So), /* S */\n    M(Pc) | M(Pd) | M(Ps) | M(Pe) | M(Pi) | M(Pf) | M(Po), /* P */\n    M(Zs) | M(Zl) | M(Zp), /* Z */\n    M(Cc) | M(Cf) | M(Cs) | M(Co) | M(Cn), /* C */\n};\n\n/* 'cr' must be initialized and empty. Return 0 if OK, -1 if error, -2\n   if not found */\nint unicode_general_category(CharRange *cr, const char *gc_name)\n{\n    int gc_idx;\n    uint32_t gc_mask;\n    \n    gc_idx = unicode_find_name(unicode_gc_name_table, gc_name);\n    if (gc_idx < 0)\n        return -2;\n    if (gc_idx <= UNICODE_GC_Co) {\n        gc_mask = (uint64_t)1 << gc_idx;\n    } else {\n        gc_mask = unicode_gc_mask_table[gc_idx - UNICODE_GC_LC];\n    }\n    return unicode_general_category1(cr, gc_mask);\n}\n\n\n/* 'cr' must be initialized and empty. Return 0 if OK, -1 if error, -2\n   if not found */\nint unicode_prop(CharRange *cr, const char *prop_name)\n{\n    int prop_idx, ret;\n    \n    prop_idx = unicode_find_name(unicode_prop_name_table, prop_name);\n    if (prop_idx < 0)\n        return -2;\n    prop_idx += UNICODE_PROP_ASCII_Hex_Digit;\n\n    ret = 0;\n    switch(prop_idx) {\n    case UNICODE_PROP_ASCII:\n        if (cr_add_interval(cr, 0x00, 0x7f + 1))\n            return -1;\n        break;\n    case UNICODE_PROP_Any:\n        if (cr_add_interval(cr, 0x00000, 0x10ffff + 1))\n            return -1;\n        break;\n    case UNICODE_PROP_Assigned:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Cn),\n                               POP_INVERT,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Math:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Sm),\n                               POP_PROP, UNICODE_PROP_Other_Math,\n                               POP_UNION,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Lowercase:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Ll),\n                               POP_PROP, UNICODE_PROP_Other_Lowercase,\n                               POP_UNION,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Uppercase:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu),\n                               POP_PROP, UNICODE_PROP_Other_Uppercase,\n                               POP_UNION,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Cased:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu) | M(Ll) | M(Lt),\n                               POP_PROP, UNICODE_PROP_Other_Uppercase,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Other_Lowercase,\n                               POP_UNION,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Alphabetic:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu) | M(Ll) | M(Lt) | M(Lm) | M(Lo) | M(Nl),\n                               POP_PROP, UNICODE_PROP_Other_Uppercase,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Other_Lowercase,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Other_Alphabetic,\n                               POP_UNION,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Grapheme_Base:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Cc) | M(Cf) | M(Cs) | M(Co) | M(Cn) | M(Zl) | M(Zp) | M(Me) | M(Mn),\n                               POP_PROP, UNICODE_PROP_Other_Grapheme_Extend,\n                               POP_UNION,\n                               POP_INVERT,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Grapheme_Extend:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Me) | M(Mn),\n                               POP_PROP, UNICODE_PROP_Other_Grapheme_Extend,\n                               POP_UNION,\n                               POP_END);\n        break;\n    case UNICODE_PROP_XID_Start:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu) | M(Ll) | M(Lt) | M(Lm) | M(Lo) | M(Nl),\n                               POP_PROP, UNICODE_PROP_Other_ID_Start,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Pattern_Syntax,\n                               POP_PROP, UNICODE_PROP_Pattern_White_Space,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_XID_Start1,\n                               POP_UNION,\n                               POP_INVERT,\n                               POP_INTER,\n                               POP_END);\n        break;\n    case UNICODE_PROP_XID_Continue:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu) | M(Ll) | M(Lt) | M(Lm) | M(Lo) | M(Nl) |\n                               M(Mn) | M(Mc) | M(Nd) | M(Pc),\n                               POP_PROP, UNICODE_PROP_Other_ID_Start,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Other_ID_Continue,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Pattern_Syntax,\n                               POP_PROP, UNICODE_PROP_Pattern_White_Space,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_XID_Continue1,\n                               POP_UNION,\n                               POP_INVERT,\n                               POP_INTER,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Changes_When_Uppercased:\n        ret = unicode_case1(cr, CASE_U);\n        break;\n    case UNICODE_PROP_Changes_When_Lowercased:\n        ret = unicode_case1(cr, CASE_L);\n        break;\n    case UNICODE_PROP_Changes_When_Casemapped:\n        ret = unicode_case1(cr, CASE_U | CASE_L | CASE_F);\n        break;\n    case UNICODE_PROP_Changes_When_Titlecased:\n        ret = unicode_prop_ops(cr,\n                               POP_CASE, CASE_U,\n                               POP_PROP, UNICODE_PROP_Changes_When_Titlecased1,\n                               POP_XOR,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Changes_When_Casefolded:\n        ret = unicode_prop_ops(cr,\n                               POP_CASE, CASE_F,\n                               POP_PROP, UNICODE_PROP_Changes_When_Casefolded1,\n                               POP_XOR,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Changes_When_NFKC_Casefolded:\n        ret = unicode_prop_ops(cr,\n                               POP_CASE, CASE_F,\n                               POP_PROP, UNICODE_PROP_Changes_When_NFKC_Casefolded1,\n                               POP_XOR,\n                               POP_END);\n        break;\n#if 0\n    case UNICODE_PROP_ID_Start:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu) | M(Ll) | M(Lt) | M(Lm) | M(Lo) | M(Nl),\n                               POP_PROP, UNICODE_PROP_Other_ID_Start,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Pattern_Syntax,\n                               POP_PROP, UNICODE_PROP_Pattern_White_Space,\n                               POP_UNION,\n                               POP_INVERT,\n                               POP_INTER,\n                               POP_END);\n        break;\n    case UNICODE_PROP_ID_Continue:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Lu) | M(Ll) | M(Lt) | M(Lm) | M(Lo) | M(Nl) |\n                               M(Mn) | M(Mc) | M(Nd) | M(Pc),\n                               POP_PROP, UNICODE_PROP_Other_ID_Start,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Other_ID_Continue,\n                               POP_UNION,\n                               POP_PROP, UNICODE_PROP_Pattern_Syntax,\n                               POP_PROP, UNICODE_PROP_Pattern_White_Space,\n                               POP_UNION,\n                               POP_INVERT,\n                               POP_INTER,\n                               POP_END);\n        break;\n    case UNICODE_PROP_Case_Ignorable:\n        ret = unicode_prop_ops(cr,\n                               POP_GC, M(Mn) | M(Cf) | M(Lm) | M(Sk),\n                               POP_PROP, UNICODE_PROP_Case_Ignorable1,\n                               POP_XOR,\n                               POP_END);\n        break;\n#else\n        /* we use the existing tables */\n    case UNICODE_PROP_ID_Continue:\n        ret = unicode_prop_ops(cr,\n                               POP_PROP, UNICODE_PROP_ID_Start,\n                               POP_PROP, UNICODE_PROP_ID_Continue1,\n                               POP_XOR,\n                               POP_END);\n        break;\n#endif\n    default:\n        if (prop_idx >= countof(unicode_prop_table))\n            return -2;\n        ret = unicode_prop1(cr, prop_idx);\n        break;\n    }\n    return ret;\n}\n\n#endif /* CONFIG_ALL_UNICODE */\n"
  },
  {
    "path": "libunicode.h",
    "content": "/*\n * Unicode utilities\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#ifndef LIBUNICODE_H\n#define LIBUNICODE_H\n\n#include <inttypes.h>\n\n#define LRE_BOOL  int       /* for documentation purposes */\n\n/* define it to include all the unicode tables (40KB larger) */\n#define CONFIG_ALL_UNICODE\n\n#define LRE_CC_RES_LEN_MAX 3\n\ntypedef enum {\n    UNICODE_NFC,\n    UNICODE_NFD,\n    UNICODE_NFKC,\n    UNICODE_NFKD,\n} UnicodeNormalizationEnum;\n\nint lre_case_conv(uint32_t *res, uint32_t c, int conv_type);\nLRE_BOOL lre_is_cased(uint32_t c);\nLRE_BOOL lre_is_case_ignorable(uint32_t c);\n\n/* char ranges */\n\ntypedef struct {\n    int len; /* in points, always even */\n    int size;\n    uint32_t *points; /* points sorted by increasing value */\n    void *mem_opaque;\n    void *(*realloc_func)(void *opaque, void *ptr, size_t size);\n} CharRange;\n\ntypedef enum {\n    CR_OP_UNION,\n    CR_OP_INTER,\n    CR_OP_XOR,\n} CharRangeOpEnum;\n\nvoid cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));\nvoid cr_free(CharRange *cr);\nint cr_realloc(CharRange *cr, int size);\nint cr_copy(CharRange *cr, const CharRange *cr1);\n\nstatic inline int cr_add_point(CharRange *cr, uint32_t v)\n{\n    if (cr->len >= cr->size) {\n        if (cr_realloc(cr, cr->len + 1))\n            return -1;\n    }\n    cr->points[cr->len++] = v;\n    return 0;\n}\n\nstatic inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2)\n{\n    if ((cr->len + 2) > cr->size) {\n        if (cr_realloc(cr, cr->len + 2))\n            return -1;\n    }\n    cr->points[cr->len++] = c1;\n    cr->points[cr->len++] = c2;\n    return 0;\n}\n\nint cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len);\n\nstatic inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2)\n{\n    uint32_t b_pt[2];\n    b_pt[0] = c1;\n    b_pt[1] = c2 + 1;\n    return cr_union1(cr, b_pt, 2);\n}\n\nint cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,\n          const uint32_t *b_pt, int b_len, int op);\n\nint cr_invert(CharRange *cr);\n\n#ifdef CONFIG_ALL_UNICODE\n\nLRE_BOOL lre_is_id_start(uint32_t c);\nLRE_BOOL lre_is_id_continue(uint32_t c);\n\nint unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,\n                      UnicodeNormalizationEnum n_type,\n                      void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));\n\n/* Unicode character range functions */\n\nint unicode_script(CharRange *cr,\n                   const char *script_name, LRE_BOOL is_ext);\nint unicode_general_category(CharRange *cr, const char *gc_name);\nint unicode_prop(CharRange *cr, const char *prop_name);\n\n#endif /* CONFIG_ALL_UNICODE */\n\n#undef LRE_BOOL\n\n#endif /* LIBUNICODE_H */\n"
  },
  {
    "path": "list.h",
    "content": "/*\n * Linux klist like system\n * \n * Copyright (c) 2016-2017 Fabrice Bellard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#ifndef LIST_H\n#define LIST_H\n\n#ifndef NULL\n#include <stddef.h>\n#endif\n\nstruct list_head {\n    struct list_head *prev;\n    struct list_head *next;\n};\n\n#define LIST_HEAD_INIT(el) { &(el), &(el) }\n\n/* return the pointer of type 'type *' containing 'el' as field 'member' */\n#define list_entry(el, type, member) \\\n    ((type *)((uint8_t *)(el) - offsetof(type, member)))\n\nstatic inline void init_list_head(struct list_head *head)\n{\n    head->prev = head;\n    head->next = head;\n}\n\n/* insert 'el' between 'prev' and 'next' */\nstatic inline void __list_add(struct list_head *el, \n                              struct list_head *prev, struct list_head *next)\n{\n    prev->next = el;\n    el->prev = prev;\n    el->next = next;\n    next->prev = el;\n}\n\n/* add 'el' at the head of the list 'head' (= after element head) */\nstatic inline void list_add(struct list_head *el, struct list_head *head)\n{\n    __list_add(el, head, head->next);\n}\n\n/* add 'el' at the end of the list 'head' (= before element head) */\nstatic inline void list_add_tail(struct list_head *el, struct list_head *head)\n{\n    __list_add(el, head->prev, head);\n}\n\nstatic inline void list_del(struct list_head *el)\n{\n    struct list_head *prev, *next;\n    prev = el->prev;\n    next = el->next;\n    prev->next = next;\n    next->prev = prev;\n    el->prev = NULL; /* fail safe */\n    el->next = NULL; /* fail safe */\n}\n\nstatic inline int list_empty(struct list_head *el)\n{\n    return el->next == el;\n}\n\n#define list_for_each(el, head) \\\n  for(el = (head)->next; el != (head); el = el->next)\n\n#define list_for_each_safe(el, el1, head)                \\\n    for(el = (head)->next, el1 = el->next; el != (head); \\\n        el = el1, el1 = el->next)\n\n#define list_for_each_prev(el, head) \\\n  for(el = (head)->prev; el != (head); el = el->prev)\n\n#define list_for_each_prev_safe(el, el1, head)           \\\n    for(el = (head)->prev, el1 = el->prev; el != (head); \\\n        el = el1, el1 = el->prev)\n\n#endif /* LIST_H */\n"
  },
  {
    "path": "quickjs-atom.h",
    "content": "/*\n * QuickJS atom definitions\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n * Copyright (c) 2017-2018 Charlie Gordon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n#ifdef DEF\n\n/* Note: first atoms are considered as keywords in the parser */\nDEF(null, \"null\") /* must be first */\nDEF(false, \"false\")\nDEF(true, \"true\")\nDEF(if, \"if\")\nDEF(else, \"else\")\nDEF(return, \"return\")\nDEF(var, \"var\")\nDEF(this, \"this\")\nDEF(delete, \"delete\")\nDEF(void, \"void\")\nDEF(typeof, \"typeof\")\nDEF(new, \"new\")\nDEF(in, \"in\")\nDEF(instanceof, \"instanceof\")\nDEF(do, \"do\")\nDEF(while, \"while\")\nDEF(for, \"for\")\nDEF(break, \"break\")\nDEF(continue, \"continue\")\nDEF(switch, \"switch\")\nDEF(case, \"case\")\nDEF(default, \"default\")\nDEF(throw, \"throw\")\nDEF(try, \"try\")\nDEF(catch, \"catch\")\nDEF(finally, \"finally\")\nDEF(function, \"function\")\nDEF(debugger, \"debugger\")\nDEF(with, \"with\")\n/* FutureReservedWord */\nDEF(class, \"class\")\nDEF(const, \"const\")\nDEF(enum, \"enum\")\nDEF(export, \"export\")\nDEF(extends, \"extends\")\nDEF(import, \"import\")\nDEF(super, \"super\")\n/* FutureReservedWords when parsing strict mode code */\nDEF(implements, \"implements\")\nDEF(interface, \"interface\")\nDEF(let, \"let\")\nDEF(package, \"package\")\nDEF(private, \"private\")\nDEF(protected, \"protected\")\nDEF(public, \"public\")\nDEF(static, \"static\")\nDEF(yield, \"yield\")\nDEF(await, \"await\")\n\n/* empty string */\nDEF(empty_string, \"\")\n/* identifiers */\nDEF(length, \"length\")\nDEF(fileName, \"fileName\")\nDEF(lineNumber, \"lineNumber\")\nDEF(message, \"message\")\nDEF(errors, \"errors\")\nDEF(stack, \"stack\")\nDEF(name, \"name\")\nDEF(toString, \"toString\")\nDEF(toLocaleString, \"toLocaleString\")\nDEF(valueOf, \"valueOf\")\nDEF(eval, \"eval\")\nDEF(prototype, \"prototype\")\nDEF(constructor, \"constructor\")\nDEF(configurable, \"configurable\")\nDEF(writable, \"writable\")\nDEF(enumerable, \"enumerable\")\nDEF(value, \"value\")\nDEF(get, \"get\")\nDEF(set, \"set\")\nDEF(of, \"of\")\nDEF(__proto__, \"__proto__\")\nDEF(undefined, \"undefined\")\nDEF(number, \"number\")\nDEF(boolean, \"boolean\")\nDEF(string, \"string\")\nDEF(object, \"object\")\nDEF(symbol, \"symbol\")\nDEF(integer, \"integer\")\nDEF(unknown, \"unknown\")\nDEF(arguments, \"arguments\")\nDEF(callee, \"callee\")\nDEF(caller, \"caller\")\nDEF(_eval_, \"<eval>\")\nDEF(_ret_, \"<ret>\")\nDEF(_var_, \"<var>\")\nDEF(_with_, \"<with>\")\nDEF(lastIndex, \"lastIndex\")\nDEF(target, \"target\")\nDEF(index, \"index\")\nDEF(input, \"input\")\nDEF(defineProperties, \"defineProperties\")\nDEF(apply, \"apply\")\nDEF(join, \"join\")\nDEF(concat, \"concat\")\nDEF(split, \"split\")\nDEF(construct, \"construct\")\nDEF(getPrototypeOf, \"getPrototypeOf\")\nDEF(setPrototypeOf, \"setPrototypeOf\")\nDEF(isExtensible, \"isExtensible\")\nDEF(preventExtensions, \"preventExtensions\")\nDEF(has, \"has\")\nDEF(deleteProperty, \"deleteProperty\")\nDEF(defineProperty, \"defineProperty\")\nDEF(getOwnPropertyDescriptor, \"getOwnPropertyDescriptor\")\nDEF(ownKeys, \"ownKeys\")\nDEF(add, \"add\")\nDEF(done, \"done\")\nDEF(next, \"next\")\nDEF(values, \"values\")\nDEF(source, \"source\")\nDEF(flags, \"flags\")\nDEF(global, \"global\")\nDEF(unicode, \"unicode\")\nDEF(raw, \"raw\")\nDEF(new_target, \"new.target\")\nDEF(this_active_func, \"this.active_func\")\nDEF(home_object, \"<home_object>\")\nDEF(computed_field, \"<computed_field>\")\nDEF(static_computed_field, \"<static_computed_field>\") /* must come after computed_fields */\nDEF(class_fields_init, \"<class_fields_init>\")\nDEF(brand, \"<brand>\")\nDEF(hash_constructor, \"#constructor\")\nDEF(as, \"as\")\nDEF(from, \"from\")\nDEF(meta, \"meta\")\nDEF(_default_, \"*default*\")\nDEF(_star_, \"*\")\nDEF(Module, \"Module\")\nDEF(then, \"then\")\nDEF(resolve, \"resolve\")\nDEF(reject, \"reject\")\nDEF(promise, \"promise\")\nDEF(proxy, \"proxy\")\nDEF(revoke, \"revoke\")\nDEF(async, \"async\")\nDEF(exec, \"exec\")\nDEF(groups, \"groups\")\nDEF(status, \"status\")\nDEF(reason, \"reason\")\nDEF(globalThis, \"globalThis\")\n#ifdef CONFIG_BIGNUM\nDEF(bigint, \"bigint\")\nDEF(bigfloat, \"bigfloat\")\nDEF(bigdecimal, \"bigdecimal\")\nDEF(roundingMode, \"roundingMode\")\nDEF(maximumSignificantDigits, \"maximumSignificantDigits\")\nDEF(maximumFractionDigits, \"maximumFractionDigits\")\n#endif\n#ifdef CONFIG_ATOMICS\nDEF(not_equal, \"not-equal\")\nDEF(timed_out, \"timed-out\")\nDEF(ok, \"ok\")\n#endif\nDEF(toJSON, \"toJSON\")\n/* class names */\nDEF(Object, \"Object\")\nDEF(Array, \"Array\")\nDEF(Error, \"Error\")\nDEF(Number, \"Number\")\nDEF(String, \"String\")\nDEF(Boolean, \"Boolean\")\nDEF(Symbol, \"Symbol\")\nDEF(Arguments, \"Arguments\")\nDEF(Math, \"Math\")\nDEF(JSON, \"JSON\")\nDEF(Date, \"Date\")\nDEF(Function, \"Function\")\nDEF(GeneratorFunction, \"GeneratorFunction\")\nDEF(ForInIterator, \"ForInIterator\")\nDEF(RegExp, \"RegExp\")\nDEF(ArrayBuffer, \"ArrayBuffer\")\nDEF(SharedArrayBuffer, \"SharedArrayBuffer\")\n/* must keep same order as class IDs for typed arrays */\nDEF(Uint8ClampedArray, \"Uint8ClampedArray\") \nDEF(Int8Array, \"Int8Array\")\nDEF(Uint8Array, \"Uint8Array\")\nDEF(Int16Array, \"Int16Array\")\nDEF(Uint16Array, \"Uint16Array\")\nDEF(Int32Array, \"Int32Array\")\nDEF(Uint32Array, \"Uint32Array\")\n#ifdef CONFIG_BIGNUM\nDEF(BigInt64Array, \"BigInt64Array\")\nDEF(BigUint64Array, \"BigUint64Array\")\n#endif\nDEF(Float32Array, \"Float32Array\")\nDEF(Float64Array, \"Float64Array\")\nDEF(DataView, \"DataView\")\n#ifdef CONFIG_BIGNUM\nDEF(BigInt, \"BigInt\")\nDEF(BigFloat, \"BigFloat\")\nDEF(BigFloatEnv, \"BigFloatEnv\")\nDEF(BigDecimal, \"BigDecimal\")\nDEF(OperatorSet, \"OperatorSet\")\nDEF(Operators, \"Operators\")\n#endif\nDEF(Map, \"Map\")\nDEF(Set, \"Set\") /* Map + 1 */\nDEF(WeakMap, \"WeakMap\") /* Map + 2 */\nDEF(WeakSet, \"WeakSet\") /* Map + 3 */\nDEF(Map_Iterator, \"Map Iterator\")\nDEF(Set_Iterator, \"Set Iterator\")\nDEF(Array_Iterator, \"Array Iterator\")\nDEF(String_Iterator, \"String Iterator\")\nDEF(RegExp_String_Iterator, \"RegExp String Iterator\")\nDEF(Generator, \"Generator\")\nDEF(Proxy, \"Proxy\")\nDEF(Promise, \"Promise\")\nDEF(PromiseResolveFunction, \"PromiseResolveFunction\")\nDEF(PromiseRejectFunction, \"PromiseRejectFunction\")\nDEF(AsyncFunction, \"AsyncFunction\")\nDEF(AsyncFunctionResolve, \"AsyncFunctionResolve\")\nDEF(AsyncFunctionReject, \"AsyncFunctionReject\")\nDEF(AsyncGeneratorFunction, \"AsyncGeneratorFunction\")\nDEF(AsyncGenerator, \"AsyncGenerator\")\nDEF(EvalError, \"EvalError\")\nDEF(RangeError, \"RangeError\")\nDEF(ReferenceError, \"ReferenceError\")\nDEF(SyntaxError, \"SyntaxError\")\nDEF(TypeError, \"TypeError\")\nDEF(URIError, \"URIError\")\nDEF(InternalError, \"InternalError\")\n/* private symbols */\nDEF(Private_brand, \"<brand>\")\n/* symbols */\nDEF(Symbol_toPrimitive, \"Symbol.toPrimitive\")\nDEF(Symbol_iterator, \"Symbol.iterator\")\nDEF(Symbol_match, \"Symbol.match\")\nDEF(Symbol_matchAll, \"Symbol.matchAll\")\nDEF(Symbol_replace, \"Symbol.replace\")\nDEF(Symbol_search, \"Symbol.search\")\nDEF(Symbol_split, \"Symbol.split\")\nDEF(Symbol_toStringTag, \"Symbol.toStringTag\")\nDEF(Symbol_isConcatSpreadable, \"Symbol.isConcatSpreadable\")\nDEF(Symbol_hasInstance, \"Symbol.hasInstance\")\nDEF(Symbol_species, \"Symbol.species\")\nDEF(Symbol_unscopables, \"Symbol.unscopables\")\nDEF(Symbol_asyncIterator, \"Symbol.asyncIterator\")\n#ifdef CONFIG_BIGNUM\nDEF(Symbol_operatorSet, \"Symbol.operatorSet\")\n#endif\n    \n#endif /* DEF */\n"
  },
  {
    "path": "quickjs-opcode.h",
    "content": "/*\n * QuickJS opcode definitions\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n * Copyright (c) 2017-2018 Charlie Gordon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n#ifdef FMT\nFMT(none)\nFMT(none_int)\nFMT(none_loc)\nFMT(none_arg)\nFMT(none_var_ref)\nFMT(u8)\nFMT(i8)\nFMT(loc8)\nFMT(const8)\nFMT(label8)\nFMT(u16)\nFMT(i16)\nFMT(label16)\nFMT(npop)\nFMT(npopx)\nFMT(npop_u16)\nFMT(loc)\nFMT(arg)\nFMT(var_ref)\nFMT(u32)\nFMT(i32)\nFMT(const)\nFMT(label)\nFMT(atom)\nFMT(atom_u8)\nFMT(atom_u16)\nFMT(atom_label_u8)\nFMT(atom_label_u16)\nFMT(label_u16)\n#undef FMT\n#endif /* FMT */\n\n#ifdef DEF\n\n#ifndef def\n#define def(id, size, n_pop, n_push, f) DEF(id, size, n_pop, n_push, f)\n#endif\n\nDEF(invalid, 1, 0, 0, none) /* never emitted */\n\n/* push values */\nDEF(       push_i32, 5, 0, 1, i32)\nDEF(     push_const, 5, 0, 1, const)\nDEF(       fclosure, 5, 0, 1, const) /* must follow push_const */\nDEF(push_atom_value, 5, 0, 1, atom)\nDEF( private_symbol, 5, 0, 1, atom)\nDEF(      undefined, 1, 0, 1, none)\nDEF(           null, 1, 0, 1, none)\nDEF(      push_this, 1, 0, 1, none) /* only used at the start of a function */\nDEF(     push_false, 1, 0, 1, none)\nDEF(      push_true, 1, 0, 1, none)\nDEF(         object, 1, 0, 1, none)\nDEF( special_object, 2, 0, 1, u8) /* only used at the start of a function */\nDEF(           rest, 3, 0, 1, u16) /* only used at the start of a function */\n\nDEF(           drop, 1, 1, 0, none) /* a -> */\nDEF(            nip, 1, 2, 1, none) /* a b -> b */\nDEF(           nip1, 1, 3, 2, none) /* a b c -> b c */\nDEF(            dup, 1, 1, 2, none) /* a -> a a */\nDEF(           dup1, 1, 2, 3, none) /* a b -> a a b */\nDEF(           dup2, 1, 2, 4, none) /* a b -> a b a b */\nDEF(           dup3, 1, 3, 6, none) /* a b c -> a b c a b c */\nDEF(        insert2, 1, 2, 3, none) /* obj a -> a obj a (dup_x1) */\nDEF(        insert3, 1, 3, 4, none) /* obj prop a -> a obj prop a (dup_x2) */\nDEF(        insert4, 1, 4, 5, none) /* this obj prop a -> a this obj prop a */\nDEF(          perm3, 1, 3, 3, none) /* obj a b -> a obj b */\nDEF(          perm4, 1, 4, 4, none) /* obj prop a b -> a obj prop b */\nDEF(          perm5, 1, 5, 5, none) /* this obj prop a b -> a this obj prop b */\nDEF(           swap, 1, 2, 2, none) /* a b -> b a */\nDEF(          swap2, 1, 4, 4, none) /* a b c d -> c d a b */\nDEF(          rot3l, 1, 3, 3, none) /* x a b -> a b x */\nDEF(          rot3r, 1, 3, 3, none) /* a b x -> x a b */\nDEF(          rot4l, 1, 4, 4, none) /* x a b c -> a b c x */\nDEF(          rot5l, 1, 5, 5, none) /* x a b c d -> a b c d x */\n\nDEF(call_constructor, 3, 2, 1, npop) /* func new.target args -> ret. arguments are not counted in n_pop */\nDEF(           call, 3, 1, 1, npop) /* arguments are not counted in n_pop */\nDEF(      tail_call, 3, 1, 0, npop) /* arguments are not counted in n_pop */\nDEF(    call_method, 3, 2, 1, npop) /* arguments are not counted in n_pop */\nDEF(tail_call_method, 3, 2, 0, npop) /* arguments are not counted in n_pop */\nDEF(     array_from, 3, 0, 1, npop) /* arguments are not counted in n_pop */\nDEF(          apply, 3, 3, 1, u16)\nDEF(         return, 1, 1, 0, none)\nDEF(   return_undef, 1, 0, 0, none)\nDEF(check_ctor_return, 1, 1, 2, none)\nDEF(     check_ctor, 1, 0, 0, none)\nDEF(    check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */\nDEF(      add_brand, 1, 2, 0, none) /* this_obj home_obj -> */\nDEF(   return_async, 1, 1, 0, none)\nDEF(          throw, 1, 1, 0, none)\nDEF(      throw_var, 6, 0, 0, atom_u8)\nDEF(           eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */\nDEF(     apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */\nDEF(         regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a\n                                       bytecode string */\nDEF(      get_super, 1, 1, 1, none)\nDEF(         import, 1, 1, 1, none) /* dynamic module import */\n\nDEF(      check_var, 5, 0, 1, atom) /* check if a variable exists */\nDEF(  get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */\nDEF(        get_var, 5, 0, 1, atom) /* throw an exception if the variable does not exist */\nDEF(        put_var, 5, 1, 0, atom) /* must come after get_var */\nDEF(   put_var_init, 5, 1, 0, atom) /* must come after put_var. Used to initialize a global lexical variable */\nDEF( put_var_strict, 5, 2, 0, atom) /* for strict mode variable write */\n\nDEF(  get_ref_value, 1, 2, 3, none)\nDEF(  put_ref_value, 1, 3, 0, none)\n\nDEF(     define_var, 6, 0, 0, atom_u8)\nDEF(check_define_var, 6, 0, 0, atom_u8)\nDEF(    define_func, 6, 1, 0, atom_u8)\nDEF(      get_field, 5, 1, 1, atom)\nDEF(     get_field2, 5, 1, 2, atom)\nDEF(      put_field, 5, 2, 0, atom)\nDEF( get_private_field, 1, 2, 1, none) /* obj prop -> value */\nDEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */\nDEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */\nDEF(   get_array_el, 1, 2, 1, none)\nDEF(  get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */\nDEF(   put_array_el, 1, 3, 0, none)\nDEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */\nDEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */\nDEF(   define_field, 5, 2, 1, atom)\nDEF(       set_name, 5, 1, 1, atom)\nDEF(set_name_computed, 1, 2, 2, none)\nDEF(      set_proto, 1, 2, 1, none)\nDEF(set_home_object, 1, 2, 2, none)\nDEF(define_array_el, 1, 3, 2, none)\nDEF(         append, 1, 3, 2, none) /* append enumerated object, update length */\nDEF(copy_data_properties, 2, 3, 3, u8)\nDEF(  define_method, 6, 2, 1, atom_u8)\nDEF(define_method_computed, 2, 3, 1, u8) /* must come after define_method */\nDEF(   define_class, 6, 2, 2, atom_u8) /* parent ctor -> ctor proto */\nDEF(   define_class_computed, 6, 3, 3, atom_u8) /* field_name parent ctor -> field_name ctor proto (class with computed name) */\n\nDEF(        get_loc, 3, 0, 1, loc)\nDEF(        put_loc, 3, 1, 0, loc) /* must come after get_loc */\nDEF(        set_loc, 3, 1, 1, loc) /* must come after put_loc */\nDEF(        get_arg, 3, 0, 1, arg)\nDEF(        put_arg, 3, 1, 0, arg) /* must come after get_arg */\nDEF(        set_arg, 3, 1, 1, arg) /* must come after put_arg */\nDEF(    get_var_ref, 3, 0, 1, var_ref) \nDEF(    put_var_ref, 3, 1, 0, var_ref) /* must come after get_var_ref */\nDEF(    set_var_ref, 3, 1, 1, var_ref) /* must come after put_var_ref */\nDEF(set_loc_uninitialized, 3, 0, 0, loc)\nDEF(  get_loc_check, 3, 0, 1, loc)\nDEF(  put_loc_check, 3, 1, 0, loc) /* must come after get_loc_check */\nDEF(  put_loc_check_init, 3, 1, 0, loc)\nDEF(get_var_ref_check, 3, 0, 1, var_ref) \nDEF(put_var_ref_check, 3, 1, 0, var_ref) /* must come after get_var_ref_check */\nDEF(put_var_ref_check_init, 3, 1, 0, var_ref)\nDEF(      close_loc, 3, 0, 0, loc)\nDEF(       if_false, 5, 1, 0, label)\nDEF(        if_true, 5, 1, 0, label) /* must come after if_false */\nDEF(           goto, 5, 0, 0, label) /* must come after if_true */\nDEF(          catch, 5, 0, 1, label)\nDEF(          gosub, 5, 0, 0, label) /* used to execute the finally block */\nDEF(            ret, 1, 1, 0, none) /* used to return from the finally block */\n\nDEF(      to_object, 1, 1, 1, none)\n//DEF(      to_string, 1, 1, 1, none)\nDEF(     to_propkey, 1, 1, 1, none)\nDEF(    to_propkey2, 1, 2, 2, none)\n\nDEF(   with_get_var, 10, 1, 0, atom_label_u8)     /* must be in the same order as scope_xxx */\nDEF(   with_put_var, 10, 2, 1, atom_label_u8)     /* must be in the same order as scope_xxx */\nDEF(with_delete_var, 10, 1, 0, atom_label_u8)     /* must be in the same order as scope_xxx */\nDEF(  with_make_ref, 10, 1, 0, atom_label_u8)     /* must be in the same order as scope_xxx */\nDEF(   with_get_ref, 10, 1, 0, atom_label_u8)     /* must be in the same order as scope_xxx */\nDEF(with_get_ref_undef, 10, 1, 0, atom_label_u8)\n\nDEF(   make_loc_ref, 7, 0, 2, atom_u16)\nDEF(   make_arg_ref, 7, 0, 2, atom_u16)\nDEF(make_var_ref_ref, 7, 0, 2, atom_u16)\nDEF(   make_var_ref, 5, 0, 2, atom)\n\nDEF(   for_in_start, 1, 1, 1, none)\nDEF(   for_of_start, 1, 1, 3, none)\nDEF(for_await_of_start, 1, 1, 3, none)\nDEF(    for_in_next, 1, 1, 3, none)\nDEF(    for_of_next, 2, 3, 5, u8)\nDEF(for_await_of_next, 1, 3, 4, none)\nDEF(iterator_get_value_done, 1, 1, 2, none)\nDEF( iterator_close, 1, 3, 0, none)\nDEF(iterator_close_return, 1, 4, 4, none)\nDEF(async_iterator_close, 1, 3, 2, none)\nDEF(async_iterator_next, 1, 4, 4, none)\nDEF(async_iterator_get, 2, 4, 5, u8)\nDEF(  initial_yield, 1, 0, 0, none)\nDEF(          yield, 1, 1, 2, none)\nDEF(     yield_star, 1, 2, 2, none)\nDEF(async_yield_star, 1, 1, 2, none)\nDEF(          await, 1, 1, 1, none)\n\n/* arithmetic/logic operations */\nDEF(            neg, 1, 1, 1, none)\nDEF(           plus, 1, 1, 1, none)\nDEF(            dec, 1, 1, 1, none)\nDEF(            inc, 1, 1, 1, none)\nDEF(       post_dec, 1, 1, 2, none)\nDEF(       post_inc, 1, 1, 2, none)\nDEF(        dec_loc, 2, 0, 0, loc8)\nDEF(        inc_loc, 2, 0, 0, loc8)\nDEF(        add_loc, 2, 1, 0, loc8)\nDEF(            not, 1, 1, 1, none)\nDEF(           lnot, 1, 1, 1, none)\nDEF(         typeof, 1, 1, 1, none)\nDEF(         delete, 1, 2, 1, none)\nDEF(     delete_var, 5, 0, 1, atom)\n\nDEF(            mul, 1, 2, 1, none)\nDEF(            div, 1, 2, 1, none)\nDEF(            mod, 1, 2, 1, none)\nDEF(            add, 1, 2, 1, none)\nDEF(            sub, 1, 2, 1, none)\nDEF(            pow, 1, 2, 1, none)\nDEF(            shl, 1, 2, 1, none)\nDEF(            sar, 1, 2, 1, none)\nDEF(            shr, 1, 2, 1, none)\nDEF(             lt, 1, 2, 1, none)\nDEF(            lte, 1, 2, 1, none)\nDEF(             gt, 1, 2, 1, none)\nDEF(            gte, 1, 2, 1, none)\nDEF(     instanceof, 1, 2, 1, none)\nDEF(             in, 1, 2, 1, none)\nDEF(             eq, 1, 2, 1, none)\nDEF(            neq, 1, 2, 1, none)\nDEF(      strict_eq, 1, 2, 1, none)\nDEF(     strict_neq, 1, 2, 1, none)\nDEF(            and, 1, 2, 1, none)\nDEF(            xor, 1, 2, 1, none)\nDEF(             or, 1, 2, 1, none)\nDEF(is_undefined_or_null, 1, 1, 1, none)\n#ifdef CONFIG_BIGNUM\nDEF(      mul_pow10, 1, 2, 1, none)\nDEF(       math_mod, 1, 2, 1, none)\n#endif\n/* must be the last non short and non temporary opcode */\nDEF(            nop, 1, 0, 0, none) \n\n/* temporary opcodes: never emitted in the final bytecode */\n\ndef(set_arg_valid_upto, 3, 0, 0, arg) /* emitted in phase 1, removed in phase 2 */\n\ndef(    enter_scope, 3, 0, 0, u16)  /* emitted in phase 1, removed in phase 2 */\ndef(    leave_scope, 3, 0, 0, u16)  /* emitted in phase 1, removed in phase 2 */\n\ndef(          label, 5, 0, 0, label) /* emitted in phase 1, removed in phase 3 */\n\ndef(scope_get_var_undef, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */\ndef(  scope_get_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */\ndef(  scope_put_var, 7, 1, 0, atom_u16) /* emitted in phase 1, removed in phase 2 */\ndef(scope_delete_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */\ndef( scope_make_ref, 11, 0, 2, atom_label_u16) /* emitted in phase 1, removed in phase 2 */\ndef(  scope_get_ref, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */\ndef(scope_put_var_init, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */\ndef(scope_get_private_field, 7, 1, 1, atom_u16) /* obj -> value, emitted in phase 1, removed in phase 2 */\ndef(scope_get_private_field2, 7, 1, 2, atom_u16) /* obj -> obj value, emitted in phase 1, removed in phase 2 */\ndef(scope_put_private_field, 7, 1, 1, atom_u16) /* obj value ->, emitted in phase 1, removed in phase 2 */\n\ndef( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */\n    \ndef(       line_num, 5, 0, 0, u32) /* emitted in phase 1, removed in phase 3 */\n\n#if SHORT_OPCODES\nDEF(    push_minus1, 1, 0, 1, none_int)\nDEF(         push_0, 1, 0, 1, none_int)\nDEF(         push_1, 1, 0, 1, none_int)\nDEF(         push_2, 1, 0, 1, none_int)\nDEF(         push_3, 1, 0, 1, none_int)\nDEF(         push_4, 1, 0, 1, none_int)\nDEF(         push_5, 1, 0, 1, none_int)\nDEF(         push_6, 1, 0, 1, none_int)\nDEF(         push_7, 1, 0, 1, none_int)\nDEF(        push_i8, 2, 0, 1, i8)\nDEF(       push_i16, 3, 0, 1, i16)\nDEF(    push_const8, 2, 0, 1, const8)\nDEF(      fclosure8, 2, 0, 1, const8) /* must follow push_const8 */\nDEF(push_empty_string, 1, 0, 1, none)\n\nDEF(       get_loc8, 2, 0, 1, loc8)\nDEF(       put_loc8, 2, 1, 0, loc8)\nDEF(       set_loc8, 2, 1, 1, loc8)\n\nDEF(       get_loc0, 1, 0, 1, none_loc)\nDEF(       get_loc1, 1, 0, 1, none_loc)\nDEF(       get_loc2, 1, 0, 1, none_loc)\nDEF(       get_loc3, 1, 0, 1, none_loc)\nDEF(       put_loc0, 1, 1, 0, none_loc)\nDEF(       put_loc1, 1, 1, 0, none_loc)\nDEF(       put_loc2, 1, 1, 0, none_loc)\nDEF(       put_loc3, 1, 1, 0, none_loc)\nDEF(       set_loc0, 1, 1, 1, none_loc)\nDEF(       set_loc1, 1, 1, 1, none_loc)\nDEF(       set_loc2, 1, 1, 1, none_loc)\nDEF(       set_loc3, 1, 1, 1, none_loc)\nDEF(       get_arg0, 1, 0, 1, none_arg)\nDEF(       get_arg1, 1, 0, 1, none_arg)\nDEF(       get_arg2, 1, 0, 1, none_arg)\nDEF(       get_arg3, 1, 0, 1, none_arg)\nDEF(       put_arg0, 1, 1, 0, none_arg)\nDEF(       put_arg1, 1, 1, 0, none_arg)\nDEF(       put_arg2, 1, 1, 0, none_arg)\nDEF(       put_arg3, 1, 1, 0, none_arg)\nDEF(       set_arg0, 1, 1, 1, none_arg)\nDEF(       set_arg1, 1, 1, 1, none_arg)\nDEF(       set_arg2, 1, 1, 1, none_arg)\nDEF(       set_arg3, 1, 1, 1, none_arg)\nDEF(   get_var_ref0, 1, 0, 1, none_var_ref)\nDEF(   get_var_ref1, 1, 0, 1, none_var_ref)\nDEF(   get_var_ref2, 1, 0, 1, none_var_ref)\nDEF(   get_var_ref3, 1, 0, 1, none_var_ref)\nDEF(   put_var_ref0, 1, 1, 0, none_var_ref)\nDEF(   put_var_ref1, 1, 1, 0, none_var_ref)\nDEF(   put_var_ref2, 1, 1, 0, none_var_ref)\nDEF(   put_var_ref3, 1, 1, 0, none_var_ref)\nDEF(   set_var_ref0, 1, 1, 1, none_var_ref)\nDEF(   set_var_ref1, 1, 1, 1, none_var_ref)\nDEF(   set_var_ref2, 1, 1, 1, none_var_ref)\nDEF(   set_var_ref3, 1, 1, 1, none_var_ref)\n\nDEF(     get_length, 1, 1, 1, none)\n\nDEF(      if_false8, 2, 1, 0, label8)\nDEF(       if_true8, 2, 1, 0, label8) /* must come after if_false8 */\nDEF(          goto8, 2, 0, 0, label8) /* must come after if_true8 */\nDEF(         goto16, 3, 0, 0, label16)\n\nDEF(          call0, 1, 1, 1, npopx)\nDEF(          call1, 1, 1, 1, npopx)\nDEF(          call2, 1, 1, 1, npopx)\nDEF(          call3, 1, 1, 1, npopx)\n\nDEF(   is_undefined, 1, 1, 1, none)\nDEF(        is_null, 1, 1, 1, none)\nDEF(    is_function, 1, 1, 1, none)\n#endif\n\n#undef DEF\n#undef def\n#endif  /* DEF */\n"
  },
  {
    "path": "quickjs.c",
    "content": "/*\n * QuickJS Javascript Engine\n * \n * Copyright (c) 2017-2020 Fabrice Bellard\n * Copyright (c) 2017-2020 Charlie Gordon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#include \"version.h\"\n#include <stdlib.h>\n#include <stdio.h>\n#include <stdarg.h>\n#include <inttypes.h>\n#include <string.h>\n#include <assert.h>\n#include <sys/time.h>\n#include <time.h>\n#include <fenv.h>\n#include <math.h>\n#if defined(__APPLE__)\n#include <malloc/malloc.h>\n#elif defined(__linux__)\n#include <malloc.h>\n#endif\n\n#include \"cutils.h\"\n#include \"list.h\"\n#include \"quickjs.h\"\n#include \"libregexp.h\"\n#ifdef CONFIG_BIGNUM\n#include \"libbf.h\"\n#endif\n\n#define OPTIMIZE         1\n#define SHORT_OPCODES    1\n#if defined(EMSCRIPTEN)\n#define DIRECT_DISPATCH  0\n#else\n#define DIRECT_DISPATCH  1\n#endif\n\n#if defined(__APPLE__)\n#define MALLOC_OVERHEAD  0\n#else\n#define MALLOC_OVERHEAD  8\n#endif\n\n#if !defined(_WIN32)\n/* define it if printf uses the RNDN rounding mode instead of RNDNA */\n#define CONFIG_PRINTF_RNDN\n#endif\n\n/* define to include Atomics.* operations which depend on the OS\n   threads */\n#if !defined(EMSCRIPTEN)\n#define CONFIG_ATOMICS\n#endif\n\n#if !defined(EMSCRIPTEN)\n/* enable stack limitation */\n#define CONFIG_STACK_CHECK\n#endif\n\n\n/* dump object free */\n//#define DUMP_FREE\n//#define DUMP_CLOSURE\n/* dump the bytecode of the compiled functions: combination of bits\n   1: dump pass 3 final byte code\n   2: dump pass 2 code\n   4: dump pass 1 code\n   8: dump stdlib functions\n  16: dump bytecode in hex\n  32: dump line number table\n */\n//#define DUMP_BYTECODE  (1)\n/* dump the occurence of the automatic GC */\n//#define DUMP_GC\n/* dump objects freed by the garbage collector */\n//#define DUMP_GC_FREE\n/* dump objects leaking when freeing the runtime */\n//#define DUMP_LEAKS  1\n/* dump memory usage before running the garbage collector */\n//#define DUMP_MEM\n//#define DUMP_OBJECTS    /* dump objects in JS_FreeContext */\n//#define DUMP_ATOMS      /* dump atoms in JS_FreeContext */\n//#define DUMP_SHAPES     /* dump shapes in JS_FreeContext */\n//#define DUMP_MODULE_RESOLVE\n//#define DUMP_PROMISE\n//#define DUMP_READ_OBJECT\n\n/* test the GC by forcing it before each object allocation */\n//#define FORCE_GC_AT_MALLOC\n\n#ifdef CONFIG_ATOMICS\n#include <pthread.h>\n#include <stdatomic.h>\n#include <errno.h>\n#endif\n\nenum {\n    /* classid tag        */    /* union usage   | properties */\n    JS_CLASS_OBJECT = 1,        /* must be first */\n    JS_CLASS_ARRAY,             /* u.array       | length */\n    JS_CLASS_ERROR,\n    JS_CLASS_NUMBER,            /* u.object_data */\n    JS_CLASS_STRING,            /* u.object_data */\n    JS_CLASS_BOOLEAN,           /* u.object_data */\n    JS_CLASS_SYMBOL,            /* u.object_data */\n    JS_CLASS_ARGUMENTS,         /* u.array       | length */\n    JS_CLASS_MAPPED_ARGUMENTS,  /*               | length */\n    JS_CLASS_DATE,              /* u.object_data */\n    JS_CLASS_MODULE_NS,\n    JS_CLASS_C_FUNCTION,        /* u.cfunc */\n    JS_CLASS_BYTECODE_FUNCTION, /* u.func */\n    JS_CLASS_BOUND_FUNCTION,    /* u.bound_function */\n    JS_CLASS_C_FUNCTION_DATA,   /* u.c_function_data_record */\n    JS_CLASS_GENERATOR_FUNCTION, /* u.func */\n    JS_CLASS_FOR_IN_ITERATOR,   /* u.for_in_iterator */\n    JS_CLASS_REGEXP,            /* u.regexp */\n    JS_CLASS_ARRAY_BUFFER,      /* u.array_buffer */\n    JS_CLASS_SHARED_ARRAY_BUFFER, /* u.array_buffer */\n    JS_CLASS_UINT8C_ARRAY,      /* u.array (typed_array) */\n    JS_CLASS_INT8_ARRAY,        /* u.array (typed_array) */\n    JS_CLASS_UINT8_ARRAY,       /* u.array (typed_array) */\n    JS_CLASS_INT16_ARRAY,       /* u.array (typed_array) */\n    JS_CLASS_UINT16_ARRAY,      /* u.array (typed_array) */\n    JS_CLASS_INT32_ARRAY,       /* u.array (typed_array) */\n    JS_CLASS_UINT32_ARRAY,      /* u.array (typed_array) */\n#ifdef CONFIG_BIGNUM\n    JS_CLASS_BIG_INT64_ARRAY,   /* u.array (typed_array) */\n    JS_CLASS_BIG_UINT64_ARRAY,  /* u.array (typed_array) */\n#endif\n    JS_CLASS_FLOAT32_ARRAY,     /* u.array (typed_array) */\n    JS_CLASS_FLOAT64_ARRAY,     /* u.array (typed_array) */\n    JS_CLASS_DATAVIEW,          /* u.typed_array */\n#ifdef CONFIG_BIGNUM\n    JS_CLASS_BIG_INT,           /* u.object_data */\n    JS_CLASS_BIG_FLOAT,         /* u.object_data */\n    JS_CLASS_FLOAT_ENV,         /* u.float_env */\n    JS_CLASS_BIG_DECIMAL,       /* u.object_data */\n    JS_CLASS_OPERATOR_SET,      /* u.operator_set */\n#endif\n    JS_CLASS_MAP,               /* u.map_state */\n    JS_CLASS_SET,               /* u.map_state */\n    JS_CLASS_WEAKMAP,           /* u.map_state */\n    JS_CLASS_WEAKSET,           /* u.map_state */\n    JS_CLASS_MAP_ITERATOR,      /* u.map_iterator_data */\n    JS_CLASS_SET_ITERATOR,      /* u.map_iterator_data */\n    JS_CLASS_ARRAY_ITERATOR,    /* u.array_iterator_data */\n    JS_CLASS_STRING_ITERATOR,   /* u.array_iterator_data */\n    JS_CLASS_REGEXP_STRING_ITERATOR,   /* u.regexp_string_iterator_data */\n    JS_CLASS_GENERATOR,         /* u.generator_data */\n    JS_CLASS_PROXY,             /* u.proxy_data */\n    JS_CLASS_PROMISE,           /* u.promise_data */\n    JS_CLASS_PROMISE_RESOLVE_FUNCTION,  /* u.promise_function_data */\n    JS_CLASS_PROMISE_REJECT_FUNCTION,   /* u.promise_function_data */\n    JS_CLASS_ASYNC_FUNCTION,            /* u.func */\n    JS_CLASS_ASYNC_FUNCTION_RESOLVE,    /* u.async_function_data */\n    JS_CLASS_ASYNC_FUNCTION_REJECT,     /* u.async_function_data */\n    JS_CLASS_ASYNC_FROM_SYNC_ITERATOR,  /* u.async_from_sync_iterator_data */\n    JS_CLASS_ASYNC_GENERATOR_FUNCTION,  /* u.func */\n    JS_CLASS_ASYNC_GENERATOR,   /* u.async_generator_data */\n\n    JS_CLASS_INIT_COUNT, /* last entry for predefined classes */\n};\n\n/* number of typed array types */\n#define JS_TYPED_ARRAY_COUNT  (JS_CLASS_FLOAT64_ARRAY - JS_CLASS_UINT8C_ARRAY + 1)\nstatic uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT];\n#define typed_array_size_log2(classid)  (typed_array_size_log2[(classid)- JS_CLASS_UINT8C_ARRAY])\n\ntypedef enum JSErrorEnum {\n    JS_EVAL_ERROR,\n    JS_RANGE_ERROR,\n    JS_REFERENCE_ERROR,\n    JS_SYNTAX_ERROR,\n    JS_TYPE_ERROR,\n    JS_URI_ERROR,\n    JS_INTERNAL_ERROR,\n    JS_AGGREGATE_ERROR,\n    \n    JS_NATIVE_ERROR_COUNT, /* number of different NativeError objects */\n} JSErrorEnum;\n\n#define JS_MAX_LOCAL_VARS 65536\n#define JS_STACK_SIZE_MAX 65536\n#define JS_STRING_LEN_MAX ((1 << 30) - 1)\n\n#define __exception __attribute__((warn_unused_result))\n\ntypedef struct JSShape JSShape;\ntypedef struct JSString JSString;\ntypedef struct JSString JSAtomStruct;\n\ntypedef enum {\n    JS_GC_PHASE_NONE,\n    JS_GC_PHASE_DECREF,\n    JS_GC_PHASE_REMOVE_CYCLES,\n} JSGCPhaseEnum;\n\ntypedef enum OPCodeEnum OPCodeEnum;\n\n#ifdef CONFIG_BIGNUM\n/* function pointers are used for numeric operations so that it is\n   possible to remove some numeric types */\ntypedef struct {\n    JSValue (*to_string)(JSContext *ctx, JSValueConst val);\n    JSValue (*from_string)(JSContext *ctx, const char *buf,\n                           int radix, int flags, slimb_t *pexponent);\n    int (*unary_arith)(JSContext *ctx,\n                       JSValue *pres, OPCodeEnum op, JSValue op1);\n    int (*binary_arith)(JSContext *ctx, OPCodeEnum op,\n                        JSValue *pres, JSValue op1, JSValue op2);\n    int (*compare)(JSContext *ctx, OPCodeEnum op,\n                   JSValue op1, JSValue op2);\n    /* only for bigfloat: */\n    JSValue (*mul_pow10_to_float64)(JSContext *ctx, const bf_t *a,\n                                    int64_t exponent);\n    int (*mul_pow10)(JSContext *ctx, JSValue *sp);\n} JSNumericOperations;\n#endif\n\nstruct JSRuntime {\n    JSMallocFunctions mf;\n    JSMallocState malloc_state;\n    const char *rt_info;\n\n    int atom_hash_size; /* power of two */\n    int atom_count;\n    int atom_size;\n    int atom_count_resize; /* resize hash table at this count */\n    uint32_t *atom_hash;\n    JSAtomStruct **atom_array;\n    int atom_free_index; /* 0 = none */\n\n    int class_count;    /* size of class_array */\n    JSClass *class_array;\n\n    struct list_head context_list; /* list of JSContext.link */\n    /* list of JSGCObjectHeader.link. List of allocated GC objects (used\n       by the garbage collector) */\n    struct list_head gc_obj_list;\n    /* list of JSGCObjectHeader.link. Used during JS_FreeValueRT() */\n    struct list_head gc_zero_ref_count_list; \n    struct list_head tmp_obj_list; /* used during GC */\n    JSGCPhaseEnum gc_phase : 8;\n    size_t malloc_gc_threshold;\n#ifdef DUMP_LEAKS\n    struct list_head string_list; /* list of JSString.link */\n#endif\n    /* stack limitation */\n    const uint8_t *stack_top;\n    size_t stack_size; /* in bytes */\n\n    JSValue current_exception;\n    /* true if inside an out of memory error, to avoid recursing */\n    BOOL in_out_of_memory : 8;\n\n    struct JSStackFrame *current_stack_frame;\n\n    JSInterruptHandler *interrupt_handler;\n    void *interrupt_opaque;\n\n    JSHostPromiseRejectionTracker *host_promise_rejection_tracker;\n    void *host_promise_rejection_tracker_opaque;\n    \n    struct list_head job_list; /* list of JSJobEntry.link */\n\n    JSModuleNormalizeFunc *module_normalize_func;\n    JSModuleLoaderFunc *module_loader_func;\n    void *module_loader_opaque;\n\n    BOOL can_block : 8; /* TRUE if Atomics.wait can block */\n    /* used to allocate, free and clone SharedArrayBuffers */\n    JSSharedArrayBufferFunctions sab_funcs;\n    \n    /* Shape hash table */\n    int shape_hash_bits;\n    int shape_hash_size;\n    int shape_hash_count; /* number of hashed shapes */\n    JSShape **shape_hash;\n#ifdef CONFIG_BIGNUM\n    bf_context_t bf_ctx;\n    JSNumericOperations bigint_ops;\n    JSNumericOperations bigfloat_ops;\n    JSNumericOperations bigdecimal_ops;\n    uint32_t operator_count;\n#endif\n    void *user_opaque;\n};\n\nstruct JSClass {\n    uint32_t class_id; /* 0 means free entry */\n    JSAtom class_name;\n    JSClassFinalizer *finalizer;\n    JSClassGCMark *gc_mark;\n    JSClassCall *call;\n    /* pointers for exotic behavior, can be NULL if none are present */\n    const JSClassExoticMethods *exotic;\n};\n\n#define JS_MODE_STRICT (1 << 0)\n#define JS_MODE_STRIP  (1 << 1)\n#define JS_MODE_MATH   (1 << 2)\n\ntypedef struct JSStackFrame {\n    struct JSStackFrame *prev_frame; /* NULL if first stack frame */\n    JSValue cur_func; /* current function, JS_UNDEFINED if the frame is detached */\n    JSValue *arg_buf; /* arguments */\n    JSValue *var_buf; /* variables */\n    struct list_head var_ref_list; /* list of JSVarRef.link */\n    const uint8_t *cur_pc; /* only used in bytecode functions : PC of the\n                        instruction after the call */\n    int arg_count;\n    int js_mode; /* 0 or JS_MODE_MATH for C functions */\n    /* only used in generators. Current stack pointer value. NULL if\n       the function is running. */ \n    JSValue *cur_sp;\n} JSStackFrame;\n\ntypedef enum {\n    JS_GC_OBJ_TYPE_JS_OBJECT,\n    JS_GC_OBJ_TYPE_FUNCTION_BYTECODE,\n    JS_GC_OBJ_TYPE_SHAPE,\n    JS_GC_OBJ_TYPE_VAR_REF,\n    JS_GC_OBJ_TYPE_ASYNC_FUNCTION,\n    JS_GC_OBJ_TYPE_JS_CONTEXT,\n} JSGCObjectTypeEnum;\n\n/* header for GC objects. GC objects are C data structures with a\n   reference count that can reference other GC objects. JS Objects are\n   a particular type of GC object. */\nstruct JSGCObjectHeader {\n    int ref_count; /* must come first, 32-bit */\n    JSGCObjectTypeEnum gc_obj_type : 4;\n    uint8_t mark : 4; /* used by the GC */\n    uint8_t dummy1; /* not used by the GC */\n    uint16_t dummy2; /* not used by the GC */\n    struct list_head link;\n};\n\ntypedef struct JSVarRef {\n    union {\n        JSGCObjectHeader header; /* must come first */\n        struct {\n            int __gc_ref_count; /* corresponds to header.ref_count */\n            uint8_t __gc_mark; /* corresponds to header.mark/gc_obj_type */\n\n            /* 0 : the JSVarRef is on the stack. header.link is an element\n               of JSStackFrame.var_ref_list.\n               1 : the JSVarRef is detached. header.link has the normal meanning \n            */\n            uint8_t is_detached : 1; \n            uint8_t is_arg : 1;\n            uint16_t var_idx; /* index of the corresponding function variable on\n                                 the stack */\n        };\n    };\n    JSValue *pvalue; /* pointer to the value, either on the stack or\n                        to 'value' */\n    JSValue value; /* used when the variable is no longer on the stack */\n} JSVarRef;\n\n#ifdef CONFIG_BIGNUM\ntypedef struct JSFloatEnv {\n    limb_t prec;\n    bf_flags_t flags;\n    unsigned int status;\n} JSFloatEnv;\n\n/* the same structure is used for big integers and big floats. Big\n   integers are never infinite or NaNs */\ntypedef struct JSBigFloat {\n    JSRefCountHeader header; /* must come first, 32-bit */\n    bf_t num;\n} JSBigFloat;\n\ntypedef struct JSBigDecimal {\n    JSRefCountHeader header; /* must come first, 32-bit */\n    bfdec_t num;\n} JSBigDecimal;\n#endif\n\ntypedef enum {\n    JS_AUTOINIT_ID_PROTOTYPE,\n    JS_AUTOINIT_ID_MODULE_NS,\n    JS_AUTOINIT_ID_PROP,\n} JSAutoInitIDEnum;\n\n/* must be large enough to have a negligible runtime cost and small\n   enough to call the interrupt callback often. */\n#define JS_INTERRUPT_COUNTER_INIT 10000\n\nstruct JSContext {\n    JSGCObjectHeader header; /* must come first */\n    JSRuntime *rt;\n    struct list_head link;\n\n    uint16_t binary_object_count;\n    int binary_object_size;\n\n    JSShape *array_shape;   /* initial shape for Array objects */\n\n    JSValue *class_proto;\n    JSValue function_proto;\n    JSValue function_ctor;\n    JSValue array_ctor;\n    JSValue regexp_ctor;\n    JSValue promise_ctor;\n    JSValue native_error_proto[JS_NATIVE_ERROR_COUNT];\n    JSValue iterator_proto;\n    JSValue async_iterator_proto;\n    JSValue array_proto_values;\n    JSValue throw_type_error;\n    JSValue eval_obj;\n\n    JSValue global_obj; /* global object */\n    JSValue global_var_obj; /* contains the global let/const definitions */\n\n    uint64_t random_state;\n#ifdef CONFIG_BIGNUM\n    bf_context_t *bf_ctx;   /* points to rt->bf_ctx, shared by all contexts */\n    JSFloatEnv fp_env; /* global FP environment */\n    BOOL bignum_ext : 8; /* enable math mode */\n    BOOL allow_operator_overloading : 8;\n#endif\n    /* when the counter reaches zero, JSRutime.interrupt_handler is called */\n    int interrupt_counter;\n    BOOL is_error_property_enabled;\n\n    struct list_head loaded_modules; /* list of JSModuleDef.link */\n\n    /* if NULL, RegExp compilation is not supported */\n    JSValue (*compile_regexp)(JSContext *ctx, JSValueConst pattern,\n                              JSValueConst flags);\n    /* if NULL, eval is not supported */\n    JSValue (*eval_internal)(JSContext *ctx, JSValueConst this_obj,\n                             const char *input, size_t input_len,\n                             const char *filename, int flags, int scope_idx);\n    void *user_opaque;\n};\n\ntypedef union JSFloat64Union {\n    double d;\n    uint64_t u64;\n    uint32_t u32[2];\n} JSFloat64Union;\n\nenum {\n    JS_ATOM_TYPE_STRING = 1,\n    JS_ATOM_TYPE_GLOBAL_SYMBOL,\n    JS_ATOM_TYPE_SYMBOL,\n    JS_ATOM_TYPE_PRIVATE,\n};\n\nenum {\n    JS_ATOM_HASH_SYMBOL,\n    JS_ATOM_HASH_PRIVATE,\n};\n\ntypedef enum {\n    JS_ATOM_KIND_STRING,\n    JS_ATOM_KIND_SYMBOL,\n    JS_ATOM_KIND_PRIVATE,\n} JSAtomKindEnum;\n\n#define JS_ATOM_HASH_MASK  ((1 << 30) - 1)\n\nstruct JSString {\n    JSRefCountHeader header; /* must come first, 32-bit */\n    uint32_t len : 31;\n    uint8_t is_wide_char : 1; /* 0 = 8 bits, 1 = 16 bits characters */\n    /* for JS_ATOM_TYPE_SYMBOL: hash = 0, atom_type = 3,\n       for JS_ATOM_TYPE_PRIVATE: hash = 1, atom_type = 3\n       XXX: could change encoding to have one more bit in hash */\n    uint32_t hash : 30;\n    uint8_t atom_type : 2; /* != 0 if atom, JS_ATOM_TYPE_x */\n    uint32_t hash_next; /* atom_index for JS_ATOM_TYPE_SYMBOL */\n#ifdef DUMP_LEAKS\n    struct list_head link; /* string list */\n#endif\n    union {\n        uint8_t str8[0]; /* 8 bit strings will get an extra null terminator */\n        uint16_t str16[0];\n    } u;\n};\n\ntypedef struct JSClosureVar {\n    uint8_t is_local : 1;\n    uint8_t is_arg : 1;\n    uint8_t is_const : 1;\n    uint8_t is_lexical : 1;\n    uint8_t var_kind : 3; /* see JSVarKindEnum */\n    /* 9 bits available */\n    uint16_t var_idx; /* is_local = TRUE: index to a normal variable of the\n                    parent function. otherwise: index to a closure\n                    variable of the parent function */\n    JSAtom var_name;\n} JSClosureVar;\n\ntypedef struct JSVarScope {\n    int parent;  /* index into fd->scopes of the enclosing scope */\n    int first;   /* index into fd->vars of the last variable in this scope */\n} JSVarScope;\n\ntypedef enum {\n    /* XXX: add more variable kinds here instead of using bit fields */\n    JS_VAR_NORMAL,\n    JS_VAR_FUNCTION_DECL, /* lexical var with function declaration */\n    JS_VAR_NEW_FUNCTION_DECL, /* lexical var with async/generator\n                                 function declaration */\n    JS_VAR_CATCH,\n    JS_VAR_PRIVATE_FIELD,\n    JS_VAR_PRIVATE_METHOD,\n    JS_VAR_PRIVATE_GETTER,\n    JS_VAR_PRIVATE_SETTER, /* must come after JS_VAR_PRIVATE_GETTER */\n    JS_VAR_PRIVATE_GETTER_SETTER, /* must come after JS_VAR_PRIVATE_SETTER */\n} JSVarKindEnum;\n\ntypedef struct JSVarDef {\n    JSAtom var_name;\n    int scope_level;   /* index into fd->scopes of this variable lexical scope */\n    int scope_next;    /* index into fd->vars of the next variable in the\n                        * same or enclosing lexical scope */\n    uint8_t is_func_var : 1; /* used for the function self reference */\n    uint8_t is_const : 1;\n    uint8_t is_lexical : 1;\n    uint8_t is_captured : 1;\n    uint8_t var_kind : 4; /* see JSVarKindEnum */\n    /* only used during compilation: function pool index for lexical\n       variables with var_kind =\n       JS_VAR_FUNCTION_DECL/JS_VAR_NEW_FUNCTION_DECL or scope level of\n       the definition of the 'var' variables (they have scope_level =\n       0) */\n    int func_pool_or_scope_idx : 24; /* only used during compilation */\n} JSVarDef;\n\n/* for the encoding of the pc2line table */\n#define PC2LINE_BASE     (-1)\n#define PC2LINE_RANGE    5\n#define PC2LINE_OP_FIRST 1\n#define PC2LINE_DIFF_PC_MAX ((255 - PC2LINE_OP_FIRST) / PC2LINE_RANGE)\n\ntypedef enum JSFunctionKindEnum {\n    JS_FUNC_NORMAL = 0,\n    JS_FUNC_GENERATOR = (1 << 0),\n    JS_FUNC_ASYNC = (1 << 1),\n    JS_FUNC_ASYNC_GENERATOR = (JS_FUNC_GENERATOR | JS_FUNC_ASYNC),\n} JSFunctionKindEnum;\n\ntypedef struct JSFunctionBytecode {\n    JSGCObjectHeader header; /* must come first */\n    uint8_t js_mode;\n    uint8_t has_prototype : 1; /* true if a prototype field is necessary */\n    uint8_t has_simple_parameter_list : 1;\n    uint8_t is_derived_class_constructor : 1;\n    /* true if home_object needs to be initialized */\n    uint8_t need_home_object : 1;\n    uint8_t func_kind : 2;\n    uint8_t new_target_allowed : 1;\n    uint8_t super_call_allowed : 1;\n    uint8_t super_allowed : 1;\n    uint8_t arguments_allowed : 1;\n    uint8_t has_debug : 1;\n    uint8_t backtrace_barrier : 1; /* stop backtrace on this function */\n    uint8_t read_only_bytecode : 1;\n    /* XXX: 4 bits available */\n    uint8_t *byte_code_buf; /* (self pointer) */\n    int byte_code_len;\n    JSAtom func_name;\n    JSVarDef *vardefs; /* arguments + local variables (arg_count + var_count) (self pointer) */\n    JSClosureVar *closure_var; /* list of variables in the closure (self pointer) */\n    uint16_t arg_count;\n    uint16_t var_count;\n    uint16_t defined_arg_count; /* for length function property */\n    uint16_t stack_size; /* maximum stack size */\n    JSContext *realm; /* function realm */\n    JSValue *cpool; /* constant pool (self pointer) */\n    int cpool_count;\n    int closure_var_count;\n    struct {\n        /* debug info, move to separate structure to save memory? */\n        JSAtom filename;\n        int line_num;\n        int source_len;\n        int pc2line_len;\n        uint8_t *pc2line_buf;\n        char *source;\n    } debug;\n} JSFunctionBytecode;\n\ntypedef struct JSBoundFunction {\n    JSValue func_obj;\n    JSValue this_val;\n    int argc;\n    JSValue argv[0];\n} JSBoundFunction;\n\ntypedef enum JSIteratorKindEnum {\n    JS_ITERATOR_KIND_KEY,\n    JS_ITERATOR_KIND_VALUE,\n    JS_ITERATOR_KIND_KEY_AND_VALUE,\n} JSIteratorKindEnum;\n\ntypedef struct JSForInIterator {\n    JSValue obj;\n    BOOL is_array;\n    uint32_t array_length;\n    uint32_t idx;\n} JSForInIterator;\n\ntypedef struct JSRegExp {\n    JSString *pattern;\n    JSString *bytecode; /* also contains the flags */\n} JSRegExp;\n\ntypedef struct JSProxyData {\n    JSValue target;\n    JSValue handler;\n    uint8_t is_func;\n    uint8_t is_revoked;\n} JSProxyData;\n\ntypedef struct JSArrayBuffer {\n    int byte_length; /* 0 if detached */\n    uint8_t detached;\n    uint8_t shared; /* if shared, the array buffer cannot be detached */\n    uint8_t *data; /* NULL if detached */\n    struct list_head array_list;\n    void *opaque;\n    JSFreeArrayBufferDataFunc *free_func;\n} JSArrayBuffer;\n\ntypedef struct JSTypedArray {\n    struct list_head link; /* link to arraybuffer */\n    JSObject *obj; /* back pointer to the TypedArray/DataView object */\n    JSObject *buffer; /* based array buffer */\n    uint32_t offset; /* offset in the array buffer */\n    uint32_t length; /* length in the array buffer */\n} JSTypedArray;\n\ntypedef struct JSAsyncFunctionState {\n    JSValue this_val; /* 'this' generator argument */\n    int argc; /* number of function arguments */\n    BOOL throw_flag; /* used to throw an exception in JS_CallInternal() */\n    JSStackFrame frame;\n} JSAsyncFunctionState;\n\n/* XXX: could use an object instead to avoid the\n   JS_TAG_ASYNC_FUNCTION tag for the GC */\ntypedef struct JSAsyncFunctionData {\n    JSGCObjectHeader header; /* must come first */\n    JSValue resolving_funcs[2];\n    BOOL is_active; /* true if the async function state is valid */\n    JSAsyncFunctionState func_state;\n} JSAsyncFunctionData;\n\ntypedef enum {\n   /* binary operators */\n   JS_OVOP_ADD,\n   JS_OVOP_SUB,\n   JS_OVOP_MUL,\n   JS_OVOP_DIV,\n   JS_OVOP_MOD,\n   JS_OVOP_POW,\n   JS_OVOP_OR,\n   JS_OVOP_AND,\n   JS_OVOP_XOR,\n   JS_OVOP_SHL,\n   JS_OVOP_SAR,\n   JS_OVOP_SHR,\n   JS_OVOP_EQ,\n   JS_OVOP_LESS,\n\n   JS_OVOP_BINARY_COUNT,\n   /* unary operators */\n   JS_OVOP_POS = JS_OVOP_BINARY_COUNT,\n   JS_OVOP_NEG,\n   JS_OVOP_INC,\n   JS_OVOP_DEC,\n   JS_OVOP_NOT,\n\n   JS_OVOP_COUNT,\n} JSOverloadableOperatorEnum;\n\ntypedef struct {\n    uint32_t operator_index;\n    JSObject *ops[JS_OVOP_BINARY_COUNT]; /* self operators */\n} JSBinaryOperatorDefEntry;\n\ntypedef struct {\n    int count;\n    JSBinaryOperatorDefEntry *tab;\n} JSBinaryOperatorDef;\n\ntypedef struct {\n    uint32_t operator_counter;\n    BOOL is_primitive; /* OperatorSet for a primitive type */\n    /* NULL if no operator is defined */\n    JSObject *self_ops[JS_OVOP_COUNT]; /* self operators */\n    JSBinaryOperatorDef left;\n    JSBinaryOperatorDef right;\n} JSOperatorSetData;\n\ntypedef struct JSReqModuleEntry {\n    JSAtom module_name;\n    JSModuleDef *module; /* used using resolution */\n} JSReqModuleEntry;\n\ntypedef enum JSExportTypeEnum {\n    JS_EXPORT_TYPE_LOCAL,\n    JS_EXPORT_TYPE_INDIRECT,\n} JSExportTypeEnum;\n\ntypedef struct JSExportEntry {\n    union {\n        struct {\n            int var_idx; /* closure variable index */\n            JSVarRef *var_ref; /* if != NULL, reference to the variable */\n        } local; /* for local export */\n        int req_module_idx; /* module for indirect export */\n    } u;\n    JSExportTypeEnum export_type;\n    JSAtom local_name; /* '*' if export ns from. not used for local\n                          export after compilation */\n    JSAtom export_name; /* exported variable name */\n} JSExportEntry;\n\ntypedef struct JSStarExportEntry {\n    int req_module_idx; /* in req_module_entries */\n} JSStarExportEntry;\n\ntypedef struct JSImportEntry {\n    int var_idx; /* closure variable index */\n    JSAtom import_name;\n    int req_module_idx; /* in req_module_entries */\n} JSImportEntry;\n\nstruct JSModuleDef {\n    JSRefCountHeader header; /* must come first, 32-bit */\n    JSAtom module_name;\n    struct list_head link;\n\n    JSReqModuleEntry *req_module_entries;\n    int req_module_entries_count;\n    int req_module_entries_size;\n\n    JSExportEntry *export_entries;\n    int export_entries_count;\n    int export_entries_size;\n\n    JSStarExportEntry *star_export_entries;\n    int star_export_entries_count;\n    int star_export_entries_size;\n\n    JSImportEntry *import_entries;\n    int import_entries_count;\n    int import_entries_size;\n\n    JSValue module_ns;\n    JSValue func_obj; /* only used for JS modules */\n    JSModuleInitFunc *init_func; /* only used for C modules */\n    BOOL resolved : 8;\n    BOOL func_created : 8;\n    BOOL instantiated : 8;\n    BOOL evaluated : 8;\n    BOOL eval_mark : 8; /* temporary use during js_evaluate_module() */\n    /* true if evaluation yielded an exception. It is saved in\n       eval_exception */\n    BOOL eval_has_exception : 8; \n    JSValue eval_exception;\n    JSValue meta_obj; /* for import.meta */\n};\n\ntypedef struct JSJobEntry {\n    struct list_head link;\n    JSContext *ctx;\n    JSJobFunc *job_func;\n    int argc;\n    JSValue argv[0];\n} JSJobEntry;\n\ntypedef struct JSProperty {\n    union {\n        JSValue value;      /* JS_PROP_NORMAL */\n        struct {            /* JS_PROP_GETSET */\n            JSObject *getter; /* NULL if undefined */\n            JSObject *setter; /* NULL if undefined */\n        } getset;\n        JSVarRef *var_ref;  /* JS_PROP_VARREF */\n        struct {            /* JS_PROP_AUTOINIT */\n            /* in order to use only 2 pointers, we compress the realm\n               and the init function pointer */\n            uintptr_t realm_and_id; /* realm and init_id (JS_AUTOINIT_ID_x)\n                                       in the 2 low bits */\n            void *opaque;\n        } init;\n    } u;\n} JSProperty;\n\n#define JS_PROP_INITIAL_SIZE 2\n#define JS_PROP_INITIAL_HASH_SIZE 4 /* must be a power of two */\n#define JS_ARRAY_INITIAL_SIZE 2\n\ntypedef struct JSShapeProperty {\n    uint32_t hash_next : 26; /* 0 if last in list */\n    uint32_t flags : 6;   /* JS_PROP_XXX */\n    JSAtom atom; /* JS_ATOM_NULL = free property entry */\n} JSShapeProperty;\n\nstruct JSShape {\n    uint32_t prop_hash_end[0]; /* hash table of size hash_mask + 1\n                                  before the start of the structure. */\n    JSGCObjectHeader header;\n    /* true if the shape is inserted in the shape hash table. If not,\n       JSShape.hash is not valid */\n    uint8_t is_hashed;\n    /* If true, the shape may have small array index properties 'n' with 0\n       <= n <= 2^31-1. If false, the shape is guaranteed not to have\n       small array index properties */\n    uint8_t has_small_array_index;\n    uint32_t hash; /* current hash value */\n    uint32_t prop_hash_mask;\n    int prop_size; /* allocated properties */\n    int prop_count; /* include deleted properties */\n    int deleted_prop_count;\n    JSShape *shape_hash_next; /* in JSRuntime.shape_hash[h] list */\n    JSObject *proto;\n    JSShapeProperty prop[0]; /* prop_size elements */\n};\n\nstruct JSObject {\n    union {\n        JSGCObjectHeader header;\n        struct {\n            int __gc_ref_count; /* corresponds to header.ref_count */\n            uint8_t __gc_mark; /* corresponds to header.mark/gc_obj_type */\n            \n            uint8_t extensible : 1;\n            uint8_t free_mark : 1; /* only used when freeing objects with cycles */\n            uint8_t is_exotic : 1; /* TRUE if object has exotic property handlers */\n            uint8_t fast_array : 1; /* TRUE if u.array is used for get/put */\n            uint8_t is_constructor : 1; /* TRUE if object is a constructor function */\n            uint8_t is_uncatchable_error : 1; /* if TRUE, error is not catchable */\n            uint8_t tmp_mark : 1; /* used in JS_WriteObjectRec() */\n            uint16_t class_id; /* see JS_CLASS_x */\n        };\n    };\n    /* byte offsets: 16/24 */\n    JSShape *shape; /* prototype and property names + flag */\n    JSProperty *prop; /* array of properties */\n    /* byte offsets: 24/40 */\n    struct JSMapRecord *first_weak_ref; /* XXX: use a bit and an external hash table? */\n    /* byte offsets: 28/48 */\n    union {\n        void *opaque;\n        struct JSBoundFunction *bound_function; /* JS_CLASS_BOUND_FUNCTION */\n        struct JSCFunctionDataRecord *c_function_data_record; /* JS_CLASS_C_FUNCTION_DATA */\n        struct JSForInIterator *for_in_iterator; /* JS_CLASS_FOR_IN_ITERATOR */\n        struct JSArrayBuffer *array_buffer; /* JS_CLASS_ARRAY_BUFFER, JS_CLASS_SHARED_ARRAY_BUFFER */\n        struct JSTypedArray *typed_array; /* JS_CLASS_UINT8C_ARRAY..JS_CLASS_DATAVIEW */\n#ifdef CONFIG_BIGNUM\n        struct JSFloatEnv *float_env; /* JS_CLASS_FLOAT_ENV */\n        struct JSOperatorSetData *operator_set; /* JS_CLASS_OPERATOR_SET */\n#endif\n        struct JSMapState *map_state;   /* JS_CLASS_MAP..JS_CLASS_WEAKSET */\n        struct JSMapIteratorData *map_iterator_data; /* JS_CLASS_MAP_ITERATOR, JS_CLASS_SET_ITERATOR */\n        struct JSArrayIteratorData *array_iterator_data; /* JS_CLASS_ARRAY_ITERATOR, JS_CLASS_STRING_ITERATOR */\n        struct JSRegExpStringIteratorData *regexp_string_iterator_data; /* JS_CLASS_REGEXP_STRING_ITERATOR */\n        struct JSGeneratorData *generator_data; /* JS_CLASS_GENERATOR */\n        struct JSProxyData *proxy_data; /* JS_CLASS_PROXY */\n        struct JSPromiseData *promise_data; /* JS_CLASS_PROMISE */\n        struct JSPromiseFunctionData *promise_function_data; /* JS_CLASS_PROMISE_RESOLVE_FUNCTION, JS_CLASS_PROMISE_REJECT_FUNCTION */\n        struct JSAsyncFunctionData *async_function_data; /* JS_CLASS_ASYNC_FUNCTION_RESOLVE, JS_CLASS_ASYNC_FUNCTION_REJECT */\n        struct JSAsyncFromSyncIteratorData *async_from_sync_iterator_data; /* JS_CLASS_ASYNC_FROM_SYNC_ITERATOR */\n        struct JSAsyncGeneratorData *async_generator_data; /* JS_CLASS_ASYNC_GENERATOR */\n        struct { /* JS_CLASS_BYTECODE_FUNCTION: 12/24 bytes */\n            /* also used by JS_CLASS_GENERATOR_FUNCTION, JS_CLASS_ASYNC_FUNCTION and JS_CLASS_ASYNC_GENERATOR_FUNCTION */\n            struct JSFunctionBytecode *function_bytecode;\n            JSVarRef **var_refs;\n            JSObject *home_object; /* for 'super' access */\n        } func;\n        struct { /* JS_CLASS_C_FUNCTION: 12/20 bytes */\n            JSContext *realm;\n            JSCFunctionType c_function;\n            uint8_t length;\n            uint8_t cproto;\n            int16_t magic;\n        } cfunc;\n        /* array part for fast arrays and typed arrays */\n        struct { /* JS_CLASS_ARRAY, JS_CLASS_ARGUMENTS, JS_CLASS_UINT8C_ARRAY..JS_CLASS_FLOAT64_ARRAY */\n            union {\n                uint32_t size;          /* JS_CLASS_ARRAY, JS_CLASS_ARGUMENTS */\n                struct JSTypedArray *typed_array; /* JS_CLASS_UINT8C_ARRAY..JS_CLASS_FLOAT64_ARRAY */\n            } u1;\n            union {\n                JSValue *values;        /* JS_CLASS_ARRAY, JS_CLASS_ARGUMENTS */ \n                void *ptr;              /* JS_CLASS_UINT8C_ARRAY..JS_CLASS_FLOAT64_ARRAY */\n                int8_t *int8_ptr;       /* JS_CLASS_INT8_ARRAY */\n                uint8_t *uint8_ptr;     /* JS_CLASS_UINT8_ARRAY, JS_CLASS_UINT8C_ARRAY */\n                int16_t *int16_ptr;     /* JS_CLASS_INT16_ARRAY */\n                uint16_t *uint16_ptr;   /* JS_CLASS_UINT16_ARRAY */\n                int32_t *int32_ptr;     /* JS_CLASS_INT32_ARRAY */\n                uint32_t *uint32_ptr;   /* JS_CLASS_UINT32_ARRAY */\n                int64_t *int64_ptr;     /* JS_CLASS_INT64_ARRAY */\n                uint64_t *uint64_ptr;   /* JS_CLASS_UINT64_ARRAY */\n                float *float_ptr;       /* JS_CLASS_FLOAT32_ARRAY */\n                double *double_ptr;     /* JS_CLASS_FLOAT64_ARRAY */\n            } u;\n            uint32_t count; /* <= 2^31-1. 0 for a detached typed array */\n        } array;    /* 12/20 bytes */\n        JSRegExp regexp;    /* JS_CLASS_REGEXP: 8/16 bytes */\n        JSValue object_data;    /* for JS_SetObjectData(): 8/16/16 bytes */\n    } u;\n    /* byte sizes: 40/48/72 */\n};\nenum {\n    JS_ATOM_NULL,\n#define DEF(name, str) JS_ATOM_ ## name,\n#include \"quickjs-atom.h\"\n#undef DEF\n    JS_ATOM_END,\n};\n#define JS_ATOM_LAST_KEYWORD JS_ATOM_super\n#define JS_ATOM_LAST_STRICT_KEYWORD JS_ATOM_yield\n\nstatic const char js_atom_init[] =\n#define DEF(name, str) str \"\\0\"\n#include \"quickjs-atom.h\"\n#undef DEF\n;\n\ntypedef enum OPCodeFormat {\n#define FMT(f) OP_FMT_ ## f,\n#define DEF(id, size, n_pop, n_push, f)\n#include \"quickjs-opcode.h\"\n#undef DEF\n#undef FMT\n} OPCodeFormat;\n\nenum OPCodeEnum {\n#define FMT(f)\n#define DEF(id, size, n_pop, n_push, f) OP_ ## id,\n#define def(id, size, n_pop, n_push, f)\n#include \"quickjs-opcode.h\"\n#undef def\n#undef DEF\n#undef FMT\n    OP_COUNT, /* excluding temporary opcodes */\n    /* temporary opcodes : overlap with the short opcodes */\n    OP_TEMP_START = OP_nop + 1,\n    OP___dummy = OP_TEMP_START - 1,\n#define FMT(f)\n#define DEF(id, size, n_pop, n_push, f)\n#define def(id, size, n_pop, n_push, f) OP_ ## id,\n#include \"quickjs-opcode.h\"\n#undef def\n#undef DEF\n#undef FMT\n    OP_TEMP_END,\n};\n\nstatic int JS_InitAtoms(JSRuntime *rt);\nstatic JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,\n                               int atom_type);\nstatic void JS_FreeAtomStruct(JSRuntime *rt, JSAtomStruct *p);\nstatic void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b);\nstatic JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,\n                                  JSValueConst this_obj,\n                                  int argc, JSValueConst *argv, int flags);\nstatic JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,\n                                      JSValueConst this_obj,\n                                      int argc, JSValueConst *argv, int flags);\nstatic JSValue JS_CallInternal(JSContext *ctx, JSValueConst func_obj,\n                               JSValueConst this_obj, JSValueConst new_target,\n                               int argc, JSValue *argv, int flags);\nstatic JSValue JS_CallConstructorInternal(JSContext *ctx,\n                                          JSValueConst func_obj,\n                                          JSValueConst new_target,\n                                          int argc, JSValue *argv, int flags);\nstatic JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueConst this_obj,\n                           int argc, JSValueConst *argv);\nstatic JSValue JS_InvokeFree(JSContext *ctx, JSValue this_val, JSAtom atom,\n                             int argc, JSValueConst *argv);\nstatic __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,\n                                            JSValue val);\nstatic JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj,\n                             JSValueConst val, int flags, int scope_idx);\nJSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);\nstatic __maybe_unused void JS_DumpAtoms(JSRuntime *rt);\nstatic __maybe_unused void JS_DumpString(JSRuntime *rt,\n                                                  const JSString *p);\nstatic __maybe_unused void JS_DumpObjectHeader(JSRuntime *rt);\nstatic __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p);\nstatic __maybe_unused void JS_DumpGCObject(JSRuntime *rt, JSGCObjectHeader *p);\nstatic __maybe_unused void JS_DumpValueShort(JSRuntime *rt,\n                                                      JSValueConst val);\nstatic __maybe_unused void JS_DumpValue(JSContext *ctx, JSValueConst val);\nstatic __maybe_unused void JS_PrintValue(JSContext *ctx,\n                                                  const char *str,\n                                                  JSValueConst val);\nstatic __maybe_unused void JS_DumpShapes(JSRuntime *rt);\nstatic JSValue js_function_apply(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv, int magic);\nstatic void js_array_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_array_mark(JSRuntime *rt, JSValueConst val,\n                          JS_MarkFunc *mark_func);\nstatic void js_object_data_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_object_data_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_c_function_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_c_function_mark(JSRuntime *rt, JSValueConst val,\n                               JS_MarkFunc *mark_func);\nstatic void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_bytecode_function_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_bound_function_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_bound_function_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_for_in_iterator_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_for_in_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_regexp_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_array_buffer_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_typed_array_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_typed_array_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_proxy_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_proxy_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_map_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_map_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_map_iterator_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_map_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_array_iterator_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_array_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_regexp_string_iterator_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_regexp_string_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_generator_finalizer(JSRuntime *rt, JSValue obj);\nstatic void js_generator_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_promise_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_promise_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\nstatic void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_promise_resolve_function_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func);\n#ifdef CONFIG_BIGNUM\nstatic void js_operator_set_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_operator_set_mark(JSRuntime *rt, JSValueConst val,\n                                 JS_MarkFunc *mark_func);\n#endif\nstatic JSValue JS_ToStringFree(JSContext *ctx, JSValue val);\nstatic int JS_ToBoolFree(JSContext *ctx, JSValue val);\nstatic int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val);\nstatic int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue val);\nstatic int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val);\nstatic JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern,\n                                 JSValueConst flags);\nstatic JSValue js_regexp_constructor_internal(JSContext *ctx, JSValueConst ctor,\n                                              JSValue pattern, JSValue bc);\nstatic void gc_decref(JSRuntime *rt);\nstatic int JS_NewClass1(JSRuntime *rt, JSClassID class_id,\n                        const JSClassDef *class_def, JSAtom name);\n\ntypedef enum JSStrictEqModeEnum {\n    JS_EQ_STRICT,\n    JS_EQ_SAME_VALUE,\n    JS_EQ_SAME_VALUE_ZERO,\n} JSStrictEqModeEnum;\n\nstatic BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,\n                          JSStrictEqModeEnum eq_mode);\nstatic BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2);\nstatic BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2);\nstatic BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2);\nstatic JSValue JS_ToObject(JSContext *ctx, JSValueConst val);\nstatic JSValue JS_ToObjectFree(JSContext *ctx, JSValue val);\nstatic JSProperty *add_property(JSContext *ctx,\n                                JSObject *p, JSAtom prop, int prop_flags);\n#ifdef CONFIG_BIGNUM\nstatic void js_float_env_finalizer(JSRuntime *rt, JSValue val);\nstatic JSValue JS_NewBigFloat(JSContext *ctx);\nstatic inline bf_t *JS_GetBigFloat(JSValueConst val)\n{\n    JSBigFloat *p = JS_VALUE_GET_PTR(val);\n    return &p->num;\n}\nstatic JSValue JS_NewBigDecimal(JSContext *ctx);\nstatic inline bfdec_t *JS_GetBigDecimal(JSValueConst val)\n{\n    JSBigDecimal *p = JS_VALUE_GET_PTR(val);\n    return &p->num;\n}\nstatic JSValue JS_NewBigInt(JSContext *ctx);\nstatic inline bf_t *JS_GetBigInt(JSValueConst val)\n{\n    JSBigFloat *p = JS_VALUE_GET_PTR(val);\n    return &p->num;\n}\nstatic JSValue JS_CompactBigInt1(JSContext *ctx, JSValue val,\n                                 BOOL convert_to_safe_integer);\nstatic JSValue JS_CompactBigInt(JSContext *ctx, JSValue val);\nstatic int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val);\nstatic bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValueConst val);\nstatic void JS_FreeBigInt(JSContext *ctx, bf_t *a, bf_t *buf);\nstatic bf_t *JS_ToBigFloat(JSContext *ctx, bf_t *buf, JSValueConst val);\nstatic JSValue JS_ToBigDecimalFree(JSContext *ctx, JSValue val,\n                                   BOOL allow_null_or_undefined);\nstatic bfdec_t *JS_ToBigDecimal(JSContext *ctx, JSValueConst val);\n#endif\nJSValue JS_ThrowOutOfMemory(JSContext *ctx);\nstatic JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx);\nstatic JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj);\nstatic int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,\n                                   JSValueConst proto_val, BOOL throw_flag);\nstatic int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj);\nstatic int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj);\nstatic int js_proxy_isArray(JSContext *ctx, JSValueConst obj);\nstatic int JS_CreateProperty(JSContext *ctx, JSObject *p,\n                             JSAtom prop, JSValueConst val,\n                             JSValueConst getter, JSValueConst setter,\n                             int flags);\nstatic int js_string_memcmp(const JSString *p1, const JSString *p2, int len);\nstatic void reset_weak_ref(JSRuntime *rt, JSObject *p);\nstatic JSValue js_array_buffer_constructor3(JSContext *ctx,\n                                            JSValueConst new_target,\n                                            uint64_t len, JSClassID class_id,\n                                            uint8_t *buf,\n                                            JSFreeArrayBufferDataFunc *free_func,\n                                            void *opaque, BOOL alloc_flag);\nstatic JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj);\nstatic JSValue js_typed_array_constructor(JSContext *ctx,\n                                          JSValueConst this_val,\n                                          int argc, JSValueConst *argv,\n                                          int classid);\nstatic BOOL typed_array_is_detached(JSContext *ctx, JSObject *p);\nstatic uint32_t typed_array_get_length(JSContext *ctx, JSObject *p);\nstatic JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx);\nstatic JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf, int var_idx,\n                             BOOL is_arg);\nstatic JSValue js_generator_function_call(JSContext *ctx, JSValueConst func_obj,\n                                          JSValueConst this_obj,\n                                          int argc, JSValueConst *argv,\n                                          int flags);\nstatic void js_async_function_resolve_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_async_function_resolve_mark(JSRuntime *rt, JSValueConst val,\n                                           JS_MarkFunc *mark_func);\nstatic JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,\n                               const char *input, size_t input_len,\n                               const char *filename, int flags, int scope_idx);\nstatic void js_free_module_def(JSContext *ctx, JSModuleDef *m);\nstatic void js_mark_module_def(JSRuntime *rt, JSModuleDef *m,\n                               JS_MarkFunc *mark_func);\nstatic JSValue js_import_meta(JSContext *ctx);\nstatic JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier);\nstatic void free_var_ref(JSRuntime *rt, JSVarRef *var_ref);\nstatic JSValue js_new_promise_capability(JSContext *ctx,\n                                         JSValue *resolving_funcs,\n                                         JSValueConst ctor);\nstatic __exception int perform_promise_then(JSContext *ctx,\n                                            JSValueConst promise,\n                                            JSValueConst *resolve_reject,\n                                            JSValueConst *cap_resolving_funcs);\nstatic JSValue js_promise_resolve(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv, int magic);\nstatic int js_string_compare(JSContext *ctx,\n                             const JSString *p1, const JSString *p2);\nstatic JSValue JS_ToNumber(JSContext *ctx, JSValueConst val);\nstatic int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,\n                               JSValue prop, JSValue val, int flags);\nstatic int JS_NumberIsInteger(JSContext *ctx, JSValueConst val);\nstatic BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst val);\nstatic JSValue JS_ToNumberFree(JSContext *ctx, JSValue val);\nstatic int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc,\n                                     JSObject *p, JSAtom prop);\nstatic void js_free_desc(JSContext *ctx, JSPropertyDescriptor *desc);\nstatic void async_func_mark(JSRuntime *rt, JSAsyncFunctionState *s,\n                            JS_MarkFunc *mark_func);\nstatic void JS_AddIntrinsicBasicObjects(JSContext *ctx);\nstatic void js_free_shape(JSRuntime *rt, JSShape *sh);\nstatic void js_free_shape_null(JSRuntime *rt, JSShape *sh);\nstatic int js_shape_prepare_update(JSContext *ctx, JSObject *p,\n                                   JSShapeProperty **pprs);\nstatic int init_shape_hash(JSRuntime *rt);\nstatic __exception int js_get_length32(JSContext *ctx, uint32_t *pres,\n                                       JSValueConst obj);\nstatic __exception int js_get_length64(JSContext *ctx, int64_t *pres,\n                                       JSValueConst obj);\nstatic void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len);\nstatic JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,\n                               JSValueConst array_arg);\nstatic BOOL js_get_fast_array(JSContext *ctx, JSValueConst obj,\n                              JSValue **arrpp, uint32_t *countp);\nstatic JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx,\n                                              JSValueConst sync_iter);\nstatic void js_c_function_data_finalizer(JSRuntime *rt, JSValue val);\nstatic void js_c_function_data_mark(JSRuntime *rt, JSValueConst val,\n                                    JS_MarkFunc *mark_func);\nstatic JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func_obj,\n                                       JSValueConst this_val,\n                                       int argc, JSValueConst *argv, int flags);\nstatic JSAtom js_symbol_to_atom(JSContext *ctx, JSValue val);\nstatic void add_gc_object(JSRuntime *rt, JSGCObjectHeader *h,\n                          JSGCObjectTypeEnum type);\nstatic void remove_gc_object(JSGCObjectHeader *h);\nstatic void js_async_function_free0(JSRuntime *rt, JSAsyncFunctionData *s);\nstatic int js_instantiate_prototype(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque);\nstatic int js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,\n                                 void *opaque);\nstatic int JS_InstantiateFunctionListItem(JSContext *ctx, JSObject *p,\n                                          JSAtom atom, void *opaque);\nvoid JS_SetUncatchableError(JSContext *ctx, JSValueConst val, BOOL flag);\n\nstatic const JSClassExoticMethods js_arguments_exotic_methods;\nstatic const JSClassExoticMethods js_string_exotic_methods;\nstatic const JSClassExoticMethods js_proxy_exotic_methods;\nstatic const JSClassExoticMethods js_module_ns_exotic_methods;\nstatic JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT;\n\nstatic void js_trigger_gc(JSRuntime *rt, size_t size)\n{\n    BOOL force_gc;\n#ifdef FORCE_GC_AT_MALLOC\n    force_gc = TRUE;\n#else\n    force_gc = ((rt->malloc_state.malloc_size + size) >\n                rt->malloc_gc_threshold);\n#endif\n    if (force_gc) {\n#ifdef DUMP_GC\n        printf(\"GC: size=%\" PRIu64 \"\\n\",\n               (uint64_t)rt->malloc_state.malloc_size);\n#endif\n        JS_RunGC(rt);\n        rt->malloc_gc_threshold = rt->malloc_state.malloc_size +\n            (rt->malloc_state.malloc_size >> 1);\n    }\n}\n\nstatic size_t js_malloc_usable_size_unknown(const void *ptr)\n{\n    return 0;\n}\n\nvoid *js_malloc_rt(JSRuntime *rt, size_t size)\n{\n    return rt->mf.js_malloc(&rt->malloc_state, size);\n}\n\nvoid js_free_rt(JSRuntime *rt, void *ptr)\n{\n    rt->mf.js_free(&rt->malloc_state, ptr);\n}\n\nvoid *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size)\n{\n    return rt->mf.js_realloc(&rt->malloc_state, ptr, size);\n}\n\nsize_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr)\n{\n    return rt->mf.js_malloc_usable_size(ptr);\n}\n\nvoid *js_mallocz_rt(JSRuntime *rt, size_t size)\n{\n    void *ptr;\n    ptr = js_malloc_rt(rt, size);\n    if (!ptr)\n        return NULL;\n    return memset(ptr, 0, size);\n}\n\n#ifdef CONFIG_BIGNUM\n/* called by libbf */\nstatic void *js_bf_realloc(void *opaque, void *ptr, size_t size)\n{\n    JSRuntime *rt = opaque;\n    return js_realloc_rt(rt, ptr, size);\n}\n#endif /* CONFIG_BIGNUM */\n\n/* Throw out of memory in case of error */\nvoid *js_malloc(JSContext *ctx, size_t size)\n{\n    void *ptr;\n    ptr = js_malloc_rt(ctx->rt, size);\n    if (unlikely(!ptr)) {\n        JS_ThrowOutOfMemory(ctx);\n        return NULL;\n    }\n    return ptr;\n}\n\n/* Throw out of memory in case of error */\nvoid *js_mallocz(JSContext *ctx, size_t size)\n{\n    void *ptr;\n    ptr = js_mallocz_rt(ctx->rt, size);\n    if (unlikely(!ptr)) {\n        JS_ThrowOutOfMemory(ctx);\n        return NULL;\n    }\n    return ptr;\n}\n\nvoid js_free(JSContext *ctx, void *ptr)\n{\n    js_free_rt(ctx->rt, ptr);\n}\n\n/* Throw out of memory in case of error */\nvoid *js_realloc(JSContext *ctx, void *ptr, size_t size)\n{\n    void *ret;\n    ret = js_realloc_rt(ctx->rt, ptr, size);\n    if (unlikely(!ret && size != 0)) {\n        JS_ThrowOutOfMemory(ctx);\n        return NULL;\n    }\n    return ret;\n}\n\n/* store extra allocated size in *pslack if successful */\nvoid *js_realloc2(JSContext *ctx, void *ptr, size_t size, size_t *pslack)\n{\n    void *ret;\n    ret = js_realloc_rt(ctx->rt, ptr, size);\n    if (unlikely(!ret && size != 0)) {\n        JS_ThrowOutOfMemory(ctx);\n        return NULL;\n    }\n    if (pslack) {\n        size_t new_size = js_malloc_usable_size_rt(ctx->rt, ret);\n        *pslack = (new_size > size) ? new_size - size : 0;\n    }\n    return ret;\n}\n\nsize_t js_malloc_usable_size(JSContext *ctx, const void *ptr)\n{\n    return js_malloc_usable_size_rt(ctx->rt, ptr);\n}\n\n/* Throw out of memory exception in case of error */\nchar *js_strndup(JSContext *ctx, const char *s, size_t n)\n{\n    char *ptr;\n    ptr = js_malloc(ctx, n + 1);\n    if (ptr) {\n        memcpy(ptr, s, n);\n        ptr[n] = '\\0';\n    }\n    return ptr;\n}\n\nchar *js_strdup(JSContext *ctx, const char *str)\n{\n    return js_strndup(ctx, str, strlen(str));\n}\n\nstatic no_inline int js_realloc_array(JSContext *ctx, void **parray,\n                                      int elem_size, int *psize, int req_size)\n{\n    int new_size;\n    size_t slack;\n    void *new_array;\n    /* XXX: potential arithmetic overflow */\n    new_size = max_int(req_size, *psize * 3 / 2);\n    new_array = js_realloc2(ctx, *parray, new_size * elem_size, &slack);\n    if (!new_array)\n        return -1;\n    new_size += slack / elem_size;\n    *psize = new_size;\n    *parray = new_array;\n    return 0;\n}\n\n/* resize the array and update its size if req_size > *psize */\nstatic inline int js_resize_array(JSContext *ctx, void **parray, int elem_size,\n                                  int *psize, int req_size)\n{\n    if (unlikely(req_size > *psize))\n        return js_realloc_array(ctx, parray, elem_size, psize, req_size);\n    else\n        return 0;\n}\n\nstatic inline void js_dbuf_init(JSContext *ctx, DynBuf *s)\n{\n    dbuf_init2(s, ctx->rt, (DynBufReallocFunc *)js_realloc_rt);\n}\n\nstatic inline int is_digit(int c) {\n    return c >= '0' && c <= '9';\n}\n\ntypedef struct JSClassShortDef {\n    JSAtom class_name;\n    JSClassFinalizer *finalizer;\n    JSClassGCMark *gc_mark;\n} JSClassShortDef;\n\nstatic JSClassShortDef const js_std_class_def[] = {\n    { JS_ATOM_Object, NULL, NULL },                             /* JS_CLASS_OBJECT */\n    { JS_ATOM_Array, js_array_finalizer, js_array_mark },       /* JS_CLASS_ARRAY */\n    { JS_ATOM_Error, NULL, NULL }, /* JS_CLASS_ERROR */\n    { JS_ATOM_Number, js_object_data_finalizer, js_object_data_mark }, /* JS_CLASS_NUMBER */\n    { JS_ATOM_String, js_object_data_finalizer, js_object_data_mark }, /* JS_CLASS_STRING */\n    { JS_ATOM_Boolean, js_object_data_finalizer, js_object_data_mark }, /* JS_CLASS_BOOLEAN */\n    { JS_ATOM_Symbol, js_object_data_finalizer, js_object_data_mark }, /* JS_CLASS_SYMBOL */\n    { JS_ATOM_Arguments, js_array_finalizer, js_array_mark },   /* JS_CLASS_ARGUMENTS */\n    { JS_ATOM_Arguments, NULL, NULL },                          /* JS_CLASS_MAPPED_ARGUMENTS */\n    { JS_ATOM_Date, js_object_data_finalizer, js_object_data_mark }, /* JS_CLASS_DATE */\n    { JS_ATOM_Object, NULL, NULL },                             /* JS_CLASS_MODULE_NS */\n    { JS_ATOM_Function, js_c_function_finalizer, js_c_function_mark }, /* JS_CLASS_C_FUNCTION */\n    { JS_ATOM_Function, js_bytecode_function_finalizer, js_bytecode_function_mark }, /* JS_CLASS_BYTECODE_FUNCTION */\n    { JS_ATOM_Function, js_bound_function_finalizer, js_bound_function_mark }, /* JS_CLASS_BOUND_FUNCTION */\n    { JS_ATOM_Function, js_c_function_data_finalizer, js_c_function_data_mark }, /* JS_CLASS_C_FUNCTION_DATA */\n    { JS_ATOM_GeneratorFunction, js_bytecode_function_finalizer, js_bytecode_function_mark },  /* JS_CLASS_GENERATOR_FUNCTION */\n    { JS_ATOM_ForInIterator, js_for_in_iterator_finalizer, js_for_in_iterator_mark },      /* JS_CLASS_FOR_IN_ITERATOR */\n    { JS_ATOM_RegExp, js_regexp_finalizer, NULL },                              /* JS_CLASS_REGEXP */\n    { JS_ATOM_ArrayBuffer, js_array_buffer_finalizer, NULL },                   /* JS_CLASS_ARRAY_BUFFER */\n    { JS_ATOM_SharedArrayBuffer, js_array_buffer_finalizer, NULL },             /* JS_CLASS_SHARED_ARRAY_BUFFER */\n    { JS_ATOM_Uint8ClampedArray, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_UINT8C_ARRAY */\n    { JS_ATOM_Int8Array, js_typed_array_finalizer, js_typed_array_mark },       /* JS_CLASS_INT8_ARRAY */\n    { JS_ATOM_Uint8Array, js_typed_array_finalizer, js_typed_array_mark },      /* JS_CLASS_UINT8_ARRAY */\n    { JS_ATOM_Int16Array, js_typed_array_finalizer, js_typed_array_mark },      /* JS_CLASS_INT16_ARRAY */\n    { JS_ATOM_Uint16Array, js_typed_array_finalizer, js_typed_array_mark },     /* JS_CLASS_UINT16_ARRAY */\n    { JS_ATOM_Int32Array, js_typed_array_finalizer, js_typed_array_mark },      /* JS_CLASS_INT32_ARRAY */\n    { JS_ATOM_Uint32Array, js_typed_array_finalizer, js_typed_array_mark },     /* JS_CLASS_UINT32_ARRAY */\n#ifdef CONFIG_BIGNUM\n    { JS_ATOM_BigInt64Array, js_typed_array_finalizer, js_typed_array_mark },   /* JS_CLASS_BIG_INT64_ARRAY */\n    { JS_ATOM_BigUint64Array, js_typed_array_finalizer, js_typed_array_mark },  /* JS_CLASS_BIG_UINT64_ARRAY */\n#endif\n    { JS_ATOM_Float32Array, js_typed_array_finalizer, js_typed_array_mark },    /* JS_CLASS_FLOAT32_ARRAY */\n    { JS_ATOM_Float64Array, js_typed_array_finalizer, js_typed_array_mark },    /* JS_CLASS_FLOAT64_ARRAY */\n    { JS_ATOM_DataView, js_typed_array_finalizer, js_typed_array_mark },        /* JS_CLASS_DATAVIEW */\n#ifdef CONFIG_BIGNUM\n    { JS_ATOM_BigInt, js_object_data_finalizer, js_object_data_mark },      /* JS_CLASS_BIG_INT */\n    { JS_ATOM_BigFloat, js_object_data_finalizer, js_object_data_mark },    /* JS_CLASS_BIG_FLOAT */\n    { JS_ATOM_BigFloatEnv, js_float_env_finalizer, NULL },      /* JS_CLASS_FLOAT_ENV */\n    { JS_ATOM_BigDecimal, js_object_data_finalizer, js_object_data_mark },    /* JS_CLASS_BIG_DECIMAL */\n    { JS_ATOM_OperatorSet, js_operator_set_finalizer, js_operator_set_mark },    /* JS_CLASS_OPERATOR_SET */\n#endif\n    { JS_ATOM_Map, js_map_finalizer, js_map_mark },             /* JS_CLASS_MAP */\n    { JS_ATOM_Set, js_map_finalizer, js_map_mark },             /* JS_CLASS_SET */\n    { JS_ATOM_WeakMap, js_map_finalizer, js_map_mark },         /* JS_CLASS_WEAKMAP */\n    { JS_ATOM_WeakSet, js_map_finalizer, js_map_mark },         /* JS_CLASS_WEAKSET */\n    { JS_ATOM_Map_Iterator, js_map_iterator_finalizer, js_map_iterator_mark }, /* JS_CLASS_MAP_ITERATOR */\n    { JS_ATOM_Set_Iterator, js_map_iterator_finalizer, js_map_iterator_mark }, /* JS_CLASS_SET_ITERATOR */\n    { JS_ATOM_Array_Iterator, js_array_iterator_finalizer, js_array_iterator_mark }, /* JS_CLASS_ARRAY_ITERATOR */\n    { JS_ATOM_String_Iterator, js_array_iterator_finalizer, js_array_iterator_mark }, /* JS_CLASS_STRING_ITERATOR */\n    { JS_ATOM_RegExp_String_Iterator, js_regexp_string_iterator_finalizer, js_regexp_string_iterator_mark }, /* JS_CLASS_REGEXP_STRING_ITERATOR */\n    { JS_ATOM_Generator, js_generator_finalizer, js_generator_mark }, /* JS_CLASS_GENERATOR */\n};\n\nstatic int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,\n                            int start, int count)\n{\n    JSClassDef cm_s, *cm = &cm_s;\n    int i, class_id;\n\n    for(i = 0; i < count; i++) {\n        class_id = i + start;\n        memset(cm, 0, sizeof(*cm));\n        cm->finalizer = tab[i].finalizer;\n        cm->gc_mark = tab[i].gc_mark;\n        if (JS_NewClass1(rt, class_id, cm, tab[i].class_name) < 0)\n            return -1;\n    }\n    return 0;\n}\n\n#ifdef CONFIG_BIGNUM\nstatic JSValue JS_ThrowUnsupportedOperation(JSContext *ctx)\n{\n    return JS_ThrowTypeError(ctx, \"unsupported operation\");\n}\n\nstatic JSValue invalid_to_string(JSContext *ctx, JSValueConst val)\n{\n    return JS_ThrowUnsupportedOperation(ctx);\n}\n\nstatic JSValue invalid_from_string(JSContext *ctx, const char *buf,\n                                   int radix, int flags, slimb_t *pexponent)\n{\n    return JS_NAN;\n}\n\nstatic int invalid_unary_arith(JSContext *ctx,\n                               JSValue *pres, OPCodeEnum op, JSValue op1)\n{\n    JS_FreeValue(ctx, op1);\n    JS_ThrowUnsupportedOperation(ctx);\n    return -1;\n}\n\nstatic int invalid_binary_arith(JSContext *ctx, OPCodeEnum op,\n                                JSValue *pres, JSValue op1, JSValue op2)\n{\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    JS_ThrowUnsupportedOperation(ctx);\n    return -1;\n}\n\nstatic JSValue invalid_mul_pow10_to_float64(JSContext *ctx, const bf_t *a,\n                                            int64_t exponent)\n{\n    return JS_ThrowUnsupportedOperation(ctx);\n}\n\nstatic int invalid_mul_pow10(JSContext *ctx, JSValue *sp)\n{\n    JS_ThrowUnsupportedOperation(ctx);\n    return -1;\n}\n\nstatic void set_dummy_numeric_ops(JSNumericOperations *ops)\n{\n    ops->to_string = invalid_to_string;\n    ops->from_string = invalid_from_string;\n    ops->unary_arith = invalid_unary_arith;\n    ops->binary_arith = invalid_binary_arith;\n    ops->mul_pow10_to_float64 = invalid_mul_pow10_to_float64;\n    ops->mul_pow10 = invalid_mul_pow10;\n}\n\n#endif /* CONFIG_BIGNUM */\n\n#if !defined(CONFIG_STACK_CHECK)\n/* no stack limitation */\nstatic inline uint8_t *js_get_stack_pointer(void)\n{\n    return NULL;\n}\n\nstatic inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)\n{\n    return FALSE;\n}\n#else\n/* Note: OS and CPU dependent */\nstatic inline uint8_t *js_get_stack_pointer(void)\n{\n    return __builtin_frame_address(0);\n}\n\nstatic inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_size)\n{\n    size_t size;\n    size = rt->stack_top - js_get_stack_pointer();\n    return unlikely((size + alloca_size) > rt->stack_size);\n}\n#endif\n\nJSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)\n{\n    JSRuntime *rt;\n    JSMallocState ms;\n\n    memset(&ms, 0, sizeof(ms));\n    ms.opaque = opaque;\n    ms.malloc_limit = -1;\n\n    rt = mf->js_malloc(&ms, sizeof(JSRuntime));\n    if (!rt)\n        return NULL;\n    memset(rt, 0, sizeof(*rt));\n    rt->mf = *mf;\n    if (!rt->mf.js_malloc_usable_size) {\n        /* use dummy function if none provided */\n        rt->mf.js_malloc_usable_size = js_malloc_usable_size_unknown;\n    }\n    rt->malloc_state = ms;\n    rt->malloc_gc_threshold = 256 * 1024;\n\n#ifdef CONFIG_BIGNUM\n    bf_context_init(&rt->bf_ctx, js_bf_realloc, rt);\n    set_dummy_numeric_ops(&rt->bigint_ops);\n    set_dummy_numeric_ops(&rt->bigfloat_ops);\n    set_dummy_numeric_ops(&rt->bigdecimal_ops);\n#endif\n\n    init_list_head(&rt->context_list);\n    init_list_head(&rt->gc_obj_list);\n    init_list_head(&rt->gc_zero_ref_count_list);\n    rt->gc_phase = JS_GC_PHASE_NONE;\n    \n#ifdef DUMP_LEAKS\n    init_list_head(&rt->string_list);\n#endif\n    init_list_head(&rt->job_list);\n\n    if (JS_InitAtoms(rt))\n        goto fail;\n\n    /* create the object, array and function classes */\n    if (init_class_range(rt, js_std_class_def, JS_CLASS_OBJECT,\n                         countof(js_std_class_def)) < 0)\n        goto fail;\n    rt->class_array[JS_CLASS_ARGUMENTS].exotic = &js_arguments_exotic_methods;\n    rt->class_array[JS_CLASS_STRING].exotic = &js_string_exotic_methods;\n    rt->class_array[JS_CLASS_MODULE_NS].exotic = &js_module_ns_exotic_methods;\n\n    rt->class_array[JS_CLASS_C_FUNCTION].call = js_call_c_function;\n    rt->class_array[JS_CLASS_C_FUNCTION_DATA].call = js_c_function_data_call;\n    rt->class_array[JS_CLASS_BOUND_FUNCTION].call = js_call_bound_function;\n    rt->class_array[JS_CLASS_GENERATOR_FUNCTION].call = js_generator_function_call;\n    if (init_shape_hash(rt))\n        goto fail;\n\n    rt->stack_top = js_get_stack_pointer();\n    rt->stack_size = JS_DEFAULT_STACK_SIZE;\n    rt->current_exception = JS_NULL;\n\n    return rt;\n fail:\n    JS_FreeRuntime(rt);\n    return NULL;\n}\n\nvoid *JS_GetRuntimeOpaque(JSRuntime *rt)\n{\n    return rt->user_opaque;\n}\n\nvoid JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque)\n{\n    rt->user_opaque = opaque;\n}\n\n/* default memory allocation functions with memory limitation */\nstatic inline size_t js_def_malloc_usable_size(void *ptr)\n{\n#if defined(__APPLE__)\n    return malloc_size(ptr);\n#elif defined(_WIN32)\n    return _msize(ptr);\n#elif defined(EMSCRIPTEN)\n    return 0;\n#elif defined(__linux__)\n    return malloc_usable_size(ptr);\n#else\n    /* change this to `return 0;` if compilation fails */\n    return malloc_usable_size(ptr);\n#endif\n}\n\nstatic void *js_def_malloc(JSMallocState *s, size_t size)\n{\n    void *ptr;\n\n    /* Do not allocate zero bytes: behavior is platform dependent */\n    assert(size != 0);\n\n    if (unlikely(s->malloc_size + size > s->malloc_limit))\n        return NULL;\n\n    ptr = malloc(size);\n    if (!ptr)\n        return NULL;\n\n    s->malloc_count++;\n    s->malloc_size += js_def_malloc_usable_size(ptr) + MALLOC_OVERHEAD;\n    return ptr;\n}\n\nstatic void js_def_free(JSMallocState *s, void *ptr)\n{\n    if (!ptr)\n        return;\n\n    s->malloc_count--;\n    s->malloc_size -= js_def_malloc_usable_size(ptr) + MALLOC_OVERHEAD;\n    free(ptr);\n}\n\nstatic void *js_def_realloc(JSMallocState *s, void *ptr, size_t size)\n{\n    size_t old_size;\n\n    if (!ptr) {\n        if (size == 0)\n            return NULL;\n        return js_def_malloc(s, size);\n    }\n    old_size = js_def_malloc_usable_size(ptr);\n    if (size == 0) {\n        s->malloc_count--;\n        s->malloc_size -= old_size + MALLOC_OVERHEAD;\n        free(ptr);\n        return NULL;\n    }\n    if (s->malloc_size + size - old_size > s->malloc_limit)\n        return NULL;\n\n    ptr = realloc(ptr, size);\n    if (!ptr)\n        return NULL;\n\n    s->malloc_size += js_def_malloc_usable_size(ptr) - old_size;\n    return ptr;\n}\n\nstatic const JSMallocFunctions def_malloc_funcs = {\n    js_def_malloc,\n    js_def_free,\n    js_def_realloc,\n#if defined(__APPLE__)\n    malloc_size,\n#elif defined(_WIN32)\n    (size_t (*)(const void *))_msize,\n#elif defined(EMSCRIPTEN)\n    NULL,\n#elif defined(__linux__)\n    (size_t (*)(const void *))malloc_usable_size,\n#else\n    /* change this to `NULL,` if compilation fails */\n    malloc_usable_size,\n#endif\n};\n\nJSRuntime *JS_NewRuntime(void)\n{\n    return JS_NewRuntime2(&def_malloc_funcs, NULL);\n}\n\nvoid JS_SetMemoryLimit(JSRuntime *rt, size_t limit)\n{\n    rt->malloc_state.malloc_limit = limit;\n}\n\n/* use -1 to disable automatic GC */\nvoid JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold)\n{\n    rt->malloc_gc_threshold = gc_threshold;\n}\n\n#define malloc(s) malloc_is_forbidden(s)\n#define free(p) free_is_forbidden(p)\n#define realloc(p,s) realloc_is_forbidden(p,s)\n\nvoid JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque)\n{\n    rt->interrupt_handler = cb;\n    rt->interrupt_opaque = opaque;\n}\n\nvoid JS_SetCanBlock(JSRuntime *rt, BOOL can_block)\n{\n    rt->can_block = can_block;\n}\n\nvoid JS_SetSharedArrayBufferFunctions(JSRuntime *rt,\n                                      const JSSharedArrayBufferFunctions *sf)\n{\n    rt->sab_funcs = *sf;\n}\n\n/* return 0 if OK, < 0 if exception */\nint JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func,\n                  int argc, JSValueConst *argv)\n{\n    JSRuntime *rt = ctx->rt;\n    JSJobEntry *e;\n    int i;\n\n    e = js_malloc(ctx, sizeof(*e) + argc * sizeof(JSValue));\n    if (!e)\n        return -1;\n    e->ctx = ctx;\n    e->job_func = job_func;\n    e->argc = argc;\n    for(i = 0; i < argc; i++) {\n        e->argv[i] = JS_DupValue(ctx, argv[i]);\n    }\n    list_add_tail(&e->link, &rt->job_list);\n    return 0;\n}\n\nBOOL JS_IsJobPending(JSRuntime *rt)\n{\n    return !list_empty(&rt->job_list);\n}\n\n/* return < 0 if exception, 0 if no job pending, 1 if a job was\n   executed successfully. the context of the job is stored in '*pctx' */\nint JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx)\n{\n    JSContext *ctx;\n    JSJobEntry *e;\n    JSValue res;\n    int i, ret;\n\n    if (list_empty(&rt->job_list)) {\n        *pctx = NULL;\n        return 0;\n    }\n\n    /* get the first pending job and execute it */\n    e = list_entry(rt->job_list.next, JSJobEntry, link);\n    list_del(&e->link);\n    ctx = e->ctx;\n    res = e->job_func(e->ctx, e->argc, (JSValueConst *)e->argv);\n    for(i = 0; i < e->argc; i++)\n        JS_FreeValue(ctx, e->argv[i]);\n    if (JS_IsException(res))\n        ret = -1;\n    else\n        ret = 1;\n    JS_FreeValue(ctx, res);\n    js_free(ctx, e);\n    *pctx = ctx;\n    return ret;\n}\n\nstatic inline uint32_t atom_get_free(const JSAtomStruct *p)\n{\n    return (uintptr_t)p >> 1;\n}\n\nstatic inline BOOL atom_is_free(const JSAtomStruct *p)\n{\n    return (uintptr_t)p & 1;\n}\n\nstatic inline JSAtomStruct *atom_set_free(uint32_t v)\n{\n    return (JSAtomStruct *)(((uintptr_t)v << 1) | 1);\n}\n\n/* Note: the string contents are uninitialized */\nstatic JSString *js_alloc_string_rt(JSRuntime *rt, int max_len, int is_wide_char)\n{\n    JSString *str;\n    str = js_malloc_rt(rt, sizeof(JSString) + (max_len << is_wide_char) + 1 - is_wide_char);\n    if (unlikely(!str))\n        return NULL;\n    str->header.ref_count = 1;\n    str->is_wide_char = is_wide_char;\n    str->len = max_len;\n    str->atom_type = 0;\n    str->hash = 0;          /* optional but costless */\n    str->hash_next = 0;     /* optional */\n#ifdef DUMP_LEAKS\n    list_add_tail(&str->link, &rt->string_list);\n#endif\n    return str;\n}\n\nstatic JSString *js_alloc_string(JSContext *ctx, int max_len, int is_wide_char)\n{\n    JSString *p;\n    p = js_alloc_string_rt(ctx->rt, max_len, is_wide_char);\n    if (unlikely(!p)) {\n        JS_ThrowOutOfMemory(ctx);\n        return NULL;\n    }\n    return p;\n}\n\n/* same as JS_FreeValueRT() but faster */\nstatic inline void js_free_string(JSRuntime *rt, JSString *str)\n{\n    if (--str->header.ref_count <= 0) {\n        if (str->atom_type) {\n            JS_FreeAtomStruct(rt, str);\n        } else {\n#ifdef DUMP_LEAKS\n            list_del(&str->link);\n#endif\n            js_free_rt(rt, str);\n        }\n    }\n}\n\nvoid JS_SetRuntimeInfo(JSRuntime *rt, const char *s)\n{\n    if (rt)\n        rt->rt_info = s;\n}\n\nvoid JS_FreeRuntime(JSRuntime *rt)\n{\n    struct list_head *el, *el1;\n    int i;\n\n    JS_FreeValueRT(rt, rt->current_exception);\n\n    list_for_each_safe(el, el1, &rt->job_list) {\n        JSJobEntry *e = list_entry(el, JSJobEntry, link);\n        for(i = 0; i < e->argc; i++)\n            JS_FreeValueRT(rt, e->argv[i]);\n        js_free_rt(rt, e);\n    }\n    init_list_head(&rt->job_list);\n\n    JS_RunGC(rt);\n\n#ifdef DUMP_LEAKS\n    /* leaking objects */\n    {\n        BOOL header_done;\n        JSGCObjectHeader *p;\n        int count;\n\n        /* remove the internal refcounts to display only the object\n           referenced externally */\n        list_for_each(el, &rt->gc_obj_list) {\n            p = list_entry(el, JSGCObjectHeader, link);\n            p->mark = 0;\n        }\n        gc_decref(rt);\n\n        header_done = FALSE;\n        list_for_each(el, &rt->gc_obj_list) {\n            p = list_entry(el, JSGCObjectHeader, link);\n            if (p->ref_count != 0) {\n                if (!header_done) {\n                    printf(\"Object leaks:\\n\");\n                    JS_DumpObjectHeader(rt);\n                    header_done = TRUE;\n                }\n                JS_DumpGCObject(rt, p);\n            }\n        }\n\n        count = 0;\n        list_for_each(el, &rt->gc_obj_list) {\n            p = list_entry(el, JSGCObjectHeader, link);\n            if (p->ref_count == 0) {\n                count++;\n            }\n        }\n        if (count != 0)\n            printf(\"Secondary object leaks: %d\\n\", count);\n    }\n#endif\n    assert(list_empty(&rt->gc_obj_list));\n\n    /* free the classes */\n    for(i = 0; i < rt->class_count; i++) {\n        JSClass *cl = &rt->class_array[i];\n        if (cl->class_id != 0) {\n            JS_FreeAtomRT(rt, cl->class_name);\n        }\n    }\n    js_free_rt(rt, rt->class_array);\n\n#ifdef CONFIG_BIGNUM\n    bf_context_end(&rt->bf_ctx);\n#endif\n\n#ifdef DUMP_LEAKS\n    /* only the atoms defined in JS_InitAtoms() should be left */\n    {\n        BOOL header_done = FALSE;\n\n        for(i = 0; i < rt->atom_size; i++) {\n            JSAtomStruct *p = rt->atom_array[i];\n            if (!atom_is_free(p) /* && p->str*/) {\n                if (i >= JS_ATOM_END || p->header.ref_count != 1) {\n                    if (!header_done) {\n                        header_done = TRUE;\n                        if (rt->rt_info) {\n                            printf(\"%s:1: atom leakage:\", rt->rt_info);\n                        } else {\n                            printf(\"Atom leaks:\\n\"\n                                   \"    %6s %6s %s\\n\",\n                                   \"ID\", \"REFCNT\", \"NAME\");\n                        }\n                    }\n                    if (rt->rt_info) {\n                        printf(\" \");\n                    } else {\n                        printf(\"    %6u %6u \", i, p->header.ref_count);\n                    }\n                    switch (p->atom_type) {\n                    case JS_ATOM_TYPE_STRING:\n                        JS_DumpString(rt, p);\n                        break;\n                    case JS_ATOM_TYPE_GLOBAL_SYMBOL:\n                        printf(\"Symbol.for(\");\n                        JS_DumpString(rt, p);\n                        printf(\")\");\n                        break;\n                    case JS_ATOM_TYPE_SYMBOL:\n                        if (p->hash == JS_ATOM_HASH_SYMBOL) {\n                            printf(\"Symbol(\");\n                            JS_DumpString(rt, p);\n                            printf(\")\");\n                        } else {\n                            printf(\"Private(\");\n                            JS_DumpString(rt, p);\n                            printf(\")\");\n                        }\n                        break;\n                    }\n                    if (rt->rt_info) {\n                        printf(\":%u\", p->header.ref_count);\n                    } else {\n                        printf(\"\\n\");\n                    }\n                }\n            }\n        }\n        if (rt->rt_info && header_done)\n            printf(\"\\n\");\n    }\n#endif\n\n    /* free the atoms */\n    for(i = 0; i < rt->atom_size; i++) {\n        JSAtomStruct *p = rt->atom_array[i];\n        if (!atom_is_free(p)) {\n#ifdef DUMP_LEAKS\n            list_del(&p->link);\n#endif\n            js_free_rt(rt, p);\n        }\n    }\n    js_free_rt(rt, rt->atom_array);\n    js_free_rt(rt, rt->atom_hash);\n    js_free_rt(rt, rt->shape_hash);\n#ifdef DUMP_LEAKS\n    if (!list_empty(&rt->string_list)) {\n        if (rt->rt_info) {\n            printf(\"%s:1: string leakage:\", rt->rt_info);\n        } else {\n            printf(\"String leaks:\\n\"\n                   \"    %6s %s\\n\",\n                   \"REFCNT\", \"VALUE\");\n        }\n        list_for_each_safe(el, el1, &rt->string_list) {\n            JSString *str = list_entry(el, JSString, link);\n            if (rt->rt_info) {\n                printf(\" \");\n            } else {\n                printf(\"    %6u \", str->header.ref_count);\n            }\n            JS_DumpString(rt, str);\n            if (rt->rt_info) {\n                printf(\":%u\", str->header.ref_count);\n            } else {\n                printf(\"\\n\");\n            }\n            list_del(&str->link);\n            js_free_rt(rt, str);\n        }\n        if (rt->rt_info)\n            printf(\"\\n\");\n    }\n    {\n        JSMallocState *s = &rt->malloc_state;\n        if (s->malloc_count > 1) {\n            if (rt->rt_info)\n                printf(\"%s:1: \", rt->rt_info);\n            printf(\"Memory leak: %\"PRIu64\" bytes lost in %\"PRIu64\" block%s\\n\",\n                   (uint64_t)(s->malloc_size - sizeof(JSRuntime)),\n                   (uint64_t)(s->malloc_count - 1), &\"s\"[s->malloc_count == 2]);\n        }\n    }\n#endif\n\n    {\n        JSMallocState ms = rt->malloc_state;\n        rt->mf.js_free(&ms, rt);\n    }\n}\n\nJSContext *JS_NewContextRaw(JSRuntime *rt)\n{\n    JSContext *ctx;\n    int i;\n\n    ctx = js_mallocz_rt(rt, sizeof(JSContext));\n    if (!ctx)\n        return NULL;\n    ctx->header.ref_count = 1;\n    add_gc_object(rt, &ctx->header, JS_GC_OBJ_TYPE_JS_CONTEXT);\n\n    ctx->class_proto = js_malloc_rt(rt, sizeof(ctx->class_proto[0]) *\n                                    rt->class_count);\n    if (!ctx->class_proto) {\n        js_free_rt(rt, ctx);\n        return NULL;\n    }\n    ctx->rt = rt;\n    list_add_tail(&ctx->link, &rt->context_list);\n#ifdef CONFIG_BIGNUM\n    ctx->bf_ctx = &rt->bf_ctx;\n    ctx->fp_env.prec = 113;\n    ctx->fp_env.flags = bf_set_exp_bits(15) | BF_RNDN | BF_FLAG_SUBNORMAL;\n#endif\n    for(i = 0; i < rt->class_count; i++)\n        ctx->class_proto[i] = JS_NULL;\n    ctx->array_ctor = JS_NULL;\n    ctx->regexp_ctor = JS_NULL;\n    ctx->promise_ctor = JS_NULL;\n    init_list_head(&ctx->loaded_modules);\n\n    JS_AddIntrinsicBasicObjects(ctx);\n    return ctx;\n}\n\nJSContext *JS_NewContext(JSRuntime *rt)\n{\n    JSContext *ctx;\n\n    ctx = JS_NewContextRaw(rt);\n    if (!ctx)\n        return NULL;\n\n    JS_AddIntrinsicBaseObjects(ctx);\n    JS_AddIntrinsicDate(ctx);\n    JS_AddIntrinsicEval(ctx);\n    JS_AddIntrinsicStringNormalize(ctx);\n    JS_AddIntrinsicRegExp(ctx);\n    JS_AddIntrinsicJSON(ctx);\n    JS_AddIntrinsicProxy(ctx);\n    JS_AddIntrinsicMapSet(ctx);\n    JS_AddIntrinsicTypedArrays(ctx);\n    JS_AddIntrinsicPromise(ctx);\n#ifdef CONFIG_BIGNUM\n    JS_AddIntrinsicBigInt(ctx);\n#endif\n    return ctx;\n}\n\nvoid *JS_GetContextOpaque(JSContext *ctx)\n{\n    return ctx->user_opaque;\n}\n\nvoid JS_SetContextOpaque(JSContext *ctx, void *opaque)\n{\n    ctx->user_opaque = opaque;\n}\n\n/* set the new value and free the old value after (freeing the value\n   can reallocate the object data) */\nstatic inline void set_value(JSContext *ctx, JSValue *pval, JSValue new_val)\n{\n    JSValue old_val;\n    old_val = *pval;\n    *pval = new_val;\n    JS_FreeValue(ctx, old_val);\n}\n\nvoid JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj)\n{\n    JSRuntime *rt = ctx->rt;\n    assert(class_id < rt->class_count);\n    set_value(ctx, &ctx->class_proto[class_id], obj);\n}\n\nJSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id)\n{\n    JSRuntime *rt = ctx->rt;\n    assert(class_id < rt->class_count);\n    return JS_DupValue(ctx, ctx->class_proto[class_id]);\n}\n\ntypedef enum JSFreeModuleEnum {\n    JS_FREE_MODULE_ALL,\n    JS_FREE_MODULE_NOT_RESOLVED,\n    JS_FREE_MODULE_NOT_EVALUATED,\n} JSFreeModuleEnum;\n\n/* XXX: would be more efficient with separate module lists */\nstatic void js_free_modules(JSContext *ctx, JSFreeModuleEnum flag)\n{\n    struct list_head *el, *el1;\n    list_for_each_safe(el, el1, &ctx->loaded_modules) {\n        JSModuleDef *m = list_entry(el, JSModuleDef, link);\n        if (flag == JS_FREE_MODULE_ALL ||\n            (flag == JS_FREE_MODULE_NOT_RESOLVED && !m->resolved) ||\n            (flag == JS_FREE_MODULE_NOT_EVALUATED && !m->evaluated)) {\n            js_free_module_def(ctx, m);\n        }\n    }\n}\n\nJSContext *JS_DupContext(JSContext *ctx)\n{\n    ctx->header.ref_count++;\n    return ctx;\n}\n\n/* used by the GC */\nstatic void JS_MarkContext(JSRuntime *rt, JSContext *ctx,\n                           JS_MarkFunc *mark_func)\n{\n    int i;\n    struct list_head *el;\n\n    /* modules are not seen by the GC, so we directly mark the objects\n       referenced by each module */\n    list_for_each(el, &ctx->loaded_modules) {\n        JSModuleDef *m = list_entry(el, JSModuleDef, link);\n        js_mark_module_def(rt, m, mark_func);\n    }\n\n    JS_MarkValue(rt, ctx->global_obj, mark_func);\n    JS_MarkValue(rt, ctx->global_var_obj, mark_func);\n\n    JS_MarkValue(rt, ctx->throw_type_error, mark_func);\n    JS_MarkValue(rt, ctx->eval_obj, mark_func);\n\n    JS_MarkValue(rt, ctx->array_proto_values, mark_func);\n    for(i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {\n        JS_MarkValue(rt, ctx->native_error_proto[i], mark_func);\n    }\n    for(i = 0; i < rt->class_count; i++) {\n        JS_MarkValue(rt, ctx->class_proto[i], mark_func);\n    }\n    JS_MarkValue(rt, ctx->iterator_proto, mark_func);\n    JS_MarkValue(rt, ctx->async_iterator_proto, mark_func);\n    JS_MarkValue(rt, ctx->promise_ctor, mark_func);\n    JS_MarkValue(rt, ctx->array_ctor, mark_func);\n    JS_MarkValue(rt, ctx->regexp_ctor, mark_func);\n    JS_MarkValue(rt, ctx->function_ctor, mark_func);\n    JS_MarkValue(rt, ctx->function_proto, mark_func);\n\n    if (ctx->array_shape)\n        mark_func(rt, &ctx->array_shape->header);\n}\n\nvoid JS_FreeContext(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    int i;\n\n    if (--ctx->header.ref_count > 0)\n        return;\n    assert(ctx->header.ref_count == 0);\n    \n#ifdef DUMP_ATOMS\n    JS_DumpAtoms(ctx->rt);\n#endif\n#ifdef DUMP_SHAPES\n    JS_DumpShapes(ctx->rt);\n#endif\n#ifdef DUMP_OBJECTS\n    {\n        struct list_head *el;\n        JSGCObjectHeader *p;\n        printf(\"JSObjects: {\\n\");\n        JS_DumpObjectHeader(ctx->rt);\n        list_for_each(el, &rt->gc_obj_list) {\n            p = list_entry(el, JSGCObjectHeader, link);\n            JS_DumpGCObject(rt, p);\n        }\n        printf(\"}\\n\");\n    }\n#endif\n#ifdef DUMP_MEM\n    {\n        JSMemoryUsage stats;\n        JS_ComputeMemoryUsage(rt, &stats);\n        JS_DumpMemoryUsage(stdout, &stats, rt);\n    }\n#endif\n\n    js_free_modules(ctx, JS_FREE_MODULE_ALL);\n\n    JS_FreeValue(ctx, ctx->global_obj);\n    JS_FreeValue(ctx, ctx->global_var_obj);\n\n    JS_FreeValue(ctx, ctx->throw_type_error);\n    JS_FreeValue(ctx, ctx->eval_obj);\n\n    JS_FreeValue(ctx, ctx->array_proto_values);\n    for(i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {\n        JS_FreeValue(ctx, ctx->native_error_proto[i]);\n    }\n    for(i = 0; i < rt->class_count; i++) {\n        JS_FreeValue(ctx, ctx->class_proto[i]);\n    }\n    js_free_rt(rt, ctx->class_proto);\n    JS_FreeValue(ctx, ctx->iterator_proto);\n    JS_FreeValue(ctx, ctx->async_iterator_proto);\n    JS_FreeValue(ctx, ctx->promise_ctor);\n    JS_FreeValue(ctx, ctx->array_ctor);\n    JS_FreeValue(ctx, ctx->regexp_ctor);\n    JS_FreeValue(ctx, ctx->function_ctor);\n    JS_FreeValue(ctx, ctx->function_proto);\n\n    js_free_shape_null(ctx->rt, ctx->array_shape);\n\n    list_del(&ctx->link);\n    remove_gc_object(&ctx->header);\n    js_free_rt(ctx->rt, ctx);\n}\n\nJSRuntime *JS_GetRuntime(JSContext *ctx)\n{\n    return ctx->rt;\n}\n\nvoid JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size)\n{\n    rt->stack_size = stack_size;\n}\n\nstatic inline BOOL is_strict_mode(JSContext *ctx)\n{\n    JSStackFrame *sf = ctx->rt->current_stack_frame;\n    return (sf && (sf->js_mode & JS_MODE_STRICT));\n}\n\n#ifdef CONFIG_BIGNUM\nstatic inline BOOL is_math_mode(JSContext *ctx)\n{\n    JSStackFrame *sf = ctx->rt->current_stack_frame;\n    return (sf && (sf->js_mode & JS_MODE_MATH));\n}\n#endif\n\n/* JSAtom support */\n\n#define JS_ATOM_TAG_INT (1U << 31)\n#define JS_ATOM_MAX_INT (JS_ATOM_TAG_INT - 1)\n#define JS_ATOM_MAX     ((1U << 30) - 1)\n\n/* return the max count from the hash size */\n#define JS_ATOM_COUNT_RESIZE(n) ((n) * 2)\n\nstatic inline BOOL __JS_AtomIsConst(JSAtom v)\n{\n#if defined(DUMP_LEAKS) && DUMP_LEAKS > 1\n        return (int32_t)v <= 0;\n#else\n        return (int32_t)v < JS_ATOM_END;\n#endif\n}\n\nstatic inline BOOL __JS_AtomIsTaggedInt(JSAtom v)\n{\n    return (v & JS_ATOM_TAG_INT) != 0;\n}\n\nstatic inline JSAtom __JS_AtomFromUInt32(uint32_t v)\n{\n    return v | JS_ATOM_TAG_INT;\n}\n\nstatic inline uint32_t __JS_AtomToUInt32(JSAtom atom)\n{\n    return atom & ~JS_ATOM_TAG_INT;\n}\n\nstatic inline int is_num(int c)\n{\n    return c >= '0' && c <= '9';\n}\n\n/* return TRUE if the string is a number n with 0 <= n <= 2^32-1 */\nstatic inline BOOL is_num_string(uint32_t *pval, const JSString *p)\n{\n    uint32_t n;\n    uint64_t n64;\n    int c, i, len;\n\n    len = p->len;\n    if (len == 0 || len > 10)\n        return FALSE;\n    if (p->is_wide_char)\n        c = p->u.str16[0];\n    else\n        c = p->u.str8[0];\n    if (is_num(c)) {\n        if (c == '0') {\n            if (len != 1)\n                return FALSE;\n            n = 0;\n        } else {\n            n = c - '0';\n            for(i = 1; i < len; i++) {\n                if (p->is_wide_char)\n                    c = p->u.str16[i];\n                else\n                    c = p->u.str8[i];\n                if (!is_num(c))\n                    return FALSE;\n                n64 = (uint64_t)n * 10 + (c - '0');\n                if ((n64 >> 32) != 0)\n                    return FALSE;\n                n = n64;\n            }\n        }\n        *pval = n;\n        return TRUE;\n    } else {\n        return FALSE;\n    }\n}\n\n/* XXX: could use faster version ? */\nstatic inline uint32_t hash_string8(const uint8_t *str, size_t len, uint32_t h)\n{\n    size_t i;\n\n    for(i = 0; i < len; i++)\n        h = h * 263 + str[i];\n    return h;\n}\n\nstatic inline uint32_t hash_string16(const uint16_t *str,\n                                     size_t len, uint32_t h)\n{\n    size_t i;\n\n    for(i = 0; i < len; i++)\n        h = h * 263 + str[i];\n    return h;\n}\n\nstatic uint32_t hash_string(const JSString *str, uint32_t h)\n{\n    if (str->is_wide_char)\n        h = hash_string16(str->u.str16, str->len, h);\n    else\n        h = hash_string8(str->u.str8, str->len, h);\n    return h;\n}\n\nstatic __maybe_unused void JS_DumpString(JSRuntime *rt,\n                                                  const JSString *p)\n{\n    int i, c, sep;\n\n    if (p == NULL) {\n        printf(\"<null>\");\n        return;\n    }\n    printf(\"%d\", p->header.ref_count);\n    sep = (p->header.ref_count == 1) ? '\\\"' : '\\'';\n    putchar(sep);\n    for(i = 0; i < p->len; i++) {\n        if (p->is_wide_char)\n            c = p->u.str16[i];\n        else\n            c = p->u.str8[i];\n        if (c == sep || c == '\\\\') {\n            putchar('\\\\');\n            putchar(c);\n        } else if (c >= ' ' && c <= 126) {\n            putchar(c);\n        } else if (c == '\\n') {\n            putchar('\\\\');\n            putchar('n');\n        } else {\n            printf(\"\\\\u%04x\", c);\n        }\n    }\n    putchar(sep);\n}\n\nstatic __maybe_unused void JS_DumpAtoms(JSRuntime *rt)\n{\n    JSAtomStruct *p;\n    int h, i;\n    /* This only dumps hashed atoms, not JS_ATOM_TYPE_SYMBOL atoms */\n    printf(\"JSAtom count=%d size=%d hash_size=%d:\\n\",\n           rt->atom_count, rt->atom_size, rt->atom_hash_size);\n    printf(\"JSAtom hash table: {\\n\");\n    for(i = 0; i < rt->atom_hash_size; i++) {\n        h = rt->atom_hash[i];\n        if (h) {\n            printf(\"  %d:\", i);\n            while (h) {\n                p = rt->atom_array[h];\n                printf(\" \");\n                JS_DumpString(rt, p);\n                h = p->hash_next;\n            }\n            printf(\"\\n\");\n        }\n    }\n    printf(\"}\\n\");\n    printf(\"JSAtom table: {\\n\");\n    for(i = 0; i < rt->atom_size; i++) {\n        p = rt->atom_array[i];\n        if (!atom_is_free(p)) {\n            printf(\"  %d: { %d %08x \", i, p->atom_type, p->hash);\n            if (!(p->len == 0 && p->is_wide_char != 0))\n                JS_DumpString(rt, p);\n            printf(\" %d }\\n\", p->hash_next);\n        }\n    }\n    printf(\"}\\n\");\n}\n\nstatic int JS_ResizeAtomHash(JSRuntime *rt, int new_hash_size)\n{\n    JSAtomStruct *p;\n    uint32_t new_hash_mask, h, i, hash_next1, j, *new_hash;\n\n    assert((new_hash_size & (new_hash_size - 1)) == 0); /* power of two */\n    new_hash_mask = new_hash_size - 1;\n    new_hash = js_mallocz_rt(rt, sizeof(rt->atom_hash[0]) * new_hash_size);\n    if (!new_hash)\n        return -1;\n    for(i = 0; i < rt->atom_hash_size; i++) {\n        h = rt->atom_hash[i];\n        while (h != 0) {\n            p = rt->atom_array[h];\n            hash_next1 = p->hash_next;\n            /* add in new hash table */\n            j = p->hash & new_hash_mask;\n            p->hash_next = new_hash[j];\n            new_hash[j] = h;\n            h = hash_next1;\n        }\n    }\n    js_free_rt(rt, rt->atom_hash);\n    rt->atom_hash = new_hash;\n    rt->atom_hash_size = new_hash_size;\n    rt->atom_count_resize = JS_ATOM_COUNT_RESIZE(new_hash_size);\n    //    JS_DumpAtoms(rt);\n    return 0;\n}\n\nstatic int JS_InitAtoms(JSRuntime *rt)\n{\n    int i, len, atom_type;\n    const char *p;\n\n    rt->atom_hash_size = 0;\n    rt->atom_hash = NULL;\n    rt->atom_count = 0;\n    rt->atom_size = 0;\n    rt->atom_free_index = 0;\n    if (JS_ResizeAtomHash(rt, 256))     /* there are at least 195 predefined atoms */\n        return -1;\n\n    p = js_atom_init;\n    for(i = 1; i < JS_ATOM_END; i++) {\n        if (i == JS_ATOM_Private_brand)\n            atom_type = JS_ATOM_TYPE_PRIVATE;\n        else if (i >= JS_ATOM_Symbol_toPrimitive)\n            atom_type = JS_ATOM_TYPE_SYMBOL;\n        else\n            atom_type = JS_ATOM_TYPE_STRING;\n        len = strlen(p);\n        if (__JS_NewAtomInit(rt, p, len, atom_type) == JS_ATOM_NULL)\n            return -1;\n        p = p + len + 1;\n    }\n    return 0;\n}\n\nstatic JSAtom JS_DupAtomRT(JSRuntime *rt, JSAtom v)\n{\n    JSAtomStruct *p;\n\n    if (!__JS_AtomIsConst(v)) {\n        p = rt->atom_array[v];\n        p->header.ref_count++;\n    }\n    return v;\n}\n\nJSAtom JS_DupAtom(JSContext *ctx, JSAtom v)\n{\n    JSRuntime *rt;\n    JSAtomStruct *p;\n\n    if (!__JS_AtomIsConst(v)) {\n        rt = ctx->rt;\n        p = rt->atom_array[v];\n        p->header.ref_count++;\n    }\n    return v;\n}\n\nstatic JSAtomKindEnum JS_AtomGetKind(JSContext *ctx, JSAtom v)\n{\n    JSRuntime *rt;\n    JSAtomStruct *p;\n\n    rt = ctx->rt;\n    if (__JS_AtomIsTaggedInt(v))\n        return JS_ATOM_KIND_STRING;\n    p = rt->atom_array[v];\n    switch(p->atom_type) {\n    case JS_ATOM_TYPE_STRING:\n        return JS_ATOM_KIND_STRING;\n    case JS_ATOM_TYPE_GLOBAL_SYMBOL:\n        return JS_ATOM_KIND_SYMBOL;\n    case JS_ATOM_TYPE_SYMBOL:\n        switch(p->hash) {\n        case JS_ATOM_HASH_SYMBOL:\n            return JS_ATOM_KIND_SYMBOL;\n        case JS_ATOM_HASH_PRIVATE:\n            return JS_ATOM_KIND_PRIVATE;\n        default:\n            abort();\n        }\n    default:\n        abort();\n    }\n}\n\nstatic BOOL JS_AtomIsString(JSContext *ctx, JSAtom v)\n{\n    return JS_AtomGetKind(ctx, v) == JS_ATOM_KIND_STRING;\n}\n\nstatic JSAtom js_get_atom_index(JSRuntime *rt, JSAtomStruct *p)\n{\n    uint32_t i = p->hash_next;  /* atom_index */\n    if (p->atom_type != JS_ATOM_TYPE_SYMBOL) {\n        JSAtomStruct *p1;\n\n        i = rt->atom_hash[p->hash & (rt->atom_hash_size - 1)];\n        p1 = rt->atom_array[i];\n        while (p1 != p) {\n            assert(i != 0);\n            i = p1->hash_next;\n            p1 = rt->atom_array[i];\n        }\n    }\n    return i;\n}\n\n/* string case (internal). Return JS_ATOM_NULL if error. 'str' is\n   freed. */\nstatic JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type)\n{\n    uint32_t h, h1, i;\n    JSAtomStruct *p;\n    int len;\n\n#if 0\n    printf(\"__JS_NewAtom: \");  JS_DumpString(rt, str); printf(\"\\n\");\n#endif\n    if (atom_type < JS_ATOM_TYPE_SYMBOL) {\n        /* str is not NULL */\n        if (str->atom_type == atom_type) {\n            /* str is the atom, return its index */\n            i = js_get_atom_index(rt, str);\n            /* reduce string refcount and increase atom's unless constant */\n            if (__JS_AtomIsConst(i))\n                str->header.ref_count--;\n            return i;\n        }\n        /* try and locate an already registered atom */\n        len = str->len;\n        h = hash_string(str, atom_type);\n        h &= JS_ATOM_HASH_MASK;\n        h1 = h & (rt->atom_hash_size - 1);\n        i = rt->atom_hash[h1];\n        while (i != 0) {\n            p = rt->atom_array[i];\n            if (p->hash == h &&\n                p->atom_type == atom_type &&\n                p->len == len &&\n                js_string_memcmp(p, str, len) == 0) {\n                if (!__JS_AtomIsConst(i))\n                    p->header.ref_count++;\n                goto done;\n            }\n            i = p->hash_next;\n        }\n    } else {\n        h1 = 0; /* avoid warning */\n        if (atom_type == JS_ATOM_TYPE_SYMBOL) {\n            h = JS_ATOM_HASH_SYMBOL;\n        } else {\n            h = JS_ATOM_HASH_PRIVATE;\n            atom_type = JS_ATOM_TYPE_SYMBOL;\n        }\n    }\n\n    if (rt->atom_free_index == 0) {\n        /* allow new atom entries */\n        uint32_t new_size, start;\n        JSAtomStruct **new_array;\n\n        /* alloc new with size progression 3/2:\n           4 6 9 13 19 28 42 63 94 141 211 316 474 711 1066 1599 2398 3597 5395 8092\n           preallocating space for predefined atoms (at least 195).\n         */\n        new_size = max_int(211, rt->atom_size * 3 / 2);\n        if (new_size > JS_ATOM_MAX)\n            goto fail;\n        /* XXX: should use realloc2 to use slack space */\n        new_array = js_realloc_rt(rt, rt->atom_array, sizeof(*new_array) * new_size);\n        if (!new_array)\n            goto fail;\n        /* Note: the atom 0 is not used */\n        start = rt->atom_size;\n        if (start == 0) {\n            /* JS_ATOM_NULL entry */\n            p = js_mallocz_rt(rt, sizeof(JSAtomStruct));\n            if (!p) {\n                js_free_rt(rt, new_array);\n                goto fail;\n            }\n            p->header.ref_count = 1;  /* not refcounted */\n            p->atom_type = JS_ATOM_TYPE_SYMBOL;\n#ifdef DUMP_LEAKS\n            list_add_tail(&p->link, &rt->string_list);\n#endif\n            new_array[0] = p;\n            rt->atom_count++;\n            start = 1;\n        }\n        rt->atom_size = new_size;\n        rt->atom_array = new_array;\n        rt->atom_free_index = start;\n        for(i = start; i < new_size; i++) {\n            uint32_t next;\n            if (i == (new_size - 1))\n                next = 0;\n            else\n                next = i + 1;\n            rt->atom_array[i] = atom_set_free(next);\n        }\n    }\n\n    if (str) {\n        if (str->atom_type == 0) {\n            p = str;\n            p->atom_type = atom_type;\n        } else {\n            p = js_malloc_rt(rt, sizeof(JSString) +\n                             (str->len << str->is_wide_char) +\n                             1 - str->is_wide_char);\n            if (unlikely(!p))\n                goto fail;\n            p->header.ref_count = 1;\n            p->is_wide_char = str->is_wide_char;\n            p->len = str->len;\n#ifdef DUMP_LEAKS\n            list_add_tail(&p->link, &rt->string_list);\n#endif\n            memcpy(p->u.str8, str->u.str8, (str->len << str->is_wide_char) +\n                   1 - str->is_wide_char);\n            js_free_string(rt, str);\n        }\n    } else {\n        p = js_malloc_rt(rt, sizeof(JSAtomStruct)); /* empty wide string */\n        if (!p)\n            return JS_ATOM_NULL;\n        p->header.ref_count = 1;\n        p->is_wide_char = 1;    /* Hack to represent NULL as a JSString */\n        p->len = 0;\n#ifdef DUMP_LEAKS\n        list_add_tail(&p->link, &rt->string_list);\n#endif\n    }\n\n    /* use an already free entry */\n    i = rt->atom_free_index;\n    rt->atom_free_index = atom_get_free(rt->atom_array[i]);\n    rt->atom_array[i] = p;\n\n    p->hash = h;\n    p->hash_next = i;   /* atom_index */\n    p->atom_type = atom_type;\n\n    rt->atom_count++;\n\n    if (atom_type != JS_ATOM_TYPE_SYMBOL) {\n        p->hash_next = rt->atom_hash[h1];\n        rt->atom_hash[h1] = i;\n        if (unlikely(rt->atom_count >= rt->atom_count_resize))\n            JS_ResizeAtomHash(rt, rt->atom_hash_size * 2);\n    }\n\n    //    JS_DumpAtoms(rt);\n    return i;\n\n fail:\n    i = JS_ATOM_NULL;\n done:\n    if (str)\n        js_free_string(rt, str);\n    return i;\n}\n\n/* only works with zero terminated 8 bit strings */\nstatic JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,\n                               int atom_type)\n{\n    JSString *p;\n    p = js_alloc_string_rt(rt, len, 0);\n    if (!p)\n        return JS_ATOM_NULL;\n    memcpy(p->u.str8, str, len);\n    p->u.str8[len] = '\\0';\n    return __JS_NewAtom(rt, p, atom_type);\n}\n\nstatic JSAtom __JS_FindAtom(JSRuntime *rt, const char *str, size_t len,\n                            int atom_type)\n{\n    uint32_t h, h1, i;\n    JSAtomStruct *p;\n\n    h = hash_string8((const uint8_t *)str, len, JS_ATOM_TYPE_STRING);\n    h &= JS_ATOM_HASH_MASK;\n    h1 = h & (rt->atom_hash_size - 1);\n    i = rt->atom_hash[h1];\n    while (i != 0) {\n        p = rt->atom_array[i];\n        if (p->hash == h &&\n            p->atom_type == JS_ATOM_TYPE_STRING &&\n            p->len == len &&\n            p->is_wide_char == 0 &&\n            memcmp(p->u.str8, str, len) == 0) {\n            if (!__JS_AtomIsConst(i))\n                p->header.ref_count++;\n            return i;\n        }\n        i = p->hash_next;\n    }\n    return JS_ATOM_NULL;\n}\n\nstatic void JS_FreeAtomStruct(JSRuntime *rt, JSAtomStruct *p)\n{\n#if 0   /* JS_ATOM_NULL is not refcounted: __JS_AtomIsConst() includes 0 */\n    if (unlikely(i == JS_ATOM_NULL)) {\n        p->header.ref_count = INT32_MAX / 2;\n        return;\n    }\n#endif\n    uint32_t i = p->hash_next;  /* atom_index */\n    if (p->atom_type != JS_ATOM_TYPE_SYMBOL) {\n        JSAtomStruct *p0, *p1;\n        uint32_t h0;\n\n        h0 = p->hash & (rt->atom_hash_size - 1);\n        i = rt->atom_hash[h0];\n        p1 = rt->atom_array[i];\n        if (p1 == p) {\n            rt->atom_hash[h0] = p1->hash_next;\n        } else {\n            for(;;) {\n                assert(i != 0);\n                p0 = p1;\n                i = p1->hash_next;\n                p1 = rt->atom_array[i];\n                if (p1 == p) {\n                    p0->hash_next = p1->hash_next;\n                    break;\n                }\n            }\n        }\n    }\n    /* insert in free atom list */\n    rt->atom_array[i] = atom_set_free(rt->atom_free_index);\n    rt->atom_free_index = i;\n    /* free the string structure */\n#ifdef DUMP_LEAKS\n    list_del(&p->link);\n#endif\n    js_free_rt(rt, p);\n    rt->atom_count--;\n    assert(rt->atom_count >= 0);\n}\n\nstatic void __JS_FreeAtom(JSRuntime *rt, uint32_t i)\n{\n    JSAtomStruct *p;\n\n    p = rt->atom_array[i];\n    if (--p->header.ref_count > 0)\n        return;\n    JS_FreeAtomStruct(rt, p);\n}\n\n/* Warning: 'p' is freed */\nstatic JSAtom JS_NewAtomStr(JSContext *ctx, JSString *p)\n{\n    JSRuntime *rt = ctx->rt;\n    uint32_t n;\n    if (is_num_string(&n, p)) {\n        if (n <= JS_ATOM_MAX_INT) {\n            js_free_string(rt, p);\n            return __JS_AtomFromUInt32(n);\n        }\n    }\n    /* XXX: should generate an exception */\n    return __JS_NewAtom(rt, p, JS_ATOM_TYPE_STRING);\n}\n\nJSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len)\n{\n    JSValue val;\n\n    if (len == 0 || !is_digit(*str)) {\n        JSAtom atom = __JS_FindAtom(ctx->rt, str, len, JS_ATOM_TYPE_STRING);\n        if (atom)\n            return atom;\n    }\n    val = JS_NewStringLen(ctx, str, len);\n    if (JS_IsException(val))\n        return JS_ATOM_NULL;\n    return JS_NewAtomStr(ctx, JS_VALUE_GET_STRING(val));\n}\n\nJSAtom JS_NewAtom(JSContext *ctx, const char *str)\n{\n    return JS_NewAtomLen(ctx, str, strlen(str));\n}\n\nJSAtom JS_NewAtomUInt32(JSContext *ctx, uint32_t n)\n{\n    if (n <= JS_ATOM_MAX_INT) {\n        return __JS_AtomFromUInt32(n);\n    } else {\n        char buf[11];\n        JSValue val;\n        snprintf(buf, sizeof(buf), \"%u\", n);\n        val = JS_NewString(ctx, buf);\n        if (JS_IsException(val))\n            return JS_ATOM_NULL;\n        return __JS_NewAtom(ctx->rt, JS_VALUE_GET_STRING(val),\n                            JS_ATOM_TYPE_STRING);\n    }\n}\n\nstatic JSAtom JS_NewAtomInt64(JSContext *ctx, int64_t n)\n{\n    if ((uint64_t)n <= JS_ATOM_MAX_INT) {\n        return __JS_AtomFromUInt32((uint32_t)n);\n    } else {\n        char buf[24];\n        JSValue val;\n        snprintf(buf, sizeof(buf), \"%\" PRId64 , n);\n        val = JS_NewString(ctx, buf);\n        if (JS_IsException(val))\n            return JS_ATOM_NULL;\n        return __JS_NewAtom(ctx->rt, JS_VALUE_GET_STRING(val),\n                            JS_ATOM_TYPE_STRING);\n    }\n}\n\n/* 'p' is freed */\nstatic JSValue JS_NewSymbol(JSContext *ctx, JSString *p, int atom_type)\n{\n    JSRuntime *rt = ctx->rt;\n    JSAtom atom;\n    atom = __JS_NewAtom(rt, p, atom_type);\n    if (atom == JS_ATOM_NULL)\n        return JS_ThrowOutOfMemory(ctx);\n    return JS_MKPTR(JS_TAG_SYMBOL, rt->atom_array[atom]);\n}\n\n/* descr must be a non-numeric string atom */\nstatic JSValue JS_NewSymbolFromAtom(JSContext *ctx, JSAtom descr,\n                                    int atom_type)\n{\n    JSRuntime *rt = ctx->rt;\n    JSString *p;\n\n    assert(!__JS_AtomIsTaggedInt(descr));\n    assert(descr < rt->atom_size);\n    p = rt->atom_array[descr];\n    JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p));\n    return JS_NewSymbol(ctx, p, atom_type);\n}\n\n#define ATOM_GET_STR_BUF_SIZE 64\n\n/* Should only be used for debug. */\nstatic const char *JS_AtomGetStrRT(JSRuntime *rt, char *buf, int buf_size,\n                                   JSAtom atom)\n{\n    if (__JS_AtomIsTaggedInt(atom)) {\n        snprintf(buf, buf_size, \"%u\", __JS_AtomToUInt32(atom));\n    } else {\n        JSAtomStruct *p;\n        assert(atom < rt->atom_size);\n        if (atom == JS_ATOM_NULL) {\n            snprintf(buf, buf_size, \"<null>\");\n        } else {\n            int i, c;\n            char *q;\n            JSString *str;\n\n            q = buf;\n            p = rt->atom_array[atom];\n            assert(!atom_is_free(p));\n            str = p;\n            if (str) {\n                if (!str->is_wide_char) {\n                    /* special case ASCII strings */\n                    c = 0;\n                    for(i = 0; i < str->len; i++) {\n                        c |= str->u.str8[i];\n                    }\n                    if (c < 0x80)\n                        return (const char *)str->u.str8;\n                }\n                for(i = 0; i < str->len; i++) {\n                    if (str->is_wide_char)\n                        c = str->u.str16[i];\n                    else\n                        c = str->u.str8[i];\n                    if ((q - buf) >= buf_size - UTF8_CHAR_LEN_MAX)\n                        break;\n                    if (c < 128) {\n                        *q++ = c;\n                    } else {\n                        q += unicode_to_utf8((uint8_t *)q, c);\n                    }\n                }\n            }\n            *q = '\\0';\n        }\n    }\n    return buf;\n}\n\nstatic const char *JS_AtomGetStr(JSContext *ctx, char *buf, int buf_size, JSAtom atom)\n{\n    return JS_AtomGetStrRT(ctx->rt, buf, buf_size, atom);\n}\n\nstatic JSValue __JS_AtomToValue(JSContext *ctx, JSAtom atom, BOOL force_string)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n\n    if (__JS_AtomIsTaggedInt(atom)) {\n        snprintf(buf, sizeof(buf), \"%u\", __JS_AtomToUInt32(atom));\n        return JS_NewString(ctx, buf);\n    } else {\n        JSRuntime *rt = ctx->rt;\n        JSAtomStruct *p;\n        assert(atom < rt->atom_size);\n        p = rt->atom_array[atom];\n        if (p->atom_type == JS_ATOM_TYPE_STRING) {\n            goto ret_string;\n        } else if (force_string) {\n            if (p->len == 0 && p->is_wide_char != 0) {\n                /* no description string */\n                p = rt->atom_array[JS_ATOM_empty_string];\n            }\n        ret_string:\n            return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p));\n        } else {\n            return JS_DupValue(ctx, JS_MKPTR(JS_TAG_SYMBOL, p));\n        }\n    }\n}\n\nJSValue JS_AtomToValue(JSContext *ctx, JSAtom atom)\n{\n    return __JS_AtomToValue(ctx, atom, FALSE);\n}\n\nJSValue JS_AtomToString(JSContext *ctx, JSAtom atom)\n{\n    return __JS_AtomToValue(ctx, atom, TRUE);\n}\n\n/* return TRUE if the atom is an array index (i.e. 0 <= index <=\n   2^32-2 and return its value */\nstatic BOOL JS_AtomIsArrayIndex(JSContext *ctx, uint32_t *pval, JSAtom atom)\n{\n    if (__JS_AtomIsTaggedInt(atom)) {\n        *pval = __JS_AtomToUInt32(atom);\n        return TRUE;\n    } else {\n        JSRuntime *rt = ctx->rt;\n        JSAtomStruct *p;\n        uint32_t val;\n\n        assert(atom < rt->atom_size);\n        p = rt->atom_array[atom];\n        if (p->atom_type == JS_ATOM_TYPE_STRING &&\n            is_num_string(&val, p) && val != -1) {\n            *pval = val;\n            return TRUE;\n        } else {\n            *pval = 0;\n            return FALSE;\n        }\n    }\n}\n\n/* This test must be fast if atom is not a numeric index (e.g. a\n   method name). Return JS_UNDEFINED if not a numeric\n   index. JS_EXCEPTION can also be returned. */\nstatic JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)\n{\n    JSRuntime *rt = ctx->rt;\n    JSAtomStruct *p1;\n    JSString *p;\n    int c, len, ret;\n    JSValue num, str;\n\n    if (__JS_AtomIsTaggedInt(atom))\n        return JS_NewInt32(ctx, __JS_AtomToUInt32(atom));\n    assert(atom < rt->atom_size);\n    p1 = rt->atom_array[atom];\n    if (p1->atom_type != JS_ATOM_TYPE_STRING)\n        return JS_UNDEFINED;\n    p = p1;\n    len = p->len;\n    if (p->is_wide_char) {\n        const uint16_t *r = p->u.str16, *r_end = p->u.str16 + len;\n        if (r >= r_end)\n            return JS_UNDEFINED;\n        c = *r;\n        if (c == '-') {\n            if (r >= r_end)\n                return JS_UNDEFINED;\n            r++;\n            c = *r;\n            /* -0 case is specific */\n            if (c == '0' && len == 2)\n                goto minus_zero;\n        }\n        /* XXX: should test NaN, but the tests do not check it */\n        if (!is_num(c)) {\n            /* XXX: String should be normalized, therefore 8-bit only */\n            const uint16_t nfinity16[7] = { 'n', 'f', 'i', 'n', 'i', 't', 'y' };\n            if (!(c =='I' && (r_end - r) == 8 &&\n                  !memcmp(r + 1, nfinity16, sizeof(nfinity16))))\n                return JS_UNDEFINED;\n        }\n    } else {\n        const uint8_t *r = p->u.str8, *r_end = p->u.str8 + len;\n        if (r >= r_end)\n            return JS_UNDEFINED;\n        c = *r;\n        if (c == '-') {\n            if (r >= r_end)\n                return JS_UNDEFINED;\n            r++;\n            c = *r;\n            /* -0 case is specific */\n            if (c == '0' && len == 2) {\n            minus_zero:\n                return __JS_NewFloat64(ctx, -0.0);\n            }\n        }\n        if (!is_num(c)) {\n            if (!(c =='I' && (r_end - r) == 8 &&\n                  !memcmp(r + 1, \"nfinity\", 7)))\n                return JS_UNDEFINED;\n        }\n    }\n    /* XXX: bignum: would be better to only accept integer to avoid\n       relying on current floating point precision */\n    /* this is ECMA CanonicalNumericIndexString primitive */\n    num = JS_ToNumber(ctx, JS_MKPTR(JS_TAG_STRING, p));\n    if (JS_IsException(num))\n        return num;\n    str = JS_ToString(ctx, num);\n    if (JS_IsException(str)) {\n        JS_FreeValue(ctx, num);\n        return str;\n    }\n    ret = js_string_compare(ctx, p, JS_VALUE_GET_STRING(str));\n    JS_FreeValue(ctx, str);\n    if (ret == 0) {\n        return num;\n    } else {\n        JS_FreeValue(ctx, num);\n        return JS_UNDEFINED;\n    }\n}\n\n/* return -1 if exception or TRUE/FALSE */\nstatic int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom)\n{\n    JSValue num;\n    num = JS_AtomIsNumericIndex1(ctx, atom);\n    if (likely(JS_IsUndefined(num)))\n        return FALSE;\n    if (JS_IsException(num))\n        return -1;\n    JS_FreeValue(ctx, num);\n    return TRUE;\n}\n\nvoid JS_FreeAtom(JSContext *ctx, JSAtom v)\n{\n    if (!__JS_AtomIsConst(v))\n        __JS_FreeAtom(ctx->rt, v);\n}\n\nvoid JS_FreeAtomRT(JSRuntime *rt, JSAtom v)\n{\n    if (!__JS_AtomIsConst(v))\n        __JS_FreeAtom(rt, v);\n}\n\n/* return TRUE if 'v' is a symbol with a string description */\nstatic BOOL JS_AtomSymbolHasDescription(JSContext *ctx, JSAtom v)\n{\n    JSRuntime *rt;\n    JSAtomStruct *p;\n\n    rt = ctx->rt;\n    if (__JS_AtomIsTaggedInt(v))\n        return FALSE;\n    p = rt->atom_array[v];\n    return (((p->atom_type == JS_ATOM_TYPE_SYMBOL &&\n              p->hash == JS_ATOM_HASH_SYMBOL) ||\n             p->atom_type == JS_ATOM_TYPE_GLOBAL_SYMBOL) &&\n            !(p->len == 0 && p->is_wide_char != 0));\n}\n\nstatic __maybe_unused void print_atom(JSContext *ctx, JSAtom atom)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n    const char *p;\n    int i;\n\n    /* XXX: should handle embedded null characters */\n    /* XXX: should move encoding code to JS_AtomGetStr */\n    p = JS_AtomGetStr(ctx, buf, sizeof(buf), atom);\n    for (i = 0; p[i]; i++) {\n        int c = (unsigned char)p[i];\n        if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||\n              (c == '_' || c == '$') || (c >= '0' && c <= '9' && i > 0)))\n            break;\n    }\n    if (i > 0 && p[i] == '\\0') {\n        printf(\"%s\", p);\n    } else {\n        putchar('\"');\n        printf(\"%.*s\", i, p);\n        for (; p[i]; i++) {\n            int c = (unsigned char)p[i];\n            if (c == '\\\"' || c == '\\\\') {\n                putchar('\\\\');\n                putchar(c);\n            } else if (c >= ' ' && c <= 126) {\n                putchar(c);\n            } else if (c == '\\n') {\n                putchar('\\\\');\n                putchar('n');\n            } else {\n                printf(\"\\\\u%04x\", c);\n            }\n        }\n        putchar('\\\"');\n    }\n}\n\n/* free with JS_FreeCString() */\nconst char *JS_AtomToCString(JSContext *ctx, JSAtom atom)\n{\n    JSValue str;\n    const char *cstr;\n\n    str = JS_AtomToString(ctx, atom);\n    if (JS_IsException(str))\n        return NULL;\n    cstr = JS_ToCString(ctx, str);\n    JS_FreeValue(ctx, str);\n    return cstr;\n}\n\n/* return a string atom containing name concatenated with str1 */\nstatic JSAtom js_atom_concat_str(JSContext *ctx, JSAtom name, const char *str1)\n{\n    JSValue str;\n    JSAtom atom;\n    const char *cstr;\n    char *cstr2;\n    size_t len, len1;\n    \n    str = JS_AtomToString(ctx, name);\n    if (JS_IsException(str))\n        return JS_ATOM_NULL;\n    cstr = JS_ToCStringLen(ctx, &len, str);\n    if (!cstr)\n        goto fail;\n    len1 = strlen(str1);\n    cstr2 = js_malloc(ctx, len + len1 + 1);\n    if (!cstr2)\n        goto fail;\n    memcpy(cstr2, cstr, len);\n    memcpy(cstr2 + len, str1, len1);\n    cstr2[len + len1] = '\\0';\n    atom = JS_NewAtomLen(ctx, cstr2, len + len1);\n    js_free(ctx, cstr2);\n    JS_FreeCString(ctx, cstr);\n    JS_FreeValue(ctx, str);\n    return atom;\n fail:\n    JS_FreeCString(ctx, cstr);\n    JS_FreeValue(ctx, str);\n    return JS_ATOM_NULL;\n}\n\nstatic JSAtom js_atom_concat_num(JSContext *ctx, JSAtom name, uint32_t n)\n{\n    char buf[16];\n    snprintf(buf, sizeof(buf), \"%u\", n);\n    return js_atom_concat_str(ctx, name, buf);\n}\n\nstatic inline BOOL JS_IsEmptyString(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_STRING && JS_VALUE_GET_STRING(v)->len == 0;\n}\n\n/* JSClass support */\n\n/* a new class ID is allocated if *pclass_id != 0 */\nJSClassID JS_NewClassID(JSClassID *pclass_id)\n{\n    JSClassID class_id;\n    /* XXX: make it thread safe */\n    class_id = *pclass_id;\n    if (class_id == 0) {\n        class_id = js_class_id_alloc++;\n        *pclass_id = class_id;\n    }\n    return class_id;\n}\n\nBOOL JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)\n{\n    return (class_id < rt->class_count &&\n            rt->class_array[class_id].class_id != 0);\n}\n\n/* create a new object internal class. Return -1 if error, 0 if\n   OK. The finalizer can be NULL if none is needed. */\nstatic int JS_NewClass1(JSRuntime *rt, JSClassID class_id,\n                        const JSClassDef *class_def, JSAtom name)\n{\n    int new_size, i;\n    JSClass *cl, *new_class_array;\n    struct list_head *el;\n\n    if (class_id < rt->class_count &&\n        rt->class_array[class_id].class_id != 0)\n        return -1;\n\n    if (class_id >= rt->class_count) {\n        new_size = max_int(JS_CLASS_INIT_COUNT,\n                           max_int(class_id + 1, rt->class_count * 3 / 2));\n\n        /* reallocate the context class prototype array, if any */\n        list_for_each(el, &rt->context_list) {\n            JSContext *ctx = list_entry(el, JSContext, link);\n            JSValue *new_tab;\n            new_tab = js_realloc_rt(rt, ctx->class_proto,\n                                    sizeof(ctx->class_proto[0]) * new_size);\n            if (!new_tab)\n                return -1;\n            for(i = rt->class_count; i < new_size; i++)\n                new_tab[i] = JS_NULL;\n            ctx->class_proto = new_tab;\n        }\n        /* reallocate the class array */\n        new_class_array = js_realloc_rt(rt, rt->class_array,\n                                        sizeof(JSClass) * new_size);\n        if (!new_class_array)\n            return -1;\n        memset(new_class_array + rt->class_count, 0,\n               (new_size - rt->class_count) * sizeof(JSClass));\n        rt->class_array = new_class_array;\n        rt->class_count = new_size;\n    }\n    cl = &rt->class_array[class_id];\n    cl->class_id = class_id;\n    cl->class_name = JS_DupAtomRT(rt, name);\n    cl->finalizer = class_def->finalizer;\n    cl->gc_mark = class_def->gc_mark;\n    cl->call = class_def->call;\n    cl->exotic = class_def->exotic;\n    return 0;\n}\n\nint JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def)\n{\n    int ret, len;\n    JSAtom name;\n\n    len = strlen(class_def->class_name);\n    name = __JS_FindAtom(rt, class_def->class_name, len, JS_ATOM_TYPE_STRING);\n    if (name == JS_ATOM_NULL) {\n        name = __JS_NewAtomInit(rt, class_def->class_name, len, JS_ATOM_TYPE_STRING);\n        if (name == JS_ATOM_NULL)\n            return -1;\n    }\n    ret = JS_NewClass1(rt, class_id, class_def, name);\n    JS_FreeAtomRT(rt, name);\n    return ret;\n}\n\nstatic JSValue js_new_string8(JSContext *ctx, const uint8_t *buf, int len)\n{\n    JSString *str;\n\n    if (len <= 0) {\n        return JS_AtomToString(ctx, JS_ATOM_empty_string);\n    }\n    str = js_alloc_string(ctx, len, 0);\n    if (!str)\n        return JS_EXCEPTION;\n    memcpy(str->u.str8, buf, len);\n    str->u.str8[len] = '\\0';\n    return JS_MKPTR(JS_TAG_STRING, str);\n}\n\nstatic JSValue js_new_string16(JSContext *ctx, const uint16_t *buf, int len)\n{\n    JSString *str;\n    str = js_alloc_string(ctx, len, 1);\n    if (!str)\n        return JS_EXCEPTION;\n    memcpy(str->u.str16, buf, len * 2);\n    return JS_MKPTR(JS_TAG_STRING, str);\n}\n\nstatic JSValue js_new_string_char(JSContext *ctx, uint16_t c)\n{\n    if (c < 0x100) {\n        uint8_t ch8 = c;\n        return js_new_string8(ctx, &ch8, 1);\n    } else {\n        uint16_t ch16 = c;\n        return js_new_string16(ctx, &ch16, 1);\n    }\n}\n\nstatic JSValue js_sub_string(JSContext *ctx, JSString *p, int start, int end)\n{\n    int len = end - start;\n    if (start == 0 && end == p->len) {\n        return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p));\n    }\n    if (p->is_wide_char && len > 0) {\n        JSString *str;\n        int i;\n        uint16_t c = 0;\n        for (i = start; i < end; i++) {\n            c |= p->u.str16[i];\n        }\n        if (c > 0xFF)\n            return js_new_string16(ctx, p->u.str16 + start, len);\n\n        str = js_alloc_string(ctx, len, 0);\n        if (!str)\n            return JS_EXCEPTION;\n        for (i = 0; i < len; i++) {\n            str->u.str8[i] = p->u.str16[start + i];\n        }\n        str->u.str8[len] = '\\0';\n        return JS_MKPTR(JS_TAG_STRING, str);\n    } else {\n        return js_new_string8(ctx, p->u.str8 + start, len);\n    }\n}\n\ntypedef struct StringBuffer {\n    JSContext *ctx;\n    JSString *str;\n    int len;\n    int size;\n    int is_wide_char;\n    int error_status;\n} StringBuffer;\n\n/* It is valid to call string_buffer_end() and all string_buffer functions even\n   if string_buffer_init() or another string_buffer function returns an error.\n   If the error_status is set, string_buffer_end() returns JS_EXCEPTION.\n */\nstatic int string_buffer_init2(JSContext *ctx, StringBuffer *s, int size,\n                               int is_wide)\n{\n    s->ctx = ctx;\n    s->size = size;\n    s->len = 0;\n    s->is_wide_char = is_wide;\n    s->error_status = 0;\n    s->str = js_alloc_string(ctx, size, is_wide);\n    if (unlikely(!s->str)) {\n        s->size = 0;\n        return s->error_status = -1;\n    }\n#ifdef DUMP_LEAKS\n    /* the StringBuffer may reallocate the JSString, only link it at the end */\n    list_del(&s->str->link);\n#endif\n    return 0;\n}\n\nstatic inline int string_buffer_init(JSContext *ctx, StringBuffer *s, int size)\n{\n    return string_buffer_init2(ctx, s, size, 0);\n}\n\nstatic void string_buffer_free(StringBuffer *s)\n{\n    js_free(s->ctx, s->str);\n    s->str = NULL;\n}\n\nstatic int string_buffer_set_error(StringBuffer *s)\n{\n    js_free(s->ctx, s->str);\n    s->str = NULL;\n    s->size = 0;\n    s->len = 0;\n    return s->error_status = -1;\n}\n\nstatic no_inline int string_buffer_widen(StringBuffer *s, int size)\n{\n    JSString *str;\n    size_t slack;\n    int i;\n\n    if (s->error_status)\n        return -1;\n\n    str = js_realloc2(s->ctx, s->str, sizeof(JSString) + (size << 1), &slack);\n    if (!str)\n        return string_buffer_set_error(s);\n    size += slack >> 1;\n    for(i = s->len; i-- > 0;) {\n        str->u.str16[i] = str->u.str8[i];\n    }\n    s->is_wide_char = 1;\n    s->size = size;\n    s->str = str;\n    return 0;\n}\n\nstatic no_inline int string_buffer_realloc(StringBuffer *s, int new_len, int c)\n{\n    JSString *new_str;\n    int new_size;\n    size_t new_size_bytes, slack;\n\n    if (s->error_status)\n        return -1;\n\n    if (new_len > JS_STRING_LEN_MAX) {\n        JS_ThrowInternalError(s->ctx, \"string too long\");\n        return string_buffer_set_error(s);\n    }\n    new_size = min_int(max_int(new_len, s->size * 3 / 2), JS_STRING_LEN_MAX);\n    if (!s->is_wide_char && c >= 0x100) {\n        return string_buffer_widen(s, new_size);\n    }\n    new_size_bytes = sizeof(JSString) + (new_size << s->is_wide_char) + 1 - s->is_wide_char;\n    new_str = js_realloc2(s->ctx, s->str, new_size_bytes, &slack);\n    if (!new_str)\n        return string_buffer_set_error(s);\n    new_size = min_int(new_size + (slack >> s->is_wide_char), JS_STRING_LEN_MAX);\n    s->size = new_size;\n    s->str = new_str;\n    return 0;\n}\n\nstatic no_inline int string_buffer_putc_slow(StringBuffer *s, uint32_t c)\n{\n    if (unlikely(s->len >= s->size)) {\n        if (string_buffer_realloc(s, s->len + 1, c))\n            return -1;\n    }\n    if (s->is_wide_char) {\n        s->str->u.str16[s->len++] = c;\n    } else if (c < 0x100) {\n        s->str->u.str8[s->len++] = c;\n    } else {\n        if (string_buffer_widen(s, s->size))\n            return -1;\n        s->str->u.str16[s->len++] = c;\n    }\n    return 0;\n}\n\n/* 0 <= c <= 0xff */\nstatic int string_buffer_putc8(StringBuffer *s, uint32_t c)\n{\n    if (unlikely(s->len >= s->size)) {\n        if (string_buffer_realloc(s, s->len + 1, c))\n            return -1;\n    }\n    if (s->is_wide_char) {\n        s->str->u.str16[s->len++] = c;\n    } else {\n        s->str->u.str8[s->len++] = c;\n    }\n    return 0;\n}\n\n/* 0 <= c <= 0xffff */\nstatic int string_buffer_putc16(StringBuffer *s, uint32_t c)\n{\n    if (likely(s->len < s->size)) {\n        if (s->is_wide_char) {\n            s->str->u.str16[s->len++] = c;\n            return 0;\n        } else if (c < 0x100) {\n            s->str->u.str8[s->len++] = c;\n            return 0;\n        }\n    }\n    return string_buffer_putc_slow(s, c);\n}\n\n/* 0 <= c <= 0x10ffff */\nstatic int string_buffer_putc(StringBuffer *s, uint32_t c)\n{\n    if (unlikely(c >= 0x10000)) {\n        /* surrogate pair */\n        c -= 0x10000;\n        if (string_buffer_putc16(s, (c >> 10) + 0xd800))\n            return -1;\n        c = (c & 0x3ff) + 0xdc00;\n    }\n    return string_buffer_putc16(s, c);\n}\n\nstatic int string_get(const JSString *p, int idx) {\n    return p->is_wide_char ? p->u.str16[idx] : p->u.str8[idx];\n}\n\nstatic int string_getc(const JSString *p, int *pidx)\n{\n    int idx, c, c1;\n    idx = *pidx;\n    if (p->is_wide_char) {\n        c = p->u.str16[idx++];\n        if (c >= 0xd800 && c < 0xdc00 && idx < p->len) {\n            c1 = p->u.str16[idx];\n            if (c1 >= 0xdc00 && c1 < 0xe000) {\n                c = (((c & 0x3ff) << 10) | (c1 & 0x3ff)) + 0x10000;\n                idx++;\n            }\n        }\n    } else {\n        c = p->u.str8[idx++];\n    }\n    *pidx = idx;\n    return c;\n}\n\nstatic int string_buffer_write8(StringBuffer *s, const uint8_t *p, int len)\n{\n    int i;\n\n    if (s->len + len > s->size) {\n        if (string_buffer_realloc(s, s->len + len, 0))\n            return -1;\n    }\n    if (s->is_wide_char) {\n        for (i = 0; i < len; i++) {\n            s->str->u.str16[s->len + i] = p[i];\n        }\n        s->len += len;\n    } else {\n        memcpy(&s->str->u.str8[s->len], p, len);\n        s->len += len;\n    }\n    return 0;\n}\n\nstatic int string_buffer_write16(StringBuffer *s, const uint16_t *p, int len)\n{\n    int c = 0, i;\n\n    for (i = 0; i < len; i++) {\n        c |= p[i];\n    }\n    if (s->len + len > s->size) {\n        if (string_buffer_realloc(s, s->len + len, c))\n            return -1;\n    } else if (!s->is_wide_char && c >= 0x100) {\n        if (string_buffer_widen(s, s->size))\n            return -1;\n    }\n    if (s->is_wide_char) {\n        memcpy(&s->str->u.str16[s->len], p, len << 1);\n        s->len += len;\n    } else {\n        for (i = 0; i < len; i++) {\n            s->str->u.str8[s->len + i] = p[i];\n        }\n        s->len += len;\n    }\n    return 0;\n}\n\n/* appending an ASCII string */\nstatic int string_buffer_puts8(StringBuffer *s, const char *str)\n{\n    return string_buffer_write8(s, (const uint8_t *)str, strlen(str));\n}\n\nstatic int string_buffer_concat(StringBuffer *s, const JSString *p,\n                                uint32_t from, uint32_t to)\n{\n    if (to <= from)\n        return 0;\n    if (p->is_wide_char)\n        return string_buffer_write16(s, p->u.str16 + from, to - from);\n    else\n        return string_buffer_write8(s, p->u.str8 + from, to - from);\n}\n\nstatic int string_buffer_concat_value(StringBuffer *s, JSValueConst v)\n{\n    JSString *p;\n    JSValue v1;\n    int res;\n\n    if (s->error_status) {\n        /* prevent exception overload */\n        return -1;\n    }\n    if (unlikely(JS_VALUE_GET_TAG(v) != JS_TAG_STRING)) {\n        v1 = JS_ToString(s->ctx, v);\n        if (JS_IsException(v1))\n            return string_buffer_set_error(s);\n        p = JS_VALUE_GET_STRING(v1);\n        res = string_buffer_concat(s, p, 0, p->len);\n        JS_FreeValue(s->ctx, v1);\n        return res;\n    }\n    p = JS_VALUE_GET_STRING(v);\n    return string_buffer_concat(s, p, 0, p->len);\n}\n\nstatic int string_buffer_concat_value_free(StringBuffer *s, JSValue v)\n{\n    JSString *p;\n    int res;\n\n    if (s->error_status) {\n        /* prevent exception overload */\n        JS_FreeValue(s->ctx, v);\n        return -1;\n    }\n    if (unlikely(JS_VALUE_GET_TAG(v) != JS_TAG_STRING)) {\n        v = JS_ToStringFree(s->ctx, v);\n        if (JS_IsException(v))\n            return string_buffer_set_error(s);\n    }\n    p = JS_VALUE_GET_STRING(v);\n    res = string_buffer_concat(s, p, 0, p->len);\n    JS_FreeValue(s->ctx, v);\n    return res;\n}\n\nstatic int string_buffer_fill(StringBuffer *s, int c, int count)\n{\n    /* XXX: optimize */\n    if (s->len + count > s->size) {\n        if (string_buffer_realloc(s, s->len + count, c))\n            return -1;\n    }\n    while (count-- > 0) {\n        if (string_buffer_putc16(s, c))\n            return -1;\n    }\n    return 0;\n}\n\nstatic JSValue string_buffer_end(StringBuffer *s)\n{\n    JSString *str;\n    str = s->str;\n    if (s->error_status)\n        return JS_EXCEPTION;\n    if (s->len == 0) {\n        js_free(s->ctx, str);\n        s->str = NULL;\n        return JS_AtomToString(s->ctx, JS_ATOM_empty_string);\n    }\n    if (s->len < s->size) {\n        /* smaller size so js_realloc should not fail, but OK if it does */\n        /* XXX: should add some slack to avoid unnecessary calls */\n        /* XXX: might need to use malloc+free to ensure smaller size */\n        str = js_realloc_rt(s->ctx->rt, str, sizeof(JSString) +\n                            (s->len << s->is_wide_char) + 1 - s->is_wide_char);\n        if (str == NULL)\n            str = s->str;\n        s->str = str;\n    }\n    if (!s->is_wide_char)\n        str->u.str8[s->len] = 0;\n#ifdef DUMP_LEAKS\n    list_add_tail(&str->link, &s->ctx->rt->string_list);\n#endif\n    str->is_wide_char = s->is_wide_char;\n    str->len = s->len;\n    s->str = NULL;\n    return JS_MKPTR(JS_TAG_STRING, str);\n}\n\n/* create a string from a UTF-8 buffer */\nJSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)\n{\n    const uint8_t *p, *p_end, *p_start, *p_next;\n    uint32_t c;\n    StringBuffer b_s, *b = &b_s;\n    size_t len1;\n    \n    p_start = (const uint8_t *)buf;\n    p_end = p_start + buf_len;\n    p = p_start;\n    while (p < p_end && *p < 128)\n        p++;\n    len1 = p - p_start;\n    if (len1 > JS_STRING_LEN_MAX)\n        return JS_ThrowInternalError(ctx, \"string too long\");\n    if (p == p_end) {\n        /* ASCII string */\n        return js_new_string8(ctx, (const uint8_t *)buf, buf_len);\n    } else {\n        if (string_buffer_init(ctx, b, buf_len))\n            goto fail;\n        string_buffer_write8(b, p_start, len1);\n        while (p < p_end) {\n            if (*p < 128) {\n                string_buffer_putc8(b, *p++);\n            } else {\n                /* parse utf-8 sequence, return 0xFFFFFFFF for error */\n                c = unicode_from_utf8(p, p_end - p, &p_next);\n                if (c < 0x10000) {\n                    p = p_next;\n                } else if (c <= 0x10FFFF) {\n                    p = p_next;\n                    /* surrogate pair */\n                    c -= 0x10000;\n                    string_buffer_putc16(b, (c >> 10) + 0xd800);\n                    c = (c & 0x3ff) + 0xdc00;\n                } else {\n                    /* invalid char */\n                    c = 0xfffd;\n                    /* skip the invalid chars */\n                    /* XXX: seems incorrect. Why not just use c = *p++; ? */\n                    while (p < p_end && (*p >= 0x80 && *p < 0xc0))\n                        p++;\n                    if (p < p_end) {\n                        p++;\n                        while (p < p_end && (*p >= 0x80 && *p < 0xc0))\n                            p++;\n                    }\n                }\n                string_buffer_putc16(b, c);\n            }\n        }\n    }\n    return string_buffer_end(b);\n\n fail:\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ConcatString3(JSContext *ctx, const char *str1,\n                                JSValue str2, const char *str3)\n{\n    StringBuffer b_s, *b = &b_s;\n    int len1, len3;\n    JSString *p;\n\n    if (unlikely(JS_VALUE_GET_TAG(str2) != JS_TAG_STRING)) {\n        str2 = JS_ToStringFree(ctx, str2);\n        if (JS_IsException(str2))\n            goto fail;\n    }\n    p = JS_VALUE_GET_STRING(str2);\n    len1 = strlen(str1);\n    len3 = strlen(str3);\n\n    if (string_buffer_init2(ctx, b, len1 + p->len + len3, p->is_wide_char))\n        goto fail;\n\n    string_buffer_write8(b, (const uint8_t *)str1, len1);\n    string_buffer_concat(b, p, 0, p->len);\n    string_buffer_write8(b, (const uint8_t *)str3, len3);\n\n    JS_FreeValue(ctx, str2);\n    return string_buffer_end(b);\n\n fail:\n    JS_FreeValue(ctx, str2);\n    return JS_EXCEPTION;\n}\n\nJSValue JS_NewString(JSContext *ctx, const char *str)\n{\n    return JS_NewStringLen(ctx, str, strlen(str));\n}\n\nJSValue JS_NewAtomString(JSContext *ctx, const char *str)\n{\n    JSAtom atom = JS_NewAtom(ctx, str);\n    if (atom == JS_ATOM_NULL)\n        return JS_EXCEPTION;\n    JSValue val = JS_AtomToString(ctx, atom);\n    JS_FreeAtom(ctx, atom);\n    return val;\n}\n\n/* return (NULL, 0) if exception. */\n/* return pointer into a JSString with a live ref_count */\n/* cesu8 determines if non-BMP1 codepoints are encoded as 1 or 2 utf-8 sequences */\nconst char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, BOOL cesu8)\n{\n    JSValue val;\n    JSString *str, *str_new;\n    int pos, len, c, c1;\n    uint8_t *q;\n\n    if (JS_VALUE_GET_TAG(val1) != JS_TAG_STRING) {\n        val = JS_ToString(ctx, val1);\n        if (JS_IsException(val))\n            goto fail;\n    } else {\n        val = JS_DupValue(ctx, val1);\n    }\n\n    str = JS_VALUE_GET_STRING(val);\n    len = str->len;\n    if (!str->is_wide_char) {\n        const uint8_t *src = str->u.str8;\n        int count;\n\n        /* count the number of non-ASCII characters */\n        /* Scanning the whole string is required for ASCII strings,\n           and computing the number of non-ASCII bytes is less expensive\n           than testing each byte, hence this method is faster for ASCII\n           strings, which is the most common case.\n         */\n        count = 0;\n        for (pos = 0; pos < len; pos++) {\n            count += src[pos] >> 7;\n        }\n        if (count == 0) {\n            if (plen)\n                *plen = len;\n            return (const char *)src;\n        }\n        str_new = js_alloc_string(ctx, len + count, 0);\n        if (!str_new)\n            goto fail;\n        q = str_new->u.str8;\n        for (pos = 0; pos < len; pos++) {\n            c = src[pos];\n            if (c < 0x80) {\n                *q++ = c;\n            } else {\n                *q++ = (c >> 6) | 0xc0;\n                *q++ = (c & 0x3f) | 0x80;\n            }\n        }\n    } else {\n        const uint16_t *src = str->u.str16;\n        /* Allocate 3 bytes per 16 bit code point. Surrogate pairs may\n           produce 4 bytes but use 2 code points.\n         */\n        str_new = js_alloc_string(ctx, len * 3, 0);\n        if (!str_new)\n            goto fail;\n        q = str_new->u.str8;\n        pos = 0;\n        while (pos < len) {\n            c = src[pos++];\n            if (c < 0x80) {\n                *q++ = c;\n            } else {\n                if (c >= 0xd800 && c < 0xdc00) {\n                    if (pos < len && !cesu8) {\n                        c1 = src[pos];\n                        if (c1 >= 0xdc00 && c1 < 0xe000) {\n                            pos++;\n                            /* surrogate pair */\n                            c = (((c & 0x3ff) << 10) | (c1 & 0x3ff)) + 0x10000;\n                        } else {\n                            /* Keep unmatched surrogate code points */\n                            /* c = 0xfffd; */ /* error */\n                        }\n                    } else {\n                        /* Keep unmatched surrogate code points */\n                        /* c = 0xfffd; */ /* error */\n                    }\n                }\n                q += unicode_to_utf8(q, c);\n            }\n        }\n    }\n\n    *q = '\\0';\n    str_new->len = q - str_new->u.str8;\n    JS_FreeValue(ctx, val);\n    if (plen)\n        *plen = str_new->len;\n    return (const char *)str_new->u.str8;\n fail:\n    if (plen)\n        *plen = 0;\n    return NULL;\n}\n\nvoid JS_FreeCString(JSContext *ctx, const char *ptr)\n{\n    JSString *p;\n    if (!ptr)\n        return;\n    /* purposely removing constness */\n    p = (JSString *)(void *)(ptr - offsetof(JSString, u));\n    JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, p));\n}\n\nstatic int memcmp16_8(const uint16_t *src1, const uint8_t *src2, int len)\n{\n    int c, i;\n    for(i = 0; i < len; i++) {\n        c = src1[i] - src2[i];\n        if (c != 0)\n            return c;\n    }\n    return 0;\n}\n\nstatic int memcmp16(const uint16_t *src1, const uint16_t *src2, int len)\n{\n    int c, i;\n    for(i = 0; i < len; i++) {\n        c = src1[i] - src2[i];\n        if (c != 0)\n            return c;\n    }\n    return 0;\n}\n\nstatic int js_string_memcmp(const JSString *p1, const JSString *p2, int len)\n{\n    int res;\n\n    if (likely(!p1->is_wide_char)) {\n        if (likely(!p2->is_wide_char))\n            res = memcmp(p1->u.str8, p2->u.str8, len);\n        else\n            res = -memcmp16_8(p2->u.str16, p1->u.str8, len);\n    } else {\n        if (!p2->is_wide_char)\n            res = memcmp16_8(p1->u.str16, p2->u.str8, len);\n        else\n            res = memcmp16(p1->u.str16, p2->u.str16, len);\n    }\n    return res;\n}\n\n/* return < 0, 0 or > 0 */\nstatic int js_string_compare(JSContext *ctx,\n                             const JSString *p1, const JSString *p2)\n{\n    int res, len;\n    len = min_int(p1->len, p2->len);\n    res = js_string_memcmp(p1, p2, len);\n    if (res == 0) {\n        if (p1->len == p2->len)\n            res = 0;\n        else if (p1->len < p2->len)\n            res = -1;\n        else\n            res = 1;\n    }\n    return res;\n}\n\nstatic void copy_str16(uint16_t *dst, const JSString *p, int offset, int len)\n{\n    if (p->is_wide_char) {\n        memcpy(dst, p->u.str16 + offset, len * 2);\n    } else {\n        const uint8_t *src1 = p->u.str8 + offset;\n        int i;\n\n        for(i = 0; i < len; i++)\n            dst[i] = src1[i];\n    }\n}\n\nstatic JSValue JS_ConcatString1(JSContext *ctx,\n                                const JSString *p1, const JSString *p2)\n{\n    JSString *p;\n    uint32_t len;\n    int is_wide_char;\n\n    len = p1->len + p2->len;\n    if (len > JS_STRING_LEN_MAX)\n        return JS_ThrowInternalError(ctx, \"string too long\");\n    is_wide_char = p1->is_wide_char | p2->is_wide_char;\n    p = js_alloc_string(ctx, len, is_wide_char);\n    if (!p)\n        return JS_EXCEPTION;\n    if (!is_wide_char) {\n        memcpy(p->u.str8, p1->u.str8, p1->len);\n        memcpy(p->u.str8 + p1->len, p2->u.str8, p2->len);\n        p->u.str8[len] = '\\0';\n    } else {\n        copy_str16(p->u.str16, p1, 0, p1->len);\n        copy_str16(p->u.str16 + p1->len, p2, 0, p2->len);\n    }\n    return JS_MKPTR(JS_TAG_STRING, p);\n}\n\n/* op1 and op2 are converted to strings. For convience, op1 or op2 =\n   JS_EXCEPTION are accepted and return JS_EXCEPTION.  */\nstatic JSValue JS_ConcatString(JSContext *ctx, JSValue op1, JSValue op2)\n{\n    JSValue ret;\n    JSString *p1, *p2;\n\n    if (unlikely(JS_VALUE_GET_TAG(op1) != JS_TAG_STRING)) {\n        op1 = JS_ToStringFree(ctx, op1);\n        if (JS_IsException(op1)) {\n            JS_FreeValue(ctx, op2);\n            return JS_EXCEPTION;\n        }\n    }\n    if (unlikely(JS_VALUE_GET_TAG(op2) != JS_TAG_STRING)) {\n        op2 = JS_ToStringFree(ctx, op2);\n        if (JS_IsException(op2)) {\n            JS_FreeValue(ctx, op1);\n            return JS_EXCEPTION;\n        }\n    }\n    p1 = JS_VALUE_GET_STRING(op1);\n    p2 = JS_VALUE_GET_STRING(op2);\n\n    /* XXX: could also check if p1 is empty */\n    if (p2->len == 0) {\n        goto ret_op1;\n    }\n    if (p1->header.ref_count == 1 && p1->is_wide_char == p2->is_wide_char\n    &&  js_malloc_usable_size(ctx, p1) >= sizeof(*p1) + ((p1->len + p2->len) << p2->is_wide_char) + 1 - p1->is_wide_char) {\n        /* Concatenate in place in available space at the end of p1 */\n        if (p1->is_wide_char) {\n            memcpy(p1->u.str16 + p1->len, p2->u.str16, p2->len << 1);\n            p1->len += p2->len;\n        } else {\n            memcpy(p1->u.str8 + p1->len, p2->u.str8, p2->len);\n            p1->len += p2->len;\n            p1->u.str8[p1->len] = '\\0';\n        }\n    ret_op1:\n        JS_FreeValue(ctx, op2);\n        return op1;\n    }\n    ret = JS_ConcatString1(ctx, p1, p2);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    return ret;\n}\n\n/* Shape support */\n\nstatic inline size_t get_shape_size(size_t hash_size, size_t prop_size)\n{\n    return hash_size * sizeof(uint32_t) + sizeof(JSShape) +\n        prop_size * sizeof(JSShapeProperty);\n}\n\nstatic inline JSShape *get_shape_from_alloc(void *sh_alloc, size_t hash_size)\n{\n    return (JSShape *)(void *)((uint32_t *)sh_alloc + hash_size);\n}\n\nstatic inline void *get_alloc_from_shape(JSShape *sh)\n{\n    return sh->prop_hash_end - ((intptr_t)sh->prop_hash_mask + 1);\n}\n\nstatic inline JSShapeProperty *get_shape_prop(JSShape *sh)\n{\n    return sh->prop;\n}\n\nstatic int init_shape_hash(JSRuntime *rt)\n{\n    rt->shape_hash_bits = 4;   /* 16 shapes */\n    rt->shape_hash_size = 1 << rt->shape_hash_bits;\n    rt->shape_hash_count = 0;\n    rt->shape_hash = js_mallocz_rt(rt, sizeof(rt->shape_hash[0]) *\n                                   rt->shape_hash_size);\n    if (!rt->shape_hash)\n        return -1;\n    return 0;\n}\n\n/* same magic hash multiplier as the Linux kernel */\nstatic uint32_t shape_hash(uint32_t h, uint32_t val)\n{\n    return (h + val) * 0x9e370001;\n}\n\n/* truncate the shape hash to 'hash_bits' bits */\nstatic uint32_t get_shape_hash(uint32_t h, int hash_bits)\n{\n    return h >> (32 - hash_bits);\n}\n\nstatic uint32_t shape_initial_hash(JSObject *proto)\n{\n    uint32_t h;\n    h = shape_hash(1, (uintptr_t)proto);\n    if (sizeof(proto) > 4)\n        h = shape_hash(h, (uint64_t)(uintptr_t)proto >> 32);\n    return h;\n}\n\nstatic int resize_shape_hash(JSRuntime *rt, int new_shape_hash_bits)\n{\n    int new_shape_hash_size, i;\n    uint32_t h;\n    JSShape **new_shape_hash, *sh, *sh_next;\n\n    new_shape_hash_size = 1 << new_shape_hash_bits;\n    new_shape_hash = js_mallocz_rt(rt, sizeof(rt->shape_hash[0]) *\n                                   new_shape_hash_size);\n    if (!new_shape_hash)\n        return -1;\n    for(i = 0; i < rt->shape_hash_size; i++) {\n        for(sh = rt->shape_hash[i]; sh != NULL; sh = sh_next) {\n            sh_next = sh->shape_hash_next;\n            h = get_shape_hash(sh->hash, new_shape_hash_bits);\n            sh->shape_hash_next = new_shape_hash[h];\n            new_shape_hash[h] = sh;\n        }\n    }\n    js_free_rt(rt, rt->shape_hash);\n    rt->shape_hash_bits = new_shape_hash_bits;\n    rt->shape_hash_size = new_shape_hash_size;\n    rt->shape_hash = new_shape_hash;\n    return 0;\n}\n\nstatic void js_shape_hash_link(JSRuntime *rt, JSShape *sh)\n{\n    uint32_t h;\n    h = get_shape_hash(sh->hash, rt->shape_hash_bits);\n    sh->shape_hash_next = rt->shape_hash[h];\n    rt->shape_hash[h] = sh;\n    rt->shape_hash_count++;\n}\n\nstatic void js_shape_hash_unlink(JSRuntime *rt, JSShape *sh)\n{\n    uint32_t h;\n    JSShape **psh;\n\n    h = get_shape_hash(sh->hash, rt->shape_hash_bits);\n    psh = &rt->shape_hash[h];\n    while (*psh != sh)\n        psh = &(*psh)->shape_hash_next;\n    *psh = sh->shape_hash_next;\n    rt->shape_hash_count--;\n}\n\n/* create a new empty shape with prototype 'proto' */\nstatic no_inline JSShape *js_new_shape2(JSContext *ctx, JSObject *proto,\n                                        int hash_size, int prop_size)\n{\n    JSRuntime *rt = ctx->rt;\n    void *sh_alloc;\n    JSShape *sh;\n\n    /* resize the shape hash table if necessary */\n    if (2 * (rt->shape_hash_count + 1) > rt->shape_hash_size) {\n        resize_shape_hash(rt, rt->shape_hash_bits + 1);\n    }\n\n    sh_alloc = js_malloc(ctx, get_shape_size(hash_size, prop_size));\n    if (!sh_alloc)\n        return NULL;\n    sh = get_shape_from_alloc(sh_alloc, hash_size);\n    sh->header.ref_count = 1;\n    add_gc_object(rt, &sh->header, JS_GC_OBJ_TYPE_SHAPE);\n    if (proto)\n        JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, proto));\n    sh->proto = proto;\n    memset(sh->prop_hash_end - hash_size, 0, sizeof(sh->prop_hash_end[0]) *\n           hash_size);\n    sh->prop_hash_mask = hash_size - 1;\n    sh->prop_size = prop_size;\n    sh->prop_count = 0;\n    sh->deleted_prop_count = 0;\n    \n    /* insert in the hash table */\n    sh->hash = shape_initial_hash(proto);\n    sh->is_hashed = TRUE;\n    sh->has_small_array_index = FALSE;\n    js_shape_hash_link(ctx->rt, sh);\n    return sh;\n}\n\nstatic JSShape *js_new_shape(JSContext *ctx, JSObject *proto)\n{\n    return js_new_shape2(ctx, proto, JS_PROP_INITIAL_HASH_SIZE,\n                         JS_PROP_INITIAL_SIZE);\n}\n\n/* The shape is cloned. The new shape is not inserted in the shape\n   hash table */\nstatic JSShape *js_clone_shape(JSContext *ctx, JSShape *sh1)\n{\n    JSShape *sh;\n    void *sh_alloc, *sh_alloc1;\n    size_t size;\n    JSShapeProperty *pr;\n    uint32_t i, hash_size;\n\n    hash_size = sh1->prop_hash_mask + 1;\n    size = get_shape_size(hash_size, sh1->prop_size);\n    sh_alloc = js_malloc(ctx, size);\n    if (!sh_alloc)\n        return NULL;\n    sh_alloc1 = get_alloc_from_shape(sh1);\n    memcpy(sh_alloc, sh_alloc1, size);\n    sh = get_shape_from_alloc(sh_alloc, hash_size);\n    sh->header.ref_count = 1;\n    add_gc_object(ctx->rt, &sh->header, JS_GC_OBJ_TYPE_SHAPE);\n    sh->is_hashed = FALSE;\n    if (sh->proto) {\n        JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, sh->proto));\n    }\n    for(i = 0, pr = get_shape_prop(sh); i < sh->prop_count; i++, pr++) {\n        JS_DupAtom(ctx, pr->atom);\n    }\n    return sh;\n}\n\nstatic JSShape *js_dup_shape(JSShape *sh)\n{\n    sh->header.ref_count++;\n    return sh;\n}\n\nstatic void js_free_shape0(JSRuntime *rt, JSShape *sh)\n{\n    uint32_t i;\n    JSShapeProperty *pr;\n\n    assert(sh->header.ref_count == 0);\n    if (sh->is_hashed)\n        js_shape_hash_unlink(rt, sh);\n    if (sh->proto != NULL) {\n        JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, sh->proto));\n    }\n    pr = get_shape_prop(sh);\n    for(i = 0; i < sh->prop_count; i++) {\n        JS_FreeAtomRT(rt, pr->atom);\n        pr++;\n    }\n    remove_gc_object(&sh->header);\n    js_free_rt(rt, get_alloc_from_shape(sh));\n}\n\nstatic void js_free_shape(JSRuntime *rt, JSShape *sh)\n{\n    if (unlikely(--sh->header.ref_count <= 0)) {\n        js_free_shape0(rt, sh);\n    }\n}\n\nstatic void js_free_shape_null(JSRuntime *rt, JSShape *sh)\n{\n    if (sh)\n        js_free_shape(rt, sh);\n}\n\n/* make space to hold at least 'count' properties */\nstatic no_inline int resize_properties(JSContext *ctx, JSShape **psh,\n                                       JSObject *p, uint32_t count)\n{\n    JSShape *sh;\n    uint32_t new_size, new_hash_size, new_hash_mask, i;\n    JSShapeProperty *pr;\n    void *sh_alloc;\n    intptr_t h;\n\n    sh = *psh;\n    new_size = max_int(count, sh->prop_size * 3 / 2);\n    /* Reallocate prop array first to avoid crash or size inconsistency\n       in case of memory allocation failure */\n    if (p) {\n        JSProperty *new_prop;\n        new_prop = js_realloc(ctx, p->prop, sizeof(new_prop[0]) * new_size);\n        if (unlikely(!new_prop))\n            return -1;\n        p->prop = new_prop;\n    }\n    new_hash_size = sh->prop_hash_mask + 1;\n    while (new_hash_size < new_size)\n        new_hash_size = 2 * new_hash_size;\n    if (new_hash_size != (sh->prop_hash_mask + 1)) {\n        JSShape *old_sh;\n        /* resize the hash table and the properties */\n        old_sh = sh;\n        sh_alloc = js_malloc(ctx, get_shape_size(new_hash_size, new_size));\n        if (!sh_alloc)\n            return -1;\n        sh = get_shape_from_alloc(sh_alloc, new_hash_size);\n        list_del(&old_sh->header.link);\n        /* copy all the fields and the properties */\n        memcpy(sh, old_sh,\n               sizeof(JSShape) + sizeof(sh->prop[0]) * old_sh->prop_count);\n        list_add_tail(&sh->header.link, &ctx->rt->gc_obj_list);\n        new_hash_mask = new_hash_size - 1;\n        sh->prop_hash_mask = new_hash_mask;\n        memset(sh->prop_hash_end - new_hash_size, 0,\n               sizeof(sh->prop_hash_end[0]) * new_hash_size);\n        for(i = 0, pr = sh->prop; i < sh->prop_count; i++, pr++) {\n            if (pr->atom != JS_ATOM_NULL) {\n                h = ((uintptr_t)pr->atom & new_hash_mask);\n                pr->hash_next = sh->prop_hash_end[-h - 1];\n                sh->prop_hash_end[-h - 1] = i + 1;\n            }\n        }\n        js_free(ctx, get_alloc_from_shape(old_sh));\n    } else {\n        /* only resize the properties */\n        list_del(&sh->header.link);\n        sh_alloc = js_realloc(ctx, get_alloc_from_shape(sh),\n                              get_shape_size(new_hash_size, new_size));\n        if (unlikely(!sh_alloc)) {\n            /* insert again in the GC list */\n            list_add_tail(&sh->header.link, &ctx->rt->gc_obj_list);\n            return -1;\n        }\n        sh = get_shape_from_alloc(sh_alloc, new_hash_size);\n        list_add_tail(&sh->header.link, &ctx->rt->gc_obj_list);\n    }\n    *psh = sh;\n    sh->prop_size = new_size;\n    return 0;\n}\n\n/* remove the deleted properties. */\nstatic int compact_properties(JSContext *ctx, JSObject *p)\n{\n    JSShape *sh, *old_sh;\n    void *sh_alloc;\n    intptr_t h;\n    uint32_t new_hash_size, i, j, new_hash_mask, new_size;\n    JSShapeProperty *old_pr, *pr;\n    JSProperty *prop, *new_prop;\n    \n    sh = p->shape;\n    assert(!sh->is_hashed);\n\n    new_size = max_int(JS_PROP_INITIAL_SIZE,\n                       sh->prop_count - sh->deleted_prop_count);\n    assert(new_size <= sh->prop_size);\n\n    new_hash_size = sh->prop_hash_mask + 1;\n    while ((new_hash_size / 2) >= new_size)\n        new_hash_size = new_hash_size / 2;\n    new_hash_mask = new_hash_size - 1;\n\n    /* resize the hash table and the properties */\n    old_sh = sh;\n    sh_alloc = js_malloc(ctx, get_shape_size(new_hash_size, new_size));\n    if (!sh_alloc)\n        return -1;\n    sh = get_shape_from_alloc(sh_alloc, new_hash_size);\n    list_del(&old_sh->header.link);\n    memcpy(sh, old_sh, sizeof(JSShape));\n    list_add_tail(&sh->header.link, &ctx->rt->gc_obj_list);\n    \n    memset(sh->prop_hash_end - new_hash_size, 0,\n           sizeof(sh->prop_hash_end[0]) * new_hash_size);\n\n    j = 0;\n    old_pr = old_sh->prop;\n    pr = sh->prop;\n    prop = p->prop;\n    for(i = 0; i < sh->prop_count; i++) {\n        if (old_pr->atom != JS_ATOM_NULL) {\n            pr->atom = old_pr->atom;\n            pr->flags = old_pr->flags;\n            h = ((uintptr_t)old_pr->atom & new_hash_mask);\n            pr->hash_next = sh->prop_hash_end[-h - 1];\n            sh->prop_hash_end[-h - 1] = j + 1;\n            prop[j] = prop[i];\n            j++;\n            pr++;\n        }\n        old_pr++;\n    }\n    assert(j == (sh->prop_count - sh->deleted_prop_count));\n    sh->prop_hash_mask = new_hash_mask;\n    sh->prop_size = new_size;\n    sh->deleted_prop_count = 0;\n    sh->prop_count = j;\n\n    p->shape = sh;\n    js_free(ctx, get_alloc_from_shape(old_sh));\n    \n    /* reduce the size of the object properties */\n    new_prop = js_realloc(ctx, p->prop, sizeof(new_prop[0]) * new_size);\n    if (new_prop)\n        p->prop = new_prop;\n    return 0;\n}\n\nstatic int add_shape_property(JSContext *ctx, JSShape **psh,\n                              JSObject *p, JSAtom atom, int prop_flags)\n{\n    JSRuntime *rt = ctx->rt;\n    JSShape *sh = *psh;\n    JSShapeProperty *pr, *prop;\n    uint32_t hash_mask, new_shape_hash = 0;\n    intptr_t h;\n\n    /* update the shape hash */\n    if (sh->is_hashed) {\n        js_shape_hash_unlink(rt, sh);\n        new_shape_hash = shape_hash(shape_hash(sh->hash, atom), prop_flags);\n    }\n\n    if (unlikely(sh->prop_count >= sh->prop_size)) {\n        if (resize_properties(ctx, psh, p, sh->prop_count + 1)) {\n            /* in case of error, reinsert in the hash table.\n               sh is still valid if resize_properties() failed */\n            if (sh->is_hashed)\n                js_shape_hash_link(rt, sh);\n            return -1;\n        }\n        sh = *psh;\n    }\n    if (sh->is_hashed) {\n        sh->hash = new_shape_hash;\n        js_shape_hash_link(rt, sh);\n    }\n    /* Initialize the new shape property.\n       The object property at p->prop[sh->prop_count] is uninitialized */\n    prop = get_shape_prop(sh);\n    pr = &prop[sh->prop_count++];\n    pr->atom = JS_DupAtom(ctx, atom);\n    pr->flags = prop_flags;\n    sh->has_small_array_index |= __JS_AtomIsTaggedInt(atom);\n    /* add in hash table */\n    hash_mask = sh->prop_hash_mask;\n    h = atom & hash_mask;\n    pr->hash_next = sh->prop_hash_end[-h - 1];\n    sh->prop_hash_end[-h - 1] = sh->prop_count;\n    return 0;\n}\n\n/* find a hashed empty shape matching the prototype. Return NULL if\n   not found */\nstatic JSShape *find_hashed_shape_proto(JSRuntime *rt, JSObject *proto)\n{\n    JSShape *sh1;\n    uint32_t h, h1;\n\n    h = shape_initial_hash(proto);\n    h1 = get_shape_hash(h, rt->shape_hash_bits);\n    for(sh1 = rt->shape_hash[h1]; sh1 != NULL; sh1 = sh1->shape_hash_next) {\n        if (sh1->hash == h &&\n            sh1->proto == proto &&\n            sh1->prop_count == 0) {\n            return sh1;\n        }\n    }\n    return NULL;\n}\n\n/* find a hashed shape matching sh + (prop, prop_flags). Return NULL if\n   not found */\nstatic JSShape *find_hashed_shape_prop(JSRuntime *rt, JSShape *sh,\n                                       JSAtom atom, int prop_flags)\n{\n    JSShape *sh1;\n    uint32_t h, h1, i, n;\n\n    h = sh->hash;\n    h = shape_hash(h, atom);\n    h = shape_hash(h, prop_flags);\n    h1 = get_shape_hash(h, rt->shape_hash_bits);\n    for(sh1 = rt->shape_hash[h1]; sh1 != NULL; sh1 = sh1->shape_hash_next) {\n        /* we test the hash first so that the rest is done only if the\n           shapes really match */\n        if (sh1->hash == h &&\n            sh1->proto == sh->proto &&\n            sh1->prop_count == ((n = sh->prop_count) + 1)) {\n            for(i = 0; i < n; i++) {\n                if (unlikely(sh1->prop[i].atom != sh->prop[i].atom) ||\n                    unlikely(sh1->prop[i].flags != sh->prop[i].flags))\n                    goto next;\n            }\n            if (unlikely(sh1->prop[n].atom != atom) ||\n                unlikely(sh1->prop[n].flags != prop_flags))\n                goto next;\n            return sh1;\n        }\n    next: ;\n    }\n    return NULL;\n}\n\nstatic __maybe_unused void JS_DumpShape(JSRuntime *rt, int i, JSShape *sh)\n{\n    char atom_buf[ATOM_GET_STR_BUF_SIZE];\n    int j;\n\n    /* XXX: should output readable class prototype */\n    printf(\"%5d %3d%c %14p %5d %5d\", i,\n           sh->header.ref_count, \" *\"[sh->is_hashed],\n           (void *)sh->proto, sh->prop_size, sh->prop_count);\n    for(j = 0; j < sh->prop_count; j++) {\n        printf(\" %s\", JS_AtomGetStrRT(rt, atom_buf, sizeof(atom_buf),\n                                      sh->prop[j].atom));\n    }\n    printf(\"\\n\");\n}\n\nstatic __maybe_unused void JS_DumpShapes(JSRuntime *rt)\n{\n    int i;\n    JSShape *sh;\n    struct list_head *el;\n    JSObject *p;\n    JSGCObjectHeader *gp;\n    \n    printf(\"JSShapes: {\\n\");\n    printf(\"%5s %4s %14s %5s %5s %s\\n\", \"SLOT\", \"REFS\", \"PROTO\", \"SIZE\", \"COUNT\", \"PROPS\");\n    for(i = 0; i < rt->shape_hash_size; i++) {\n        for(sh = rt->shape_hash[i]; sh != NULL; sh = sh->shape_hash_next) {\n            JS_DumpShape(rt, i, sh);\n            assert(sh->is_hashed);\n        }\n    }\n    /* dump non-hashed shapes */\n    list_for_each(el, &rt->gc_obj_list) {\n        gp = list_entry(el, JSGCObjectHeader, link);\n        if (gp->gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT) {\n            p = (JSObject *)gp;\n            if (!p->shape->is_hashed) {\n                JS_DumpShape(rt, -1, p->shape);\n            }\n        }\n    }\n    printf(\"}\\n\");\n}\n\nstatic JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID class_id)\n{\n    JSObject *p;\n\n    js_trigger_gc(ctx->rt, sizeof(JSObject));\n    p = js_malloc(ctx, sizeof(JSObject));\n    if (unlikely(!p))\n        goto fail;\n    p->class_id = class_id;\n    p->extensible = TRUE;\n    p->free_mark = 0;\n    p->is_exotic = 0;\n    p->fast_array = 0;\n    p->is_constructor = 0;\n    p->is_uncatchable_error = 0;\n    p->tmp_mark = 0;\n    p->first_weak_ref = NULL;\n    p->u.opaque = NULL;\n    p->shape = sh;\n    p->prop = js_malloc(ctx, sizeof(JSProperty) * sh->prop_size);\n    if (unlikely(!p->prop)) {\n        js_free(ctx, p);\n    fail:\n        js_free_shape(ctx->rt, sh);\n        return JS_EXCEPTION;\n    }\n\n    switch(class_id) {\n    case JS_CLASS_OBJECT:\n        break;\n    case JS_CLASS_ARRAY:\n        {\n            JSProperty *pr;\n            p->is_exotic = 1;\n            p->fast_array = 1;\n            p->u.array.u.values = NULL;\n            p->u.array.count = 0;\n            p->u.array.u1.size = 0;\n            /* the length property is always the first one */\n            if (likely(sh == ctx->array_shape)) {\n                pr = &p->prop[0];\n            } else {\n                /* only used for the first array */\n                /* cannot fail */\n                pr = add_property(ctx, p, JS_ATOM_length,\n                                  JS_PROP_WRITABLE | JS_PROP_LENGTH);\n            }\n            pr->u.value = JS_NewInt32(ctx, 0);\n        }\n        break;\n    case JS_CLASS_C_FUNCTION:\n        p->prop[0].u.value = JS_UNDEFINED;\n        break;\n    case JS_CLASS_ARGUMENTS:\n    case JS_CLASS_UINT8C_ARRAY ... JS_CLASS_FLOAT64_ARRAY:\n        p->is_exotic = 1;\n        p->fast_array = 1;\n        p->u.array.u.ptr = NULL;\n        p->u.array.count = 0;\n        break;\n    case JS_CLASS_DATAVIEW:\n        p->u.array.u.ptr = NULL;\n        p->u.array.count = 0;\n        break;\n    case JS_CLASS_NUMBER:\n    case JS_CLASS_STRING:\n    case JS_CLASS_BOOLEAN:\n    case JS_CLASS_SYMBOL:\n    case JS_CLASS_DATE:\n#ifdef CONFIG_BIGNUM\n    case JS_CLASS_BIG_INT:\n    case JS_CLASS_BIG_FLOAT:\n    case JS_CLASS_BIG_DECIMAL:\n#endif\n        p->u.object_data = JS_UNDEFINED;\n        goto set_exotic;\n    case JS_CLASS_REGEXP:\n        p->u.regexp.pattern = NULL;\n        p->u.regexp.bytecode = NULL;\n        goto set_exotic;\n    default:\n    set_exotic:\n        if (ctx->rt->class_array[class_id].exotic) {\n            p->is_exotic = 1;\n        }\n        break;\n    }\n    p->header.ref_count = 1;\n    add_gc_object(ctx->rt, &p->header, JS_GC_OBJ_TYPE_JS_OBJECT);\n    return JS_MKPTR(JS_TAG_OBJECT, p);\n}\n\nstatic JSObject *get_proto_obj(JSValueConst proto_val)\n{\n    if (JS_VALUE_GET_TAG(proto_val) != JS_TAG_OBJECT)\n        return NULL;\n    else\n        return JS_VALUE_GET_OBJ(proto_val);\n}\n\n/* WARNING: proto must be an object or JS_NULL */\nJSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto_val,\n                               JSClassID class_id)\n{\n    JSShape *sh;\n    JSObject *proto;\n\n    proto = get_proto_obj(proto_val);\n    sh = find_hashed_shape_proto(ctx->rt, proto);\n    if (likely(sh)) {\n        sh = js_dup_shape(sh);\n    } else {\n        sh = js_new_shape(ctx, proto);\n        if (!sh)\n            return JS_EXCEPTION;\n    }\n    return JS_NewObjectFromShape(ctx, sh, class_id);\n}\n\n#if 0\nstatic JSValue JS_GetObjectData(JSContext *ctx, JSValueConst obj)\n{\n    JSObject *p;\n\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        p = JS_VALUE_GET_OBJ(obj);\n        switch(p->class_id) {\n        case JS_CLASS_NUMBER:\n        case JS_CLASS_STRING:\n        case JS_CLASS_BOOLEAN:\n        case JS_CLASS_SYMBOL:\n        case JS_CLASS_DATE:\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT:\n        case JS_CLASS_BIG_FLOAT:\n        case JS_CLASS_BIG_DECIMAL:\n#endif\n            return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_UNDEFINED;\n}\n#endif\n\nstatic int JS_SetObjectData(JSContext *ctx, JSValueConst obj, JSValue val)\n{\n    JSObject *p;\n\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        p = JS_VALUE_GET_OBJ(obj);\n        switch(p->class_id) {\n        case JS_CLASS_NUMBER:\n        case JS_CLASS_STRING:\n        case JS_CLASS_BOOLEAN:\n        case JS_CLASS_SYMBOL:\n        case JS_CLASS_DATE:\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT:\n        case JS_CLASS_BIG_FLOAT:\n        case JS_CLASS_BIG_DECIMAL:\n#endif\n            JS_FreeValue(ctx, p->u.object_data);\n            p->u.object_data = val;\n            return 0;\n        }\n    }\n    JS_FreeValue(ctx, val);\n    if (!JS_IsException(obj))\n        JS_ThrowTypeError(ctx, \"invalid object type\");\n    return -1;\n}\n\nJSValue JS_NewObjectClass(JSContext *ctx, int class_id)\n{\n    return JS_NewObjectProtoClass(ctx, ctx->class_proto[class_id], class_id);\n}\n\nJSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto)\n{\n    return JS_NewObjectProtoClass(ctx, proto, JS_CLASS_OBJECT);\n}\n\nJSValue JS_NewArray(JSContext *ctx)\n{\n    return JS_NewObjectFromShape(ctx, js_dup_shape(ctx->array_shape),\n                                 JS_CLASS_ARRAY);\n}\n\nJSValue JS_NewObject(JSContext *ctx)\n{\n    /* inline JS_NewObjectClass(ctx, JS_CLASS_OBJECT); */\n    return JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT], JS_CLASS_OBJECT);\n}\n\nstatic void js_function_set_properties(JSContext *ctx, JSValueConst func_obj,\n                                       JSAtom name, int len)\n{\n    /* ES6 feature non compatible with ES5.1: length is configurable */\n    JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_length, JS_NewInt32(ctx, len),\n                           JS_PROP_CONFIGURABLE);\n    JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_name,\n                           JS_AtomToString(ctx, name), JS_PROP_CONFIGURABLE);\n}\n\nstatic BOOL js_class_has_bytecode(JSClassID class_id)\n{\n    return (class_id == JS_CLASS_BYTECODE_FUNCTION ||\n            class_id == JS_CLASS_GENERATOR_FUNCTION ||\n            class_id == JS_CLASS_ASYNC_FUNCTION ||\n            class_id == JS_CLASS_ASYNC_GENERATOR_FUNCTION);\n}\n\n/* return NULL without exception if not a function or no bytecode */\nstatic JSFunctionBytecode *JS_GetFunctionBytecode(JSValueConst val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return NULL;\n    p = JS_VALUE_GET_OBJ(val);\n    if (!js_class_has_bytecode(p->class_id))\n        return NULL;\n    return p->u.func.function_bytecode;\n}\n\nstatic void js_method_set_home_object(JSContext *ctx, JSValueConst func_obj,\n                                      JSValueConst home_obj)\n{\n    JSObject *p, *p1;\n    JSFunctionBytecode *b;\n\n    if (JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)\n        return;\n    p = JS_VALUE_GET_OBJ(func_obj);\n    if (!js_class_has_bytecode(p->class_id))\n        return;\n    b = p->u.func.function_bytecode;\n    if (b->need_home_object) {\n        p1 = p->u.func.home_object;\n        if (p1) {\n            JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1));\n        }\n        if (JS_VALUE_GET_TAG(home_obj) == JS_TAG_OBJECT)\n            p1 = JS_VALUE_GET_OBJ(JS_DupValue(ctx, home_obj));\n        else\n            p1 = NULL;\n        p->u.func.home_object = p1;\n    }\n}\n\nstatic JSValue js_get_function_name(JSContext *ctx, JSAtom name)\n{\n    JSValue name_str;\n\n    name_str = JS_AtomToString(ctx, name);\n    if (JS_AtomSymbolHasDescription(ctx, name)) {\n        name_str = JS_ConcatString3(ctx, \"[\", name_str, \"]\");\n    }\n    return name_str;\n}\n\n/* Modify the name of a method according to the atom and\n   'flags'. 'flags' is a bitmask of JS_PROP_HAS_GET and\n   JS_PROP_HAS_SET. Also set the home object of the method.\n   Return < 0 if exception. */\nstatic int js_method_set_properties(JSContext *ctx, JSValueConst func_obj,\n                                    JSAtom name, int flags, JSValueConst home_obj)\n{\n    JSValue name_str;\n\n    name_str = js_get_function_name(ctx, name);\n    if (flags & JS_PROP_HAS_GET) {\n        name_str = JS_ConcatString3(ctx, \"get \", name_str, \"\");\n    } else if (flags & JS_PROP_HAS_SET) {\n        name_str = JS_ConcatString3(ctx, \"set \", name_str, \"\");\n    }\n    if (JS_IsException(name_str))\n        return -1;\n    if (JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_name, name_str,\n                               JS_PROP_CONFIGURABLE) < 0)\n        return -1;\n    js_method_set_home_object(ctx, func_obj, home_obj);\n    return 0;\n}\n\n/* Note: at least 'length' arguments will be readable in 'argv' */\nstatic JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func,\n                                const char *name,\n                                int length, JSCFunctionEnum cproto, int magic,\n                                JSValueConst proto_val)\n{\n    JSValue func_obj;\n    JSObject *p;\n    JSAtom name_atom;\n    \n    func_obj = JS_NewObjectProtoClass(ctx, proto_val, JS_CLASS_C_FUNCTION);\n    if (JS_IsException(func_obj))\n        return func_obj;\n    p = JS_VALUE_GET_OBJ(func_obj);\n    p->u.cfunc.realm = JS_DupContext(ctx);\n    p->u.cfunc.c_function.generic = func;\n    p->u.cfunc.length = length;\n    p->u.cfunc.cproto = cproto;\n    p->u.cfunc.magic = magic;\n    p->is_constructor = (cproto == JS_CFUNC_constructor ||\n                         cproto == JS_CFUNC_constructor_magic ||\n                         cproto == JS_CFUNC_constructor_or_func ||\n                         cproto == JS_CFUNC_constructor_or_func_magic);\n    if (!name)\n        name = \"\";\n    name_atom = JS_NewAtom(ctx, name);\n    js_function_set_properties(ctx, func_obj, name_atom, length);\n    JS_FreeAtom(ctx, name_atom);\n    return func_obj;\n}\n\n/* Note: at least 'length' arguments will be readable in 'argv' */\nJSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,\n                         const char *name,\n                         int length, JSCFunctionEnum cproto, int magic)\n{\n    return JS_NewCFunction3(ctx, func, name, length, cproto, magic,\n                            ctx->function_proto);\n}\n\ntypedef struct JSCFunctionDataRecord {\n    JSCFunctionData *func;\n    uint8_t length;\n    uint8_t data_len;\n    uint16_t magic;\n    JSValue data[0];\n} JSCFunctionDataRecord;\n\nstatic void js_c_function_data_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSCFunctionDataRecord *s = JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA);\n    int i;\n\n    if (s) {\n        for(i = 0; i < s->data_len; i++) {\n            JS_FreeValueRT(rt, s->data[i]);\n        }\n        js_free_rt(rt, s);\n    }\n}\n\nstatic void js_c_function_data_mark(JSRuntime *rt, JSValueConst val,\n                                    JS_MarkFunc *mark_func)\n{\n    JSCFunctionDataRecord *s = JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA);\n    int i;\n\n    if (s) {\n        for(i = 0; i < s->data_len; i++) {\n            JS_MarkValue(rt, s->data[i], mark_func);\n        }\n    }\n}\n\nstatic JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func_obj,\n                                       JSValueConst this_val,\n                                       int argc, JSValueConst *argv, int flags)\n{\n    JSCFunctionDataRecord *s = JS_GetOpaque(func_obj, JS_CLASS_C_FUNCTION_DATA);\n    JSValueConst *arg_buf;\n    int i;\n\n    /* XXX: could add the function on the stack for debug */\n    if (unlikely(argc < s->length)) {\n        arg_buf = alloca(sizeof(arg_buf[0]) * s->length);\n        for(i = 0; i < argc; i++)\n            arg_buf[i] = argv[i];\n        for(i = argc; i < s->length; i++)\n            arg_buf[i] = JS_UNDEFINED;\n    } else {\n        arg_buf = argv;\n    }\n\n    return s->func(ctx, this_val, argc, arg_buf, s->magic, s->data);\n}\n\nJSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,\n                            int length, int magic, int data_len,\n                            JSValueConst *data)\n{\n    JSCFunctionDataRecord *s;\n    JSValue func_obj;\n    int i;\n\n    func_obj = JS_NewObjectProtoClass(ctx, ctx->function_proto,\n                                      JS_CLASS_C_FUNCTION_DATA);\n    if (JS_IsException(func_obj))\n        return func_obj;\n    s = js_malloc(ctx, sizeof(*s) + data_len * sizeof(JSValue));\n    if (!s) {\n        JS_FreeValue(ctx, func_obj);\n        return JS_EXCEPTION;\n    }\n    s->func = func;\n    s->length = length;\n    s->data_len = data_len;\n    s->magic = magic;\n    for(i = 0; i < data_len; i++)\n        s->data[i] = JS_DupValue(ctx, data[i]);\n    JS_SetOpaque(func_obj, s);\n    js_function_set_properties(ctx, func_obj,\n                               JS_ATOM_empty_string, length);\n    return func_obj;\n}\n\nstatic JSContext *js_autoinit_get_realm(JSProperty *pr)\n{\n    return (JSContext *)(pr->u.init.realm_and_id & ~3);\n}\n\nstatic JSAutoInitIDEnum js_autoinit_get_id(JSProperty *pr)\n{\n    return pr->u.init.realm_and_id & 3;\n}\n\nstatic void js_autoinit_free(JSRuntime *rt, JSProperty *pr)\n{\n    JS_FreeContext(js_autoinit_get_realm(pr));\n}\n\nstatic void js_autoinit_mark(JSRuntime *rt, JSProperty *pr,\n                             JS_MarkFunc *mark_func)\n{\n    mark_func(rt, &js_autoinit_get_realm(pr)->header);\n}\n\nstatic void free_property(JSRuntime *rt, JSProperty *pr, int prop_flags)\n{\n    if (unlikely(prop_flags & JS_PROP_TMASK)) {\n        if ((prop_flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n            if (pr->u.getset.getter)\n                JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter));\n            if (pr->u.getset.setter)\n                JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter));\n        } else if ((prop_flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n            free_var_ref(rt, pr->u.var_ref);\n        } else if ((prop_flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n            js_autoinit_free(rt, pr);\n        }\n    } else {\n        JS_FreeValueRT(rt, pr->u.value);\n    }\n}\n\nstatic force_inline JSShapeProperty *find_own_property1(JSObject *p,\n                                                        JSAtom atom)\n{\n    JSShape *sh;\n    JSShapeProperty *pr, *prop;\n    intptr_t h;\n    sh = p->shape;\n    h = (uintptr_t)atom & sh->prop_hash_mask;\n    h = sh->prop_hash_end[-h - 1];\n    prop = get_shape_prop(sh);\n    while (h) {\n        pr = &prop[h - 1];\n        if (likely(pr->atom == atom)) {\n            return pr;\n        }\n        h = pr->hash_next;\n    }\n    return NULL;\n}\n\nstatic force_inline JSShapeProperty *find_own_property(JSProperty **ppr,\n                                                       JSObject *p,\n                                                       JSAtom atom)\n{\n    JSShape *sh;\n    JSShapeProperty *pr, *prop;\n    intptr_t h;\n    sh = p->shape;\n    h = (uintptr_t)atom & sh->prop_hash_mask;\n    h = sh->prop_hash_end[-h - 1];\n    prop = get_shape_prop(sh);\n    while (h) {\n        pr = &prop[h - 1];\n        if (likely(pr->atom == atom)) {\n            *ppr = &p->prop[h - 1];\n            /* the compiler should be able to assume that pr != NULL here */\n            return pr;\n        }\n        h = pr->hash_next;\n    }\n    *ppr = NULL;\n    return NULL;\n}\n\n/* indicate that the object may be part of a function prototype cycle */\nstatic void set_cycle_flag(JSContext *ctx, JSValueConst obj)\n{\n}\n\nstatic void free_var_ref(JSRuntime *rt, JSVarRef *var_ref)\n{\n    if (var_ref) {\n        assert(var_ref->header.ref_count > 0);\n        if (--var_ref->header.ref_count == 0) {\n            if (var_ref->is_detached) {\n                JS_FreeValueRT(rt, var_ref->value);\n                remove_gc_object(&var_ref->header);\n            } else {\n                list_del(&var_ref->header.link); /* still on the stack */\n            }\n            js_free_rt(rt, var_ref);\n        }\n    }\n}\n\nstatic void js_array_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    int i;\n\n    for(i = 0; i < p->u.array.count; i++) {\n        JS_FreeValueRT(rt, p->u.array.u.values[i]);\n    }\n    js_free_rt(rt, p->u.array.u.values);\n}\n\nstatic void js_array_mark(JSRuntime *rt, JSValueConst val,\n                          JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    int i;\n\n    for(i = 0; i < p->u.array.count; i++) {\n        JS_MarkValue(rt, p->u.array.u.values[i], mark_func);\n    }\n}\n\nstatic void js_object_data_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JS_FreeValueRT(rt, p->u.object_data);\n    p->u.object_data = JS_UNDEFINED;\n}\n\nstatic void js_object_data_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JS_MarkValue(rt, p->u.object_data, mark_func);\n}\n\nstatic void js_c_function_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n\n    if (p->u.cfunc.realm)\n        JS_FreeContext(p->u.cfunc.realm);\n}\n\nstatic void js_c_function_mark(JSRuntime *rt, JSValueConst val,\n                               JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n\n    if (p->u.cfunc.realm)\n        mark_func(rt, &p->u.cfunc.realm->header);\n}\n\nstatic void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p1, *p = JS_VALUE_GET_OBJ(val);\n    JSFunctionBytecode *b;\n    JSVarRef **var_refs;\n    int i;\n\n    p1 = p->u.func.home_object;\n    if (p1) {\n        JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, p1));\n    }\n    b = p->u.func.function_bytecode;\n    if (b) {\n        var_refs = p->u.func.var_refs;\n        if (var_refs) {\n            for(i = 0; i < b->closure_var_count; i++)\n                free_var_ref(rt, var_refs[i]);\n            js_free_rt(rt, var_refs);\n        }\n        JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_FUNCTION_BYTECODE, b));\n    }\n}\n\nstatic void js_bytecode_function_mark(JSRuntime *rt, JSValueConst val,\n                                      JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSVarRef **var_refs = p->u.func.var_refs;\n    JSFunctionBytecode *b = p->u.func.function_bytecode;\n    int i;\n\n    if (p->u.func.home_object) {\n        JS_MarkValue(rt, JS_MKPTR(JS_TAG_OBJECT, p->u.func.home_object),\n                     mark_func);\n    }\n    if (b) {\n        if (var_refs) {\n            for(i = 0; i < b->closure_var_count; i++) {\n                JSVarRef *var_ref = var_refs[i];\n                if (var_ref && var_ref->is_detached) {\n                    mark_func(rt, &var_ref->header);\n                }\n            }\n        }\n        /* must mark the function bytecode because template objects may be\n           part of a cycle */\n        JS_MarkValue(rt, JS_MKPTR(JS_TAG_FUNCTION_BYTECODE, b), mark_func);\n    }\n}\n\nstatic void js_bound_function_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSBoundFunction *bf = p->u.bound_function;\n    int i;\n\n    JS_FreeValueRT(rt, bf->func_obj);\n    JS_FreeValueRT(rt, bf->this_val);\n    for(i = 0; i < bf->argc; i++) {\n        JS_FreeValueRT(rt, bf->argv[i]);\n    }\n    js_free_rt(rt, bf);\n}\n\nstatic void js_bound_function_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSBoundFunction *bf = p->u.bound_function;\n    int i;\n\n    JS_MarkValue(rt, bf->func_obj, mark_func);\n    JS_MarkValue(rt, bf->this_val, mark_func);\n    for(i = 0; i < bf->argc; i++)\n        JS_MarkValue(rt, bf->argv[i], mark_func);\n}\n\nstatic void js_for_in_iterator_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSForInIterator *it = p->u.for_in_iterator;\n    JS_FreeValueRT(rt, it->obj);\n    js_free_rt(rt, it);\n}\n\nstatic void js_for_in_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSForInIterator *it = p->u.for_in_iterator;\n    JS_MarkValue(rt, it->obj, mark_func);\n}\n\nstatic void free_object(JSRuntime *rt, JSObject *p)\n{\n    int i;\n    JSClassFinalizer *finalizer;\n    JSShape *sh;\n    JSShapeProperty *pr;\n\n    p->free_mark = 1; /* used to tell the object is invalid when\n                         freeing cycles */\n    /* free all the fields */\n    sh = p->shape;\n    pr = get_shape_prop(sh);\n    for(i = 0; i < sh->prop_count; i++) {\n        free_property(rt, &p->prop[i], pr->flags);\n        pr++;\n    }\n    js_free_rt(rt, p->prop);\n    /* as an optimization we destroy the shape immediately without\n       putting it in gc_zero_ref_count_list */\n    js_free_shape(rt, sh);\n\n    /* fail safe */\n    p->shape = NULL;\n    p->prop = NULL;\n\n    if (unlikely(p->first_weak_ref)) {\n        reset_weak_ref(rt, p);\n    }\n\n    finalizer = rt->class_array[p->class_id].finalizer;\n    if (finalizer)\n        (*finalizer)(rt, JS_MKPTR(JS_TAG_OBJECT, p));\n\n    /* fail safe */\n    p->class_id = 0;\n    p->u.opaque = NULL;\n    p->u.func.var_refs = NULL;\n    p->u.func.home_object = NULL;\n\n    remove_gc_object(&p->header);\n    if (rt->gc_phase == JS_GC_PHASE_REMOVE_CYCLES && p->header.ref_count != 0) {\n        list_add_tail(&p->header.link, &rt->gc_zero_ref_count_list);\n    } else {\n        js_free_rt(rt, p);\n    }\n}\n\nstatic void free_gc_object(JSRuntime *rt, JSGCObjectHeader *gp)\n{\n    switch(gp->gc_obj_type) {\n    case JS_GC_OBJ_TYPE_JS_OBJECT:\n        free_object(rt, (JSObject *)gp);\n        break;\n    case JS_GC_OBJ_TYPE_FUNCTION_BYTECODE:\n        free_function_bytecode(rt, (JSFunctionBytecode *)gp);\n        break;\n    default:\n        abort();\n    }\n}\n\nstatic void free_zero_refcount(JSRuntime *rt)\n{\n    struct list_head *el;\n    JSGCObjectHeader *p;\n    \n    rt->gc_phase = JS_GC_PHASE_DECREF;\n    for(;;) {\n        el = rt->gc_zero_ref_count_list.next;\n        if (el == &rt->gc_zero_ref_count_list)\n            break;\n        p = list_entry(el, JSGCObjectHeader, link);\n        assert(p->ref_count == 0);\n        free_gc_object(rt, p);\n    }\n    rt->gc_phase = JS_GC_PHASE_NONE;\n}\n\n/* called with the ref_count of 'v' reaches zero. */\nvoid __JS_FreeValueRT(JSRuntime *rt, JSValue v)\n{\n    uint32_t tag = JS_VALUE_GET_TAG(v);\n\n#ifdef DUMP_FREE\n    {\n        printf(\"Freeing \");\n        if (tag == JS_TAG_OBJECT) {\n            JS_DumpObject(rt, JS_VALUE_GET_OBJ(v));\n        } else {\n            JS_DumpValueShort(rt, v);\n            printf(\"\\n\");\n        }\n    }\n#endif\n\n    switch(tag) {\n    case JS_TAG_STRING:\n        {\n            JSString *p = JS_VALUE_GET_STRING(v);\n            if (p->atom_type) {\n                JS_FreeAtomStruct(rt, p);\n            } else {\n#ifdef DUMP_LEAKS\n                list_del(&p->link);\n#endif\n                js_free_rt(rt, p);\n            }\n        }\n        break;\n    case JS_TAG_OBJECT:\n    case JS_TAG_FUNCTION_BYTECODE:\n        {\n            JSGCObjectHeader *p = JS_VALUE_GET_PTR(v);\n            if (rt->gc_phase != JS_GC_PHASE_REMOVE_CYCLES) {\n                list_del(&p->link);\n                list_add(&p->link, &rt->gc_zero_ref_count_list);\n                if (rt->gc_phase == JS_GC_PHASE_NONE) {\n                    free_zero_refcount(rt);\n                }\n            }\n        }\n        break;\n    case JS_TAG_MODULE:\n        abort(); /* never freed here */\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *bf = JS_VALUE_GET_PTR(v);\n            bf_delete(&bf->num);\n            js_free_rt(rt, bf);\n        }\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        {\n            JSBigDecimal *bf = JS_VALUE_GET_PTR(v);\n            bfdec_delete(&bf->num);\n            js_free_rt(rt, bf);\n        }\n        break;\n#endif\n    case JS_TAG_SYMBOL:\n        {\n            JSAtomStruct *p = JS_VALUE_GET_PTR(v);\n            JS_FreeAtomStruct(rt, p);\n        }\n        break;\n    default:\n        printf(\"__JS_FreeValue: unknown tag=%d\\n\", tag);\n        abort();\n    }\n}\n\nvoid __JS_FreeValue(JSContext *ctx, JSValue v)\n{\n    __JS_FreeValueRT(ctx->rt, v);\n}\n\n/* garbage collection */\n\nstatic void add_gc_object(JSRuntime *rt, JSGCObjectHeader *h,\n                          JSGCObjectTypeEnum type)\n{\n    h->mark = 0;\n    h->gc_obj_type = type;\n    list_add_tail(&h->link, &rt->gc_obj_list);\n}\n\nstatic void remove_gc_object(JSGCObjectHeader *h)\n{\n    list_del(&h->link);\n}\n\nvoid JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)\n{\n    if (JS_VALUE_HAS_REF_COUNT(val)) {\n        switch(JS_VALUE_GET_TAG(val)) {\n        case JS_TAG_OBJECT:\n        case JS_TAG_FUNCTION_BYTECODE:\n            mark_func(rt, JS_VALUE_GET_PTR(val));\n            break;\n        default:\n            break;\n        }\n    }\n}\n\nstatic void mark_children(JSRuntime *rt, JSGCObjectHeader *gp,\n                          JS_MarkFunc *mark_func)\n{\n    switch(gp->gc_obj_type) {\n    case JS_GC_OBJ_TYPE_JS_OBJECT:\n        {\n            JSObject *p = (JSObject *)gp;\n            JSShapeProperty *prs;\n            JSShape *sh;\n            int i;\n            sh = p->shape;\n            mark_func(rt, &sh->header);\n            /* mark all the fields */\n            prs = get_shape_prop(sh);\n            for(i = 0; i < sh->prop_count; i++) {\n                JSProperty *pr = &p->prop[i];\n                if (prs->atom != JS_ATOM_NULL) {\n                    if (prs->flags & JS_PROP_TMASK) {\n                        if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n                            if (pr->u.getset.getter)\n                                mark_func(rt, &pr->u.getset.getter->header);\n                            if (pr->u.getset.setter)\n                                mark_func(rt, &pr->u.getset.setter->header);\n                        } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                            if (pr->u.var_ref->is_detached) {\n                                /* Note: the tag does not matter\n                                   provided it is a GC object */\n                                mark_func(rt, &pr->u.var_ref->header);\n                            }\n                        } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                            js_autoinit_mark(rt, pr, mark_func);\n                        }\n                    } else {\n                        JS_MarkValue(rt, pr->u.value, mark_func);\n                    }\n                }\n                prs++;\n            }\n\n            if (p->class_id != JS_CLASS_OBJECT) {\n                JSClassGCMark *gc_mark;\n                gc_mark = rt->class_array[p->class_id].gc_mark;\n                if (gc_mark)\n                    gc_mark(rt, JS_MKPTR(JS_TAG_OBJECT, p), mark_func);\n            }\n        }\n        break;\n    case JS_GC_OBJ_TYPE_FUNCTION_BYTECODE:\n        /* the template objects can be part of a cycle */\n        {\n            JSFunctionBytecode *b = (JSFunctionBytecode *)gp;\n            int i;\n            for(i = 0; i < b->cpool_count; i++) {\n                JS_MarkValue(rt, b->cpool[i], mark_func);\n            }\n            if (b->realm)\n                mark_func(rt, &b->realm->header);\n        }\n        break;\n    case JS_GC_OBJ_TYPE_VAR_REF:\n        {\n            JSVarRef *var_ref = (JSVarRef *)gp;\n            /* only detached variable referenced are taken into account */\n            assert(var_ref->is_detached);\n            JS_MarkValue(rt, *var_ref->pvalue, mark_func);\n        }\n        break;\n    case JS_GC_OBJ_TYPE_ASYNC_FUNCTION:\n        {\n            JSAsyncFunctionData *s = (JSAsyncFunctionData *)gp;\n            if (s->is_active)\n                async_func_mark(rt, &s->func_state, mark_func);\n            JS_MarkValue(rt, s->resolving_funcs[0], mark_func);\n            JS_MarkValue(rt, s->resolving_funcs[1], mark_func);\n        }\n        break;\n    case JS_GC_OBJ_TYPE_SHAPE:\n        {\n            JSShape *sh = (JSShape *)gp;\n            if (sh->proto != NULL) {\n                mark_func(rt, &sh->proto->header);\n            }\n        }\n        break;\n    case JS_GC_OBJ_TYPE_JS_CONTEXT:\n        {\n            JSContext *ctx = (JSContext *)gp;\n            JS_MarkContext(rt, ctx, mark_func);\n        }\n        break;\n    default:\n        abort();\n    }\n}\n\nstatic void gc_decref_child(JSRuntime *rt, JSGCObjectHeader *p)\n{\n    assert(p->ref_count > 0);\n    p->ref_count--;\n    if (p->ref_count == 0 && p->mark == 1) {\n        list_del(&p->link);\n        list_add_tail(&p->link, &rt->tmp_obj_list);\n    }\n}\n\nstatic void gc_decref(JSRuntime *rt)\n{\n    struct list_head *el, *el1;\n    JSGCObjectHeader *p;\n    \n    init_list_head(&rt->tmp_obj_list);\n\n    /* decrement the refcount of all the children of all the GC\n       objects and move the GC objects with zero refcount to\n       tmp_obj_list */\n    list_for_each_safe(el, el1, &rt->gc_obj_list) {\n        p = list_entry(el, JSGCObjectHeader, link);\n        assert(p->mark == 0);\n        mark_children(rt, p, gc_decref_child);\n        p->mark = 1;\n        if (p->ref_count == 0) {\n            list_del(&p->link);\n            list_add_tail(&p->link, &rt->tmp_obj_list);\n        }\n    }\n}\n\nstatic void gc_scan_incref_child(JSRuntime *rt, JSGCObjectHeader *p)\n{\n    p->ref_count++;\n    if (p->ref_count == 1) {\n        /* ref_count was 0: remove from tmp_obj_list and add at the\n           end of gc_obj_list */\n        list_del(&p->link);\n        list_add_tail(&p->link, &rt->gc_obj_list);\n        p->mark = 0; /* reset the mark for the next GC call */\n    }\n}\n\nstatic void gc_scan_incref_child2(JSRuntime *rt, JSGCObjectHeader *p)\n{\n    p->ref_count++;\n}\n\nstatic void gc_scan(JSRuntime *rt)\n{\n    struct list_head *el;\n    JSGCObjectHeader *p;\n\n    /* keep the objects with a refcount > 0 and their children. */\n    list_for_each(el, &rt->gc_obj_list) {\n        p = list_entry(el, JSGCObjectHeader, link);\n        assert(p->ref_count > 0);\n        p->mark = 0; /* reset the mark for the next GC call */\n        mark_children(rt, p, gc_scan_incref_child);\n    }\n    \n    /* restore the refcount of the objects to be deleted. */\n    list_for_each(el, &rt->tmp_obj_list) {\n        p = list_entry(el, JSGCObjectHeader, link);\n        mark_children(rt, p, gc_scan_incref_child2);\n    }\n}\n\nstatic void gc_free_cycles(JSRuntime *rt)\n{\n    struct list_head *el, *el1;\n    JSGCObjectHeader *p;\n#ifdef DUMP_GC_FREE\n    BOOL header_done = FALSE;\n#endif\n\n    rt->gc_phase = JS_GC_PHASE_REMOVE_CYCLES;\n\n    for(;;) {\n        el = rt->tmp_obj_list.next;\n        if (el == &rt->tmp_obj_list)\n            break;\n        p = list_entry(el, JSGCObjectHeader, link);\n        /* Only need to free the GC object associated with JS\n           values. The rest will be automatically removed because they\n           must be referenced by them. */\n        switch(p->gc_obj_type) {\n        case JS_GC_OBJ_TYPE_JS_OBJECT:\n        case JS_GC_OBJ_TYPE_FUNCTION_BYTECODE:\n#ifdef DUMP_GC_FREE\n            if (!header_done) {\n                printf(\"Freeing cycles:\\n\");\n                JS_DumpObjectHeader(rt);\n                header_done = TRUE;\n            }\n            JS_DumpGCObject(rt, p);\n#endif\n            free_gc_object(rt, p);\n            break;\n        default:\n            list_del(&p->link);\n            list_add_tail(&p->link, &rt->gc_zero_ref_count_list);\n            break;\n        }\n    }\n    rt->gc_phase = JS_GC_PHASE_NONE;\n           \n    list_for_each_safe(el, el1, &rt->gc_zero_ref_count_list) {\n        p = list_entry(el, JSGCObjectHeader, link);\n        assert(p->gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT ||\n               p->gc_obj_type == JS_GC_OBJ_TYPE_FUNCTION_BYTECODE);\n        js_free_rt(rt, p);\n    }\n\n    init_list_head(&rt->gc_zero_ref_count_list);\n}\n\nvoid JS_RunGC(JSRuntime *rt)\n{\n    /* decrement the reference of the children of each object. mark =\n       1 after this pass. */\n    gc_decref(rt);\n\n    /* keep the GC objects with a non zero refcount and their childs */\n    gc_scan(rt);\n\n    /* free the GC objects in a cycle */\n    gc_free_cycles(rt);\n}\n\n/* Return false if not an object or if the object has already been\n   freed (zombie objects are visible in finalizers when freeing\n   cycles). */\nBOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj)\n{\n    JSObject *p;\n    if (!JS_IsObject(obj))\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(obj);\n    return !p->free_mark;\n}\n\n/* Compute memory used by various object types */\n/* XXX: poor man's approach to handling multiply referenced objects */\ntypedef struct JSMemoryUsage_helper {\n    double memory_used_count;\n    double str_count;\n    double str_size;\n    int64_t js_func_count;\n    double js_func_size;\n    int64_t js_func_code_size;\n    int64_t js_func_pc2line_count;\n    int64_t js_func_pc2line_size;\n} JSMemoryUsage_helper;\n\nstatic void compute_value_size(JSValueConst val, JSMemoryUsage_helper *hp);\n\nstatic void compute_jsstring_size(JSString *str, JSMemoryUsage_helper *hp)\n{\n    if (!str->atom_type) {  /* atoms are handled separately */\n        double s_ref_count = str->header.ref_count;\n        hp->str_count += 1 / s_ref_count;\n        hp->str_size += ((sizeof(*str) + (str->len << str->is_wide_char) +\n                          1 - str->is_wide_char) / s_ref_count);\n    }\n}\n\nstatic void compute_bytecode_size(JSFunctionBytecode *b, JSMemoryUsage_helper *hp)\n{\n    int memory_used_count, js_func_size, i;\n\n    memory_used_count = 0;\n    js_func_size = offsetof(JSFunctionBytecode, debug);\n    if (b->vardefs) {\n        js_func_size += (b->arg_count + b->var_count) * sizeof(*b->vardefs);\n    }\n    if (b->cpool) {\n        js_func_size += b->cpool_count * sizeof(*b->cpool);\n        for (i = 0; i < b->cpool_count; i++) {\n            JSValueConst val = b->cpool[i];\n            compute_value_size(val, hp);\n        }\n    }\n    if (b->closure_var) {\n        js_func_size += b->closure_var_count * sizeof(*b->closure_var);\n    }\n    if (!b->read_only_bytecode && b->byte_code_buf) {\n        hp->js_func_code_size += b->byte_code_len;\n    }\n    if (b->has_debug) {\n        js_func_size += sizeof(*b) - offsetof(JSFunctionBytecode, debug);\n        if (b->debug.source) {\n            memory_used_count++;\n            js_func_size += b->debug.source_len + 1;\n        }\n        if (b->debug.pc2line_len) {\n            memory_used_count++;\n            hp->js_func_pc2line_count += 1;\n            hp->js_func_pc2line_size += b->debug.pc2line_len;\n        }\n    }\n    hp->js_func_size += js_func_size;\n    hp->js_func_count += 1;\n    hp->memory_used_count += memory_used_count;\n}\n\nstatic void compute_value_size(JSValueConst val, JSMemoryUsage_helper *hp)\n{\n    switch(JS_VALUE_GET_TAG(val)) {\n    case JS_TAG_STRING:\n        compute_jsstring_size(JS_VALUE_GET_STRING(val), hp);\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n    case JS_TAG_BIG_DECIMAL:\n        /* should track JSBigFloat usage */\n        break;\n#endif\n    }\n}\n\nvoid JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s)\n{\n    struct list_head *el, *el1;\n    int i;\n    JSMemoryUsage_helper mem = { 0 }, *hp = &mem;\n\n    memset(s, 0, sizeof(*s));\n    s->malloc_count = rt->malloc_state.malloc_count;\n    s->malloc_size = rt->malloc_state.malloc_size;\n    s->malloc_limit = rt->malloc_state.malloc_limit;\n\n    s->memory_used_count = 2; /* rt + rt->class_array */\n    s->memory_used_size = sizeof(JSRuntime) + sizeof(JSValue) * rt->class_count;\n\n    list_for_each(el, &rt->context_list) {\n        JSContext *ctx = list_entry(el, JSContext, link);\n        JSShape *sh = ctx->array_shape;\n        s->memory_used_count += 2; /* ctx + ctx->class_proto */\n        s->memory_used_size += sizeof(JSContext) +\n            sizeof(JSValue) * rt->class_count;\n        s->binary_object_count += ctx->binary_object_count;\n        s->binary_object_size += ctx->binary_object_size;\n\n        /* the hashed shapes are counted separately */\n        if (sh && !sh->is_hashed) {\n            int hash_size = sh->prop_hash_mask + 1;\n            s->shape_count++;\n            s->shape_size += get_shape_size(hash_size, sh->prop_size);\n        }\n        list_for_each(el1, &ctx->loaded_modules) {\n            JSModuleDef *m = list_entry(el1, JSModuleDef, link);\n            s->memory_used_count += 1;\n            s->memory_used_size += sizeof(*m);\n            if (m->req_module_entries) {\n                s->memory_used_count += 1;\n                s->memory_used_size += m->req_module_entries_count * sizeof(*m->req_module_entries);\n            }\n            if (m->export_entries) {\n                s->memory_used_count += 1;\n                s->memory_used_size += m->export_entries_count * sizeof(*m->export_entries);\n                for (i = 0; i < m->export_entries_count; i++) {\n                    JSExportEntry *me = &m->export_entries[i];\n                    if (me->export_type == JS_EXPORT_TYPE_LOCAL && me->u.local.var_ref) {\n                        /* potential multiple count */\n                        s->memory_used_count += 1;\n                        compute_value_size(me->u.local.var_ref->value, hp);\n                    }\n                }\n            }\n            if (m->star_export_entries) {\n                s->memory_used_count += 1;\n                s->memory_used_size += m->star_export_entries_count * sizeof(*m->star_export_entries);\n            }\n            if (m->import_entries) {\n                s->memory_used_count += 1;\n                s->memory_used_size += m->import_entries_count * sizeof(*m->import_entries);\n            }\n            compute_value_size(m->module_ns, hp);\n            compute_value_size(m->func_obj, hp);\n        }\n    }\n\n    list_for_each(el, &rt->gc_obj_list) {\n        JSGCObjectHeader *gp = list_entry(el, JSGCObjectHeader, link);\n        JSObject *p;\n        JSShape *sh;\n        JSShapeProperty *prs;\n\n        /* XXX: could count the other GC object types too */\n        if (gp->gc_obj_type == JS_GC_OBJ_TYPE_FUNCTION_BYTECODE) {\n            compute_bytecode_size((JSFunctionBytecode *)gp, hp);\n            continue;\n        } else if (gp->gc_obj_type != JS_GC_OBJ_TYPE_JS_OBJECT) {\n            continue;\n        }\n        p = (JSObject *)gp;\n        sh = p->shape;\n        s->obj_count++;\n        if (p->prop) {\n            s->memory_used_count++;\n            s->prop_size += sh->prop_size * sizeof(*p->prop);\n            s->prop_count += sh->prop_count;\n            prs = get_shape_prop(sh);\n            for(i = 0; i < sh->prop_count; i++) {\n                JSProperty *pr = &p->prop[i];\n                if (prs->atom != JS_ATOM_NULL && !(prs->flags & JS_PROP_TMASK)) {\n                    compute_value_size(pr->u.value, hp);\n                }\n                prs++;\n            }\n        }\n        /* the hashed shapes are counted separately */\n        if (!sh->is_hashed) {\n            int hash_size = sh->prop_hash_mask + 1;\n            s->shape_count++;\n            s->shape_size += get_shape_size(hash_size, sh->prop_size);\n        }\n\n        switch(p->class_id) {\n        case JS_CLASS_ARRAY:             /* u.array | length */\n        case JS_CLASS_ARGUMENTS:         /* u.array | length */\n            s->array_count++;\n            if (p->fast_array) {\n                s->fast_array_count++;\n                if (p->u.array.u.values) {\n                    s->memory_used_count++;\n                    s->memory_used_size += p->u.array.count *\n                        sizeof(*p->u.array.u.values);\n                    s->fast_array_elements += p->u.array.count;\n                    for (i = 0; i < p->u.array.count; i++) {\n                        compute_value_size(p->u.array.u.values[i], hp);\n                    }\n                }\n            }\n            break;\n        case JS_CLASS_NUMBER:            /* u.object_data */\n        case JS_CLASS_STRING:            /* u.object_data */\n        case JS_CLASS_BOOLEAN:           /* u.object_data */\n        case JS_CLASS_SYMBOL:            /* u.object_data */\n        case JS_CLASS_DATE:              /* u.object_data */\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT:           /* u.object_data */\n        case JS_CLASS_BIG_FLOAT:         /* u.object_data */\n        case JS_CLASS_BIG_DECIMAL:         /* u.object_data */\n#endif\n            compute_value_size(p->u.object_data, hp);\n            break;\n        case JS_CLASS_C_FUNCTION:        /* u.cfunc */\n            s->c_func_count++;\n            break;\n        case JS_CLASS_BYTECODE_FUNCTION: /* u.func */\n            {\n                JSFunctionBytecode *b = p->u.func.function_bytecode;\n                JSVarRef **var_refs = p->u.func.var_refs;\n                /* home_object: object will be accounted for in list scan */\n                if (var_refs) {\n                    s->memory_used_count++;\n                    s->js_func_size += b->closure_var_count * sizeof(*var_refs);\n                    for (i = 0; i < b->closure_var_count; i++) {\n                        if (var_refs[i]) {\n                            double ref_count = var_refs[i]->header.ref_count;\n                            s->memory_used_count += 1 / ref_count;\n                            s->js_func_size += sizeof(*var_refs[i]) / ref_count;\n                            /* handle non object closed values */\n                            if (var_refs[i]->pvalue == &var_refs[i]->value) {\n                                /* potential multiple count */\n                                compute_value_size(var_refs[i]->value, hp);\n                            }\n                        }\n                    }\n                }\n            }\n            break;\n        case JS_CLASS_BOUND_FUNCTION:    /* u.bound_function */\n            {\n                JSBoundFunction *bf = p->u.bound_function;\n                /* func_obj and this_val are objects */\n                for (i = 0; i < bf->argc; i++) {\n                    compute_value_size(bf->argv[i], hp);\n                }\n                s->memory_used_count += 1;\n                s->memory_used_size += sizeof(*bf) + bf->argc * sizeof(*bf->argv);\n            }\n            break;\n        case JS_CLASS_C_FUNCTION_DATA:   /* u.c_function_data_record */\n            {\n                JSCFunctionDataRecord *fd = p->u.c_function_data_record;\n                if (fd) {\n                    for (i = 0; i < fd->data_len; i++) {\n                        compute_value_size(fd->data[i], hp);\n                    }\n                    s->memory_used_count += 1;\n                    s->memory_used_size += sizeof(*fd) + fd->data_len * sizeof(*fd->data);\n                }\n            }\n            break;\n        case JS_CLASS_REGEXP:            /* u.regexp */\n            compute_jsstring_size(p->u.regexp.pattern, hp);\n            compute_jsstring_size(p->u.regexp.bytecode, hp);\n            break;\n\n        case JS_CLASS_FOR_IN_ITERATOR:   /* u.for_in_iterator */\n            {\n                JSForInIterator *it = p->u.for_in_iterator;\n                if (it) {\n                    compute_value_size(it->obj, hp);\n                    s->memory_used_count += 1;\n                    s->memory_used_size += sizeof(*it);\n                }\n            }\n            break;\n        case JS_CLASS_ARRAY_BUFFER:      /* u.array_buffer */\n        case JS_CLASS_SHARED_ARRAY_BUFFER: /* u.array_buffer */\n            {\n                JSArrayBuffer *abuf = p->u.array_buffer;\n                if (abuf) {\n                    s->memory_used_count += 1;\n                    s->memory_used_size += sizeof(*abuf);\n                    if (abuf->data) {\n                        s->memory_used_count += 1;\n                        s->memory_used_size += abuf->byte_length;\n                    }\n                }\n            }\n            break;\n        case JS_CLASS_GENERATOR:         /* u.generator_data */\n        case JS_CLASS_UINT8C_ARRAY:      /* u.typed_array / u.array */\n        case JS_CLASS_INT8_ARRAY:        /* u.typed_array / u.array */\n        case JS_CLASS_UINT8_ARRAY:       /* u.typed_array / u.array */\n        case JS_CLASS_INT16_ARRAY:       /* u.typed_array / u.array */\n        case JS_CLASS_UINT16_ARRAY:      /* u.typed_array / u.array */\n        case JS_CLASS_INT32_ARRAY:       /* u.typed_array / u.array */\n        case JS_CLASS_UINT32_ARRAY:      /* u.typed_array / u.array */\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT64_ARRAY:   /* u.typed_array / u.array */\n        case JS_CLASS_BIG_UINT64_ARRAY:  /* u.typed_array / u.array */\n#endif\n        case JS_CLASS_FLOAT32_ARRAY:     /* u.typed_array / u.array */\n        case JS_CLASS_FLOAT64_ARRAY:     /* u.typed_array / u.array */\n        case JS_CLASS_DATAVIEW:          /* u.typed_array */\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_FLOAT_ENV:         /* u.float_env */\n#endif\n        case JS_CLASS_MAP:               /* u.map_state */\n        case JS_CLASS_SET:               /* u.map_state */\n        case JS_CLASS_WEAKMAP:           /* u.map_state */\n        case JS_CLASS_WEAKSET:           /* u.map_state */\n        case JS_CLASS_MAP_ITERATOR:      /* u.map_iterator_data */\n        case JS_CLASS_SET_ITERATOR:      /* u.map_iterator_data */\n        case JS_CLASS_ARRAY_ITERATOR:    /* u.array_iterator_data */\n        case JS_CLASS_STRING_ITERATOR:   /* u.array_iterator_data */\n        case JS_CLASS_PROXY:             /* u.proxy_data */\n        case JS_CLASS_PROMISE:           /* u.promise_data */\n        case JS_CLASS_PROMISE_RESOLVE_FUNCTION:  /* u.promise_function_data */\n        case JS_CLASS_PROMISE_REJECT_FUNCTION:   /* u.promise_function_data */\n        case JS_CLASS_ASYNC_FUNCTION_RESOLVE:    /* u.async_function_data */\n        case JS_CLASS_ASYNC_FUNCTION_REJECT:     /* u.async_function_data */\n        case JS_CLASS_ASYNC_FROM_SYNC_ITERATOR:  /* u.async_from_sync_iterator_data */\n        case JS_CLASS_ASYNC_GENERATOR:   /* u.async_generator_data */\n            /* TODO */\n        default:\n            /* XXX: class definition should have an opaque block size */\n            if (p->u.opaque) {\n                s->memory_used_count += 1;\n            }\n            break;\n        }\n    }\n    s->obj_size += s->obj_count * sizeof(JSObject);\n\n    /* hashed shapes */\n    s->memory_used_count++; /* rt->shape_hash */\n    s->memory_used_size += sizeof(rt->shape_hash[0]) * rt->shape_hash_size;\n    for(i = 0; i < rt->shape_hash_size; i++) {\n        JSShape *sh;\n        for(sh = rt->shape_hash[i]; sh != NULL; sh = sh->shape_hash_next) {\n            int hash_size = sh->prop_hash_mask + 1;\n            s->shape_count++;\n            s->shape_size += get_shape_size(hash_size, sh->prop_size);\n        }\n    }\n\n    /* atoms */\n    s->memory_used_count += 2; /* rt->atom_array, rt->atom_hash */\n    s->atom_count = rt->atom_count;\n    s->atom_size = sizeof(rt->atom_array[0]) * rt->atom_size +\n        sizeof(rt->atom_hash[0]) * rt->atom_hash_size;\n    for(i = 0; i < rt->atom_size; i++) {\n        JSAtomStruct *p = rt->atom_array[i];\n        if (!atom_is_free(p)) {\n            s->atom_size += (sizeof(*p) + (p->len << p->is_wide_char) +\n                             1 - p->is_wide_char);\n        }\n    }\n    s->str_count = round(mem.str_count);\n    s->str_size = round(mem.str_size);\n    s->js_func_count = mem.js_func_count;\n    s->js_func_size = round(mem.js_func_size);\n    s->js_func_code_size = mem.js_func_code_size;\n    s->js_func_pc2line_count = mem.js_func_pc2line_count;\n    s->js_func_pc2line_size = mem.js_func_pc2line_size;\n    s->memory_used_count += round(mem.memory_used_count) +\n        s->atom_count + s->str_count +\n        s->obj_count + s->shape_count +\n        s->js_func_count + s->js_func_pc2line_count;\n    s->memory_used_size += s->atom_size + s->str_size +\n        s->obj_size + s->prop_size + s->shape_size +\n        s->js_func_size + s->js_func_code_size + s->js_func_pc2line_size;\n}\n\nvoid JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt)\n{\n    fprintf(fp, \"QuickJS memory usage -- \"\n#ifdef CONFIG_BIGNUM\n            \"BigNum \"\n#endif\n            CONFIG_VERSION \" version, %d-bit, malloc limit: %\"PRId64\"\\n\\n\",\n            (int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit);\n#if 1\n    if (rt) {\n        static const struct {\n            const char *name;\n            size_t size;\n        } object_types[] = {\n            { \"JSRuntime\", sizeof(JSRuntime) },\n            { \"JSContext\", sizeof(JSContext) },\n            { \"JSObject\", sizeof(JSObject) },\n            { \"JSString\", sizeof(JSString) },\n            { \"JSFunctionBytecode\", sizeof(JSFunctionBytecode) },\n        };\n        int i, usage_size_ok = 0;\n        for(i = 0; i < countof(object_types); i++) {\n            unsigned int size = object_types[i].size;\n            void *p = js_malloc_rt(rt, size);\n            if (p) {\n                unsigned int size1 = js_malloc_usable_size_rt(rt, p);\n                if (size1 >= size) {\n                    usage_size_ok = 1;\n                    fprintf(fp, \"  %3u + %-2u  %s\\n\",\n                            size, size1 - size, object_types[i].name);\n                }\n                js_free_rt(rt, p);\n            }\n        }\n        if (!usage_size_ok) {\n            fprintf(fp, \"  malloc_usable_size unavailable\\n\");\n        }\n        {\n            int obj_classes[JS_CLASS_INIT_COUNT + 1] = { 0 };\n            int class_id;\n            struct list_head *el;\n            list_for_each(el, &rt->gc_obj_list) {\n                JSGCObjectHeader *gp = list_entry(el, JSGCObjectHeader, link);\n                JSObject *p;\n                if (gp->gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT) {\n                    p = (JSObject *)gp;\n                    obj_classes[min_uint32(p->class_id, JS_CLASS_INIT_COUNT)]++;\n                }\n            }\n            fprintf(fp, \"\\n\" \"JSObject classes\\n\");\n            if (obj_classes[0])\n                fprintf(fp, \"  %5d  %2.0d %s\\n\", obj_classes[0], 0, \"none\");\n            for (class_id = 1; class_id < JS_CLASS_INIT_COUNT; class_id++) {\n                if (obj_classes[class_id]) {\n                    char buf[ATOM_GET_STR_BUF_SIZE];\n                    fprintf(fp, \"  %5d  %2.0d %s\\n\", obj_classes[class_id], class_id,\n                            JS_AtomGetStrRT(rt, buf, sizeof(buf), js_std_class_def[class_id - 1].class_name));\n                }\n            }\n            if (obj_classes[JS_CLASS_INIT_COUNT])\n                fprintf(fp, \"  %5d  %2.0d %s\\n\", obj_classes[JS_CLASS_INIT_COUNT], 0, \"other\");\n        }\n        fprintf(fp, \"\\n\");\n    }\n#endif\n    fprintf(fp, \"%-20s %8s %8s\\n\", \"NAME\", \"COUNT\", \"SIZE\");\n\n    if (s->malloc_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per block)\\n\",\n                \"memory allocated\", s->malloc_count, s->malloc_size,\n                (double)s->malloc_size / s->malloc_count);\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%d overhead, %0.1f average slack)\\n\",\n                \"memory used\", s->memory_used_count, s->memory_used_size,\n                MALLOC_OVERHEAD, ((double)(s->malloc_size - s->memory_used_size) /\n                                  s->memory_used_count));\n    }\n    if (s->atom_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per atom)\\n\",\n                \"atoms\", s->atom_count, s->atom_size,\n                (double)s->atom_size / s->atom_count);\n    }\n    if (s->str_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per string)\\n\",\n                \"strings\", s->str_count, s->str_size,\n                (double)s->str_size / s->str_count);\n    }\n    if (s->obj_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per object)\\n\",\n                \"objects\", s->obj_count, s->obj_size,\n                (double)s->obj_size / s->obj_count);\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per object)\\n\",\n                \"  properties\", s->prop_count, s->prop_size,\n                (double)s->prop_count / s->obj_count);\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per shape)\\n\",\n                \"  shapes\", s->shape_count, s->shape_size,\n                (double)s->shape_size / s->shape_count);\n    }\n    if (s->js_func_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"\\n\",\n                \"bytecode functions\", s->js_func_count, s->js_func_size);\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per function)\\n\",\n                \"  bytecode\", s->js_func_count, s->js_func_code_size,\n                (double)s->js_func_code_size / s->js_func_count);\n        if (s->js_func_pc2line_count) {\n            fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per function)\\n\",\n                    \"  pc2line\", s->js_func_pc2line_count,\n                    s->js_func_pc2line_size,\n                    (double)s->js_func_pc2line_size / s->js_func_pc2line_count);\n        }\n    }\n    if (s->c_func_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\"\\n\", \"C functions\", s->c_func_count);\n    }\n    if (s->array_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\"\\n\", \"arrays\", s->array_count);\n        if (s->fast_array_count) {\n            fprintf(fp, \"%-20s %8\"PRId64\"\\n\", \"  fast arrays\", s->fast_array_count);\n            fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"  (%0.1f per fast array)\\n\",\n                    \"  elements\", s->fast_array_elements,\n                    s->fast_array_elements * (int)sizeof(JSValue),\n                    (double)s->fast_array_elements / s->fast_array_count);\n        }\n    }\n    if (s->binary_object_count) {\n        fprintf(fp, \"%-20s %8\"PRId64\" %8\"PRId64\"\\n\",\n                \"binary objects\", s->binary_object_count, s->binary_object_size);\n    }\n}\n\nJSValue JS_GetGlobalObject(JSContext *ctx)\n{\n    return JS_DupValue(ctx, ctx->global_obj);\n}\n\n/* WARNING: obj is freed */\nJSValue JS_Throw(JSContext *ctx, JSValue obj)\n{\n    JSRuntime *rt = ctx->rt;\n    JS_FreeValue(ctx, rt->current_exception);\n    rt->current_exception = obj;\n    return JS_EXCEPTION;\n}\n\n/* return the pending exception (cannot be called twice). */\nJSValue JS_GetException(JSContext *ctx)\n{\n    JSValue val;\n    JSRuntime *rt = ctx->rt;\n    val = rt->current_exception;\n    rt->current_exception = JS_NULL;\n    return val;\n}\n\nstatic void dbuf_put_leb128(DynBuf *s, uint32_t v)\n{\n    uint32_t a;\n    for(;;) {\n        a = v & 0x7f;\n        v >>= 7;\n        if (v != 0) {\n            dbuf_putc(s, a | 0x80);\n        } else {\n            dbuf_putc(s, a);\n            break;\n        }\n    }\n}\n\nstatic void dbuf_put_sleb128(DynBuf *s, int32_t v1)\n{\n    uint32_t v = v1;\n    dbuf_put_leb128(s, (2 * v) ^ -(v >> 31));\n}\n\nstatic int get_leb128(uint32_t *pval, const uint8_t *buf,\n                      const uint8_t *buf_end)\n{\n    const uint8_t *ptr = buf;\n    uint32_t v, a, i;\n    v = 0;\n    for(i = 0; i < 5; i++) {\n        if (unlikely(ptr >= buf_end))\n            break;\n        a = *ptr++;\n        v |= (a & 0x7f) << (i * 7);\n        if (!(a & 0x80)) {\n            *pval = v;\n            return ptr - buf;\n        }\n    }\n    *pval = 0;\n    return -1;\n}\n\nstatic int get_sleb128(int32_t *pval, const uint8_t *buf,\n                       const uint8_t *buf_end)\n{\n    int ret;\n    uint32_t val;\n    ret = get_leb128(&val, buf, buf_end);\n    if (ret < 0) {\n        *pval = 0;\n        return -1;\n    }\n    *pval = (val >> 1) ^ -(val & 1);\n    return ret;\n}\n\nstatic int find_line_num(JSContext *ctx, JSFunctionBytecode *b,\n                         uint32_t pc_value)\n{\n    const uint8_t *p_end, *p;\n    int new_line_num, line_num, pc, v, ret;\n    unsigned int op;\n\n    if (!b->has_debug || !b->debug.pc2line_buf) {\n        /* function was stripped */\n        return -1;\n    }\n\n    p = b->debug.pc2line_buf;\n    p_end = p + b->debug.pc2line_len;\n    pc = 0;\n    line_num = b->debug.line_num;\n    while (p < p_end) {\n        op = *p++;\n        if (op == 0) {\n            uint32_t val;\n            ret = get_leb128(&val, p, p_end);\n            if (ret < 0)\n                goto fail;\n            pc += val;\n            p += ret;\n            ret = get_sleb128(&v, p, p_end);\n            if (ret < 0) {\n            fail:\n                /* should never happen */\n                return b->debug.line_num;\n            }\n            p += ret;\n            new_line_num = line_num + v;\n        } else {\n            op -= PC2LINE_OP_FIRST;\n            pc += (op / PC2LINE_RANGE);\n            new_line_num = line_num + (op % PC2LINE_RANGE) + PC2LINE_BASE;\n        }\n        if (pc_value < pc)\n            return line_num;\n        line_num = new_line_num;\n    }\n    return line_num;\n}\n\n/* in order to avoid executing arbitrary code during the stack trace\n   generation, we only look at simple 'name' properties containing a\n   string. */\nstatic const char *get_func_name(JSContext *ctx, JSValueConst func)\n{\n    JSProperty *pr;\n    JSShapeProperty *prs;\n    JSValueConst val;\n    \n    if (JS_VALUE_GET_TAG(func) != JS_TAG_OBJECT)\n        return NULL;\n    prs = find_own_property(&pr, JS_VALUE_GET_OBJ(func), JS_ATOM_name);\n    if (!prs)\n        return NULL;\n    if ((prs->flags & JS_PROP_TMASK) != JS_PROP_NORMAL)\n        return NULL;\n    val = pr->u.value;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_STRING)\n        return NULL;\n    return JS_ToCString(ctx, val);\n}\n\n#define JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL (1 << 0)\n/* only taken into account if filename is provided */\n#define JS_BACKTRACE_FLAG_SINGLE_LEVEL     (1 << 1)\n\n/* if filename != NULL, an additional level is added with the filename\n   and line number information (used for parse error). */\nstatic void build_backtrace(JSContext *ctx, JSValueConst error_obj,\n                            const char *filename, int line_num,\n                            int backtrace_flags)\n{\n    JSStackFrame *sf;\n    JSValue str;\n    DynBuf dbuf;\n    const char *func_name_str;\n    const char *str1;\n    JSObject *p;\n    BOOL backtrace_barrier;\n    \n    js_dbuf_init(ctx, &dbuf);\n    if (filename) {\n        dbuf_printf(&dbuf, \"    at %s\", filename);\n        if (line_num != -1)\n            dbuf_printf(&dbuf, \":%d\", line_num);\n        dbuf_putc(&dbuf, '\\n');\n        str = JS_NewString(ctx, filename);\n        JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_fileName, str,\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n        JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_lineNumber, JS_NewInt32(ctx, line_num),\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n        if (backtrace_flags & JS_BACKTRACE_FLAG_SINGLE_LEVEL)\n            goto done;\n    }\n    for(sf = ctx->rt->current_stack_frame; sf != NULL; sf = sf->prev_frame) {\n        if (backtrace_flags & JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL) {\n            backtrace_flags &= ~JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL;\n            continue;\n        }\n        func_name_str = get_func_name(ctx, sf->cur_func);\n        if (!func_name_str || func_name_str[0] == '\\0')\n            str1 = \"<anonymous>\";\n        else\n            str1 = func_name_str;\n        dbuf_printf(&dbuf, \"    at %s\", str1);\n        JS_FreeCString(ctx, func_name_str);\n\n        p = JS_VALUE_GET_OBJ(sf->cur_func);\n        backtrace_barrier = FALSE;\n        if (js_class_has_bytecode(p->class_id)) {\n            JSFunctionBytecode *b;\n            const char *atom_str;\n            int line_num1;\n\n            b = p->u.func.function_bytecode;\n            backtrace_barrier = b->backtrace_barrier;\n            if (b->has_debug) {\n                line_num1 = find_line_num(ctx, b,\n                                          sf->cur_pc - b->byte_code_buf - 1);\n                atom_str = JS_AtomToCString(ctx, b->debug.filename);\n                dbuf_printf(&dbuf, \" (%s\",\n                            atom_str ? atom_str : \"<null>\");\n                JS_FreeCString(ctx, atom_str);\n                if (line_num1 != -1)\n                    dbuf_printf(&dbuf, \":%d\", line_num1);\n                dbuf_putc(&dbuf, ')');\n            }\n        } else {\n            dbuf_printf(&dbuf, \" (native)\");\n        }\n        dbuf_putc(&dbuf, '\\n');\n        /* stop backtrace if JS_EVAL_FLAG_BACKTRACE_BARRIER was used */\n        if (backtrace_barrier)\n            break;\n    }\n done:\n    dbuf_putc(&dbuf, '\\0');\n    if (dbuf_error(&dbuf))\n        str = JS_NULL;\n    else\n        str = JS_NewString(ctx, (char *)dbuf.buf);\n    dbuf_free(&dbuf);\n    JS_DefinePropertyValue(ctx, error_obj, JS_ATOM_stack, str,\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n}\n\n/* Note: it is important that no exception is returned by this function */\nstatic BOOL is_backtrace_needed(JSContext *ctx, JSValueConst obj)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (p->class_id != JS_CLASS_ERROR)\n        return FALSE;\n    if (find_own_property1(p, JS_ATOM_stack))\n        return FALSE;\n    return TRUE;\n}\n\nJSValue JS_NewError(JSContext *ctx)\n{\n    return JS_NewObjectClass(ctx, JS_CLASS_ERROR);\n}\n\nstatic JSValue JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,\n                              const char *fmt, va_list ap, BOOL add_backtrace)\n{\n    char buf[256];\n    JSValue obj, ret;\n\n    vsnprintf(buf, sizeof(buf), fmt, ap);\n    obj = JS_NewObjectProtoClass(ctx, ctx->native_error_proto[error_num],\n                                 JS_CLASS_ERROR);\n    if (unlikely(JS_IsException(obj))) {\n        /* out of memory: throw JS_NULL to avoid recursing */\n        obj = JS_NULL;\n    } else {\n        JS_DefinePropertyValue(ctx, obj, JS_ATOM_message,\n                               JS_NewString(ctx, buf),\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    }\n    if (add_backtrace) {\n        build_backtrace(ctx, obj, NULL, 0, 0);\n    }\n    ret = JS_Throw(ctx, obj);\n    return ret;\n}\n\nstatic JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,\n                             const char *fmt, va_list ap)\n{\n    JSRuntime *rt = ctx->rt;\n    JSStackFrame *sf;\n    BOOL add_backtrace;\n\n    /* the backtrace is added later if called from a bytecode function */\n    sf = rt->current_stack_frame;\n    add_backtrace = !rt->in_out_of_memory &&\n        (!sf || (JS_GetFunctionBytecode(sf->cur_func) == NULL));\n    return JS_ThrowError2(ctx, error_num, fmt, ap, add_backtrace);\n}\n\nJSValue __attribute__((format(printf, 2, 3))) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...)\n{\n    JSValue val;\n    va_list ap;\n\n    va_start(ap, fmt);\n    val = JS_ThrowError(ctx, JS_SYNTAX_ERROR, fmt, ap);\n    va_end(ap);\n    return val;\n}\n\nJSValue __attribute__((format(printf, 2, 3))) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...)\n{\n    JSValue val;\n    va_list ap;\n\n    va_start(ap, fmt);\n    val = JS_ThrowError(ctx, JS_TYPE_ERROR, fmt, ap);\n    va_end(ap);\n    return val;\n}\n\nstatic int __attribute__((format(printf, 3, 4))) JS_ThrowTypeErrorOrFalse(JSContext *ctx, int flags, const char *fmt, ...)\n{\n    va_list ap;\n\n    if ((flags & JS_PROP_THROW) ||\n        ((flags & JS_PROP_THROW_STRICT) && is_strict_mode(ctx))) {\n        va_start(ap, fmt);\n        JS_ThrowError(ctx, JS_TYPE_ERROR, fmt, ap);\n        va_end(ap);\n        return -1;\n    } else {\n        return FALSE;\n    }\n}\n\n/* never use it directly */\nstatic JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowTypeErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n    return JS_ThrowTypeError(ctx, fmt,\n                             JS_AtomGetStr(ctx, buf, sizeof(buf), atom));\n}\n\n/* never use it directly */\nstatic JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowSyntaxErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n    return JS_ThrowSyntaxError(ctx, fmt,\n                             JS_AtomGetStr(ctx, buf, sizeof(buf), atom));\n}\n\n/* %s is replaced by 'atom'. The macro is used so that gcc can check\n    the format string. */\n#define JS_ThrowTypeErrorAtom(ctx, fmt, atom) __JS_ThrowTypeErrorAtom(ctx, atom, fmt, \"\")\n#define JS_ThrowSyntaxErrorAtom(ctx, fmt, atom) __JS_ThrowSyntaxErrorAtom(ctx, atom, fmt, \"\")\n\nstatic int JS_ThrowTypeErrorReadOnly(JSContext *ctx, int flags, JSAtom atom)\n{\n    if ((flags & JS_PROP_THROW) ||\n        ((flags & JS_PROP_THROW_STRICT) && is_strict_mode(ctx))) {\n        JS_ThrowTypeErrorAtom(ctx, \"'%s' is read-only\", atom);\n        return -1;\n    } else {\n        return FALSE;\n    }\n}\n\nJSValue __attribute__((format(printf, 2, 3))) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...)\n{\n    JSValue val;\n    va_list ap;\n\n    va_start(ap, fmt);\n    val = JS_ThrowError(ctx, JS_REFERENCE_ERROR, fmt, ap);\n    va_end(ap);\n    return val;\n}\n\nJSValue __attribute__((format(printf, 2, 3))) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...)\n{\n    JSValue val;\n    va_list ap;\n\n    va_start(ap, fmt);\n    val = JS_ThrowError(ctx, JS_RANGE_ERROR, fmt, ap);\n    va_end(ap);\n    return val;\n}\n\nJSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...)\n{\n    JSValue val;\n    va_list ap;\n\n    va_start(ap, fmt);\n    val = JS_ThrowError(ctx, JS_INTERNAL_ERROR, fmt, ap);\n    va_end(ap);\n    return val;\n}\n\nJSValue JS_ThrowOutOfMemory(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    if (!rt->in_out_of_memory) {\n        rt->in_out_of_memory = TRUE;\n        JS_ThrowInternalError(ctx, \"out of memory\");\n        rt->in_out_of_memory = FALSE;\n    }\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ThrowStackOverflow(JSContext *ctx)\n{\n    return JS_ThrowInternalError(ctx, \"stack overflow\");\n}\n\nstatic JSValue JS_ThrowTypeErrorNotAnObject(JSContext *ctx)\n{\n    return JS_ThrowTypeError(ctx, \"not an object\");\n}\n\nstatic JSValue JS_ThrowTypeErrorNotASymbol(JSContext *ctx)\n{\n    return JS_ThrowTypeError(ctx, \"not a symbol\");\n}\n\nstatic JSValue JS_ThrowReferenceErrorNotDefined(JSContext *ctx, JSAtom name)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n    return JS_ThrowReferenceError(ctx, \"'%s' is not defined\",\n                                  JS_AtomGetStr(ctx, buf, sizeof(buf), name));\n}\n\nstatic JSValue JS_ThrowReferenceErrorUninitialized(JSContext *ctx, JSAtom name)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n    return JS_ThrowReferenceError(ctx, \"%s is not initialized\",\n                                  name == JS_ATOM_NULL ? \"lexical variable\" :\n                                  JS_AtomGetStr(ctx, buf, sizeof(buf), name));\n}\n\nstatic JSValue JS_ThrowTypeErrorInvalidClass(JSContext *ctx, int class_id)\n{\n    JSRuntime *rt = ctx->rt;\n    JSAtom name;\n    name = rt->class_array[class_id].class_name;\n    return JS_ThrowTypeErrorAtom(ctx, \"%s object expected\", name);\n}\n\nstatic no_inline __exception int __js_poll_interrupts(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    ctx->interrupt_counter = JS_INTERRUPT_COUNTER_INIT;\n    if (rt->interrupt_handler) {\n        if (rt->interrupt_handler(rt, rt->interrupt_opaque)) {\n            /* XXX: should set a specific flag to avoid catching */\n            JS_ThrowInternalError(ctx, \"interrupted\");\n            JS_SetUncatchableError(ctx, ctx->rt->current_exception, TRUE);\n            return -1;\n        }\n    }\n    return 0;\n}\n\nstatic inline __exception int js_poll_interrupts(JSContext *ctx)\n{\n    if (unlikely(--ctx->interrupt_counter <= 0)) {\n        return __js_poll_interrupts(ctx);\n    } else {\n        return 0;\n    }\n}\n\n/* return -1 (exception) or TRUE/FALSE */\nstatic int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj,\n                                   JSValueConst proto_val,\n                                   BOOL throw_flag)\n{\n    JSObject *proto, *p, *p1;\n    JSShape *sh;\n\n    if (throw_flag) {\n        if (JS_VALUE_GET_TAG(obj) == JS_TAG_NULL ||\n            JS_VALUE_GET_TAG(obj) == JS_TAG_UNDEFINED)\n            goto not_obj;\n    } else {\n        if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n            goto not_obj;\n    }\n    p = JS_VALUE_GET_OBJ(obj);\n    if (JS_VALUE_GET_TAG(proto_val) != JS_TAG_OBJECT) {\n        if (JS_VALUE_GET_TAG(proto_val) != JS_TAG_NULL) {\n        not_obj:\n            JS_ThrowTypeErrorNotAnObject(ctx);\n            return -1;\n        }\n        proto = NULL;\n    } else {\n        proto = JS_VALUE_GET_OBJ(proto_val);\n    }\n\n    if (throw_flag && JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return TRUE;\n\n    if (unlikely(p->class_id == JS_CLASS_PROXY))\n        return js_proxy_setPrototypeOf(ctx, obj, proto_val, throw_flag);\n    sh = p->shape;\n    if (sh->proto == proto)\n        return TRUE;\n    if (!p->extensible) {\n        if (throw_flag) {\n            JS_ThrowTypeError(ctx, \"object is not extensible\");\n            return -1;\n        } else {\n            return FALSE;\n        }\n    }\n    if (proto) {\n        /* check if there is a cycle */\n        p1 = proto;\n        do {\n            if (p1 == p) {\n                if (throw_flag) {\n                    JS_ThrowTypeError(ctx, \"circular prototype chain\");\n                    return -1;\n                } else {\n                    return FALSE;\n                }\n            }\n            /* Note: for Proxy objects, proto is NULL */\n            p1 = p1->shape->proto;\n        } while (p1 != NULL);\n        JS_DupValue(ctx, proto_val);\n    }\n\n    if (js_shape_prepare_update(ctx, p, NULL))\n        return -1;\n    sh = p->shape;\n    if (sh->proto)\n        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, sh->proto));\n    sh->proto = proto;\n    return TRUE;\n}\n\n/* return -1 (exception) or TRUE/FALSE */\nint JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValueConst proto_val)\n{\n    return JS_SetPrototypeInternal(ctx, obj, proto_val, TRUE);\n}\n\n/* Only works for primitive types, otherwise return JS_NULL. */\nstatic JSValueConst JS_GetPrototypePrimitive(JSContext *ctx, JSValueConst val)\n{\n    switch(JS_VALUE_GET_NORM_TAG(val)) {\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        val = ctx->class_proto[JS_CLASS_BIG_INT];\n        break;\n    case JS_TAG_BIG_FLOAT:\n        val = ctx->class_proto[JS_CLASS_BIG_FLOAT];\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        val = ctx->class_proto[JS_CLASS_BIG_DECIMAL];\n        break;\n#endif\n    case JS_TAG_INT:\n    case JS_TAG_FLOAT64:\n        val = ctx->class_proto[JS_CLASS_NUMBER];\n        break;\n    case JS_TAG_BOOL:\n        val = ctx->class_proto[JS_CLASS_BOOLEAN];\n        break;\n    case JS_TAG_STRING:\n        val = ctx->class_proto[JS_CLASS_STRING];\n        break;\n    case JS_TAG_SYMBOL:\n        val = ctx->class_proto[JS_CLASS_SYMBOL];\n        break;\n    case JS_TAG_OBJECT:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n    default:\n        val = JS_NULL;\n        break;\n    }\n    return val;\n}\n\n/* Return an Object, JS_NULL or JS_EXCEPTION in case of Proxy object. */\nJSValue JS_GetPrototype(JSContext *ctx, JSValueConst obj)\n{\n    JSValue val;\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        JSObject *p;\n        p = JS_VALUE_GET_OBJ(obj);\n        if (unlikely(p->class_id == JS_CLASS_PROXY)) {\n            val = js_proxy_getPrototypeOf(ctx, obj);\n        } else {\n            p = p->shape->proto;\n            if (!p)\n                val = JS_NULL;\n            else\n                val = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n        }\n    } else {\n        val = JS_DupValue(ctx, JS_GetPrototypePrimitive(ctx, obj));\n    }\n    return val;\n}\n\nstatic JSValue JS_GetPrototypeFree(JSContext *ctx, JSValue obj)\n{\n    JSValue obj1;\n    obj1 = JS_GetPrototype(ctx, obj);\n    JS_FreeValue(ctx, obj);\n    return obj1;\n}\n\n/* return TRUE, FALSE or (-1) in case of exception */\nstatic int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val,\n                                   JSValueConst obj)\n{\n    JSValue obj_proto;\n    JSObject *proto;\n    const JSObject *p, *proto1;\n    BOOL ret;\n\n    if (!JS_IsFunction(ctx, obj))\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (p->class_id == JS_CLASS_BOUND_FUNCTION) {\n        JSBoundFunction *s = p->u.bound_function;\n        return JS_IsInstanceOf(ctx, val, s->func_obj);\n    }\n\n    /* Only explicitly boxed values are instances of constructors */\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return FALSE;\n    obj_proto = JS_GetProperty(ctx, obj, JS_ATOM_prototype);\n    if (JS_VALUE_GET_TAG(obj_proto) != JS_TAG_OBJECT) {\n        if (!JS_IsException(obj_proto))\n            JS_ThrowTypeError(ctx, \"operand 'prototype' property is not an object\");\n        ret = -1;\n        goto done;\n    }\n    proto = JS_VALUE_GET_OBJ(obj_proto);\n    p = JS_VALUE_GET_OBJ(val);\n    for(;;) {\n        proto1 = p->shape->proto;\n        if (!proto1) {\n            /* slow case if proxy in the prototype chain */\n            if (unlikely(p->class_id == JS_CLASS_PROXY)) {\n                JSValue obj1;\n                obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, (JSObject *)p));\n                for(;;) {\n                    obj1 = JS_GetPrototypeFree(ctx, obj1);\n                    if (JS_IsException(obj1)) {\n                        ret = -1;\n                        break;\n                    }\n                    if (JS_IsNull(obj1)) {\n                        ret = FALSE;\n                        break;\n                    }\n                    if (proto == JS_VALUE_GET_OBJ(obj1)) {\n                        JS_FreeValue(ctx, obj1);\n                        ret = TRUE;\n                        break;\n                    }\n                    /* must check for timeout to avoid infinite loop */\n                    if (js_poll_interrupts(ctx)) {\n                        JS_FreeValue(ctx, obj1);\n                        ret = -1;\n                        break;\n                    }\n                }\n            } else {\n                ret = FALSE;\n            }\n            break;\n        }\n        p = proto1;\n        if (proto == p) {\n            ret = TRUE;\n            break;\n        }\n    }\ndone:\n    JS_FreeValue(ctx, obj_proto);\n    return ret;\n}\n\n/* return TRUE, FALSE or (-1) in case of exception */\nint JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj)\n{\n    JSValue method;\n\n    if (!JS_IsObject(obj))\n        goto fail;\n    method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_hasInstance);\n    if (JS_IsException(method))\n        return -1;\n    if (!JS_IsNull(method) && !JS_IsUndefined(method)) {\n        JSValue ret;\n        ret = JS_CallFree(ctx, method, obj, 1, &val);\n        return JS_ToBoolFree(ctx, ret);\n    }\n\n    /* legacy case */\n    if (!JS_IsFunction(ctx, obj)) {\n    fail:\n        JS_ThrowTypeError(ctx, \"invalid 'instanceof' right operand\");\n        return -1;\n    }\n    return JS_OrdinaryIsInstanceOf(ctx, val, obj);\n}\n\ntypedef int JSAutoInitFunc(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque);\n\nstatic JSAutoInitFunc *js_autoinit_func_table[] = {\n    js_instantiate_prototype, /* JS_AUTOINIT_ID_PROTOTYPE */\n    js_module_ns_autoinit, /* JS_AUTOINIT_ID_MODULE_NS */\n    JS_InstantiateFunctionListItem, /* JS_AUTOINIT_ID_PROP */\n};\n\nstatic int JS_AutoInitProperty(JSContext *ctx, JSObject *p, JSAtom prop,\n                               JSProperty *pr)\n{\n    int ret;\n    JSContext *realm;\n    JSAutoInitFunc *func;\n    \n    realm = js_autoinit_get_realm(pr);\n    func = js_autoinit_func_table[js_autoinit_get_id(pr)];\n    ret = func(realm, p, prop, pr->u.init.opaque);\n    return ret;\n}\n\nJSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,\n                               JSAtom prop, JSValueConst this_obj,\n                               BOOL throw_ref_error)\n{\n    JSObject *p;\n    JSProperty *pr;\n    JSShapeProperty *prs;\n    uint32_t tag;\n\n    tag = JS_VALUE_GET_TAG(obj);\n    if (unlikely(tag != JS_TAG_OBJECT)) {\n        switch(tag) {\n        case JS_TAG_NULL:\n            return JS_ThrowTypeErrorAtom(ctx, \"cannot read property '%s' of null\", prop);\n        case JS_TAG_UNDEFINED:\n            return JS_ThrowTypeErrorAtom(ctx, \"cannot read property '%s' of undefined\", prop);\n        case JS_TAG_EXCEPTION:\n            return JS_EXCEPTION;\n        case JS_TAG_STRING:\n            {\n                JSString *p1 = JS_VALUE_GET_STRING(obj);\n                if (__JS_AtomIsTaggedInt(prop)) {\n                    uint32_t idx, ch;\n                    idx = __JS_AtomToUInt32(prop);\n                    if (idx < p1->len) {\n                        if (p1->is_wide_char)\n                            ch = p1->u.str16[idx];\n                        else\n                            ch = p1->u.str8[idx];\n                        return js_new_string_char(ctx, ch);\n                    }\n                } else if (prop == JS_ATOM_length) {\n                    return JS_NewInt32(ctx, p1->len);\n                }\n            }\n            break;\n        default:\n            break;\n        }\n        /* cannot raise an exception */\n        p = JS_VALUE_GET_OBJ(JS_GetPrototypePrimitive(ctx, obj));\n        if (!p)\n            return JS_UNDEFINED;\n    } else {\n        p = JS_VALUE_GET_OBJ(obj);\n    }\n\n    for(;;) {\n        prs = find_own_property(&pr, p, prop);\n        if (prs) {\n            /* found */\n            if (unlikely(prs->flags & JS_PROP_TMASK)) {\n                if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n                    if (unlikely(!pr->u.getset.getter)) {\n                        return JS_UNDEFINED;\n                    } else {\n                        JSValue func = JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter);\n                        /* Note: the field could be removed in the getter */\n                        func = JS_DupValue(ctx, func);\n                        return JS_CallFree(ctx, func, this_obj, 0, NULL);\n                    }\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                    JSValue val = *pr->u.var_ref->pvalue;\n                    if (unlikely(JS_IsUninitialized(val)))\n                        return JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n                    return JS_DupValue(ctx, val);\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                    /* Instantiate property and retry */\n                    if (JS_AutoInitProperty(ctx, p, prop, pr))\n                        return JS_EXCEPTION;\n                    continue;\n                }\n            } else {\n                return JS_DupValue(ctx, pr->u.value);\n            }\n        }\n        if (unlikely(p->is_exotic)) {\n            /* exotic behaviors */\n            if (p->fast_array) {\n                if (__JS_AtomIsTaggedInt(prop)) {\n                    uint32_t idx = __JS_AtomToUInt32(prop);\n                    if (idx < p->u.array.count) {\n                        /* we avoid duplicating the code */\n                        return JS_GetPropertyUint32(ctx, JS_MKPTR(JS_TAG_OBJECT, p), idx);\n                    } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                               p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                        goto typed_array_oob;\n                    }\n                } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                           p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                    int ret;\n                    ret = JS_AtomIsNumericIndex(ctx, prop);\n                    if (ret != 0) {\n                        if (ret < 0)\n                            return JS_EXCEPTION;\n                    typed_array_oob:\n                        if (typed_array_is_detached(ctx, p))\n                            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n                        return JS_UNDEFINED;\n                    }\n                }\n            } else {\n                const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n                if (em) {\n                    if (em->get_property) {\n                        JSValue obj1, retval;\n                        /* XXX: should pass throw_ref_error */\n                        /* Note: if 'p' is a prototype, it can be\n                           freed in the called function */\n                        obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n                        retval = em->get_property(ctx, obj1, prop, this_obj);\n                        JS_FreeValue(ctx, obj1);\n                        return retval;\n                    }\n                    if (em->get_own_property) {\n                        JSPropertyDescriptor desc;\n                        int ret;\n                        JSValue obj1;\n\n                        /* Note: if 'p' is a prototype, it can be\n                           freed in the called function */\n                        obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n                        ret = em->get_own_property(ctx, &desc, obj1, prop);\n                        JS_FreeValue(ctx, obj1);\n                        if (ret < 0)\n                            return JS_EXCEPTION;\n                        if (ret) {\n                            if (desc.flags & JS_PROP_GETSET) {\n                                JS_FreeValue(ctx, desc.setter);\n                                return JS_CallFree(ctx, desc.getter, this_obj, 0, NULL);\n                            } else {\n                                return desc.value;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        p = p->shape->proto;\n        if (!p)\n            break;\n    }\n    if (unlikely(throw_ref_error)) {\n        return JS_ThrowReferenceErrorNotDefined(ctx, prop);\n    } else {\n        return JS_UNDEFINED;\n    }\n}\n\nstatic JSValue JS_ThrowTypeErrorPrivateNotFound(JSContext *ctx, JSAtom atom)\n{\n    return JS_ThrowTypeErrorAtom(ctx, \"private class field '%s' does not exist\",\n                                 atom);\n}\n\n/* Private fields can be added even on non extensible objects or\n   Proxies */\nstatic int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,\n                                 JSValueConst name, JSValue val)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    JSAtom prop;\n\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        goto fail;\n    }\n    /* safety check */\n    if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL)) {\n        JS_ThrowTypeErrorNotASymbol(ctx);\n        goto fail;\n    }\n    prop = js_symbol_to_atom(ctx, (JSValue)name);\n    p = JS_VALUE_GET_OBJ(obj);\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        JS_ThrowTypeErrorAtom(ctx, \"private class field '%s' already exists\",\n                              prop);\n        goto fail;\n    }\n    pr = add_property(ctx, p, prop, JS_PROP_C_W_E);\n    if (unlikely(!pr)) {\n    fail:\n        JS_FreeValue(ctx, val);\n        return -1;\n    }\n    pr->u.value = val;\n    return 0;\n}\n\nstatic JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj,\n                                  JSValueConst name)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    JSAtom prop;\n\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    /* safety check */\n    if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL))\n        return JS_ThrowTypeErrorNotASymbol(ctx);\n    prop = js_symbol_to_atom(ctx, (JSValue)name);\n    p = JS_VALUE_GET_OBJ(obj);\n    prs = find_own_property(&pr, p, prop);\n    if (!prs) {\n        JS_ThrowTypeErrorPrivateNotFound(ctx, prop);\n        return JS_EXCEPTION;\n    }\n    return JS_DupValue(ctx, pr->u.value);\n}\n\nstatic int JS_SetPrivateField(JSContext *ctx, JSValueConst obj,\n                              JSValueConst name, JSValue val)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    JSAtom prop;\n\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        goto fail;\n    }\n    /* safety check */\n    if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL)) {\n        JS_ThrowTypeErrorNotASymbol(ctx);\n        goto fail;\n    }\n    prop = js_symbol_to_atom(ctx, (JSValue)name);\n    p = JS_VALUE_GET_OBJ(obj);\n    prs = find_own_property(&pr, p, prop);\n    if (!prs) {\n        JS_ThrowTypeErrorPrivateNotFound(ctx, prop);\n    fail:\n        JS_FreeValue(ctx, val);\n        return -1;\n    }\n    set_value(ctx, &pr->u.value, val);\n    return 0;\n}\n\nstatic int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst home_obj)\n{\n    JSObject *p, *p1;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    JSValue brand;\n    JSAtom brand_atom;\n    \n    if (unlikely(JS_VALUE_GET_TAG(home_obj) != JS_TAG_OBJECT)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    p = JS_VALUE_GET_OBJ(home_obj);\n    prs = find_own_property(&pr, p, JS_ATOM_Private_brand);\n    if (!prs) {\n        brand = JS_NewSymbolFromAtom(ctx, JS_ATOM_brand, JS_ATOM_TYPE_PRIVATE);\n        if (JS_IsException(brand))\n            return -1;\n        /* if the brand is not present, add it */\n        pr = add_property(ctx, p, JS_ATOM_Private_brand, JS_PROP_C_W_E);\n        if (!pr) {\n            JS_FreeValue(ctx, brand);\n            return -1;\n        }\n        pr->u.value = JS_DupValue(ctx, brand);\n    } else {\n        brand = JS_DupValue(ctx, pr->u.value);\n    }\n    brand_atom = js_symbol_to_atom(ctx, brand);\n    \n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        JS_FreeAtom(ctx, brand_atom);\n        return -1;\n    }\n    p1 = JS_VALUE_GET_OBJ(obj);\n    pr = add_property(ctx, p1, brand_atom, JS_PROP_C_W_E);\n    JS_FreeAtom(ctx, brand_atom);\n    if (!pr)\n        return -1;\n    pr->u.value = JS_UNDEFINED;\n    return 0;\n}\n\nstatic int JS_CheckBrand(JSContext *ctx, JSValueConst obj, JSValueConst func)\n{\n    JSObject *p, *p1, *home_obj;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    JSValueConst brand;\n    \n    /* get the home object of 'func' */\n    if (unlikely(JS_VALUE_GET_TAG(func) != JS_TAG_OBJECT)) {\n    not_obj:\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    p1 = JS_VALUE_GET_OBJ(func);\n    if (!js_class_has_bytecode(p1->class_id))\n        goto not_obj;\n    home_obj = p1->u.func.home_object;\n    if (!home_obj)\n        goto not_obj;\n    prs = find_own_property(&pr, home_obj, JS_ATOM_Private_brand);\n    if (!prs) {\n        JS_ThrowTypeError(ctx, \"expecting <brand> private field\");\n        return -1;\n    }\n    brand = pr->u.value;\n    /* safety check */\n    if (unlikely(JS_VALUE_GET_TAG(brand) != JS_TAG_SYMBOL))\n        goto not_obj;\n    \n    /* get the brand array of 'obj' */\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))\n        goto not_obj;\n    p = JS_VALUE_GET_OBJ(obj);\n    prs = find_own_property(&pr, p, js_symbol_to_atom(ctx, (JSValue)brand));\n    if (!prs) {\n        JS_ThrowTypeError(ctx, \"invalid brand on object\");\n        return -1;\n    }\n    return 0;\n}\n\nstatic int num_keys_cmp(const void *p1, const void *p2, void *opaque)\n{\n    JSContext *ctx = opaque;\n    JSAtom atom1 = ((const JSPropertyEnum *)p1)->atom;\n    JSAtom atom2 = ((const JSPropertyEnum *)p2)->atom;\n    uint32_t v1, v2;\n    BOOL atom1_is_integer, atom2_is_integer;\n\n    atom1_is_integer = JS_AtomIsArrayIndex(ctx, &v1, atom1);\n    atom2_is_integer = JS_AtomIsArrayIndex(ctx, &v2, atom2);\n    assert(atom1_is_integer && atom2_is_integer);\n    if (v1 < v2)\n        return -1;\n    else if (v1 == v2)\n        return 0;\n    else\n        return 1;\n}\n\nstatic void js_free_prop_enum(JSContext *ctx, JSPropertyEnum *tab, uint32_t len)\n{\n    uint32_t i;\n    if (tab) {\n        for(i = 0; i < len; i++)\n            JS_FreeAtom(ctx, tab[i].atom);\n        js_free(ctx, tab);\n    }\n}\n\n/* return < 0 in case if exception, 0 if OK. ptab and its atoms must\n   be freed by the user. */\nstatic int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,\n                                                      JSPropertyEnum **ptab,\n                                                      uint32_t *plen,\n                                                      JSObject *p, int flags)\n{\n    int i, j;\n    JSShape *sh;\n    JSShapeProperty *prs;\n    JSPropertyEnum *tab_atom, *tab_exotic;\n    JSAtom atom;\n    uint32_t num_keys_count, str_keys_count, sym_keys_count, atom_count;\n    uint32_t num_index, str_index, sym_index, exotic_count;\n    BOOL is_enumerable, num_sorted;\n    uint32_t num_key;\n    JSAtomKindEnum kind;\n    \n    /* clear pointer for consistency in case of failure */\n    *ptab = NULL;\n    *plen = 0;\n\n    /* compute the number of returned properties */\n    num_keys_count = 0;\n    str_keys_count = 0;\n    sym_keys_count = 0;\n    exotic_count = 0;\n    tab_exotic = NULL;\n    sh = p->shape;\n    for(i = 0, prs = get_shape_prop(sh); i < sh->prop_count; i++, prs++) {\n        atom = prs->atom;\n        if (atom != JS_ATOM_NULL) {\n            is_enumerable = ((prs->flags & JS_PROP_ENUMERABLE) != 0);\n            kind = JS_AtomGetKind(ctx, atom);\n            if ((!(flags & JS_GPN_ENUM_ONLY) || is_enumerable) &&\n                ((flags >> kind) & 1) != 0) {\n                /* need to raise an exception in case of the module\n                   name space (implicit GetOwnProperty) */\n                if (unlikely((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) &&\n                    (flags & (JS_GPN_SET_ENUM | JS_GPN_ENUM_ONLY))) {\n                    JSVarRef *var_ref = p->prop[i].u.var_ref;\n                    if (unlikely(JS_IsUninitialized(*var_ref->pvalue))) {\n                        JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n                        return -1;\n                    }\n                }\n                if (JS_AtomIsArrayIndex(ctx, &num_key, atom)) {\n                    num_keys_count++;\n                } else if (kind == JS_ATOM_KIND_STRING) {\n                    str_keys_count++;\n                } else {\n                    sym_keys_count++;\n                }\n            }\n        }\n    }\n\n    if (p->is_exotic) {\n        if (p->fast_array) {\n            /* the implicit GetOwnProperty raises an exception if the\n               typed array is detached */\n            if ((flags & (JS_GPN_SET_ENUM | JS_GPN_ENUM_ONLY)) &&\n                 (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                  p->class_id <= JS_CLASS_FLOAT64_ARRAY) &&\n                 typed_array_is_detached(ctx, p) &&\n                typed_array_get_length(ctx, p) != 0) {\n                JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n                return -1;\n            }\n            if (flags & JS_GPN_STRING_MASK) {\n                num_keys_count += p->u.array.count;\n            }\n        } else {\n            const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n            if (em && em->get_own_property_names) {\n                if (em->get_own_property_names(ctx, &tab_exotic, &exotic_count,\n                                               JS_MKPTR(JS_TAG_OBJECT, p)))\n                    return -1;\n                for(i = 0; i < exotic_count; i++) {\n                    atom = tab_exotic[i].atom;\n                    kind = JS_AtomGetKind(ctx, atom);\n                    if (((flags >> kind) & 1) != 0) {\n                        is_enumerable = FALSE;\n                        if (flags & (JS_GPN_SET_ENUM | JS_GPN_ENUM_ONLY)) {\n                            JSPropertyDescriptor desc;\n                            int res;\n                            /* set the \"is_enumerable\" field if necessary */\n                            res = JS_GetOwnPropertyInternal(ctx, &desc, p, atom);\n                            if (res < 0) {\n                                js_free_prop_enum(ctx, tab_exotic, exotic_count);\n                                return -1;\n                            }\n                            if (res) {\n                                is_enumerable =\n                                    ((desc.flags & JS_PROP_ENUMERABLE) != 0);\n                                js_free_desc(ctx, &desc);\n                            }\n                            tab_exotic[i].is_enumerable = is_enumerable;\n                        }\n                        if (!(flags & JS_GPN_ENUM_ONLY) || is_enumerable) {\n                            if (JS_AtomIsArrayIndex(ctx, &num_key, atom)) {\n                                num_keys_count++;\n                            } else if (kind == JS_ATOM_KIND_STRING) {\n                                str_keys_count++;\n                            } else {\n                                sym_keys_count++;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    /* fill them */\n\n    atom_count = num_keys_count + str_keys_count + sym_keys_count;\n    /* avoid allocating 0 bytes */\n    tab_atom = js_malloc(ctx, sizeof(tab_atom[0]) * max_int(atom_count, 1));\n    if (!tab_atom) {\n        js_free_prop_enum(ctx, tab_exotic, exotic_count);\n        return -1;\n    }\n\n    num_index = 0;\n    str_index = num_keys_count;\n    sym_index = str_index + str_keys_count;\n\n    num_sorted = TRUE;\n    sh = p->shape;\n    for(i = 0, prs = get_shape_prop(sh); i < sh->prop_count; i++, prs++) {\n        atom = prs->atom;\n        if (atom != JS_ATOM_NULL) {\n            is_enumerable = ((prs->flags & JS_PROP_ENUMERABLE) != 0);\n            kind = JS_AtomGetKind(ctx, atom);\n            if ((!(flags & JS_GPN_ENUM_ONLY) || is_enumerable) &&\n                ((flags >> kind) & 1) != 0) {\n                if (JS_AtomIsArrayIndex(ctx, &num_key, atom)) {\n                    j = num_index++;\n                    num_sorted = FALSE;\n                } else if (kind == JS_ATOM_KIND_STRING) {\n                    j = str_index++;\n                } else {\n                    j = sym_index++;\n                }\n                tab_atom[j].atom = JS_DupAtom(ctx, atom);\n                tab_atom[j].is_enumerable = is_enumerable;\n            }\n        }\n    }\n\n    if (p->is_exotic) {\n        if (p->fast_array) {\n            if (flags & JS_GPN_STRING_MASK) {\n                for(i = 0; i < p->u.array.count; i++) {\n                    tab_atom[num_index].atom = __JS_AtomFromUInt32(i);\n                    if (tab_atom[num_index].atom == JS_ATOM_NULL) {\n                        js_free_prop_enum(ctx, tab_exotic, exotic_count);\n                        js_free_prop_enum(ctx, tab_atom, num_index);\n                        return -1;\n                    }\n                    tab_atom[num_index].is_enumerable = TRUE;\n                    num_index++;\n                }\n            }\n        }\n        if (exotic_count > 0) {\n            for(i = 0; i < exotic_count; i++) {\n                atom = tab_exotic[i].atom;\n                is_enumerable = tab_exotic[i].is_enumerable;\n                kind = JS_AtomGetKind(ctx, atom);\n                if ((!(flags & JS_GPN_ENUM_ONLY) || is_enumerable) &&\n                    ((flags >> kind) & 1) != 0) {\n                    if (JS_AtomIsArrayIndex(ctx, &num_key, atom)) {\n                        j = num_index++;\n                        num_sorted = FALSE;\n                    } else if (kind == JS_ATOM_KIND_STRING) {\n                        j = str_index++;\n                    } else {\n                        j = sym_index++;\n                    }\n                    tab_atom[j].atom = atom;\n                    tab_atom[j].is_enumerable = is_enumerable;\n                } else {\n                    JS_FreeAtom(ctx, atom);\n                }\n            }\n        }\n        js_free(ctx, tab_exotic);\n    }\n\n    assert(num_index == num_keys_count);\n    assert(str_index == num_keys_count + str_keys_count);\n    assert(sym_index == atom_count);\n\n    if (num_keys_count != 0 && !num_sorted) {\n        rqsort(tab_atom, num_keys_count, sizeof(tab_atom[0]), num_keys_cmp,\n               ctx);\n    }\n    *ptab = tab_atom;\n    *plen = atom_count;\n    return 0;\n}\n\nint JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,\n                           uint32_t *plen, JSValueConst obj, int flags)\n{\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    return JS_GetOwnPropertyNamesInternal(ctx, ptab, plen,\n                                          JS_VALUE_GET_OBJ(obj), flags);\n}\n\n/* Return -1 if exception,\n   FALSE if the property does not exist, TRUE if it exists. If TRUE is\n   returned, the property descriptor 'desc' is filled present. */\nstatic int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescriptor *desc,\n                                     JSObject *p, JSAtom prop)\n{\n    JSShapeProperty *prs;\n    JSProperty *pr;\n\nretry:\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        if (desc) {\n            desc->flags = prs->flags & JS_PROP_C_W_E;\n            desc->getter = JS_UNDEFINED;\n            desc->setter = JS_UNDEFINED;\n            desc->value = JS_UNDEFINED;\n            if (unlikely(prs->flags & JS_PROP_TMASK)) {\n                if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n                    desc->flags |= JS_PROP_GETSET;\n                    if (pr->u.getset.getter)\n                        desc->getter = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter));\n                    if (pr->u.getset.setter)\n                        desc->setter = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter));\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                    JSValue val = *pr->u.var_ref->pvalue;\n                    if (unlikely(JS_IsUninitialized(val))) {\n                        JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n                        return -1;\n                    }\n                    desc->value = JS_DupValue(ctx, val);\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                    /* Instantiate property and retry */\n                    if (JS_AutoInitProperty(ctx, p, prop, pr))\n                        return -1;\n                    goto retry;\n                }\n            } else {\n                desc->value = JS_DupValue(ctx, pr->u.value);\n            }\n        } else {\n            /* for consistency, send the exception even if desc is NULL */\n            if (unlikely((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF)) {\n                if (unlikely(JS_IsUninitialized(*pr->u.var_ref->pvalue))) {\n                    JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n                    return -1;\n                }\n            } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                /* nothing to do: delay instantiation until actual value and/or attributes are read */\n            }\n        }\n        return TRUE;\n    }\n    if (p->is_exotic) {\n        if (p->fast_array) {\n            /* specific case for fast arrays */\n            if (__JS_AtomIsTaggedInt(prop)) {\n                uint32_t idx;\n                idx = __JS_AtomToUInt32(prop);\n                if (idx < p->u.array.count) {\n                    if (desc) {\n                        desc->flags = JS_PROP_WRITABLE | JS_PROP_ENUMERABLE;\n                        if (p->class_id == JS_CLASS_ARRAY ||\n                            p->class_id == JS_CLASS_ARGUMENTS)\n                            desc->flags |= JS_PROP_CONFIGURABLE;\n                        desc->getter = JS_UNDEFINED;\n                        desc->setter = JS_UNDEFINED;\n                        desc->value = JS_GetPropertyUint32(ctx, JS_MKPTR(JS_TAG_OBJECT, p), idx);\n                    }\n                    return TRUE;\n                }\n            }\n            if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                int ret;\n                ret = JS_AtomIsNumericIndex(ctx, prop);\n                if (ret != 0) {\n                    if (ret < 0)\n                        return -1;\n                    if (typed_array_is_detached(ctx, p)) {\n                        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n                        return -1;\n                    }\n                }\n            }\n        } else {\n            const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n            if (em && em->get_own_property) {\n                return em->get_own_property(ctx, desc,\n                                            JS_MKPTR(JS_TAG_OBJECT, p), prop);\n            }\n        }\n    }\n    return FALSE;\n}\n\nint JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,\n                      JSValueConst obj, JSAtom prop)\n{\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    return JS_GetOwnPropertyInternal(ctx, desc, JS_VALUE_GET_OBJ(obj), prop);\n}\n\n/* return -1 if exception (Proxy object only) or TRUE/FALSE */\nint JS_IsExtensible(JSContext *ctx, JSValueConst obj)\n{\n    JSObject *p;\n\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (unlikely(p->class_id == JS_CLASS_PROXY))\n        return js_proxy_isExtensible(ctx, obj);\n    else\n        return p->extensible;\n}\n\n/* return -1 if exception (Proxy object only) or TRUE/FALSE */\nint JS_PreventExtensions(JSContext *ctx, JSValueConst obj)\n{\n    JSObject *p;\n\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (unlikely(p->class_id == JS_CLASS_PROXY))\n        return js_proxy_preventExtensions(ctx, obj);\n    p->extensible = FALSE;\n    return TRUE;\n}\n\n/* return -1 if exception otherwise TRUE or FALSE */\nint JS_HasProperty(JSContext *ctx, JSValueConst obj, JSAtom prop)\n{\n    JSObject *p;\n    int ret;\n    JSValue obj1;\n\n    if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT))\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(obj);\n    for(;;) {\n        if (p->is_exotic) {\n            const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n            if (em && em->has_property) {\n                /* has_property can free the prototype */\n                obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n                ret = em->has_property(ctx, obj1, prop);\n                JS_FreeValue(ctx, obj1);\n                return ret;\n            }\n        }\n        /* JS_GetOwnPropertyInternal can free the prototype */\n        JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n        ret = JS_GetOwnPropertyInternal(ctx, NULL, p, prop);\n        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n        if (ret != 0)\n            return ret;\n        if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n            p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n            ret = JS_AtomIsNumericIndex(ctx, prop);\n            if (ret != 0) {\n                if (ret < 0)\n                    return -1;\n                /* the detached array test was done in\n                   JS_GetOwnPropertyInternal() */\n                return FALSE;\n            }\n        }\n        p = p->shape->proto;\n        if (!p)\n            break;\n    }\n    return FALSE;\n}\n\n/* val must be a symbol */\nstatic JSAtom js_symbol_to_atom(JSContext *ctx, JSValue val)\n{\n    JSAtomStruct *p = JS_VALUE_GET_PTR(val);\n    return js_get_atom_index(ctx->rt, p);\n}\n\n/* return JS_ATOM_NULL in case of exception */\nJSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val)\n{\n    JSAtom atom;\n    uint32_t tag;\n    tag = JS_VALUE_GET_TAG(val);\n    if (tag == JS_TAG_INT &&\n        (uint32_t)JS_VALUE_GET_INT(val) <= JS_ATOM_MAX_INT) {\n        /* fast path for integer values */\n        atom = __JS_AtomFromUInt32(JS_VALUE_GET_INT(val));\n    } else if (tag == JS_TAG_SYMBOL) {\n        JSAtomStruct *p = JS_VALUE_GET_PTR(val);\n        atom = JS_DupAtom(ctx, js_get_atom_index(ctx->rt, p));\n    } else {\n        JSValue str;\n        str = JS_ToPropertyKey(ctx, val);\n        if (JS_IsException(str))\n            return JS_ATOM_NULL;\n        if (JS_VALUE_GET_TAG(str) == JS_TAG_SYMBOL) {\n            atom = js_symbol_to_atom(ctx, str);\n        } else {\n            atom = JS_NewAtomStr(ctx, JS_VALUE_GET_STRING(str));\n        }\n    }\n    return atom;\n}\n\nstatic JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,\n                                   JSValue prop)\n{\n    JSAtom atom;\n    JSValue ret;\n\n    if (likely(JS_VALUE_GET_TAG(this_obj) == JS_TAG_OBJECT &&\n               JS_VALUE_GET_TAG(prop) == JS_TAG_INT)) {\n        JSObject *p;\n        uint32_t idx, len;\n        /* fast path for array access */\n        p = JS_VALUE_GET_OBJ(this_obj);\n        idx = JS_VALUE_GET_INT(prop);\n        len = (uint32_t)p->u.array.count;\n        if (unlikely(idx >= len))\n            goto slow_path;\n        switch(p->class_id) {\n        case JS_CLASS_ARRAY:\n        case JS_CLASS_ARGUMENTS:\n            return JS_DupValue(ctx, p->u.array.u.values[idx]);\n        case JS_CLASS_INT8_ARRAY:\n            return JS_NewInt32(ctx, p->u.array.u.int8_ptr[idx]);\n        case JS_CLASS_UINT8C_ARRAY:\n        case JS_CLASS_UINT8_ARRAY:\n            return JS_NewInt32(ctx, p->u.array.u.uint8_ptr[idx]);\n        case JS_CLASS_INT16_ARRAY:\n            return JS_NewInt32(ctx, p->u.array.u.int16_ptr[idx]);\n        case JS_CLASS_UINT16_ARRAY:\n            return JS_NewInt32(ctx, p->u.array.u.uint16_ptr[idx]);\n        case JS_CLASS_INT32_ARRAY:\n            return JS_NewInt32(ctx, p->u.array.u.int32_ptr[idx]);\n        case JS_CLASS_UINT32_ARRAY:\n            return JS_NewUint32(ctx, p->u.array.u.uint32_ptr[idx]);\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT64_ARRAY:\n            return JS_NewBigInt64(ctx, p->u.array.u.int64_ptr[idx]);\n        case JS_CLASS_BIG_UINT64_ARRAY:\n            return JS_NewBigUint64(ctx, p->u.array.u.uint64_ptr[idx]);\n#endif\n        case JS_CLASS_FLOAT32_ARRAY:\n            return __JS_NewFloat64(ctx, p->u.array.u.float_ptr[idx]);\n        case JS_CLASS_FLOAT64_ARRAY:\n            return __JS_NewFloat64(ctx, p->u.array.u.double_ptr[idx]);\n        default:\n            goto slow_path;\n        }\n    } else {\n    slow_path:\n        atom = JS_ValueToAtom(ctx, prop);\n        JS_FreeValue(ctx, prop);\n        if (unlikely(atom == JS_ATOM_NULL))\n            return JS_EXCEPTION;\n        ret = JS_GetProperty(ctx, this_obj, atom);\n        JS_FreeAtom(ctx, atom);\n        return ret;\n    }\n}\n\nJSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,\n                             uint32_t idx)\n{\n    return JS_GetPropertyValue(ctx, this_obj, JS_NewUint32(ctx, idx));\n}\n\n/* Check if an object has a generalized numeric property. Return value:\n   -1 for exception,\n   TRUE if property exists, stored into *pval,\n   FALSE if proprty does not exist.\n */\nstatic int JS_TryGetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx, JSValue *pval)\n{\n    JSValue val = JS_UNDEFINED;\n    JSAtom prop;\n    int present;\n\n    if (likely((uint64_t)idx <= JS_ATOM_MAX_INT)) {\n        /* fast path */\n        present = JS_HasProperty(ctx, obj, __JS_AtomFromUInt32(idx));\n        if (present > 0) {\n            val = JS_GetPropertyValue(ctx, obj, JS_NewInt32(ctx, idx));\n            if (unlikely(JS_IsException(val)))\n                present = -1;\n        }\n    } else {\n        prop = JS_NewAtomInt64(ctx, idx);\n        present = -1;\n        if (likely(prop != JS_ATOM_NULL)) {\n            present = JS_HasProperty(ctx, obj, prop);\n            if (present > 0) {\n                val = JS_GetProperty(ctx, obj, prop);\n                if (unlikely(JS_IsException(val)))\n                    present = -1;\n            }\n            JS_FreeAtom(ctx, prop);\n        }\n    }\n    *pval = val;\n    return present;\n}\n\nstatic JSValue JS_GetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx)\n{\n    JSAtom prop;\n    JSValue val;\n\n    if ((uint64_t)idx <= INT32_MAX) {\n        /* fast path for fast arrays */\n        return JS_GetPropertyValue(ctx, obj, JS_NewInt32(ctx, idx));\n    }\n    prop = JS_NewAtomInt64(ctx, idx);\n    if (prop == JS_ATOM_NULL)\n        return JS_EXCEPTION;\n\n    val = JS_GetProperty(ctx, obj, prop);\n    JS_FreeAtom(ctx, prop);\n    return val;\n}\n\nJSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,\n                          const char *prop)\n{\n    JSAtom atom;\n    JSValue ret;\n    atom = JS_NewAtom(ctx, prop);\n    ret = JS_GetProperty(ctx, this_obj, atom);\n    JS_FreeAtom(ctx, atom);\n    return ret;\n}\n\n/* Note: the property value is not initialized. Return NULL if memory\n   error. */\nstatic JSProperty *add_property(JSContext *ctx,\n                                JSObject *p, JSAtom prop, int prop_flags)\n{\n    JSShape *sh, *new_sh;\n\n    sh = p->shape;\n    if (sh->is_hashed) {\n        /* try to find an existing shape */\n        new_sh = find_hashed_shape_prop(ctx->rt, sh, prop, prop_flags);\n        if (new_sh) {\n            /* matching shape found: use it */\n            /*  the property array may need to be resized */\n            if (new_sh->prop_size != sh->prop_size) {\n                JSProperty *new_prop;\n                new_prop = js_realloc(ctx, p->prop, sizeof(p->prop[0]) *\n                                      new_sh->prop_size);\n                if (!new_prop)\n                    return NULL;\n                p->prop = new_prop;\n            }\n            p->shape = js_dup_shape(new_sh);\n            js_free_shape(ctx->rt, sh);\n            return &p->prop[new_sh->prop_count - 1];\n        } else if (sh->header.ref_count != 1) {\n            /* if the shape is shared, clone it */\n            new_sh = js_clone_shape(ctx, sh);\n            if (!new_sh)\n                return NULL;\n            /* hash the cloned shape */\n            new_sh->is_hashed = TRUE;\n            js_shape_hash_link(ctx->rt, new_sh);\n            js_free_shape(ctx->rt, p->shape);\n            p->shape = new_sh;\n        }\n    }\n    assert(p->shape->header.ref_count == 1);\n    if (add_shape_property(ctx, &p->shape, p, prop, prop_flags))\n        return NULL;\n    return &p->prop[p->shape->prop_count - 1];\n}\n\n/* can be called on Array or Arguments objects. return < 0 if\n   memory alloc error. */\nstatic no_inline __exception int convert_fast_array_to_array(JSContext *ctx,\n                                                             JSObject *p)\n{\n    JSProperty *pr;\n    JSShape *sh;\n    JSValue *tab;\n    uint32_t i, len, new_count;\n\n    if (js_shape_prepare_update(ctx, p, NULL))\n        return -1;\n    len = p->u.array.count;\n    /* resize the properties once to simplify the error handling */\n    sh = p->shape;\n    new_count = sh->prop_count + len;\n    if (new_count > sh->prop_size) {\n        if (resize_properties(ctx, &p->shape, p, new_count))\n            return -1;\n    }\n\n    tab = p->u.array.u.values;\n    for(i = 0; i < len; i++) {\n        /* add_property cannot fail here but\n           __JS_AtomFromUInt32(i) fails for i > INT32_MAX */\n        pr = add_property(ctx, p, __JS_AtomFromUInt32(i), JS_PROP_C_W_E);\n        pr->u.value = *tab++;\n    }\n    js_free(ctx, p->u.array.u.values);\n    p->u.array.count = 0;\n    p->u.array.u.values = NULL; /* fail safe */\n    p->u.array.u1.size = 0;\n    p->fast_array = 0;\n    return 0;\n}\n\nstatic int delete_property(JSContext *ctx, JSObject *p, JSAtom atom)\n{\n    JSShape *sh;\n    JSShapeProperty *pr, *lpr, *prop;\n    JSProperty *pr1;\n    uint32_t lpr_idx;\n    intptr_t h, h1;\n\n redo:\n    sh = p->shape;\n    h1 = atom & sh->prop_hash_mask;\n    h = sh->prop_hash_end[-h1 - 1];\n    prop = get_shape_prop(sh);\n    lpr = NULL;\n    lpr_idx = 0;   /* prevent warning */\n    while (h != 0) {\n        pr = &prop[h - 1];\n        if (likely(pr->atom == atom)) {\n            /* found ! */\n            if (!(pr->flags & JS_PROP_CONFIGURABLE))\n                return FALSE;\n            /* realloc the shape if needed */\n            if (lpr)\n                lpr_idx = lpr - get_shape_prop(sh);\n            if (js_shape_prepare_update(ctx, p, &pr))\n                return -1;\n            sh = p->shape;\n            /* remove property */\n            if (lpr) {\n                lpr = get_shape_prop(sh) + lpr_idx;\n                lpr->hash_next = pr->hash_next;\n            } else {\n                sh->prop_hash_end[-h1 - 1] = pr->hash_next;\n            }\n            sh->deleted_prop_count++;\n            /* free the entry */\n            pr1 = &p->prop[h - 1];\n            free_property(ctx->rt, pr1, pr->flags);\n            JS_FreeAtom(ctx, pr->atom);\n            /* put default values */\n            pr->flags = 0;\n            pr->atom = JS_ATOM_NULL;\n            pr1->u.value = JS_UNDEFINED;\n\n            /* compact the properties if too many deleted properties */\n            if (sh->deleted_prop_count >= 8 &&\n                sh->deleted_prop_count >= ((unsigned)sh->prop_count / 2)) {\n                compact_properties(ctx, p);\n            }\n            return TRUE;\n        }\n        lpr = pr;\n        h = pr->hash_next;\n    }\n\n    if (p->is_exotic) {\n        if (p->fast_array) {\n            uint32_t idx;\n            if (JS_AtomIsArrayIndex(ctx, &idx, atom) &&\n                idx < p->u.array.count) {\n                if (p->class_id == JS_CLASS_ARRAY ||\n                    p->class_id == JS_CLASS_ARGUMENTS) {\n                    /* Special case deleting the last element of a fast Array */\n                    if (idx == p->u.array.count - 1) {\n                        JS_FreeValue(ctx, p->u.array.u.values[idx]);\n                        p->u.array.count = idx;\n                        return TRUE;\n                    }\n                    if (convert_fast_array_to_array(ctx, p))\n                        return -1;\n                    goto redo;\n                } else {\n                    return FALSE; /* not configurable */\n                }\n            }\n        } else {\n            const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n            if (em && em->delete_property) {\n                return em->delete_property(ctx, JS_MKPTR(JS_TAG_OBJECT, p), atom);\n            }\n        }\n    }\n    /* not found */\n    return TRUE;\n}\n\nstatic int call_setter(JSContext *ctx, JSObject *setter,\n                       JSValueConst this_obj, JSValue val, int flags)\n{\n    JSValue ret, func;\n    if (likely(setter)) {\n        func = JS_MKPTR(JS_TAG_OBJECT, setter);\n        /* Note: the field could be removed in the setter */\n        func = JS_DupValue(ctx, func);\n        ret = JS_CallFree(ctx, func, this_obj, 1, (JSValueConst *)&val);\n        JS_FreeValue(ctx, val);\n        if (JS_IsException(ret))\n            return -1;\n        JS_FreeValue(ctx, ret);\n        return TRUE;\n    } else {\n        JS_FreeValue(ctx, val);\n        if ((flags & JS_PROP_THROW) ||\n            ((flags & JS_PROP_THROW_STRICT) && is_strict_mode(ctx))) {\n            JS_ThrowTypeError(ctx, \"no setter for property\");\n            return -1;\n        }\n        return FALSE;\n    }\n}\n\n/* set the array length and remove the array elements if necessary. */\nstatic int set_array_length(JSContext *ctx, JSObject *p, JSProperty *prop,\n                            JSValue val, int flags)\n{\n    uint32_t len, idx, cur_len;\n    int i, ret;\n\n    ret = JS_ToArrayLengthFree(ctx, &len, val);\n    if (ret)\n        return -1;\n    if (likely(p->fast_array)) {\n        uint32_t old_len = p->u.array.count;\n        if (len < old_len) {\n            for(i = len; i < old_len; i++) {\n                JS_FreeValue(ctx, p->u.array.u.values[i]);\n            }\n            p->u.array.count = len;\n        }\n        prop->u.value = JS_NewUint32(ctx, len);\n    } else {\n        /* Note: length is always a uint32 because the object is an\n           array */\n        JS_ToUint32(ctx, &cur_len, prop->u.value);\n        if (len < cur_len) {\n            uint32_t d;\n            JSShape *sh;\n            JSShapeProperty *pr;\n\n            d = cur_len - len;\n            sh = p->shape;\n            if (d <= sh->prop_count) {\n                JSAtom atom;\n\n                /* faster to iterate */\n                while (cur_len > len) {\n                    atom = JS_NewAtomUInt32(ctx, cur_len - 1);\n                    ret = delete_property(ctx, p, atom);\n                    JS_FreeAtom(ctx, atom);\n                    if (unlikely(!ret)) {\n                        /* unlikely case: property is not\n                           configurable */\n                        break;\n                    }\n                    cur_len--;\n                }\n            } else {\n                /* faster to iterate thru all the properties. Need two\n                   passes in case one of the property is not\n                   configurable */\n                cur_len = len;\n                for(i = 0, pr = get_shape_prop(sh); i < sh->prop_count;\n                    i++, pr++) {\n                    if (pr->atom != JS_ATOM_NULL &&\n                        JS_AtomIsArrayIndex(ctx, &idx, pr->atom)) {\n                        if (idx >= cur_len &&\n                            !(pr->flags & JS_PROP_CONFIGURABLE)) {\n                            cur_len = idx + 1;\n                        }\n                    }\n                }\n\n                for(i = 0, pr = get_shape_prop(sh); i < sh->prop_count;\n                    i++, pr++) {\n                    if (pr->atom != JS_ATOM_NULL &&\n                        JS_AtomIsArrayIndex(ctx, &idx, pr->atom)) {\n                        if (idx >= cur_len) {\n                            /* remove the property */\n                            delete_property(ctx, p, pr->atom);\n                            /* WARNING: the shape may have been modified */\n                            sh = p->shape;\n                            pr = get_shape_prop(sh) + i;\n                        }\n                    }\n                }\n            }\n        } else {\n            cur_len = len;\n        }\n        set_value(ctx, &p->prop[0].u.value, JS_NewUint32(ctx, cur_len));\n        if (unlikely(cur_len > len)) {\n            return JS_ThrowTypeErrorOrFalse(ctx, flags, \"not configurable\");\n        }\n    }\n    return TRUE;\n}\n\n/* Preconditions: 'p' must be of class JS_CLASS_ARRAY, p->fast_array =\n   TRUE and p->extensible = TRUE */\nstatic int add_fast_array_element(JSContext *ctx, JSObject *p,\n                                  JSValue val, int flags)\n{\n    uint32_t new_len, array_len;\n    /* extend the array by one */\n    /* XXX: convert to slow array if new_len > 2^31-1 elements */\n    new_len = p->u.array.count + 1;\n    /* update the length if necessary. We assume that if the length is\n       not an integer, then if it >= 2^31.  */\n    if (likely(JS_VALUE_GET_TAG(p->prop[0].u.value) == JS_TAG_INT)) {\n        array_len = JS_VALUE_GET_INT(p->prop[0].u.value);\n        if (new_len > array_len) {\n            if (unlikely(!(get_shape_prop(p->shape)->flags & JS_PROP_WRITABLE))) {\n                JS_FreeValue(ctx, val);\n                return JS_ThrowTypeErrorReadOnly(ctx, flags, JS_ATOM_length);\n            }\n            p->prop[0].u.value = JS_NewInt32(ctx, new_len);\n        }\n    }\n    if (unlikely(new_len > p->u.array.u1.size)) {\n        uint32_t new_size;\n        size_t slack;\n        JSValue *new_array_prop;\n        /* XXX: potential arithmetic overflow */\n        new_size = max_int(new_len, p->u.array.u1.size * 3 / 2);\n        new_array_prop = js_realloc2(ctx, p->u.array.u.values, sizeof(JSValue) * new_size, &slack);\n        if (!new_array_prop) {\n            JS_FreeValue(ctx, val);\n            return -1;\n        }\n        new_size += slack / sizeof(*new_array_prop);\n        p->u.array.u.values = new_array_prop;\n        p->u.array.u1.size = new_size;\n    }\n    p->u.array.u.values[new_len - 1] = val;\n    p->u.array.count = new_len;\n    return TRUE;\n}\n\nstatic void js_free_desc(JSContext *ctx, JSPropertyDescriptor *desc)\n{\n    JS_FreeValue(ctx, desc->getter);\n    JS_FreeValue(ctx, desc->setter);\n    JS_FreeValue(ctx, desc->value);\n}\n\n/* generic (and slower) version of JS_SetProperty() for Reflect.set() */\nstatic int JS_SetPropertyGeneric(JSContext *ctx,\n                                 JSObject *p, JSAtom prop,\n                                 JSValue val, JSValueConst this_obj,\n                                 int flags)\n{\n    int ret;\n    JSPropertyDescriptor desc;\n\n    while (p != NULL) {\n        if (p->is_exotic) {\n            const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n            if (em && em->set_property) {\n                JSValue obj1;\n                /* set_property can free the prototype */\n                obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n                ret = em->set_property(ctx, obj1, prop,\n                                       val, this_obj, flags);\n                JS_FreeValue(ctx, obj1);\n                JS_FreeValue(ctx, val);\n                return ret;\n            }\n        }\n\n        ret = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);\n        if (ret < 0)\n            return ret;\n        if (ret) {\n            if (desc.flags & JS_PROP_GETSET) {\n                JSObject *setter;\n                if (JS_IsUndefined(desc.setter))\n                    setter = NULL;\n                else\n                    setter = JS_VALUE_GET_OBJ(desc.setter);\n                ret = call_setter(ctx, setter, this_obj, val, flags);\n                JS_FreeValue(ctx, desc.getter);\n                JS_FreeValue(ctx, desc.setter);\n                return ret;\n            } else {\n                JS_FreeValue(ctx, desc.value);\n                if (!(desc.flags & JS_PROP_WRITABLE)) {\n                    goto read_only_error;\n                }\n            }\n            break;\n        }\n        p = p->shape->proto;\n    }\n\n    if (!JS_IsObject(this_obj))\n        return JS_ThrowTypeErrorOrFalse(ctx, flags, \"receiver is not an object\");\n\n    p = JS_VALUE_GET_OBJ(this_obj);\n\n    /* modify the property in this_obj if it already exists */\n    ret = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);\n    if (ret < 0)\n        return ret;\n    if (ret) {\n        if (desc.flags & JS_PROP_GETSET) {\n            JS_FreeValue(ctx, desc.getter);\n            JS_FreeValue(ctx, desc.setter);\n            JS_FreeValue(ctx, val);\n            return JS_ThrowTypeErrorOrFalse(ctx, flags, \"setter is forbidden\");\n        } else {\n            JS_FreeValue(ctx, desc.value);\n            if (!(desc.flags & JS_PROP_WRITABLE) ||\n                p->class_id == JS_CLASS_MODULE_NS) {\n            read_only_error:\n                JS_FreeValue(ctx, val);\n                return JS_ThrowTypeErrorReadOnly(ctx, flags, prop);\n            }\n        }\n        ret = JS_DefineProperty(ctx, this_obj, prop, val,\n                                JS_UNDEFINED, JS_UNDEFINED,\n                                JS_PROP_HAS_VALUE);\n        JS_FreeValue(ctx, val);\n        return ret;\n    }\n\n    ret = JS_CreateProperty(ctx, p, prop, val, JS_UNDEFINED, JS_UNDEFINED,\n                            flags |\n                            JS_PROP_HAS_VALUE |\n                            JS_PROP_HAS_ENUMERABLE |\n                            JS_PROP_HAS_WRITABLE |\n                            JS_PROP_HAS_CONFIGURABLE |\n                            JS_PROP_C_W_E);\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\n/* return -1 in case of exception or TRUE or FALSE. Warning: 'val' is\n   freed by the function. 'flags' is a bitmask of JS_PROP_NO_ADD,\n   JS_PROP_THROW or JS_PROP_THROW_STRICT. If JS_PROP_NO_ADD is set,\n   the new property is not added and an error is raised. */\nint JS_SetPropertyInternal(JSContext *ctx, JSValueConst this_obj,\n                           JSAtom prop, JSValue val, int flags)\n{\n    JSObject *p, *p1;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    uint32_t tag;\n    JSPropertyDescriptor desc;\n    int ret;\n#if 0\n    printf(\"JS_SetPropertyInternal: \"); print_atom(ctx, prop); printf(\"\\n\");\n#endif\n    tag = JS_VALUE_GET_TAG(this_obj);\n    if (unlikely(tag != JS_TAG_OBJECT)) {\n        switch(tag) {\n        case JS_TAG_NULL:\n            JS_FreeValue(ctx, val);\n            JS_ThrowTypeErrorAtom(ctx, \"cannot set property '%s' of null\", prop);\n            return -1;\n        case JS_TAG_UNDEFINED:\n            JS_FreeValue(ctx, val);\n            JS_ThrowTypeErrorAtom(ctx, \"cannot set property '%s' of undefined\", prop);\n            return -1;\n        default:\n            /* even on a primitive type we can have setters on the prototype */\n            p = NULL;\n            p1 = JS_VALUE_GET_OBJ(JS_GetPrototypePrimitive(ctx, this_obj));\n            goto prototype_lookup;\n        }\n    }\n    p = JS_VALUE_GET_OBJ(this_obj);\nretry:\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        if (likely((prs->flags & (JS_PROP_TMASK | JS_PROP_WRITABLE |\n                                  JS_PROP_LENGTH)) == JS_PROP_WRITABLE)) {\n            /* fast case */\n            set_value(ctx, &pr->u.value, val);\n            return TRUE;\n        } else if ((prs->flags & (JS_PROP_LENGTH | JS_PROP_WRITABLE)) ==\n                   (JS_PROP_LENGTH | JS_PROP_WRITABLE)) {\n            assert(p->class_id == JS_CLASS_ARRAY);\n            assert(prop == JS_ATOM_length);\n            return set_array_length(ctx, p, pr, val, flags);\n        } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n            return call_setter(ctx, pr->u.getset.setter, this_obj, val, flags);\n        } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n            /* JS_PROP_WRITABLE is always true for variable\n               references, but they are write protected in module name\n               spaces. */\n            if (p->class_id == JS_CLASS_MODULE_NS)\n                goto read_only_prop;\n            set_value(ctx, pr->u.var_ref->pvalue, val);\n            return TRUE;\n        } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n            /* Instantiate property and retry (potentially useless) */\n            if (JS_AutoInitProperty(ctx, p, prop, pr)) {\n                JS_FreeValue(ctx, val);\n                return -1;\n            }\n            goto retry;\n        } else {\n            goto read_only_prop;\n        }\n    }\n\n    p1 = p;\n    for(;;) {\n        if (p1->is_exotic) {\n            if (p1->fast_array) {\n                if (__JS_AtomIsTaggedInt(prop)) {\n                    uint32_t idx = __JS_AtomToUInt32(prop);\n                    if (idx < p1->u.array.count) {\n                        if (unlikely(p == p1))\n                            return JS_SetPropertyValue(ctx, this_obj, JS_NewInt32(ctx, idx), val, flags);\n                        else\n                            break;\n                    } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                               p1->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                        goto typed_array_oob;\n                    }\n                } else if (p1->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                           p1->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                    ret = JS_AtomIsNumericIndex(ctx, prop);\n                    if (ret != 0) {\n                        if (ret < 0) {\n                            JS_FreeValue(ctx, val);\n                            return -1;\n                        }\n                    typed_array_oob:\n                        val = JS_ToNumberFree(ctx, val);\n                        JS_FreeValue(ctx, val);\n                        if (JS_IsException(val))\n                            return -1;\n                        if (typed_array_is_detached(ctx, p1)) {\n                            JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n                            return -1;\n                        }\n                        return JS_ThrowTypeErrorOrFalse(ctx, flags, \"out-of-bound numeric index\");\n                    }\n                }\n            } else {\n                const JSClassExoticMethods *em = ctx->rt->class_array[p1->class_id].exotic;\n                if (em) {\n                    JSValue obj1;\n                    if (em->set_property) {\n                        /* set_property can free the prototype */\n                        obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1));\n                        ret = em->set_property(ctx, obj1, prop,\n                                               val, this_obj, flags);\n                        JS_FreeValue(ctx, obj1);\n                        JS_FreeValue(ctx, val);\n                        return ret;\n                    }\n                    if (em->get_own_property) {\n                        /* get_own_property can free the prototype */\n                        obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1));\n                        ret = em->get_own_property(ctx, &desc,\n                                                   obj1, prop);\n                        JS_FreeValue(ctx, obj1);\n                        if (ret < 0) {\n                            JS_FreeValue(ctx, val);\n                            return ret;\n                        }\n                        if (ret) {\n                            if (desc.flags & JS_PROP_GETSET) {\n                                JSObject *setter;\n                                if (JS_IsUndefined(desc.setter))\n                                    setter = NULL;\n                                else\n                                    setter = JS_VALUE_GET_OBJ(desc.setter);\n                                ret = call_setter(ctx, setter, this_obj, val, flags);\n                                JS_FreeValue(ctx, desc.getter);\n                                JS_FreeValue(ctx, desc.setter);\n                                return ret;\n                            } else {\n                                JS_FreeValue(ctx, desc.value);\n                                if (!(desc.flags & JS_PROP_WRITABLE))\n                                    goto read_only_prop;\n                                if (likely(p == p1)) {\n                                    ret = JS_DefineProperty(ctx, this_obj, prop, val,\n                                                            JS_UNDEFINED, JS_UNDEFINED,\n                                                            JS_PROP_HAS_VALUE);\n                                    JS_FreeValue(ctx, val);\n                                    return ret;\n                                } else {\n                                    break;\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        p1 = p1->shape->proto;\n    prototype_lookup:\n        if (!p1)\n            break;\n\n    retry2:\n        prs = find_own_property(&pr, p1, prop);\n        if (prs) {\n            if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n                return call_setter(ctx, pr->u.getset.setter, this_obj, val, flags);\n            } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                /* Instantiate property and retry (potentially useless) */\n                if (JS_AutoInitProperty(ctx, p1, prop, pr))\n                    return -1;\n                goto retry2;\n            } else if (!(prs->flags & JS_PROP_WRITABLE)) {\n            read_only_prop:\n                JS_FreeValue(ctx, val);\n                return JS_ThrowTypeErrorReadOnly(ctx, flags, prop);\n            }\n        }\n    }\n\n    if (unlikely(flags & JS_PROP_NO_ADD)) {\n        JS_FreeValue(ctx, val);\n        JS_ThrowReferenceErrorNotDefined(ctx, prop);\n        return -1;\n    }\n\n    if (unlikely(!p)) {\n        JS_FreeValue(ctx, val);\n        return JS_ThrowTypeErrorOrFalse(ctx, flags, \"not an object\");\n    }\n\n    if (unlikely(!p->extensible)) {\n        JS_FreeValue(ctx, val);\n        return JS_ThrowTypeErrorOrFalse(ctx, flags, \"object is not extensible\");\n    }\n\n    if (p->is_exotic) {\n        if (p->class_id == JS_CLASS_ARRAY && p->fast_array &&\n            __JS_AtomIsTaggedInt(prop)) {\n            uint32_t idx = __JS_AtomToUInt32(prop);\n            if (idx == p->u.array.count) {\n                /* fast case */\n                return add_fast_array_element(ctx, p, val, flags);\n            } else {\n                goto generic_create_prop;\n            }\n        } else {\n        generic_create_prop:\n            ret = JS_CreateProperty(ctx, p, prop, val, JS_UNDEFINED, JS_UNDEFINED,\n                                    flags |\n                                    JS_PROP_HAS_VALUE |\n                                    JS_PROP_HAS_ENUMERABLE |\n                                    JS_PROP_HAS_WRITABLE |\n                                    JS_PROP_HAS_CONFIGURABLE |\n                                    JS_PROP_C_W_E);\n            JS_FreeValue(ctx, val);\n            return ret;\n        }\n    }\n\n    pr = add_property(ctx, p, prop, JS_PROP_C_W_E);\n    if (unlikely(!pr)) {\n        JS_FreeValue(ctx, val);\n        return -1;\n    }\n    pr->u.value = val;\n    return TRUE;\n}\n\n/* flags can be JS_PROP_THROW or JS_PROP_THROW_STRICT */\nstatic int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,\n                               JSValue prop, JSValue val, int flags)\n{\n    if (likely(JS_VALUE_GET_TAG(this_obj) == JS_TAG_OBJECT &&\n               JS_VALUE_GET_TAG(prop) == JS_TAG_INT)) {\n        JSObject *p;\n        uint32_t idx;\n        double d;\n        int32_t v;\n\n        /* fast path for array access */\n        p = JS_VALUE_GET_OBJ(this_obj);\n        idx = JS_VALUE_GET_INT(prop);\n        switch(p->class_id) {\n        case JS_CLASS_ARRAY:\n            if (unlikely(idx >= (uint32_t)p->u.array.count)) {\n                JSObject *p1;\n                JSShape *sh1;\n\n                /* fast path to add an element to the array */\n                if (idx != (uint32_t)p->u.array.count ||\n                    !p->fast_array || !p->extensible)\n                    goto slow_path;\n                /* check if prototype chain has a numeric property */\n                p1 = p->shape->proto;\n                while (p1 != NULL) {\n                    sh1 = p1->shape;\n                    if (p1->class_id == JS_CLASS_ARRAY) {\n                        if (unlikely(!p1->fast_array))\n                            goto slow_path;\n                    } else if (p1->class_id == JS_CLASS_OBJECT) {\n                        if (unlikely(sh1->has_small_array_index))\n                            goto slow_path;\n                    } else {\n                        goto slow_path;\n                    }\n                    p1 = sh1->proto;\n                }\n                /* add element */\n                return add_fast_array_element(ctx, p, val, flags);\n            }\n            set_value(ctx, &p->u.array.u.values[idx], val);\n            break;\n        case JS_CLASS_ARGUMENTS:\n            if (unlikely(idx >= (uint32_t)p->u.array.count))\n                goto slow_path;\n            set_value(ctx, &p->u.array.u.values[idx], val);\n            break;\n        case JS_CLASS_UINT8C_ARRAY:\n            if (JS_ToUint8ClampFree(ctx, &v, val))\n                return -1;\n            /* Note: the conversion can detach the typed array, so the\n               array bound check must be done after */\n            if (unlikely(idx >= (uint32_t)p->u.array.count))\n                goto ta_out_of_bound;\n            p->u.array.u.uint8_ptr[idx] = v;\n            break;\n        case JS_CLASS_INT8_ARRAY:\n        case JS_CLASS_UINT8_ARRAY:\n            if (JS_ToInt32Free(ctx, &v, val))\n                return -1;\n            if (unlikely(idx >= (uint32_t)p->u.array.count))\n                goto ta_out_of_bound;\n            p->u.array.u.uint8_ptr[idx] = v;\n            break;\n        case JS_CLASS_INT16_ARRAY:\n        case JS_CLASS_UINT16_ARRAY:\n            if (JS_ToInt32Free(ctx, &v, val))\n                return -1;\n            if (unlikely(idx >= (uint32_t)p->u.array.count))\n                goto ta_out_of_bound;\n            p->u.array.u.uint16_ptr[idx] = v;\n            break;\n        case JS_CLASS_INT32_ARRAY:\n        case JS_CLASS_UINT32_ARRAY:\n            if (JS_ToInt32Free(ctx, &v, val))\n                return -1;\n            if (unlikely(idx >= (uint32_t)p->u.array.count))\n                goto ta_out_of_bound;\n            p->u.array.u.uint32_ptr[idx] = v;\n            break;\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT64_ARRAY:\n        case JS_CLASS_BIG_UINT64_ARRAY:\n            /* XXX: need specific conversion function */\n            {\n                int64_t v;\n                if (JS_ToBigInt64Free(ctx, &v, val))\n                    return -1;\n                if (unlikely(idx >= (uint32_t)p->u.array.count))\n                    goto ta_out_of_bound;\n                p->u.array.u.uint64_ptr[idx] = v;\n            }\n            break;\n#endif\n        case JS_CLASS_FLOAT32_ARRAY:\n            if (JS_ToFloat64Free(ctx, &d, val))\n                return -1;\n            if (unlikely(idx >= (uint32_t)p->u.array.count))\n                goto ta_out_of_bound;\n            p->u.array.u.float_ptr[idx] = d;\n            break;\n        case JS_CLASS_FLOAT64_ARRAY:\n            if (JS_ToFloat64Free(ctx, &d, val))\n                return -1;\n            if (unlikely(idx >= (uint32_t)p->u.array.count)) {\n            ta_out_of_bound:\n                if (typed_array_is_detached(ctx, p)) {\n                    JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n                    return -1;\n                } else {\n                    return JS_ThrowTypeErrorOrFalse(ctx, flags, \"out-of-bound numeric index\");\n                }\n            }\n            p->u.array.u.double_ptr[idx] = d;\n            break;\n        default:\n            goto slow_path;\n        }\n        return TRUE;\n    } else {\n        JSAtom atom;\n        int ret;\n    slow_path:\n        atom = JS_ValueToAtom(ctx, prop);\n        JS_FreeValue(ctx, prop);\n        if (unlikely(atom == JS_ATOM_NULL)) {\n            JS_FreeValue(ctx, val);\n            return -1;\n        }\n        ret = JS_SetPropertyInternal(ctx, this_obj, atom, val, flags);\n        JS_FreeAtom(ctx, atom);\n        return ret;\n    }\n}\n\nint JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,\n                         uint32_t idx, JSValue val)\n{\n    return JS_SetPropertyValue(ctx, this_obj, JS_NewUint32(ctx, idx), val,\n                               JS_PROP_THROW);\n}\n\nint JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,\n                        int64_t idx, JSValue val)\n{\n    JSAtom prop;\n    int res;\n\n    if ((uint64_t)idx <= INT32_MAX) {\n        /* fast path for fast arrays */\n        return JS_SetPropertyValue(ctx, this_obj, JS_NewInt32(ctx, idx), val,\n                                   JS_PROP_THROW);\n    }\n    prop = JS_NewAtomInt64(ctx, idx);\n    if (prop == JS_ATOM_NULL) {\n        JS_FreeValue(ctx, val);\n        return -1;\n    }\n    res = JS_SetProperty(ctx, this_obj, prop, val);\n    JS_FreeAtom(ctx, prop);\n    return res;\n}\n\nint JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,\n                      const char *prop, JSValue val)\n{\n    JSAtom atom;\n    int ret;\n    atom = JS_NewAtom(ctx, prop);\n    ret = JS_SetPropertyInternal(ctx, this_obj, atom, val, JS_PROP_THROW);\n    JS_FreeAtom(ctx, atom);\n    return ret;\n}\n\n/* compute the property flags. For each flag: (JS_PROP_HAS_x forces\n   it, otherwise def_flags is used)\n   Note: makes assumption about the bit pattern of the flags\n*/\nstatic int get_prop_flags(int flags, int def_flags)\n{\n    int mask;\n    mask = (flags >> JS_PROP_HAS_SHIFT) & JS_PROP_C_W_E;\n    return (flags & mask) | (def_flags & ~mask);\n}\n\nstatic int JS_CreateProperty(JSContext *ctx, JSObject *p,\n                             JSAtom prop, JSValueConst val,\n                             JSValueConst getter, JSValueConst setter,\n                             int flags)\n{\n    JSProperty *pr;\n    int ret, prop_flags;\n\n    /* add a new property or modify an existing exotic one */\n    if (p->is_exotic) {\n        if (p->class_id == JS_CLASS_ARRAY) {\n            uint32_t idx, len;\n\n            if (p->fast_array) {\n                if (__JS_AtomIsTaggedInt(prop)) {\n                    idx = __JS_AtomToUInt32(prop);\n                    if (idx == p->u.array.count) {\n                        if (!p->extensible)\n                            goto not_extensible;\n                        if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET))\n                            goto convert_to_array;\n                        prop_flags = get_prop_flags(flags, 0);\n                        if (prop_flags != JS_PROP_C_W_E)\n                            goto convert_to_array;\n                        return add_fast_array_element(ctx, p,\n                                                      JS_DupValue(ctx, val), flags);\n                    } else {\n                        goto convert_to_array;\n                    }\n                } else if (JS_AtomIsArrayIndex(ctx, &idx, prop)) {\n                    /* convert the fast array to normal array */\n                convert_to_array:\n                    if (convert_fast_array_to_array(ctx, p))\n                        return -1;\n                    goto generic_array;\n                }\n            } else if (JS_AtomIsArrayIndex(ctx, &idx, prop)) {\n                JSProperty *plen;\n                JSShapeProperty *pslen;\n            generic_array:\n                /* update the length field */\n                plen = &p->prop[0];\n                JS_ToUint32(ctx, &len, plen->u.value);\n                if ((idx + 1) > len) {\n                    pslen = get_shape_prop(p->shape);\n                    if (unlikely(!(pslen->flags & JS_PROP_WRITABLE)))\n                        return JS_ThrowTypeErrorReadOnly(ctx, flags, JS_ATOM_length);\n                    /* XXX: should update the length after defining\n                       the property */\n                    len = idx + 1;\n                    set_value(ctx, &plen->u.value, JS_NewUint32(ctx, len));\n                }\n            }\n        } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                   p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n            ret = JS_AtomIsNumericIndex(ctx, prop);\n            if (ret != 0) {\n                if (ret < 0)\n                    return -1;\n                return JS_ThrowTypeErrorOrFalse(ctx, flags, \"cannot create numeric index in typed array\");\n            }\n        } else if (!(flags & JS_PROP_NO_EXOTIC)) {\n            const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic;\n            if (em) {\n                if (em->define_own_property) {\n                    return em->define_own_property(ctx, JS_MKPTR(JS_TAG_OBJECT, p),\n                                                   prop, val, getter, setter, flags);\n                }\n                ret = JS_IsExtensible(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n                if (ret < 0)\n                    return -1;\n                if (!ret)\n                    goto not_extensible;\n            }\n        }\n    }\n\n    if (!p->extensible) {\n    not_extensible:\n        return JS_ThrowTypeErrorOrFalse(ctx, flags, \"object is not extensible\");\n    }\n\n    if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n        prop_flags = (flags & (JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE)) |\n            JS_PROP_GETSET;\n    } else {\n        prop_flags = flags & JS_PROP_C_W_E;\n    }\n    pr = add_property(ctx, p, prop, prop_flags);\n    if (unlikely(!pr))\n        return -1;\n    if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n        pr->u.getset.getter = NULL;\n        if ((flags & JS_PROP_HAS_GET) && JS_IsFunction(ctx, getter)) {\n            pr->u.getset.getter =\n                JS_VALUE_GET_OBJ(JS_DupValue(ctx, getter));\n        }\n        pr->u.getset.setter = NULL;\n        if ((flags & JS_PROP_HAS_SET) && JS_IsFunction(ctx, setter)) {\n            pr->u.getset.setter =\n                JS_VALUE_GET_OBJ(JS_DupValue(ctx, setter));\n        }\n    } else {\n        if (flags & JS_PROP_HAS_VALUE) {\n            pr->u.value = JS_DupValue(ctx, val);\n        } else {\n            pr->u.value = JS_UNDEFINED;\n        }\n    }\n    return TRUE;\n}\n\n/* return FALSE if not OK */\nstatic BOOL check_define_prop_flags(int prop_flags, int flags)\n{\n    BOOL has_accessor, is_getset;\n\n    if (!(prop_flags & JS_PROP_CONFIGURABLE)) {\n        if ((flags & (JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE)) ==\n            (JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE)) {\n            return FALSE;\n        }\n        if ((flags & JS_PROP_HAS_ENUMERABLE) &&\n            (flags & JS_PROP_ENUMERABLE) != (prop_flags & JS_PROP_ENUMERABLE))\n            return FALSE;\n    }\n    if (flags & (JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE |\n                 JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n        if (!(prop_flags & JS_PROP_CONFIGURABLE)) {\n            has_accessor = ((flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) != 0);\n            is_getset = ((prop_flags & JS_PROP_TMASK) == JS_PROP_GETSET);\n            if (has_accessor != is_getset)\n                return FALSE;\n            if (!has_accessor && !is_getset && !(prop_flags & JS_PROP_WRITABLE)) {\n                /* not writable: cannot set the writable bit */\n                if ((flags & (JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE)) ==\n                    (JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE))\n                    return FALSE;\n            }\n        }\n    }\n    return TRUE;\n}\n\n/* ensure that the shape can be safely modified */\nstatic int js_shape_prepare_update(JSContext *ctx, JSObject *p,\n                                   JSShapeProperty **pprs)\n{\n    JSShape *sh;\n    uint32_t idx = 0;    /* prevent warning */\n\n    sh = p->shape;\n    if (sh->is_hashed) {\n        if (sh->header.ref_count != 1) {\n            if (pprs)\n                idx = *pprs - get_shape_prop(sh);\n            /* clone the shape (the resulting one is no longer hashed) */\n            sh = js_clone_shape(ctx, sh);\n            if (!sh)\n                return -1;\n            js_free_shape(ctx->rt, p->shape);\n            p->shape = sh;\n            if (pprs)\n                *pprs = get_shape_prop(sh) + idx;\n        } else {\n            js_shape_hash_unlink(ctx->rt, sh);\n            sh->is_hashed = FALSE;\n        }\n    }\n    return 0;\n}\n\nstatic int js_update_property_flags(JSContext *ctx, JSObject *p,\n                                    JSShapeProperty **pprs, int flags)\n{\n    if (flags != (*pprs)->flags) {\n        if (js_shape_prepare_update(ctx, p, pprs))\n            return -1;\n        (*pprs)->flags = flags;\n    }\n    return 0;\n}\n\n/* allowed flags:\n   JS_PROP_CONFIGURABLE, JS_PROP_WRITABLE, JS_PROP_ENUMERABLE\n   JS_PROP_HAS_GET, JS_PROP_HAS_SET, JS_PROP_HAS_VALUE,\n   JS_PROP_HAS_CONFIGURABLE, JS_PROP_HAS_WRITABLE, JS_PROP_HAS_ENUMERABLE,\n   JS_PROP_THROW, JS_PROP_NO_EXOTIC.\n   If JS_PROP_THROW is set, return an exception instead of FALSE.\n   if JS_PROP_NO_EXOTIC is set, do not call the exotic\n   define_own_property callback.\n   return -1 (exception), FALSE or TRUE.\n*/\nint JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,\n                      JSAtom prop, JSValueConst val,\n                      JSValueConst getter, JSValueConst setter, int flags)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    int mask, res;\n\n    if (JS_VALUE_GET_TAG(this_obj) != JS_TAG_OBJECT) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    p = JS_VALUE_GET_OBJ(this_obj);\n\n redo_prop_update:\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        /* property already exists */\n        if (!check_define_prop_flags(prs->flags, flags)) {\n        not_configurable:\n            return JS_ThrowTypeErrorOrFalse(ctx, flags, \"property is not configurable\");\n        }\n\n    retry:\n        if (flags & (JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE |\n                     JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n            if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n                JSObject *new_getter, *new_setter;\n\n                if (JS_IsFunction(ctx, getter)) {\n                    new_getter = JS_VALUE_GET_OBJ(getter);\n                } else {\n                    new_getter = NULL;\n                }\n                if (JS_IsFunction(ctx, setter)) {\n                    new_setter = JS_VALUE_GET_OBJ(setter);\n                } else {\n                    new_setter = NULL;\n                }\n\n                if ((prs->flags & JS_PROP_TMASK) != JS_PROP_GETSET) {\n                    if (js_shape_prepare_update(ctx, p, &prs))\n                        return -1;\n                    /* convert to getset */\n                    if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                        free_var_ref(ctx->rt, pr->u.var_ref);\n                    } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                        /* clear property and update */\n                        if (js_shape_prepare_update(ctx, p, &prs))\n                            return -1;\n                        js_autoinit_free(ctx->rt, pr);\n                        prs->flags &= ~JS_PROP_TMASK;\n                        pr->u.value = JS_UNDEFINED;\n                        goto retry;\n                    } else {\n                        JS_FreeValue(ctx, pr->u.value);\n                    }\n                    prs->flags = (prs->flags &\n                                  (JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE)) |\n                        JS_PROP_GETSET;\n                    pr->u.getset.getter = NULL;\n                    pr->u.getset.setter = NULL;\n                } else {\n                    if (!(prs->flags & JS_PROP_CONFIGURABLE)) {\n                        if ((flags & JS_PROP_HAS_GET) &&\n                            new_getter != pr->u.getset.getter) {\n                            goto not_configurable;\n                        }\n                        if ((flags & JS_PROP_HAS_SET) &&\n                            new_setter != pr->u.getset.setter) {\n                            goto not_configurable;\n                        }\n                    }\n                }\n                if (flags & JS_PROP_HAS_GET) {\n                    if (pr->u.getset.getter)\n                        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter));\n                    if (new_getter)\n                        JS_DupValue(ctx, getter);\n                    pr->u.getset.getter = new_getter;\n                }\n                if (flags & JS_PROP_HAS_SET) {\n                    if (pr->u.getset.setter)\n                        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter));\n                    if (new_setter)\n                        JS_DupValue(ctx, setter);\n                    pr->u.getset.setter = new_setter;\n                }\n            } else {\n                if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n                    /* convert to data descriptor */\n                    if (js_shape_prepare_update(ctx, p, &prs))\n                        return -1;\n                    if (pr->u.getset.getter)\n                        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter));\n                    if (pr->u.getset.setter)\n                        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter));\n                    prs->flags &= ~(JS_PROP_TMASK | JS_PROP_WRITABLE);\n                    pr->u.value = JS_UNDEFINED;\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                    /* Note: JS_PROP_VARREF is always writable */\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                    /* clear property and update */\n                    if (js_shape_prepare_update(ctx, p, &prs))\n                        return -1;\n                    js_autoinit_free(ctx->rt, pr);\n                    prs->flags &= ~JS_PROP_TMASK;\n                    pr->u.value = JS_UNDEFINED;\n                } else {\n                    if ((prs->flags & (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)) == 0 &&\n                        (flags & JS_PROP_HAS_VALUE) &&\n                        !js_same_value(ctx, val, pr->u.value)) {\n                        goto not_configurable;\n                    }\n                }\n                if (prs->flags & JS_PROP_LENGTH) {\n                    if (flags & JS_PROP_HAS_VALUE) {\n                        res = set_array_length(ctx, p, pr, JS_DupValue(ctx, val),\n                                               flags);\n                    } else {\n                        res = TRUE;\n                    }\n                    /* still need to reset the writable flag if needed.\n                       The JS_PROP_LENGTH is reset to have the correct\n                       read-only behavior in JS_SetProperty(). */\n                    if ((flags & (JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE)) ==\n                        JS_PROP_HAS_WRITABLE) {\n                        prs = get_shape_prop(p->shape);\n                        if (js_update_property_flags(ctx, p, &prs,\n                                                     prs->flags & ~(JS_PROP_WRITABLE | JS_PROP_LENGTH)))\n                            return -1;\n                    }\n                    return res;\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                    if (flags & JS_PROP_HAS_VALUE) {\n                        if (p->class_id == JS_CLASS_MODULE_NS) {\n                            /* JS_PROP_WRITABLE is always true for variable\n                               references, but they are write protected in module name\n                               spaces. */\n                            if (!js_same_value(ctx, val, *pr->u.var_ref->pvalue))\n                                goto not_configurable;\n                        }\n                        /* update the reference */\n                        set_value(ctx, pr->u.var_ref->pvalue,\n                                  JS_DupValue(ctx, val));\n                    }\n                    /* if writable is set to false, no longer a\n                       reference (for mapped arguments) */\n                    if ((flags & (JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE)) == JS_PROP_HAS_WRITABLE) {\n                        JSValue val1;\n                        if (js_shape_prepare_update(ctx, p, &prs))\n                            return -1;\n                        val1 = JS_DupValue(ctx, *pr->u.var_ref->pvalue);\n                        free_var_ref(ctx->rt, pr->u.var_ref);\n                        pr->u.value = val1;\n                        prs->flags &= ~(JS_PROP_TMASK | JS_PROP_WRITABLE);\n                    }\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                    /* XXX: should never happen, type was reset above */\n                    abort();\n                } else {\n                    if (flags & JS_PROP_HAS_VALUE) {\n                        JS_FreeValue(ctx, pr->u.value);\n                        pr->u.value = JS_DupValue(ctx, val);\n                    }\n                    if (flags & JS_PROP_HAS_WRITABLE) {\n                        if (js_update_property_flags(ctx, p, &prs,\n                                                     (prs->flags & ~JS_PROP_WRITABLE) |\n                                                     (flags & JS_PROP_WRITABLE)))\n                            return -1;\n                    }\n                }\n            }\n        }\n        mask = 0;\n        if (flags & JS_PROP_HAS_CONFIGURABLE)\n            mask |= JS_PROP_CONFIGURABLE;\n        if (flags & JS_PROP_HAS_ENUMERABLE)\n            mask |= JS_PROP_ENUMERABLE;\n        if (js_update_property_flags(ctx, p, &prs,\n                                     (prs->flags & ~mask) | (flags & mask)))\n            return -1;\n        return TRUE;\n    }\n\n    /* handle modification of fast array elements */\n    if (p->fast_array) {\n        uint32_t idx;\n        uint32_t prop_flags;\n        if (p->class_id == JS_CLASS_ARRAY) {\n            if (__JS_AtomIsTaggedInt(prop)) {\n                idx = __JS_AtomToUInt32(prop);\n                if (idx < p->u.array.count) {\n                    prop_flags = get_prop_flags(flags, JS_PROP_C_W_E);\n                    if (prop_flags != JS_PROP_C_W_E)\n                        goto convert_to_slow_array;\n                    if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n                    convert_to_slow_array:\n                        if (convert_fast_array_to_array(ctx, p))\n                            return -1;\n                        else\n                            goto redo_prop_update;\n                    }\n                    if (flags & JS_PROP_HAS_VALUE) {\n                        set_value(ctx, &p->u.array.u.values[idx], JS_DupValue(ctx, val));\n                    }\n                    return TRUE;\n                }\n            }\n        } else if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                   p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n            JSValue num;\n            int ret;\n\n            if (!__JS_AtomIsTaggedInt(prop)) {\n                /* slow path with to handle all numeric indexes */\n                num = JS_AtomIsNumericIndex1(ctx, prop);\n                if (JS_IsUndefined(num))\n                    goto typed_array_done;\n                if (JS_IsException(num))\n                    return -1;\n                ret = JS_NumberIsInteger(ctx, num);\n                if (ret < 0) {\n                    JS_FreeValue(ctx, num);\n                    return -1;\n                }\n                if (!ret) {\n                    JS_FreeValue(ctx, num);\n                    return JS_ThrowTypeErrorOrFalse(ctx, flags, \"non integer index in typed array\");\n                }\n                ret = JS_NumberIsNegativeOrMinusZero(ctx, num);\n                JS_FreeValue(ctx, num);\n                if (ret) {\n                    return JS_ThrowTypeErrorOrFalse(ctx, flags, \"negative index in typed array\");\n                }\n                if (!__JS_AtomIsTaggedInt(prop))\n                    goto typed_array_oob;\n            }\n            idx = __JS_AtomToUInt32(prop);\n            /* if the typed array is detached, p->u.array.count = 0 */\n            if (idx >= typed_array_get_length(ctx, p)) {\n            typed_array_oob:\n                return JS_ThrowTypeErrorOrFalse(ctx, flags, \"out-of-bound index in typed array\");\n            }\n            prop_flags = get_prop_flags(flags, JS_PROP_ENUMERABLE | JS_PROP_WRITABLE);\n            if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET) ||\n                prop_flags != (JS_PROP_ENUMERABLE | JS_PROP_WRITABLE)) {\n                return JS_ThrowTypeErrorOrFalse(ctx, flags, \"invalid descriptor flags\");\n            }\n            if (flags & JS_PROP_HAS_VALUE) {\n                return JS_SetPropertyValue(ctx, this_obj, JS_NewInt32(ctx, idx), JS_DupValue(ctx, val), flags);\n            }\n            return TRUE;\n        typed_array_done: ;\n        }\n    }\n\n    return JS_CreateProperty(ctx, p, prop, val, getter, setter, flags);\n}\n\nstatic int JS_DefineAutoInitProperty(JSContext *ctx, JSValueConst this_obj,\n                                     JSAtom prop, JSAutoInitIDEnum id,\n                                     void *opaque, int flags)\n{\n    JSObject *p;\n    JSProperty *pr;\n\n    if (JS_VALUE_GET_TAG(this_obj) != JS_TAG_OBJECT)\n        return FALSE;\n\n    p = JS_VALUE_GET_OBJ(this_obj);\n\n    if (find_own_property(&pr, p, prop)) {\n        /* property already exists */\n        abort();\n        return FALSE;\n    }\n\n    /* Specialized CreateProperty */\n    pr = add_property(ctx, p, prop, (flags & JS_PROP_C_W_E) | JS_PROP_AUTOINIT);\n    if (unlikely(!pr))\n        return -1;\n    pr->u.init.realm_and_id = (uintptr_t)JS_DupContext(ctx);\n    assert((pr->u.init.realm_and_id & 3) == 0);\n    assert(id <= 3);\n    pr->u.init.realm_and_id |= id;\n    pr->u.init.opaque = opaque;\n    return TRUE;\n}\n\n/* shortcut to add or redefine a new property value */\nint JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,\n                           JSAtom prop, JSValue val, int flags)\n{\n    int ret;\n    ret = JS_DefineProperty(ctx, this_obj, prop, val, JS_UNDEFINED, JS_UNDEFINED,\n                            flags | JS_PROP_HAS_VALUE | JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_WRITABLE | JS_PROP_HAS_ENUMERABLE);\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nint JS_DefinePropertyValueValue(JSContext *ctx, JSValueConst this_obj,\n                                JSValue prop, JSValue val, int flags)\n{\n    JSAtom atom;\n    int ret;\n    atom = JS_ValueToAtom(ctx, prop);\n    JS_FreeValue(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL)) {\n        JS_FreeValue(ctx, val);\n        return -1;\n    }\n    ret = JS_DefinePropertyValue(ctx, this_obj, atom, val, flags);\n    JS_FreeAtom(ctx, atom);\n    return ret;\n}\n\nint JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,\n                                 uint32_t idx, JSValue val, int flags)\n{\n    return JS_DefinePropertyValueValue(ctx, this_obj, JS_NewUint32(ctx, idx),\n                                       val, flags);\n}\n\nint JS_DefinePropertyValueInt64(JSContext *ctx, JSValueConst this_obj,\n                                int64_t idx, JSValue val, int flags)\n{\n    return JS_DefinePropertyValueValue(ctx, this_obj, JS_NewInt64(ctx, idx),\n                                       val, flags);\n}\n\nint JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,\n                              const char *prop, JSValue val, int flags)\n{\n    JSAtom atom;\n    int ret;\n    atom = JS_NewAtom(ctx, prop);\n    ret = JS_DefinePropertyValue(ctx, this_obj, atom, val, flags);\n    JS_FreeAtom(ctx, atom);\n    return ret;\n}\n\n/* shortcut to add getter & setter */\nint JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,\n                            JSAtom prop, JSValue getter, JSValue setter,\n                            int flags)\n{\n    int ret;\n    ret = JS_DefineProperty(ctx, this_obj, prop, JS_UNDEFINED, getter, setter,\n                            flags | JS_PROP_HAS_GET | JS_PROP_HAS_SET |\n                            JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_ENUMERABLE);\n    JS_FreeValue(ctx, getter);\n    JS_FreeValue(ctx, setter);\n    return ret;\n}\n\nstatic int JS_CreateDataPropertyUint32(JSContext *ctx, JSValueConst this_obj,\n                                       int64_t idx, JSValue val, int flags)\n{\n    return JS_DefinePropertyValueValue(ctx, this_obj, JS_NewInt64(ctx, idx),\n                                       val, flags | JS_PROP_CONFIGURABLE |\n                                       JS_PROP_ENUMERABLE | JS_PROP_WRITABLE);\n}\n\n\n/* return TRUE if 'obj' has a non empty 'name' string */\nstatic BOOL js_object_has_name(JSContext *ctx, JSValueConst obj)\n{\n    JSProperty *pr;\n    JSShapeProperty *prs;\n    JSValueConst val;\n    JSString *p;\n    \n    prs = find_own_property(&pr, JS_VALUE_GET_OBJ(obj), JS_ATOM_name);\n    if (!prs)\n        return FALSE;\n    if ((prs->flags & JS_PROP_TMASK) != JS_PROP_NORMAL)\n        return TRUE;\n    val = pr->u.value;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_STRING)\n        return TRUE;\n    p = JS_VALUE_GET_STRING(val);\n    return (p->len != 0);\n}\n\nstatic int JS_DefineObjectName(JSContext *ctx, JSValueConst obj,\n                               JSAtom name, int flags)\n{\n    if (name != JS_ATOM_NULL\n    &&  JS_IsObject(obj)\n    &&  !js_object_has_name(ctx, obj)\n    &&  JS_DefinePropertyValue(ctx, obj, JS_ATOM_name, JS_AtomToString(ctx, name), flags) < 0) {\n        return -1;\n    }\n    return 0;\n}\n\nstatic int JS_DefineObjectNameComputed(JSContext *ctx, JSValueConst obj,\n                                       JSValueConst str, int flags)\n{\n    if (JS_IsObject(obj) &&\n        !js_object_has_name(ctx, obj)) {\n        JSAtom prop;\n        JSValue name_str;\n        prop = JS_ValueToAtom(ctx, str);\n        if (prop == JS_ATOM_NULL)\n            return -1;\n        name_str = js_get_function_name(ctx, prop);\n        JS_FreeAtom(ctx, prop);\n        if (JS_IsException(name_str))\n            return -1;\n        if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_name, name_str, flags) < 0)\n            return -1;\n    }\n    return 0;\n}\n\n#define DEFINE_GLOBAL_LEX_VAR (1 << 7)\n#define DEFINE_GLOBAL_FUNC_VAR (1 << 6)\n\nstatic JSValue JS_ThrowSyntaxErrorVarRedeclaration(JSContext *ctx, JSAtom prop)\n{\n    return JS_ThrowSyntaxErrorAtom(ctx, \"redeclaration of '%s'\", prop);\n}\n\n/* flags is 0, DEFINE_GLOBAL_LEX_VAR or DEFINE_GLOBAL_FUNC_VAR */\n/* XXX: could support exotic global object. */\nstatic int JS_CheckDefineGlobalVar(JSContext *ctx, JSAtom prop, int flags)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n\n    p = JS_VALUE_GET_OBJ(ctx->global_obj);\n    prs = find_own_property1(p, prop);\n    /* XXX: should handle JS_PROP_AUTOINIT */\n    if (flags & DEFINE_GLOBAL_LEX_VAR) {\n        if (prs && !(prs->flags & JS_PROP_CONFIGURABLE))\n            goto fail_redeclaration;\n    } else {\n        if (!prs && !p->extensible)\n            goto define_error;\n        if (flags & DEFINE_GLOBAL_FUNC_VAR) {\n            if (prs) {\n                if (!(prs->flags & JS_PROP_CONFIGURABLE) &&\n                    ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET ||\n                     ((prs->flags & (JS_PROP_WRITABLE | JS_PROP_ENUMERABLE)) !=\n                      (JS_PROP_WRITABLE | JS_PROP_ENUMERABLE)))) {\n                define_error:\n                    JS_ThrowTypeErrorAtom(ctx, \"cannot define variable '%s'\",\n                                          prop);\n                    return -1;\n                }\n            }\n        }\n    }\n    /* check if there already is a lexical declaration */\n    p = JS_VALUE_GET_OBJ(ctx->global_var_obj);\n    prs = find_own_property1(p, prop);\n    if (prs) {\n    fail_redeclaration:\n        JS_ThrowSyntaxErrorVarRedeclaration(ctx, prop);\n        return -1;\n    }\n    return 0;\n}\n\n/* def_flags is (0, DEFINE_GLOBAL_LEX_VAR) |\n   JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE */\n/* XXX: could support exotic global object. */\nstatic int JS_DefineGlobalVar(JSContext *ctx, JSAtom prop, int def_flags)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    JSValue val;\n    int flags;\n\n    if (def_flags & DEFINE_GLOBAL_LEX_VAR) {\n        p = JS_VALUE_GET_OBJ(ctx->global_var_obj);\n        flags = JS_PROP_ENUMERABLE | (def_flags & JS_PROP_WRITABLE) |\n            JS_PROP_CONFIGURABLE;\n        val = JS_UNINITIALIZED;\n    } else {\n        p = JS_VALUE_GET_OBJ(ctx->global_obj);\n        flags = JS_PROP_ENUMERABLE | JS_PROP_WRITABLE |\n            (def_flags & JS_PROP_CONFIGURABLE);\n        val = JS_UNDEFINED;\n    }\n    prs = find_own_property1(p, prop);\n    if (prs)\n        return 0;\n    if (!p->extensible)\n        return 0;\n    pr = add_property(ctx, p, prop, flags);\n    if (unlikely(!pr))\n        return -1;\n    pr->u.value = val;\n    return 0;\n}\n\n/* 'def_flags' is 0 or JS_PROP_CONFIGURABLE. */\n/* XXX: could support exotic global object. */\nstatic int JS_DefineGlobalFunction(JSContext *ctx, JSAtom prop,\n                                   JSValueConst func, int def_flags)\n{\n\n    JSObject *p;\n    JSShapeProperty *prs;\n    int flags;\n\n    p = JS_VALUE_GET_OBJ(ctx->global_obj);\n    prs = find_own_property1(p, prop);\n    flags = JS_PROP_HAS_VALUE | JS_PROP_THROW;\n    if (!prs || (prs->flags & JS_PROP_CONFIGURABLE)) {\n        flags |= JS_PROP_ENUMERABLE | JS_PROP_WRITABLE | def_flags |\n            JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_WRITABLE | JS_PROP_HAS_ENUMERABLE;\n    }\n    if (JS_DefineProperty(ctx, ctx->global_obj, prop, func,\n                          JS_UNDEFINED, JS_UNDEFINED, flags) < 0)\n        return -1;\n    return 0;\n}\n\nstatic JSValue JS_GetGlobalVar(JSContext *ctx, JSAtom prop,\n                               BOOL throw_ref_error)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n\n    /* no exotic behavior is possible in global_var_obj */\n    p = JS_VALUE_GET_OBJ(ctx->global_var_obj);\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        /* XXX: should handle JS_PROP_TMASK properties */\n        if (unlikely(JS_IsUninitialized(pr->u.value)))\n            return JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n        return JS_DupValue(ctx, pr->u.value);\n    }\n    return JS_GetPropertyInternal(ctx, ctx->global_obj, prop,\n                                 ctx->global_obj, throw_ref_error);\n}\n\n/* construct a reference to a global variable */\nstatic int JS_GetGlobalVarRef(JSContext *ctx, JSAtom prop, JSValue *sp)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n\n    /* no exotic behavior is possible in global_var_obj */\n    p = JS_VALUE_GET_OBJ(ctx->global_var_obj);\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        /* XXX: should handle JS_PROP_AUTOINIT properties? */\n        /* XXX: conformance: do these tests in\n           OP_put_var_ref/OP_get_var_ref ? */\n        if (unlikely(JS_IsUninitialized(pr->u.value))) {\n            JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n            return -1;\n        }\n        if (unlikely(!(prs->flags & JS_PROP_WRITABLE))) {\n            return JS_ThrowTypeErrorReadOnly(ctx, JS_PROP_THROW, prop);\n        }\n        sp[0] = JS_DupValue(ctx, ctx->global_var_obj);\n    } else {\n        int ret;\n        ret = JS_HasProperty(ctx, ctx->global_obj, prop);\n        if (ret < 0)\n            return -1;\n        if (ret) {\n            sp[0] = JS_DupValue(ctx, ctx->global_obj);\n        } else {\n            sp[0] = JS_UNDEFINED;\n        }\n    }\n    sp[1] = JS_AtomToValue(ctx, prop);\n    return 0;\n}\n\n/* use for strict variable access: test if the variable exists */\nstatic int JS_CheckGlobalVar(JSContext *ctx, JSAtom prop)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    int ret;\n\n    /* no exotic behavior is possible in global_var_obj */\n    p = JS_VALUE_GET_OBJ(ctx->global_var_obj);\n    prs = find_own_property1(p, prop);\n    if (prs) {\n        ret = TRUE;\n    } else {\n        ret = JS_HasProperty(ctx, ctx->global_obj, prop);\n        if (ret < 0)\n            return -1;\n    }\n    return ret;\n}\n\n/* flag = 0: normal variable write\n   flag = 1: initialize lexical variable\n   flag = 2: normal variable write, strict check was done before\n*/\nstatic int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val,\n                           int flag)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    int flags;\n\n    /* no exotic behavior is possible in global_var_obj */\n    p = JS_VALUE_GET_OBJ(ctx->global_var_obj);\n    prs = find_own_property(&pr, p, prop);\n    if (prs) {\n        /* XXX: should handle JS_PROP_AUTOINIT properties? */\n        if (flag != 1) {\n            if (unlikely(JS_IsUninitialized(pr->u.value))) {\n                JS_FreeValue(ctx, val);\n                JS_ThrowReferenceErrorUninitialized(ctx, prs->atom);\n                return -1;\n            }\n            if (unlikely(!(prs->flags & JS_PROP_WRITABLE))) {\n                JS_FreeValue(ctx, val);\n                return JS_ThrowTypeErrorReadOnly(ctx, JS_PROP_THROW, prop);\n            }\n        }\n        set_value(ctx, &pr->u.value, val);\n        return 0;\n    }\n\n    flags = JS_PROP_THROW_STRICT;\n    if (flag != 2 && is_strict_mode(ctx))\n        flags |= JS_PROP_NO_ADD;\n    return JS_SetPropertyInternal(ctx, ctx->global_obj, prop, val, flags);\n}\n\n/* return -1, FALSE or TRUE. return FALSE if not configurable or\n   invalid object. return -1 in case of exception.\n   flags can be 0, JS_PROP_THROW or JS_PROP_THROW_STRICT */\nint JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags)\n{\n    JSValue obj1;\n    JSObject *p;\n    int res;\n    \n    obj1 = JS_ToObject(ctx, obj);\n    if (JS_IsException(obj1))\n        return -1;\n    p = JS_VALUE_GET_OBJ(obj1);\n    res = delete_property(ctx, p, prop);\n    JS_FreeValue(ctx, obj1);\n    if (res != FALSE)\n        return res;\n    if ((flags & JS_PROP_THROW) ||\n        ((flags & JS_PROP_THROW_STRICT) && is_strict_mode(ctx))) {\n        JS_ThrowTypeError(ctx, \"could not delete property\");\n        return -1;\n    }\n    return FALSE;\n}\n\nint JS_DeletePropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx, int flags)\n{\n    JSAtom prop;\n    int res;\n\n    if ((uint64_t)idx <= JS_ATOM_MAX_INT) {\n        /* fast path for fast arrays */\n        return JS_DeleteProperty(ctx, obj, __JS_AtomFromUInt32(idx), flags);\n    }\n    prop = JS_NewAtomInt64(ctx, idx);\n    if (prop == JS_ATOM_NULL)\n        return -1;\n    res = JS_DeleteProperty(ctx, obj, prop, flags);\n    JS_FreeAtom(ctx, prop);\n    return res;\n}\n\nBOOL JS_IsFunction(JSContext *ctx, JSValueConst val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(val);\n    switch(p->class_id) {\n    case JS_CLASS_BYTECODE_FUNCTION:\n        return TRUE;\n    case JS_CLASS_PROXY:\n        return p->u.proxy_data->is_func;\n    default:\n        return (ctx->rt->class_array[p->class_id].call != NULL);\n    }\n}\n\nBOOL JS_IsCFunction(JSContext *ctx, JSValueConst val, JSCFunction *func, int magic)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(val);\n    if (p->class_id == JS_CLASS_C_FUNCTION)\n        return (p->u.cfunc.c_function.generic == func && p->u.cfunc.magic == magic);\n    else\n        return FALSE;\n}\n\nBOOL JS_IsConstructor(JSContext *ctx, JSValueConst val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(val);\n    return p->is_constructor;\n}\n\nBOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, BOOL val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(func_obj);\n    p->is_constructor = val;\n    return TRUE;\n}\n\nBOOL JS_IsError(JSContext *ctx, JSValueConst val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(val);\n    return (p->class_id == JS_CLASS_ERROR);\n}\n\n/* used to avoid catching interrupt exceptions */\nBOOL JS_IsUncatchableError(JSContext *ctx, JSValueConst val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return FALSE;\n    p = JS_VALUE_GET_OBJ(val);\n    return p->class_id == JS_CLASS_ERROR && p->is_uncatchable_error;\n}\n\nvoid JS_SetUncatchableError(JSContext *ctx, JSValueConst val, BOOL flag)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return;\n    p = JS_VALUE_GET_OBJ(val);\n    if (p->class_id == JS_CLASS_ERROR)\n        p->is_uncatchable_error = flag;\n}\n\nvoid JS_ResetUncatchableError(JSContext *ctx)\n{\n    JS_SetUncatchableError(ctx, ctx->rt->current_exception, FALSE);\n}\n\nvoid JS_SetOpaque(JSValue obj, void *opaque)\n{\n   JSObject *p;\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        p = JS_VALUE_GET_OBJ(obj);\n        p->u.opaque = opaque;\n    }\n}\n\n/* return NULL if not an object of class class_id */\nvoid *JS_GetOpaque(JSValueConst obj, JSClassID class_id)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return NULL;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (p->class_id != class_id)\n        return NULL;\n    return p->u.opaque;\n}\n\nvoid *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id)\n{\n    void *p = JS_GetOpaque(obj, class_id);\n    if (unlikely(!p)) {\n        JS_ThrowTypeErrorInvalidClass(ctx, class_id);\n    }\n    return p;\n}\n\n#define HINT_STRING  0\n#define HINT_NUMBER  1\n#define HINT_NONE    2\n/* don't try Symbol.toPrimitive */\n#define HINT_FORCE_ORDINARY (1 << 4)\n\nstatic JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint)\n{\n    int i;\n    BOOL force_ordinary;\n\n    JSAtom method_name;\n    JSValue method, ret;\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)\n        return val;\n    force_ordinary = hint & HINT_FORCE_ORDINARY;\n    hint &= ~HINT_FORCE_ORDINARY;\n    if (!force_ordinary) {\n        method = JS_GetProperty(ctx, val, JS_ATOM_Symbol_toPrimitive);\n        if (JS_IsException(method))\n            goto exception;\n        /* ECMA says *If exoticToPrim is not undefined* but tests in\n           test262 use null as a non callable converter */\n        if (!JS_IsUndefined(method) && !JS_IsNull(method)) {\n            JSAtom atom;\n            JSValue arg;\n            switch(hint) {\n            case HINT_STRING:\n                atom = JS_ATOM_string;\n                break;\n            case HINT_NUMBER:\n                atom = JS_ATOM_number;\n                break;\n            default:\n            case HINT_NONE:\n                atom = JS_ATOM_default;\n                break;\n            }\n            arg = JS_AtomToString(ctx, atom);\n            ret = JS_CallFree(ctx, method, val, 1, (JSValueConst *)&arg);\n            JS_FreeValue(ctx, arg);\n            if (JS_IsException(ret))\n                goto exception;\n            JS_FreeValue(ctx, val);\n            if (JS_VALUE_GET_TAG(ret) != JS_TAG_OBJECT)\n                return ret;\n            JS_FreeValue(ctx, ret);\n            return JS_ThrowTypeError(ctx, \"toPrimitive\");\n        }\n    }\n    if (hint != HINT_STRING)\n        hint = HINT_NUMBER;\n    for(i = 0; i < 2; i++) {\n        if ((i ^ hint) == 0) {\n            method_name = JS_ATOM_toString;\n        } else {\n            method_name = JS_ATOM_valueOf;\n        }\n        method = JS_GetProperty(ctx, val, method_name);\n        if (JS_IsException(method))\n            goto exception;\n        if (JS_IsFunction(ctx, method)) {\n            ret = JS_CallFree(ctx, method, val, 0, NULL);\n            if (JS_IsException(ret))\n                goto exception;\n            if (JS_VALUE_GET_TAG(ret) != JS_TAG_OBJECT) {\n                JS_FreeValue(ctx, val);\n                return ret;\n            }\n            JS_FreeValue(ctx, ret);\n        } else {\n            JS_FreeValue(ctx, method);\n        }\n    }\n    JS_ThrowTypeError(ctx, \"toPrimitive\");\nexception:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ToPrimitive(JSContext *ctx, JSValueConst val, int hint)\n{\n    return JS_ToPrimitiveFree(ctx, JS_DupValue(ctx, val), hint);\n}\n\nstatic int JS_ToBoolFree(JSContext *ctx, JSValue val)\n{\n    uint32_t tag = JS_VALUE_GET_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n        return JS_VALUE_GET_INT(val) != 0;\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        return JS_VALUE_GET_INT(val);\n    case JS_TAG_EXCEPTION:\n        return -1;\n    case JS_TAG_STRING:\n        {\n            BOOL ret = JS_VALUE_GET_STRING(val)->len != 0;\n            JS_FreeValue(ctx, val);\n            return ret;\n        }\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            BOOL ret;\n            ret = p->num.expn != BF_EXP_ZERO && p->num.expn != BF_EXP_NAN;\n            JS_FreeValue(ctx, val);\n            return ret;\n        }\n    case JS_TAG_BIG_DECIMAL:\n        {\n            JSBigDecimal *p = JS_VALUE_GET_PTR(val);\n            BOOL ret;\n            ret = p->num.expn != BF_EXP_ZERO && p->num.expn != BF_EXP_NAN;\n            JS_FreeValue(ctx, val);\n            return ret;\n        }\n#endif\n    default:\n        if (JS_TAG_IS_FLOAT64(tag)) {\n            double d = JS_VALUE_GET_FLOAT64(val);\n            return !isnan(d) && d != 0;\n        } else {\n            JS_FreeValue(ctx, val);\n            return TRUE;\n        }\n    }\n}\n\nint JS_ToBool(JSContext *ctx, JSValueConst val)\n{\n    return JS_ToBoolFree(ctx, JS_DupValue(ctx, val));\n}\n\nstatic int skip_spaces(const char *pc)\n{\n    const uint8_t *p, *p_next, *p_start;\n    uint32_t c;\n\n    p = p_start = (const uint8_t *)pc;\n    for (;;) {\n        c = *p;\n        if (c < 128) {\n            if (!((c >= 0x09 && c <= 0x0d) || (c == 0x20)))\n                break;\n            p++;\n        } else {\n            c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p_next);\n            if (!lre_is_space(c))\n                break;\n            p = p_next;\n        }\n    }\n    return p - p_start;\n}\n\nstatic inline int to_digit(int c)\n{\n    if (c >= '0' && c <= '9')\n        return c - '0';\n    else if (c >= 'A' && c <= 'Z')\n        return c - 'A' + 10;\n    else if (c >= 'a' && c <= 'z')\n        return c - 'a' + 10;\n    else\n        return 36;\n}\n\n/* XXX: remove */\nstatic double js_strtod(const char *p, int radix, BOOL is_float)\n{\n    double d;\n    int c;\n    \n    if (!is_float || radix != 10) {\n        uint64_t n_max, n;\n        int int_exp, is_neg;\n        \n        is_neg = 0;\n        if (*p == '-') {\n            is_neg = 1;\n            p++;\n        }\n\n        /* skip leading zeros */\n        while (*p == '0')\n            p++;\n        n = 0;\n        if (radix == 10)\n            n_max = ((uint64_t)-1 - 9) / 10; /* most common case */\n        else\n            n_max = ((uint64_t)-1 - (radix - 1)) / radix;\n        /* XXX: could be more precise */\n        int_exp = 0;\n        while (*p != '\\0') {\n            c = to_digit((uint8_t)*p);\n            if (c >= radix)\n                break;\n            if (n <= n_max) {\n                n = n * radix + c;\n            } else {\n                int_exp++;\n            }\n            p++;\n        }\n        d = n;\n        if (int_exp != 0) {\n            d *= pow(radix, int_exp);\n        }\n        if (is_neg)\n            d = -d;\n    } else {\n        d = strtod(p, NULL);\n    }\n    return d;\n}\n\n#define ATOD_INT_ONLY        (1 << 0)\n/* accept Oo and Ob prefixes in addition to 0x prefix if radix = 0 */\n#define ATOD_ACCEPT_BIN_OCT  (1 << 2)\n/* accept O prefix as octal if radix == 0 and properly formed (Annex B) */\n#define ATOD_ACCEPT_LEGACY_OCTAL  (1 << 4)\n/* accept _ between digits as a digit separator */\n#define ATOD_ACCEPT_UNDERSCORES  (1 << 5)\n/* allow a suffix to override the type */\n#define ATOD_ACCEPT_SUFFIX    (1 << 6) \n/* default type */\n#define ATOD_TYPE_MASK        (3 << 7)\n#define ATOD_TYPE_FLOAT64     (0 << 7)\n#define ATOD_TYPE_BIG_INT     (1 << 7)\n#define ATOD_TYPE_BIG_FLOAT   (2 << 7)\n#define ATOD_TYPE_BIG_DECIMAL (3 << 7)\n/* assume bigint mode: floats are parsed as integers if no decimal\n   point nor exponent */\n#define ATOD_MODE_BIGINT      (1 << 9) \n/* accept -0x1 */\n#define ATOD_ACCEPT_PREFIX_AFTER_SIGN (1 << 10)\n\n#ifdef CONFIG_BIGNUM\nstatic JSValue js_string_to_bigint(JSContext *ctx, const char *buf,\n                                   int radix, int flags, slimb_t *pexponent)\n{\n    bf_t a_s, *a = &a_s;\n    int ret;\n    JSValue val;\n    val = JS_NewBigInt(ctx);\n    if (JS_IsException(val))\n        return val;\n    a = JS_GetBigInt(val);\n    ret = bf_atof(a, buf, NULL, radix, BF_PREC_INF, BF_RNDZ);\n    if (ret & BF_ST_MEM_ERROR) {\n        JS_FreeValue(ctx, val);\n        return JS_ThrowOutOfMemory(ctx);\n    }\n    val = JS_CompactBigInt1(ctx, val, (flags & ATOD_MODE_BIGINT) != 0);\n    return val;\n}\n\nstatic JSValue js_string_to_bigfloat(JSContext *ctx, const char *buf,\n                                     int radix, int flags, slimb_t *pexponent)\n{\n    bf_t *a;\n    int ret;\n    JSValue val;\n    \n    val = JS_NewBigFloat(ctx);\n    if (JS_IsException(val))\n        return val;\n    a = JS_GetBigFloat(val);\n    if (flags & ATOD_ACCEPT_SUFFIX) {\n        /* return the exponent to get infinite precision */\n        ret = bf_atof2(a, pexponent, buf, NULL, radix, BF_PREC_INF,\n                       BF_RNDZ | BF_ATOF_EXPONENT);\n    } else {\n        ret = bf_atof(a, buf, NULL, radix, ctx->fp_env.prec,\n                      ctx->fp_env.flags);\n    }\n    if (ret & BF_ST_MEM_ERROR) {\n        JS_FreeValue(ctx, val);\n        return JS_ThrowOutOfMemory(ctx);\n    }\n    return val;\n}\n\nstatic JSValue js_string_to_bigdecimal(JSContext *ctx, const char *buf,\n                                       int radix, int flags, slimb_t *pexponent)\n{\n    bfdec_t *a;\n    int ret;\n    JSValue val;\n    \n    val = JS_NewBigDecimal(ctx);\n    if (JS_IsException(val))\n        return val;\n    a = JS_GetBigDecimal(val);\n    ret = bfdec_atof(a, buf, NULL, BF_PREC_INF,\n                     BF_RNDZ | BF_ATOF_NO_NAN_INF);\n    if (ret & BF_ST_MEM_ERROR) {\n        JS_FreeValue(ctx, val);\n        return JS_ThrowOutOfMemory(ctx);\n    }\n    return val;\n}\n\n#endif\n\n/* return an exception in case of memory error. Return JS_NAN if\n   invalid syntax */\n#ifdef CONFIG_BIGNUM\nstatic JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,\n                        int radix, int flags, slimb_t *pexponent)\n#else\nstatic JSValue js_atof(JSContext *ctx, const char *str, const char **pp,\n                       int radix, int flags)\n#endif\n{\n    const char *p, *p_start;\n    int sep, is_neg;\n    BOOL is_float, has_legacy_octal;\n    int atod_type = flags & ATOD_TYPE_MASK;\n    char buf1[64], *buf;\n    int i, j, len;\n    BOOL buf_allocated = FALSE;\n    JSValue val;\n    \n    /* optional separator between digits */\n    sep = (flags & ATOD_ACCEPT_UNDERSCORES) ? '_' : 256;\n    has_legacy_octal = FALSE;\n    \n    p = str;\n    p_start = p;\n    is_neg = 0;\n    if (p[0] == '+') {\n        p++;\n        p_start++;\n        if (!(flags & ATOD_ACCEPT_PREFIX_AFTER_SIGN))\n            goto no_radix_prefix;\n    } else if (p[0] == '-') {\n        p++;\n        p_start++;\n        is_neg = 1;\n        if (!(flags & ATOD_ACCEPT_PREFIX_AFTER_SIGN))\n            goto no_radix_prefix;\n    }\n    if (p[0] == '0') {\n        if ((p[1] == 'x' || p[1] == 'X') &&\n            (radix == 0 || radix == 16)) {\n            p += 2;\n            radix = 16;\n        } else if ((p[1] == 'o' || p[1] == 'O') &&\n                   radix == 0 && (flags & ATOD_ACCEPT_BIN_OCT)) {\n            p += 2;\n            radix = 8;\n        } else if ((p[1] == 'b' || p[1] == 'B') &&\n                   radix == 0 && (flags & ATOD_ACCEPT_BIN_OCT)) {\n            p += 2;\n            radix = 2;\n        } else if ((p[1] >= '0' && p[1] <= '9') &&\n                   radix == 0 && (flags & ATOD_ACCEPT_LEGACY_OCTAL)) {\n            int i;\n            has_legacy_octal = TRUE;\n            sep = 256;\n            for (i = 1; (p[i] >= '0' && p[i] <= '7'); i++)\n                continue;\n            if (p[i] == '8' || p[i] == '9')\n                goto no_prefix;\n            p += 1;\n            radix = 8;\n        } else {\n            goto no_prefix;\n        }\n        /* there must be a digit after the prefix */\n        if (to_digit((uint8_t)*p) >= radix)\n            goto fail;\n    no_prefix: ;\n    } else {\n no_radix_prefix:\n        if (!(flags & ATOD_INT_ONLY) &&\n            (atod_type == ATOD_TYPE_FLOAT64 ||\n             atod_type == ATOD_TYPE_BIG_FLOAT) &&\n            strstart(p, \"Infinity\", &p)) {\n#ifdef CONFIG_BIGNUM\n            if (atod_type == ATOD_TYPE_BIG_FLOAT) {\n                bf_t *a;\n                val = JS_NewBigFloat(ctx);\n                if (JS_IsException(val))\n                    goto done;\n                a = JS_GetBigFloat(val);\n                bf_set_inf(a, is_neg);\n            } else\n#endif\n            {\n                double d = 1.0 / 0.0;\n                if (is_neg)\n                    d = -d;\n                val = JS_NewFloat64(ctx, d);\n            }\n            goto done;\n        }\n    }\n    if (radix == 0)\n        radix = 10;\n    is_float = FALSE;\n    p_start = p;\n    while (to_digit((uint8_t)*p) < radix\n           ||  (*p == sep && (radix != 10 ||\n                              p != p_start + 1 || p[-1] != '0') &&\n                to_digit((uint8_t)p[1]) < radix)) {\n        p++;\n    }\n    if (!(flags & ATOD_INT_ONLY)) {\n        if (*p == '.' && (p > p_start || to_digit((uint8_t)p[1]) < radix)) {\n            is_float = TRUE;\n            p++;\n            if (*p == sep)\n                goto fail;\n            while (to_digit((uint8_t)*p) < radix ||\n                   (*p == sep && to_digit((uint8_t)p[1]) < radix))\n                p++;\n        }\n        if (p > p_start &&\n            (((*p == 'e' || *p == 'E') && radix == 10) ||\n             ((*p == 'p' || *p == 'P') && (radix == 2 || radix == 8 || radix == 16)))) {\n            const char *p1 = p + 1;\n            is_float = TRUE;\n            if (*p1 == '+') {\n                p1++;\n            } else if (*p1 == '-') {\n                p1++;\n            }\n            if (is_digit((uint8_t)*p1)) {\n                p = p1 + 1;\n                while (is_digit((uint8_t)*p) || (*p == sep && is_digit((uint8_t)p[1])))\n                    p++;\n            }\n        }\n    }\n    if (p == p_start)\n        goto fail;\n\n    buf = buf1;\n    buf_allocated = FALSE;\n    len = p - p_start;\n    if (unlikely((len + 2) > sizeof(buf1))) {\n        buf = js_malloc_rt(ctx->rt, len + 2); /* no exception raised */\n        if (!buf)\n            goto mem_error;\n        buf_allocated = TRUE;\n    }\n    /* remove the separators and the radix prefixes */\n    j = 0;\n    if (is_neg)\n        buf[j++] = '-';\n    for (i = 0; i < len; i++) {\n        if (p_start[i] != '_')\n            buf[j++] = p_start[i];\n    }\n    buf[j] = '\\0';\n\n#ifdef CONFIG_BIGNUM\n    if (flags & ATOD_ACCEPT_SUFFIX) {\n        if (*p == 'n') {\n            p++;\n            atod_type = ATOD_TYPE_BIG_INT;\n        } else if (*p == 'l') {\n            p++;\n            atod_type = ATOD_TYPE_BIG_FLOAT;\n        } else if (*p == 'm') {\n            p++;\n            atod_type = ATOD_TYPE_BIG_DECIMAL;\n        } else {\n            if (flags & ATOD_MODE_BIGINT) {\n                if (!is_float)\n                    atod_type = ATOD_TYPE_BIG_INT;\n                if (has_legacy_octal)\n                    goto fail;\n            } else {\n                if (is_float && radix != 10)\n                    goto fail;\n            }\n        }\n    } else {\n        if (atod_type == ATOD_TYPE_FLOAT64) {\n            if (flags & ATOD_MODE_BIGINT) {\n                if (!is_float)\n                    atod_type = ATOD_TYPE_BIG_INT;\n                if (has_legacy_octal)\n                    goto fail;\n            } else {\n                if (is_float && radix != 10)\n                    goto fail;\n            }\n        }\n    }\n\n    switch(atod_type) {\n    case ATOD_TYPE_FLOAT64:\n        {\n            double d;\n            d = js_strtod(buf, radix, is_float);\n            /* return int or float64 */\n            val = JS_NewFloat64(ctx, d);\n        }\n        break;\n    case ATOD_TYPE_BIG_INT:\n        if (has_legacy_octal || is_float)\n            goto fail;\n        val = ctx->rt->bigint_ops.from_string(ctx, buf, radix, flags, NULL);\n        break;\n    case ATOD_TYPE_BIG_FLOAT:\n        if (has_legacy_octal)\n            goto fail;\n        val = ctx->rt->bigfloat_ops.from_string(ctx, buf, radix, flags,\n                                                pexponent);\n        break;\n    case ATOD_TYPE_BIG_DECIMAL:\n        if (radix != 10)\n            goto fail;\n        val = ctx->rt->bigdecimal_ops.from_string(ctx, buf, radix, flags, NULL);\n        break;\n    default:\n        abort();\n    }\n#else\n    {\n        double d;\n        (void)has_legacy_octal;\n        if (is_float && radix != 10)\n            goto fail;\n        d = js_strtod(buf, radix, is_float);\n        val = JS_NewFloat64(ctx, d);\n    }\n#endif\n    \ndone:\n    if (buf_allocated)\n        js_free_rt(ctx->rt, buf);\n    if (pp)\n        *pp = p;\n    return val;\n fail:\n    val = JS_NAN;\n    goto done;\n mem_error:\n    val = JS_ThrowOutOfMemory(ctx);\n    goto done;\n}\n\n#ifdef CONFIG_BIGNUM\nstatic JSValue js_atof(JSContext *ctx, const char *str, const char **pp,\n                       int radix, int flags)\n{\n    return js_atof2(ctx, str, pp, radix, flags, NULL);\n}\n#endif\n\ntypedef enum JSToNumberHintEnum {\n    TON_FLAG_NUMBER,\n    TON_FLAG_NUMERIC,\n} JSToNumberHintEnum;\n\nstatic JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val,\n                                   JSToNumberHintEnum flag)\n{\n    uint32_t tag;\n    JSValue ret;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_DECIMAL:\n        if (flag != TON_FLAG_NUMERIC) {\n            JS_FreeValue(ctx, val);\n            return JS_ThrowTypeError(ctx, \"cannot convert bigdecimal to number\");\n        }\n        ret = val;\n        break;\n    case JS_TAG_BIG_INT:\n        if (flag != TON_FLAG_NUMERIC) {\n            JS_FreeValue(ctx, val);\n            return JS_ThrowTypeError(ctx, \"cannot convert bigint to number\");\n        }\n        ret = val;\n        break;\n    case JS_TAG_BIG_FLOAT:\n        if (flag != TON_FLAG_NUMERIC) {\n            JS_FreeValue(ctx, val);\n            return JS_ThrowTypeError(ctx, \"cannot convert bigfloat to number\");\n        }\n        ret = val;\n        break;\n#endif\n    case JS_TAG_FLOAT64:\n    case JS_TAG_INT:\n    case JS_TAG_EXCEPTION:\n        ret = val;\n        break;\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n        ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val));\n        break;\n    case JS_TAG_UNDEFINED:\n        ret = JS_NAN;\n        break;\n    case JS_TAG_OBJECT:\n        val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);\n        if (JS_IsException(val))\n            return JS_EXCEPTION;\n        goto redo;\n    case JS_TAG_STRING:\n        {\n            const char *str;\n            const char *p;\n            size_t len;\n            \n            str = JS_ToCStringLen(ctx, &len, val);\n            JS_FreeValue(ctx, val);\n            if (!str)\n                return JS_EXCEPTION;\n            p = str;\n            p += skip_spaces(p);\n            if ((p - str) == len) {\n                ret = JS_NewInt32(ctx, 0);\n            } else {\n                int flags = ATOD_ACCEPT_BIN_OCT;\n                ret = js_atof(ctx, p, &p, 0, flags);\n                if (!JS_IsException(ret)) {\n                    p += skip_spaces(p);\n                    if ((p - str) != len) {\n                        JS_FreeValue(ctx, ret);\n                        ret = JS_NAN;\n                    }\n                }\n            }\n            JS_FreeCString(ctx, str);\n        }\n        break;\n    case JS_TAG_SYMBOL:\n        JS_FreeValue(ctx, val);\n        return JS_ThrowTypeError(ctx, \"cannot convert symbol to number\");\n    default:\n        JS_FreeValue(ctx, val);\n        ret = JS_NAN;\n        break;\n    }\n    return ret;\n}\n\nstatic JSValue JS_ToNumberFree(JSContext *ctx, JSValue val)\n{\n    return JS_ToNumberHintFree(ctx, val, TON_FLAG_NUMBER);\n}\n\nstatic JSValue JS_ToNumericFree(JSContext *ctx, JSValue val)\n{\n    return JS_ToNumberHintFree(ctx, val, TON_FLAG_NUMERIC);\n}\n\nstatic JSValue JS_ToNumeric(JSContext *ctx, JSValueConst val)\n{\n    return JS_ToNumericFree(ctx, JS_DupValue(ctx, val));\n}\n\nstatic __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres,\n                                          JSValue val)\n{\n    double d;\n    uint32_t tag;\n\n    val = JS_ToNumberFree(ctx, val);\n    if (JS_IsException(val)) {\n        *pres = JS_FLOAT64_NAN;\n        return -1;\n    }\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n        d = JS_VALUE_GET_INT(val);\n        break;\n    case JS_TAG_FLOAT64:\n        d = JS_VALUE_GET_FLOAT64(val);\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            /* XXX: there can be a double rounding issue with some\n               primitives (such as JS_ToUint8ClampFree()), but it is\n               not critical to fix it. */\n            bf_get_float64(&p->num, &d, BF_RNDN);\n            JS_FreeValue(ctx, val);\n        }\n        break;\n#endif\n    default:\n        abort();\n    }\n    *pres = d;\n    return 0;\n}\n\nstatic inline int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue val)\n{\n    uint32_t tag;\n\n    tag = JS_VALUE_GET_TAG(val);\n    if (tag <= JS_TAG_NULL) {\n        *pres = JS_VALUE_GET_INT(val);\n        return 0;\n    } else if (JS_TAG_IS_FLOAT64(tag)) {\n        *pres = JS_VALUE_GET_FLOAT64(val);\n        return 0;\n    } else {\n        return __JS_ToFloat64Free(ctx, pres, val);\n    }\n}\n\nint JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val)\n{\n    return JS_ToFloat64Free(ctx, pres, JS_DupValue(ctx, val));\n}\n\nstatic JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)\n{\n    return JS_ToNumberFree(ctx, JS_DupValue(ctx, val));\n}\n\n/* same as JS_ToNumber() but return 0 in case of NaN/Undefined */\nstatic __maybe_unused JSValue JS_ToIntegerFree(JSContext *ctx, JSValue val)\n{\n    uint32_t tag;\n    JSValue ret;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val));\n        break;\n    case JS_TAG_FLOAT64:\n        {\n            double d = JS_VALUE_GET_FLOAT64(val);\n            if (isnan(d)) {\n                ret = JS_NewInt32(ctx, 0);\n            } else {\n                /* convert -0 to +0 */\n                d = trunc(d) + 0.0;\n                ret = JS_NewFloat64(ctx, d);\n            }\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n        {\n            bf_t a_s, *a, r_s, *r = &r_s;\n            BOOL is_nan;\n\n            a = JS_ToBigFloat(ctx, &a_s, val);\n            if (!bf_is_finite(a)) {\n                is_nan = bf_is_nan(a);\n                if (is_nan)\n                    ret = JS_NewInt32(ctx, 0);\n                else\n                    ret = JS_DupValue(ctx, val);\n            } else {\n                ret = JS_NewBigInt(ctx);\n                if (!JS_IsException(ret)) {\n                    r = JS_GetBigInt(ret);\n                    bf_set(r, a);\n                    bf_rint(r, BF_RNDZ);\n                    ret = JS_CompactBigInt(ctx, ret);\n                }\n            }\n            if (a == &a_s)\n                bf_delete(a);\n            JS_FreeValue(ctx, val);\n        }\n        break;\n#endif\n    default:\n        val = JS_ToNumberFree(ctx, val);\n        if (JS_IsException(val))\n            return val;\n        goto redo;\n    }\n    return ret;\n}\n\n/* Note: the integer value is satured to 32 bits */\nstatic int JS_ToInt32SatFree(JSContext *ctx, int *pres, JSValue val)\n{\n    uint32_t tag;\n    int ret;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        ret = JS_VALUE_GET_INT(val);\n        break;\n    case JS_TAG_EXCEPTION:\n        *pres = 0;\n        return -1;\n    case JS_TAG_FLOAT64:\n        {\n            double d = JS_VALUE_GET_FLOAT64(val);\n            if (isnan(d)) {\n                ret = 0;\n            } else {\n                if (d < INT32_MIN)\n                    ret = INT32_MIN;\n                else if (d > INT32_MAX)\n                    ret = INT32_MAX;\n                else\n                    ret = (int)d;\n            }\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            bf_get_int32(&ret, &p->num, 0);\n            JS_FreeValue(ctx, val);\n        }\n        break;\n#endif\n    default:\n        val = JS_ToNumberFree(ctx, val);\n        if (JS_IsException(val)) {\n            *pres = 0;\n            return -1;\n        }\n        goto redo;\n    }\n    *pres = ret;\n    return 0;\n}\n\nint JS_ToInt32Sat(JSContext *ctx, int *pres, JSValueConst val)\n{\n    return JS_ToInt32SatFree(ctx, pres, JS_DupValue(ctx, val));\n}\n\nint JS_ToInt32Clamp(JSContext *ctx, int *pres, JSValueConst val,\n                    int min, int max, int min_offset)\n{\n    int res = JS_ToInt32SatFree(ctx, pres, JS_DupValue(ctx, val));\n    if (res == 0) {\n        if (*pres < min) {\n            *pres += min_offset;\n            if (*pres < min)\n                *pres = min;\n        } else {\n            if (*pres > max)\n                *pres = max;\n        }\n    }\n    return res;\n}\n\nstatic int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val)\n{\n    uint32_t tag;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        *pres = JS_VALUE_GET_INT(val);\n        return 0;\n    case JS_TAG_EXCEPTION:\n        *pres = 0;\n        return -1;\n    case JS_TAG_FLOAT64:\n        {\n            double d = JS_VALUE_GET_FLOAT64(val);\n            if (isnan(d)) {\n                *pres = 0;\n            } else {\n                if (d < INT64_MIN)\n                    *pres = INT64_MIN;\n                else if (d > INT64_MAX)\n                    *pres = INT64_MAX;\n                else\n                    *pres = (int64_t)d;\n            }\n        }\n        return 0;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            bf_get_int64(pres, &p->num, 0);\n            JS_FreeValue(ctx, val);\n        }\n        return 0;\n#endif\n    default:\n        val = JS_ToNumberFree(ctx, val);\n        if (JS_IsException(val)) {\n            *pres = 0;\n            return -1;\n        }\n        goto redo;\n    }\n}\n\nint JS_ToInt64Sat(JSContext *ctx, int64_t *pres, JSValueConst val)\n{\n    return JS_ToInt64SatFree(ctx, pres, JS_DupValue(ctx, val));\n}\n\nint JS_ToInt64Clamp(JSContext *ctx, int64_t *pres, JSValueConst val,\n                    int64_t min, int64_t max, int64_t neg_offset)\n{\n    int res = JS_ToInt64SatFree(ctx, pres, JS_DupValue(ctx, val));\n    if (res == 0) {\n        if (*pres < 0)\n            *pres += neg_offset;\n        if (*pres < min)\n            *pres = min;\n        else if (*pres > max)\n            *pres = max;\n    }\n    return res;\n}\n\n/* Same as JS_ToInt32Free() but with a 64 bit result. Return (<0, 0)\n   in case of exception */\nstatic int JS_ToInt64Free(JSContext *ctx, int64_t *pres, JSValue val)\n{\n    uint32_t tag;\n    int64_t ret;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        ret = JS_VALUE_GET_INT(val);\n        break;\n    case JS_TAG_FLOAT64:\n        {\n            JSFloat64Union u;\n            double d;\n            int e;\n            d = JS_VALUE_GET_FLOAT64(val);\n            u.d = d;\n            /* we avoid doing fmod(x, 2^64) */\n            e = (u.u64 >> 52) & 0x7ff;\n            if (likely(e <= (1023 + 62))) {\n                /* fast case */\n                ret = (int64_t)d;\n            } else if (e <= (1023 + 62 + 53)) {\n                uint64_t v;\n                /* remainder modulo 2^64 */\n                v = (u.u64 & (((uint64_t)1 << 52) - 1)) | ((uint64_t)1 << 52);\n                ret = v << ((e - 1023) - 52);\n                /* take the sign into account */\n                if (u.u64 >> 63)\n                    ret = -ret;\n            } else {\n                ret = 0; /* also handles NaN and +inf */\n            }\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            bf_get_int64(&ret, &p->num, BF_GET_INT_MOD);\n            JS_FreeValue(ctx, val);\n        }\n        break;\n#endif\n    default:\n        val = JS_ToNumberFree(ctx, val);\n        if (JS_IsException(val)) {\n            *pres = 0;\n            return -1;\n        }\n        goto redo;\n    }\n    *pres = ret;\n    return 0;\n}\n\nint JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val)\n{\n    return JS_ToInt64Free(ctx, pres, JS_DupValue(ctx, val));\n}\n\nint JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val)\n{\n    if (JS_IsBigInt(ctx, val))\n        return JS_ToBigInt64(ctx, pres, val);\n    else\n        return JS_ToInt64(ctx, pres, val);\n}\n\n/* return (<0, 0) in case of exception */\nstatic int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val)\n{\n    uint32_t tag;\n    int32_t ret;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        ret = JS_VALUE_GET_INT(val);\n        break;\n    case JS_TAG_FLOAT64:\n        {\n            JSFloat64Union u;\n            double d;\n            int e;\n            d = JS_VALUE_GET_FLOAT64(val);\n            u.d = d;\n            /* we avoid doing fmod(x, 2^32) */\n            e = (u.u64 >> 52) & 0x7ff;\n            if (likely(e <= (1023 + 30))) {\n                /* fast case */\n                ret = (int32_t)d;\n            } else if (e <= (1023 + 30 + 53)) {\n                uint64_t v;\n                /* remainder modulo 2^32 */\n                v = (u.u64 & (((uint64_t)1 << 52) - 1)) | ((uint64_t)1 << 52);\n                v = v << ((e - 1023) - 52 + 32);\n                ret = v >> 32;\n                /* take the sign into account */\n                if (u.u64 >> 63)\n                    ret = -ret;\n            } else {\n                ret = 0; /* also handles NaN and +inf */\n            }\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            bf_get_int32(&ret, &p->num, BF_GET_INT_MOD);\n            JS_FreeValue(ctx, val);\n        }\n        break;\n#endif\n    default:\n        val = JS_ToNumberFree(ctx, val);\n        if (JS_IsException(val)) {\n            *pres = 0;\n            return -1;\n        }\n        goto redo;\n    }\n    *pres = ret;\n    return 0;\n}\n\nint JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val)\n{\n    return JS_ToInt32Free(ctx, pres, JS_DupValue(ctx, val));\n}\n\nstatic inline int JS_ToUint32Free(JSContext *ctx, uint32_t *pres, JSValue val)\n{\n    return JS_ToInt32Free(ctx, (int32_t *)pres, val);\n}\n\nstatic int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val)\n{\n    uint32_t tag;\n    int res;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        res = JS_VALUE_GET_INT(val);\n#ifdef CONFIG_BIGNUM\n    int_clamp:\n#endif\n        res = max_int(0, min_int(255, res));\n        break;\n    case JS_TAG_FLOAT64:\n        {\n            double d = JS_VALUE_GET_FLOAT64(val);\n            if (isnan(d)) {\n                res = 0;\n            } else {\n                if (d < 0)\n                    res = 0;\n                else if (d > 255)\n                    res = 255;\n                else\n                    res = lrint(d);\n            }\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            bf_t r_s, *r = &r_s;\n            bf_init(ctx->bf_ctx, r);\n            bf_set(r, &p->num);\n            bf_rint(r, BF_RNDN);\n            bf_get_int32(&res, r, 0);\n            bf_delete(r);\n            JS_FreeValue(ctx, val);\n        }\n        goto int_clamp;\n#endif\n    default:\n        val = JS_ToNumberFree(ctx, val);\n        if (JS_IsException(val)) {\n            *pres = 0;\n            return -1;\n        }\n        goto redo;\n    }\n    *pres = res;\n    return 0;\n}\n\nstatic __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,\n                                            JSValue val)\n{\n    uint32_t tag, len;\n\n redo:\n    tag = JS_VALUE_GET_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n        {\n            int v;\n            v = JS_VALUE_GET_INT(val);\n            if (v < 0)\n                goto fail;\n            len = v;\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            bf_t a;\n            BOOL res;\n            bf_get_int32((int32_t *)&len, &p->num, BF_GET_INT_MOD);\n            bf_init(ctx->bf_ctx, &a);\n            bf_set_ui(&a, len);\n            res = bf_cmp_eq(&a, &p->num);\n            bf_delete(&a);\n            JS_FreeValue(ctx, val);\n            if (!res)\n                goto fail;\n        }\n        break;\n#endif\n    default:\n        if (JS_TAG_IS_FLOAT64(tag)) {\n            double d;\n            d = JS_VALUE_GET_FLOAT64(val);\n            len = (uint32_t)d;\n            if (len != d) {\n            fail:\n                JS_ThrowRangeError(ctx, \"invalid array length\");\n                return -1;\n            }\n        } else {\n            val = JS_ToNumberFree(ctx, val);\n            if (JS_IsException(val))\n                return -1;\n            goto redo;\n        }\n        break;\n    }\n    *plen = len;\n    return 0;\n}\n\n#define MAX_SAFE_INTEGER (((int64_t)1 << 53) - 1)\n\nstatic BOOL is_safe_integer(double d)\n{\n    return isfinite(d) && floor(d) == d &&\n        fabs(d) <= (double)MAX_SAFE_INTEGER;\n}\n\nint JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val)\n{\n    int64_t v;\n    if (JS_ToInt64Sat(ctx, &v, val))\n        return -1;\n    if (v < 0 || v > MAX_SAFE_INTEGER) {\n        JS_ThrowRangeError(ctx, \"invalid array index\");\n        *plen = 0;\n        return -1;\n    }\n    *plen = v;\n    return 0;\n}\n\n/* convert a value to a length between 0 and MAX_SAFE_INTEGER.\n   return -1 for exception */\nstatic __exception int JS_ToLengthFree(JSContext *ctx, int64_t *plen,\n                                       JSValue val)\n{\n    int res = JS_ToInt64Clamp(ctx, plen, val, 0, MAX_SAFE_INTEGER, 0);\n    JS_FreeValue(ctx, val);\n    return res;\n}\n\n/* Note: can return an exception */\nstatic int JS_NumberIsInteger(JSContext *ctx, JSValueConst val)\n{\n    double d;\n    if (!JS_IsNumber(val))\n        return FALSE;\n    if (unlikely(JS_ToFloat64(ctx, &d, val)))\n        return -1;\n    return isfinite(d) && floor(d) == d;\n}\n\nstatic BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst val)\n{\n    uint32_t tag;\n\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n        {\n            int v;\n            v = JS_VALUE_GET_INT(val);\n            return (v < 0);\n        }\n    case JS_TAG_FLOAT64:\n        {\n            JSFloat64Union u;\n            u.d = JS_VALUE_GET_FLOAT64(val);\n            return (u.u64 >> 63);\n        }\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            /* Note: integer zeros are not necessarily positive */\n            return p->num.sign && !bf_is_zero(&p->num);\n        }\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            return p->num.sign;\n        }\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        {\n            JSBigDecimal *p = JS_VALUE_GET_PTR(val);\n            return p->num.sign;\n        }\n        break;\n#endif\n    default:\n        return FALSE;\n    }\n}\n\n#ifdef CONFIG_BIGNUM\n\nstatic JSValue js_bigint_to_string1(JSContext *ctx, JSValueConst val, int radix)\n{\n    JSValue ret;\n    bf_t a_s, *a;\n    char *str;\n    int saved_sign;\n\n    a = JS_ToBigInt(ctx, &a_s, val);\n    if (!a)\n        return JS_EXCEPTION;\n    saved_sign = a->sign;\n    if (a->expn == BF_EXP_ZERO)\n        a->sign = 0;\n    str = bf_ftoa(NULL, a, radix, 0, BF_RNDZ | BF_FTOA_FORMAT_FRAC |\n                  BF_FTOA_JS_QUIRKS);\n    a->sign = saved_sign;\n    JS_FreeBigInt(ctx, a, &a_s);\n    if (!str)\n        return JS_ThrowOutOfMemory(ctx);\n    ret = JS_NewString(ctx, str);\n    bf_free(ctx->bf_ctx, str);\n    return ret;\n}\n\nstatic JSValue js_bigint_to_string(JSContext *ctx, JSValueConst val)\n{\n    return js_bigint_to_string1(ctx, val, 10);\n}\n\nstatic JSValue js_ftoa(JSContext *ctx, JSValueConst val1, int radix,\n                       limb_t prec, bf_flags_t flags)\n{\n    JSValue val, ret;\n    bf_t a_s, *a;\n    char *str;\n    int saved_sign;\n\n    val = JS_ToNumeric(ctx, val1);\n    if (JS_IsException(val))\n        return val;\n    a = JS_ToBigFloat(ctx, &a_s, val);\n    saved_sign = a->sign;\n    if (a->expn == BF_EXP_ZERO)\n        a->sign = 0;\n    flags |= BF_FTOA_JS_QUIRKS;\n    if ((flags & BF_FTOA_FORMAT_MASK) == BF_FTOA_FORMAT_FREE_MIN) {\n        /* Note: for floating point numbers with a radix which is not\n           a power of two, the current precision is used to compute\n           the number of digits. */\n        if ((radix & (radix - 1)) != 0) {\n            bf_t r_s, *r = &r_s;\n            int prec, flags1;\n            /* must round first */\n            if (JS_VALUE_GET_TAG(val) == JS_TAG_BIG_FLOAT) {\n                prec = ctx->fp_env.prec;\n                flags1 = ctx->fp_env.flags &\n                    (BF_FLAG_SUBNORMAL | (BF_EXP_BITS_MASK << BF_EXP_BITS_SHIFT));\n            } else {\n                prec = 53;\n                flags1 = bf_set_exp_bits(11) | BF_FLAG_SUBNORMAL;\n            }\n            bf_init(ctx->bf_ctx, r);\n            bf_set(r, a);\n            bf_round(r, prec, flags1 | BF_RNDN);\n            str = bf_ftoa(NULL, r, radix, prec, flags1 | flags);\n            bf_delete(r);\n        } else {\n            str = bf_ftoa(NULL, a, radix, BF_PREC_INF, flags);\n        }\n    } else {\n        str = bf_ftoa(NULL, a, radix, prec, flags);\n    }\n    a->sign = saved_sign;\n    if (a == &a_s)\n        bf_delete(a);\n    JS_FreeValue(ctx, val);\n    if (!str)\n        return JS_ThrowOutOfMemory(ctx);\n    ret = JS_NewString(ctx, str);\n    bf_free(ctx->bf_ctx, str);\n    return ret;\n}\n\nstatic JSValue js_bigfloat_to_string(JSContext *ctx, JSValueConst val)\n{\n    return js_ftoa(ctx, val, 10, 0, BF_RNDN | BF_FTOA_FORMAT_FREE_MIN);\n}\n\nstatic JSValue js_bigdecimal_to_string1(JSContext *ctx, JSValueConst val,\n                                        limb_t prec, int flags)\n{\n    JSValue ret;\n    bfdec_t *a;\n    char *str;\n    int saved_sign;\n\n    a = JS_ToBigDecimal(ctx, val);\n    saved_sign = a->sign;\n    if (a->expn == BF_EXP_ZERO)\n        a->sign = 0;\n    str = bfdec_ftoa(NULL, a, prec, flags | BF_FTOA_JS_QUIRKS);\n    a->sign = saved_sign;\n    if (!str)\n        return JS_ThrowOutOfMemory(ctx);\n    ret = JS_NewString(ctx, str);\n    bf_free(ctx->bf_ctx, str);\n    return ret;\n}\n\nstatic JSValue js_bigdecimal_to_string(JSContext *ctx, JSValueConst val)\n{\n    return js_bigdecimal_to_string1(ctx, val, 0,\n                                    BF_RNDZ | BF_FTOA_FORMAT_FREE);\n}\n\n#endif /* CONFIG_BIGNUM */\n\n/* 2 <= base <= 36 */\nstatic char *i64toa(char *buf_end, int64_t n, unsigned int base)\n{\n    char *q = buf_end;\n    int digit, is_neg;\n\n    is_neg = 0;\n    if (n < 0) {\n        is_neg = 1;\n        n = -n;\n    }\n    *--q = '\\0';\n    do {\n        digit = (uint64_t)n % base;\n        n = (uint64_t)n / base;\n        if (digit < 10)\n            digit += '0';\n        else\n            digit += 'a' - 10;\n        *--q = digit;\n    } while (n != 0);\n    if (is_neg)\n        *--q = '-';\n    return q;\n}\n\n/* buf1 contains the printf result */\nstatic void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf,\n                     int rounding_mode, char *buf1, int buf1_size)\n{\n    if (rounding_mode != FE_TONEAREST)\n        fesetround(rounding_mode);\n    snprintf(buf1, buf1_size, \"%+.*e\", n_digits - 1, d);\n    if (rounding_mode != FE_TONEAREST)\n        fesetround(FE_TONEAREST);\n    *sign = (buf1[0] == '-');\n    /* mantissa */\n    buf[0] = buf1[1];\n    if (n_digits > 1)\n        memcpy(buf + 1, buf1 + 3, n_digits - 1);\n    buf[n_digits] = '\\0';\n    /* exponent */\n    *decpt = atoi(buf1 + n_digits + 2 + (n_digits > 1)) + 1;\n}\n\n/* maximum buffer size for js_dtoa */\n#define JS_DTOA_BUF_SIZE 128\n\n/* needed because ecvt usually limits the number of digits to\n   17. Return the number of digits. */\nstatic int js_ecvt(double d, int n_digits, int *decpt, int *sign, char *buf,\n                   BOOL is_fixed)\n{\n    int rounding_mode;\n    char buf_tmp[JS_DTOA_BUF_SIZE];\n\n    if (!is_fixed) {\n        unsigned int n_digits_min, n_digits_max;\n        /* find the minimum amount of digits (XXX: inefficient but simple) */\n        n_digits_min = 1;\n        n_digits_max = 17;\n        while (n_digits_min < n_digits_max) {\n            n_digits = (n_digits_min + n_digits_max) / 2;\n            js_ecvt1(d, n_digits, decpt, sign, buf, FE_TONEAREST,\n                     buf_tmp, sizeof(buf_tmp));\n            if (strtod(buf_tmp, NULL) == d) {\n                /* no need to keep the trailing zeros */\n                while (n_digits >= 2 && buf[n_digits - 1] == '0')\n                    n_digits--;\n                n_digits_max = n_digits;\n            } else {\n                n_digits_min = n_digits + 1;\n            }\n        }\n        n_digits = n_digits_max;\n        rounding_mode = FE_TONEAREST;\n    } else {\n        rounding_mode = FE_TONEAREST;\n#ifdef CONFIG_PRINTF_RNDN\n        {\n            char buf1[JS_DTOA_BUF_SIZE], buf2[JS_DTOA_BUF_SIZE];\n            int decpt1, sign1, decpt2, sign2;\n            /* The JS rounding is specified as round to nearest ties away\n               from zero (RNDNA), but in printf the \"ties\" case is not\n               specified (for example it is RNDN for glibc, RNDNA for\n               Windows), so we must round manually. */\n            js_ecvt1(d, n_digits + 1, &decpt1, &sign1, buf1, FE_TONEAREST,\n                     buf_tmp, sizeof(buf_tmp));\n            /* XXX: could use 2 digits to reduce the average running time */\n            if (buf1[n_digits] == '5') {\n                js_ecvt1(d, n_digits + 1, &decpt1, &sign1, buf1, FE_DOWNWARD,\n                         buf_tmp, sizeof(buf_tmp));\n                js_ecvt1(d, n_digits + 1, &decpt2, &sign2, buf2, FE_UPWARD,\n                         buf_tmp, sizeof(buf_tmp));\n                if (memcmp(buf1, buf2, n_digits + 1) == 0 && decpt1 == decpt2) {\n                    /* exact result: round away from zero */\n                    if (sign1)\n                        rounding_mode = FE_DOWNWARD;\n                    else\n                        rounding_mode = FE_UPWARD;\n                }\n            }\n        }\n#endif /* CONFIG_PRINTF_RNDN */\n    }\n    js_ecvt1(d, n_digits, decpt, sign, buf, rounding_mode,\n             buf_tmp, sizeof(buf_tmp));\n    return n_digits;\n}\n\nstatic int js_fcvt1(char *buf, int buf_size, double d, int n_digits,\n                    int rounding_mode)\n{\n    int n;\n    if (rounding_mode != FE_TONEAREST)\n        fesetround(rounding_mode);\n    n = snprintf(buf, buf_size, \"%.*f\", n_digits, d);\n    if (rounding_mode != FE_TONEAREST)\n        fesetround(FE_TONEAREST);\n    assert(n < buf_size);\n    return n;\n}\n\nstatic void js_fcvt(char *buf, int buf_size, double d, int n_digits)\n{\n    int rounding_mode;\n    rounding_mode = FE_TONEAREST;\n#ifdef CONFIG_PRINTF_RNDN\n    {\n        int n1, n2;\n        char buf1[JS_DTOA_BUF_SIZE];\n        char buf2[JS_DTOA_BUF_SIZE];\n\n        /* The JS rounding is specified as round to nearest ties away from\n           zero (RNDNA), but in printf the \"ties\" case is not specified\n           (for example it is RNDN for glibc, RNDNA for Windows), so we\n           must round manually. */\n        n1 = js_fcvt1(buf1, sizeof(buf1), d, n_digits + 1, FE_TONEAREST);\n        rounding_mode = FE_TONEAREST;\n        /* XXX: could use 2 digits to reduce the average running time */\n        if (buf1[n1 - 1] == '5') {\n            n1 = js_fcvt1(buf1, sizeof(buf1), d, n_digits + 1, FE_DOWNWARD);\n            n2 = js_fcvt1(buf2, sizeof(buf2), d, n_digits + 1, FE_UPWARD);\n            if (n1 == n2 && memcmp(buf1, buf2, n1) == 0) {\n                /* exact result: round away from zero */\n                if (buf1[0] == '-')\n                    rounding_mode = FE_DOWNWARD;\n                else\n                    rounding_mode = FE_UPWARD;\n            }\n        }\n    }\n#endif /* CONFIG_PRINTF_RNDN */\n    js_fcvt1(buf, buf_size, d, n_digits, rounding_mode);\n}\n\n/* radix != 10 is only supported with flags = JS_DTOA_VAR_FORMAT */\n/* use as many digits as necessary */\n#define JS_DTOA_VAR_FORMAT   (0 << 0)\n/* use n_digits significant digits (1 <= n_digits <= 101) */\n#define JS_DTOA_FIXED_FORMAT (1 << 0)\n/* force fractional format: [-]dd.dd with n_digits fractional digits */\n#define JS_DTOA_FRAC_FORMAT  (2 << 0)\n/* force exponential notation either in fixed or variable format */\n#define JS_DTOA_FORCE_EXP    (1 << 2)\n\n/* XXX: slow and maybe not fully correct. Use libbf when it is fast enough.\n   XXX: radix != 10 is only supported for small integers\n*/\nstatic void js_dtoa1(char *buf, double d, int radix, int n_digits, int flags)\n{\n    char *q;\n\n    if (!isfinite(d)) {\n        if (isnan(d)) {\n            strcpy(buf, \"NaN\");\n        } else {\n            q = buf;\n            if (d < 0)\n                *q++ = '-';\n            strcpy(q, \"Infinity\");\n        }\n    } else if (flags == JS_DTOA_VAR_FORMAT) {\n        int64_t i64;\n        char buf1[70], *ptr;\n        i64 = (int64_t)d;\n        if (d != i64 || i64 > MAX_SAFE_INTEGER || i64 < -MAX_SAFE_INTEGER)\n            goto generic_conv;\n        /* fast path for integers */\n        ptr = i64toa(buf1 + sizeof(buf1), i64, radix);\n        strcpy(buf, ptr);\n    } else {\n        if (d == 0.0)\n            d = 0.0; /* convert -0 to 0 */\n        if (flags == JS_DTOA_FRAC_FORMAT) {\n            js_fcvt(buf, JS_DTOA_BUF_SIZE, d, n_digits);\n        } else {\n            char buf1[JS_DTOA_BUF_SIZE];\n            int sign, decpt, k, n, i, p, n_max;\n            BOOL is_fixed;\n        generic_conv:\n            is_fixed = ((flags & 3) == JS_DTOA_FIXED_FORMAT);\n            if (is_fixed) {\n                n_max = n_digits;\n            } else {\n                n_max = 21;\n            }\n            /* the number has k digits (k >= 1) */\n            k = js_ecvt(d, n_digits, &decpt, &sign, buf1, is_fixed);\n            n = decpt; /* d=10^(n-k)*(buf1) i.e. d= < x.yyyy 10^(n-1) */\n            q = buf;\n            if (sign)\n                *q++ = '-';\n            if (flags & JS_DTOA_FORCE_EXP)\n                goto force_exp;\n            if (n >= 1 && n <= n_max) {\n                if (k <= n) {\n                    memcpy(q, buf1, k);\n                    q += k;\n                    for(i = 0; i < (n - k); i++)\n                        *q++ = '0';\n                    *q = '\\0';\n                } else {\n                    /* k > n */\n                    memcpy(q, buf1, n);\n                    q += n;\n                    *q++ = '.';\n                    for(i = 0; i < (k - n); i++)\n                        *q++ = buf1[n + i];\n                    *q = '\\0';\n                }\n            } else if (n >= -5 && n <= 0) {\n                *q++ = '0';\n                *q++ = '.';\n                for(i = 0; i < -n; i++)\n                    *q++ = '0';\n                memcpy(q, buf1, k);\n                q += k;\n                *q = '\\0';\n            } else {\n            force_exp:\n                /* exponential notation */\n                *q++ = buf1[0];\n                if (k > 1) {\n                    *q++ = '.';\n                    for(i = 1; i < k; i++)\n                        *q++ = buf1[i];\n                }\n                *q++ = 'e';\n                p = n - 1;\n                if (p >= 0)\n                    *q++ = '+';\n                sprintf(q, \"%d\", p);\n            }\n        }\n    }\n}\n\nstatic JSValue js_dtoa(JSContext *ctx,\n                       double d, int radix, int n_digits, int flags)\n{\n    char buf[JS_DTOA_BUF_SIZE];\n    js_dtoa1(buf, d, radix, n_digits, flags);\n    return JS_NewString(ctx, buf);\n}\n\nJSValue JS_ToStringInternal(JSContext *ctx, JSValueConst val, BOOL is_ToPropertyKey)\n{\n    uint32_t tag;\n    const char *str;\n    char buf[32];\n\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_STRING:\n        return JS_DupValue(ctx, val);\n    case JS_TAG_INT:\n        snprintf(buf, sizeof(buf), \"%d\", JS_VALUE_GET_INT(val));\n        str = buf;\n        goto new_string;\n    case JS_TAG_BOOL:\n        return JS_AtomToString(ctx, JS_VALUE_GET_BOOL(val) ?\n                          JS_ATOM_true : JS_ATOM_false);\n    case JS_TAG_NULL:\n        return JS_AtomToString(ctx, JS_ATOM_null);\n    case JS_TAG_UNDEFINED:\n        return JS_AtomToString(ctx, JS_ATOM_undefined);\n    case JS_TAG_EXCEPTION:\n        return JS_EXCEPTION;\n    case JS_TAG_OBJECT:\n        {\n            JSValue val1, ret;\n            val1 = JS_ToPrimitive(ctx, val, HINT_STRING);\n            if (JS_IsException(val1))\n                return val1;\n            ret = JS_ToStringInternal(ctx, val1, is_ToPropertyKey);\n            JS_FreeValue(ctx, val1);\n            return ret;\n        }\n        break;\n    case JS_TAG_FUNCTION_BYTECODE:\n        str = \"[function bytecode]\";\n        goto new_string;\n    case JS_TAG_SYMBOL:\n        if (is_ToPropertyKey) {\n            return JS_DupValue(ctx, val);\n        } else {\n            return JS_ThrowTypeError(ctx, \"cannot convert symbol to string\");\n        }\n    case JS_TAG_FLOAT64:\n        return js_dtoa(ctx, JS_VALUE_GET_FLOAT64(val), 10, 0,\n                       JS_DTOA_VAR_FORMAT);\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        return ctx->rt->bigint_ops.to_string(ctx, val);\n    case JS_TAG_BIG_FLOAT:\n        return ctx->rt->bigfloat_ops.to_string(ctx, val);\n    case JS_TAG_BIG_DECIMAL:\n        return ctx->rt->bigdecimal_ops.to_string(ctx, val);\n#endif\n    default:\n        str = \"[unsupported type]\";\n    new_string:\n        return JS_NewString(ctx, str);\n    }\n}\n\nJSValue JS_ToString(JSContext *ctx, JSValueConst val)\n{\n    return JS_ToStringInternal(ctx, val, FALSE);\n}\n\nstatic JSValue JS_ToStringFree(JSContext *ctx, JSValue val)\n{\n    JSValue ret;\n    ret = JS_ToString(ctx, val);\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic JSValue JS_ToLocaleStringFree(JSContext *ctx, JSValue val)\n{\n    if (JS_IsUndefined(val) || JS_IsNull(val))\n        return JS_ToStringFree(ctx, val);\n    return JS_InvokeFree(ctx, val, JS_ATOM_toLocaleString, 0, NULL);\n}\n\nJSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val)\n{\n    return JS_ToStringInternal(ctx, val, TRUE);\n}\n\nstatic JSValue JS_ToStringCheckObject(JSContext *ctx, JSValueConst val)\n{\n    uint32_t tag = JS_VALUE_GET_TAG(val);\n    if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED)\n        return JS_ThrowTypeError(ctx, \"null or undefined are forbidden\");\n    return JS_ToString(ctx, val);\n}\n\nstatic JSValue JS_ToQuotedString(JSContext *ctx, JSValueConst val1)\n{\n    JSValue val;\n    JSString *p;\n    int i;\n    uint32_t c;\n    StringBuffer b_s, *b = &b_s;\n    char buf[16];\n\n    val = JS_ToStringCheckObject(ctx, val1);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_STRING(val);\n\n    if (string_buffer_init(ctx, b, p->len + 2))\n        goto fail;\n\n    if (string_buffer_putc8(b, '\\\"'))\n        goto fail;\n    for(i = 0; i < p->len; ) {\n        c = string_getc(p, &i);\n        switch(c) {\n        case '\\t':\n            c = 't';\n            goto quote;\n        case '\\r':\n            c = 'r';\n            goto quote;\n        case '\\n':\n            c = 'n';\n            goto quote;\n        case '\\b':\n            c = 'b';\n            goto quote;\n        case '\\f':\n            c = 'f';\n            goto quote;\n        case '\\\"':\n        case '\\\\':\n        quote:\n            if (string_buffer_putc8(b, '\\\\'))\n                goto fail;\n            if (string_buffer_putc8(b, c))\n                goto fail;\n            break;\n        default:\n            if (c < 32 || (c >= 0xd800 && c < 0xe000)) {\n                snprintf(buf, sizeof(buf), \"\\\\u%04x\", c);\n                if (string_buffer_puts8(b, buf))\n                    goto fail;\n            } else {\n                if (string_buffer_putc(b, c))\n                    goto fail;\n            }\n            break;\n        }\n    }\n    if (string_buffer_putc8(b, '\\\"'))\n        goto fail;\n    JS_FreeValue(ctx, val);\n    return string_buffer_end(b);\n fail:\n    JS_FreeValue(ctx, val);\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic __maybe_unused void JS_DumpObjectHeader(JSRuntime *rt)\n{\n    printf(\"%14s %4s %4s %14s %10s %s\\n\",\n           \"ADDRESS\", \"REFS\", \"SHRF\", \"PROTO\", \"CLASS\", \"PROPS\");\n}\n\n/* for debug only: dump an object without side effect */\nstatic __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p)\n{\n    uint32_t i;\n    char atom_buf[ATOM_GET_STR_BUF_SIZE];\n    JSShape *sh;\n    JSShapeProperty *prs;\n    JSProperty *pr;\n    BOOL is_first = TRUE;\n\n    /* XXX: should encode atoms with special characters */\n    sh = p->shape; /* the shape can be NULL while freeing an object */\n    printf(\"%14p %4d \",\n           (void *)p,\n           p->header.ref_count);\n    if (sh) {\n        printf(\"%3d%c %14p \",\n               sh->header.ref_count,\n               \" *\"[sh->is_hashed],\n               (void *)sh->proto);\n    } else {\n        printf(\"%3s  %14s \", \"-\", \"-\");\n    }\n    printf(\"%10s \",\n           JS_AtomGetStrRT(rt, atom_buf, sizeof(atom_buf), rt->class_array[p->class_id].class_name));\n    if (p->is_exotic && p->fast_array) {\n        printf(\"[ \");\n        for(i = 0; i < p->u.array.count; i++) {\n            if (i != 0)\n                printf(\", \");\n            switch (p->class_id) {\n            case JS_CLASS_ARRAY:\n            case JS_CLASS_ARGUMENTS:\n                JS_DumpValueShort(rt, p->u.array.u.values[i]);\n                break;\n            case JS_CLASS_UINT8C_ARRAY ... JS_CLASS_FLOAT64_ARRAY:\n                {\n                    int size = 1 << typed_array_size_log2(p->class_id);\n                    const uint8_t *b = p->u.array.u.uint8_ptr + i * size;\n                    while (size-- > 0)\n                        printf(\"%02X\", *b++);\n                }\n                break;\n            }\n        }\n        printf(\" ] \");\n    }\n\n    if (sh) {\n        printf(\"{ \");\n        for(i = 0, prs = get_shape_prop(sh); i < sh->prop_count; i++, prs++) {\n            if (prs->atom != JS_ATOM_NULL) {\n                pr = &p->prop[i];\n                if (!is_first)\n                    printf(\", \");\n                printf(\"%s: \",\n                       JS_AtomGetStrRT(rt, atom_buf, sizeof(atom_buf), prs->atom));\n                if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) {\n                    printf(\"[getset %p %p]\", (void *)pr->u.getset.getter,\n                           (void *)pr->u.getset.setter);\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) {\n                    printf(\"[varref %p]\", (void *)pr->u.var_ref);\n                } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_AUTOINIT) {\n                    printf(\"[autoinit %p %d %p]\",\n                           (void *)js_autoinit_get_realm(pr),\n                           js_autoinit_get_id(pr),\n                           (void *)pr->u.init.opaque);\n                } else {\n                    JS_DumpValueShort(rt, pr->u.value);\n                }\n                is_first = FALSE;\n            }\n        }\n        printf(\" }\");\n    }\n    \n    if (js_class_has_bytecode(p->class_id)) {\n        JSFunctionBytecode *b = p->u.func.function_bytecode;\n        JSVarRef **var_refs;\n        if (b->closure_var_count) {\n            var_refs = p->u.func.var_refs;\n            printf(\" Closure:\");\n            for(i = 0; i < b->closure_var_count; i++) {\n                printf(\" \");\n                JS_DumpValueShort(rt, var_refs[i]->value);\n            }\n            if (p->u.func.home_object) {\n                printf(\" HomeObject: \");\n                JS_DumpValueShort(rt, JS_MKPTR(JS_TAG_OBJECT, p->u.func.home_object));\n            }\n        }\n    }\n    printf(\"\\n\");\n}\n\nstatic __maybe_unused void JS_DumpGCObject(JSRuntime *rt, JSGCObjectHeader *p)\n{\n    if (p->gc_obj_type == JS_GC_OBJ_TYPE_JS_OBJECT) {\n        JS_DumpObject(rt, (JSObject *)p);\n    } else {\n        printf(\"%14p %4d \",\n               (void *)p,\n               p->ref_count);\n        switch(p->gc_obj_type) {\n        case JS_GC_OBJ_TYPE_FUNCTION_BYTECODE:\n            printf(\"[function bytecode]\");\n            break;\n        case JS_GC_OBJ_TYPE_SHAPE:\n            printf(\"[shape]\");\n            break;\n        case JS_GC_OBJ_TYPE_VAR_REF:\n            printf(\"[var_ref]\");\n            break;\n        case JS_GC_OBJ_TYPE_ASYNC_FUNCTION:\n            printf(\"[async_function]\");\n            break;\n        case JS_GC_OBJ_TYPE_JS_CONTEXT:\n            printf(\"[js_context]\");\n            break;\n        default:\n            printf(\"[unknown %d]\", p->gc_obj_type);\n            break;\n        }\n        printf(\"\\n\");\n    }\n}\n\nstatic __maybe_unused void JS_DumpValueShort(JSRuntime *rt,\n                                                      JSValueConst val)\n{\n    uint32_t tag = JS_VALUE_GET_NORM_TAG(val);\n    const char *str;\n\n    switch(tag) {\n    case JS_TAG_INT:\n        printf(\"%d\", JS_VALUE_GET_INT(val));\n        break;\n    case JS_TAG_BOOL:\n        if (JS_VALUE_GET_BOOL(val))\n            str = \"true\";\n        else\n            str = \"false\";\n        goto print_str;\n    case JS_TAG_NULL:\n        str = \"null\";\n        goto print_str;\n    case JS_TAG_EXCEPTION:\n        str = \"exception\";\n        goto print_str;\n    case JS_TAG_UNINITIALIZED:\n        str = \"uninitialized\";\n        goto print_str;\n    case JS_TAG_UNDEFINED:\n        str = \"undefined\";\n    print_str:\n        printf(\"%s\", str);\n        break;\n    case JS_TAG_FLOAT64:\n        printf(\"%.14g\", JS_VALUE_GET_FLOAT64(val));\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            char *str;\n            str = bf_ftoa(NULL, &p->num, 10, 0,\n                          BF_RNDZ | BF_FTOA_FORMAT_FRAC);\n            printf(\"%sn\", str);\n            bf_realloc(&rt->bf_ctx, str, 0);\n        }\n        break;\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            char *str;\n            str = bf_ftoa(NULL, &p->num, 16, BF_PREC_INF,\n                          BF_RNDZ | BF_FTOA_FORMAT_FREE | BF_FTOA_ADD_PREFIX);\n            printf(\"%sl\", str);\n            bf_free(&rt->bf_ctx, str);\n        }\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        {\n            JSBigDecimal *p = JS_VALUE_GET_PTR(val);\n            char *str;\n            str = bfdec_ftoa(NULL, &p->num, BF_PREC_INF,\n                             BF_RNDZ | BF_FTOA_FORMAT_FREE);\n            printf(\"%sm\", str);\n            bf_free(&rt->bf_ctx, str);\n        }\n        break;\n#endif\n    case JS_TAG_STRING:\n        {\n            JSString *p;\n            p = JS_VALUE_GET_STRING(val);\n            JS_DumpString(rt, p);\n        }\n        break;\n    case JS_TAG_FUNCTION_BYTECODE:\n        {\n            JSFunctionBytecode *b = JS_VALUE_GET_PTR(val);\n            char buf[ATOM_GET_STR_BUF_SIZE];\n            printf(\"[bytecode %s]\", JS_AtomGetStrRT(rt, buf, sizeof(buf), b->func_name));\n        }\n        break;\n    case JS_TAG_OBJECT:\n        {\n            JSObject *p = JS_VALUE_GET_OBJ(val);\n            JSAtom atom = rt->class_array[p->class_id].class_name;\n            char atom_buf[ATOM_GET_STR_BUF_SIZE];\n            printf(\"[%s %p]\",\n                   JS_AtomGetStrRT(rt, atom_buf, sizeof(atom_buf), atom), (void *)p);\n        }\n        break;\n    case JS_TAG_SYMBOL:\n        {\n            JSAtomStruct *p = JS_VALUE_GET_PTR(val);\n            char atom_buf[ATOM_GET_STR_BUF_SIZE];\n            printf(\"Symbol(%s)\",\n                   JS_AtomGetStrRT(rt, atom_buf, sizeof(atom_buf), js_get_atom_index(rt, p)));\n        }\n        break;\n    case JS_TAG_MODULE:\n        printf(\"[module]\");\n        break;\n    default:\n        printf(\"[unknown tag %d]\", tag);\n        break;\n    }\n}\n\nstatic __maybe_unused void JS_DumpValue(JSContext *ctx,\n                                                 JSValueConst val)\n{\n    JS_DumpValueShort(ctx->rt, val);\n}\n\nstatic __maybe_unused void JS_PrintValue(JSContext *ctx,\n                                                  const char *str,\n                                                  JSValueConst val)\n{\n    printf(\"%s=\", str);\n    JS_DumpValueShort(ctx->rt, val);\n    printf(\"\\n\");\n}\n\n/* return -1 if exception (proxy case) or TRUE/FALSE */\nint JS_IsArray(JSContext *ctx, JSValueConst val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {\n        p = JS_VALUE_GET_OBJ(val);\n        if (unlikely(p->class_id == JS_CLASS_PROXY))\n            return js_proxy_isArray(ctx, val);\n        else\n            return p->class_id == JS_CLASS_ARRAY;\n    } else {\n        return FALSE;\n    }\n}\n\nstatic double js_pow(double a, double b)\n{\n    if (unlikely(!isfinite(b)) && fabs(a) == 1) {\n        /* not compatible with IEEE 754 */\n        return JS_FLOAT64_NAN;\n    } else {\n        return pow(a, b);\n    }\n}\n\n#ifdef CONFIG_BIGNUM\n\nJSValue JS_NewBigInt64_1(JSContext *ctx, int64_t v)\n{\n    JSValue val;\n    bf_t *a;\n    val = JS_NewBigInt(ctx);\n    if (JS_IsException(val))\n        return val;\n    a = JS_GetBigInt(val);\n    if (bf_set_si(a, v)) {\n        JS_FreeValue(ctx, val);\n        return JS_ThrowOutOfMemory(ctx);\n    }\n    return val;\n}\n\nJSValue JS_NewBigInt64(JSContext *ctx, int64_t v)\n{\n    if (is_math_mode(ctx) &&\n        v >= -MAX_SAFE_INTEGER && v <= MAX_SAFE_INTEGER) {\n        return JS_NewInt64(ctx, v);\n    } else {\n        return JS_NewBigInt64_1(ctx, v);\n    }\n}\n\nJSValue JS_NewBigUint64(JSContext *ctx, uint64_t v)\n{\n    JSValue val;\n    if (is_math_mode(ctx) && v <= MAX_SAFE_INTEGER) {\n        val = JS_NewInt64(ctx, v);\n    } else {\n        bf_t *a;\n        val = JS_NewBigInt(ctx);\n        if (JS_IsException(val))\n            return val;\n        a = JS_GetBigInt(val);\n        if (bf_set_ui(a, v)) {\n            JS_FreeValue(ctx, val);\n            return JS_ThrowOutOfMemory(ctx);\n        }\n    }\n    return val;\n}\n\n/* if the returned bigfloat is allocated it is equal to\n   'buf'. Otherwise it is a pointer to the bigfloat in 'val'. Return\n   NULL in case of error. */\nstatic bf_t *JS_ToBigFloat(JSContext *ctx, bf_t *buf, JSValueConst val)\n{\n    uint32_t tag;\n    bf_t *r;\n    JSBigFloat *p;\n\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n        r = buf;\n        bf_init(ctx->bf_ctx, r);\n        if (bf_set_si(r, JS_VALUE_GET_INT(val)))\n            goto fail;\n        break;\n    case JS_TAG_FLOAT64:\n        r = buf;\n        bf_init(ctx->bf_ctx, r);\n        if (bf_set_float64(r, JS_VALUE_GET_FLOAT64(val))) {\n        fail:\n            bf_delete(r);\n            return NULL;\n        }\n        break;\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n        p = JS_VALUE_GET_PTR(val);\n        r = &p->num;\n        break;\n    case JS_TAG_UNDEFINED:\n    default:\n        r = buf;\n        bf_init(ctx->bf_ctx, r);\n        bf_set_nan(r);\n        break;\n    }\n    return r;\n}\n\n/* return NULL if invalid type */\nstatic bfdec_t *JS_ToBigDecimal(JSContext *ctx, JSValueConst val)\n{\n    uint32_t tag;\n    JSBigDecimal *p;\n    bfdec_t *r;\n    \n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_BIG_DECIMAL:\n        p = JS_VALUE_GET_PTR(val);\n        r = &p->num;\n        break;\n    default:\n        JS_ThrowTypeError(ctx, \"bigdecimal expected\");\n        r = NULL;\n        break;\n    }\n    return r;\n}\n\n/* return NaN if bad bigint literal */\nstatic JSValue JS_StringToBigInt(JSContext *ctx, JSValue val)\n{\n    const char *str, *p;\n    size_t len;\n    int flags;\n    \n    str = JS_ToCStringLen(ctx, &len, val);\n    JS_FreeValue(ctx, val);\n    if (!str)\n        return JS_EXCEPTION;\n    p = str;\n    p += skip_spaces(p);\n    if ((p - str) == len) {\n        val = JS_NewBigInt64(ctx, 0);\n    } else {\n        flags = ATOD_INT_ONLY | ATOD_ACCEPT_BIN_OCT | ATOD_TYPE_BIG_INT;\n        if (is_math_mode(ctx))\n            flags |= ATOD_MODE_BIGINT;\n        val = js_atof(ctx, p, &p, 0, flags);\n        p += skip_spaces(p);\n        if (!JS_IsException(val)) {\n            if ((p - str) != len) {\n                JS_FreeValue(ctx, val);\n                val = JS_NAN;\n            }\n        }\n    }\n    JS_FreeCString(ctx, str);\n    return val;\n}\n\nstatic JSValue JS_StringToBigIntErr(JSContext *ctx, JSValue val)\n{\n    val = JS_StringToBigInt(ctx, val);\n    if (JS_VALUE_IS_NAN(val))\n        return JS_ThrowSyntaxError(ctx, \"invalid bigint literal\");\n    return val;\n}\n\n/* if the returned bigfloat is allocated it is equal to\n   'buf'. Otherwise it is a pointer to the bigfloat in 'val'. */\nstatic bf_t *JS_ToBigIntFree(JSContext *ctx, bf_t *buf, JSValue val)\n{\n    uint32_t tag;\n    bf_t *r;\n    JSBigFloat *p;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        if (!is_math_mode(ctx))\n            goto fail;\n        /* fall tru */\n    case JS_TAG_BOOL:\n        r = buf;\n        bf_init(ctx->bf_ctx, r);\n        bf_set_si(r, JS_VALUE_GET_INT(val));\n        break;\n    case JS_TAG_FLOAT64:\n        {\n            double d = JS_VALUE_GET_FLOAT64(val);\n            if (!is_math_mode(ctx))\n                goto fail;\n            if (!isfinite(d))\n                goto fail;\n            r = buf;\n            bf_init(ctx->bf_ctx, r);\n            d = trunc(d);\n            bf_set_float64(r, d);\n        }\n        break;\n    case JS_TAG_BIG_INT:\n        p = JS_VALUE_GET_PTR(val);\n        r = &p->num;\n        break;\n    case JS_TAG_BIG_FLOAT:\n        if (!is_math_mode(ctx))\n            goto fail;\n        p = JS_VALUE_GET_PTR(val);\n        if (!bf_is_finite(&p->num))\n            goto fail;\n        r = buf;\n        bf_init(ctx->bf_ctx, r);\n        bf_set(r, &p->num);\n        bf_rint(r, BF_RNDZ);\n        JS_FreeValue(ctx, val);\n        break;\n    case JS_TAG_STRING:\n        val = JS_StringToBigIntErr(ctx, val);\n        if (JS_IsException(val))\n            return NULL;\n        goto redo;\n    case JS_TAG_OBJECT:\n        val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);\n        if (JS_IsException(val))\n            return NULL;\n        goto redo;\n    default:\n    fail:\n        JS_FreeValue(ctx, val);\n        JS_ThrowTypeError(ctx, \"cannot convert to bigint\");\n        return NULL;\n    }\n    return r;\n}\n\nstatic bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValueConst val)\n{\n    return JS_ToBigIntFree(ctx, buf, JS_DupValue(ctx, val));\n}\n\nstatic __maybe_unused JSValue JS_ToBigIntValueFree(JSContext *ctx, JSValue val)\n{\n    if (JS_VALUE_GET_TAG(val) == JS_TAG_BIG_INT) {\n        return val;\n    } else {\n        bf_t a_s, *a, *r;\n        int ret;\n        JSValue res; \n\n        res = JS_NewBigInt(ctx);\n        if (JS_IsException(res))\n            return JS_EXCEPTION;\n        a = JS_ToBigIntFree(ctx, &a_s, val);\n        if (!a) {\n            JS_FreeValue(ctx, res);\n            return JS_EXCEPTION;\n        }\n        r = JS_GetBigInt(res);\n        ret = bf_set(r, a);\n        JS_FreeBigInt(ctx, a, &a_s);\n        if (ret) {\n            JS_FreeValue(ctx, res);\n            return JS_ThrowOutOfMemory(ctx);\n        }\n        return JS_CompactBigInt(ctx, res);\n    }\n}\n\n/* free the bf_t allocated by JS_ToBigInt */\nstatic void JS_FreeBigInt(JSContext *ctx, bf_t *a, bf_t *buf)\n{\n    if (a == buf) {\n        bf_delete(a);\n    } else {\n        JSBigFloat *p = (JSBigFloat *)((uint8_t *)a -\n                                       offsetof(JSBigFloat, num));\n        JS_FreeValue(ctx, JS_MKPTR(JS_TAG_BIG_FLOAT, p));\n    }\n}\n\n/* XXX: merge with JS_ToInt64Free with a specific flag */\nstatic int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val)\n{\n    bf_t a_s, *a;\n\n    a = JS_ToBigIntFree(ctx, &a_s, val);\n    if (!a) {\n        *pres = 0;\n        return -1;\n    }\n    bf_get_int64(pres, a, BF_GET_INT_MOD);\n    JS_FreeBigInt(ctx, a, &a_s);\n    return 0;\n}\n\nint JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val)\n{\n    return JS_ToBigInt64Free(ctx, pres, JS_DupValue(ctx, val));\n}\n\nstatic JSBigFloat *js_new_bf(JSContext *ctx)\n{\n    JSBigFloat *p;\n    p = js_malloc(ctx, sizeof(*p));\n    if (!p)\n        return NULL;\n    p->header.ref_count = 1;\n    bf_init(ctx->bf_ctx, &p->num);\n    return p;\n}\n\nstatic JSValue JS_NewBigFloat(JSContext *ctx)\n{\n    JSBigFloat *p;\n    p = js_malloc(ctx, sizeof(*p));\n    if (!p)\n        return JS_EXCEPTION;\n    p->header.ref_count = 1;\n    bf_init(ctx->bf_ctx, &p->num);\n    return JS_MKPTR(JS_TAG_BIG_FLOAT, p);\n}\n\nstatic JSValue JS_NewBigDecimal(JSContext *ctx)\n{\n    JSBigDecimal *p;\n    p = js_malloc(ctx, sizeof(*p));\n    if (!p)\n        return JS_EXCEPTION;\n    p->header.ref_count = 1;\n    bfdec_init(ctx->bf_ctx, &p->num);\n    return JS_MKPTR(JS_TAG_BIG_DECIMAL, p);\n}\n\nstatic JSValue JS_NewBigInt(JSContext *ctx)\n{\n    JSBigFloat *p;\n    p = js_malloc(ctx, sizeof(*p));\n    if (!p)\n        return JS_EXCEPTION;\n    p->header.ref_count = 1;\n    bf_init(ctx->bf_ctx, &p->num);\n    return JS_MKPTR(JS_TAG_BIG_INT, p);\n}\n\nstatic JSValue JS_CompactBigInt1(JSContext *ctx, JSValue val,\n                                 BOOL convert_to_safe_integer)\n{\n    int64_t v;\n    bf_t *a;\n    \n    if (JS_VALUE_GET_TAG(val) != JS_TAG_BIG_INT)\n        return val; /* fail safe */\n    a = JS_GetBigInt(val);\n    if (convert_to_safe_integer && bf_get_int64(&v, a, 0) == 0 &&\n        v >= -MAX_SAFE_INTEGER && v <= MAX_SAFE_INTEGER) {\n        JS_FreeValue(ctx, val);\n        return JS_NewInt64(ctx, v);\n    } else if (a->expn == BF_EXP_ZERO && a->sign) {\n        JSBigFloat *p = JS_VALUE_GET_PTR(val);\n        assert(p->header.ref_count == 1);\n        a->sign = 0;\n    }\n    return val;\n}\n\n/* Convert the big int to a safe integer if in math mode. normalize\n   the zero representation. Could also be used to convert the bigint\n   to a short bigint value. The reference count of the value must be\n   1. Cannot fail */\nstatic JSValue JS_CompactBigInt(JSContext *ctx, JSValue val)\n{\n    return JS_CompactBigInt1(ctx, val, is_math_mode(ctx));\n}\n\n/* must be kept in sync with JSOverloadableOperatorEnum */\n/* XXX: use atoms ? */\nstatic const char js_overloadable_operator_names[JS_OVOP_COUNT][4] = {\n    \"+\",\n    \"-\",\n    \"*\",\n    \"/\",\n    \"%\",\n    \"**\",\n    \"|\",\n    \"&\",\n    \"^\",\n    \"<<\",\n    \">>\",\n    \">>>\",\n    \"==\",\n    \"<\",\n    \"pos\",\n    \"neg\",\n    \"++\",\n    \"--\",\n    \"~\",\n};\n\nstatic int get_ovop_from_opcode(OPCodeEnum op)\n{\n    switch(op) {\n    case OP_add:\n        return JS_OVOP_ADD;\n    case OP_sub:\n        return JS_OVOP_SUB;\n    case OP_mul:\n        return JS_OVOP_MUL;\n    case OP_div:\n        return JS_OVOP_DIV;\n    case OP_mod:\n    case OP_math_mod:\n        return JS_OVOP_MOD;\n    case OP_pow:\n        return JS_OVOP_POW;\n    case OP_or:\n        return JS_OVOP_OR;\n    case OP_and:\n        return JS_OVOP_AND;\n    case OP_xor:\n        return JS_OVOP_XOR;\n    case OP_shl:\n        return JS_OVOP_SHL;\n    case OP_sar:\n        return JS_OVOP_SAR;\n    case OP_shr:\n        return JS_OVOP_SHR;\n    case OP_eq:\n    case OP_neq:\n        return JS_OVOP_EQ;\n    case OP_lt:\n    case OP_lte:\n    case OP_gt:\n    case OP_gte:\n        return JS_OVOP_LESS;\n    case OP_plus:\n        return JS_OVOP_POS;\n    case OP_neg:\n        return JS_OVOP_NEG;\n    case OP_inc:\n        return JS_OVOP_INC;\n    case OP_dec:\n        return JS_OVOP_DEC;\n    default:\n        abort();\n    }\n}\n\n/* return NULL if not present */\nstatic JSObject *find_binary_op(JSBinaryOperatorDef *def,\n                                uint32_t operator_index,\n                                JSOverloadableOperatorEnum op)\n{\n    JSBinaryOperatorDefEntry *ent;\n    int i;\n    for(i = 0; i < def->count; i++) {\n        ent = &def->tab[i];\n        if (ent->operator_index == operator_index)\n            return ent->ops[op];\n    }\n    return NULL;\n}\n\n/* return -1 if exception, 0 if no operator overloading, 1 if\n   overloaded operator called */\nstatic __exception int js_call_binary_op_fallback(JSContext *ctx,\n                                                  JSValue *pret,\n                                                  JSValueConst op1,\n                                                  JSValueConst op2,\n                                                  OPCodeEnum op,\n                                                  BOOL is_numeric,\n                                                  int hint)\n{\n    JSValue opset1_obj, opset2_obj, method, ret, new_op1, new_op2;\n    JSOperatorSetData *opset1, *opset2;\n    JSOverloadableOperatorEnum ovop;\n    JSObject *p;\n    JSValueConst args[2];\n    \n    if (!ctx->allow_operator_overloading)\n        return 0;\n    \n    opset2_obj = JS_UNDEFINED;\n    opset1_obj = JS_GetProperty(ctx, op1, JS_ATOM_Symbol_operatorSet);\n    if (JS_IsException(opset1_obj))\n        goto exception;\n    if (JS_IsUndefined(opset1_obj))\n        return 0;\n    opset1 = JS_GetOpaque2(ctx, opset1_obj, JS_CLASS_OPERATOR_SET);\n    if (!opset1)\n        goto exception;\n\n    opset2_obj = JS_GetProperty(ctx, op2, JS_ATOM_Symbol_operatorSet);\n    if (JS_IsException(opset2_obj))\n        goto exception;\n    if (JS_IsUndefined(opset2_obj)) {\n        JS_FreeValue(ctx, opset1_obj);\n        return 0;\n    }\n    opset2 = JS_GetOpaque2(ctx, opset2_obj, JS_CLASS_OPERATOR_SET);\n    if (!opset2)\n        goto exception;\n\n    if (opset1->is_primitive && opset2->is_primitive) {\n        JS_FreeValue(ctx, opset1_obj);\n        JS_FreeValue(ctx, opset2_obj);\n        return 0;\n    }\n\n    ovop = get_ovop_from_opcode(op);\n    \n    if (opset1->operator_counter == opset2->operator_counter) {\n        p = opset1->self_ops[ovop];\n    } else if (opset1->operator_counter > opset2->operator_counter) {\n        p = find_binary_op(&opset1->left, opset2->operator_counter, ovop);\n    } else {\n        p = find_binary_op(&opset2->right, opset1->operator_counter, ovop);\n    }\n    if (!p) {\n        JS_ThrowTypeError(ctx, \"operator %s: no function defined\",\n                          js_overloadable_operator_names[ovop]);\n        goto exception;\n    }\n\n    if (opset1->is_primitive) {\n        if (is_numeric) {\n            new_op1 = JS_ToNumeric(ctx, op1);\n        } else {\n            new_op1 = JS_ToPrimitive(ctx, op1, hint);\n        }\n        if (JS_IsException(new_op1))\n            goto exception;\n    } else {\n        new_op1 = JS_DupValue(ctx, op1);\n    }\n    \n    if (opset2->is_primitive) {\n        if (is_numeric) {\n            new_op2 = JS_ToNumeric(ctx, op2);\n        } else {\n            new_op2 = JS_ToPrimitive(ctx, op2, hint);\n        }\n        if (JS_IsException(new_op2)) {\n            JS_FreeValue(ctx, new_op1);\n            goto exception;\n        }\n    } else {\n        new_op2 = JS_DupValue(ctx, op2);\n    }\n\n    /* XXX: could apply JS_ToPrimitive() if primitive type so that the\n       operator function does not get a value object */\n    \n    method = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n    if (ovop == JS_OVOP_LESS && (op == OP_lte || op == OP_gt)) {\n        args[0] = new_op2;\n        args[1] = new_op1;\n    } else {\n        args[0] = new_op1;\n        args[1] = new_op2;\n    }\n    ret = JS_CallFree(ctx, method, JS_UNDEFINED, 2, args);\n    JS_FreeValue(ctx, new_op1);\n    JS_FreeValue(ctx, new_op2);\n    if (JS_IsException(ret))\n        goto exception;\n    if (ovop == JS_OVOP_EQ) {\n        BOOL res = JS_ToBoolFree(ctx, ret);\n        if (op == OP_neq)\n            res ^= 1;\n        ret = JS_NewBool(ctx, res);\n    } else if (ovop == JS_OVOP_LESS) {\n        if (JS_IsUndefined(ret)) {\n            ret = JS_FALSE;\n        } else {\n            BOOL res = JS_ToBoolFree(ctx, ret);\n            if (op == OP_lte || op == OP_gte)\n                res ^= 1;\n            ret = JS_NewBool(ctx, res);\n        }\n    }\n    JS_FreeValue(ctx, opset1_obj);\n    JS_FreeValue(ctx, opset2_obj);\n    *pret = ret;\n    return 1;\n exception:\n    JS_FreeValue(ctx, opset1_obj);\n    JS_FreeValue(ctx, opset2_obj);\n    *pret = JS_UNDEFINED;\n    return -1;\n}\n\n/* try to call the operation on the operatorSet field of 'obj'. Only\n   used for \"/\" and \"**\" on the BigInt prototype in math mode */\nstatic __exception int js_call_binary_op_simple(JSContext *ctx,\n                                                JSValue *pret,\n                                                JSValueConst obj,\n                                                JSValueConst op1,\n                                                JSValueConst op2,\n                                                OPCodeEnum op)\n{\n    JSValue opset1_obj, method, ret, new_op1, new_op2;\n    JSOperatorSetData *opset1;\n    JSOverloadableOperatorEnum ovop;\n    JSObject *p;\n    JSValueConst args[2];\n\n    opset1_obj = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_operatorSet);\n    if (JS_IsException(opset1_obj))\n        goto exception;\n    if (JS_IsUndefined(opset1_obj))\n        return 0;\n    opset1 = JS_GetOpaque2(ctx, opset1_obj, JS_CLASS_OPERATOR_SET);\n    if (!opset1)\n        goto exception;\n    ovop = get_ovop_from_opcode(op);\n\n    p = opset1->self_ops[ovop];\n    if (!p) {\n        JS_FreeValue(ctx, opset1_obj);\n        return 0;\n    }\n\n    new_op1 = JS_ToNumeric(ctx, op1);\n    if (JS_IsException(new_op1))\n        goto exception;\n    new_op2 = JS_ToNumeric(ctx, op2);\n    if (JS_IsException(new_op2)) {\n        JS_FreeValue(ctx, new_op1);\n        goto exception;\n    }\n\n    method = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n    args[0] = new_op1;\n    args[1] = new_op2;\n    ret = JS_CallFree(ctx, method, JS_UNDEFINED, 2, args);\n    JS_FreeValue(ctx, new_op1);\n    JS_FreeValue(ctx, new_op2);\n    if (JS_IsException(ret))\n        goto exception;\n    JS_FreeValue(ctx, opset1_obj);\n    *pret = ret;\n    return 1;\n exception:\n    JS_FreeValue(ctx, opset1_obj);\n    *pret = JS_UNDEFINED;\n    return -1;\n}\n\n/* return -1 if exception, 0 if no operator overloading, 1 if\n   overloaded operator called */\nstatic __exception int js_call_unary_op_fallback(JSContext *ctx,\n                                                 JSValue *pret,\n                                                 JSValueConst op1,\n                                                 OPCodeEnum op)\n{\n    JSValue opset1_obj, method, ret;\n    JSOperatorSetData *opset1;\n    JSOverloadableOperatorEnum ovop;\n    JSObject *p;\n\n    if (!ctx->allow_operator_overloading)\n        return 0;\n    \n    opset1_obj = JS_GetProperty(ctx, op1, JS_ATOM_Symbol_operatorSet);\n    if (JS_IsException(opset1_obj))\n        goto exception;\n    if (JS_IsUndefined(opset1_obj))\n        return 0;\n    opset1 = JS_GetOpaque2(ctx, opset1_obj, JS_CLASS_OPERATOR_SET);\n    if (!opset1)\n        goto exception;\n    if (opset1->is_primitive) {\n        JS_FreeValue(ctx, opset1_obj);\n        return 0;\n    }\n\n    ovop = get_ovop_from_opcode(op);\n\n    p = opset1->self_ops[ovop];\n    if (!p) {\n        JS_ThrowTypeError(ctx, \"no overloaded operator %s\",\n                          js_overloadable_operator_names[ovop]);\n        goto exception;\n    }\n    method = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p));\n    ret = JS_CallFree(ctx, method, JS_UNDEFINED, 1, &op1);\n    if (JS_IsException(ret))\n        goto exception;\n    JS_FreeValue(ctx, opset1_obj);\n    *pret = ret;\n    return 1;\n exception:\n    JS_FreeValue(ctx, opset1_obj);\n    *pret = JS_UNDEFINED;\n    return -1;\n}\n\nstatic JSValue throw_bf_exception(JSContext *ctx, int status)\n{\n    const char *str;\n    if (status & BF_ST_MEM_ERROR)\n        return JS_ThrowOutOfMemory(ctx);\n    if (status & BF_ST_DIVIDE_ZERO) {\n        str = \"division by zero\";\n    } else if (status & BF_ST_INVALID_OP) {\n        str = \"invalid operation\";\n    } else {\n        str = \"integer overflow\";\n    }\n    return JS_ThrowRangeError(ctx, \"%s\", str);\n}\n\nstatic int js_unary_arith_bigint(JSContext *ctx,\n                                 JSValue *pres, OPCodeEnum op, JSValue op1)\n{\n    bf_t a_s, *r, *a;\n    int ret, v;\n    JSValue res;\n    \n    if (op == OP_plus && !is_math_mode(ctx)) {\n        JS_ThrowTypeError(ctx, \"bigint argument with unary +\");\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n    res = JS_NewBigInt(ctx);\n    if (JS_IsException(res)) {\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n    r = JS_GetBigInt(res);\n    a = JS_ToBigInt(ctx, &a_s, op1);\n    ret = 0;\n    switch(op) {\n    case OP_inc:\n    case OP_dec:\n        v = 2 * (op - OP_dec) - 1;\n        ret = bf_add_si(r, a, v, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_plus:\n        ret = bf_set(r, a);\n        break;\n    case OP_neg:\n        ret = bf_set(r, a);\n        bf_neg(r);\n        break;\n    case OP_not:\n        ret = bf_add_si(r, a, 1, BF_PREC_INF, BF_RNDZ);\n        bf_neg(r);\n        break;\n    default:\n        abort();\n    }\n    JS_FreeBigInt(ctx, a, &a_s);\n    JS_FreeValue(ctx, op1);\n    if (unlikely(ret)) {\n        JS_FreeValue(ctx, res);\n        throw_bf_exception(ctx, ret);\n        return -1;\n    }\n    res = JS_CompactBigInt(ctx, res);\n    *pres = res;\n    return 0;\n}\n\nstatic int js_unary_arith_bigfloat(JSContext *ctx,\n                                   JSValue *pres, OPCodeEnum op, JSValue op1)\n{\n    bf_t a_s, *r, *a;\n    int ret, v;\n    JSValue res;\n    \n    if (op == OP_plus && !is_math_mode(ctx)) {\n        JS_ThrowTypeError(ctx, \"bigfloat argument with unary +\");\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n\n    res = JS_NewBigFloat(ctx);\n    if (JS_IsException(res)) {\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n    r = JS_GetBigFloat(res);\n    a = JS_ToBigFloat(ctx, &a_s, op1);\n    ret = 0;\n    switch(op) {\n    case OP_inc:\n    case OP_dec:\n        v = 2 * (op - OP_dec) - 1;\n        ret = bf_add_si(r, a, v, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case OP_plus:\n        ret = bf_set(r, a);\n        break;\n    case OP_neg:\n        ret = bf_set(r, a);\n        bf_neg(r);\n        break;\n    default:\n        abort();\n    }\n    if (a == &a_s)\n        bf_delete(a);\n    JS_FreeValue(ctx, op1);\n    if (unlikely(ret & BF_ST_MEM_ERROR)) {\n        JS_FreeValue(ctx, res);\n        throw_bf_exception(ctx, ret);\n        return -1;\n    }\n    *pres = res;\n    return 0;\n}\n\nstatic int js_unary_arith_bigdecimal(JSContext *ctx,\n                                     JSValue *pres, OPCodeEnum op, JSValue op1)\n{\n    bfdec_t *r, *a;\n    int ret, v;\n    JSValue res;\n    \n    if (op == OP_plus && !is_math_mode(ctx)) {\n        JS_ThrowTypeError(ctx, \"bigdecimal argument with unary +\");\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n\n    res = JS_NewBigDecimal(ctx);\n    if (JS_IsException(res)) {\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n    r = JS_GetBigDecimal(res);\n    a = JS_ToBigDecimal(ctx, op1);\n    ret = 0;\n    switch(op) {\n    case OP_inc:\n    case OP_dec:\n        v = 2 * (op - OP_dec) - 1;\n        ret = bfdec_add_si(r, a, v, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_plus:\n        ret = bfdec_set(r, a);\n        break;\n    case OP_neg:\n        ret = bfdec_set(r, a);\n        bfdec_neg(r);\n        break;\n    default:\n        abort();\n    }\n    JS_FreeValue(ctx, op1);\n    if (unlikely(ret)) {\n        JS_FreeValue(ctx, res);\n        throw_bf_exception(ctx, ret);\n        return -1;\n    }\n    *pres = res;\n    return 0;\n}\n\nstatic no_inline __exception int js_unary_arith_slow(JSContext *ctx,\n                                                     JSValue *sp,\n                                                     OPCodeEnum op)\n{\n    JSValue op1, val;\n    int v, ret;\n    uint32_t tag;\n\n    op1 = sp[-1];\n    /* fast path for float64 */\n    if (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(op1)))\n        goto handle_float64;\n    if (JS_IsObject(op1)) {\n        ret = js_call_unary_op_fallback(ctx, &val, op1, op);\n        if (ret < 0)\n            return -1;\n        if (ret) {\n            JS_FreeValue(ctx, op1);\n            sp[-1] = val;\n            return 0;\n        }\n    }\n\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1))\n        goto exception;\n    tag = JS_VALUE_GET_TAG(op1);\n    switch(tag) {\n    case JS_TAG_INT:\n        {\n            int64_t v64;\n            v64 = JS_VALUE_GET_INT(op1);\n            switch(op) {\n            case OP_inc:\n            case OP_dec:\n                v = 2 * (op - OP_dec) - 1;\n                v64 += v;\n                break;\n            case OP_plus:\n                break;\n            case OP_neg:\n                if (v64 == 0) {\n                    sp[-1] = __JS_NewFloat64(ctx, -0.0);\n                    return 0;\n                } else {\n                    v64 = -v64;\n                }\n                break;\n            default:\n                abort();\n            }\n            sp[-1] = JS_NewInt64(ctx, v64);\n        }\n        break;\n    case JS_TAG_BIG_INT:\n    handle_bigint:\n        if (ctx->rt->bigint_ops.unary_arith(ctx, sp - 1, op, op1))\n            goto exception;\n        break;\n    case JS_TAG_BIG_FLOAT:\n        if (ctx->rt->bigfloat_ops.unary_arith(ctx, sp - 1, op, op1))\n            goto exception;\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        if (ctx->rt->bigdecimal_ops.unary_arith(ctx, sp - 1, op, op1))\n            goto exception;\n        break;\n    default:\n    handle_float64:\n        {\n            double d;\n            if (is_math_mode(ctx))\n                goto handle_bigint;\n            d = JS_VALUE_GET_FLOAT64(op1);\n            switch(op) {\n            case OP_inc:\n            case OP_dec:\n                v = 2 * (op - OP_dec) - 1;\n                d += v;\n                break;\n            case OP_plus:\n                break;\n            case OP_neg:\n                d = -d;\n                break;\n            default:\n                abort();\n            }\n            sp[-1] = __JS_NewFloat64(ctx, d);\n        }\n        break;\n    }\n    return 0;\n exception:\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic __exception int js_post_inc_slow(JSContext *ctx,\n                                        JSValue *sp, OPCodeEnum op)\n{\n    JSValue op1;\n\n    /* XXX: allow custom operators */\n    op1 = sp[-1];\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1)) {\n        sp[-1] = JS_UNDEFINED;\n        return -1;\n    }\n    sp[-1] = op1;\n    sp[0] = JS_DupValue(ctx, op1);\n    return js_unary_arith_slow(ctx, sp + 1, op - OP_post_dec + OP_dec);\n}\n\nstatic no_inline int js_not_slow(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, val;\n    int ret;\n    \n    op1 = sp[-1];\n    if (JS_IsObject(op1)) {\n        ret = js_call_unary_op_fallback(ctx, &val, op1, OP_not);\n        if (ret < 0)\n            return -1;\n        if (ret) {\n            JS_FreeValue(ctx, op1);\n            sp[-1] = val;\n            return 0;\n        }\n    }\n\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1))\n        goto exception;\n    if (is_math_mode(ctx) || JS_VALUE_GET_TAG(op1) == JS_TAG_BIG_INT) {\n        if (ctx->rt->bigint_ops.unary_arith(ctx, sp - 1, OP_not, op1))\n            goto exception;\n    } else {\n        int32_t v1;\n        if (unlikely(JS_ToInt32Free(ctx, &v1, op1)))\n            goto exception;\n        sp[-1] = JS_NewInt32(ctx, ~v1);\n    }\n    return 0;\n exception:\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic int js_binary_arith_bigfloat(JSContext *ctx, OPCodeEnum op,\n                                    JSValue *pres, JSValue op1, JSValue op2)\n{\n    bf_t a_s, b_s, *r, *a, *b;\n    int ret;\n    JSValue res;\n    \n    res = JS_NewBigFloat(ctx);\n    if (JS_IsException(res)) {\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        return -1;\n    }\n    r = JS_GetBigFloat(res);\n    a = JS_ToBigFloat(ctx, &a_s, op1);\n    b = JS_ToBigFloat(ctx, &b_s, op2);\n    bf_init(ctx->bf_ctx, r);\n    switch(op) {\n    case OP_add:\n        ret = bf_add(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case OP_sub:\n        ret = bf_sub(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case OP_mul:\n        ret = bf_mul(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case OP_div:\n        ret = bf_div(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case OP_math_mod:\n        /* Euclidian remainder */\n        ret = bf_rem(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags,\n                     BF_DIVREM_EUCLIDIAN);\n        break;\n    case OP_mod:\n        ret = bf_rem(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags,\n                     BF_RNDZ);\n        break;\n    case OP_pow:\n        ret = bf_pow(r, a, b, ctx->fp_env.prec,\n                     ctx->fp_env.flags | BF_POW_JS_QUIRKS);\n        break;\n    default:\n        abort();\n    }\n    if (a == &a_s)\n        bf_delete(a);\n    if (b == &b_s)\n        bf_delete(b);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    if (unlikely(ret & BF_ST_MEM_ERROR)) {\n        JS_FreeValue(ctx, res);\n        throw_bf_exception(ctx, ret);\n        return -1;\n    }\n    *pres = res;\n    return 0;\n}\n\nstatic int js_binary_arith_bigint(JSContext *ctx, OPCodeEnum op,\n                                  JSValue *pres, JSValue op1, JSValue op2)\n{\n    bf_t a_s, b_s, *r, *a, *b;\n    int ret;\n    JSValue res;\n    \n    res = JS_NewBigInt(ctx);\n    if (JS_IsException(res))\n        goto fail;\n    a = JS_ToBigInt(ctx, &a_s, op1);\n    if (!a)\n        goto fail;\n    b = JS_ToBigInt(ctx, &b_s, op2);\n    if (!b) {\n        JS_FreeBigInt(ctx, a, &a_s);\n        goto fail;\n    }\n    r = JS_GetBigInt(res);\n    ret = 0;\n    switch(op) {\n    case OP_add:\n        ret = bf_add(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_sub:\n        ret = bf_sub(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_mul:\n        ret = bf_mul(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_div:\n        if (!is_math_mode(ctx)) {\n            bf_t rem_s, *rem = &rem_s;\n            bf_init(ctx->bf_ctx, rem);\n            ret = bf_divrem(r, rem, a, b, BF_PREC_INF, BF_RNDZ,\n                            BF_RNDZ);\n            bf_delete(rem);\n        } else {\n            goto math_mode_div_pow;\n        }\n        break;\n    case OP_math_mod:\n        /* Euclidian remainder */\n        ret = bf_rem(r, a, b, BF_PREC_INF, BF_RNDZ,\n                     BF_DIVREM_EUCLIDIAN) & BF_ST_INVALID_OP;\n        break;\n    case OP_mod:\n        ret = bf_rem(r, a, b, BF_PREC_INF, BF_RNDZ,\n                     BF_RNDZ) & BF_ST_INVALID_OP;\n        break;\n    case OP_pow:\n        if (b->sign) {\n            if (!is_math_mode(ctx)) {\n                ret = BF_ST_INVALID_OP;\n            } else {\n            math_mode_div_pow:\n                JS_FreeValue(ctx, res);\n                ret = js_call_binary_op_simple(ctx, &res, ctx->class_proto[JS_CLASS_BIG_INT], op1, op2, op);\n                if (ret != 0) {\n                    JS_FreeBigInt(ctx, a, &a_s);\n                    JS_FreeBigInt(ctx, b, &b_s);\n                    JS_FreeValue(ctx, op1);\n                    JS_FreeValue(ctx, op2);\n                    if (ret < 0) {\n                        return -1;\n                    } else {\n                        *pres = res;\n                        return 0;\n                    }\n                }\n                /* if no BigInt power operator defined, return a\n                   bigfloat */\n                res = JS_NewBigFloat(ctx);\n                if (JS_IsException(res)) {\n                    JS_FreeBigInt(ctx, a, &a_s);\n                    JS_FreeBigInt(ctx, b, &b_s);\n                    goto fail;\n                }\n                r = JS_GetBigFloat(res);\n                if (op == OP_div) {\n                    ret = bf_div(r, a, b, ctx->fp_env.prec, ctx->fp_env.flags) & BF_ST_MEM_ERROR;\n                } else {\n                    ret = bf_pow(r, a, b, ctx->fp_env.prec,\n                                 ctx->fp_env.flags | BF_POW_JS_QUIRKS) & BF_ST_MEM_ERROR;\n                }\n                JS_FreeBigInt(ctx, a, &a_s);\n                JS_FreeBigInt(ctx, b, &b_s);\n                JS_FreeValue(ctx, op1);\n                JS_FreeValue(ctx, op2);\n                if (unlikely(ret)) {\n                    JS_FreeValue(ctx, res);\n                    throw_bf_exception(ctx, ret);\n                    return -1;\n                }\n                *pres = res;\n                return 0;\n            }\n        } else {\n            ret = bf_pow(r, a, b, BF_PREC_INF, BF_RNDZ | BF_POW_JS_QUIRKS);\n        }\n        break;\n\n        /* logical operations */\n    case OP_shl:\n    case OP_sar:\n        {\n            slimb_t v2;\n#if LIMB_BITS == 32\n            bf_get_int32(&v2, b, 0);\n            if (v2 == INT32_MIN)\n                v2 = INT32_MIN + 1;\n#else\n            bf_get_int64(&v2, b, 0);\n            if (v2 == INT64_MIN)\n                v2 = INT64_MIN + 1;\n#endif\n            if (op == OP_sar)\n                v2 = -v2;\n            ret = bf_set(r, a);\n            ret |= bf_mul_2exp(r, v2, BF_PREC_INF, BF_RNDZ);\n            if (v2 < 0) {\n                ret |= bf_rint(r, BF_RNDD) & (BF_ST_OVERFLOW | BF_ST_MEM_ERROR);\n            }\n        }\n        break;\n    case OP_and:\n        ret = bf_logic_and(r, a, b);\n        break;\n    case OP_or:\n        ret = bf_logic_or(r, a, b);\n        break;\n    case OP_xor:\n        ret = bf_logic_xor(r, a, b);\n        break;\n    default:\n        abort();\n    }\n    JS_FreeBigInt(ctx, a, &a_s);\n    JS_FreeBigInt(ctx, b, &b_s);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    if (unlikely(ret)) {\n        JS_FreeValue(ctx, res);\n        throw_bf_exception(ctx, ret);\n        return -1;\n    }\n    *pres = JS_CompactBigInt(ctx, res);\n    return 0;\n fail:\n    JS_FreeValue(ctx, res);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    return -1;\n}\n\n/* b must be a positive integer */\nstatic int js_bfdec_pow(bfdec_t *r, const bfdec_t *a, const bfdec_t *b)\n{\n    bfdec_t b1;\n    int32_t b2;\n    int ret;\n\n    bfdec_init(b->ctx, &b1);\n    ret = bfdec_set(&b1, b);\n    if (ret) {\n        bfdec_delete(&b1);\n        return ret;\n    }\n    ret = bfdec_rint(&b1, BF_RNDZ);\n    if (ret) {\n        bfdec_delete(&b1);\n        return BF_ST_INVALID_OP; /* must be an integer */\n    }\n    ret = bfdec_get_int32(&b2, &b1);\n    bfdec_delete(&b1);\n    if (ret)\n        return ret; /* overflow */\n    if (b2 < 0)\n        return BF_ST_INVALID_OP; /* must be positive */\n    return bfdec_pow_ui(r, a, b2);\n}\n\nstatic int js_binary_arith_bigdecimal(JSContext *ctx, OPCodeEnum op,\n                                      JSValue *pres, JSValue op1, JSValue op2)\n{\n    bfdec_t *r, *a, *b;\n    int ret;\n    JSValue res;\n\n    res = JS_NewBigDecimal(ctx);\n    if (JS_IsException(res))\n        goto fail;\n    r = JS_GetBigDecimal(res);\n    \n    a = JS_ToBigDecimal(ctx, op1);\n    if (!a)\n        goto fail;\n    b = JS_ToBigDecimal(ctx, op2);\n    if (!b)\n        goto fail;\n    switch(op) {\n    case OP_add:\n        ret = bfdec_add(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_sub:\n        ret = bfdec_sub(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_mul:\n        ret = bfdec_mul(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_div:\n        ret = bfdec_div(r, a, b, BF_PREC_INF, BF_RNDZ);\n        break;\n    case OP_math_mod:\n        /* Euclidian remainder */\n        ret = bfdec_rem(r, a, b, BF_PREC_INF, BF_RNDZ, BF_DIVREM_EUCLIDIAN);\n        break;\n    case OP_mod:\n        ret = bfdec_rem(r, a, b, BF_PREC_INF, BF_RNDZ, BF_RNDZ);\n        break;\n    case OP_pow:\n        ret = js_bfdec_pow(r, a, b);\n        break;\n    default:\n        abort();\n    }\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    if (unlikely(ret)) {\n        JS_FreeValue(ctx, res);\n        throw_bf_exception(ctx, ret);\n        return -1;\n    }\n    *pres = res;\n    return 0;\n fail:\n    JS_FreeValue(ctx, res);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    return -1;\n}\n\nstatic no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *sp,\n                                                      OPCodeEnum op)\n{\n    JSValue op1, op2, res;\n    uint32_t tag1, tag2;\n    int ret;\n    double d1, d2;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    /* fast path for float operations */\n    if (tag1 == JS_TAG_FLOAT64 && tag2 == JS_TAG_FLOAT64) {\n        d1 = JS_VALUE_GET_FLOAT64(op1);\n        d2 = JS_VALUE_GET_FLOAT64(op2);\n        goto handle_float64;\n    }\n\n    /* try to call an overloaded operator */\n    if ((tag1 == JS_TAG_OBJECT &&\n         (tag2 != JS_TAG_NULL && tag2 != JS_TAG_UNDEFINED)) ||\n        (tag2 == JS_TAG_OBJECT &&\n         (tag1 != JS_TAG_NULL && tag1 != JS_TAG_UNDEFINED))) {\n        ret = js_call_binary_op_fallback(ctx, &res, op1, op2, op, TRUE, 0);\n        if (ret != 0) {\n            JS_FreeValue(ctx, op1);\n            JS_FreeValue(ctx, op2);\n            if (ret < 0) {\n                goto exception;\n            } else {\n                sp[-2] = res;\n                return 0;\n            }\n        }\n    }\n\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    op2 = JS_ToNumericFree(ctx, op2);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        goto exception;\n    }\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n\n    if (tag1 == JS_TAG_INT && tag2 == JS_TAG_INT) {\n        int32_t v1, v2;\n        int64_t v;\n        v1 = JS_VALUE_GET_INT(op1);\n        v2 = JS_VALUE_GET_INT(op2);\n        switch(op) {\n        case OP_sub:\n            v = (int64_t)v1 - (int64_t)v2;\n            break;\n        case OP_mul:\n            v = (int64_t)v1 * (int64_t)v2;\n            if (is_math_mode(ctx) &&\n                (v < -MAX_SAFE_INTEGER || v > MAX_SAFE_INTEGER))\n                goto handle_bigint;\n            if (v == 0 && (v1 | v2) < 0) {\n                sp[-2] = __JS_NewFloat64(ctx, -0.0);\n                return 0;\n            }\n            break;\n        case OP_div:\n            if (is_math_mode(ctx))\n                goto handle_bigint;\n            sp[-2] = __JS_NewFloat64(ctx, (double)v1 / (double)v2);\n            return 0;\n        case OP_math_mod:\n            if (unlikely(v2 == 0)) {\n                throw_bf_exception(ctx, BF_ST_DIVIDE_ZERO);\n                goto exception;\n            }\n            v = (int64_t)v1 % (int64_t)v2;\n            if (v < 0) {\n                if (v2 < 0)\n                    v -= v2;\n                else\n                    v += v2;\n            }\n            break;\n        case OP_mod:\n            if (v1 < 0 || v2 <= 0) {\n                sp[-2] = JS_NewFloat64(ctx, fmod(v1, v2));\n                return 0;\n            } else {\n                v = (int64_t)v1 % (int64_t)v2;\n            }\n            break;\n        case OP_pow:\n            if (!is_math_mode(ctx)) {\n                sp[-2] = JS_NewFloat64(ctx, js_pow(v1, v2));\n                return 0;\n            } else {\n                goto handle_bigint;\n            }\n            break;\n        default:\n            abort();\n        }\n        sp[-2] = JS_NewInt64(ctx, v);\n    } else if (tag1 == JS_TAG_BIG_DECIMAL || tag2 == JS_TAG_BIG_DECIMAL) {\n        if (ctx->rt->bigdecimal_ops.binary_arith(ctx, op, sp - 2, op1, op2))\n            goto exception;\n    } else if (tag1 == JS_TAG_BIG_FLOAT || tag2 == JS_TAG_BIG_FLOAT) {\n        if (ctx->rt->bigfloat_ops.binary_arith(ctx, op, sp - 2, op1, op2))\n            goto exception;\n    } else if (tag1 == JS_TAG_BIG_INT || tag2 == JS_TAG_BIG_INT) {\n    handle_bigint:\n        if (ctx->rt->bigint_ops.binary_arith(ctx, op, sp - 2, op1, op2))\n            goto exception;\n    } else {\n        double dr;\n        /* float64 result */\n        if (JS_ToFloat64Free(ctx, &d1, op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        if (JS_ToFloat64Free(ctx, &d2, op2))\n            goto exception;\n    handle_float64:\n        if (is_math_mode(ctx) && is_safe_integer(d1) && is_safe_integer(d2))\n            goto handle_bigint;\n        switch(op) {\n        case OP_sub:\n            dr = d1 - d2;\n            break;\n        case OP_mul:\n            dr = d1 * d2;\n            break;\n        case OP_div:\n            dr = d1 / d2;\n            break;\n        case OP_mod:\n            dr = fmod(d1, d2);\n            break;\n        case OP_math_mod:\n            d2 = fabs(d2);\n            dr = fmod(d1, d2);\n            /* XXX: loss of accuracy if dr < 0 */\n            if (dr < 0)\n                dr += d2;\n            break;\n        case OP_pow:\n            dr = js_pow(d1, d2);\n            break;\n        default:\n            abort();\n        }\n        sp[-2] = __JS_NewFloat64(ctx, dr);\n    }\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2, res;\n    uint32_t tag1, tag2;\n    int ret;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    /* fast path for float64 */\n    if (tag1 == JS_TAG_FLOAT64 && tag2 == JS_TAG_FLOAT64) {\n        double d1, d2;\n        d1 = JS_VALUE_GET_FLOAT64(op1);\n        d2 = JS_VALUE_GET_FLOAT64(op2);\n        sp[-2] = __JS_NewFloat64(ctx, d1 + d2);\n        return 0;\n    }\n\n    if (tag1 == JS_TAG_OBJECT || tag2 == JS_TAG_OBJECT) {\n        /* try to call an overloaded operator */\n        if ((tag1 == JS_TAG_OBJECT &&\n             (tag2 != JS_TAG_NULL && tag2 != JS_TAG_UNDEFINED &&\n              tag2 != JS_TAG_STRING)) ||\n            (tag2 == JS_TAG_OBJECT &&\n             (tag1 != JS_TAG_NULL && tag1 != JS_TAG_UNDEFINED &&\n              tag1 != JS_TAG_STRING))) {\n            ret = js_call_binary_op_fallback(ctx, &res, op1, op2, OP_add,\n                                             FALSE, HINT_NONE);\n            if (ret != 0) {\n                JS_FreeValue(ctx, op1);\n                JS_FreeValue(ctx, op2);\n                if (ret < 0) {\n                    goto exception;\n                } else {\n                    sp[-2] = res;\n                    return 0;\n                }\n            }\n        }\n\n        op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE);\n        if (JS_IsException(op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n\n        op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NONE);\n        if (JS_IsException(op2)) {\n            JS_FreeValue(ctx, op1);\n            goto exception;\n        }\n        tag1 = JS_VALUE_GET_NORM_TAG(op1);\n        tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    }\n\n    if (tag1 == JS_TAG_STRING || tag2 == JS_TAG_STRING) {\n        sp[-2] = JS_ConcatString(ctx, op1, op2);\n        if (JS_IsException(sp[-2]))\n            goto exception;\n        return 0;\n    }\n\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    op2 = JS_ToNumericFree(ctx, op2);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        goto exception;\n    }\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n\n    if (tag1 == JS_TAG_INT && tag2 == JS_TAG_INT) {\n        int32_t v1, v2;\n        int64_t v;\n        v1 = JS_VALUE_GET_INT(op1);\n        v2 = JS_VALUE_GET_INT(op2);\n        v = (int64_t)v1 + (int64_t)v2;\n        sp[-2] = JS_NewInt64(ctx, v);\n    } else if (tag1 == JS_TAG_BIG_DECIMAL || tag2 == JS_TAG_BIG_DECIMAL) {\n        if (ctx->rt->bigdecimal_ops.binary_arith(ctx, OP_add, sp - 2, op1, op2))\n            goto exception;\n    } else if (tag1 == JS_TAG_BIG_FLOAT || tag2 == JS_TAG_BIG_FLOAT) {\n        if (ctx->rt->bigfloat_ops.binary_arith(ctx, OP_add, sp - 2, op1, op2))\n            goto exception;\n    } else if (tag1 == JS_TAG_BIG_INT || tag2 == JS_TAG_BIG_INT) {\n    handle_bigint:\n        if (ctx->rt->bigint_ops.binary_arith(ctx, OP_add, sp - 2, op1, op2))\n            goto exception;\n    } else {\n        double d1, d2;\n        /* float64 result */\n        if (JS_ToFloat64Free(ctx, &d1, op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        if (JS_ToFloat64Free(ctx, &d2, op2))\n            goto exception;\n        if (is_math_mode(ctx) && is_safe_integer(d1) && is_safe_integer(d2))\n            goto handle_bigint;\n        sp[-2] = __JS_NewFloat64(ctx, d1 + d2);\n    }\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline __exception int js_binary_logic_slow(JSContext *ctx,\n                                                      JSValue *sp,\n                                                      OPCodeEnum op)\n{\n    JSValue op1, op2, res;\n    int ret;\n    uint32_t tag1, tag2;\n    uint32_t v1, v2, r;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n\n    /* try to call an overloaded operator */\n    if ((tag1 == JS_TAG_OBJECT &&\n         (tag2 != JS_TAG_NULL && tag2 != JS_TAG_UNDEFINED)) ||\n        (tag2 == JS_TAG_OBJECT &&\n         (tag1 != JS_TAG_NULL && tag1 != JS_TAG_UNDEFINED))) {\n        ret = js_call_binary_op_fallback(ctx, &res, op1, op2, op, TRUE, 0);\n        if (ret != 0) {\n            JS_FreeValue(ctx, op1);\n            JS_FreeValue(ctx, op2);\n            if (ret < 0) {\n                goto exception;\n            } else {\n                sp[-2] = res;\n                return 0;\n            }\n        }\n    }\n\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    op2 = JS_ToNumericFree(ctx, op2);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        goto exception;\n    }\n\n    if (is_math_mode(ctx))\n        goto bigint_op;\n\n    tag1 = JS_VALUE_GET_TAG(op1);\n    tag2 = JS_VALUE_GET_TAG(op2);\n    if (tag1 == JS_TAG_BIG_INT || tag2 == JS_TAG_BIG_INT) {\n        if (tag1 != tag2) {\n            JS_FreeValue(ctx, op1);\n            JS_FreeValue(ctx, op2);\n            JS_ThrowTypeError(ctx, \"both operands must be bigint\");\n            goto exception;\n        } else {\n        bigint_op:\n            if (ctx->rt->bigint_ops.binary_arith(ctx, op, sp - 2, op1, op2))\n                goto exception;\n        }\n    } else {\n        if (unlikely(JS_ToInt32Free(ctx, (int32_t *)&v1, op1))) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        if (unlikely(JS_ToInt32Free(ctx, (int32_t *)&v2, op2)))\n            goto exception;\n        switch(op) {\n        case OP_shl:\n            r = v1 << (v2 & 0x1f);\n            break;\n        case OP_sar:\n            r = (int)v1 >> (v2 & 0x1f);\n            break;\n        case OP_and:\n            r = v1 & v2;\n            break;\n        case OP_or:\n            r = v1 | v2;\n            break;\n        case OP_xor:\n            r = v1 ^ v2;\n            break;\n        default:\n            abort();\n        }\n        sp[-2] = JS_NewInt32(ctx, r);\n    }\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\n/* Note: also used for bigint */\nstatic int js_compare_bigfloat(JSContext *ctx, OPCodeEnum op,\n                               JSValue op1, JSValue op2)\n{\n    bf_t a_s, b_s, *a, *b;\n    int res;\n    \n    a = JS_ToBigFloat(ctx, &a_s, op1);\n    if (!a) {\n        JS_FreeValue(ctx, op2);\n        return -1;\n    }\n    b = JS_ToBigFloat(ctx, &b_s, op2);\n    if (!b) {\n        if (a == &a_s)\n            bf_delete(a);\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n    switch(op) {\n    case OP_lt:\n        res = bf_cmp_lt(a, b); /* if NaN return false */\n        break;\n    case OP_lte:\n        res = bf_cmp_le(a, b); /* if NaN return false */\n        break;\n    case OP_gt:\n        res = bf_cmp_lt(b, a); /* if NaN return false */\n        break;\n    case OP_gte:\n        res = bf_cmp_le(b, a); /* if NaN return false */\n        break;\n    case OP_eq:\n        res = bf_cmp_eq(a, b); /* if NaN return false */\n        break;\n    default:\n        abort();\n    }\n    if (a == &a_s)\n        bf_delete(a);\n    if (b == &b_s)\n        bf_delete(b);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    return res;\n}\n\nstatic int js_compare_bigdecimal(JSContext *ctx, OPCodeEnum op,\n                                 JSValue op1, JSValue op2)\n{\n    bfdec_t *a, *b;\n    int res;\n\n    /* Note: binary floats are converted to bigdecimal with\n       toString(). It is not mathematically correct but is consistent\n       with the BigDecimal() constructor behavior */\n    op1 = JS_ToBigDecimalFree(ctx, op1, TRUE);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        return -1;\n    }\n    op2 = JS_ToBigDecimalFree(ctx, op2, TRUE);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        return -1;\n    }\n    a = JS_ToBigDecimal(ctx, op1);\n    b = JS_ToBigDecimal(ctx, op2);\n    \n    switch(op) {\n    case OP_lt:\n        res = bfdec_cmp_lt(a, b); /* if NaN return false */\n        break;\n    case OP_lte:\n        res = bfdec_cmp_le(a, b); /* if NaN return false */\n        break;\n    case OP_gt:\n        res = bfdec_cmp_lt(b, a); /* if NaN return false */\n        break;\n    case OP_gte:\n        res = bfdec_cmp_le(b, a); /* if NaN return false */\n        break;\n    case OP_eq:\n        res = bfdec_cmp_eq(a, b); /* if NaN return false */\n        break;\n    default:\n        abort();\n    }\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    return res;\n}\n\nstatic no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,\n                                        OPCodeEnum op)\n{\n    JSValue op1, op2, ret;\n    int res;\n    uint32_t tag1, tag2;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    /* try to call an overloaded operator */\n    if ((tag1 == JS_TAG_OBJECT &&\n         (tag2 != JS_TAG_NULL && tag2 != JS_TAG_UNDEFINED)) ||\n        (tag2 == JS_TAG_OBJECT &&\n         (tag1 != JS_TAG_NULL && tag1 != JS_TAG_UNDEFINED))) {\n        res = js_call_binary_op_fallback(ctx, &ret, op1, op2, op,\n                                         FALSE, HINT_NUMBER);\n        if (res != 0) {\n            JS_FreeValue(ctx, op1);\n            JS_FreeValue(ctx, op2);\n            if (res < 0) {\n                goto exception;\n            } else {\n                sp[-2] = ret;\n                return 0;\n            }\n        }\n    }\n    op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NUMBER);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NUMBER);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        goto exception;\n    }\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n\n    if (tag1 == JS_TAG_STRING && tag2 == JS_TAG_STRING) {\n        JSString *p1, *p2;\n        p1 = JS_VALUE_GET_STRING(op1);\n        p2 = JS_VALUE_GET_STRING(op2);\n        res = js_string_compare(ctx, p1, p2);\n        switch(op) {\n        case OP_lt:\n            res = (res < 0);\n            break;\n        case OP_lte:\n            res = (res <= 0);\n            break;\n        case OP_gt:\n            res = (res > 0);\n            break;\n        default:\n        case OP_gte:\n            res = (res >= 0);\n            break;\n        }\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n    } else if ((tag1 <= JS_TAG_NULL || tag1 == JS_TAG_FLOAT64) &&\n               (tag2 <= JS_TAG_NULL || tag2 == JS_TAG_FLOAT64)) {\n        /* can use floating point comparison */\n        double d1, d2;\n        if (tag1 == JS_TAG_FLOAT64) {\n            d1 = JS_VALUE_GET_FLOAT64(op1);\n        } else {\n            d1 = JS_VALUE_GET_INT(op1);\n        }\n        if (tag2 == JS_TAG_FLOAT64) {\n            d2 = JS_VALUE_GET_FLOAT64(op2);\n        } else {\n            d2 = JS_VALUE_GET_INT(op2);\n        }\n        switch(op) {\n        case OP_lt:\n            res = (d1 < d2); /* if NaN return false */\n            break;\n        case OP_lte:\n            res = (d1 <= d2); /* if NaN return false */\n            break;\n        case OP_gt:\n            res = (d1 > d2); /* if NaN return false */\n            break;\n        default:\n        case OP_gte:\n            res = (d1 >= d2); /* if NaN return false */\n            break;\n        }\n    } else {\n        if (((tag1 == JS_TAG_BIG_INT && tag2 == JS_TAG_STRING) ||\n             (tag2 == JS_TAG_BIG_INT && tag1 == JS_TAG_STRING)) &&\n            !is_math_mode(ctx)) {\n            if (tag1 == JS_TAG_STRING) {\n                op1 = JS_StringToBigInt(ctx, op1);\n                if (JS_VALUE_GET_TAG(op1) != JS_TAG_BIG_INT)\n                    goto invalid_bigint_string;\n            }\n            if (tag2 == JS_TAG_STRING) {\n                op2 = JS_StringToBigInt(ctx, op2);\n                if (JS_VALUE_GET_TAG(op2) != JS_TAG_BIG_INT) {\n                invalid_bigint_string:\n                    JS_FreeValue(ctx, op1);\n                    JS_FreeValue(ctx, op2);\n                    res = FALSE;\n                    goto done;\n                }\n            }\n        } else {\n            op1 = JS_ToNumericFree(ctx, op1);\n            if (JS_IsException(op1)) {\n                JS_FreeValue(ctx, op2);\n                goto exception;\n            }\n            op2 = JS_ToNumericFree(ctx, op2);\n            if (JS_IsException(op2)) {\n                JS_FreeValue(ctx, op1);\n                goto exception;\n            }\n        }\n\n        if (JS_VALUE_GET_TAG(op1) == JS_TAG_BIG_DECIMAL ||\n            JS_VALUE_GET_TAG(op2) == JS_TAG_BIG_DECIMAL) {\n            res = ctx->rt->bigdecimal_ops.compare(ctx, op, op1, op2);\n            if (res < 0)\n                goto exception;\n        } else if (JS_VALUE_GET_TAG(op1) == JS_TAG_BIG_FLOAT ||\n                   JS_VALUE_GET_TAG(op2) == JS_TAG_BIG_FLOAT) {\n            res = ctx->rt->bigfloat_ops.compare(ctx, op, op1, op2);\n            if (res < 0)\n                goto exception;\n        } else {\n            res = ctx->rt->bigint_ops.compare(ctx, op, op1, op2);\n            if (res < 0)\n                goto exception;\n        }\n    }\n done:\n    sp[-2] = JS_NewBool(ctx, res);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic BOOL tag_is_number(uint32_t tag)\n{\n    return (tag == JS_TAG_INT || tag == JS_TAG_BIG_INT ||\n            tag == JS_TAG_FLOAT64 || tag == JS_TAG_BIG_FLOAT ||\n            tag == JS_TAG_BIG_DECIMAL);\n}\n\nstatic no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,\n                                            BOOL is_neq)\n{\n    JSValue op1, op2, ret;\n    int res;\n    uint32_t tag1, tag2;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n redo:\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    if (tag_is_number(tag1) && tag_is_number(tag2)) {\n        if (tag1 == JS_TAG_INT && tag2 == JS_TAG_INT) {\n            res = JS_VALUE_GET_INT(op1) == JS_VALUE_GET_INT(op2);\n        } else if ((tag1 == JS_TAG_FLOAT64 &&\n                    (tag2 == JS_TAG_INT || tag2 == JS_TAG_FLOAT64)) ||\n                   (tag2 == JS_TAG_FLOAT64 &&\n                    (tag1 == JS_TAG_INT || tag1 == JS_TAG_FLOAT64))) {\n            double d1, d2;\n            if (tag1 == JS_TAG_FLOAT64) {\n                d1 = JS_VALUE_GET_FLOAT64(op1);\n            } else {\n                d1 = JS_VALUE_GET_INT(op1);\n            }\n            if (tag2 == JS_TAG_FLOAT64) {\n                d2 = JS_VALUE_GET_FLOAT64(op2);\n            } else {\n                d2 = JS_VALUE_GET_INT(op2);\n            }\n            res = (d1 == d2);\n        } else if (tag1 == JS_TAG_BIG_DECIMAL || tag2 == JS_TAG_BIG_DECIMAL) {\n            res = ctx->rt->bigdecimal_ops.compare(ctx, OP_eq, op1, op2);\n            if (res < 0)\n                goto exception;\n        } else if (tag1 == JS_TAG_BIG_FLOAT || tag2 == JS_TAG_BIG_FLOAT) {\n            res = ctx->rt->bigfloat_ops.compare(ctx, OP_eq, op1, op2);\n            if (res < 0)\n                goto exception;\n        } else {\n            res = ctx->rt->bigint_ops.compare(ctx, OP_eq, op1, op2);\n            if (res < 0)\n                goto exception;\n        }\n    } else if (tag1 == tag2) {\n        if (tag1 == JS_TAG_OBJECT) {\n            /* try the fallback operator */\n            res = js_call_binary_op_fallback(ctx, &ret, op1, op2,\n                                             is_neq ? OP_neq : OP_eq,\n                                             FALSE, HINT_NONE);\n            if (res != 0) {\n                JS_FreeValue(ctx, op1);\n                JS_FreeValue(ctx, op2);\n                if (res < 0) {\n                    goto exception;\n                } else {\n                    sp[-2] = ret;\n                    return 0;\n                }\n            }\n        }\n        res = js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT);\n    } else if ((tag1 == JS_TAG_NULL && tag2 == JS_TAG_UNDEFINED) ||\n               (tag2 == JS_TAG_NULL && tag1 == JS_TAG_UNDEFINED)) {\n        res = TRUE;\n    } else if ((tag1 == JS_TAG_STRING && tag_is_number(tag2)) ||\n               (tag2 == JS_TAG_STRING && tag_is_number(tag1))) {\n\n        if ((tag1 == JS_TAG_BIG_INT || tag2 == JS_TAG_BIG_INT) &&\n            !is_math_mode(ctx)) {\n            if (tag1 == JS_TAG_STRING) {\n                op1 = JS_StringToBigInt(ctx, op1);\n                if (JS_VALUE_GET_TAG(op1) != JS_TAG_BIG_INT)\n                    goto invalid_bigint_string;\n            }\n            if (tag2 == JS_TAG_STRING) {\n                op2 = JS_StringToBigInt(ctx, op2);\n                if (JS_VALUE_GET_TAG(op2) != JS_TAG_BIG_INT) {\n                invalid_bigint_string:\n                    JS_FreeValue(ctx, op1);\n                    JS_FreeValue(ctx, op2);\n                    res = FALSE;\n                    goto done;\n                }\n            }\n        } else {\n            op1 = JS_ToNumericFree(ctx, op1);\n            if (JS_IsException(op1)) {\n                JS_FreeValue(ctx, op2);\n                goto exception;\n            }\n            op2 = JS_ToNumericFree(ctx, op2);\n            if (JS_IsException(op2)) {\n                JS_FreeValue(ctx, op1);\n                goto exception;\n            }\n        }\n        res = js_strict_eq(ctx, op1, op2);\n    } else if (tag1 == JS_TAG_BOOL) {\n        op1 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op1));\n        goto redo;\n    } else if (tag2 == JS_TAG_BOOL) {\n        op2 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op2));\n        goto redo;\n    } else if ((tag1 == JS_TAG_OBJECT &&\n                (tag_is_number(tag2) || tag2 == JS_TAG_STRING || tag2 == JS_TAG_SYMBOL)) ||\n               (tag2 == JS_TAG_OBJECT &&\n                (tag_is_number(tag1) || tag1 == JS_TAG_STRING || tag1 == JS_TAG_SYMBOL))) {\n\n        /* try the fallback operator */\n        res = js_call_binary_op_fallback(ctx, &ret, op1, op2,\n                                         is_neq ? OP_neq : OP_eq,\n                                         FALSE, HINT_NONE);\n        if (res != 0) {\n            JS_FreeValue(ctx, op1);\n            JS_FreeValue(ctx, op2);\n            if (res < 0) {\n                goto exception;\n            } else {\n                sp[-2] = ret;\n                return 0;\n            }\n        }\n\n        op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE);\n        if (JS_IsException(op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NONE);\n        if (JS_IsException(op2)) {\n            JS_FreeValue(ctx, op1);\n            goto exception;\n        }\n        goto redo;\n    } else {\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        res = FALSE;\n    }\n done:\n    sp[-2] = JS_NewBool(ctx, res ^ is_neq);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline int js_shr_slow(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2;\n    uint32_t v1, v2, r;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    op1 = JS_ToNumericFree(ctx, op1);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    op2 = JS_ToNumericFree(ctx, op2);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        goto exception;\n    }\n    /* XXX: could forbid >>> in bignum mode */\n    if (!is_math_mode(ctx) &&\n        (JS_VALUE_GET_TAG(op1) == JS_TAG_BIG_INT ||\n         JS_VALUE_GET_TAG(op2) == JS_TAG_BIG_INT)) {\n        JS_ThrowTypeError(ctx, \"bigint operands are forbidden for >>>\");\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    /* cannot give an exception */\n    JS_ToUint32Free(ctx, &v1, op1);\n    JS_ToUint32Free(ctx, &v2, op2);\n    r = v1 >> (v2 & 0x1f);\n    sp[-2] = JS_NewUint32(ctx, r);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic JSValue js_mul_pow10_to_float64(JSContext *ctx, const bf_t *a,\n                                       int64_t exponent)\n{\n    bf_t r_s, *r = &r_s;\n    double d;\n    int ret;\n    \n    /* always convert to Float64 */\n    bf_init(ctx->bf_ctx, r);\n    ret = bf_mul_pow_radix(r, a, 10, exponent,\n                           53, bf_set_exp_bits(11) | BF_RNDN |\n                           BF_FLAG_SUBNORMAL);\n    bf_get_float64(r, &d, BF_RNDN);\n    bf_delete(r);\n    if (ret & BF_ST_MEM_ERROR)\n        return JS_ThrowOutOfMemory(ctx);\n    else\n        return __JS_NewFloat64(ctx, d);\n}\n\nstatic no_inline int js_mul_pow10(JSContext *ctx, JSValue *sp)\n{\n    bf_t a_s, *a, *r;\n    JSValue op1, op2, res;\n    int64_t e;\n    int ret;\n\n    res = JS_NewBigFloat(ctx);\n    if (JS_IsException(res))\n        return -1;\n    r = JS_GetBigFloat(res);\n    op1 = sp[-2];\n    op2 = sp[-1];\n    a = JS_ToBigFloat(ctx, &a_s, op1);\n    if (!a)\n        return -1;\n    if (JS_IsBigInt(ctx, op2)) {\n        ret = JS_ToBigInt64(ctx, &e, op2);\n    } else {\n        ret = JS_ToInt64(ctx, &e, op2);\n    }\n    if (ret) {\n        if (a == &a_s)\n            bf_delete(a);\n        JS_FreeValue(ctx, res);\n        return -1;\n    }\n\n    bf_mul_pow_radix(r, a, 10, e, ctx->fp_env.prec, ctx->fp_env.flags);\n    if (a == &a_s)\n        bf_delete(a);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    sp[-2] = res;\n    return 0;\n}\n\n#else /* !CONFIG_BIGNUM */\n\nstatic JSValue JS_ThrowUnsupportedBigint(JSContext *ctx)\n{\n    return JS_ThrowTypeError(ctx, \"bigint is not supported\");\n}\n\nJSValue JS_NewBigInt64(JSContext *ctx, int64_t v)\n{\n    return JS_ThrowUnsupportedBigint(ctx);\n}\n\nJSValue JS_NewBigUint64(JSContext *ctx, uint64_t v)\n{\n    return JS_ThrowUnsupportedBigint(ctx);\n}\n\nint JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val)\n{\n    JS_ThrowUnsupportedBigint(ctx);\n    *pres = 0;\n    return -1;\n}\n\nstatic no_inline __exception int js_unary_arith_slow(JSContext *ctx,\n                                                     JSValue *sp,\n                                                     OPCodeEnum op)\n{\n    JSValue op1;\n    double d;\n\n    op1 = sp[-1];\n    if (unlikely(JS_ToFloat64Free(ctx, &d, op1))) {\n        sp[-1] = JS_UNDEFINED;\n        return -1;\n    }\n    switch(op) {\n    case OP_inc:\n        d++;\n        break;\n    case OP_dec:\n        d--;\n        break;\n    case OP_plus:\n        break;\n    case OP_neg:\n        d = -d;\n        break;\n    default:\n        abort();\n    }\n    sp[-1] = JS_NewFloat64(ctx, d);\n    return 0;\n}\n\n/* specific case necessary for correct return value semantics */\nstatic __exception int js_post_inc_slow(JSContext *ctx,\n                                        JSValue *sp, OPCodeEnum op)\n{\n    JSValue op1;\n    double d, r;\n\n    op1 = sp[-1];\n    if (unlikely(JS_ToFloat64Free(ctx, &d, op1))) {\n        sp[-1] = JS_UNDEFINED;\n        return -1;\n    }\n    r = d + 2 * (op - OP_post_dec) - 1;\n    sp[0] = JS_NewFloat64(ctx, r);\n    sp[-1] = JS_NewFloat64(ctx, d);\n    return 0;\n}\n\nstatic no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *sp,\n                                                      OPCodeEnum op)\n{\n    JSValue op1, op2;\n    double d1, d2, r;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    if (unlikely(JS_ToFloat64Free(ctx, &d1, op1))) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    if (unlikely(JS_ToFloat64Free(ctx, &d2, op2))) {\n        goto exception;\n    }\n    switch(op) {\n    case OP_sub:\n        r = d1 - d2;\n        break;\n    case OP_mul:\n        r = d1 * d2;\n        break;\n    case OP_div:\n        r = d1 / d2;\n        break;\n    case OP_mod:\n        r = fmod(d1, d2);\n        break;\n    case OP_pow:\n        r = js_pow(d1, d2);\n        break;\n    default:\n        abort();\n    }\n    sp[-2] = JS_NewFloat64(ctx, r);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2;\n    uint32_t tag1, tag2;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    tag1 = JS_VALUE_GET_TAG(op1);\n    tag2 = JS_VALUE_GET_TAG(op2);\n    if ((tag1 == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag1)) &&\n        (tag2 == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag2))) {\n        goto add_numbers;\n    } else {\n        op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE);\n        if (JS_IsException(op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NONE);\n        if (JS_IsException(op2)) {\n            JS_FreeValue(ctx, op1);\n            goto exception;\n        }\n        tag1 = JS_VALUE_GET_TAG(op1);\n        tag2 = JS_VALUE_GET_TAG(op2);\n        if (tag1 == JS_TAG_STRING || tag2 == JS_TAG_STRING) {\n            sp[-2] = JS_ConcatString(ctx, op1, op2);\n            if (JS_IsException(sp[-2]))\n                goto exception;\n        } else {\n            double d1, d2;\n        add_numbers:\n            if (JS_ToFloat64Free(ctx, &d1, op1)) {\n                JS_FreeValue(ctx, op2);\n                goto exception;\n            }\n            if (JS_ToFloat64Free(ctx, &d2, op2))\n                goto exception;\n            sp[-2] = JS_NewFloat64(ctx, d1 + d2);\n        }\n    }\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline __exception int js_binary_logic_slow(JSContext *ctx,\n                                                      JSValue *sp,\n                                                      OPCodeEnum op)\n{\n    JSValue op1, op2;\n    uint32_t v1, v2, r;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    if (unlikely(JS_ToInt32Free(ctx, (int32_t *)&v1, op1))) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    if (unlikely(JS_ToInt32Free(ctx, (int32_t *)&v2, op2)))\n        goto exception;\n    switch(op) {\n    case OP_shl:\n        r = v1 << (v2 & 0x1f);\n        break;\n    case OP_sar:\n        r = (int)v1 >> (v2 & 0x1f);\n        break;\n    case OP_and:\n        r = v1 & v2;\n        break;\n    case OP_or:\n        r = v1 | v2;\n        break;\n    case OP_xor:\n        r = v1 ^ v2;\n        break;\n    default:\n        abort();\n    }\n    sp[-2] = JS_NewInt32(ctx, r);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline int js_not_slow(JSContext *ctx, JSValue *sp)\n{\n    int32_t v1;\n\n    if (unlikely(JS_ToInt32Free(ctx, &v1, sp[-1]))) {\n        sp[-1] = JS_UNDEFINED;\n        return -1;\n    }\n    sp[-1] = JS_NewInt32(ctx, ~v1);\n    return 0;\n}\n\nstatic no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,\n                                        OPCodeEnum op)\n{\n    JSValue op1, op2;\n    int res;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NUMBER);\n    if (JS_IsException(op1)) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NUMBER);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        goto exception;\n    }\n    if (JS_VALUE_GET_TAG(op1) == JS_TAG_STRING &&\n        JS_VALUE_GET_TAG(op2) == JS_TAG_STRING) {\n        JSString *p1, *p2;\n        p1 = JS_VALUE_GET_STRING(op1);\n        p2 = JS_VALUE_GET_STRING(op2);\n        res = js_string_compare(ctx, p1, p2);\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        switch(op) {\n        case OP_lt:\n            res = (res < 0);\n            break;\n        case OP_lte:\n            res = (res <= 0);\n            break;\n        case OP_gt:\n            res = (res > 0);\n            break;\n        default:\n        case OP_gte:\n            res = (res >= 0);\n            break;\n        }\n    } else {\n        double d1, d2;\n        if (JS_ToFloat64Free(ctx, &d1, op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        if (JS_ToFloat64Free(ctx, &d2, op2))\n            goto exception;\n        switch(op) {\n        case OP_lt:\n            res = (d1 < d2); /* if NaN return false */\n            break;\n        case OP_lte:\n            res = (d1 <= d2); /* if NaN return false */\n            break;\n        case OP_gt:\n            res = (d1 > d2); /* if NaN return false */\n            break;\n        default:\n        case OP_gte:\n            res = (d1 >= d2); /* if NaN return false */\n            break;\n        }\n    }\n    sp[-2] = JS_NewBool(ctx, res);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp,\n                                            BOOL is_neq)\n{\n    JSValue op1, op2;\n    int tag1, tag2;\n    BOOL res;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n redo:\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    if (tag1 == tag2 ||\n        (tag1 == JS_TAG_INT && tag2 == JS_TAG_FLOAT64) ||\n        (tag2 == JS_TAG_INT && tag1 == JS_TAG_FLOAT64)) {\n        res = js_strict_eq(ctx, op1, op2);\n    } else if ((tag1 == JS_TAG_NULL && tag2 == JS_TAG_UNDEFINED) ||\n               (tag2 == JS_TAG_NULL && tag1 == JS_TAG_UNDEFINED)) {\n        res = TRUE;\n    } else if ((tag1 == JS_TAG_STRING && (tag2 == JS_TAG_INT ||\n                                   tag2 == JS_TAG_FLOAT64)) ||\n        (tag2 == JS_TAG_STRING && (tag1 == JS_TAG_INT ||\n                                   tag1 == JS_TAG_FLOAT64))) {\n        double d1;\n        double d2;\n        if (JS_ToFloat64Free(ctx, &d1, op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        if (JS_ToFloat64Free(ctx, &d2, op2))\n            goto exception;\n        res = (d1 == d2);\n    } else if (tag1 == JS_TAG_BOOL) {\n        op1 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op1));\n        goto redo;\n    } else if (tag2 == JS_TAG_BOOL) {\n        op2 = JS_NewInt32(ctx, JS_VALUE_GET_INT(op2));\n        goto redo;\n    } else if (tag1 == JS_TAG_OBJECT &&\n               (tag2 == JS_TAG_INT || tag2 == JS_TAG_FLOAT64 || tag2 == JS_TAG_STRING || tag2 == JS_TAG_SYMBOL)) {\n        op1 = JS_ToPrimitiveFree(ctx, op1, HINT_NONE);\n        if (JS_IsException(op1)) {\n            JS_FreeValue(ctx, op2);\n            goto exception;\n        }\n        goto redo;\n    } else if (tag2 == JS_TAG_OBJECT &&\n               (tag1 == JS_TAG_INT || tag1 == JS_TAG_FLOAT64 || tag1 == JS_TAG_STRING || tag1 == JS_TAG_SYMBOL)) {\n        op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NONE);\n        if (JS_IsException(op2)) {\n            JS_FreeValue(ctx, op1);\n            goto exception;\n        }\n        goto redo;\n    } else {\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        res = FALSE;\n    }\n    sp[-2] = JS_NewBool(ctx, res ^ is_neq);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic no_inline int js_shr_slow(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2;\n    uint32_t v1, v2, r;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    if (unlikely(JS_ToUint32Free(ctx, &v1, op1))) {\n        JS_FreeValue(ctx, op2);\n        goto exception;\n    }\n    if (unlikely(JS_ToUint32Free(ctx, &v2, op2)))\n        goto exception;\n    r = v1 >> (v2 & 0x1f);\n    sp[-2] = JS_NewUint32(ctx, r);\n    return 0;\n exception:\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\n#endif /* !CONFIG_BIGNUM */\n\n/* XXX: Should take JSValueConst arguments */\nstatic BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,\n                          JSStrictEqModeEnum eq_mode)\n{\n    BOOL res;\n    int tag1, tag2;\n    double d1, d2;\n\n    tag1 = JS_VALUE_GET_NORM_TAG(op1);\n    tag2 = JS_VALUE_GET_NORM_TAG(op2);\n    switch(tag1) {\n    case JS_TAG_BOOL:\n        if (tag1 != tag2) {\n            res = FALSE;\n        } else {\n            res = JS_VALUE_GET_INT(op1) == JS_VALUE_GET_INT(op2);\n            goto done_no_free;\n        }\n        break;\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        res = (tag1 == tag2);\n        break;\n    case JS_TAG_STRING:\n        {\n            JSString *p1, *p2;\n            if (tag1 != tag2) {\n                res = FALSE;\n            } else {\n                p1 = JS_VALUE_GET_STRING(op1);\n                p2 = JS_VALUE_GET_STRING(op2);\n                res = (js_string_compare(ctx, p1, p2) == 0);\n            }\n        }\n        break;\n    case JS_TAG_SYMBOL:\n        {\n            JSAtomStruct *p1, *p2;\n            if (tag1 != tag2) {\n                res = FALSE;\n            } else {\n                p1 = JS_VALUE_GET_PTR(op1);\n                p2 = JS_VALUE_GET_PTR(op2);\n                res = (p1 == p2);\n            }\n        }\n        break;\n    case JS_TAG_OBJECT:\n        if (tag1 != tag2)\n            res = FALSE;\n        else\n            res = JS_VALUE_GET_OBJ(op1) == JS_VALUE_GET_OBJ(op2);\n        break;\n    case JS_TAG_INT:\n        d1 = JS_VALUE_GET_INT(op1);\n        if (tag2 == JS_TAG_INT) {\n            d2 = JS_VALUE_GET_INT(op2);\n            goto number_test;\n        } else if (tag2 == JS_TAG_FLOAT64) {\n            d2 = JS_VALUE_GET_FLOAT64(op2);\n            goto number_test;\n        } else {\n            res = FALSE;\n        }\n        break;\n    case JS_TAG_FLOAT64:\n        d1 = JS_VALUE_GET_FLOAT64(op1);\n        if (tag2 == JS_TAG_FLOAT64) {\n            d2 = JS_VALUE_GET_FLOAT64(op2);\n        } else if (tag2 == JS_TAG_INT) {\n            d2 = JS_VALUE_GET_INT(op2);\n        } else {\n            res = FALSE;\n            break;\n        }\n    number_test:\n        if (unlikely(eq_mode >= JS_EQ_SAME_VALUE)) {\n            JSFloat64Union u1, u2;\n            /* NaN is not always normalized, so this test is necessary */\n            if (isnan(d1) || isnan(d2)) {\n                res = isnan(d1) == isnan(d2);\n            } else if (eq_mode == JS_EQ_SAME_VALUE_ZERO) {\n                res = (d1 == d2); /* +0 == -0 */\n            } else {\n                u1.d = d1;\n                u2.d = d2;\n                res = (u1.u64 == u2.u64); /* +0 != -0 */\n            }\n        } else {\n            res = (d1 == d2); /* if NaN return false and +0 == -0 */\n        }\n        goto done_no_free;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        {\n            bf_t a_s, *a, b_s, *b;\n            if (tag1 != tag2) {\n                res = FALSE;\n                break;\n            }\n            a = JS_ToBigFloat(ctx, &a_s, op1);\n            b = JS_ToBigFloat(ctx, &b_s, op2);\n            res = bf_cmp_eq(a, b);\n            if (a == &a_s)\n                bf_delete(a);\n            if (b == &b_s)\n                bf_delete(b);\n        }\n        break;\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p1, *p2;\n            const bf_t *a, *b;\n            if (tag1 != tag2) {\n                res = FALSE;\n                break;\n            }\n            p1 = JS_VALUE_GET_PTR(op1);\n            p2 = JS_VALUE_GET_PTR(op2);\n            a = &p1->num;\n            b = &p2->num;\n            if (unlikely(eq_mode >= JS_EQ_SAME_VALUE)) {\n                if (eq_mode == JS_EQ_SAME_VALUE_ZERO &&\n                           a->expn == BF_EXP_ZERO && b->expn == BF_EXP_ZERO) {\n                    res = TRUE;\n                } else {\n                    res = (bf_cmp_full(a, b) == 0);\n                }\n            } else {\n                res = bf_cmp_eq(a, b);\n            }\n        }\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        {\n            JSBigDecimal *p1, *p2;\n            const bfdec_t *a, *b;\n            if (tag1 != tag2) {\n                res = FALSE;\n                break;\n            }\n            p1 = JS_VALUE_GET_PTR(op1);\n            p2 = JS_VALUE_GET_PTR(op2);\n            a = &p1->num;\n            b = &p2->num;\n            res = bfdec_cmp_eq(a, b);\n        }\n        break;\n#endif\n    default:\n        res = FALSE;\n        break;\n    }\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n done_no_free:\n    return res;\n}\n\nstatic BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2)\n{\n    return js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT);\n}\n\nstatic BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2)\n{\n    return js_strict_eq2(ctx,\n                         JS_DupValue(ctx, op1), JS_DupValue(ctx, op2),\n                         JS_EQ_SAME_VALUE);\n}\n\nstatic BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2)\n{\n    return js_strict_eq2(ctx,\n                         JS_DupValue(ctx, op1), JS_DupValue(ctx, op2),\n                         JS_EQ_SAME_VALUE_ZERO);\n}\n\nstatic no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp,\n                                       BOOL is_neq)\n{\n    BOOL res;\n    res = js_strict_eq(ctx, sp[-2], sp[-1]);\n    sp[-2] = JS_NewBool(ctx, res ^ is_neq);\n    return 0;\n}\n\nstatic __exception int js_operator_in(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2;\n    JSAtom atom;\n    int ret;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n\n    if (JS_VALUE_GET_TAG(op2) != JS_TAG_OBJECT) {\n        JS_ThrowTypeError(ctx, \"invalid 'in' operand\");\n        return -1;\n    }\n    atom = JS_ValueToAtom(ctx, op1);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return -1;\n    ret = JS_HasProperty(ctx, op2, atom);\n    JS_FreeAtom(ctx, atom);\n    if (ret < 0)\n        return -1;\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    sp[-2] = JS_NewBool(ctx, ret);\n    return 0;\n}\n\nstatic __exception int js_has_unscopable(JSContext *ctx, JSValueConst obj,\n                                         JSAtom atom)\n{\n    JSValue arr, val;\n    int ret;\n\n    arr = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_unscopables);\n    if (JS_IsException(arr))\n        return -1;\n    ret = 0;\n    if (JS_IsObject(arr)) {\n        val = JS_GetProperty(ctx, arr, atom);\n        ret = JS_ToBoolFree(ctx, val);\n    }\n    JS_FreeValue(ctx, arr);\n    return ret;\n}\n\nstatic __exception int js_operator_instanceof(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2;\n    BOOL ret;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    ret = JS_IsInstanceOf(ctx, op1, op2);\n    if (ret < 0)\n        return ret;\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    sp[-2] = JS_NewBool(ctx, ret);\n    return 0;\n}\n\nstatic __exception int js_operator_typeof(JSContext *ctx, JSValue op1)\n{\n    JSAtom atom;\n    uint32_t tag;\n\n    tag = JS_VALUE_GET_NORM_TAG(op1);\n    switch(tag) {\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        atom = JS_ATOM_bigint;\n        break;\n    case JS_TAG_BIG_FLOAT:\n        atom = JS_ATOM_bigfloat;\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        atom = JS_ATOM_bigdecimal;\n        break;\n#endif\n    case JS_TAG_INT:\n    case JS_TAG_FLOAT64:\n        atom = JS_ATOM_number;\n        break;\n    case JS_TAG_UNDEFINED:\n        atom = JS_ATOM_undefined;\n        break;\n    case JS_TAG_BOOL:\n        atom = JS_ATOM_boolean;\n        break;\n    case JS_TAG_STRING:\n        atom = JS_ATOM_string;\n        break;\n    case JS_TAG_OBJECT:\n        if (JS_IsFunction(ctx, op1))\n            atom = JS_ATOM_function;\n        else\n            goto obj_type;\n        break;\n    case JS_TAG_NULL:\n    obj_type:\n        atom = JS_ATOM_object;\n        break;\n    case JS_TAG_SYMBOL:\n        atom = JS_ATOM_symbol;\n        break;\n    default:\n        atom = JS_ATOM_unknown;\n        break;\n    }\n    return atom;\n}\n\nstatic __exception int js_operator_delete(JSContext *ctx, JSValue *sp)\n{\n    JSValue op1, op2;\n    JSAtom atom;\n    int ret;\n\n    op1 = sp[-2];\n    op2 = sp[-1];\n    atom = JS_ValueToAtom(ctx, op2);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return -1;\n    ret = JS_DeleteProperty(ctx, op1, atom, JS_PROP_THROW_STRICT);\n    JS_FreeAtom(ctx, atom);\n    if (unlikely(ret < 0))\n        return -1;\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    sp[-2] = JS_NewBool(ctx, ret);\n    return 0;\n}\n\nstatic JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    return JS_ThrowTypeError(ctx, \"invalid property access\");\n}\n\n/* XXX: not 100% compatible, but mozilla seems to use a similar\n   implementation to ensure that caller in non strict mode does not\n   throw (ES5 compatibility) */\nstatic JSValue js_function_proto_caller(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);\n    if (!b || (b->js_mode & JS_MODE_STRICT) || !b->has_prototype) {\n        return js_throw_type_error(ctx, this_val, 0, NULL);\n    }\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_function_proto_fileName(JSContext *ctx,\n                                          JSValueConst this_val)\n{\n    JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);\n    if (b && b->has_debug) {\n        return JS_AtomToString(ctx, b->debug.filename);\n    }\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_function_proto_lineNumber(JSContext *ctx,\n                                            JSValueConst this_val)\n{\n    JSFunctionBytecode *b = JS_GetFunctionBytecode(this_val);\n    if (b && b->has_debug) {\n        return JS_NewInt32(ctx, b->debug.line_num);\n    }\n    return JS_UNDEFINED;\n}\n\nstatic int js_arguments_define_own_property(JSContext *ctx,\n                                            JSValueConst this_obj,\n                                            JSAtom prop, JSValueConst val,\n                                            JSValueConst getter, JSValueConst setter, int flags)\n{\n    JSObject *p;\n    uint32_t idx;\n    p = JS_VALUE_GET_OBJ(this_obj);\n    /* convert to normal array when redefining an existing numeric field */\n    if (p->fast_array && JS_AtomIsArrayIndex(ctx, &idx, prop) &&\n        idx < p->u.array.count) {\n        if (convert_fast_array_to_array(ctx, p))\n            return -1;\n    }\n    /* run the default define own property */\n    return JS_DefineProperty(ctx, this_obj, prop, val, getter, setter,\n                             flags | JS_PROP_NO_EXOTIC);\n}\n\nstatic const JSClassExoticMethods js_arguments_exotic_methods = {\n    .define_own_property = js_arguments_define_own_property,\n};\n\nstatic JSValue js_build_arguments(JSContext *ctx, int argc, JSValueConst *argv)\n{\n    JSValue val, *tab;\n    JSProperty *pr;\n    JSObject *p;\n    int i;\n\n    val = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                                 JS_CLASS_ARGUMENTS);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_OBJ(val);\n\n    /* add the length field (cannot fail) */\n    pr = add_property(ctx, p, JS_ATOM_length,\n                      JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    pr->u.value = JS_NewInt32(ctx, argc);\n\n    /* initialize the fast array part */\n    tab = NULL;\n    if (argc > 0) {\n        tab = js_malloc(ctx, sizeof(tab[0]) * argc);\n        if (!tab) {\n            JS_FreeValue(ctx, val);\n            return JS_EXCEPTION;\n        }\n        for(i = 0; i < argc; i++) {\n            tab[i] = JS_DupValue(ctx, argv[i]);\n        }\n    }\n    p->u.array.u.values = tab;\n    p->u.array.count = argc;\n\n    JS_DefinePropertyValue(ctx, val, JS_ATOM_Symbol_iterator,\n                           JS_DupValue(ctx, ctx->array_proto_values),\n                           JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE);\n    /* add callee property to throw a TypeError in strict mode */\n    JS_DefineProperty(ctx, val, JS_ATOM_callee, JS_UNDEFINED,\n                      ctx->throw_type_error, ctx->throw_type_error,\n                      JS_PROP_HAS_GET | JS_PROP_HAS_SET);\n    return val;\n}\n\n#define GLOBAL_VAR_OFFSET 0x40000000\n#define ARGUMENT_VAR_OFFSET 0x20000000\n\n/* legacy arguments object: add references to the function arguments */\nstatic JSValue js_build_mapped_arguments(JSContext *ctx, int argc,\n                                         JSValueConst *argv,\n                                         JSStackFrame *sf, int arg_count)\n{\n    JSValue val;\n    JSProperty *pr;\n    JSObject *p;\n    int i;\n\n    val = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                                 JS_CLASS_MAPPED_ARGUMENTS);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_OBJ(val);\n\n    /* add the length field (cannot fail) */\n    pr = add_property(ctx, p, JS_ATOM_length,\n                      JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    pr->u.value = JS_NewInt32(ctx, argc);\n\n    for(i = 0; i < arg_count; i++) {\n        JSVarRef *var_ref;\n        var_ref = get_var_ref(ctx, sf, i, TRUE);\n        if (!var_ref)\n            goto fail;\n        pr = add_property(ctx, p, __JS_AtomFromUInt32(i), JS_PROP_C_W_E | JS_PROP_VARREF);\n        if (!pr) {\n            free_var_ref(ctx->rt, var_ref);\n            goto fail;\n        }\n        pr->u.var_ref = var_ref;\n    }\n\n    /* the arguments not mapped to the arguments of the function can\n       be normal properties */\n    for(i = arg_count; i < argc; i++) {\n        if (JS_DefinePropertyValueUint32(ctx, val, i,\n                                         JS_DupValue(ctx, argv[i]),\n                                         JS_PROP_C_W_E) < 0)\n            goto fail;\n    }\n\n    JS_DefinePropertyValue(ctx, val, JS_ATOM_Symbol_iterator,\n                           JS_DupValue(ctx, ctx->array_proto_values),\n                           JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE);\n    /* callee returns this function in non strict mode */\n    JS_DefinePropertyValue(ctx, val, JS_ATOM_callee,\n                           JS_DupValue(ctx, ctx->rt->current_stack_frame->cur_func),\n                           JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE);\n    return val;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_build_rest(JSContext *ctx, int first, int argc, JSValueConst *argv)\n{\n    JSValue val;\n    int i, ret;\n\n    val = JS_NewArray(ctx);\n    if (JS_IsException(val))\n        return val;\n    for (i = first; i < argc; i++) {\n        ret = JS_DefinePropertyValueUint32(ctx, val, i - first,\n                                           JS_DupValue(ctx, argv[i]),\n                                           JS_PROP_C_W_E);\n        if (ret < 0) {\n            JS_FreeValue(ctx, val);\n            return JS_EXCEPTION;\n        }\n    }\n    return val;\n}\n\nstatic JSValue build_for_in_iterator(JSContext *ctx, JSValue obj)\n{\n    JSObject *p, *p1;\n    JSPropertyEnum *tab_atom;\n    int i;\n    JSValue enum_obj;\n    JSForInIterator *it;\n    uint32_t tag, tab_atom_count;\n\n    tag = JS_VALUE_GET_TAG(obj);\n    if (tag != JS_TAG_OBJECT && tag != JS_TAG_NULL && tag != JS_TAG_UNDEFINED) {\n        obj = JS_ToObjectFree(ctx, obj);\n    }\n\n    it = js_malloc(ctx, sizeof(*it));\n    if (!it) {\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    enum_obj = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_FOR_IN_ITERATOR);\n    if (JS_IsException(enum_obj)) {\n        js_free(ctx, it);\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    it->is_array = FALSE;\n    it->obj = obj;\n    it->idx = 0;\n    p = JS_VALUE_GET_OBJ(enum_obj);\n    p->u.for_in_iterator = it;\n\n    if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED)\n        return enum_obj;\n\n    p = JS_VALUE_GET_OBJ(obj);\n\n    /* fast path: assume no enumerable properties in the prototype chain */\n    p1 = p->shape->proto;\n    while (p1 != NULL) {\n        if (JS_GetOwnPropertyNamesInternal(ctx, &tab_atom, &tab_atom_count, p1,\n                                   JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY))\n            goto fail;\n        js_free_prop_enum(ctx, tab_atom, tab_atom_count);\n        if (tab_atom_count != 0) {\n            goto slow_path;\n        }\n        p1 = p1->shape->proto;\n    }\n    if (p->fast_array) {\n        JSShape *sh;\n        JSShapeProperty *prs;\n        /* check that there are no enumerable normal fields */\n        sh = p->shape;\n        for(i = 0, prs = get_shape_prop(sh); i < sh->prop_count; i++, prs++) {\n            if (prs->flags & JS_PROP_ENUMERABLE)\n                goto normal_case;\n        }\n        /* the implicit GetOwnProperty raises an exception if the\n           typed array is detached */\n        if ((p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n             p->class_id <= JS_CLASS_FLOAT64_ARRAY) &&\n            typed_array_is_detached(ctx, p) &&\n            typed_array_get_length(ctx, p) != 0) {\n            JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n            goto fail;\n        }\n        /* for fast arrays, we only store the number of elements */\n        it->is_array = TRUE;\n        it->array_length = p->u.array.count;\n    } else {\n    normal_case:\n        if (JS_GetOwnPropertyNamesInternal(ctx, &tab_atom, &tab_atom_count, p,\n                                   JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY))\n            goto fail;\n        for(i = 0; i < tab_atom_count; i++) {\n            JS_SetPropertyInternal(ctx, enum_obj, tab_atom[i].atom, JS_NULL, 0);\n        }\n        js_free_prop_enum(ctx, tab_atom, tab_atom_count);\n    }\n    return enum_obj;\n\n slow_path:\n    /* non enumerable properties hide the enumerables ones in the\n       prototype chain */\n    while (p != NULL) {\n        if (JS_GetOwnPropertyNamesInternal(ctx, &tab_atom, &tab_atom_count, p,\n                                   JS_GPN_STRING_MASK | JS_GPN_SET_ENUM))\n            goto fail;\n        for(i = 0; i < tab_atom_count; i++) {\n            JS_DefinePropertyValue(ctx, enum_obj, tab_atom[i].atom, JS_NULL,\n                                   (tab_atom[i].is_enumerable ?\n                                    JS_PROP_ENUMERABLE : 0));\n        }\n        js_free_prop_enum(ctx, tab_atom, tab_atom_count);\n        p = p->shape->proto;\n    }\n    return enum_obj;\n\n fail:\n    JS_FreeValue(ctx, enum_obj);\n    return JS_EXCEPTION;\n}\n\n/* obj -> enum_obj */\nstatic __exception int js_for_in_start(JSContext *ctx, JSValue *sp)\n{\n    sp[-1] = build_for_in_iterator(ctx, sp[-1]);\n    if (JS_IsException(sp[-1]))\n        return -1;\n    return 0;\n}\n\n/* enum_obj -> enum_obj value done */\nstatic __exception int js_for_in_next(JSContext *ctx, JSValue *sp)\n{\n    JSValueConst enum_obj;\n    JSObject *p;\n    JSAtom prop;\n    JSForInIterator *it;\n    int ret;\n\n    enum_obj = sp[-1];\n    /* fail safe */\n    if (JS_VALUE_GET_TAG(enum_obj) != JS_TAG_OBJECT)\n        goto done;\n    p = JS_VALUE_GET_OBJ(enum_obj);\n    if (p->class_id != JS_CLASS_FOR_IN_ITERATOR)\n        goto done;\n    it = p->u.for_in_iterator;\n\n    for(;;) {\n        if (it->is_array) {\n            if (it->idx >= it->array_length)\n                goto done;\n            prop = __JS_AtomFromUInt32(it->idx);\n            it->idx++;\n        } else {\n            JSShape *sh = p->shape;\n            JSShapeProperty *prs;\n            if (it->idx >= sh->prop_count)\n                goto done;\n            prs = get_shape_prop(sh) + it->idx;\n            prop = prs->atom;\n            it->idx++;\n            if (prop == JS_ATOM_NULL || !(prs->flags & JS_PROP_ENUMERABLE))\n                continue;\n        }\n        /* check if the property was deleted */\n        ret = JS_HasProperty(ctx, it->obj, prop);\n        if (ret < 0)\n            return ret;\n        if (ret)\n            break;\n    }\n    /* return the property */\n    sp[0] = JS_AtomToValue(ctx, prop);\n    sp[1] = JS_FALSE;\n    return 0;\n done:\n    /* return the end */\n    sp[0] = JS_UNDEFINED;\n    sp[1] = JS_TRUE;\n    return 0;\n}\n\nstatic JSValue JS_GetIterator2(JSContext *ctx, JSValueConst obj,\n                               JSValueConst method)\n{\n    JSValue enum_obj;\n\n    enum_obj = JS_Call(ctx, method, obj, 0, NULL);\n    if (JS_IsException(enum_obj))\n        return enum_obj;\n    if (!JS_IsObject(enum_obj)) {\n        JS_FreeValue(ctx, enum_obj);\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    }\n    return enum_obj;\n}\n\nstatic JSValue JS_GetIterator(JSContext *ctx, JSValueConst obj, BOOL is_async)\n{\n    JSValue method, ret, sync_iter;\n\n    if (is_async) {\n        method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_asyncIterator);\n        if (JS_IsException(method))\n            return method;\n        if (JS_IsUndefined(method) || JS_IsNull(method)) {\n            method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_iterator);\n            if (JS_IsException(method))\n                return method;\n            sync_iter = JS_GetIterator2(ctx, obj, method);\n            JS_FreeValue(ctx, method);\n            if (JS_IsException(sync_iter))\n                return sync_iter;\n            ret = JS_CreateAsyncFromSyncIterator(ctx, sync_iter);\n            JS_FreeValue(ctx, sync_iter);\n            return ret;\n        }\n    } else {\n        method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_iterator);\n        if (JS_IsException(method))\n            return method;\n    }\n    if (!JS_IsFunction(ctx, method)) {\n        JS_FreeValue(ctx, method);\n        return JS_ThrowTypeError(ctx, \"value is not iterable\");\n    }\n    ret = JS_GetIterator2(ctx, obj, method);\n    JS_FreeValue(ctx, method);\n    return ret;\n}\n\n/* return *pdone = 2 if the iterator object is not parsed */\nstatic JSValue JS_IteratorNext2(JSContext *ctx, JSValueConst enum_obj,\n                                JSValueConst method,\n                                int argc, JSValueConst *argv, int *pdone)\n{\n    JSValue obj;\n\n    /* fast path for the built-in iterators (avoid creating the\n       intermediate result object) */\n    if (JS_IsObject(method)) {\n        JSObject *p = JS_VALUE_GET_OBJ(method);\n        if (p->class_id == JS_CLASS_C_FUNCTION &&\n            p->u.cfunc.cproto == JS_CFUNC_iterator_next) {\n            JSCFunctionType func;\n            JSValueConst args[1];\n\n            /* in case the function expects one argument */\n            if (argc == 0) {\n                args[0] = JS_UNDEFINED;\n                argv = args;\n            }\n            func = p->u.cfunc.c_function;\n            return func.iterator_next(ctx, enum_obj, argc, argv,\n                                      pdone, p->u.cfunc.magic);\n        }\n    }\n    obj = JS_Call(ctx, method, enum_obj, argc, argv);\n    if (JS_IsException(obj))\n        goto fail;\n    if (!JS_IsObject(obj)) {\n        JS_FreeValue(ctx, obj);\n        JS_ThrowTypeError(ctx, \"iterator must return an object\");\n        goto fail;\n    }\n    *pdone = 2;\n    return obj;\n fail:\n    *pdone = FALSE;\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj,\n                               JSValueConst method,\n                               int argc, JSValueConst *argv, BOOL *pdone)\n{\n    JSValue obj, value, done_val;\n    int done;\n\n    obj = JS_IteratorNext2(ctx, enum_obj, method, argc, argv, &done);\n    if (JS_IsException(obj))\n        goto fail;\n    if (done != 2) {\n        *pdone = done;\n        return obj;\n    } else {\n        done_val = JS_GetProperty(ctx, obj, JS_ATOM_done);\n        if (JS_IsException(done_val))\n            goto fail;\n        *pdone = JS_ToBoolFree(ctx, done_val);\n        value = JS_UNDEFINED;\n        if (!*pdone) {\n            value = JS_GetProperty(ctx, obj, JS_ATOM_value);\n        }\n        JS_FreeValue(ctx, obj);\n        return value;\n    }\n fail:\n    JS_FreeValue(ctx, obj);\n    *pdone = FALSE;\n    return JS_EXCEPTION;\n}\n\n/* return < 0 in case of exception */\nstatic int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj,\n                            BOOL is_exception_pending)\n{\n    JSValue method, ret, ex_obj;\n    int res;\n\n    if (is_exception_pending) {\n        ex_obj = ctx->rt->current_exception;\n        ctx->rt->current_exception = JS_NULL;\n        res = -1;\n    } else {\n        ex_obj = JS_UNDEFINED;\n        res = 0;\n    }\n    method = JS_GetProperty(ctx, enum_obj, JS_ATOM_return);\n    if (JS_IsException(method)) {\n        res = -1;\n        goto done;\n    }\n    if (JS_IsUndefined(method) || JS_IsNull(method)) {\n        goto done;\n    }\n    ret = JS_CallFree(ctx, method, enum_obj, 0, NULL);\n    if (!is_exception_pending) {\n        if (JS_IsException(ret)) {\n            res = -1;\n        } else if (!JS_IsObject(ret)) {\n            JS_ThrowTypeErrorNotAnObject(ctx);\n            res = -1;\n        }\n    }\n    JS_FreeValue(ctx, ret);\n done:\n    if (is_exception_pending) {\n        JS_Throw(ctx, ex_obj);\n    }\n    return res;\n}\n\n/* obj -> enum_rec (3 slots) */\nstatic __exception int js_for_of_start(JSContext *ctx, JSValue *sp,\n                                       BOOL is_async)\n{\n    JSValue op1, obj, method;\n    op1 = sp[-1];\n    obj = JS_GetIterator(ctx, op1, is_async);\n    if (JS_IsException(obj))\n        return -1;\n    JS_FreeValue(ctx, op1);\n    sp[-1] = obj;\n    method = JS_GetProperty(ctx, obj, JS_ATOM_next);\n    if (JS_IsException(method))\n        return -1;\n    sp[0] = method;\n    return 0;\n}\n\n/* enum_rec -> enum_rec value done */\nstatic __exception int js_for_of_next(JSContext *ctx, JSValue *sp, int offset)\n{\n    JSValue value = JS_UNDEFINED;\n    int done = 1;\n\n    if (likely(!JS_IsUndefined(sp[offset]))) {\n        value = JS_IteratorNext(ctx, sp[offset], sp[offset + 1], 0, NULL, &done);\n        if (JS_IsException(value))\n            done = -1;\n        if (done) {\n            /* value is JS_UNDEFINED or JS_EXCEPTION */\n            /* replace the iteration object with undefined */\n            JS_FreeValue(ctx, sp[offset]);\n            sp[offset] = JS_UNDEFINED;\n            if (done < 0)\n                return -1;\n        }\n    }\n    sp[0] = value;\n    sp[1] = JS_NewBool(ctx, done);\n    return 0;\n}\n\nstatic __exception int js_for_await_of_next(JSContext *ctx, JSValue *sp)\n{\n    JSValue result;\n    result = JS_Call(ctx, sp[-2], sp[-3], 0, NULL);\n    if (JS_IsException(result))\n        return -1;\n    sp[0] = result;\n    return 0;\n}\n\nstatic JSValue JS_IteratorGetCompleteValue(JSContext *ctx, JSValueConst obj,\n                                           BOOL *pdone)\n{\n    JSValue done_val, value;\n    BOOL done;\n    done_val = JS_GetProperty(ctx, obj, JS_ATOM_done);\n    if (JS_IsException(done_val))\n        goto fail;\n    done = JS_ToBoolFree(ctx, done_val);\n    value = JS_GetProperty(ctx, obj, JS_ATOM_value);\n    if (JS_IsException(value))\n        goto fail;\n    *pdone = done;\n    return value;\n fail:\n    *pdone = FALSE;\n    return JS_EXCEPTION;\n}\n\nstatic __exception int js_iterator_get_value_done(JSContext *ctx, JSValue *sp)\n{\n    JSValue obj, value;\n    BOOL done;\n    obj = sp[-1];\n    if (!JS_IsObject(obj)) {\n        JS_ThrowTypeError(ctx, \"iterator must return an object\");\n        return -1;\n    }\n    value = JS_IteratorGetCompleteValue(ctx, obj, &done);\n    if (JS_IsException(value))\n        return -1;\n    JS_FreeValue(ctx, obj);\n    sp[-1] = value;\n    sp[0] = JS_NewBool(ctx, done);\n    return 0;\n}\n\nstatic JSValue js_create_iterator_result(JSContext *ctx,\n                                         JSValue val,\n                                         BOOL done)\n{\n    JSValue obj;\n    obj = JS_NewObject(ctx);\n    if (JS_IsException(obj)) {\n        JS_FreeValue(ctx, val);\n        return obj;\n    }\n    if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_value,\n                               val, JS_PROP_C_W_E) < 0) {\n        goto fail;\n    }\n    if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_done,\n                               JS_NewBool(ctx, done), JS_PROP_C_W_E) < 0) {\n    fail:\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    return obj;\n}\n\nstatic JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv,\n                                      BOOL *pdone, int magic);\n\nstatic JSValue js_create_array_iterator(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv, int magic);\n\nstatic BOOL js_is_fast_array(JSContext *ctx, JSValueConst obj)\n{\n    /* Try and handle fast arrays explicitly */\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(obj);\n        if (p->class_id == JS_CLASS_ARRAY && p->fast_array) {\n            return TRUE;\n        }\n    }\n    return FALSE;\n}\n\n/* Access an Array's internal JSValue array if available */\nstatic BOOL js_get_fast_array(JSContext *ctx, JSValueConst obj,\n                              JSValue **arrpp, uint32_t *countp)\n{\n    /* Try and handle fast arrays explicitly */\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(obj);\n        if (p->class_id == JS_CLASS_ARRAY && p->fast_array) {\n            *countp = p->u.array.count;\n            *arrpp = p->u.array.u.values;\n            return TRUE;\n        }\n    }\n    return FALSE;\n}\n\nstatic __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)\n{\n    JSValue iterator, enumobj, method, value;\n    int pos, is_array_iterator;\n    JSValue *arrp;\n    uint32_t i, count32;\n\n    if (JS_VALUE_GET_TAG(sp[-2]) != JS_TAG_INT) {\n        JS_ThrowInternalError(ctx, \"invalid index for append\");\n        return -1;\n    }\n\n    pos = JS_VALUE_GET_INT(sp[-2]);\n\n    /* XXX: further optimisations:\n       - use ctx->array_proto_values?\n       - check if array_iterator_prototype next method is built-in and\n         avoid constructing actual iterator object?\n       - build this into js_for_of_start and use in all `for (x of o)` loops\n     */\n    iterator = JS_GetProperty(ctx, sp[-1], JS_ATOM_Symbol_iterator);\n    if (JS_IsException(iterator))\n        return -1;\n    is_array_iterator = JS_IsCFunction(ctx, iterator,\n                                       (JSCFunction *)js_create_array_iterator,\n                                       JS_ITERATOR_KIND_VALUE);\n    JS_FreeValue(ctx, iterator);\n\n    enumobj = JS_GetIterator(ctx, sp[-1], FALSE);\n    if (JS_IsException(enumobj))\n        return -1;\n    method = JS_GetProperty(ctx, enumobj, JS_ATOM_next);\n    if (JS_IsException(method)) {\n        JS_FreeValue(ctx, enumobj);\n        return -1;\n    }\n    if (is_array_iterator\n    &&  JS_IsCFunction(ctx, method, (JSCFunction *)js_array_iterator_next, 0)\n    &&  js_get_fast_array(ctx, sp[-1], &arrp, &count32)) {\n        int64_t len;\n        /* Handle fast arrays explicitly */\n        if (js_get_length64(ctx, &len, sp[-1]))\n            goto exception;\n        for (i = 0; i < count32; i++) {\n            if (JS_DefinePropertyValueUint32(ctx, sp[-3], pos++,\n                                             JS_DupValue(ctx, arrp[i]), JS_PROP_C_W_E) < 0)\n                goto exception;\n        }\n        if (len > count32) {\n            /* This is not strictly correct because the trailing elements are\n               empty instead of undefined. Append undefined entries instead.\n             */\n            pos += len - count32;\n            if (JS_SetProperty(ctx, sp[-3], JS_ATOM_length, JS_NewUint32(ctx, pos)) < 0)\n                goto exception;\n        }\n    } else {\n        for (;;) {\n            BOOL done;\n            value = JS_IteratorNext(ctx, enumobj, method, 0, NULL, &done);\n            if (JS_IsException(value))\n                goto exception;\n            if (done) {\n                /* value is JS_UNDEFINED */\n                break;\n            }\n            if (JS_DefinePropertyValueUint32(ctx, sp[-3], pos++, value, JS_PROP_C_W_E) < 0)\n                goto exception;\n        }\n    }\n    sp[-2] = JS_NewInt32(ctx, pos);\n    JS_FreeValue(ctx, enumobj);\n    JS_FreeValue(ctx, method);\n    return 0;\n\nexception:\n    JS_IteratorClose(ctx, enumobj, TRUE);\n    JS_FreeValue(ctx, enumobj);\n    JS_FreeValue(ctx, method);\n    return -1;\n}\n\nstatic __exception int JS_CopyDataProperties(JSContext *ctx,\n                                             JSValueConst target,\n                                             JSValueConst source,\n                                             JSValueConst excluded,\n                                             BOOL setprop)\n{\n    JSPropertyEnum *tab_atom;\n    JSValue val;\n    uint32_t i, tab_atom_count;\n    JSObject *p;\n    JSObject *pexcl = NULL;\n    int ret = 0, flags;\n\n    if (JS_VALUE_GET_TAG(source) != JS_TAG_OBJECT)\n        return 0;\n\n    if (JS_VALUE_GET_TAG(excluded) == JS_TAG_OBJECT)\n        pexcl = JS_VALUE_GET_OBJ(excluded);\n\n    p = JS_VALUE_GET_OBJ(source);\n    if (JS_GetOwnPropertyNamesInternal(ctx, &tab_atom, &tab_atom_count, p,\n                               JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK |\n                               JS_GPN_ENUM_ONLY))\n        return -1;\n\n    flags = JS_PROP_C_W_E;\n\n    for (i = 0; i < tab_atom_count; i++) {\n        if (pexcl) {\n            ret = JS_GetOwnPropertyInternal(ctx, NULL, pexcl, tab_atom[i].atom);\n            if (ret) {\n                if (ret < 0)\n                    break;\n                ret = 0;\n                continue;\n            }\n        }\n        ret = -1;\n        val = JS_GetProperty(ctx, source, tab_atom[i].atom);\n        if (JS_IsException(val))\n            break;\n        if (setprop)\n            ret = JS_SetProperty(ctx, target, tab_atom[i].atom, val);\n        else\n            ret = JS_DefinePropertyValue(ctx, target, tab_atom[i].atom, val, flags);\n        if (ret < 0)\n            break;\n        ret = 0;\n    }\n    js_free_prop_enum(ctx, tab_atom, tab_atom_count);\n    return ret;\n}\n\n/* only valid inside C functions */\nstatic JSValueConst JS_GetActiveFunction(JSContext *ctx)\n{\n    return ctx->rt->current_stack_frame->cur_func;\n}\n\nstatic JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,\n                             int var_idx, BOOL is_arg)\n{\n    JSVarRef *var_ref;\n    struct list_head *el;\n\n    list_for_each(el, &sf->var_ref_list) {\n        var_ref = list_entry(el, JSVarRef, header.link);\n        if (var_ref->var_idx == var_idx && var_ref->is_arg == is_arg) {\n            var_ref->header.ref_count++;\n            return var_ref;\n        }\n    }\n    /* create a new one */\n    var_ref = js_malloc(ctx, sizeof(JSVarRef));\n    if (!var_ref)\n        return NULL;\n    var_ref->header.ref_count = 1;\n    var_ref->is_detached = FALSE;\n    var_ref->is_arg = is_arg;\n    var_ref->var_idx = var_idx;\n    list_add_tail(&var_ref->header.link, &sf->var_ref_list);\n    if (is_arg)\n        var_ref->pvalue = &sf->arg_buf[var_idx];\n    else\n        var_ref->pvalue = &sf->var_buf[var_idx];\n    var_ref->value = JS_UNDEFINED;\n    return var_ref;\n}\n\nstatic JSValue js_closure2(JSContext *ctx, JSValue func_obj,\n                           JSFunctionBytecode *b,\n                           JSVarRef **cur_var_refs,\n                           JSStackFrame *sf)\n{\n    JSObject *p;\n    JSVarRef **var_refs;\n    int i;\n\n    p = JS_VALUE_GET_OBJ(func_obj);\n    p->u.func.function_bytecode = b;\n    p->u.func.home_object = NULL;\n    p->u.func.var_refs = NULL;\n    if (b->closure_var_count) {\n        var_refs = js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count);\n        if (!var_refs)\n            goto fail;\n        p->u.func.var_refs = var_refs;\n        for(i = 0; i < b->closure_var_count; i++) {\n            JSClosureVar *cv = &b->closure_var[i];\n            JSVarRef *var_ref;\n            if (cv->is_local) {\n                /* reuse the existing variable reference if it already exists */\n                var_ref = get_var_ref(ctx, sf, cv->var_idx, cv->is_arg);\n                if (!var_ref)\n                    goto fail;\n            } else {\n                var_ref = cur_var_refs[cv->var_idx];\n                var_ref->header.ref_count++;\n            }\n            var_refs[i] = var_ref;\n        }\n    }\n    return func_obj;\n fail:\n    /* bfunc is freed when func_obj is freed */\n    JS_FreeValue(ctx, func_obj);\n    return JS_EXCEPTION;\n}\n\nstatic int js_instantiate_prototype(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque)\n{\n    JSValue obj, this_val;\n    int ret;\n\n    this_val = JS_MKPTR(JS_TAG_OBJECT, p);\n    obj = JS_NewObject(ctx);\n    if (JS_IsException(obj))\n        return -1;\n    set_cycle_flag(ctx, obj);\n    set_cycle_flag(ctx, this_val);\n    ret = JS_DefinePropertyValue(ctx, obj, JS_ATOM_constructor,\n                                 JS_DupValue(ctx, this_val),\n                                 JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    if (JS_DefinePropertyValue(ctx, this_val, atom, obj, JS_PROP_WRITABLE) < 0 || ret < 0)\n        return -1;\n    return 0;\n}\n\nstatic const uint16_t func_kind_to_class_id[] = {\n    [JS_FUNC_NORMAL] = JS_CLASS_BYTECODE_FUNCTION,\n    [JS_FUNC_GENERATOR] = JS_CLASS_GENERATOR_FUNCTION,\n    [JS_FUNC_ASYNC] = JS_CLASS_ASYNC_FUNCTION,\n    [JS_FUNC_ASYNC_GENERATOR] = JS_CLASS_ASYNC_GENERATOR_FUNCTION,\n};\n\nstatic JSValue js_closure(JSContext *ctx, JSValue bfunc,\n                          JSVarRef **cur_var_refs,\n                          JSStackFrame *sf)\n{\n    JSFunctionBytecode *b;\n    JSValue func_obj;\n    JSAtom name_atom;\n\n    b = JS_VALUE_GET_PTR(bfunc);\n    func_obj = JS_NewObjectClass(ctx, func_kind_to_class_id[b->func_kind]);\n    if (JS_IsException(func_obj)) {\n        JS_FreeValue(ctx, bfunc);\n        return JS_EXCEPTION;\n    }\n    func_obj = js_closure2(ctx, func_obj, b, cur_var_refs, sf);\n    if (JS_IsException(func_obj)) {\n        /* bfunc has been freed */\n        goto fail;\n    }\n    name_atom = b->func_name;\n    if (name_atom == JS_ATOM_NULL)\n        name_atom = JS_ATOM_empty_string;\n    js_function_set_properties(ctx, func_obj, name_atom,\n                               b->defined_arg_count);\n\n    if (b->func_kind & JS_FUNC_GENERATOR) {\n        JSValue proto;\n        int proto_class_id;\n        /* generators have a prototype field which is used as\n           prototype for the generator object */\n        if (b->func_kind == JS_FUNC_ASYNC_GENERATOR)\n            proto_class_id = JS_CLASS_ASYNC_GENERATOR;\n        else\n            proto_class_id = JS_CLASS_GENERATOR;\n        proto = JS_NewObjectProto(ctx, ctx->class_proto[proto_class_id]);\n        if (JS_IsException(proto))\n            goto fail;\n        JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_prototype, proto,\n                               JS_PROP_WRITABLE);\n    } else if (b->has_prototype) {\n        /* add the 'prototype' property: delay instantiation to avoid\n           creating cycles for every javascript function. The prototype\n           object is created on the fly when first accessed */\n        JS_SetConstructorBit(ctx, func_obj, TRUE);\n        JS_DefineAutoInitProperty(ctx, func_obj, JS_ATOM_prototype,\n                                  JS_AUTOINIT_ID_PROTOTYPE, NULL,\n                                  JS_PROP_WRITABLE);\n    }\n    return func_obj;\n fail:\n    /* bfunc is freed when func_obj is freed */\n    JS_FreeValue(ctx, func_obj);\n    return JS_EXCEPTION;\n}\n\n#define JS_DEFINE_CLASS_HAS_HERITAGE     (1 << 0)\n\nstatic int js_op_define_class(JSContext *ctx, JSValue *sp,\n                              JSAtom class_name, int class_flags,\n                              JSVarRef **cur_var_refs,\n                              JSStackFrame *sf, BOOL is_computed_name)\n{\n    JSValue bfunc, parent_class, proto = JS_UNDEFINED;\n    JSValue ctor = JS_UNDEFINED, parent_proto = JS_UNDEFINED;\n    JSFunctionBytecode *b;\n\n    parent_class = sp[-2];\n    bfunc = sp[-1];\n\n    if (class_flags & JS_DEFINE_CLASS_HAS_HERITAGE) {\n        if (JS_IsNull(parent_class)) {\n            parent_proto = JS_NULL;\n            parent_class = JS_DupValue(ctx, ctx->function_proto);\n        } else {\n            if (!JS_IsConstructor(ctx, parent_class)) {\n                JS_ThrowTypeError(ctx, \"parent class must be constructor\");\n                goto fail;\n            }\n            parent_proto = JS_GetProperty(ctx, parent_class, JS_ATOM_prototype);\n            if (JS_IsException(parent_proto))\n                goto fail;\n            if (!JS_IsNull(parent_proto) && !JS_IsObject(parent_proto)) {\n                JS_ThrowTypeError(ctx, \"parent prototype must be an object or null\");\n                goto fail;\n            }\n        }\n    } else {\n        /* parent_class is JS_UNDEFINED in this case */\n        parent_proto = JS_DupValue(ctx, ctx->class_proto[JS_CLASS_OBJECT]);\n        parent_class = JS_DupValue(ctx, ctx->function_proto);\n    }\n    proto = JS_NewObjectProto(ctx, parent_proto);\n    if (JS_IsException(proto))\n        goto fail;\n\n    b = JS_VALUE_GET_PTR(bfunc);\n    assert(b->func_kind == JS_FUNC_NORMAL);\n    ctor = JS_NewObjectProtoClass(ctx, parent_class,\n                                  JS_CLASS_BYTECODE_FUNCTION);\n    if (JS_IsException(ctor))\n        goto fail;\n    ctor = js_closure2(ctx, ctor, b, cur_var_refs, sf);\n    bfunc = JS_UNDEFINED;\n    if (JS_IsException(ctor))\n        goto fail;\n    js_method_set_home_object(ctx, ctor, proto);\n    JS_SetConstructorBit(ctx, ctor, TRUE);\n\n    JS_DefinePropertyValue(ctx, ctor, JS_ATOM_length,\n                           JS_NewInt32(ctx, b->defined_arg_count),\n                           JS_PROP_CONFIGURABLE);\n\n    if (is_computed_name) {\n        if (JS_DefineObjectNameComputed(ctx, ctor, sp[-3],\n                                        JS_PROP_CONFIGURABLE) < 0)\n            goto fail;\n    } else {\n        if (JS_DefineObjectName(ctx, ctor, class_name, JS_PROP_CONFIGURABLE) < 0)\n            goto fail;\n    }\n\n    /* the constructor property must be first. It can be overriden by\n       computed property names */\n    if (JS_DefinePropertyValue(ctx, proto, JS_ATOM_constructor,\n                               JS_DupValue(ctx, ctor),\n                               JS_PROP_CONFIGURABLE |\n                               JS_PROP_WRITABLE | JS_PROP_THROW) < 0)\n        goto fail;\n    /* set the prototype property */\n    if (JS_DefinePropertyValue(ctx, ctor, JS_ATOM_prototype,\n                               JS_DupValue(ctx, proto), JS_PROP_THROW) < 0)\n        goto fail;\n    set_cycle_flag(ctx, ctor);\n    set_cycle_flag(ctx, proto);\n\n    JS_FreeValue(ctx, parent_proto);\n    JS_FreeValue(ctx, parent_class);\n\n    sp[-2] = ctor;\n    sp[-1] = proto;\n    return 0;\n fail:\n    JS_FreeValue(ctx, parent_class);\n    JS_FreeValue(ctx, parent_proto);\n    JS_FreeValue(ctx, bfunc);\n    JS_FreeValue(ctx, proto);\n    JS_FreeValue(ctx, ctor);\n    sp[-2] = JS_UNDEFINED;\n    sp[-1] = JS_UNDEFINED;\n    return -1;\n}\n\nstatic void close_var_refs(JSRuntime *rt, JSStackFrame *sf)\n{\n    struct list_head *el, *el1;\n    JSVarRef *var_ref;\n    int var_idx;\n\n    list_for_each_safe(el, el1, &sf->var_ref_list) {\n        var_ref = list_entry(el, JSVarRef, header.link);\n        var_idx = var_ref->var_idx;\n        if (var_ref->is_arg)\n            var_ref->value = JS_DupValueRT(rt, sf->arg_buf[var_idx]);\n        else\n            var_ref->value = JS_DupValueRT(rt, sf->var_buf[var_idx]);\n        var_ref->pvalue = &var_ref->value;\n        /* the reference is no longer to a local variable */\n        var_ref->is_detached = TRUE;\n        add_gc_object(rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);\n    }\n}\n\nstatic void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int idx, int is_arg)\n{\n    struct list_head *el, *el1;\n    JSVarRef *var_ref;\n    int var_idx = idx;\n\n    list_for_each_safe(el, el1, &sf->var_ref_list) {\n        var_ref = list_entry(el, JSVarRef, header.link);\n        if (var_idx == var_ref->var_idx && var_ref->is_arg == is_arg) {\n            var_ref->value = JS_DupValue(ctx, sf->var_buf[var_idx]);\n            var_ref->pvalue = &var_ref->value;\n            list_del(&var_ref->header.link);\n            /* the reference is no longer to a local variable */\n            var_ref->is_detached = TRUE;\n            add_gc_object(ctx->rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);\n        }\n    }\n}\n\n#define JS_CALL_FLAG_COPY_ARGV   (1 << 1)\n#define JS_CALL_FLAG_GENERATOR   (1 << 2)\n\nstatic JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,\n                                  JSValueConst this_obj,\n                                  int argc, JSValueConst *argv, int flags)\n{\n    JSRuntime *rt = ctx->rt;\n    JSCFunctionType func;\n    JSObject *p;\n    JSStackFrame sf_s, *sf = &sf_s, *prev_sf;\n    JSValue ret_val;\n    JSValueConst *arg_buf;\n    int arg_count, i;\n    JSCFunctionEnum cproto;\n\n    p = JS_VALUE_GET_OBJ(func_obj);\n    cproto = p->u.cfunc.cproto;\n    arg_count = p->u.cfunc.length;\n\n    /* better to always check stack overflow */\n    if (js_check_stack_overflow(rt, sizeof(arg_buf[0]) * arg_count))\n        return JS_ThrowStackOverflow(ctx);\n\n    prev_sf = rt->current_stack_frame;\n    sf->prev_frame = prev_sf;\n    rt->current_stack_frame = sf;\n    ctx = p->u.cfunc.realm; /* change the current realm */\n    \n#ifdef CONFIG_BIGNUM\n    /* we only propagate the bignum mode as some runtime functions\n       test it */\n    if (prev_sf)\n        sf->js_mode = prev_sf->js_mode & JS_MODE_MATH;\n    else\n        sf->js_mode = 0;\n#else\n    sf->js_mode = 0;\n#endif\n    sf->cur_func = (JSValue)func_obj;\n    sf->arg_count = argc;\n    arg_buf = argv;\n\n    if (unlikely(argc < arg_count)) {\n        /* ensure that at least argc_count arguments are readable */\n        arg_buf = alloca(sizeof(arg_buf[0]) * arg_count);\n        for(i = 0; i < argc; i++)\n            arg_buf[i] = argv[i];\n        for(i = argc; i < arg_count; i++)\n            arg_buf[i] = JS_UNDEFINED;\n        sf->arg_count = arg_count;\n    }\n    sf->arg_buf = (JSValue*)arg_buf;\n\n    func = p->u.cfunc.c_function;\n    switch(cproto) {\n    case JS_CFUNC_constructor:\n    case JS_CFUNC_constructor_or_func:\n        if (!(flags & JS_CALL_FLAG_CONSTRUCTOR)) {\n            if (cproto == JS_CFUNC_constructor) {\n            not_a_constructor:\n                ret_val = JS_ThrowTypeError(ctx, \"must be called with new\");\n                break;\n            } else {\n                this_obj = JS_UNDEFINED;\n            }\n        }\n        /* here this_obj is new_target */\n        /* fall thru */\n    case JS_CFUNC_generic:\n        ret_val = func.generic(ctx, this_obj, argc, arg_buf);\n        break;\n    case JS_CFUNC_constructor_magic:\n    case JS_CFUNC_constructor_or_func_magic:\n        if (!(flags & JS_CALL_FLAG_CONSTRUCTOR)) {\n            if (cproto == JS_CFUNC_constructor_magic) {\n                goto not_a_constructor;\n            } else {\n                this_obj = JS_UNDEFINED;\n            }\n        }\n        /* fall thru */\n    case JS_CFUNC_generic_magic:\n        ret_val = func.generic_magic(ctx, this_obj, argc, arg_buf,\n                                     p->u.cfunc.magic);\n        break;\n    case JS_CFUNC_getter:\n        ret_val = func.getter(ctx, this_obj);\n        break;\n    case JS_CFUNC_setter:\n        ret_val = func.setter(ctx, this_obj, arg_buf[0]);\n        break;\n    case JS_CFUNC_getter_magic:\n        ret_val = func.getter_magic(ctx, this_obj, p->u.cfunc.magic);\n        break;\n    case JS_CFUNC_setter_magic:\n        ret_val = func.setter_magic(ctx, this_obj, arg_buf[0], p->u.cfunc.magic);\n        break;\n    case JS_CFUNC_f_f:\n        {\n            double d1;\n\n            if (unlikely(JS_ToFloat64(ctx, &d1, arg_buf[0]))) {\n                ret_val = JS_EXCEPTION;\n                break;\n            }\n            ret_val = JS_NewFloat64(ctx, func.f_f(d1));\n        }\n        break;\n    case JS_CFUNC_f_f_f:\n        {\n            double d1, d2;\n\n            if (unlikely(JS_ToFloat64(ctx, &d1, arg_buf[0]))) {\n                ret_val = JS_EXCEPTION;\n                break;\n            }\n            if (unlikely(JS_ToFloat64(ctx, &d2, arg_buf[1]))) {\n                ret_val = JS_EXCEPTION;\n                break;\n            }\n            ret_val = JS_NewFloat64(ctx, func.f_f_f(d1, d2));\n        }\n        break;\n    case JS_CFUNC_iterator_next:\n        {\n            int done;\n            ret_val = func.iterator_next(ctx, this_obj, argc, arg_buf,\n                                         &done, p->u.cfunc.magic);\n            if (!JS_IsException(ret_val) && done != 2) {\n                ret_val = js_create_iterator_result(ctx, ret_val, done);\n            }\n        }\n        break;\n    default:\n        abort();\n    }\n\n    rt->current_stack_frame = sf->prev_frame;\n    return ret_val;\n}\n\nstatic JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,\n                                      JSValueConst this_obj,\n                                      int argc, JSValueConst *argv, int flags)\n{\n    JSObject *p;\n    JSBoundFunction *bf;\n    JSValueConst *arg_buf, new_target;\n    int arg_count, i;\n\n    p = JS_VALUE_GET_OBJ(func_obj);\n    bf = p->u.bound_function;\n    arg_count = bf->argc + argc;\n    if (js_check_stack_overflow(ctx->rt, sizeof(JSValue) * arg_count))\n        return JS_ThrowStackOverflow(ctx);\n    arg_buf = alloca(sizeof(JSValue) * arg_count);\n    for(i = 0; i < bf->argc; i++) {\n        arg_buf[i] = bf->argv[i];\n    }\n    for(i = 0; i < argc; i++) {\n        arg_buf[bf->argc + i] = argv[i];\n    }\n    if (flags & JS_CALL_FLAG_CONSTRUCTOR) {\n        new_target = this_obj;\n        if (js_same_value(ctx, func_obj, new_target))\n            new_target = bf->func_obj;\n        return JS_CallConstructor2(ctx, bf->func_obj, new_target,\n                                   arg_count, arg_buf);\n    } else {\n        return JS_Call(ctx, bf->func_obj, bf->this_val,\n                       arg_count, arg_buf);\n    }\n}\n\n/* argument of OP_special_object */\ntypedef enum {\n    OP_SPECIAL_OBJECT_ARGUMENTS,\n    OP_SPECIAL_OBJECT_MAPPED_ARGUMENTS,\n    OP_SPECIAL_OBJECT_THIS_FUNC,\n    OP_SPECIAL_OBJECT_NEW_TARGET,\n    OP_SPECIAL_OBJECT_HOME_OBJECT,\n    OP_SPECIAL_OBJECT_VAR_OBJECT,\n    OP_SPECIAL_OBJECT_IMPORT_META,\n} OPSpecialObjectEnum;\n\n#define FUNC_RET_AWAIT      0\n#define FUNC_RET_YIELD      1\n#define FUNC_RET_YIELD_STAR 2\n\n/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */\nstatic JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,\n                               JSValueConst this_obj, JSValueConst new_target,\n                               int argc, JSValue *argv, int flags)\n{\n    JSRuntime *rt = caller_ctx->rt;\n    JSContext *ctx;\n    JSObject *p;\n    JSFunctionBytecode *b;\n    JSStackFrame sf_s, *sf = &sf_s;\n    const uint8_t *pc;\n    int opcode, arg_allocated_size, i;\n    JSValue *local_buf, *stack_buf, *var_buf, *arg_buf, *sp, ret_val, *pval;\n    JSVarRef **var_refs;\n    size_t alloca_size;\n\n#if !DIRECT_DISPATCH\n#define SWITCH(pc)      switch (opcode = *pc++)\n#define CASE(op)        case op\n#define DEFAULT         default\n#define BREAK           break\n#else\n    static const void * const dispatch_table[256] = {\n#define DEF(id, size, n_pop, n_push, f) && case_OP_ ## id,\n#if SHORT_OPCODES\n#define def(id, size, n_pop, n_push, f)\n#else                                                     \n#define def(id, size, n_pop, n_push, f) && case_default,\n#endif\n#include \"quickjs-opcode.h\"\n        [ OP_COUNT ... 255 ] = &&case_default\n    };\n#define SWITCH(pc)      goto *dispatch_table[opcode = *pc++];\n#define CASE(op)        case_ ## op\n#define DEFAULT         case_default\n#define BREAK           SWITCH(pc)\n#endif\n\n    if (js_poll_interrupts(caller_ctx))\n        return JS_EXCEPTION;\n    if (unlikely(JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)) {\n        if (flags & JS_CALL_FLAG_GENERATOR) {\n            JSAsyncFunctionState *s = JS_VALUE_GET_PTR(func_obj);\n            /* func_obj get contains a pointer to JSFuncAsyncState */\n            /* the stack frame is already allocated */\n            sf = &s->frame;\n            p = JS_VALUE_GET_OBJ(sf->cur_func);\n            b = p->u.func.function_bytecode;\n            ctx = b->realm;\n            var_refs = p->u.func.var_refs;\n            local_buf = arg_buf = sf->arg_buf;\n            var_buf = sf->var_buf;\n            stack_buf = sf->var_buf + b->var_count;\n            sp = sf->cur_sp;\n            sf->cur_sp = NULL; /* cur_sp is NULL if the function is running */\n            pc = sf->cur_pc;\n            sf->prev_frame = rt->current_stack_frame;\n            rt->current_stack_frame = sf;\n            if (s->throw_flag)\n                goto exception;\n            else\n                goto restart;\n        } else {\n            goto not_a_function;\n        }\n    }\n    p = JS_VALUE_GET_OBJ(func_obj);\n    if (unlikely(p->class_id != JS_CLASS_BYTECODE_FUNCTION)) {\n        JSClassCall *call_func;\n        call_func = rt->class_array[p->class_id].call;\n        if (!call_func) {\n        not_a_function:\n            return JS_ThrowTypeError(caller_ctx, \"not a function\");\n        }\n        return call_func(caller_ctx, func_obj, this_obj, argc,\n                         (JSValueConst *)argv, flags);\n    }\n    b = p->u.func.function_bytecode;\n\n    if (unlikely(argc < b->arg_count || (flags & JS_CALL_FLAG_COPY_ARGV))) {\n        arg_allocated_size = b->arg_count;\n    } else {\n        arg_allocated_size = 0;\n    }\n\n    alloca_size = sizeof(JSValue) * (arg_allocated_size + b->var_count +\n                                     b->stack_size);\n    if (js_check_stack_overflow(rt, alloca_size))\n        return JS_ThrowStackOverflow(caller_ctx);\n\n    sf->js_mode = b->js_mode;\n    arg_buf = argv;\n    sf->arg_count = argc;\n    sf->cur_func = (JSValue)func_obj;\n    init_list_head(&sf->var_ref_list);\n    var_refs = p->u.func.var_refs;\n\n    local_buf = alloca(alloca_size);\n    if (unlikely(arg_allocated_size)) {\n        int n = min_int(argc, b->arg_count);\n        arg_buf = local_buf;\n        for(i = 0; i < n; i++)\n            arg_buf[i] = JS_DupValue(caller_ctx, argv[i]);\n        for(; i < b->arg_count; i++)\n            arg_buf[i] = JS_UNDEFINED;\n        sf->arg_count = b->arg_count;\n    }\n    var_buf = local_buf + arg_allocated_size;\n    sf->var_buf = var_buf;\n    sf->arg_buf = arg_buf;\n\n    for(i = 0; i < b->var_count; i++)\n        var_buf[i] = JS_UNDEFINED;\n\n    stack_buf = var_buf + b->var_count;\n    sp = stack_buf;\n    pc = b->byte_code_buf;\n    sf->prev_frame = rt->current_stack_frame;\n    rt->current_stack_frame = sf;\n    ctx = b->realm; /* set the current realm */\n    \n restart:\n    for(;;) {\n        int call_argc;\n        JSValue *call_argv;\n\n        SWITCH(pc) {\n        CASE(OP_push_i32):\n            *sp++ = JS_NewInt32(ctx, get_u32(pc));\n            pc += 4;\n            BREAK;\n        CASE(OP_push_const):\n            *sp++ = JS_DupValue(ctx, b->cpool[get_u32(pc)]);\n            pc += 4;\n            BREAK;\n#if SHORT_OPCODES\n        CASE(OP_push_minus1):\n        CASE(OP_push_0):\n        CASE(OP_push_1):\n        CASE(OP_push_2):\n        CASE(OP_push_3):\n        CASE(OP_push_4):\n        CASE(OP_push_5):\n        CASE(OP_push_6):\n        CASE(OP_push_7):\n            *sp++ = JS_NewInt32(ctx, opcode - OP_push_0);\n            BREAK;\n        CASE(OP_push_i8):\n            *sp++ = JS_NewInt32(ctx, get_i8(pc));\n            pc += 1;\n            BREAK;\n        CASE(OP_push_i16):\n            *sp++ = JS_NewInt32(ctx, get_i16(pc));\n            pc += 2;\n            BREAK;\n        CASE(OP_push_const8):\n            *sp++ = JS_DupValue(ctx, b->cpool[*pc++]);\n            BREAK;\n        CASE(OP_fclosure8):\n            *sp++ = js_closure(ctx, JS_DupValue(ctx, b->cpool[*pc++]), var_refs, sf);\n            if (unlikely(JS_IsException(sp[-1])))\n                goto exception;\n            BREAK;\n        CASE(OP_push_empty_string):\n            *sp++ = JS_AtomToString(ctx, JS_ATOM_empty_string);\n            BREAK;\n        CASE(OP_get_length):\n            {\n                JSValue val;\n\n                val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length);\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = val;\n            }\n            BREAK;\n#endif\n        CASE(OP_push_atom_value):\n            *sp++ = JS_AtomToValue(ctx, get_u32(pc));\n            pc += 4;\n            BREAK;\n        CASE(OP_undefined):\n            *sp++ = JS_UNDEFINED;\n            BREAK;\n        CASE(OP_null):\n            *sp++ = JS_NULL;\n            BREAK;\n        CASE(OP_push_this):\n            /* OP_push_this is only called at the start of a function */\n            {\n                JSValue val;\n                if (!(b->js_mode & JS_MODE_STRICT)) {\n                    uint32_t tag = JS_VALUE_GET_TAG(this_obj);\n                    if (likely(tag == JS_TAG_OBJECT))\n                        goto normal_this;\n                    if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED) {\n                        val = JS_DupValue(ctx, ctx->global_obj);\n                    } else {\n                        val = JS_ToObject(ctx, this_obj);\n                        if (JS_IsException(val))\n                            goto exception;\n                    }\n                } else {\n                normal_this:\n                    val = JS_DupValue(ctx, this_obj);\n                }\n                *sp++ = val;\n            }\n            BREAK;\n        CASE(OP_push_false):\n            *sp++ = JS_FALSE;\n            BREAK;\n        CASE(OP_push_true):\n            *sp++ = JS_TRUE;\n            BREAK;\n        CASE(OP_object):\n            *sp++ = JS_NewObject(ctx);\n            if (unlikely(JS_IsException(sp[-1])))\n                goto exception;\n            BREAK;\n        CASE(OP_special_object):\n            {\n                int arg = *pc++;\n                switch(arg) {\n                case OP_SPECIAL_OBJECT_ARGUMENTS:\n                    *sp++ = js_build_arguments(ctx, argc, (JSValueConst *)argv);\n                    if (unlikely(JS_IsException(sp[-1])))\n                        goto exception;\n                    break;\n                case OP_SPECIAL_OBJECT_MAPPED_ARGUMENTS:\n                    *sp++ = js_build_mapped_arguments(ctx, argc, (JSValueConst *)argv,\n                                                      sf, min_int(argc, b->arg_count));\n                    if (unlikely(JS_IsException(sp[-1])))\n                        goto exception;\n                    break;\n                case OP_SPECIAL_OBJECT_THIS_FUNC:\n                    *sp++ = JS_DupValue(ctx, sf->cur_func);\n                    break;\n                case OP_SPECIAL_OBJECT_NEW_TARGET:\n                    *sp++ = JS_DupValue(ctx, new_target);\n                    break;\n                case OP_SPECIAL_OBJECT_HOME_OBJECT:\n                    {\n                        JSObject *p1;\n                        p1 = p->u.func.home_object;\n                        if (unlikely(!p1))\n                            *sp++ = JS_UNDEFINED;\n                        else\n                            *sp++ = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p1));\n                    }\n                    break;\n                case OP_SPECIAL_OBJECT_VAR_OBJECT:\n                    *sp++ = JS_NewObjectProto(ctx, JS_NULL);\n                    if (unlikely(JS_IsException(sp[-1])))\n                        goto exception;\n                    break;\n                case OP_SPECIAL_OBJECT_IMPORT_META:\n                    *sp++ = js_import_meta(ctx);\n                    if (unlikely(JS_IsException(sp[-1])))\n                        goto exception;\n                    break;\n                default:\n                    abort();\n                }\n            }\n            BREAK;\n        CASE(OP_rest):\n            {\n                int first = get_u16(pc);\n                pc += 2;\n                *sp++ = js_build_rest(ctx, first, argc, (JSValueConst *)argv);\n                if (unlikely(JS_IsException(sp[-1])))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_drop):\n            JS_FreeValue(ctx, sp[-1]);\n            sp--;\n            BREAK;\n        CASE(OP_nip):\n            JS_FreeValue(ctx, sp[-2]);\n            sp[-2] = sp[-1];\n            sp--;\n            BREAK;\n        CASE(OP_nip1): /* a b c -> b c */\n            JS_FreeValue(ctx, sp[-3]);\n            sp[-3] = sp[-2];\n            sp[-2] = sp[-1];\n            sp--;\n            BREAK;\n        CASE(OP_dup):\n            sp[0] = JS_DupValue(ctx, sp[-1]);\n            sp++;\n            BREAK;\n        CASE(OP_dup2): /* a b -> a b a b */\n            sp[0] = JS_DupValue(ctx, sp[-2]);\n            sp[1] = JS_DupValue(ctx, sp[-1]);\n            sp += 2;\n            BREAK;\n        CASE(OP_dup3): /* a b c -> a b c a b c */\n            sp[0] = JS_DupValue(ctx, sp[-3]);\n            sp[1] = JS_DupValue(ctx, sp[-2]);\n            sp[2] = JS_DupValue(ctx, sp[-1]);\n            sp += 3;\n            BREAK;\n        CASE(OP_dup1): /* a b -> a a b */\n            sp[0] = sp[-1];\n            sp[-1] = JS_DupValue(ctx, sp[-2]);\n            sp++;\n            BREAK;\n        CASE(OP_insert2): /* obj a -> a obj a (dup_x1) */\n            sp[0] = sp[-1];\n            sp[-1] = sp[-2];\n            sp[-2] = JS_DupValue(ctx, sp[0]);\n            sp++;\n            BREAK;\n        CASE(OP_insert3): /* obj prop a -> a obj prop a (dup_x2) */\n            sp[0] = sp[-1];\n            sp[-1] = sp[-2];\n            sp[-2] = sp[-3];\n            sp[-3] = JS_DupValue(ctx, sp[0]);\n            sp++;\n            BREAK;\n        CASE(OP_insert4): /* this obj prop a -> a this obj prop a */\n            sp[0] = sp[-1];\n            sp[-1] = sp[-2];\n            sp[-2] = sp[-3];\n            sp[-3] = sp[-4];\n            sp[-4] = JS_DupValue(ctx, sp[0]);\n            sp++;\n            BREAK;\n        CASE(OP_perm3): /* obj a b -> a obj b (213) */\n            {\n                JSValue tmp;\n                tmp = sp[-2];\n                sp[-2] = sp[-3];\n                sp[-3] = tmp;\n            }\n            BREAK;\n        CASE(OP_rot3l): /* x a b -> a b x (231) */\n            {\n                JSValue tmp;\n                tmp = sp[-3];\n                sp[-3] = sp[-2];\n                sp[-2] = sp[-1];\n                sp[-1] = tmp;\n            }\n            BREAK;\n        CASE(OP_rot4l): /* x a b c -> a b c x */\n            {\n                JSValue tmp;\n                tmp = sp[-4];\n                sp[-4] = sp[-3];\n                sp[-3] = sp[-2];\n                sp[-2] = sp[-1];\n                sp[-1] = tmp;\n            }\n            BREAK;\n        CASE(OP_rot5l): /* x a b c d -> a b c d x */\n            {\n                JSValue tmp;\n                tmp = sp[-5];\n                sp[-5] = sp[-4];\n                sp[-4] = sp[-3];\n                sp[-3] = sp[-2];\n                sp[-2] = sp[-1];\n                sp[-1] = tmp;\n            }\n            BREAK;\n        CASE(OP_rot3r): /* a b x -> x a b (312) */\n            {\n                JSValue tmp;\n                tmp = sp[-1];\n                sp[-1] = sp[-2];\n                sp[-2] = sp[-3];\n                sp[-3] = tmp;\n            }\n            BREAK;\n        CASE(OP_perm4): /* obj prop a b -> a obj prop b */\n            {\n                JSValue tmp;\n                tmp = sp[-2];\n                sp[-2] = sp[-3];\n                sp[-3] = sp[-4];\n                sp[-4] = tmp;\n            }\n            BREAK;\n        CASE(OP_perm5): /* this obj prop a b -> a this obj prop b */\n            {\n                JSValue tmp;\n                tmp = sp[-2];\n                sp[-2] = sp[-3];\n                sp[-3] = sp[-4];\n                sp[-4] = sp[-5];\n                sp[-5] = tmp;\n            }\n            BREAK;\n        CASE(OP_swap): /* a b -> b a */\n            {\n                JSValue tmp;\n                tmp = sp[-2];\n                sp[-2] = sp[-1];\n                sp[-1] = tmp;\n            }\n            BREAK;\n        CASE(OP_swap2): /* a b c d -> c d a b */\n            {\n                JSValue tmp1, tmp2;\n                tmp1 = sp[-4];\n                tmp2 = sp[-3];\n                sp[-4] = sp[-2];\n                sp[-3] = sp[-1];\n                sp[-2] = tmp1;\n                sp[-1] = tmp2;\n            }\n            BREAK;\n\n        CASE(OP_fclosure):\n            {\n                JSValue bfunc = JS_DupValue(ctx, b->cpool[get_u32(pc)]);\n                pc += 4;\n                *sp++ = js_closure(ctx, bfunc, var_refs, sf);\n                if (unlikely(JS_IsException(sp[-1])))\n                    goto exception;\n            }\n            BREAK;\n#if SHORT_OPCODES\n        CASE(OP_call0):\n        CASE(OP_call1):\n        CASE(OP_call2):\n        CASE(OP_call3):\n            call_argc = opcode - OP_call0;\n            goto has_call_argc;\n#endif\n        CASE(OP_call):\n        CASE(OP_tail_call):\n            {\n                call_argc = get_u16(pc);\n                pc += 2;\n                goto has_call_argc;\n            has_call_argc:\n                call_argv = sp - call_argc;\n                sf->cur_pc = pc;\n                ret_val = JS_CallInternal(ctx, call_argv[-1], JS_UNDEFINED,\n                                          JS_UNDEFINED, call_argc, call_argv, 0);\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                if (opcode == OP_tail_call)\n                    goto done;\n                for(i = -1; i < call_argc; i++)\n                    JS_FreeValue(ctx, call_argv[i]);\n                sp -= call_argc + 1;\n                *sp++ = ret_val;\n            }\n            BREAK;\n        CASE(OP_call_constructor):\n            {\n                call_argc = get_u16(pc);\n                pc += 2;\n                call_argv = sp - call_argc;\n                sf->cur_pc = pc;\n                ret_val = JS_CallConstructorInternal(ctx, call_argv[-2],\n                                                     call_argv[-1],\n                                                     call_argc, call_argv, 0);\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                for(i = -2; i < call_argc; i++)\n                    JS_FreeValue(ctx, call_argv[i]);\n                sp -= call_argc + 2;\n                *sp++ = ret_val;\n            }\n            BREAK;\n        CASE(OP_call_method):\n        CASE(OP_tail_call_method):\n            {\n                call_argc = get_u16(pc);\n                pc += 2;\n                call_argv = sp - call_argc;\n                sf->cur_pc = pc;\n                ret_val = JS_CallInternal(ctx, call_argv[-1], call_argv[-2],\n                                          JS_UNDEFINED, call_argc, call_argv, 0);\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                if (opcode == OP_tail_call_method)\n                    goto done;\n                for(i = -2; i < call_argc; i++)\n                    JS_FreeValue(ctx, call_argv[i]);\n                sp -= call_argc + 2;\n                *sp++ = ret_val;\n            }\n            BREAK;\n        CASE(OP_array_from):\n            {\n                int i, ret;\n\n                call_argc = get_u16(pc);\n                pc += 2;\n                ret_val = JS_NewArray(ctx);\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                call_argv = sp - call_argc;\n                for(i = 0; i < call_argc; i++) {\n                    ret = JS_DefinePropertyValue(ctx, ret_val, __JS_AtomFromUInt32(i), call_argv[i],\n                                                 JS_PROP_C_W_E | JS_PROP_THROW);\n                    call_argv[i] = JS_UNDEFINED;\n                    if (ret < 0) {\n                        JS_FreeValue(ctx, ret_val);\n                        goto exception;\n                    }\n                }\n                sp -= call_argc;\n                *sp++ = ret_val;\n            }\n            BREAK;\n\n        CASE(OP_apply):\n            {\n                int magic;\n                magic = get_u16(pc);\n                pc += 2;\n\n                ret_val = js_function_apply(ctx, sp[-3], 2, (JSValueConst *)&sp[-2], magic);\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-3]);\n                JS_FreeValue(ctx, sp[-2]);\n                JS_FreeValue(ctx, sp[-1]);\n                sp -= 3;\n                *sp++ = ret_val;\n            }\n            BREAK;\n        CASE(OP_return):\n            ret_val = *--sp;\n            goto done;\n        CASE(OP_return_undef):\n            ret_val = JS_UNDEFINED;\n            goto done;\n\n        CASE(OP_check_ctor_return):\n            /* return TRUE if 'this' should be returned */\n            if (!JS_IsObject(sp[-1])) {\n                if (!JS_IsUndefined(sp[-1])) {\n                    JS_ThrowTypeError(caller_ctx, \"derived class constructor must return an object or undefined\");\n                    goto exception;\n                }\n                sp[0] = JS_TRUE;\n            } else {\n                sp[0] = JS_FALSE;\n            }\n            sp++;\n            BREAK;\n        CASE(OP_check_ctor):\n            if (JS_IsUndefined(new_target)) {\n                JS_ThrowTypeError(caller_ctx, \"class constructors must be invoked with 'new'\");\n                goto exception;\n            }\n            BREAK;\n        CASE(OP_check_brand):\n            if (JS_CheckBrand(ctx, sp[-2], sp[-1]) < 0)\n                goto exception;\n            BREAK;\n        CASE(OP_add_brand):\n            if (JS_AddBrand(ctx, sp[-2], sp[-1]) < 0)\n                goto exception;\n            JS_FreeValue(ctx, sp[-2]);\n            JS_FreeValue(ctx, sp[-1]);\n            sp -= 2;\n            BREAK;\n            \n        CASE(OP_throw):\n            JS_Throw(ctx, *--sp);\n            goto exception;\n\n        CASE(OP_throw_var):\n#define JS_THROW_VAR_RO             0\n#define JS_THROW_VAR_REDECL         1\n#define JS_THROW_VAR_UNINITIALIZED  2\n#define JS_THROW_VAR_DELETE_SUPER   3\n            {\n                JSAtom atom;\n                int type;\n                atom = get_u32(pc);\n                type = pc[4];\n                pc += 5;\n                if (type == JS_THROW_VAR_RO)\n                    JS_ThrowTypeErrorReadOnly(ctx, JS_PROP_THROW, atom);\n                else\n                if (type == JS_THROW_VAR_REDECL)\n                    JS_ThrowSyntaxErrorVarRedeclaration(ctx, atom);\n                else\n                if (type == JS_THROW_VAR_UNINITIALIZED)\n                    JS_ThrowReferenceErrorUninitialized(ctx, atom);\n                else\n                if (type == JS_THROW_VAR_DELETE_SUPER)\n                    JS_ThrowReferenceError(ctx, \"unsupported reference to 'super'\");\n                else\n                    JS_ThrowInternalError(ctx, \"invalid throw var type %d\", type);\n            }\n            goto exception;\n\n        CASE(OP_eval):\n            {\n                JSValueConst obj;\n                int scope_idx;\n                call_argc = get_u16(pc);\n                scope_idx = get_u16(pc + 2) - 1;\n                pc += 4;\n                call_argv = sp - call_argc;\n                sf->cur_pc = pc;\n                if (js_same_value(ctx, call_argv[-1], ctx->eval_obj)) {\n                    if (call_argc >= 1)\n                        obj = call_argv[0];\n                    else\n                        obj = JS_UNDEFINED;\n                    ret_val = JS_EvalObject(ctx, JS_UNDEFINED, obj,\n                                            JS_EVAL_TYPE_DIRECT, scope_idx);\n                } else {\n                    ret_val = JS_CallInternal(ctx, call_argv[-1], JS_UNDEFINED,\n                                              JS_UNDEFINED, call_argc, call_argv, 0);\n                }\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                for(i = -1; i < call_argc; i++)\n                    JS_FreeValue(ctx, call_argv[i]);\n                sp -= call_argc + 1;\n                *sp++ = ret_val;\n            }\n            BREAK;\n            /* could merge with OP_apply */\n        CASE(OP_apply_eval):\n            {\n                int scope_idx;\n                uint32_t len;\n                JSValue *tab;\n                JSValueConst obj;\n\n                scope_idx = get_u16(pc) - 1;\n                pc += 2;\n                tab = build_arg_list(ctx, &len, sp[-1]);\n                if (!tab)\n                    goto exception;\n                if (js_same_value(ctx, sp[-2], ctx->eval_obj)) {\n                    if (len >= 1)\n                        obj = tab[0];\n                    else\n                        obj = JS_UNDEFINED;\n                    ret_val = JS_EvalObject(ctx, JS_UNDEFINED, obj,\n                                            JS_EVAL_TYPE_DIRECT, scope_idx);\n                } else {\n                    ret_val = JS_Call(ctx, sp[-2], JS_UNDEFINED, len,\n                                      (JSValueConst *)tab);\n                }\n                free_arg_list(ctx, tab, len);\n                if (unlikely(JS_IsException(ret_val)))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-2]);\n                JS_FreeValue(ctx, sp[-1]);\n                sp -= 2;\n                *sp++ = ret_val;\n            }\n            BREAK;\n\n        CASE(OP_regexp):\n            {\n                sp[-2] = js_regexp_constructor_internal(ctx, JS_UNDEFINED,\n                                                        sp[-2], sp[-1]);\n                sp--;\n            }\n            BREAK;\n\n        CASE(OP_get_super):\n            {\n                JSValue proto;\n                proto = JS_GetPrototype(ctx, sp[-1]);\n                if (JS_IsException(proto))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = proto;\n            }\n            BREAK;\n\n        CASE(OP_import):\n            {\n                JSValue val;\n                val = js_dynamic_import(ctx, sp[-1]);\n                if (JS_IsException(val))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = val;\n            }\n            BREAK;\n\n        CASE(OP_check_var):\n            {\n                int ret;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                ret = JS_CheckGlobalVar(ctx, atom);\n                if (ret < 0)\n                    goto exception;\n                *sp++ = JS_NewBool(ctx, ret);\n            }\n            BREAK;\n\n        CASE(OP_get_var_undef):\n        CASE(OP_get_var):\n            {\n                JSValue val;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                val = JS_GetGlobalVar(ctx, atom, opcode - OP_get_var_undef);\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n                *sp++ = val;\n            }\n            BREAK;\n\n        CASE(OP_put_var):\n        CASE(OP_put_var_init):\n            {\n                int ret;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                ret = JS_SetGlobalVar(ctx, atom, sp[-1], opcode - OP_put_var);\n                sp--;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_put_var_strict):\n            {\n                int ret;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                /* sp[-2] is JS_TRUE or JS_FALSE */\n                if (unlikely(!JS_VALUE_GET_INT(sp[-2]))) {\n                    JS_ThrowReferenceErrorNotDefined(ctx, atom);\n                    goto exception;\n                }\n                ret = JS_SetGlobalVar(ctx, atom, sp[-1], 2);\n                sp -= 2;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_check_define_var):\n            {\n                JSAtom atom;\n                int flags;\n                atom = get_u32(pc);\n                flags = pc[4];\n                pc += 5;\n                if (JS_CheckDefineGlobalVar(ctx, atom, flags))\n                    goto exception;\n            }\n            BREAK;\n        CASE(OP_define_var):\n            {\n                JSAtom atom;\n                int flags;\n                atom = get_u32(pc);\n                flags = pc[4];\n                pc += 5;\n                if (JS_DefineGlobalVar(ctx, atom, flags))\n                    goto exception;\n            }\n            BREAK;\n        CASE(OP_define_func):\n            {\n                JSAtom atom;\n                int flags;\n                atom = get_u32(pc);\n                flags = pc[4];\n                pc += 5;\n                if (JS_DefineGlobalFunction(ctx, atom, sp[-1], flags))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp--;\n            }\n            BREAK;\n\n        CASE(OP_get_loc):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                sp[0] = JS_DupValue(ctx, var_buf[idx]);\n                sp++;\n            }\n            BREAK;\n        CASE(OP_put_loc):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, &var_buf[idx], sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_set_loc):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, &var_buf[idx], JS_DupValue(ctx, sp[-1]));\n            }\n            BREAK;\n        CASE(OP_get_arg):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                sp[0] = JS_DupValue(ctx, arg_buf[idx]);\n                sp++;\n            }\n            BREAK;\n        CASE(OP_put_arg):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, &arg_buf[idx], sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_set_arg):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, &arg_buf[idx], JS_DupValue(ctx, sp[-1]));\n            }\n            BREAK;\n\n#if SHORT_OPCODES\n        CASE(OP_get_loc8): *sp++ = JS_DupValue(ctx, var_buf[*pc++]); BREAK;\n        CASE(OP_put_loc8): set_value(ctx, &var_buf[*pc++], *--sp); BREAK;\n        CASE(OP_set_loc8): set_value(ctx, &var_buf[*pc++], JS_DupValue(ctx, sp[-1])); BREAK;\n\n        CASE(OP_get_loc0): *sp++ = JS_DupValue(ctx, var_buf[0]); BREAK;\n        CASE(OP_get_loc1): *sp++ = JS_DupValue(ctx, var_buf[1]); BREAK;\n        CASE(OP_get_loc2): *sp++ = JS_DupValue(ctx, var_buf[2]); BREAK;\n        CASE(OP_get_loc3): *sp++ = JS_DupValue(ctx, var_buf[3]); BREAK;\n        CASE(OP_put_loc0): set_value(ctx, &var_buf[0], *--sp); BREAK;\n        CASE(OP_put_loc1): set_value(ctx, &var_buf[1], *--sp); BREAK;\n        CASE(OP_put_loc2): set_value(ctx, &var_buf[2], *--sp); BREAK;\n        CASE(OP_put_loc3): set_value(ctx, &var_buf[3], *--sp); BREAK;\n        CASE(OP_set_loc0): set_value(ctx, &var_buf[0], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_loc1): set_value(ctx, &var_buf[1], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_loc2): set_value(ctx, &var_buf[2], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_loc3): set_value(ctx, &var_buf[3], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_get_arg0): *sp++ = JS_DupValue(ctx, arg_buf[0]); BREAK;\n        CASE(OP_get_arg1): *sp++ = JS_DupValue(ctx, arg_buf[1]); BREAK;\n        CASE(OP_get_arg2): *sp++ = JS_DupValue(ctx, arg_buf[2]); BREAK;\n        CASE(OP_get_arg3): *sp++ = JS_DupValue(ctx, arg_buf[3]); BREAK;\n        CASE(OP_put_arg0): set_value(ctx, &arg_buf[0], *--sp); BREAK;\n        CASE(OP_put_arg1): set_value(ctx, &arg_buf[1], *--sp); BREAK;\n        CASE(OP_put_arg2): set_value(ctx, &arg_buf[2], *--sp); BREAK;\n        CASE(OP_put_arg3): set_value(ctx, &arg_buf[3], *--sp); BREAK;\n        CASE(OP_set_arg0): set_value(ctx, &arg_buf[0], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_arg1): set_value(ctx, &arg_buf[1], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_arg2): set_value(ctx, &arg_buf[2], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_arg3): set_value(ctx, &arg_buf[3], JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_get_var_ref0): *sp++ = JS_DupValue(ctx, *var_refs[0]->pvalue); BREAK;\n        CASE(OP_get_var_ref1): *sp++ = JS_DupValue(ctx, *var_refs[1]->pvalue); BREAK;\n        CASE(OP_get_var_ref2): *sp++ = JS_DupValue(ctx, *var_refs[2]->pvalue); BREAK;\n        CASE(OP_get_var_ref3): *sp++ = JS_DupValue(ctx, *var_refs[3]->pvalue); BREAK;\n        CASE(OP_put_var_ref0): set_value(ctx, var_refs[0]->pvalue, *--sp); BREAK;\n        CASE(OP_put_var_ref1): set_value(ctx, var_refs[1]->pvalue, *--sp); BREAK;\n        CASE(OP_put_var_ref2): set_value(ctx, var_refs[2]->pvalue, *--sp); BREAK;\n        CASE(OP_put_var_ref3): set_value(ctx, var_refs[3]->pvalue, *--sp); BREAK;\n        CASE(OP_set_var_ref0): set_value(ctx, var_refs[0]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_var_ref1): set_value(ctx, var_refs[1]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_var_ref2): set_value(ctx, var_refs[2]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK;\n        CASE(OP_set_var_ref3): set_value(ctx, var_refs[3]->pvalue, JS_DupValue(ctx, sp[-1])); BREAK;\n#endif\n\n        CASE(OP_get_var_ref):\n            {\n                int idx;\n                JSValue val;\n                idx = get_u16(pc);\n                pc += 2;\n                val = *var_refs[idx]->pvalue;\n                sp[0] = JS_DupValue(ctx, val);\n                sp++;\n            }\n            BREAK;\n        CASE(OP_put_var_ref):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, var_refs[idx]->pvalue, sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_set_var_ref):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, var_refs[idx]->pvalue, JS_DupValue(ctx, sp[-1]));\n            }\n            BREAK;\n        CASE(OP_get_var_ref_check):\n            {\n                int idx;\n                JSValue val;\n                idx = get_u16(pc);\n                pc += 2;\n                val = *var_refs[idx]->pvalue;\n                if (unlikely(JS_IsUninitialized(val))) {\n                    JS_ThrowReferenceErrorUninitialized(ctx, JS_ATOM_NULL);\n                    goto exception;\n                }\n                sp[0] = JS_DupValue(ctx, val);\n                sp++;\n            }\n            BREAK;\n        CASE(OP_put_var_ref_check):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                if (unlikely(JS_IsUninitialized(*var_refs[idx]->pvalue))) {\n                    JS_ThrowReferenceErrorUninitialized(ctx, JS_ATOM_NULL);\n                    goto exception;\n                }\n                set_value(ctx, var_refs[idx]->pvalue, sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_put_var_ref_check_init):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                if (unlikely(!JS_IsUninitialized(*var_refs[idx]->pvalue))) {\n                    JS_ThrowReferenceErrorUninitialized(ctx, JS_ATOM_NULL);\n                    goto exception;\n                }\n                set_value(ctx, var_refs[idx]->pvalue, sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_set_loc_uninitialized):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                set_value(ctx, &var_buf[idx], JS_UNINITIALIZED);\n            }\n            BREAK;\n        CASE(OP_get_loc_check):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                if (unlikely(JS_IsUninitialized(var_buf[idx]))) {\n                    JS_ThrowReferenceErrorUninitialized(ctx, JS_ATOM_NULL);\n                    goto exception;\n                }\n                sp[0] = JS_DupValue(ctx, var_buf[idx]);\n                sp++;\n            }\n            BREAK;\n        CASE(OP_put_loc_check):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                if (unlikely(JS_IsUninitialized(var_buf[idx]))) {\n                    JS_ThrowReferenceErrorUninitialized(ctx, JS_ATOM_NULL);\n                    goto exception;\n                }\n                set_value(ctx, &var_buf[idx], sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_put_loc_check_init):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                if (unlikely(!JS_IsUninitialized(var_buf[idx]))) {\n                    JS_ThrowReferenceError(ctx, \"'this' can be initialized only once\");\n                    goto exception;\n                }\n                set_value(ctx, &var_buf[idx], sp[-1]);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_close_loc):\n            {\n                int idx;\n                idx = get_u16(pc);\n                pc += 2;\n                close_lexical_var(ctx, sf, idx, FALSE);\n            }\n            BREAK;\n\n        CASE(OP_make_loc_ref):\n        CASE(OP_make_arg_ref):\n        CASE(OP_make_var_ref_ref):\n            {\n                JSVarRef *var_ref;\n                JSProperty *pr;\n                JSAtom atom;\n                int idx;\n                atom = get_u32(pc);\n                idx = get_u16(pc + 4);\n                pc += 6;\n                *sp++ = JS_NewObjectProto(ctx, JS_NULL);\n                if (unlikely(JS_IsException(sp[-1])))\n                    goto exception;\n                if (opcode == OP_make_var_ref_ref) {\n                    var_ref = var_refs[idx];\n                    var_ref->header.ref_count++;\n                } else {\n                    var_ref = get_var_ref(ctx, sf, idx, opcode == OP_make_arg_ref);\n                    if (!var_ref)\n                        goto exception;\n                }\n                pr = add_property(ctx, JS_VALUE_GET_OBJ(sp[-1]), atom,\n                                  JS_PROP_WRITABLE | JS_PROP_VARREF);\n                if (!pr) {\n                    free_var_ref(rt, var_ref);\n                    goto exception;\n                }\n                pr->u.var_ref = var_ref;\n                *sp++ = JS_AtomToValue(ctx, atom);\n            }\n            BREAK;\n        CASE(OP_make_var_ref):\n            {\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                if (JS_GetGlobalVarRef(ctx, atom, sp))\n                    goto exception;\n                sp += 2;\n            }\n            BREAK;\n\n        CASE(OP_goto):\n            pc += (int32_t)get_u32(pc);\n            if (unlikely(js_poll_interrupts(ctx)))\n                goto exception;\n            BREAK;\n#if SHORT_OPCODES\n        CASE(OP_goto16):\n            pc += (int16_t)get_u16(pc);\n            if (unlikely(js_poll_interrupts(ctx)))\n                goto exception;\n            BREAK;\n        CASE(OP_goto8):\n            pc += (int8_t)pc[0];\n            if (unlikely(js_poll_interrupts(ctx)))\n                goto exception;\n            BREAK;\n#endif\n        CASE(OP_if_true):\n            {\n                int res;\n                JSValue op1;\n\n                op1 = sp[-1];\n                pc += 4;\n                if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) {\n                    res = JS_VALUE_GET_INT(op1);\n                } else {\n                    res = JS_ToBoolFree(ctx, op1);\n                }\n                sp--;\n                if (res) {\n                    pc += (int32_t)get_u32(pc - 4) - 4;\n                }\n                if (unlikely(js_poll_interrupts(ctx)))\n                    goto exception;\n            }\n            BREAK;\n        CASE(OP_if_false):\n            {\n                int res;\n                JSValue op1;\n\n                op1 = sp[-1];\n                pc += 4;\n                if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) {\n                    res = JS_VALUE_GET_INT(op1);\n                } else {\n                    res = JS_ToBoolFree(ctx, op1);\n                }\n                sp--;\n                if (!res) {\n                    pc += (int32_t)get_u32(pc - 4) - 4;\n                }\n                if (unlikely(js_poll_interrupts(ctx)))\n                    goto exception;\n            }\n            BREAK;\n#if SHORT_OPCODES\n        CASE(OP_if_true8):\n            {\n                int res;\n                JSValue op1;\n\n                op1 = sp[-1];\n                pc += 1;\n                if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) {\n                    res = JS_VALUE_GET_INT(op1);\n                } else {\n                    res = JS_ToBoolFree(ctx, op1);\n                }\n                sp--;\n                if (res) {\n                    pc += (int8_t)pc[-1] - 1;\n                }\n                if (unlikely(js_poll_interrupts(ctx)))\n                    goto exception;\n            }\n            BREAK;\n        CASE(OP_if_false8):\n            {\n                int res;\n                JSValue op1;\n\n                op1 = sp[-1];\n                pc += 1;\n                if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) {\n                    res = JS_VALUE_GET_INT(op1);\n                } else {\n                    res = JS_ToBoolFree(ctx, op1);\n                }\n                sp--;\n                if (!res) {\n                    pc += (int8_t)pc[-1] - 1;\n                }\n                if (unlikely(js_poll_interrupts(ctx)))\n                    goto exception;\n            }\n            BREAK;\n#endif\n        CASE(OP_catch):\n            {\n                int32_t diff;\n                diff = get_u32(pc);\n                sp[0] = JS_NewCatchOffset(ctx, pc + diff - b->byte_code_buf);\n                sp++;\n                pc += 4;\n            }\n            BREAK;\n        CASE(OP_gosub):\n            {\n                int32_t diff;\n                diff = get_u32(pc);\n                /* XXX: should have a different tag to avoid security flaw */\n                sp[0] = JS_NewInt32(ctx, pc + 4 - b->byte_code_buf);\n                sp++;\n                pc += diff;\n            }\n            BREAK;\n        CASE(OP_ret):\n            {\n                JSValue op1;\n                uint32_t pos;\n                op1 = sp[-1];\n                if (unlikely(JS_VALUE_GET_TAG(op1) != JS_TAG_INT))\n                    goto ret_fail;\n                pos = JS_VALUE_GET_INT(op1);\n                if (unlikely(pos >= b->byte_code_len)) {\n                ret_fail:\n                    JS_ThrowInternalError(ctx, \"invalid ret value\");\n                    goto exception;\n                }\n                sp--;\n                pc = b->byte_code_buf + pos;\n            }\n            BREAK;\n\n        CASE(OP_for_in_start):\n            if (js_for_in_start(ctx, sp))\n                goto exception;\n            BREAK;\n        CASE(OP_for_in_next):\n            if (js_for_in_next(ctx, sp))\n                goto exception;\n            sp += 2;\n            BREAK;\n        CASE(OP_for_of_start):\n            if (js_for_of_start(ctx, sp, FALSE))\n                goto exception;\n            sp += 1;\n            *sp++ = JS_NewCatchOffset(ctx, 0);\n            BREAK;\n        CASE(OP_for_of_next):\n            {\n                int offset = -3 - pc[0];\n                pc += 1;\n                if (js_for_of_next(ctx, sp, offset))\n                    goto exception;\n                sp += 2;\n            }\n            BREAK;\n        CASE(OP_for_await_of_start):\n            if (js_for_of_start(ctx, sp, TRUE))\n                goto exception;\n            sp += 1;\n            *sp++ = JS_NewCatchOffset(ctx, 0);\n            BREAK;\n        CASE(OP_for_await_of_next):\n            if (js_for_await_of_next(ctx, sp))\n                goto exception;\n            sp += 1;\n            BREAK;\n        CASE(OP_iterator_get_value_done):\n            if (js_iterator_get_value_done(ctx, sp))\n                goto exception;\n            sp += 1;\n            BREAK;\n\n        CASE(OP_iterator_close):\n            /* iter_obj next catch_offset -> */\n            sp--; /* drop the catch offset to avoid getting caught by exception */\n            JS_FreeValue(ctx, sp[-1]); /* drop the next method */\n            sp--;\n            if (!JS_IsUndefined(sp[-1])) {\n                if (JS_IteratorClose(ctx, sp[-1], FALSE))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n            }\n            sp--;\n            BREAK;\n        CASE(OP_iterator_close_return):\n            {\n                JSValue ret_val;\n                /* iter_obj next catch_offset ... ret_val ->\n                   ret_eval iter_obj next catch_offset */\n                ret_val = *--sp;\n                while (sp > stack_buf &&\n                       JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_CATCH_OFFSET) {\n                    JS_FreeValue(ctx, *--sp);\n                }\n                if (unlikely(sp < stack_buf + 3)) {\n                    JS_ThrowInternalError(ctx, \"iterator_close_return\");\n                    JS_FreeValue(ctx, ret_val);\n                    goto exception;\n                }\n                sp[0] = sp[-1];\n                sp[-1] = sp[-2];\n                sp[-2] = sp[-3];\n                sp[-3] = ret_val;\n                sp++;\n            }\n            BREAK;\n\n        CASE(OP_async_iterator_close):\n            /* iter_obj next catch_offset -> value flag */\n            {\n                JSValue ret, method;\n                int ret_flag;\n                sp--; /* remove the catch offset */\n                method = JS_GetProperty(ctx, sp[-2], JS_ATOM_return);\n                if (JS_IsException(method))\n                    goto exception;\n                if (JS_IsUndefined(method) || JS_IsNull(method)) {\n                    ret = JS_UNDEFINED;\n                    ret_flag = TRUE;\n                } else {\n                    ret = JS_CallFree(ctx, method, sp[-2], 0, NULL);\n                    if (JS_IsException(ret))\n                        goto exception;\n                    if (!JS_IsObject(ret)) {\n                        JS_FreeValue(ctx, ret);\n                        JS_ThrowTypeErrorNotAnObject(ctx);\n                        goto exception;\n                    }\n                    ret_flag = FALSE;\n                }\n                JS_FreeValue(ctx, sp[-2]);\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-2] = ret;\n                sp[-1] = JS_NewBool(ctx, ret_flag);\n            }\n            BREAK;\n\n        CASE(OP_async_iterator_next):\n            /* stack: iter_obj next catch_offset val */\n            {\n                JSValue ret;\n                ret = JS_Call(ctx, sp[-3], sp[-4],\n                              1, (JSValueConst *)(sp - 1));\n                if (JS_IsException(ret))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = ret;\n            }\n            BREAK;\n\n        CASE(OP_async_iterator_get):\n            /* stack: iter_obj next catch_offset val */\n            {\n                JSValue method, ret;\n                BOOL ret_flag;\n                int flags;\n                flags = *pc++;\n                /* XXX: use another opcode such as OP_throw_var */\n                if (flags == 2) {\n                    JS_ThrowTypeError(ctx, \"iterator does not have a throw method\");\n                    goto exception;\n                }\n                method = JS_GetProperty(ctx, sp[-4], flags ? JS_ATOM_throw : JS_ATOM_return);\n                if (JS_IsException(method))\n                    goto exception;\n                if (JS_IsUndefined(method) || JS_IsNull(method)) {\n                    ret_flag = TRUE;\n                } else {\n                    ret = JS_CallFree(ctx, method, sp[-4],\n                                      1, (JSValueConst *)(sp - 1));\n                    if (JS_IsException(ret))\n                        goto exception;\n                    JS_FreeValue(ctx, sp[-1]);\n                    sp[-1] = ret;\n                    ret_flag = FALSE;\n                }\n                sp[0] = JS_NewBool(ctx, ret_flag);\n                sp += 1;\n            }\n            BREAK;\n\n        CASE(OP_lnot):\n            {\n                int res;\n                JSValue op1;\n\n                op1 = sp[-1];\n                if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) {\n                    res = JS_VALUE_GET_INT(op1) != 0;\n                } else {\n                    res = JS_ToBoolFree(ctx, op1);\n                }\n                sp[-1] = JS_NewBool(ctx, !res);\n            }\n            BREAK;\n\n        CASE(OP_get_field):\n            {\n                JSValue val;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                val = JS_GetProperty(ctx, sp[-1], atom);\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = val;\n            }\n            BREAK;\n\n        CASE(OP_get_field2):\n            {\n                JSValue val;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                val = JS_GetProperty(ctx, sp[-1], atom);\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n                *sp++ = val;\n            }\n            BREAK;\n\n        CASE(OP_put_field):\n            {\n                int ret;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                ret = JS_SetPropertyInternal(ctx, sp[-2], atom, sp[-1],\n                                             JS_PROP_THROW_STRICT);\n                JS_FreeValue(ctx, sp[-2]);\n                sp -= 2;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_private_symbol):\n            {\n                JSAtom atom;\n                JSValue val;\n                \n                atom = get_u32(pc);\n                pc += 4;\n                val = JS_NewSymbolFromAtom(ctx, atom, JS_ATOM_TYPE_PRIVATE);\n                if (JS_IsException(val))\n                    goto exception;\n                *sp++ = val;\n            }\n            BREAK;\n            \n        CASE(OP_get_private_field):\n            {\n                JSValue val;\n\n                val = JS_GetPrivateField(ctx, sp[-2], sp[-1]);\n                JS_FreeValue(ctx, sp[-1]);\n                JS_FreeValue(ctx, sp[-2]);\n                sp[-2] = val;\n                sp--;\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_put_private_field):\n            {\n                int ret;\n                ret = JS_SetPrivateField(ctx, sp[-3], sp[-1], sp[-2]);\n                JS_FreeValue(ctx, sp[-3]);\n                JS_FreeValue(ctx, sp[-1]);\n                sp -= 3;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_define_private_field):\n            {\n                int ret;\n                ret = JS_DefinePrivateField(ctx, sp[-3], sp[-2], sp[-1]);\n                JS_FreeValue(ctx, sp[-2]);\n                sp -= 2;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_define_field):\n            {\n                int ret;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                ret = JS_DefinePropertyValue(ctx, sp[-2], atom, sp[-1],\n                                             JS_PROP_C_W_E | JS_PROP_THROW);\n                sp--;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_set_name):\n            {\n                int ret;\n                JSAtom atom;\n                atom = get_u32(pc);\n                pc += 4;\n\n                ret = JS_DefineObjectName(ctx, sp[-1], atom, JS_PROP_CONFIGURABLE);\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n        CASE(OP_set_name_computed):\n            {\n                int ret;\n                ret = JS_DefineObjectNameComputed(ctx, sp[-1], sp[-2], JS_PROP_CONFIGURABLE);\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n        CASE(OP_set_proto):\n            {\n                JSValue proto;\n                proto = sp[-1];\n                if (JS_IsObject(proto) || JS_IsNull(proto)) {\n                    if (JS_SetPrototypeInternal(ctx, sp[-2], proto, TRUE) < 0)\n                        goto exception;\n                }\n                JS_FreeValue(ctx, proto);\n                sp--;\n            }\n            BREAK;\n        CASE(OP_set_home_object):\n            js_method_set_home_object(ctx, sp[-1], sp[-2]);\n            BREAK;\n        CASE(OP_define_method):\n        CASE(OP_define_method_computed):\n            {\n                JSValue getter, setter, value;\n                JSValueConst obj;\n                JSAtom atom;\n                int flags, ret, op_flags;\n                BOOL is_computed;\n#define OP_DEFINE_METHOD_METHOD 0\n#define OP_DEFINE_METHOD_GETTER 1\n#define OP_DEFINE_METHOD_SETTER 2\n#define OP_DEFINE_METHOD_ENUMERABLE 4\n\n                is_computed = (opcode == OP_define_method_computed);\n                if (is_computed) {\n                    atom = JS_ValueToAtom(ctx, sp[-2]);\n                    if (unlikely(atom == JS_ATOM_NULL))\n                        goto exception;\n                    opcode += OP_define_method - OP_define_method_computed;\n                } else {\n                    atom = get_u32(pc);\n                    pc += 4;\n                }\n                op_flags = *pc++;\n\n                obj = sp[-2 - is_computed];\n                flags = JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE |\n                    JS_PROP_HAS_ENUMERABLE | JS_PROP_THROW;\n                if (op_flags & OP_DEFINE_METHOD_ENUMERABLE)\n                    flags |= JS_PROP_ENUMERABLE;\n                op_flags &= 3;\n                value = JS_UNDEFINED;\n                getter = JS_UNDEFINED;\n                setter = JS_UNDEFINED;\n                if (op_flags == OP_DEFINE_METHOD_METHOD) {\n                    value = sp[-1];\n                    flags |= JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE;\n                } else if (op_flags == OP_DEFINE_METHOD_GETTER) {\n                    getter = sp[-1];\n                    flags |= JS_PROP_HAS_GET;\n                } else {\n                    setter = sp[-1];\n                    flags |= JS_PROP_HAS_SET;\n                }\n                ret = js_method_set_properties(ctx, sp[-1], atom, flags, obj);\n                if (ret >= 0) {\n                    ret = JS_DefineProperty(ctx, obj, atom, value,\n                                            getter, setter, flags);\n                }\n                JS_FreeValue(ctx, sp[-1]);\n                if (is_computed) {\n                    JS_FreeAtom(ctx, atom);\n                    JS_FreeValue(ctx, sp[-2]);\n                }\n                sp -= 1 + is_computed;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_define_class):\n        CASE(OP_define_class_computed):\n            {\n                int class_flags;\n                JSAtom atom;\n                \n                atom = get_u32(pc);\n                class_flags = pc[4];\n                pc += 5;\n                if (js_op_define_class(ctx, sp, atom, class_flags,\n                                       var_refs, sf,\n                                       (opcode == OP_define_class_computed)) < 0)\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_get_array_el):\n            {\n                JSValue val;\n\n                val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]);\n                JS_FreeValue(ctx, sp[-2]);\n                sp[-2] = val;\n                sp--;\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_get_array_el2):\n            {\n                JSValue val;\n\n                val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]);\n                sp[-1] = val;\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_get_ref_value):\n            {\n                JSValue val;\n                if (unlikely(JS_IsUndefined(sp[-2]))) {\n                    JSAtom atom = JS_ValueToAtom(ctx, sp[-1]);\n                    if (atom != JS_ATOM_NULL) {\n                        JS_ThrowReferenceErrorNotDefined(ctx, atom);\n                        JS_FreeAtom(ctx, atom);\n                    }\n                    goto exception;\n                }\n                val = JS_GetPropertyValue(ctx, sp[-2],\n                                          JS_DupValue(ctx, sp[-1]));\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n                sp[0] = val;\n                sp++;\n            }\n            BREAK;\n\n        CASE(OP_get_super_value):\n            {\n                JSValue val;\n                JSAtom atom;\n                atom = JS_ValueToAtom(ctx, sp[-1]);\n                if (unlikely(atom == JS_ATOM_NULL))\n                    goto exception;\n                val = JS_GetPropertyInternal(ctx, sp[-2], atom, sp[-3], FALSE);\n                JS_FreeAtom(ctx, atom);\n                if (unlikely(JS_IsException(val)))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                JS_FreeValue(ctx, sp[-2]);\n                JS_FreeValue(ctx, sp[-3]);\n                sp[-3] = val;\n                sp -= 2;\n            }\n            BREAK;\n\n        CASE(OP_put_array_el):\n            {\n                int ret;\n\n                ret = JS_SetPropertyValue(ctx, sp[-3], sp[-2], sp[-1], JS_PROP_THROW_STRICT);\n                JS_FreeValue(ctx, sp[-3]);\n                sp -= 3;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_put_ref_value):\n            {\n                int ret;\n                if (unlikely(JS_IsUndefined(sp[-3]))) {\n                    if (is_strict_mode(ctx)) {\n                        JSAtom atom = JS_ValueToAtom(ctx, sp[-2]);\n                        if (atom != JS_ATOM_NULL) {\n                            JS_ThrowReferenceErrorNotDefined(ctx, atom);\n                            JS_FreeAtom(ctx, atom);\n                        }\n                        goto exception;\n                    } else {\n                        sp[-3] = JS_DupValue(ctx, ctx->global_obj);\n                    }\n                }\n                ret = JS_SetPropertyValue(ctx, sp[-3], sp[-2], sp[-1], JS_PROP_THROW_STRICT);\n                JS_FreeValue(ctx, sp[-3]);\n                sp -= 3;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_put_super_value):\n            {\n                int ret;\n                JSAtom atom;\n                if (JS_VALUE_GET_TAG(sp[-3]) != JS_TAG_OBJECT) {\n                    JS_ThrowTypeErrorNotAnObject(ctx);\n                    goto exception;\n                }\n                atom = JS_ValueToAtom(ctx, sp[-2]);\n                if (unlikely(atom == JS_ATOM_NULL))\n                    goto exception;\n                ret = JS_SetPropertyGeneric(ctx, JS_VALUE_GET_OBJ(sp[-3]),\n                                            atom, sp[-1], sp[-4],\n                                            JS_PROP_THROW_STRICT);\n                JS_FreeAtom(ctx, atom);\n                JS_FreeValue(ctx, sp[-4]);\n                JS_FreeValue(ctx, sp[-3]);\n                JS_FreeValue(ctx, sp[-2]);\n                sp -= 4;\n                if (ret < 0)\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_define_array_el):\n            {\n                int ret;\n                ret = JS_DefinePropertyValueValue(ctx, sp[-3], JS_DupValue(ctx, sp[-2]), sp[-1],\n                                                  JS_PROP_C_W_E | JS_PROP_THROW);\n                sp -= 1;\n                if (unlikely(ret < 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_append):    /* array pos enumobj -- array pos */\n            {\n                if (js_append_enumerate(ctx, sp))\n                    goto exception;\n                JS_FreeValue(ctx, *--sp);\n            }\n            BREAK;\n\n        CASE(OP_copy_data_properties):    /* target source excludeList */\n            {\n                /* stack offsets (-1 based):\n                   2 bits for target,\n                   3 bits for source,\n                   2 bits for exclusionList */\n                int mask;\n\n                mask = *pc++;\n                if (JS_CopyDataProperties(ctx, sp[-1 - (mask & 3)],\n                                          sp[-1 - ((mask >> 2) & 7)],\n                                          sp[-1 - ((mask >> 5) & 7)], 0))\n                    goto exception;\n            }\n            BREAK;\n\n        CASE(OP_add):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    int64_t r;\n                    r = (int64_t)JS_VALUE_GET_INT(op1) + JS_VALUE_GET_INT(op2);\n                    if (unlikely((int)r != r))\n                        goto add_slow;\n                    sp[-2] = JS_NewInt32(ctx, r);\n                    sp--;\n                } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) {\n                    sp[-2] = __JS_NewFloat64(ctx, JS_VALUE_GET_FLOAT64(op1) +\n                                             JS_VALUE_GET_FLOAT64(op2));\n                    sp--;\n                } else {\n                add_slow:\n                    if (js_add_slow(ctx, sp))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n        CASE(OP_add_loc):\n            {\n                JSValue ops[2];\n                int idx;\n                idx = *pc;\n                pc += 1;\n\n                ops[0] = var_buf[idx];\n                ops[1] = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(ops[0], ops[1]))) {\n                    int64_t r;\n                    r = (int64_t)JS_VALUE_GET_INT(ops[0]) + JS_VALUE_GET_INT(ops[1]);\n                    if (unlikely((int)r != r))\n                        goto add_loc_slow;\n                    var_buf[idx] = JS_NewInt32(ctx, r);\n                    sp--;\n                } else if (JS_VALUE_GET_TAG(ops[0]) == JS_TAG_STRING) {\n                    sp--;\n                    ops[1] = JS_ToPrimitiveFree(ctx, ops[1], HINT_NONE);\n                    if (JS_IsException(ops[1])) {\n                        goto exception;\n                    }\n                    /* XXX: should not modify the variable in case of\n                       exception */\n                    ops[0] = JS_ConcatString(ctx, ops[0], ops[1]);\n                    if (JS_IsException(ops[0])) {\n                        var_buf[idx] = JS_UNDEFINED;\n                        goto exception;\n                    }\n                    var_buf[idx] = ops[0];\n                } else {\n                add_loc_slow:\n                    /* XXX: should not modify the variable in case of\n                       exception */\n                    sp--;\n                    /* In case of exception, js_add_slow frees ops[0]\n                       and ops[1]. */\n                    /* XXX: change API */\n                    if (js_add_slow(ctx, ops + 2)) {\n                        var_buf[idx] = JS_UNDEFINED;\n                        goto exception;\n                    }\n                    var_buf[idx] = ops[0];\n                }\n            }\n            BREAK;\n        CASE(OP_sub):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    int64_t r;\n                    r = (int64_t)JS_VALUE_GET_INT(op1) - JS_VALUE_GET_INT(op2);\n                    if (unlikely((int)r != r))\n                        goto binary_arith_slow;\n                    sp[-2] = JS_NewInt32(ctx, r);\n                    sp--;\n                } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) {\n                    sp[-2] = __JS_NewFloat64(ctx, JS_VALUE_GET_FLOAT64(op1) -\n                                             JS_VALUE_GET_FLOAT64(op2));\n                    sp--;\n                } else {\n                    goto binary_arith_slow;\n                }\n            }\n            BREAK;\n        CASE(OP_mul):\n            {\n                JSValue op1, op2;\n                double d;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    int32_t v1, v2;\n                    int64_t r;\n                    v1 = JS_VALUE_GET_INT(op1);\n                    v2 = JS_VALUE_GET_INT(op2);\n                    r = (int64_t)v1 * v2;\n                    if (unlikely((int)r != r)) {\n#ifdef CONFIG_BIGNUM\n                        if (unlikely(sf->js_mode & JS_MODE_MATH) &&\n                            (r < -MAX_SAFE_INTEGER || r > MAX_SAFE_INTEGER))\n                            goto binary_arith_slow;\n#endif\n                        d = (double)r;\n                        goto mul_fp_res;\n                    }\n                    /* need to test zero case for -0 result */\n                    if (unlikely(r == 0 && (v1 | v2) < 0)) {\n                        d = -0.0;\n                        goto mul_fp_res;\n                    }\n                    sp[-2] = JS_NewInt32(ctx, r);\n                    sp--;\n                } else if (JS_VALUE_IS_BOTH_FLOAT(op1, op2)) {\n#ifdef CONFIG_BIGNUM\n                    if (unlikely(sf->js_mode & JS_MODE_MATH))\n                        goto binary_arith_slow;\n#endif\n                    d = JS_VALUE_GET_FLOAT64(op1) * JS_VALUE_GET_FLOAT64(op2);\n                mul_fp_res:\n                    sp[-2] = __JS_NewFloat64(ctx, d);\n                    sp--;\n                } else {\n                    goto binary_arith_slow;\n                }\n            }\n            BREAK;\n        CASE(OP_div):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    int v1, v2;\n                    if (unlikely(sf->js_mode & JS_MODE_MATH))\n                        goto binary_arith_slow;\n                    v1 = JS_VALUE_GET_INT(op1);\n                    v2 = JS_VALUE_GET_INT(op2);\n                    sp[-2] = JS_NewFloat64(ctx, (double)v1 / (double)v2);\n                    sp--;\n                } else {\n                    goto binary_arith_slow;\n                }\n            }\n            BREAK;\n        CASE(OP_mod):\n#ifdef CONFIG_BIGNUM\n        CASE(OP_math_mod):\n#endif\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    int v1, v2, r;\n                    v1 = JS_VALUE_GET_INT(op1);\n                    v2 = JS_VALUE_GET_INT(op2);\n                    /* We must avoid v2 = 0, v1 = INT32_MIN and v2 =\n                       -1 and the cases where the result is -0. */\n                    if (unlikely(v1 < 0 || v2 <= 0))\n                        goto binary_arith_slow;\n                    r = v1 % v2;\n                    sp[-2] = JS_NewInt32(ctx, r);\n                    sp--;\n                } else {\n                    goto binary_arith_slow;\n                }\n            }\n            BREAK;\n        CASE(OP_pow):\n        binary_arith_slow:\n            if (js_binary_arith_slow(ctx, sp, opcode))\n                goto exception;\n            sp--;\n            BREAK;\n\n        CASE(OP_plus):\n            {\n                JSValue op1;\n                uint32_t tag;\n                op1 = sp[-1];\n                tag = JS_VALUE_GET_TAG(op1);\n                if (tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag)) {\n                } else {\n                    if (js_unary_arith_slow(ctx, sp, opcode))\n                        goto exception;\n                }\n            }\n            BREAK;\n        CASE(OP_neg):\n            {\n                JSValue op1;\n                uint32_t tag;\n                int val;\n                double d;\n                op1 = sp[-1];\n                tag = JS_VALUE_GET_TAG(op1);\n                if (tag == JS_TAG_INT) {\n                    val = JS_VALUE_GET_INT(op1);\n                    /* Note: -0 cannot be expressed as integer */\n                    if (unlikely(val == 0)) {\n                        d = -0.0;\n                        goto neg_fp_res;\n                    }\n                    if (unlikely(val == INT32_MIN)) {\n                        d = -(double)val;\n                        goto neg_fp_res;\n                    }\n                    sp[-1] = JS_NewInt32(ctx, -val);\n                } else if (JS_TAG_IS_FLOAT64(tag)) {\n                    d = -JS_VALUE_GET_FLOAT64(op1);\n                neg_fp_res:\n                    sp[-1] = __JS_NewFloat64(ctx, d);\n                } else {\n                    if (js_unary_arith_slow(ctx, sp, opcode))\n                        goto exception;\n                }\n            }\n            BREAK;\n        CASE(OP_inc):\n            {\n                JSValue op1;\n                int val;\n                op1 = sp[-1];\n                if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {\n                    val = JS_VALUE_GET_INT(op1);\n                    if (unlikely(val == INT32_MAX))\n                        goto inc_slow;\n                    sp[-1] = JS_NewInt32(ctx, val + 1);\n                } else {\n                inc_slow:\n                    if (js_unary_arith_slow(ctx, sp, opcode))\n                        goto exception;\n                }\n            }\n            BREAK;\n        CASE(OP_dec):\n            {\n                JSValue op1;\n                int val;\n                op1 = sp[-1];\n                if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {\n                    val = JS_VALUE_GET_INT(op1);\n                    if (unlikely(val == INT32_MIN))\n                        goto dec_slow;\n                    sp[-1] = JS_NewInt32(ctx, val - 1);\n                } else {\n                dec_slow:\n                    if (js_unary_arith_slow(ctx, sp, opcode))\n                        goto exception;\n                }\n            }\n            BREAK;\n        CASE(OP_post_inc):\n        CASE(OP_post_dec):\n            if (js_post_inc_slow(ctx, sp, opcode))\n                goto exception;\n            sp++;\n            BREAK;\n        CASE(OP_inc_loc):\n            {\n                JSValue op1;\n                int val;\n                int idx;\n                idx = *pc;\n                pc += 1;\n\n                op1 = var_buf[idx];\n                if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {\n                    val = JS_VALUE_GET_INT(op1);\n                    if (unlikely(val == INT32_MAX))\n                        goto inc_loc_slow;\n                    var_buf[idx] = JS_NewInt32(ctx, val + 1);\n                } else {\n                inc_loc_slow:\n                    if (js_unary_arith_slow(ctx, var_buf + idx + 1, OP_inc))\n                        goto exception;\n                }\n            }\n            BREAK;\n        CASE(OP_dec_loc):\n            {\n                JSValue op1;\n                int val;\n                int idx;\n                idx = *pc;\n                pc += 1;\n\n                op1 = var_buf[idx];\n                if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {\n                    val = JS_VALUE_GET_INT(op1);\n                    if (unlikely(val == INT32_MIN))\n                        goto dec_loc_slow;\n                    var_buf[idx] = JS_NewInt32(ctx, val - 1);\n                } else {\n                dec_loc_slow:\n                    if (js_unary_arith_slow(ctx, var_buf + idx + 1, OP_dec))\n                        goto exception;\n                }\n            }\n            BREAK;\n        CASE(OP_not):\n            {\n                JSValue op1;\n                op1 = sp[-1];\n                if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {\n                    sp[-1] = JS_NewInt32(ctx, ~JS_VALUE_GET_INT(op1));\n                } else {\n                    if (js_not_slow(ctx, sp))\n                        goto exception;\n                }\n            }\n            BREAK;\n\n        CASE(OP_shl):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    uint32_t v1, v2;\n                    v1 = JS_VALUE_GET_INT(op1);\n                    v2 = JS_VALUE_GET_INT(op2);\n#ifdef CONFIG_BIGNUM\n                    {\n                        int64_t r;\n                        if (unlikely(sf->js_mode & JS_MODE_MATH)) {\n                            if (v2 > 0x1f)\n                                goto shl_slow;\n                            r = (int64_t)v1 << v2;\n                            if ((int)r != r)\n                                goto shl_slow;\n                        } else {\n                            v2 &= 0x1f;\n                        }\n                    }\n#else\n                    v2 &= 0x1f;\n#endif\n                    sp[-2] = JS_NewInt32(ctx, v1 << v2);\n                    sp--;\n                } else {\n#ifdef CONFIG_BIGNUM\n                shl_slow:\n#endif\n                    if (js_binary_logic_slow(ctx, sp, opcode))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n        CASE(OP_shr):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    uint32_t v2;\n                    v2 = JS_VALUE_GET_INT(op2);\n                    /* v1 >>> v2 retains its JS semantics if CONFIG_BIGNUM */\n                    v2 &= 0x1f;\n                    sp[-2] = JS_NewUint32(ctx,\n                                          (uint32_t)JS_VALUE_GET_INT(op1) >>\n                                          v2);\n                    sp--;\n                } else {\n                    if (js_shr_slow(ctx, sp))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n        CASE(OP_sar):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    uint32_t v2;\n                    v2 = JS_VALUE_GET_INT(op2);\n#ifdef CONFIG_BIGNUM\n                    if (unlikely(v2 > 0x1f)) {\n                        if (unlikely(sf->js_mode & JS_MODE_MATH))\n                            goto sar_slow;\n                        else\n                            v2 &= 0x1f;\n                    }\n#else\n                    v2 &= 0x1f;\n#endif\n                    sp[-2] = JS_NewInt32(ctx,\n                                          (int)JS_VALUE_GET_INT(op1) >> v2);\n                    sp--;\n                } else {\n#ifdef CONFIG_BIGNUM\n                sar_slow:\n#endif\n                    if (js_binary_logic_slow(ctx, sp, opcode))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n        CASE(OP_and):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    sp[-2] = JS_NewInt32(ctx,\n                                         JS_VALUE_GET_INT(op1) &\n                                         JS_VALUE_GET_INT(op2));\n                    sp--;\n                } else {\n                    if (js_binary_logic_slow(ctx, sp, opcode))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n        CASE(OP_or):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    sp[-2] = JS_NewInt32(ctx,\n                                         JS_VALUE_GET_INT(op1) |\n                                         JS_VALUE_GET_INT(op2));\n                    sp--;\n                } else {\n                    if (js_binary_logic_slow(ctx, sp, opcode))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n        CASE(OP_xor):\n            {\n                JSValue op1, op2;\n                op1 = sp[-2];\n                op2 = sp[-1];\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {\n                    sp[-2] = JS_NewInt32(ctx,\n                                         JS_VALUE_GET_INT(op1) ^\n                                         JS_VALUE_GET_INT(op2));\n                    sp--;\n                } else {\n                    if (js_binary_logic_slow(ctx, sp, opcode))\n                        goto exception;\n                    sp--;\n                }\n            }\n            BREAK;\n\n\n#define OP_CMP(opcode, binary_op, slow_call)              \\\n            CASE(opcode):                                 \\\n                {                                         \\\n                JSValue op1, op2;                         \\\n                op1 = sp[-2];                             \\\n                op2 = sp[-1];                                   \\\n                if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {           \\\n                    sp[-2] = JS_NewBool(ctx, JS_VALUE_GET_INT(op1) binary_op JS_VALUE_GET_INT(op2)); \\\n                    sp--;                                               \\\n                } else {                                                \\\n                    if (slow_call)                                      \\\n                        goto exception;                                 \\\n                    sp--;                                               \\\n                }                                                       \\\n                }                                                       \\\n            BREAK\n\n            OP_CMP(OP_lt, <, js_relational_slow(ctx, sp, opcode));\n            OP_CMP(OP_lte, <=, js_relational_slow(ctx, sp, opcode));\n            OP_CMP(OP_gt, >, js_relational_slow(ctx, sp, opcode));\n            OP_CMP(OP_gte, >=, js_relational_slow(ctx, sp, opcode));\n            OP_CMP(OP_eq, ==, js_eq_slow(ctx, sp, 0));\n            OP_CMP(OP_neq, !=, js_eq_slow(ctx, sp, 1));\n            OP_CMP(OP_strict_eq, ==, js_strict_eq_slow(ctx, sp, 0));\n            OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, 1));\n\n#ifdef CONFIG_BIGNUM\n        CASE(OP_mul_pow10):\n            if (rt->bigfloat_ops.mul_pow10(ctx, sp))\n                goto exception;\n            sp--;\n            BREAK;\n#endif\n        CASE(OP_in):\n            if (js_operator_in(ctx, sp))\n                goto exception;\n            sp--;\n            BREAK;\n        CASE(OP_instanceof):\n            if (js_operator_instanceof(ctx, sp))\n                goto exception;\n            sp--;\n            BREAK;\n        CASE(OP_typeof):\n            {\n                JSValue op1;\n                JSAtom atom;\n\n                op1 = sp[-1];\n                atom = js_operator_typeof(ctx, op1);\n                JS_FreeValue(ctx, op1);\n                sp[-1] = JS_AtomToString(ctx, atom);\n            }\n            BREAK;\n        CASE(OP_delete):\n            if (js_operator_delete(ctx, sp))\n                goto exception;\n            sp--;\n            BREAK;\n        CASE(OP_delete_var):\n            {\n                JSAtom atom;\n                int ret;\n\n                atom = get_u32(pc);\n                pc += 4;\n\n                ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0);\n                if (unlikely(ret < 0))\n                    goto exception;\n                *sp++ = JS_NewBool(ctx, ret);\n            }\n            BREAK;\n\n        CASE(OP_to_object):\n            if (JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_OBJECT) {\n                ret_val = JS_ToObject(ctx, sp[-1]);\n                if (JS_IsException(ret_val))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = ret_val;\n            }\n            BREAK;\n\n        CASE(OP_to_propkey):\n            switch (JS_VALUE_GET_TAG(sp[-1])) {\n            case JS_TAG_INT:\n            case JS_TAG_STRING:\n            case JS_TAG_SYMBOL:\n                break;\n            default:\n                ret_val = JS_ToPropertyKey(ctx, sp[-1]);\n                if (JS_IsException(ret_val))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = ret_val;\n                break;\n            }\n            BREAK;\n\n        CASE(OP_to_propkey2):\n            /* must be tested first */\n            if (unlikely(JS_IsUndefined(sp[-2]) || JS_IsNull(sp[-2]))) {\n                JS_ThrowTypeError(ctx, \"value has no property\");\n                goto exception;\n            }\n            switch (JS_VALUE_GET_TAG(sp[-1])) {\n            case JS_TAG_INT:\n            case JS_TAG_STRING:\n            case JS_TAG_SYMBOL:\n                break;\n            default:\n                ret_val = JS_ToPropertyKey(ctx, sp[-1]);\n                if (JS_IsException(ret_val))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = ret_val;\n                break;\n            }\n            BREAK;\n#if 0\n        CASE(OP_to_string):\n            if (JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_STRING) {\n                ret_val = JS_ToString(ctx, sp[-1]);\n                if (JS_IsException(ret_val))\n                    goto exception;\n                JS_FreeValue(ctx, sp[-1]);\n                sp[-1] = ret_val;\n            }\n            BREAK;\n#endif\n        CASE(OP_with_get_var):\n        CASE(OP_with_put_var):\n        CASE(OP_with_delete_var):\n        CASE(OP_with_make_ref):\n        CASE(OP_with_get_ref):\n        CASE(OP_with_get_ref_undef):\n            {\n                JSAtom atom;\n                int32_t diff;\n                JSValue obj, val;\n                int ret, is_with;\n                atom = get_u32(pc);\n                diff = get_u32(pc + 4);\n                is_with = pc[8];\n                pc += 9;\n\n                obj = sp[-1];\n                ret = JS_HasProperty(ctx, obj, atom);\n                if (unlikely(ret < 0))\n                    goto exception;\n                if (ret) {\n                    if (is_with) {\n                        ret = js_has_unscopable(ctx, obj, atom);\n                        if (unlikely(ret < 0))\n                            goto exception;\n                        if (ret)\n                            goto no_with;\n                    }\n                    switch (opcode) {\n                    case OP_with_get_var:\n                        val = JS_GetProperty(ctx, obj, atom);\n                        if (unlikely(JS_IsException(val)))\n                            goto exception;\n                        set_value(ctx, &sp[-1], val);\n                        break;\n                    case OP_with_put_var:\n                        ret = JS_SetPropertyInternal(ctx, obj, atom, sp[-2],\n                                                     JS_PROP_THROW_STRICT);\n                        JS_FreeValue(ctx, sp[-1]);\n                        sp -= 2;\n                        if (unlikely(ret < 0))\n                            goto exception;\n                        break;\n                    case OP_with_delete_var:\n                        ret = JS_DeleteProperty(ctx, obj, atom, 0);\n                        if (unlikely(ret < 0))\n                            goto exception;\n                        JS_FreeValue(ctx, sp[-1]);\n                        sp[-1] = JS_NewBool(ctx, ret);\n                        break;\n                    case OP_with_make_ref:\n                        /* produce a pair object/propname on the stack */\n                        *sp++ = JS_AtomToValue(ctx, atom);\n                        break;\n                    case OP_with_get_ref:\n                        /* produce a pair object/method on the stack */\n                        val = JS_GetProperty(ctx, obj, atom);\n                        if (unlikely(JS_IsException(val)))\n                            goto exception;\n                        *sp++ = val;\n                        break;\n                    case OP_with_get_ref_undef:\n                        /* produce a pair undefined/function on the stack */\n                        val = JS_GetProperty(ctx, obj, atom);\n                        if (unlikely(JS_IsException(val)))\n                            goto exception;\n                        JS_FreeValue(ctx, sp[-1]);\n                        sp[-1] = JS_UNDEFINED;\n                        *sp++ = val;\n                        break;\n                    }\n                    pc += diff - 5;\n                } else {\n                no_with:\n                    /* if not jumping, drop the object argument */\n                    JS_FreeValue(ctx, sp[-1]);\n                    sp--;\n                }\n            }\n            BREAK;\n\n        CASE(OP_await):\n            ret_val = JS_NewInt32(ctx, FUNC_RET_AWAIT);\n            goto done_generator;\n        CASE(OP_yield):\n            ret_val = JS_NewInt32(ctx, FUNC_RET_YIELD);\n            goto done_generator;\n        CASE(OP_yield_star):\n        CASE(OP_async_yield_star):\n            ret_val = JS_NewInt32(ctx, FUNC_RET_YIELD_STAR);\n            goto done_generator;\n        CASE(OP_return_async):\n        CASE(OP_initial_yield):\n            ret_val = JS_UNDEFINED;\n            goto done_generator;\n\n        CASE(OP_nop):\n            BREAK;\n        CASE(OP_is_undefined_or_null):\n            if (JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_UNDEFINED ||\n                JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_NULL) {\n                goto set_true;\n            } else {\n                goto free_and_set_false;\n            }\n#if SHORT_OPCODES\n        CASE(OP_is_undefined):\n            if (JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_UNDEFINED) {\n                goto set_true;\n            } else {\n                goto free_and_set_false;\n            }\n        CASE(OP_is_null):\n            if (JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_NULL) {\n                goto set_true;\n            } else {\n                goto free_and_set_false;\n            }\n        CASE(OP_is_function):\n            if (js_operator_typeof(ctx, sp[-1]) == JS_ATOM_function) {\n                goto free_and_set_true;\n            } else {\n                goto free_and_set_false;\n            }\n        free_and_set_true:\n            JS_FreeValue(ctx, sp[-1]);\n#endif\n        set_true:\n            sp[-1] = JS_TRUE;\n            BREAK;\n        free_and_set_false:\n            JS_FreeValue(ctx, sp[-1]);\n            sp[-1] = JS_FALSE;\n            BREAK;\n        CASE(OP_invalid):\n        DEFAULT:\n            JS_ThrowInternalError(ctx, \"invalid opcode: pc=%u opcode=0x%02x\",\n                                  (int)(pc - b->byte_code_buf - 1), opcode);\n            goto exception;\n        }\n    }\n exception:\n    if (is_backtrace_needed(ctx, rt->current_exception)) {\n        /* add the backtrace information now (it is not done\n           before if the exception happens in a bytecode\n           operation */\n        sf->cur_pc = pc;\n        build_backtrace(ctx, rt->current_exception, NULL, 0, 0);\n    }\n    if (!JS_IsUncatchableError(ctx, rt->current_exception)) {\n        while (sp > stack_buf) {\n            JSValue val = *--sp;\n            JS_FreeValue(ctx, val);\n            if (JS_VALUE_GET_TAG(val) == JS_TAG_CATCH_OFFSET) {\n                int pos = JS_VALUE_GET_INT(val);\n                if (pos == 0) {\n                    /* enumerator: close it with a throw */\n                    JS_FreeValue(ctx, sp[-1]); /* drop the next method */\n                    sp--;\n                    JS_IteratorClose(ctx, sp[-1], TRUE);\n                } else {\n                    *sp++ = rt->current_exception;\n                    rt->current_exception = JS_NULL;\n                    pc = b->byte_code_buf + pos;\n                    goto restart;\n                }\n            }\n        }\n    }\n    ret_val = JS_EXCEPTION;\n    /* the local variables are freed by the caller in the generator\n       case. Hence the label 'done' should never be reached in a\n       generator function. */\n    if (b->func_kind != JS_FUNC_NORMAL) {\n    done_generator:\n        sf->cur_pc = pc;\n        sf->cur_sp = sp;\n    } else {\n    done:\n        if (unlikely(!list_empty(&sf->var_ref_list))) {\n            /* variable references reference the stack: must close them */\n            close_var_refs(rt, sf);\n        }\n        /* free the local variables and stack */\n        for(pval = local_buf; pval < sp; pval++) {\n            JS_FreeValue(ctx, *pval);\n        }\n    }\n    rt->current_stack_frame = sf->prev_frame;\n    return ret_val;\n}\n\nJSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj,\n                int argc, JSValueConst *argv)\n{\n    return JS_CallInternal(ctx, func_obj, this_obj, JS_UNDEFINED,\n                           argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV);\n}\n\nstatic JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueConst this_obj,\n                           int argc, JSValueConst *argv)\n{\n    JSValue res = JS_CallInternal(ctx, func_obj, this_obj, JS_UNDEFINED,\n                                  argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV);\n    JS_FreeValue(ctx, func_obj);\n    return res;\n}\n\n/* warning: the refcount of the context is not incremented. Return\n   NULL in case of exception (case of revoked proxy only) */\nstatic JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValueConst func_obj)\n{\n    JSObject *p;\n    JSContext *realm;\n    \n    if (JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)\n        return ctx;\n    p = JS_VALUE_GET_OBJ(func_obj);\n    switch(p->class_id) {\n    case JS_CLASS_C_FUNCTION:\n        realm = p->u.cfunc.realm;\n        break;\n    case JS_CLASS_BYTECODE_FUNCTION:\n    case JS_CLASS_GENERATOR_FUNCTION:\n    case JS_CLASS_ASYNC_FUNCTION:\n    case JS_CLASS_ASYNC_GENERATOR_FUNCTION:\n        {\n            JSFunctionBytecode *b;\n            b = p->u.func.function_bytecode;\n            realm = b->realm;\n        }\n        break;\n    case JS_CLASS_PROXY:\n        {\n            JSProxyData *s = p->u.opaque;\n            if (!s)\n                return ctx;\n            if (s->is_revoked) {\n                JS_ThrowTypeErrorRevokedProxy(ctx);\n                return NULL;\n            } else {\n                realm = JS_GetFunctionRealm(ctx, s->target);\n            }\n        }\n        break;\n    case JS_CLASS_BOUND_FUNCTION:\n        {\n            JSBoundFunction *bf = p->u.bound_function;\n            realm = JS_GetFunctionRealm(ctx, bf->func_obj);\n        }\n        break;\n    default:\n        realm = ctx;\n        break;\n    }\n    return realm;\n}\n\nstatic JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor,\n                                   int class_id)\n{\n    JSValue proto, obj;\n    JSContext *realm;\n    \n    if (JS_IsUndefined(ctor)) {\n        proto = JS_DupValue(ctx, ctx->class_proto[class_id]);\n    } else {\n        proto = JS_GetProperty(ctx, ctor, JS_ATOM_prototype);\n        if (JS_IsException(proto))\n            return proto;\n        if (!JS_IsObject(proto)) {\n            JS_FreeValue(ctx, proto);\n            realm = JS_GetFunctionRealm(ctx, ctor);\n            if (!realm)\n                return JS_EXCEPTION;\n            proto = JS_DupValue(ctx, realm->class_proto[class_id]);\n        }\n    }\n    obj = JS_NewObjectProtoClass(ctx, proto, class_id);\n    JS_FreeValue(ctx, proto);\n    return obj;\n}\n\n/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */\nstatic JSValue JS_CallConstructorInternal(JSContext *ctx,\n                                          JSValueConst func_obj,\n                                          JSValueConst new_target,\n                                          int argc, JSValue *argv, int flags)\n{\n    JSObject *p;\n    JSFunctionBytecode *b;\n\n    if (js_poll_interrupts(ctx))\n        return JS_EXCEPTION;\n    flags |= JS_CALL_FLAG_CONSTRUCTOR;\n    if (unlikely(JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT))\n        goto not_a_function;\n    p = JS_VALUE_GET_OBJ(func_obj);\n    if (unlikely(!p->is_constructor))\n        return JS_ThrowTypeError(ctx, \"not a constructor\");\n    if (unlikely(p->class_id != JS_CLASS_BYTECODE_FUNCTION)) {\n        JSClassCall *call_func;\n        call_func = ctx->rt->class_array[p->class_id].call;\n        if (!call_func) {\n        not_a_function:\n            return JS_ThrowTypeError(ctx, \"not a function\");\n        }\n        return call_func(ctx, func_obj, new_target, argc,\n                         (JSValueConst *)argv, flags);\n    }\n\n    b = p->u.func.function_bytecode;\n    if (b->is_derived_class_constructor) {\n        return JS_CallInternal(ctx, func_obj, JS_UNDEFINED, new_target, argc, argv, flags);\n    } else {\n        JSValue obj, ret;\n        /* legacy constructor behavior */\n        obj = js_create_from_ctor(ctx, new_target, JS_CLASS_OBJECT);\n        if (JS_IsException(obj))\n            return JS_EXCEPTION;\n        ret = JS_CallInternal(ctx, func_obj, obj, new_target, argc, argv, flags);\n        if (JS_VALUE_GET_TAG(ret) == JS_TAG_OBJECT ||\n            JS_IsException(ret)) {\n            JS_FreeValue(ctx, obj);\n            return ret;\n        } else {\n            JS_FreeValue(ctx, ret);\n            return obj;\n        }\n    }\n}\n\nJSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,\n                            JSValueConst new_target,\n                            int argc, JSValueConst *argv)\n{\n    return JS_CallConstructorInternal(ctx, func_obj, new_target,\n                                      argc, (JSValue *)argv,\n                                      JS_CALL_FLAG_COPY_ARGV);\n}\n\nJSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,\n                           int argc, JSValueConst *argv)\n{\n    return JS_CallConstructorInternal(ctx, func_obj, func_obj,\n                                      argc, (JSValue *)argv,\n                                      JS_CALL_FLAG_COPY_ARGV);\n}\n\nJSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,\n                  int argc, JSValueConst *argv)\n{\n    JSValue func_obj;\n    func_obj = JS_GetProperty(ctx, this_val, atom);\n    if (JS_IsException(func_obj))\n        return func_obj;\n    return JS_CallFree(ctx, func_obj, this_val, argc, argv);\n}\n\nstatic JSValue JS_InvokeFree(JSContext *ctx, JSValue this_val, JSAtom atom,\n                             int argc, JSValueConst *argv)\n{\n    JSValue res = JS_Invoke(ctx, this_val, atom, argc, argv);\n    JS_FreeValue(ctx, this_val);\n    return res;\n}\n\n/* JSAsyncFunctionState (used by generator and async functions) */\nstatic __exception int async_func_init(JSContext *ctx, JSAsyncFunctionState *s,\n                                       JSValueConst func_obj, JSValueConst this_obj,\n                                       int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    JSFunctionBytecode *b;\n    JSStackFrame *sf;\n    int local_count, i, arg_buf_len, n;\n\n    sf = &s->frame;\n    init_list_head(&sf->var_ref_list);\n    p = JS_VALUE_GET_OBJ(func_obj);\n    b = p->u.func.function_bytecode;\n    sf->js_mode = b->js_mode;\n    sf->cur_pc = b->byte_code_buf;\n    arg_buf_len = max_int(b->arg_count, argc);\n    local_count = arg_buf_len + b->var_count + b->stack_size;\n    sf->arg_buf = js_malloc(ctx, sizeof(JSValue) * max_int(local_count, 1));\n    if (!sf->arg_buf)\n        return -1;\n    sf->cur_func = JS_DupValue(ctx, func_obj);\n    s->this_val = JS_DupValue(ctx, this_obj);\n    s->argc = argc;\n    sf->arg_count = arg_buf_len;\n    sf->var_buf = sf->arg_buf + arg_buf_len;\n    sf->cur_sp = sf->var_buf + b->var_count;\n    for(i = 0; i < argc; i++)\n        sf->arg_buf[i] = JS_DupValue(ctx, argv[i]);\n    n = arg_buf_len + b->var_count;\n    for(i = argc; i < n; i++)\n        sf->arg_buf[i] = JS_UNDEFINED;\n    return 0;\n}\n\nstatic void async_func_mark(JSRuntime *rt, JSAsyncFunctionState *s,\n                            JS_MarkFunc *mark_func)\n{\n    JSStackFrame *sf;\n    JSValue *sp;\n\n    sf = &s->frame;\n    JS_MarkValue(rt, sf->cur_func, mark_func);\n    JS_MarkValue(rt, s->this_val, mark_func);\n    if (sf->cur_sp) {\n        /* if the function is running, cur_sp is not known so we\n           cannot mark the stack. Marking the variables is not needed\n           because a running function cannot be part of a removable\n           cycle */\n        for(sp = sf->arg_buf; sp < sf->cur_sp; sp++)\n            JS_MarkValue(rt, *sp, mark_func);\n    }\n}\n\nstatic void async_func_free(JSRuntime *rt, JSAsyncFunctionState *s)\n{\n    JSStackFrame *sf;\n    JSValue *sp;\n\n    sf = &s->frame;\n\n    /* close the closure variables. */\n    close_var_refs(rt, sf);\n    \n    if (sf->arg_buf) {\n        /* cannot free the function if it is running */\n        assert(sf->cur_sp != NULL);\n        for(sp = sf->arg_buf; sp < sf->cur_sp; sp++) {\n            JS_FreeValueRT(rt, *sp);\n        }\n        js_free_rt(rt, sf->arg_buf);\n    }\n    JS_FreeValueRT(rt, sf->cur_func);\n    JS_FreeValueRT(rt, s->this_val);\n}\n\nstatic JSValue async_func_resume(JSContext *ctx, JSAsyncFunctionState *s)\n{\n    JSValue func_obj;\n\n    if (js_check_stack_overflow(ctx->rt, 0))\n        return JS_ThrowStackOverflow(ctx);\n\n    /* the tag does not matter provided it is not an object */\n    func_obj = JS_MKPTR(JS_TAG_INT, s);\n    return JS_CallInternal(ctx, func_obj, s->this_val, JS_UNDEFINED,\n                           s->argc, s->frame.arg_buf, JS_CALL_FLAG_GENERATOR);\n}\n\n\n/* Generators */\n\ntypedef enum JSGeneratorStateEnum {\n    JS_GENERATOR_STATE_SUSPENDED_START,\n    JS_GENERATOR_STATE_SUSPENDED_YIELD,\n    JS_GENERATOR_STATE_SUSPENDED_YIELD_STAR,\n    JS_GENERATOR_STATE_EXECUTING,\n    JS_GENERATOR_STATE_COMPLETED,\n} JSGeneratorStateEnum;\n\ntypedef struct JSGeneratorData {\n    JSGeneratorStateEnum state;\n    JSAsyncFunctionState func_state;\n} JSGeneratorData;\n\nstatic void free_generator_stack_rt(JSRuntime *rt, JSGeneratorData *s)\n{\n    if (s->state == JS_GENERATOR_STATE_COMPLETED)\n        return;\n    async_func_free(rt, &s->func_state);\n    s->state = JS_GENERATOR_STATE_COMPLETED;\n}\n\nstatic void js_generator_finalizer(JSRuntime *rt, JSValue obj)\n{\n    JSGeneratorData *s = JS_GetOpaque(obj, JS_CLASS_GENERATOR);\n\n    if (s) {\n        free_generator_stack_rt(rt, s);\n        js_free_rt(rt, s);\n    }\n}\n\nstatic void free_generator_stack(JSContext *ctx, JSGeneratorData *s)\n{\n    free_generator_stack_rt(ctx->rt, s);\n}\n\nstatic void js_generator_mark(JSRuntime *rt, JSValueConst val,\n                              JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSGeneratorData *s = p->u.generator_data;\n\n    if (!s || s->state == JS_GENERATOR_STATE_COMPLETED)\n        return;\n    async_func_mark(rt, &s->func_state, mark_func);\n}\n\n/* XXX: use enum */\n#define GEN_MAGIC_NEXT   0\n#define GEN_MAGIC_RETURN 1\n#define GEN_MAGIC_THROW  2\n\nstatic JSValue js_generator_next(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv,\n                                 BOOL *pdone, int magic)\n{\n    JSGeneratorData *s = JS_GetOpaque(this_val, JS_CLASS_GENERATOR);\n    JSStackFrame *sf;\n    JSValue ret, func_ret;\n    JSValueConst iter_args[1];\n\n    *pdone = TRUE;\n    if (!s)\n        return JS_ThrowTypeError(ctx, \"not a generator\");\n    sf = &s->func_state.frame;\n redo:\n    switch(s->state) {\n    default:\n    case JS_GENERATOR_STATE_SUSPENDED_START:\n        if (magic == GEN_MAGIC_NEXT) {\n            goto exec_no_arg;\n        } else {\n            free_generator_stack(ctx, s);\n            goto done;\n        }\n        break;\n    case JS_GENERATOR_STATE_SUSPENDED_YIELD_STAR:\n        {\n            int done;\n            JSValue method, iter_obj;\n\n            iter_obj = sf->cur_sp[-2];\n            if (magic == GEN_MAGIC_NEXT) {\n                method = JS_DupValue(ctx, sf->cur_sp[-1]);\n            } else {\n                method = JS_GetProperty(ctx, iter_obj,\n                                        magic == GEN_MAGIC_RETURN ?\n                                        JS_ATOM_return : JS_ATOM_throw);\n                if (JS_IsException(method))\n                    goto iter_exception;\n            }\n            if (magic != GEN_MAGIC_NEXT &&\n                (JS_IsUndefined(method) || JS_IsNull(method))) {\n                /* default action */\n                if (magic == GEN_MAGIC_RETURN) {\n                    ret = JS_DupValue(ctx, argv[0]);\n                    goto iter_done;\n                } else {\n                    if (JS_IteratorClose(ctx, iter_obj, FALSE))\n                        goto iter_exception;\n                    JS_ThrowTypeError(ctx, \"iterator does not have a throw method\");\n                    goto iter_exception;\n                }\n            }\n            ret = JS_IteratorNext2(ctx, iter_obj, method, argc, argv, &done);\n            JS_FreeValue(ctx, method);\n            if (JS_IsException(ret)) {\n            iter_exception:\n                goto exec_throw;\n            }\n            /* if not done, the iterator returns the exact object\n               returned by 'method' */\n            if (done == 2) {\n                JSValue done_val, value;\n                done_val = JS_GetProperty(ctx, ret, JS_ATOM_done);\n                if (JS_IsException(done_val)) {\n                    JS_FreeValue(ctx, ret);\n                    goto iter_exception;\n                }\n                done = JS_ToBoolFree(ctx, done_val);\n                if (done) {\n                    value = JS_GetProperty(ctx, ret, JS_ATOM_value);\n                    JS_FreeValue(ctx, ret);\n                    if (JS_IsException(value))\n                        goto iter_exception;\n                    ret = value;\n                    goto iter_done;\n                } else {\n                    *pdone = 2;\n                }\n            } else {\n                if (done) {\n                    /* 'yield *' returns the value associated to done = true */\n                iter_done:\n                    JS_FreeValue(ctx, sf->cur_sp[-2]);\n                    JS_FreeValue(ctx, sf->cur_sp[-1]);\n                    sf->cur_sp--;\n                    goto exec_arg;\n                } else {\n                    *pdone = FALSE;\n                }\n            }\n            break;\n        }\n        break;\n    case JS_GENERATOR_STATE_SUSPENDED_YIELD:\n        /* cur_sp[-1] was set to JS_UNDEFINED in the previous call */\n        ret = JS_DupValue(ctx, argv[0]);\n        if (magic == GEN_MAGIC_THROW) {\n            JS_Throw(ctx, ret);\n        exec_throw:\n            s->func_state.throw_flag = TRUE;\n        } else {\n        exec_arg:\n            sf->cur_sp[-1] = ret;\n            sf->cur_sp[0] = JS_NewBool(ctx, (magic == GEN_MAGIC_RETURN));\n            sf->cur_sp++;\n        exec_no_arg:\n            s->func_state.throw_flag = FALSE;\n        }\n        s->state = JS_GENERATOR_STATE_EXECUTING;\n        func_ret = async_func_resume(ctx, &s->func_state);\n        s->state = JS_GENERATOR_STATE_SUSPENDED_YIELD;\n        if (JS_IsException(func_ret)) {\n            /* finalize the execution in case of exception */\n            free_generator_stack(ctx, s);\n            return func_ret;\n        }\n        if (JS_VALUE_GET_TAG(func_ret) == JS_TAG_INT) {\n            if (JS_VALUE_GET_INT(func_ret) == FUNC_RET_YIELD_STAR) {\n                /* 'yield *' */\n                s->state = JS_GENERATOR_STATE_SUSPENDED_YIELD_STAR;\n                iter_args[0] = JS_UNDEFINED;\n                argc = 1;\n                argv = iter_args;\n                goto redo;\n            } else {\n                /* get the return the yield value at the top of the stack */\n                ret = sf->cur_sp[-1];\n                sf->cur_sp[-1] = JS_UNDEFINED;\n                *pdone = FALSE;\n            }\n        } else {\n            /* end of iterator */\n            ret = sf->cur_sp[-1];\n            sf->cur_sp[-1] = JS_UNDEFINED;\n            JS_FreeValue(ctx, func_ret);\n            free_generator_stack(ctx, s);\n        }\n        break;\n    case JS_GENERATOR_STATE_COMPLETED:\n    done:\n        /* execution is finished */\n        switch(magic) {\n        default:\n        case GEN_MAGIC_NEXT:\n            ret = JS_UNDEFINED;\n            break;\n        case GEN_MAGIC_RETURN:\n            ret = JS_DupValue(ctx, argv[0]);\n            break;\n        case GEN_MAGIC_THROW:\n            ret = JS_Throw(ctx, JS_DupValue(ctx, argv[0]));\n            break;\n        }\n        break;\n    case JS_GENERATOR_STATE_EXECUTING:\n        ret = JS_ThrowTypeError(ctx, \"cannot invoke a running generator\");\n        break;\n    }\n    return ret;\n}\n\nstatic JSValue js_generator_function_call(JSContext *ctx, JSValueConst func_obj,\n                                          JSValueConst this_obj,\n                                          int argc, JSValueConst *argv,\n                                          int flags)\n{\n    JSValue obj, func_ret;\n    JSGeneratorData *s;\n\n    s = js_mallocz(ctx, sizeof(*s));\n    if (!s)\n        return JS_EXCEPTION;\n    s->state = JS_GENERATOR_STATE_SUSPENDED_START;\n    if (async_func_init(ctx, &s->func_state, func_obj, this_obj, argc, argv)) {\n        s->state = JS_GENERATOR_STATE_COMPLETED;\n        goto fail;\n    }\n\n    /* execute the function up to 'OP_initial_yield' */\n    func_ret = async_func_resume(ctx, &s->func_state);\n    if (JS_IsException(func_ret))\n        goto fail;\n    JS_FreeValue(ctx, func_ret);\n\n    obj = js_create_from_ctor(ctx, func_obj, JS_CLASS_GENERATOR);\n    if (JS_IsException(obj))\n        goto fail;\n    JS_SetOpaque(obj, s);\n    return obj;\n fail:\n    free_generator_stack_rt(ctx->rt, s);\n    js_free(ctx, s);\n    return JS_EXCEPTION;\n}\n\n/* AsyncFunction */\n\nstatic void js_async_function_terminate(JSRuntime *rt, JSAsyncFunctionData *s)\n{\n    if (s->is_active) {\n        async_func_free(rt, &s->func_state);\n        s->is_active = FALSE;\n    }\n}\n\nstatic void js_async_function_free0(JSRuntime *rt, JSAsyncFunctionData *s)\n{\n    js_async_function_terminate(rt, s);\n    JS_FreeValueRT(rt, s->resolving_funcs[0]);\n    JS_FreeValueRT(rt, s->resolving_funcs[1]);\n    remove_gc_object(&s->header);\n    js_free_rt(rt, s);\n}\n\nstatic void js_async_function_free(JSRuntime *rt, JSAsyncFunctionData *s)\n{\n    if (--s->header.ref_count == 0) {\n        js_async_function_free0(rt, s);\n    }\n}\n\nstatic void js_async_function_resolve_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSAsyncFunctionData *s = p->u.async_function_data;\n    if (s) {\n        js_async_function_free(rt, s);\n    }\n}\n\nstatic void js_async_function_resolve_mark(JSRuntime *rt, JSValueConst val,\n                                           JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSAsyncFunctionData *s = p->u.async_function_data;\n    if (s) {\n        mark_func(rt, &s->header);\n    }\n}\n\nstatic int js_async_function_resolve_create(JSContext *ctx,\n                                            JSAsyncFunctionData *s,\n                                            JSValue *resolving_funcs)\n{\n    int i;\n    JSObject *p;\n\n    for(i = 0; i < 2; i++) {\n        resolving_funcs[i] =\n            JS_NewObjectProtoClass(ctx, ctx->function_proto,\n                                   JS_CLASS_ASYNC_FUNCTION_RESOLVE + i);\n        if (JS_IsException(resolving_funcs[i])) {\n            if (i == 1)\n                JS_FreeValue(ctx, resolving_funcs[0]);\n            return -1;\n        }\n        p = JS_VALUE_GET_OBJ(resolving_funcs[i]);\n        s->header.ref_count++;\n        p->u.async_function_data = s;\n    }\n    return 0;\n}\n\nstatic void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData *s)\n{\n    JSValue func_ret, ret2;\n\n    func_ret = async_func_resume(ctx, &s->func_state);\n    if (JS_IsException(func_ret)) {\n        JSValue error;\n    fail:\n        error = JS_GetException(ctx);\n        ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,\n                       1, (JSValueConst *)&error);\n        JS_FreeValue(ctx, error);\n        js_async_function_terminate(ctx->rt, s);\n        JS_FreeValue(ctx, ret2); /* XXX: what to do if exception ? */\n    } else {\n        JSValue value;\n        value = s->func_state.frame.cur_sp[-1];\n        s->func_state.frame.cur_sp[-1] = JS_UNDEFINED;\n        if (JS_IsUndefined(func_ret)) {\n            /* function returned */\n            ret2 = JS_Call(ctx, s->resolving_funcs[0], JS_UNDEFINED,\n                           1, (JSValueConst *)&value);\n            JS_FreeValue(ctx, ret2); /* XXX: what to do if exception ? */\n            JS_FreeValue(ctx, value);\n            js_async_function_terminate(ctx->rt, s);\n        } else {\n            JSValue promise, resolving_funcs[2], resolving_funcs1[2];\n            int i, res;\n\n            /* await */\n            JS_FreeValue(ctx, func_ret); /* not used */\n            promise = js_promise_resolve(ctx, ctx->promise_ctor,\n                                         1, (JSValueConst *)&value, 0);\n            JS_FreeValue(ctx, value);\n            if (JS_IsException(promise))\n                goto fail;\n            if (js_async_function_resolve_create(ctx, s, resolving_funcs)) {\n                JS_FreeValue(ctx, promise);\n                goto fail;\n            }\n\n            /* Note: no need to create 'thrownawayCapability' as in\n               the spec */\n            for(i = 0; i < 2; i++)\n                resolving_funcs1[i] = JS_UNDEFINED;\n            res = perform_promise_then(ctx, promise,\n                                       (JSValueConst *)resolving_funcs,\n                                       (JSValueConst *)resolving_funcs1);\n            JS_FreeValue(ctx, promise);\n            for(i = 0; i < 2; i++)\n                JS_FreeValue(ctx, resolving_funcs[i]);\n            if (res)\n                goto fail;\n        }\n    }\n}\n\nstatic JSValue js_async_function_resolve_call(JSContext *ctx,\n                                              JSValueConst func_obj,\n                                              JSValueConst this_obj,\n                                              int argc, JSValueConst *argv,\n                                              int flags)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(func_obj);\n    JSAsyncFunctionData *s = p->u.async_function_data;\n    BOOL is_reject = p->class_id - JS_CLASS_ASYNC_FUNCTION_RESOLVE;\n    JSValueConst arg;\n\n    if (argc > 0)\n        arg = argv[0];\n    else\n        arg = JS_UNDEFINED;\n    s->func_state.throw_flag = is_reject;\n    if (is_reject) {\n        JS_Throw(ctx, JS_DupValue(ctx, arg));\n    } else {\n        /* return value of await */\n        s->func_state.frame.cur_sp[-1] = JS_DupValue(ctx, arg);\n    }\n    js_async_function_resume(ctx, s);\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_async_function_call(JSContext *ctx, JSValueConst func_obj,\n                                      JSValueConst this_obj,\n                                      int argc, JSValueConst *argv, int flags)\n{\n    JSValue promise;\n    JSAsyncFunctionData *s;\n\n    s = js_mallocz(ctx, sizeof(*s));\n    if (!s)\n        return JS_EXCEPTION;\n    s->header.ref_count = 1;\n    add_gc_object(ctx->rt, &s->header, JS_GC_OBJ_TYPE_ASYNC_FUNCTION);\n    s->is_active = FALSE;\n    s->resolving_funcs[0] = JS_UNDEFINED;\n    s->resolving_funcs[1] = JS_UNDEFINED;\n\n    promise = JS_NewPromiseCapability(ctx, s->resolving_funcs);\n    if (JS_IsException(promise))\n        goto fail;\n\n    if (async_func_init(ctx, &s->func_state, func_obj, this_obj, argc, argv)) {\n    fail:\n        JS_FreeValue(ctx, promise);\n        js_async_function_free(ctx->rt, s);\n        return JS_EXCEPTION;\n    }\n    s->is_active = TRUE;\n\n    js_async_function_resume(ctx, s);\n\n    js_async_function_free(ctx->rt, s);\n\n    return promise;\n}\n\n/* AsyncGenerator */\n\ntypedef enum JSAsyncGeneratorStateEnum {\n    JS_ASYNC_GENERATOR_STATE_SUSPENDED_START,\n    JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD,\n    JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD_STAR,\n    JS_ASYNC_GENERATOR_STATE_EXECUTING,\n    JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN,\n    JS_ASYNC_GENERATOR_STATE_COMPLETED,\n} JSAsyncGeneratorStateEnum;\n\ntypedef struct JSAsyncGeneratorRequest {\n    struct list_head link;\n    /* completion */\n    int completion_type; /* GEN_MAGIC_x */\n    JSValue result;\n    /* promise capability */\n    JSValue promise;\n    JSValue resolving_funcs[2];\n} JSAsyncGeneratorRequest;\n\ntypedef struct JSAsyncGeneratorData {\n    JSObject *generator; /* back pointer to the object (const) */\n    JSAsyncGeneratorStateEnum state;\n    JSAsyncFunctionState func_state;\n    struct list_head queue; /* list of JSAsyncGeneratorRequest.link */\n} JSAsyncGeneratorData;\n\nstatic void js_async_generator_free(JSRuntime *rt,\n                                    JSAsyncGeneratorData *s)\n{\n    struct list_head *el, *el1;\n    JSAsyncGeneratorRequest *req;\n\n    list_for_each_safe(el, el1, &s->queue) {\n        req = list_entry(el, JSAsyncGeneratorRequest, link);\n        JS_FreeValueRT(rt, req->result);\n        JS_FreeValueRT(rt, req->promise);\n        JS_FreeValueRT(rt, req->resolving_funcs[0]);\n        JS_FreeValueRT(rt, req->resolving_funcs[1]);\n        js_free_rt(rt, req);\n    }\n    if (s->state != JS_ASYNC_GENERATOR_STATE_COMPLETED &&\n        s->state != JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN) {\n        async_func_free(rt, &s->func_state);\n    }\n    js_free_rt(rt, s);\n}\n\nstatic void js_async_generator_finalizer(JSRuntime *rt, JSValue obj)\n{\n    JSAsyncGeneratorData *s = JS_GetOpaque(obj, JS_CLASS_ASYNC_GENERATOR);\n\n    if (s) {\n        js_async_generator_free(rt, s);\n    }\n}\n\nstatic void js_async_generator_mark(JSRuntime *rt, JSValueConst val,\n                                    JS_MarkFunc *mark_func)\n{\n    JSAsyncGeneratorData *s = JS_GetOpaque(val, JS_CLASS_ASYNC_GENERATOR);\n    struct list_head *el;\n    JSAsyncGeneratorRequest *req;\n    if (s) {\n        list_for_each(el, &s->queue) {\n            req = list_entry(el, JSAsyncGeneratorRequest, link);\n            JS_MarkValue(rt, req->result, mark_func);\n            JS_MarkValue(rt, req->promise, mark_func);\n            JS_MarkValue(rt, req->resolving_funcs[0], mark_func);\n            JS_MarkValue(rt, req->resolving_funcs[1], mark_func);\n        }\n        if (s->state != JS_ASYNC_GENERATOR_STATE_COMPLETED &&\n            s->state != JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN) {\n            async_func_mark(rt, &s->func_state, mark_func);\n        }\n    }\n}\n\nstatic JSValue js_async_generator_resolve_function(JSContext *ctx,\n                                          JSValueConst this_obj,\n                                          int argc, JSValueConst *argv,\n                                          int magic, JSValue *func_data);\n\nstatic int js_async_generator_resolve_function_create(JSContext *ctx,\n                                                      JSValueConst generator,\n                                                      JSValue *resolving_funcs,\n                                                      BOOL is_resume_next)\n{\n    int i;\n    JSValue func;\n\n    for(i = 0; i < 2; i++) {\n        func = JS_NewCFunctionData(ctx, js_async_generator_resolve_function, 1,\n                                   i + is_resume_next * 2, 1, &generator);\n        if (JS_IsException(func)) {\n            if (i == 1)\n                JS_FreeValue(ctx, resolving_funcs[0]);\n            return -1;\n        }\n        resolving_funcs[i] = func;\n    }\n    return 0;\n}\n\nstatic int js_async_generator_await(JSContext *ctx,\n                                    JSAsyncGeneratorData *s,\n                                    JSValueConst value)\n{\n    JSValue promise, resolving_funcs[2], resolving_funcs1[2];\n    int i, res;\n\n    promise = js_promise_resolve(ctx, ctx->promise_ctor,\n                                 1, &value, 0);\n    if (JS_IsException(promise))\n        goto fail;\n\n    if (js_async_generator_resolve_function_create(ctx, JS_MKPTR(JS_TAG_OBJECT, s->generator),\n                                                   resolving_funcs, FALSE)) {\n        JS_FreeValue(ctx, promise);\n        goto fail;\n    }\n\n    /* Note: no need to create 'thrownawayCapability' as in\n       the spec */\n    for(i = 0; i < 2; i++)\n        resolving_funcs1[i] = JS_UNDEFINED;\n    res = perform_promise_then(ctx, promise,\n                               (JSValueConst *)resolving_funcs,\n                               (JSValueConst *)resolving_funcs1);\n    JS_FreeValue(ctx, promise);\n    for(i = 0; i < 2; i++)\n        JS_FreeValue(ctx, resolving_funcs[i]);\n    if (res)\n        goto fail;\n    return 0;\n fail:\n    return -1;\n}\n\nstatic void js_async_generator_resolve_or_reject(JSContext *ctx,\n                                                 JSAsyncGeneratorData *s,\n                                                 JSValueConst result,\n                                                 int is_reject)\n{\n    JSAsyncGeneratorRequest *next;\n    JSValue ret;\n\n    next = list_entry(s->queue.next, JSAsyncGeneratorRequest, link);\n    list_del(&next->link);\n    ret = JS_Call(ctx, next->resolving_funcs[is_reject], JS_UNDEFINED, 1,\n                  &result);\n    JS_FreeValue(ctx, ret);\n    JS_FreeValue(ctx, next->result);\n    JS_FreeValue(ctx, next->promise);\n    JS_FreeValue(ctx, next->resolving_funcs[0]);\n    JS_FreeValue(ctx, next->resolving_funcs[1]);\n    js_free(ctx, next);\n}\n\nstatic void js_async_generator_resolve(JSContext *ctx,\n                                       JSAsyncGeneratorData *s,\n                                       JSValueConst value,\n                                       BOOL done)\n{\n    JSValue result;\n    result = js_create_iterator_result(ctx, JS_DupValue(ctx, value), done);\n    /* XXX: better exception handling ? */\n    js_async_generator_resolve_or_reject(ctx, s, result, 0);\n    JS_FreeValue(ctx, result);\n }\n\nstatic void js_async_generator_reject(JSContext *ctx,\n                                       JSAsyncGeneratorData *s,\n                                       JSValueConst exception)\n{\n    js_async_generator_resolve_or_reject(ctx, s, exception, 1);\n}\n\nstatic void js_async_generator_complete(JSContext *ctx,\n                                        JSAsyncGeneratorData *s)\n{\n    if (s->state != JS_ASYNC_GENERATOR_STATE_COMPLETED) {\n        s->state = JS_ASYNC_GENERATOR_STATE_COMPLETED;\n        async_func_free(ctx->rt, &s->func_state);\n    }\n}\n\nstatic int js_async_generator_completed_return(JSContext *ctx,\n                                               JSAsyncGeneratorData *s,\n                                               JSValueConst value)\n{\n    JSValue promise, resolving_funcs[2], resolving_funcs1[2];\n    int res;\n\n    promise = js_promise_resolve(ctx, ctx->promise_ctor,\n                                 1, (JSValueConst *)&value, 0);\n    if (JS_IsException(promise))\n        return -1;\n    if (js_async_generator_resolve_function_create(ctx,\n                                                   JS_MKPTR(JS_TAG_OBJECT, s->generator),\n                                                   resolving_funcs1,\n                                                   TRUE)) {\n        JS_FreeValue(ctx, promise);\n        return -1;\n    }\n    resolving_funcs[0] = JS_UNDEFINED;\n    resolving_funcs[1] = JS_UNDEFINED;\n    res = perform_promise_then(ctx, promise,\n                               (JSValueConst *)resolving_funcs1,\n                               (JSValueConst *)resolving_funcs);\n    JS_FreeValue(ctx, resolving_funcs1[0]);\n    JS_FreeValue(ctx, resolving_funcs1[1]);\n    JS_FreeValue(ctx, promise);\n    return res;\n}\n\nstatic void js_async_generator_resume_next(JSContext *ctx,\n                                           JSAsyncGeneratorData *s)\n{\n    JSAsyncGeneratorRequest *next;\n    JSValue func_ret, value;\n\n    for(;;) {\n        if (list_empty(&s->queue))\n            break;\n        next = list_entry(s->queue.next, JSAsyncGeneratorRequest, link);\n        switch(s->state) {\n        case JS_ASYNC_GENERATOR_STATE_EXECUTING:\n            /* only happens when restarting execution after await() */\n            goto resume_exec;\n        case JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN:\n            goto done;\n        case JS_ASYNC_GENERATOR_STATE_SUSPENDED_START:\n            if (next->completion_type == GEN_MAGIC_NEXT) {\n                goto exec_no_arg;\n            } else {\n                js_async_generator_complete(ctx, s);\n            }\n            break;\n        case JS_ASYNC_GENERATOR_STATE_COMPLETED:\n            if (next->completion_type == GEN_MAGIC_NEXT) {\n                js_async_generator_resolve(ctx, s, JS_UNDEFINED, TRUE);\n            } else if (next->completion_type == GEN_MAGIC_RETURN) {\n                s->state = JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN;\n                js_async_generator_completed_return(ctx, s, next->result);\n                goto done;\n            } else {\n                js_async_generator_reject(ctx, s, next->result);\n            }\n            goto done;\n        case JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD:\n        case JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD_STAR:\n            value = JS_DupValue(ctx, next->result);\n            if (next->completion_type == GEN_MAGIC_THROW &&\n                s->state == JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD) {\n                JS_Throw(ctx, value);\n                s->func_state.throw_flag = TRUE;\n            } else {\n                /* 'yield' returns a value. 'yield *' also returns a value\n                   in case the 'throw' method is called */\n                s->func_state.frame.cur_sp[-1] = value;\n                s->func_state.frame.cur_sp[0] =\n                    JS_NewInt32(ctx, next->completion_type);\n                s->func_state.frame.cur_sp++;\n            exec_no_arg:\n                s->func_state.throw_flag = FALSE;\n            }\n            s->state = JS_ASYNC_GENERATOR_STATE_EXECUTING;\n        resume_exec:\n            func_ret = async_func_resume(ctx, &s->func_state);\n            if (JS_IsException(func_ret)) {\n                value = JS_GetException(ctx);\n                js_async_generator_complete(ctx, s);\n                js_async_generator_reject(ctx, s, value);\n                JS_FreeValue(ctx, value);\n            } else if (JS_VALUE_GET_TAG(func_ret) == JS_TAG_INT) {\n                int func_ret_code;\n                value = s->func_state.frame.cur_sp[-1];\n                s->func_state.frame.cur_sp[-1] = JS_UNDEFINED;\n                func_ret_code = JS_VALUE_GET_INT(func_ret);\n                switch(func_ret_code) {\n                case FUNC_RET_YIELD:\n                case FUNC_RET_YIELD_STAR:\n                    if (func_ret_code == FUNC_RET_YIELD_STAR)\n                        s->state = JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD_STAR;\n                    else\n                        s->state = JS_ASYNC_GENERATOR_STATE_SUSPENDED_YIELD;\n                    js_async_generator_resolve(ctx, s, value, FALSE);\n                    JS_FreeValue(ctx, value);\n                    break;\n                case FUNC_RET_AWAIT:\n                    js_async_generator_await(ctx, s, value);\n                    JS_FreeValue(ctx, value);\n                    goto done;\n                default:\n                    abort();\n                }\n            } else {\n                assert(JS_IsUndefined(func_ret));\n                /* end of function */\n                value = s->func_state.frame.cur_sp[-1];\n                s->func_state.frame.cur_sp[-1] = JS_UNDEFINED;\n                js_async_generator_complete(ctx, s);\n                js_async_generator_resolve(ctx, s, value, TRUE);\n                JS_FreeValue(ctx, value);\n            }\n            break;\n        default:\n            abort();\n        }\n    }\n done: ;\n}\n\nstatic JSValue js_async_generator_resolve_function(JSContext *ctx,\n                                                   JSValueConst this_obj,\n                                                   int argc, JSValueConst *argv,\n                                                   int magic, JSValue *func_data)\n{\n    BOOL is_reject = magic & 1;\n    JSAsyncGeneratorData *s = JS_GetOpaque(func_data[0], JS_CLASS_ASYNC_GENERATOR);\n    JSValueConst arg = argv[0];\n\n    /* XXX: what if s == NULL */\n\n    if (magic >= 2) {\n        /* resume next case in AWAITING_RETURN state */\n        assert(s->state == JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN ||\n               s->state == JS_ASYNC_GENERATOR_STATE_COMPLETED);\n        s->state = JS_ASYNC_GENERATOR_STATE_COMPLETED;\n        if (is_reject) {\n            js_async_generator_reject(ctx, s, arg);\n        } else {\n            js_async_generator_resolve(ctx, s, arg, TRUE);\n        }\n    } else {\n        /* restart function execution after await() */\n        assert(s->state == JS_ASYNC_GENERATOR_STATE_EXECUTING);\n        s->func_state.throw_flag = is_reject;\n        if (is_reject) {\n            JS_Throw(ctx, JS_DupValue(ctx, arg));\n        } else {\n            /* return value of await */\n            s->func_state.frame.cur_sp[-1] = JS_DupValue(ctx, arg);\n        }\n        js_async_generator_resume_next(ctx, s);\n    }\n    return JS_UNDEFINED;\n}\n\n/* magic = GEN_MAGIC_x */\nstatic JSValue js_async_generator_next(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv,\n                                       int magic)\n{\n    JSAsyncGeneratorData *s = JS_GetOpaque(this_val, JS_CLASS_ASYNC_GENERATOR);\n    JSValue promise, resolving_funcs[2];\n    JSAsyncGeneratorRequest *req;\n\n    promise = JS_NewPromiseCapability(ctx, resolving_funcs);\n    if (JS_IsException(promise))\n        return JS_EXCEPTION;\n    if (!s) {\n        JSValue err, res2;\n        JS_ThrowTypeError(ctx, \"not an AsyncGenerator object\");\n        err = JS_GetException(ctx);\n        res2 = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED,\n                       1, (JSValueConst *)&err);\n        JS_FreeValue(ctx, err);\n        JS_FreeValue(ctx, res2);\n        JS_FreeValue(ctx, resolving_funcs[0]);\n        JS_FreeValue(ctx, resolving_funcs[1]);\n        return promise;\n    }\n    req = js_mallocz(ctx, sizeof(*req));\n    if (!req)\n        goto fail;\n    req->completion_type = magic;\n    req->result = JS_DupValue(ctx, argv[0]);\n    req->promise = JS_DupValue(ctx, promise);\n    req->resolving_funcs[0] = resolving_funcs[0];\n    req->resolving_funcs[1] = resolving_funcs[1];\n    list_add_tail(&req->link, &s->queue);\n    if (s->state != JS_ASYNC_GENERATOR_STATE_EXECUTING) {\n        js_async_generator_resume_next(ctx, s);\n    }\n    return promise;\n fail:\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    JS_FreeValue(ctx, promise);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_async_generator_function_call(JSContext *ctx, JSValueConst func_obj,\n                                                JSValueConst this_obj,\n                                                int argc, JSValueConst *argv,\n                                                int flags)\n{\n    JSValue obj, func_ret;\n    JSAsyncGeneratorData *s;\n\n    s = js_mallocz(ctx, sizeof(*s));\n    if (!s)\n        return JS_EXCEPTION;\n    s->state = JS_ASYNC_GENERATOR_STATE_SUSPENDED_START;\n    init_list_head(&s->queue);\n    if (async_func_init(ctx, &s->func_state, func_obj, this_obj, argc, argv)) {\n        s->state = JS_ASYNC_GENERATOR_STATE_COMPLETED;\n        goto fail;\n    }\n\n    /* execute the function up to 'OP_initial_yield' (no yield nor\n       await are possible) */\n    func_ret = async_func_resume(ctx, &s->func_state);\n    if (JS_IsException(func_ret))\n        goto fail;\n    JS_FreeValue(ctx, func_ret);\n\n    obj = js_create_from_ctor(ctx, func_obj, JS_CLASS_ASYNC_GENERATOR);\n    if (JS_IsException(obj))\n        goto fail;\n    s->generator = JS_VALUE_GET_OBJ(obj);\n    JS_SetOpaque(obj, s);\n    return obj;\n fail:\n    js_async_generator_free(ctx->rt, s);\n    return JS_EXCEPTION;\n}\n\n/* JS parser */\n\nenum {\n    TOK_NUMBER = -128,\n    TOK_STRING,\n    TOK_TEMPLATE,\n    TOK_IDENT,\n    TOK_REGEXP,\n    /* warning: order matters (see js_parse_assign_expr) */\n    TOK_MUL_ASSIGN,\n    TOK_DIV_ASSIGN,\n    TOK_MOD_ASSIGN,\n    TOK_PLUS_ASSIGN,\n    TOK_MINUS_ASSIGN,\n    TOK_SHL_ASSIGN,\n    TOK_SAR_ASSIGN,\n    TOK_SHR_ASSIGN,\n    TOK_AND_ASSIGN,\n    TOK_XOR_ASSIGN,\n    TOK_OR_ASSIGN,\n#ifdef CONFIG_BIGNUM\n    TOK_MATH_POW_ASSIGN,\n#endif\n    TOK_POW_ASSIGN,\n    TOK_DEC,\n    TOK_INC,\n    TOK_SHL,\n    TOK_SAR,\n    TOK_SHR,\n    TOK_LT,\n    TOK_LTE,\n    TOK_GT,\n    TOK_GTE,\n    TOK_EQ,\n    TOK_STRICT_EQ,\n    TOK_NEQ,\n    TOK_STRICT_NEQ,\n    TOK_LAND,\n    TOK_LOR,\n#ifdef CONFIG_BIGNUM\n    TOK_MATH_POW,\n#endif\n    TOK_POW,\n    TOK_ARROW,\n    TOK_ELLIPSIS,\n    TOK_DOUBLE_QUESTION_MARK,\n    TOK_QUESTION_MARK_DOT,\n    TOK_ERROR,\n    TOK_PRIVATE_NAME,\n    TOK_EOF,\n    /* keywords: WARNING: same order as atoms */\n    TOK_NULL, /* must be first */\n    TOK_FALSE,\n    TOK_TRUE,\n    TOK_IF,\n    TOK_ELSE,\n    TOK_RETURN,\n    TOK_VAR,\n    TOK_THIS,\n    TOK_DELETE,\n    TOK_VOID,\n    TOK_TYPEOF,\n    TOK_NEW,\n    TOK_IN,\n    TOK_INSTANCEOF,\n    TOK_DO,\n    TOK_WHILE,\n    TOK_FOR,\n    TOK_BREAK,\n    TOK_CONTINUE,\n    TOK_SWITCH,\n    TOK_CASE,\n    TOK_DEFAULT,\n    TOK_THROW,\n    TOK_TRY,\n    TOK_CATCH,\n    TOK_FINALLY,\n    TOK_FUNCTION,\n    TOK_DEBUGGER,\n    TOK_WITH,\n    /* FutureReservedWord */\n    TOK_CLASS,\n    TOK_CONST,\n    TOK_ENUM,\n    TOK_EXPORT,\n    TOK_EXTENDS,\n    TOK_IMPORT,\n    TOK_SUPER,\n    /* FutureReservedWords when parsing strict mode code */\n    TOK_IMPLEMENTS,\n    TOK_INTERFACE,\n    TOK_LET,\n    TOK_PACKAGE,\n    TOK_PRIVATE,\n    TOK_PROTECTED,\n    TOK_PUBLIC,\n    TOK_STATIC,\n    TOK_YIELD,\n    TOK_AWAIT, /* must be last */\n    TOK_OF,     /* only used for js_parse_skip_parens_token() */\n};\n\n#define TOK_FIRST_KEYWORD   TOK_NULL\n#define TOK_LAST_KEYWORD    TOK_AWAIT\n\n/* unicode code points */\n#define CP_NBSP 0x00a0\n#define CP_BOM  0xfeff\n\n#define CP_LS   0x2028\n#define CP_PS   0x2029\n\ntypedef struct BlockEnv {\n    struct BlockEnv *prev;\n    JSAtom label_name; /* JS_ATOM_NULL if none */\n    int label_break; /* -1 if none */\n    int label_cont; /* -1 if none */\n    int drop_count; /* number of stack elements to drop */\n    int label_finally; /* -1 if none */\n    int scope_level;\n    int has_iterator;\n} BlockEnv;\n\ntypedef struct JSHoistedDef {\n    int cpool_idx; /* -1 means variable global definition */\n    uint8_t force_init : 1; /* initialize to undefined */\n    uint8_t is_lexical : 1; /* global let/const definition */\n    uint8_t is_const   : 1; /* const definition */\n    int var_idx;   /* function object index if cpool_idx >= 0 */\n    int scope_level;    /* scope of definition */\n    JSAtom var_name;  /* variable name if cpool_idx < 0 */\n} JSHoistedDef;\n\ntypedef struct RelocEntry {\n    struct RelocEntry *next;\n    uint32_t addr; /* address to patch */\n    int size;   /* address size: 1, 2 or 4 bytes */\n} RelocEntry;\n\ntypedef struct JumpSlot {\n    int op;\n    int size;\n    int pos;\n    int label;\n} JumpSlot;\n\ntypedef struct LabelSlot {\n    int ref_count;\n    int pos;    /* phase 1 address, -1 means not resolved yet */\n    int pos2;   /* phase 2 address, -1 means not resolved yet */\n    int addr;   /* phase 3 address, -1 means not resolved yet */\n    RelocEntry *first_reloc;\n} LabelSlot;\n\ntypedef struct LineNumberSlot {\n    uint32_t pc;\n    int line_num;\n} LineNumberSlot;\n\ntypedef enum JSParseFunctionEnum {\n    JS_PARSE_FUNC_STATEMENT,\n    JS_PARSE_FUNC_VAR,\n    JS_PARSE_FUNC_EXPR,\n    JS_PARSE_FUNC_ARROW,\n    JS_PARSE_FUNC_GETTER,\n    JS_PARSE_FUNC_SETTER,\n    JS_PARSE_FUNC_METHOD,\n    JS_PARSE_FUNC_CLASS_CONSTRUCTOR,\n    JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR,\n} JSParseFunctionEnum;\n\ntypedef enum JSParseExportEnum {\n    JS_PARSE_EXPORT_NONE,\n    JS_PARSE_EXPORT_NAMED,\n    JS_PARSE_EXPORT_DEFAULT,\n} JSParseExportEnum;\n\ntypedef struct JSFunctionDef {\n    JSContext *ctx;\n    struct JSFunctionDef *parent;\n    int parent_cpool_idx; /* index in the constant pool of the parent\n                             or -1 if none */\n    int parent_scope_level; /* scope level in parent at point of definition */\n    struct list_head child_list; /* list of JSFunctionDef.link */\n    struct list_head link;\n\n    BOOL is_eval; /* TRUE if eval code */\n    int eval_type; /* only valid if is_eval = TRUE */\n    BOOL is_global_var; /* TRUE if variables are not defined locally:\n                           eval global, eval module or non strict eval */\n    BOOL is_func_expr; /* TRUE if function expression */\n    BOOL has_home_object; /* TRUE if the home object is available */\n    BOOL has_prototype; /* true if a prototype field is necessary */\n    BOOL has_simple_parameter_list;\n    BOOL has_use_strict; /* to reject directive in special cases */\n    BOOL has_eval_call; /* true if the function contains a call to eval() */\n    BOOL has_arguments_binding; /* true if the 'arguments' binding is\n                                   available in the function */\n    BOOL has_this_binding; /* true if the 'this' and new.target binding are\n                              available in the function */\n    BOOL new_target_allowed; /* true if the 'new.target' does not\n                                throw a syntax error */\n    BOOL super_call_allowed; /* true if super() is allowed */\n    BOOL super_allowed; /* true if super. or super[] is allowed */\n    BOOL arguments_allowed; /* true if the 'arguments' identifier is allowed */\n    BOOL is_derived_class_constructor;\n    BOOL in_function_body;\n    BOOL backtrace_barrier;\n    JSFunctionKindEnum func_kind : 8;\n    JSParseFunctionEnum func_type : 8;\n    uint8_t js_mode; /* bitmap of JS_MODE_x */\n    JSAtom func_name; /* JS_ATOM_NULL if no name */\n\n    JSVarDef *vars;\n    int var_size; /* allocated size for vars[] */\n    int var_count;\n    JSVarDef *args;\n    int arg_size; /* allocated size for args[] */\n    int arg_count; /* number of arguments */\n    int defined_arg_count;\n    int var_object_idx; /* -1 if none */\n    int arguments_var_idx; /* -1 if none */\n    int func_var_idx; /* variable containing the current function (-1\n                         if none, only used if is_func_expr is true) */\n    int eval_ret_idx; /* variable containing the return value of the eval, -1 if none */\n    int this_var_idx; /* variable containg the 'this' value, -1 if none */\n    int new_target_var_idx; /* variable containg the 'new.target' value, -1 if none */\n    int this_active_func_var_idx; /* variable containg the 'this.active_func' value, -1 if none */\n    int home_object_var_idx;\n    BOOL need_home_object;\n    \n    int scope_level;    /* index into fd->scopes if the current lexical scope */\n    int scope_first;    /* index into vd->vars of first lexically scoped variable */\n    int scope_size;     /* allocated size of fd->scopes array */\n    int scope_count;    /* number of entries used in the fd->scopes array */\n    JSVarScope *scopes;\n    JSVarScope def_scope_array[4];\n\n    int hoisted_def_count;\n    int hoisted_def_size;\n    JSHoistedDef *hoisted_def;\n\n    DynBuf byte_code;\n    int last_opcode_pos; /* -1 if no last opcode */\n    int last_opcode_line_num;\n    BOOL use_short_opcodes; /* true if short opcodes are used in byte_code */\n    \n    LabelSlot *label_slots;\n    int label_size; /* allocated size for label_slots[] */\n    int label_count;\n    BlockEnv *top_break; /* break/continue label stack */\n\n    /* constant pool (strings, functions, numbers) */\n    JSValue *cpool;\n    int cpool_count;\n    int cpool_size;\n\n    /* list of variables in the closure */\n    int closure_var_count;\n    int closure_var_size;\n    JSClosureVar *closure_var;\n\n    JumpSlot *jump_slots;\n    int jump_size;\n    int jump_count;\n\n    LineNumberSlot *line_number_slots;\n    int line_number_size;\n    int line_number_count;\n    int line_number_last;\n    int line_number_last_pc;\n\n    /* pc2line table */\n    JSAtom filename;\n    int line_num;\n    DynBuf pc2line;\n\n    char *source;  /* raw source, utf-8 encoded */\n    int source_len;\n\n    JSModuleDef *module; /* != NULL when parsing a module */\n} JSFunctionDef;\n\ntypedef struct JSToken {\n    int val;\n    int line_num;   /* line number of token start */\n    const uint8_t *ptr;\n    union {\n        struct {\n            JSValue str;\n            int sep;\n        } str;\n        struct {\n            JSValue val;\n#ifdef CONFIG_BIGNUM\n            slimb_t exponent; /* may be != 0 only if val is a float */\n#endif\n        } num;\n        struct {\n            JSAtom atom;\n            BOOL has_escape;\n            BOOL is_reserved;\n        } ident;\n        struct {\n            JSValue body;\n            JSValue flags;\n        } regexp;\n    } u;\n} JSToken;\n\ntypedef struct JSParseState {\n    JSContext *ctx;\n    int last_line_num;  /* line number of last token */\n    int line_num;       /* line number of current offset */\n    const char *filename;\n    JSToken token;\n    BOOL got_lf; /* true if got line feed before the current token */\n    const uint8_t *last_ptr;\n    const uint8_t *buf_ptr;\n    const uint8_t *buf_end;\n\n    /* current function code */\n    JSFunctionDef *cur_func;\n    BOOL is_module; /* parsing a module */\n    BOOL allow_html_comments;\n    BOOL ext_json; /* true if accepting JSON superset */\n} JSParseState;\n\ntypedef struct JSOpCode {\n#ifdef DUMP_BYTECODE\n    const char *name;\n#endif\n    uint8_t size; /* in bytes */\n    /* the opcodes remove n_pop items from the top of the stack, then\n       pushes n_push items */\n    uint8_t n_pop;\n    uint8_t n_push;\n    uint8_t fmt;\n} JSOpCode;\n\nstatic const JSOpCode opcode_info[OP_COUNT + (OP_TEMP_END - OP_TEMP_START)] = {\n#define FMT(f)\n#ifdef DUMP_BYTECODE\n#define DEF(id, size, n_pop, n_push, f) { #id, size, n_pop, n_push, OP_FMT_ ## f },\n#else\n#define DEF(id, size, n_pop, n_push, f) { size, n_pop, n_push, OP_FMT_ ## f },\n#endif\n#include \"quickjs-opcode.h\"\n#undef DEF\n#undef FMT\n};\n\n#if SHORT_OPCODES\n/* After the final compilation pass, short opcodes are used. Their\n   opcodes overlap with the temporary opcodes which cannot appear in\n   the final bytecode. Their description is after the temporary\n   opcodes in opcode_info[]. */\n#define short_opcode_info(op)           \\\n    opcode_info[(op) >= OP_TEMP_START ? \\\n                (op) + (OP_TEMP_END - OP_TEMP_START) : (op)]\n#else\n#define short_opcode_info(op) opcode_info[op]\n#endif\n\nstatic __exception int next_token(JSParseState *s);\n\nstatic void free_token(JSParseState *s, JSToken *token)\n{\n    switch(token->val) {\n#ifdef CONFIG_BIGNUM\n    case TOK_NUMBER:\n        JS_FreeValue(s->ctx, token->u.num.val);\n        break;\n#endif\n    case TOK_STRING:\n    case TOK_TEMPLATE:\n        JS_FreeValue(s->ctx, token->u.str.str);\n        break;\n    case TOK_REGEXP:\n        JS_FreeValue(s->ctx, token->u.regexp.body);\n        JS_FreeValue(s->ctx, token->u.regexp.flags);\n        break;\n    case TOK_IDENT:\n    case TOK_FIRST_KEYWORD ... TOK_LAST_KEYWORD:\n    case TOK_PRIVATE_NAME:\n        JS_FreeAtom(s->ctx, token->u.ident.atom);\n        break;\n    default:\n        break;\n    }\n}\n\nstatic void __attribute((unused)) dump_token(JSParseState *s,\n                                             const JSToken *token)\n{\n    switch(token->val) {\n    case TOK_NUMBER:\n        {\n            double d;\n            JS_ToFloat64(s->ctx, &d, token->u.num.val);  /* no exception possible */\n            printf(\"number: %.14g\\n\", d);\n        }\n        break;\n    case TOK_IDENT:\n    dump_atom:\n        {\n            char buf[ATOM_GET_STR_BUF_SIZE];\n            printf(\"ident: '%s'\\n\",\n                   JS_AtomGetStr(s->ctx, buf, sizeof(buf), token->u.ident.atom));\n        }\n        break;\n    case TOK_STRING:\n        {\n            const char *str;\n            /* XXX: quote the string */\n            str = JS_ToCString(s->ctx, token->u.str.str);\n            printf(\"string: '%s'\\n\", str);\n            JS_FreeCString(s->ctx, str);\n        }\n        break;\n    case TOK_TEMPLATE:\n        {\n            const char *str;\n            str = JS_ToCString(s->ctx, token->u.str.str);\n            printf(\"template: `%s`\\n\", str);\n            JS_FreeCString(s->ctx, str);\n        }\n        break;\n    case TOK_REGEXP:\n        {\n            const char *str, *str2;\n            str = JS_ToCString(s->ctx, token->u.regexp.body);\n            str2 = JS_ToCString(s->ctx, token->u.regexp.flags);\n            printf(\"regexp: '%s' '%s'\\n\", str, str2);\n            JS_FreeCString(s->ctx, str);\n            JS_FreeCString(s->ctx, str2);\n        }\n        break;\n    case TOK_EOF:\n        printf(\"eof\\n\");\n        break;\n    default:\n        if (s->token.val >= TOK_NULL && s->token.val <= TOK_LAST_KEYWORD) {\n            goto dump_atom;\n        } else if (s->token.val >= 256) {\n            printf(\"token: %d\\n\", token->val);\n        } else {\n            printf(\"token: '%c'\\n\", token->val);\n        }\n        break;\n    }\n}\n\nint __attribute__((format(printf, 2, 3))) js_parse_error(JSParseState *s, const char *fmt, ...)\n{\n    JSContext *ctx = s->ctx;\n    va_list ap;\n    int backtrace_flags;\n    \n    va_start(ap, fmt);\n    JS_ThrowError2(ctx, JS_SYNTAX_ERROR, fmt, ap, FALSE);\n    va_end(ap);\n    backtrace_flags = 0;\n    if (s->cur_func && s->cur_func->backtrace_barrier)\n        backtrace_flags = JS_BACKTRACE_FLAG_SINGLE_LEVEL;\n    build_backtrace(ctx, ctx->rt->current_exception, s->filename, s->line_num,\n                    backtrace_flags);\n    return -1;\n}\n\nstatic int js_parse_expect(JSParseState *s, int tok)\n{\n    if (s->token.val != tok) {\n        /* XXX: dump token correctly in all cases */\n        return js_parse_error(s, \"expecting '%c'\", tok);\n    }\n    return next_token(s);\n}\n\nstatic int js_parse_expect_semi(JSParseState *s)\n{\n    if (s->token.val != ';') {\n        /* automatic insertion of ';' */\n        if (s->token.val == TOK_EOF || s->token.val == '}' || s->got_lf) {\n            return 0;\n        }\n        return js_parse_error(s, \"expecting '%c'\", ';');\n    }\n    return next_token(s);\n}\n\nstatic int js_parse_error_reserved_identifier(JSParseState *s)\n{\n    char buf1[ATOM_GET_STR_BUF_SIZE];\n    return js_parse_error(s, \"'%s' is a reserved identifier\",\n                          JS_AtomGetStr(s->ctx, buf1, sizeof(buf1),\n                                        s->token.u.ident.atom));\n}\n\nstatic __exception int js_parse_template_part(JSParseState *s, const uint8_t *p)\n{\n    uint32_t c;\n    StringBuffer b_s, *b = &b_s;\n\n    /* p points to the first byte of the template part */\n    if (string_buffer_init(s->ctx, b, 32))\n        goto fail;\n    for(;;) {\n        if (p >= s->buf_end)\n            goto unexpected_eof;\n        c = *p++;\n        if (c == '`') {\n            /* template end part */\n            break;\n        }\n        if (c == '$' && *p == '{') {\n            /* template start or middle part */\n            p++;\n            break;\n        }\n        if (c == '\\\\') {\n            if (string_buffer_putc8(b, c))\n                goto fail;\n            if (p >= s->buf_end)\n                goto unexpected_eof;\n            c = *p++;\n        }\n        /* newline sequences are normalized as single '\\n' bytes */\n        if (c == '\\r') {\n            if (*p == '\\n')\n                p++;\n            c = '\\n';\n        }\n        if (c == '\\n') {\n            s->line_num++;\n        } else if (c >= 0x80) {\n            const uint8_t *p_next;\n            c = unicode_from_utf8(p - 1, UTF8_CHAR_LEN_MAX, &p_next);\n            if (c > 0x10FFFF) {\n                js_parse_error(s, \"invalid UTF-8 sequence\");\n                goto fail;\n            }\n            p = p_next;\n        }\n        if (string_buffer_putc(b, c))\n            goto fail;\n    }\n    s->token.val = TOK_TEMPLATE;\n    s->token.u.str.sep = c;\n    s->token.u.str.str = string_buffer_end(b);\n    s->buf_ptr = p;\n    return 0;\n\n unexpected_eof:\n    js_parse_error(s, \"unexpected end of string\");\n fail:\n    string_buffer_free(b);\n    return -1;\n}\n\nstatic __exception int js_parse_string(JSParseState *s, int sep,\n                                       BOOL do_throw, const uint8_t *p,\n                                       JSToken *token, const uint8_t **pp)\n{\n    int ret;\n    uint32_t c;\n    StringBuffer b_s, *b = &b_s;\n\n    /* string */\n    if (string_buffer_init(s->ctx, b, 32))\n        goto fail;\n    for(;;) {\n        if (p >= s->buf_end)\n            goto invalid_char;\n        c = *p;\n        if (c < 0x20) {\n            if (!s->cur_func) {\n                if (do_throw)\n                    js_parse_error(s, \"invalid character in a JSON string\");\n                goto fail;\n            }\n            if (sep == '`') {\n                if (c == '\\r') {\n                    if (p[1] == '\\n')\n                        p++;\n                    c = '\\n';\n                }\n                /* do not update s->line_num */\n            } else if (c == '\\n' || c == '\\r')\n                goto invalid_char;\n        }\n        p++;\n        if (c == sep)\n            break;\n        if (c == '$' && *p == '{' && sep == '`') {\n            /* template start or middle part */\n            p++;\n            break;\n        }\n        if (c == '\\\\') {\n            c = *p;\n            switch(c) {\n            case '\\0':\n                if (p >= s->buf_end)\n                    goto invalid_char;\n                p++;\n                break;\n            case '\\'':\n            case '\\\"':\n            case '\\\\':\n                p++;\n                break;\n            case '\\r':  /* accept DOS and MAC newline sequences */\n                if (p[1] == '\\n') {\n                    p++;\n                }\n                /* fall thru */\n            case '\\n':\n                /* ignore escaped newline sequence */\n                p++;\n                if (sep != '`')\n                    s->line_num++;\n                continue;\n            default:\n                if (c >= '0' && c <= '7') {\n                    if (!s->cur_func)\n                        goto invalid_octal; /* JSON case */\n                    if (!(s->cur_func->js_mode & JS_MODE_STRICT) && sep != '`')\n                        goto parse_escape;\n                    if (c == '0' && !(p[1] >= '0' && p[1] <= '9')) {\n                        p++;\n                        c = '\\0';\n                    } else {\n                    invalid_octal:\n                        if (do_throw)\n                            js_parse_error(s, \"invalid octal syntax in strict mode\");\n                        goto fail;\n                    }\n                } else if (c >= 0x80) {\n                    const uint8_t *p_next;\n                    c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p_next);\n                    if (c > 0x10FFFF) {\n                        goto invalid_utf8;\n                    }\n                    p = p_next;\n                    /* LS or PS are skipped */\n                    if (c == CP_LS || c == CP_PS)\n                        continue;\n                } else {\n                parse_escape:\n                    ret = lre_parse_escape(&p, TRUE);\n                    if (ret == -1) {\n                        if (do_throw)\n                            js_parse_error(s, \"malformed escape sequence in string literal\");\n                        goto fail;\n                    } else if (ret < 0) {\n                        /* ignore the '\\' (could output a warning) */\n                        p++;\n                    } else {\n                        c = ret;\n                    }\n                }\n                break;\n            }\n        } else if (c >= 0x80) {\n            const uint8_t *p_next;\n            c = unicode_from_utf8(p - 1, UTF8_CHAR_LEN_MAX, &p_next);\n            if (c > 0x10FFFF)\n                goto invalid_utf8;\n            p = p_next;\n        }\n        if (string_buffer_putc(b, c))\n            goto fail;\n    }\n    token->val = TOK_STRING;\n    token->u.str.sep = c;\n    token->u.str.str = string_buffer_end(b);\n    *pp = p;\n    return 0;\n\n invalid_utf8:\n    if (do_throw)\n        js_parse_error(s, \"invalid UTF-8 sequence\");\n    goto fail;\n invalid_char:\n    if (do_throw)\n        js_parse_error(s, \"unexpected end of string\");\n fail:\n    string_buffer_free(b);\n    return -1;\n}\n\nstatic inline BOOL token_is_pseudo_keyword(JSParseState *s, JSAtom atom) {\n    return s->token.val == TOK_IDENT && s->token.u.ident.atom == atom &&\n        !s->token.u.ident.has_escape;\n}\n\nstatic __exception int js_parse_regexp(JSParseState *s)\n{\n    const uint8_t *p;\n    BOOL in_class;\n    StringBuffer b_s, *b = &b_s;\n    StringBuffer b2_s, *b2 = &b2_s;\n    uint32_t c;\n\n    p = s->buf_ptr;\n    p++;\n    in_class = FALSE;\n    if (string_buffer_init(s->ctx, b, 32))\n        return -1;\n    if (string_buffer_init(s->ctx, b2, 1))\n        goto fail;\n    for(;;) {\n        if (p >= s->buf_end) {\n        eof_error:\n            js_parse_error(s, \"unexpected end of regexp\");\n            goto fail;\n        }\n        c = *p++;\n        if (c == '\\n' || c == '\\r') {\n            goto eol_error;\n        } else if (c == '/') {\n            if (!in_class)\n                break;\n        } else if (c == '[') {\n            in_class = TRUE;\n        } else if (c == ']') {\n            /* XXX: incorrect as the first character in a class */\n            in_class = FALSE;\n        } else if (c == '\\\\') {\n            if (string_buffer_putc8(b, c))\n                goto fail;\n            c = *p++;\n            if (c == '\\n' || c == '\\r')\n                goto eol_error;\n            else if (c == '\\0' && p >= s->buf_end)\n                goto eof_error;\n            else if (c >= 0x80) {\n                const uint8_t *p_next;\n                c = unicode_from_utf8(p - 1, UTF8_CHAR_LEN_MAX, &p_next);\n                if (c > 0x10FFFF) {\n                    goto invalid_utf8;\n                }\n                p = p_next;\n                if (c == CP_LS || c == CP_PS)\n                    goto eol_error;\n            }\n        } else if (c >= 0x80) {\n            const uint8_t *p_next;\n            c = unicode_from_utf8(p - 1, UTF8_CHAR_LEN_MAX, &p_next);\n            if (c > 0x10FFFF) {\n            invalid_utf8:\n                js_parse_error(s, \"invalid UTF-8 sequence\");\n                goto fail;\n            }\n            p = p_next;\n            /* LS or PS are considered as line terminator */\n            if (c == CP_LS || c == CP_PS) {\n            eol_error:\n                js_parse_error(s, \"unexpected line terminator in regexp\");\n                goto fail;\n            }\n        }\n        if (string_buffer_putc(b, c))\n            goto fail;\n    }\n\n    /* flags */\n    for(;;) {\n        const uint8_t *p_next = p;\n        c = *p_next++;\n        if (c >= 0x80) {\n            c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p_next);\n            if (c > 0x10FFFF) {\n                goto invalid_utf8;\n            }\n        }\n        if (!lre_js_is_ident_next(c))\n            break;\n        if (string_buffer_putc(b2, c))\n            goto fail;\n        p = p_next;\n    }\n\n    s->token.val = TOK_REGEXP;\n    s->token.u.regexp.body = string_buffer_end(b);\n    s->token.u.regexp.flags = string_buffer_end(b2);\n    s->buf_ptr = p;\n    return 0;\n fail:\n    string_buffer_free(b);\n    string_buffer_free(b2);\n    return -1;\n}\n\nstatic __exception int ident_realloc(JSContext *ctx, char **pbuf, size_t *psize,\n                                     char *static_buf)\n{\n    char *buf, *new_buf;\n    size_t size, new_size;\n    \n    buf = *pbuf;\n    size = *psize;\n    if (size >= (SIZE_MAX / 3) * 2)\n        new_size = SIZE_MAX;\n    else\n        new_size = size + (size >> 1);\n    if (buf == static_buf) {\n        new_buf = js_malloc(ctx, new_size);\n        if (!new_buf)\n            return -1;\n        memcpy(new_buf, buf, size);\n    } else {\n        new_buf = js_realloc(ctx, buf, new_size);\n        if (!new_buf)\n            return -1;\n    }\n    *pbuf = new_buf;\n    *psize = new_size;\n    return 0;\n}\n\n/* 'c' is the first character. Return JS_ATOM_NULL in case of error */\nstatic JSAtom parse_ident(JSParseState *s, const uint8_t **pp,\n                          BOOL *pident_has_escape, int c, BOOL is_private)\n{\n    const uint8_t *p, *p1;\n    char ident_buf[128], *buf;\n    size_t ident_size, ident_pos;\n    JSAtom atom;\n    \n    p = *pp;\n    buf = ident_buf;\n    ident_size = sizeof(ident_buf);\n    ident_pos = 0;\n    if (is_private)\n        buf[ident_pos++] = '#';\n    for(;;) {\n        p1 = p;\n        \n        if (c < 128) {\n            buf[ident_pos++] = c;\n        } else {\n            ident_pos += unicode_to_utf8((uint8_t*)buf + ident_pos, c);\n        }\n        c = *p1++;\n        if (c == '\\\\' && *p1 == 'u') {\n            c = lre_parse_escape(&p1, TRUE);\n            *pident_has_escape = TRUE;\n        } else if (c >= 128) {\n            c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1);\n        }\n        if (!lre_js_is_ident_next(c))\n            break;\n        p = p1;\n        if (unlikely(ident_pos >= ident_size - UTF8_CHAR_LEN_MAX)) {\n            if (ident_realloc(s->ctx, &buf, &ident_size, ident_buf)) {\n                atom = JS_ATOM_NULL;\n                goto done;\n            }\n        }\n    }\n    atom = JS_NewAtomLen(s->ctx, buf, ident_pos);\n done:\n    if (unlikely(buf != ident_buf))\n        js_free(s->ctx, buf);\n    *pp = p;\n    return atom;\n}\n\n\nstatic __exception int next_token(JSParseState *s)\n{\n    const uint8_t *p;\n    int c;\n    BOOL ident_has_escape;\n    JSAtom atom;\n    \n    if (js_check_stack_overflow(s->ctx->rt, 0)) {\n        return js_parse_error(s, \"stack overflow\");\n    }\n    \n    free_token(s, &s->token);\n\n    p = s->last_ptr = s->buf_ptr;\n    s->got_lf = FALSE;\n    s->last_line_num = s->token.line_num;\n redo:\n    s->token.line_num = s->line_num;\n    s->token.ptr = p;\n    c = *p;\n    switch(c) {\n    case 0:\n        if (p >= s->buf_end) {\n            s->token.val = TOK_EOF;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '`':\n        if (js_parse_template_part(s, p + 1))\n            goto fail;\n        p = s->buf_ptr;\n        break;\n    case '\\'':\n    case '\\\"':\n        if (js_parse_string(s, c, TRUE, p + 1, &s->token, &p))\n            goto fail;\n        break;\n    case '\\r':  /* accept DOS and MAC newline sequences */\n        if (p[1] == '\\n') {\n            p++;\n        }\n        /* fall thru */\n    case '\\n':\n        p++;\n    line_terminator:\n        s->got_lf = TRUE;\n        s->line_num++;\n        goto redo;\n    case '\\f':\n    case '\\v':\n    case ' ':\n    case '\\t':\n        p++;\n        goto redo;\n    case '/':\n        if (p[1] == '*') {\n            /* comment */\n            p += 2;\n            for(;;) {\n                if (*p == '\\0' && p >= s->buf_end) {\n                    js_parse_error(s, \"unexpected end of comment\");\n                    goto fail;\n                }\n                if (p[0] == '*' && p[1] == '/') {\n                    p += 2;\n                    break;\n                }\n                if (*p == '\\n') {\n                    s->line_num++;\n                    s->got_lf = TRUE; /* considered as LF for ASI */\n                    p++;\n                } else if (*p == '\\r') {\n                    s->got_lf = TRUE; /* considered as LF for ASI */\n                    p++;\n                } else if (*p >= 0x80) {\n                    c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n                    if (c == CP_LS || c == CP_PS) {\n                        s->got_lf = TRUE; /* considered as LF for ASI */\n                    } else if (c == -1) {\n                        p++; /* skip invalid UTF-8 */\n                    }\n                } else {\n                    p++;\n                }\n            }\n            goto redo;\n        } else if (p[1] == '/') {\n            /* line comment */\n            p += 2;\n        skip_line_comment:\n            for(;;) {\n                if (*p == '\\0' && p >= s->buf_end)\n                    break;\n                if (*p == '\\r' || *p == '\\n')\n                    break;\n                if (*p >= 0x80) {\n                    c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n                    /* LS or PS are considered as line terminator */\n                    if (c == CP_LS || c == CP_PS) {\n                        break;\n                    } else if (c == -1) {\n                        p++; /* skip invalid UTF-8 */\n                    }\n                } else {\n                    p++;\n                }\n            }\n            goto redo;\n        } else if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_DIV_ASSIGN;\n        } else {\n            p++;\n            s->token.val = c;\n        }\n        break;\n    case '\\\\':\n        if (p[1] == 'u') {\n            const uint8_t *p1 = p + 1;\n            int c1 = lre_parse_escape(&p1, TRUE);\n            if (c1 >= 0 && lre_js_is_ident_first(c1)) {\n                c = c1;\n                p = p1;\n                ident_has_escape = TRUE;\n                goto has_ident;\n            } else {\n                /* XXX: syntax error? */\n            }\n        }\n        goto def_token;\n    case 'a' ... 'z':\n    case 'A' ... 'Z':\n    case '_':\n    case '$':\n        /* identifier */\n        p++;\n        ident_has_escape = FALSE;\n    has_ident:\n        atom = parse_ident(s, &p, &ident_has_escape, c, FALSE);\n        if (atom == JS_ATOM_NULL)\n            goto fail;\n        s->token.u.ident.atom = atom;\n        s->token.u.ident.has_escape = ident_has_escape;\n        s->token.u.ident.is_reserved = FALSE;\n        if (s->token.u.ident.atom <= JS_ATOM_LAST_KEYWORD ||\n            (s->token.u.ident.atom <= JS_ATOM_LAST_STRICT_KEYWORD &&\n             (s->cur_func->js_mode & JS_MODE_STRICT)) ||\n            (s->token.u.ident.atom == JS_ATOM_yield &&\n             ((s->cur_func->func_kind & JS_FUNC_GENERATOR) ||\n              (s->cur_func->func_type == JS_PARSE_FUNC_ARROW &&\n               !s->cur_func->in_function_body && s->cur_func->parent &&\n               (s->cur_func->parent->func_kind & JS_FUNC_GENERATOR)))) ||\n            (s->token.u.ident.atom == JS_ATOM_await &&\n             (s->is_module ||\n              (((s->cur_func->func_kind & JS_FUNC_ASYNC) ||\n                (s->cur_func->func_type == JS_PARSE_FUNC_ARROW &&\n                 !s->cur_func->in_function_body && s->cur_func->parent &&\n                 (s->cur_func->parent->func_kind & JS_FUNC_ASYNC))))))) {\n                  if (ident_has_escape) {\n                      s->token.u.ident.is_reserved = TRUE;\n                      s->token.val = TOK_IDENT;\n                  } else {\n                      /* The keywords atoms are pre allocated */\n                      s->token.val = s->token.u.ident.atom - 1 + TOK_FIRST_KEYWORD;\n                  }\n        } else {\n            s->token.val = TOK_IDENT;\n        }\n        break;\n    case '#':\n        /* private name */\n        {\n            const uint8_t *p1;\n            p++;\n            p1 = p;\n            c = *p1++;\n            if (c == '\\\\' && *p1 == 'u') {\n                c = lre_parse_escape(&p1, TRUE);\n            } else if (c >= 128) {\n                c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1);\n            }\n            if (!lre_js_is_ident_first(c)) {\n                js_parse_error(s, \"invalid first character of private name\");\n                goto fail;\n            }\n            p = p1;\n            ident_has_escape = FALSE; /* not used */\n            atom = parse_ident(s, &p, &ident_has_escape, c, TRUE);\n            if (atom == JS_ATOM_NULL)\n                goto fail;\n            s->token.u.ident.atom = atom;\n            s->token.val = TOK_PRIVATE_NAME;\n        }\n        break;\n    case '.':\n        if (p[1] == '.' && p[2] == '.') {\n            p += 3;\n            s->token.val = TOK_ELLIPSIS;\n            break;\n        }\n        if (p[1] >= '0' && p[1] <= '9') {\n            goto parse_number;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '0':\n        /* in strict mode, octal literals are not accepted */\n        if (is_digit(p[1]) && (s->cur_func->js_mode & JS_MODE_STRICT)) {\n            js_parse_error(s, \"octal literals are deprecated in strict mode\");\n            goto fail;\n        }\n        goto parse_number;\n    case '1' ... '9':\n        /* number */\n    parse_number:\n        {\n            JSValue ret;\n            const uint8_t *p1;\n            int flags, radix;\n            flags = ATOD_ACCEPT_BIN_OCT | ATOD_ACCEPT_LEGACY_OCTAL |\n                ATOD_ACCEPT_UNDERSCORES;\n#ifdef CONFIG_BIGNUM\n            flags |= ATOD_ACCEPT_SUFFIX;\n            if (s->cur_func->js_mode & JS_MODE_MATH) {\n                flags |= ATOD_MODE_BIGINT;\n                if (s->cur_func->js_mode & JS_MODE_MATH)\n                    flags |= ATOD_TYPE_BIG_FLOAT;\n            }\n#endif\n            radix = 0;\n#ifdef CONFIG_BIGNUM\n            s->token.u.num.exponent = 0;\n            ret = js_atof2(s->ctx, (const char *)p, (const char **)&p, radix,\n                           flags, &s->token.u.num.exponent);\n#else\n            ret = js_atof(s->ctx, (const char *)p, (const char **)&p, radix,\n                          flags);\n#endif\n            if (JS_IsException(ret))\n                goto fail;\n            /* reject `10instanceof Number` */\n            if (JS_VALUE_IS_NAN(ret) ||\n                lre_js_is_ident_next(unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1))) {\n                JS_FreeValue(s->ctx, ret);\n                js_parse_error(s, \"invalid number literal\");\n                goto fail;\n            }\n            s->token.val = TOK_NUMBER;\n            s->token.u.num.val = ret;\n        }\n        break;\n    case '*':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_MUL_ASSIGN;\n        } else if (p[1] == '*') {\n            if (p[2] == '=') {\n                p += 3;\n                s->token.val = TOK_POW_ASSIGN;\n            } else {\n                p += 2;\n                s->token.val = TOK_POW;\n            }\n        } else {\n            goto def_token;\n        }\n        break;\n    case '%':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_MOD_ASSIGN;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '+':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_PLUS_ASSIGN;\n        } else if (p[1] == '+') {\n            p += 2;\n            s->token.val = TOK_INC;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '-':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_MINUS_ASSIGN;\n        } else if (p[1] == '-') {\n            if (s->allow_html_comments &&\n                p[2] == '>' && s->last_line_num != s->line_num) {\n                /* Annex B: `-->` at beginning of line is an html comment end.\n                   It extends to the end of the line.\n                 */\n                goto skip_line_comment;\n            }\n            p += 2;\n            s->token.val = TOK_DEC;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '<':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_LTE;\n        } else if (p[1] == '<') {\n            if (p[2] == '=') {\n                p += 3;\n                s->token.val = TOK_SHL_ASSIGN;\n            } else {\n                p += 2;\n                s->token.val = TOK_SHL;\n            }\n        } else if (s->allow_html_comments &&\n                   p[1] == '!' && p[2] == '-' && p[3] == '-') {\n            /* Annex B: handle `<!--` single line html comments */\n            goto skip_line_comment;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '>':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_GTE;\n        } else if (p[1] == '>') {\n            if (p[2] == '>') {\n                if (p[3] == '=') {\n                    p += 4;\n                    s->token.val = TOK_SHR_ASSIGN;\n                } else {\n                    p += 3;\n                    s->token.val = TOK_SHR;\n                }\n            } else if (p[2] == '=') {\n                p += 3;\n                s->token.val = TOK_SAR_ASSIGN;\n            } else {\n                p += 2;\n                s->token.val = TOK_SAR;\n            }\n        } else {\n            goto def_token;\n        }\n        break;\n    case '=':\n        if (p[1] == '=') {\n            if (p[2] == '=') {\n                p += 3;\n                s->token.val = TOK_STRICT_EQ;\n            } else {\n                p += 2;\n                s->token.val = TOK_EQ;\n            }\n        } else if (p[1] == '>') {\n            p += 2;\n            s->token.val = TOK_ARROW;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '!':\n        if (p[1] == '=') {\n            if (p[2] == '=') {\n                p += 3;\n                s->token.val = TOK_STRICT_NEQ;\n            } else {\n                p += 2;\n                s->token.val = TOK_NEQ;\n            }\n        } else {\n            goto def_token;\n        }\n        break;\n    case '&':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_AND_ASSIGN;\n        } else if (p[1] == '&') {\n            p += 2;\n            s->token.val = TOK_LAND;\n        } else {\n            goto def_token;\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n        /* in math mode, '^' is the power operator. '^^' is always the\n           xor operator and '**' is always the power operator */\n    case '^':\n        if (p[1] == '=') {\n            p += 2;\n            if (s->cur_func->js_mode & JS_MODE_MATH)\n                s->token.val = TOK_MATH_POW_ASSIGN;\n            else\n                s->token.val = TOK_XOR_ASSIGN;\n        } else if (p[1] == '^') {\n            if (p[2] == '=') {\n                p += 3;\n                s->token.val = TOK_XOR_ASSIGN;\n            } else {\n                p += 2;\n                s->token.val = '^';\n            }\n        } else {\n            p++;\n            if (s->cur_func->js_mode & JS_MODE_MATH)\n                s->token.val = TOK_MATH_POW;\n            else\n                s->token.val = '^';\n        }\n        break;\n#else\n    case '^':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_XOR_ASSIGN;\n        } else {\n            goto def_token;\n        }\n        break;\n#endif\n    case '|':\n        if (p[1] == '=') {\n            p += 2;\n            s->token.val = TOK_OR_ASSIGN;\n        } else if (p[1] == '|') {\n            p += 2;\n            s->token.val = TOK_LOR;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '?':\n        if (p[1] == '?') {\n            p += 2;\n            s->token.val = TOK_DOUBLE_QUESTION_MARK;\n        } else if (p[1] == '.' && !(p[2] >= '0' && p[2] <= '9')) {\n            p += 2;\n            s->token.val = TOK_QUESTION_MARK_DOT;\n        } else {\n            goto def_token;\n        }\n        break;\n    default:\n        if (c >= 128) {\n            /* unicode value */\n            c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n            switch(c) {\n            case CP_PS:\n            case CP_LS:\n                /* XXX: should avoid incrementing line_number, but\n                   needed to handle HTML comments */\n                goto line_terminator; \n            default:\n                if (lre_is_space(c)) {\n                    goto redo;\n                } else if (lre_js_is_ident_first(c)) {\n                    ident_has_escape = FALSE;\n                    goto has_ident;\n                } else {\n                    js_parse_error(s, \"unexpected character\");\n                    goto fail;\n                }\n            }\n        }\n    def_token:\n        s->token.val = c;\n        p++;\n        break;\n    }\n    s->buf_ptr = p;\n\n    //    dump_token(s, &s->token);\n    return 0;\n\n fail:\n    s->token.val = TOK_ERROR;\n    return -1;\n}\n\n/* 'c' is the first character. Return JS_ATOM_NULL in case of error */\nstatic JSAtom json_parse_ident(JSParseState *s, const uint8_t **pp, int c)\n{\n    const uint8_t *p;\n    char ident_buf[128], *buf;\n    size_t ident_size, ident_pos;\n    JSAtom atom;\n    \n    p = *pp;\n    buf = ident_buf;\n    ident_size = sizeof(ident_buf);\n    ident_pos = 0;\n    for(;;) {\n        buf[ident_pos++] = c;\n        c = *p;\n        if (c >= 128 ||\n            !((lre_id_continue_table_ascii[c >> 5] >> (c & 31)) & 1))\n            break;\n        p++;\n        if (unlikely(ident_pos >= ident_size - UTF8_CHAR_LEN_MAX)) {\n            if (ident_realloc(s->ctx, &buf, &ident_size, ident_buf)) {\n                atom = JS_ATOM_NULL;\n                goto done;\n            }\n        }\n    }\n    atom = JS_NewAtomLen(s->ctx, buf, ident_pos);\n done:\n    if (unlikely(buf != ident_buf))\n        js_free(s->ctx, buf);\n    *pp = p;\n    return atom;\n}\n\nstatic __exception int json_next_token(JSParseState *s)\n{\n    const uint8_t *p;\n    int c;\n    JSAtom atom;\n    \n    if (js_check_stack_overflow(s->ctx->rt, 0)) {\n        return js_parse_error(s, \"stack overflow\");\n    }\n    \n    free_token(s, &s->token);\n\n    p = s->last_ptr = s->buf_ptr;\n    s->last_line_num = s->token.line_num;\n redo:\n    s->token.line_num = s->line_num;\n    s->token.ptr = p;\n    c = *p;\n    switch(c) {\n    case 0:\n        if (p >= s->buf_end) {\n            s->token.val = TOK_EOF;\n        } else {\n            goto def_token;\n        }\n        break;\n    case '\\'':\n        if (!s->ext_json) {\n            /* JSON does not accept single quoted strings */\n            goto def_token;\n        }\n        /* fall through */\n    case '\\\"':\n        if (js_parse_string(s, c, TRUE, p + 1, &s->token, &p))\n            goto fail;\n        break;\n    case '\\r':  /* accept DOS and MAC newline sequences */\n        if (p[1] == '\\n') {\n            p++;\n        }\n        /* fall thru */\n    case '\\n':\n        p++;\n        s->line_num++;\n        goto redo;\n    case '\\f':\n    case '\\v':\n        if (!s->ext_json) {\n            /* JSONWhitespace does not match <VT>, nor <FF> */\n            goto def_token;\n        }\n        /* fall through */\n    case ' ':\n    case '\\t':\n        p++;\n        goto redo;\n    case '/':\n        if (!s->ext_json) {\n            /* JSON does not accept comments */\n            goto def_token;\n        }\n        if (p[1] == '*') {\n            /* comment */\n            p += 2;\n            for(;;) {\n                if (*p == '\\0' && p >= s->buf_end) {\n                    js_parse_error(s, \"unexpected end of comment\");\n                    goto fail;\n                }\n                if (p[0] == '*' && p[1] == '/') {\n                    p += 2;\n                    break;\n                }\n                if (*p == '\\n') {\n                    s->line_num++;\n                    p++;\n                } else if (*p == '\\r') {\n                    p++;\n                } else if (*p >= 0x80) {\n                    c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n                    if (c == -1) {\n                        p++; /* skip invalid UTF-8 */\n                    }\n                } else {\n                    p++;\n                }\n            }\n            goto redo;\n        } else if (p[1] == '/') {\n            /* line comment */\n            p += 2;\n            for(;;) {\n                if (*p == '\\0' && p >= s->buf_end)\n                    break;\n                if (*p == '\\r' || *p == '\\n')\n                    break;\n                if (*p >= 0x80) {\n                    c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n                    /* LS or PS are considered as line terminator */\n                    if (c == CP_LS || c == CP_PS) {\n                        break;\n                    } else if (c == -1) {\n                        p++; /* skip invalid UTF-8 */\n                    }\n                } else {\n                    p++;\n                }\n            }\n            goto redo;\n        } else {\n            goto def_token;\n        }\n        break;\n    case 'a' ... 'z':\n    case 'A' ... 'Z':\n    case '_':\n    case '$':\n        /* identifier : only pure ascii characters are accepted */\n        p++;\n        atom = json_parse_ident(s, &p, c);\n        if (atom == JS_ATOM_NULL)\n            goto fail;\n        s->token.u.ident.atom = atom;\n        s->token.u.ident.has_escape = FALSE;\n        s->token.u.ident.is_reserved = FALSE;\n        s->token.val = TOK_IDENT;\n        break;\n    case '+':\n        if (!s->ext_json || !is_digit(p[1]))\n            goto def_token;\n        goto parse_number;\n    case '0':\n        if (is_digit(p[1]))\n            goto def_token;\n        goto parse_number;\n    case '-':\n        if (!is_digit(p[1]))\n            goto def_token;\n        goto parse_number;\n    case '1' ... '9':\n        /* number */\n    parse_number:\n        {\n            JSValue ret;\n            int flags, radix;\n            if (!s->ext_json) {\n                flags = 0;\n                radix = 10;\n            } else {\n                flags = ATOD_ACCEPT_BIN_OCT;\n                radix = 0;\n            }\n            ret = js_atof(s->ctx, (const char *)p, (const char **)&p, radix,\n                          flags);\n            if (JS_IsException(ret))\n                goto fail;\n            s->token.val = TOK_NUMBER;\n            s->token.u.num.val = ret;\n        }\n        break;\n    default:\n        if (c >= 128) {\n            js_parse_error(s, \"unexpected character\");\n            goto fail;\n        }\n    def_token:\n        s->token.val = c;\n        p++;\n        break;\n    }\n    s->buf_ptr = p;\n\n    //    dump_token(s, &s->token);\n    return 0;\n\n fail:\n    s->token.val = TOK_ERROR;\n    return -1;\n}\n\n/* only used for ':' and '=>', 'let' or 'function' look-ahead. *pp is\n   only set if TOK_IMPORT is returned */\n/* XXX: handle all unicode cases */\nstatic int simple_next_token(const uint8_t **pp, BOOL no_line_terminator)\n{\n    const uint8_t *p;\n    uint32_t c;\n    \n    /* skip spaces and comments */\n    p = *pp;\n    for (;;) {\n        switch(c = *p++) {\n        case '\\r':\n        case '\\n':\n            if (no_line_terminator)\n                return '\\n';\n            continue;\n        case ' ':\n        case '\\t':\n        case '\\v':\n        case '\\f':\n            continue;\n        case '/':\n            if (*p == '/') {\n                if (no_line_terminator)\n                    return '\\n';\n                while (*p && *p != '\\r' && *p != '\\n')\n                    p++;\n                continue;\n            }\n            if (*p == '*') {\n                while (*++p) {\n                    if ((*p == '\\r' || *p == '\\n') && no_line_terminator)\n                        return '\\n';\n                    if (*p == '*' && p[1] == '/') {\n                        p += 2;\n                        break;\n                    }\n                }\n                continue;\n            }\n            break;\n        case '=':\n            if (*p == '>')\n                return TOK_ARROW;\n            break;\n        default:\n            if (lre_js_is_ident_first(c)) {\n                if (c == 'i') {\n                    if (p[0] == 'n' && !lre_js_is_ident_next(p[1])) {\n                        return TOK_IN;\n                    }\n                    if (p[0] == 'm' && p[1] == 'p' && p[2] == 'o' &&\n                        p[3] == 'r' && p[4] == 't' &&\n                        !lre_js_is_ident_next(p[5])) {\n                        *pp = p + 5;\n                        return TOK_IMPORT;\n                    }\n                } else if (c == 'o' && *p == 'f' && !lre_js_is_ident_next(p[1])) {\n                    return TOK_OF;\n                } else if (c == 'e' &&\n                           p[0] == 'x' && p[1] == 'p' && p[2] == 'o' &&\n                           p[3] == 'r' && p[4] == 't' &&\n                           !lre_js_is_ident_next(p[5])) {\n                    *pp = p + 5;\n                    return TOK_EXPORT;\n                } else if (c == 'f' && p[0] == 'u' && p[1] == 'n' &&\n                         p[2] == 'c' && p[3] == 't' && p[4] == 'i' &&\n                         p[5] == 'o' && p[6] == 'n' && !lre_js_is_ident_next(p[7])) {\n                    return TOK_FUNCTION;\n                }\n                return TOK_IDENT;\n            }\n            break;\n        }\n        return c;\n    }\n}\n\nstatic int peek_token(JSParseState *s, BOOL no_line_terminator)\n{\n    const uint8_t *p = s->buf_ptr;\n    return simple_next_token(&p, no_line_terminator);\n}\n\n/* return true if 'input' contains the source of a module\n   (heuristic). 'input' must be a zero terminated.\n\n   Heuristic: skip comments and expect 'import' keyword not followed\n   by '(' or '.' or export keyword.\n*/\nBOOL JS_DetectModule(const char *input, size_t input_len)\n{\n    const uint8_t *p = (const uint8_t *)input;\n    int tok;\n    switch(simple_next_token(&p, FALSE)) {\n    case TOK_IMPORT:\n        tok = simple_next_token(&p, FALSE);\n        return (tok != '.' && tok != '(');\n    case TOK_EXPORT:\n        return TRUE;\n    default:\n        return FALSE;\n    }\n}\n\nstatic inline int get_prev_opcode(JSFunctionDef *fd) {\n    if (fd->last_opcode_pos < 0)\n        return OP_invalid;\n    else\n        return fd->byte_code.buf[fd->last_opcode_pos];\n}\n\nstatic BOOL js_is_live_code(JSParseState *s) {\n    switch (get_prev_opcode(s->cur_func)) {\n    case OP_tail_call:\n    case OP_tail_call_method:\n    case OP_return:\n    case OP_return_undef:\n    case OP_return_async:\n    case OP_throw:\n    case OP_throw_var:\n    case OP_goto:\n#if SHORT_OPCODES\n    case OP_goto8:\n    case OP_goto16:\n#endif\n    case OP_ret:\n        return FALSE;\n    default:\n        return TRUE;\n    }\n}\n\nstatic void emit_u8(JSParseState *s, uint8_t val)\n{\n    dbuf_putc(&s->cur_func->byte_code, val);\n}\n\nstatic void emit_u16(JSParseState *s, uint16_t val)\n{\n    dbuf_put_u16(&s->cur_func->byte_code, val);\n}\n\nstatic void emit_u32(JSParseState *s, uint32_t val)\n{\n    dbuf_put_u32(&s->cur_func->byte_code, val);\n}\n\nstatic void emit_op(JSParseState *s, uint8_t val)\n{\n    JSFunctionDef *fd = s->cur_func;\n    DynBuf *bc = &fd->byte_code;\n\n    /* Use the line number of the last token used, not the next token,\n       nor the current offset in the source file.\n     */\n    if (unlikely(fd->last_opcode_line_num != s->last_line_num)) {\n        dbuf_putc(bc, OP_line_num);\n        dbuf_put_u32(bc, s->last_line_num);\n        fd->last_opcode_line_num = s->last_line_num;\n    }\n    fd->last_opcode_pos = bc->size;\n    dbuf_putc(bc, val);\n}\n\nstatic void emit_atom(JSParseState *s, JSAtom name)\n{\n    emit_u32(s, JS_DupAtom(s->ctx, name));\n}\n\nstatic int update_label(JSFunctionDef *s, int label, int delta)\n{\n    LabelSlot *ls;\n\n    assert(label >= 0 && label < s->label_count);\n    ls = &s->label_slots[label];\n    ls->ref_count += delta;\n    assert(ls->ref_count >= 0);\n    return ls->ref_count;\n}\n\nstatic int new_label_fd(JSFunctionDef *fd, int label)\n{\n    LabelSlot *ls;\n\n    if (label < 0) {\n        if (js_resize_array(fd->ctx, (void *)&fd->label_slots,\n                            sizeof(fd->label_slots[0]),\n                            &fd->label_size, fd->label_count + 1))\n            return -1;\n        label = fd->label_count++;\n        ls = &fd->label_slots[label];\n        ls->ref_count = 0;\n        ls->pos = -1;\n        ls->pos2 = -1;\n        ls->addr = -1;\n        ls->first_reloc = NULL;\n    }\n    return label;\n}\n\nstatic int new_label(JSParseState *s)\n{\n    return new_label_fd(s->cur_func, -1);\n}\n\n/* return the label ID offset */\nstatic int emit_label(JSParseState *s, int label)\n{\n    if (label >= 0) {\n        emit_op(s, OP_label);\n        emit_u32(s, label);\n        s->cur_func->label_slots[label].pos = s->cur_func->byte_code.size;\n        return s->cur_func->byte_code.size - 4;\n    } else {\n        return -1;\n    }\n}\n\n/* return label or -1 if dead code */\nstatic int emit_goto(JSParseState *s, int opcode, int label)\n{\n    if (js_is_live_code(s)) {\n        if (label < 0)\n            label = new_label(s);\n        emit_op(s, opcode);\n        emit_u32(s, label);\n        s->cur_func->label_slots[label].ref_count++;\n        return label;\n    }\n    return -1;\n}\n\n/* return the constant pool index. 'val' is not duplicated. */\nstatic int cpool_add(JSParseState *s, JSValue val)\n{\n    JSFunctionDef *fd = s->cur_func;\n    \n    if (js_resize_array(s->ctx, (void *)&fd->cpool, sizeof(fd->cpool[0]),\n                        &fd->cpool_size, fd->cpool_count + 1))\n        return -1;\n    fd->cpool[fd->cpool_count++] = val;\n    return fd->cpool_count - 1;\n}\n\nstatic __exception int emit_push_const(JSParseState *s, JSValueConst val,\n                                       BOOL as_atom)\n{\n    int idx;\n\n    if (JS_VALUE_GET_TAG(val) == JS_TAG_STRING && as_atom) {\n        JSAtom atom;\n        /* warning: JS_NewAtomStr frees the string value */\n        JS_DupValue(s->ctx, val);\n        atom = JS_NewAtomStr(s->ctx, JS_VALUE_GET_STRING(val));\n        if (atom != JS_ATOM_NULL && !__JS_AtomIsTaggedInt(atom)) {\n            emit_op(s, OP_push_atom_value);\n            emit_u32(s, atom);\n            return 0;\n        }\n    }\n\n    idx = cpool_add(s, JS_DupValue(s->ctx, val));\n    if (idx < 0)\n        return -1;\n    emit_op(s, OP_push_const);\n    emit_u32(s, idx);\n    return 0;\n}\n\n/* return the variable index or -1 if not found,\n   add ARGUMENT_VAR_OFFSET for argument variables */\nstatic int find_arg(JSContext *ctx, JSFunctionDef *fd, JSAtom name)\n{\n    int i;\n    for(i = fd->arg_count; i-- > 0;) {\n        if (fd->args[i].var_name == name)\n            return i | ARGUMENT_VAR_OFFSET;\n    }\n    return -1;\n}\n\nstatic int find_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)\n{\n    int i;\n    for(i = fd->var_count; i-- > 0;) {\n        if (fd->vars[i].var_name == name && fd->vars[i].scope_level == 0)\n            return i;\n    }\n    return find_arg(ctx, fd, name);\n}\n\n/* return true if scope == parent_scope or if scope is a child of\n   parent_scope */\nstatic BOOL is_child_scope(JSContext *ctx, JSFunctionDef *fd,\n                           int scope, int parent_scope)\n{\n    while (scope >= 0) {\n        if (scope == parent_scope)\n            return TRUE;\n        scope = fd->scopes[scope].parent;\n    }\n    return FALSE;\n}\n\n/* find a 'var' declaration in the same scope or a child scope */\nstatic int find_var_in_child_scope(JSContext *ctx, JSFunctionDef *fd,\n                                   JSAtom name, int scope_level)\n{\n    int i;\n    for(i = 0; i < fd->var_count; i++) {\n        JSVarDef *vd = &fd->vars[i];\n        if (vd->var_name == name && vd->scope_level == 0) {\n            if (is_child_scope(ctx, fd, vd->func_pool_or_scope_idx,\n                               scope_level))\n                return i;\n        }\n    }\n    return -1;\n}\n\n\nstatic JSHoistedDef *find_hoisted_def(JSFunctionDef *fd, JSAtom name)\n{\n    int i;\n    for(i = 0; i < fd->hoisted_def_count; i++) {\n        JSHoistedDef *hf = &fd->hoisted_def[i];\n        if (hf->var_name == name)\n            return hf;\n    }\n    return NULL;\n\n}\n\nstatic JSHoistedDef *find_lexical_hoisted_def(JSFunctionDef *fd, JSAtom name)\n{\n    JSHoistedDef *hf = find_hoisted_def(fd, name);\n    if (hf && hf->is_lexical)\n        return hf;\n    else\n        return NULL;\n}\n\nstatic int find_lexical_decl(JSContext *ctx, JSFunctionDef *fd, JSAtom name,\n                             int scope_idx, BOOL check_catch_var)\n{\n    while (scope_idx >= 0) {\n        JSVarDef *vd = &fd->vars[scope_idx];\n        if (vd->var_name == name &&\n            (vd->is_lexical || (vd->var_kind == JS_VAR_CATCH &&\n                                check_catch_var)))\n            return scope_idx;\n        scope_idx = vd->scope_next;\n    }\n\n    if (fd->is_eval && fd->eval_type == JS_EVAL_TYPE_GLOBAL) {\n        if (find_lexical_hoisted_def(fd, name))\n            return GLOBAL_VAR_OFFSET;\n    }\n    return -1;\n}\n\nstatic int push_scope(JSParseState *s) {\n    if (s->cur_func) {\n        JSFunctionDef *fd = s->cur_func;\n        int scope = fd->scope_count;\n        /* XXX: should check for scope overflow */\n        if ((fd->scope_count + 1) > fd->scope_size) {\n            int new_size;\n            size_t slack;\n            JSVarScope *new_buf;\n            /* XXX: potential arithmetic overflow */\n            new_size = max_int(fd->scope_count + 1, fd->scope_size * 3 / 2);\n            if (fd->scopes == fd->def_scope_array) {\n                new_buf = js_realloc2(s->ctx, NULL, new_size * sizeof(*fd->scopes), &slack);\n                if (!new_buf)\n                    return -1;\n                memcpy(new_buf, fd->scopes, fd->scope_count * sizeof(*fd->scopes));\n            } else {\n                new_buf = js_realloc2(s->ctx, fd->scopes, new_size * sizeof(*fd->scopes), &slack);\n                if (!new_buf)\n                    return -1;\n            }\n            new_size += slack / sizeof(*new_buf);\n            fd->scopes = new_buf;\n            fd->scope_size = new_size;\n        }\n        fd->scope_count++;\n        fd->scopes[scope].parent = fd->scope_level;\n        fd->scopes[scope].first = fd->scope_first;\n        emit_op(s, OP_enter_scope);\n        emit_u16(s, scope);\n        return fd->scope_level = scope;\n    }\n    return 0;\n}\n\nstatic int get_first_lexical_var(JSFunctionDef *fd, int scope)\n{\n    while (scope >= 0) {\n        int scope_idx = fd->scopes[scope].first;\n        if (scope_idx >= 0)\n            return scope_idx;\n        scope = fd->scopes[scope].parent;\n    }\n    return -1;\n}\n\nstatic void pop_scope(JSParseState *s) {\n    if (s->cur_func) {\n        /* disable scoped variables */\n        JSFunctionDef *fd = s->cur_func;\n        int scope = fd->scope_level;\n        emit_op(s, OP_leave_scope);\n        emit_u16(s, scope);\n        fd->scope_level = fd->scopes[scope].parent;\n        fd->scope_first = get_first_lexical_var(fd, fd->scope_level);\n    }\n}\n\nstatic void close_scopes(JSParseState *s, int scope, int scope_stop)\n{\n    while (scope > scope_stop) {\n        emit_op(s, OP_leave_scope);\n        emit_u16(s, scope);\n        scope = s->cur_func->scopes[scope].parent;\n    }\n}\n\n/* return the variable index or -1 if error */\nstatic int add_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)\n{\n    JSVarDef *vd;\n\n    /* the local variable indexes are currently stored on 16 bits */\n    if (fd->var_count >= JS_MAX_LOCAL_VARS) {\n        JS_ThrowInternalError(ctx, \"too many local variables\");\n        return -1;\n    }\n    if (js_resize_array(ctx, (void **)&fd->vars, sizeof(fd->vars[0]),\n                        &fd->var_size, fd->var_count + 1))\n        return -1;\n    vd = &fd->vars[fd->var_count++];\n    memset(vd, 0, sizeof(*vd));\n    vd->var_name = JS_DupAtom(ctx, name);\n    return fd->var_count - 1;\n}\n\nstatic int add_scope_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name,\n                         JSVarKindEnum var_kind)\n{\n    int idx = add_var(ctx, fd, name);\n    if (idx >= 0) {\n        JSVarDef *vd = &fd->vars[idx];\n        vd->var_kind = var_kind;\n        vd->scope_level = fd->scope_level;\n        vd->scope_next = fd->scope_first;\n        fd->scopes[fd->scope_level].first = idx;\n        fd->scope_first = idx;\n    }\n    return idx;\n}\n\nstatic int add_func_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)\n{\n    int idx = fd->func_var_idx;\n    if (idx < 0 && (idx = add_var(ctx, fd, name)) >= 0) {\n        fd->func_var_idx = idx;\n        fd->vars[idx].is_func_var = TRUE;\n        if (fd->js_mode & JS_MODE_STRICT)\n            fd->vars[idx].is_const = TRUE;\n    }\n    return idx;\n}\n\nstatic int add_arguments_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)\n{\n    int idx = fd->arguments_var_idx;\n    if (idx < 0 && (idx = add_var(ctx, fd, name)) >= 0) {\n        fd->arguments_var_idx = idx;\n    }\n    return idx;\n}\n\nstatic int add_arg(JSContext *ctx, JSFunctionDef *fd, JSAtom name)\n{\n    JSVarDef *vd;\n\n    /* the local variable indexes are currently stored on 16 bits */\n    if (fd->arg_count >= JS_MAX_LOCAL_VARS) {\n        JS_ThrowInternalError(ctx, \"too many arguments\");\n        return -1;\n    }\n    if (js_resize_array(ctx, (void **)&fd->args, sizeof(fd->args[0]),\n                        &fd->arg_size, fd->arg_count + 1))\n        return -1;\n    vd = &fd->args[fd->arg_count++];\n    memset(vd, 0, sizeof(*vd));\n    vd->var_name = JS_DupAtom(ctx, name);\n    return fd->arg_count - 1;\n}\n\n/* add a Hoisted definition for a function (cpool_idx >= 0) or a\n   global variable (cpool_idx = -1) */\nstatic JSHoistedDef *add_hoisted_def(JSContext *ctx,\n                                     JSFunctionDef *s, int cpool_idx,\n                                     JSAtom name, int var_idx, BOOL is_lexical)\n{\n    JSHoistedDef *hf;\n\n    if (js_resize_array(ctx, (void **)&s->hoisted_def,\n                        sizeof(s->hoisted_def[0]),\n                        &s->hoisted_def_size, s->hoisted_def_count + 1))\n        return NULL;\n    hf = &s->hoisted_def[s->hoisted_def_count++];\n    hf->cpool_idx = cpool_idx;\n    hf->force_init = 0;\n    hf->is_lexical = is_lexical;\n    hf->is_const = FALSE;\n    hf->var_idx = var_idx;\n    hf->scope_level = s->scope_level;\n    hf->var_name = JS_ATOM_NULL;\n    if (name != JS_ATOM_NULL) {\n        hf->var_name = JS_DupAtom(ctx, name);\n    }\n    return hf;\n}\n\ntypedef enum {\n    JS_VAR_DEF_WITH,\n    JS_VAR_DEF_LET,\n    JS_VAR_DEF_CONST,\n    JS_VAR_DEF_FUNCTION_DECL, /* function declaration */\n    JS_VAR_DEF_NEW_FUNCTION_DECL, /* async/generator function declaration */\n    JS_VAR_DEF_CATCH,\n    JS_VAR_DEF_VAR,\n} JSVarDefEnum;\n\nstatic int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,\n                      JSVarDefEnum var_def_type)\n{\n    JSContext *ctx = s->ctx;\n    JSVarDef *vd;\n    int idx;\n\n    switch (var_def_type) {\n    case JS_VAR_DEF_WITH:\n        idx = add_scope_var(ctx, fd, name, JS_VAR_NORMAL);\n        break;\n\n    case JS_VAR_DEF_LET:\n    case JS_VAR_DEF_CONST:\n    case JS_VAR_DEF_FUNCTION_DECL:\n    case JS_VAR_DEF_NEW_FUNCTION_DECL:\n        idx = find_lexical_decl(ctx, fd, name, fd->scope_first, TRUE);\n        if (idx >= 0) {\n            if (idx < GLOBAL_VAR_OFFSET) {\n                if (fd->vars[idx].scope_level == fd->scope_level) {\n                    /* same scope: in non strict mode, functions\n                       can be redefined (annex B.3.3.4). */\n                    if (!(!(fd->js_mode & JS_MODE_STRICT) &&\n                          var_def_type == JS_VAR_DEF_FUNCTION_DECL &&\n                          fd->vars[idx].var_kind == JS_VAR_FUNCTION_DECL)) {\n                        goto redef_lex_error;\n                    }\n                } else if (fd->vars[idx].var_kind == JS_VAR_CATCH && (fd->vars[idx].scope_level + 2) == fd->scope_level) {\n                    goto redef_lex_error;\n                }\n            } else {\n                if (fd->scope_level == 1) {\n                redef_lex_error:\n                    /* redefining a scoped var in the same scope: error */\n                    return js_parse_error(s, \"invalid redefinition of lexical identifier\");\n                }\n            }\n        }\n        if (var_def_type != JS_VAR_DEF_FUNCTION_DECL &&\n            var_def_type != JS_VAR_DEF_NEW_FUNCTION_DECL &&\n            fd->scope_level == 1 &&\n            find_arg(ctx, fd, name) >= 0) {\n            /* lexical variable redefines a parameter name */\n            return js_parse_error(s, \"invalid redefinition of parameter name\");\n        }\n\n        if (find_var_in_child_scope(ctx, fd, name, fd->scope_level) >= 0) {\n            return js_parse_error(s, \"invalid redefinition of a variable\");\n        }\n        \n        if (fd->is_global_var) {\n            JSHoistedDef *hf;\n            hf = find_hoisted_def(fd, name);\n            if (hf && is_child_scope(ctx, fd, hf->scope_level,\n                                     fd->scope_level)) {\n                return js_parse_error(s, \"invalid redefinition of global identifier\");\n            }\n        }\n        \n        if (fd->is_eval &&\n            (fd->eval_type == JS_EVAL_TYPE_GLOBAL ||\n             fd->eval_type == JS_EVAL_TYPE_MODULE) &&\n            fd->scope_level == 1) {\n            JSHoistedDef *hf;\n            hf = add_hoisted_def(s->ctx, fd, -1, name, -1, TRUE);\n            if (!hf)\n                return -1;\n            hf->is_const = (var_def_type == JS_VAR_DEF_CONST);\n            idx = GLOBAL_VAR_OFFSET;\n        } else {\n            JSVarKindEnum var_kind;\n            if (var_def_type == JS_VAR_DEF_FUNCTION_DECL)\n                var_kind = JS_VAR_FUNCTION_DECL;\n            else if (var_def_type == JS_VAR_DEF_NEW_FUNCTION_DECL)\n                var_kind = JS_VAR_NEW_FUNCTION_DECL;\n            else\n                var_kind = JS_VAR_NORMAL;\n            idx = add_scope_var(ctx, fd, name, var_kind);\n            if (idx >= 0) {\n                vd = &fd->vars[idx];\n                vd->is_lexical = 1;\n                vd->is_const = (var_def_type == JS_VAR_DEF_CONST);\n            }\n        }\n        break;\n\n    case JS_VAR_DEF_CATCH:\n        idx = add_scope_var(ctx, fd, name, JS_VAR_CATCH);\n        break;\n\n    case JS_VAR_DEF_VAR:\n        if (find_lexical_decl(ctx, fd, name, fd->scope_first,\n                              FALSE) >= 0) {\n       invalid_lexical_redefinition:\n            /* error to redefine a var that inside a lexical scope */\n            return js_parse_error(s, \"invalid redefinition of lexical identifier\");\n        }\n        if (fd->is_global_var) {\n            JSHoistedDef *hf;\n            hf = find_hoisted_def(fd, name);\n            if (hf && hf->is_lexical && hf->scope_level == fd->scope_level &&\n                fd->eval_type == JS_EVAL_TYPE_MODULE) {\n                goto invalid_lexical_redefinition;\n            }\n            hf = add_hoisted_def(s->ctx, fd, -1, name, -1, FALSE);\n            if (!hf)\n                return -1;\n            idx = GLOBAL_VAR_OFFSET;\n        } else {\n            /* if the variable already exists, don't add it again  */\n            idx = find_var(ctx, fd, name);\n            if (idx >= 0)\n                break;\n            idx = add_var(ctx, fd, name);\n            if (idx >= 0) {\n                if (name == JS_ATOM_arguments && fd->has_arguments_binding)\n                    fd->arguments_var_idx = idx;\n                fd->vars[idx].func_pool_or_scope_idx = fd->scope_level;\n            }\n        }\n        break;\n    default:\n        abort();\n    }\n    return idx;\n}\n\n/* add a private field variable in the current scope */\nstatic int add_private_class_field(JSParseState *s, JSFunctionDef *fd,\n                                   JSAtom name, JSVarKindEnum var_kind)\n{\n    JSContext *ctx = s->ctx;\n    JSVarDef *vd;\n    int idx;\n\n    idx = add_scope_var(ctx, fd, name, var_kind);\n    if (idx < 0)\n        return idx;\n    vd = &fd->vars[idx];\n    vd->is_lexical = 1;\n    vd->is_const = 1;\n    return idx;\n}\n\nstatic __exception int js_parse_expr(JSParseState *s);\nstatic __exception int js_parse_function_decl(JSParseState *s,\n                                              JSParseFunctionEnum func_type,\n                                              JSFunctionKindEnum func_kind,\n                                              JSAtom func_name, const uint8_t *ptr,\n                                              int start_line);\nstatic JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s);\nstatic __exception int js_parse_function_decl2(JSParseState *s,\n                                               JSParseFunctionEnum func_type,\n                                               JSFunctionKindEnum func_kind,\n                                               JSAtom func_name,\n                                               const uint8_t *ptr,\n                                               int function_line_num,\n                                               JSParseExportEnum export_flag,\n                                               JSFunctionDef **pfd);\nstatic __exception int js_parse_assign_expr(JSParseState *s, int in_accepted);\nstatic __exception int js_parse_unary(JSParseState *s, int exponentiation_flag);\nstatic void push_break_entry(JSFunctionDef *fd, BlockEnv *be,\n                             JSAtom label_name,\n                             int label_break, int label_cont,\n                             int drop_count);\nstatic void pop_break_entry(JSFunctionDef *fd);\nstatic JSExportEntry *add_export_entry(JSParseState *s, JSModuleDef *m,\n                                       JSAtom local_name, JSAtom export_name,\n                                       JSExportTypeEnum export_type);\n\n/* Note: all the fields are already sealed except length */\nstatic int seal_template_obj(JSContext *ctx, JSValueConst obj)\n{\n    JSObject *p;\n    JSShapeProperty *prs;\n\n    p = JS_VALUE_GET_OBJ(obj);\n    prs = find_own_property1(p, JS_ATOM_length);\n    if (prs) {\n        if (js_update_property_flags(ctx, p, &prs,\n                                     prs->flags & ~(JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)))\n            return -1;\n    }\n    p->extensible = FALSE;\n    return 0;\n}\n\nstatic __exception int js_parse_template(JSParseState *s, int call, int *argc)\n{\n    JSContext *ctx = s->ctx;\n    JSValue raw_array, template_object;\n    JSToken cooked;\n    int depth, ret;\n\n    raw_array = JS_UNDEFINED; /* avoid warning */\n    template_object = JS_UNDEFINED; /* avoid warning */\n    if (call) {\n        /* Create a template object: an array of cooked strings */\n        /* Create an array of raw strings and store it to the raw property */\n        template_object = JS_NewArray(ctx);\n        if (JS_IsException(template_object))\n            return -1;\n        //        pool_idx = s->cur_func->cpool_count;\n        ret = emit_push_const(s, template_object, 0);\n        JS_FreeValue(ctx, template_object);\n        if (ret)\n            return -1;\n        raw_array = JS_NewArray(ctx);\n        if (JS_IsException(raw_array))\n            return -1;\n        if (JS_DefinePropertyValue(ctx, template_object, JS_ATOM_raw,\n                                   raw_array, JS_PROP_THROW) < 0) {\n            return -1;\n        }\n    }\n\n    depth = 0;\n    while (s->token.val == TOK_TEMPLATE) {\n        const uint8_t *p = s->token.ptr + 1;\n        cooked = s->token;\n        if (call) {\n            if (JS_DefinePropertyValueUint32(ctx, raw_array, depth,\n                                             JS_DupValue(ctx, s->token.u.str.str),\n                                             JS_PROP_ENUMERABLE | JS_PROP_THROW) < 0) {\n                return -1;\n            }\n            /* re-parse the string with escape sequences but do not throw a\n               syntax error if it contains invalid sequences\n             */\n            if (js_parse_string(s, '`', FALSE, p, &cooked, &p)) {\n                cooked.u.str.str = JS_UNDEFINED;\n            }\n            if (JS_DefinePropertyValueUint32(ctx, template_object, depth,\n                                             cooked.u.str.str,\n                                             JS_PROP_ENUMERABLE | JS_PROP_THROW) < 0) {\n                return -1;\n            }\n        } else {\n            JSString *str;\n            /* re-parse the string with escape sequences and throw a\n               syntax error if it contains invalid sequences\n             */\n            JS_FreeValue(ctx, s->token.u.str.str);\n            s->token.u.str.str = JS_UNDEFINED;\n            if (js_parse_string(s, '`', TRUE, p, &cooked, &p))\n                return -1;\n            str = JS_VALUE_GET_STRING(cooked.u.str.str);\n            if (str->len != 0 || depth == 0) {\n                ret = emit_push_const(s, cooked.u.str.str, 1);\n                JS_FreeValue(s->ctx, cooked.u.str.str);\n                if (ret)\n                    return -1;\n                if (depth == 0) {\n                    if (s->token.u.str.sep == '`')\n                        goto done1;\n                    emit_op(s, OP_get_field2);\n                    emit_atom(s, JS_ATOM_concat);\n                }\n                depth++;\n            } else {\n                JS_FreeValue(s->ctx, cooked.u.str.str);\n            }\n        }\n        if (s->token.u.str.sep == '`')\n            goto done;\n        if (next_token(s))\n            return -1;\n        if (js_parse_expr(s))\n            return -1;\n        depth++;\n        if (s->token.val != '}') {\n            return js_parse_error(s, \"expected '}' after template expression\");\n        }\n        /* XXX: should convert to string at this stage? */\n        free_token(s, &s->token);\n        /* Resume TOK_TEMPLATE parsing (s->token.line_num and\n         * s->token.ptr are OK) */\n        s->got_lf = FALSE;\n        s->last_line_num = s->token.line_num;\n        if (js_parse_template_part(s, s->buf_ptr))\n            return -1;\n    }\n    return js_parse_expect(s, TOK_TEMPLATE);\n\n done:\n    if (call) {\n        /* Seal the objects */\n        seal_template_obj(ctx, raw_array);\n        seal_template_obj(ctx, template_object);\n        *argc = depth + 1;\n    } else {\n        emit_op(s, OP_call_method);\n        emit_u16(s, depth - 1);\n    }\n done1:\n    return next_token(s);\n}\n\n\n#define PROP_TYPE_IDENT 0\n#define PROP_TYPE_VAR   1\n#define PROP_TYPE_GET   2\n#define PROP_TYPE_SET   3\n#define PROP_TYPE_STAR  4\n#define PROP_TYPE_ASYNC 5\n#define PROP_TYPE_ASYNC_STAR 6\n\n#define PROP_TYPE_PRIVATE (1 << 4)\n\nstatic BOOL token_is_ident(int tok)\n{\n    /* Accept keywords and reserved words as property names */\n    return (tok == TOK_IDENT ||\n            (tok >= TOK_FIRST_KEYWORD &&\n             tok <= TOK_LAST_KEYWORD));\n}\n\n/* if the property is an expression, name = JS_ATOM_NULL */\nstatic int __exception js_parse_property_name(JSParseState *s,\n                                              JSAtom *pname,\n                                              BOOL allow_method, BOOL allow_var,\n                                              BOOL allow_private)\n{\n    int is_private = 0;\n    BOOL is_non_reserved_ident;\n    JSAtom name;\n    int prop_type;\n    \n    prop_type = PROP_TYPE_IDENT;\n    if (allow_method) {\n        if (token_is_pseudo_keyword(s, JS_ATOM_get)\n        ||  token_is_pseudo_keyword(s, JS_ATOM_set)) {\n            /* get x(), set x() */\n            name = JS_DupAtom(s->ctx, s->token.u.ident.atom);\n            if (next_token(s))\n                goto fail1;\n            if (s->token.val == ':' || s->token.val == ',' ||\n                s->token.val == '}' || s->token.val == '(') {\n                is_non_reserved_ident = TRUE;\n                goto ident_found;\n            }\n            prop_type = PROP_TYPE_GET + (name == JS_ATOM_set);\n            JS_FreeAtom(s->ctx, name);\n        } else if (s->token.val == '*') {\n            if (next_token(s))\n                goto fail;\n            prop_type = PROP_TYPE_STAR;\n        } else if (token_is_pseudo_keyword(s, JS_ATOM_async) &&\n                   peek_token(s, TRUE) != '\\n') {\n            name = JS_DupAtom(s->ctx, s->token.u.ident.atom);\n            if (next_token(s))\n                goto fail1;\n            if (s->token.val == ':' || s->token.val == ',' ||\n                s->token.val == '}' || s->token.val == '(') {\n                is_non_reserved_ident = TRUE;\n                goto ident_found;\n            }\n            JS_FreeAtom(s->ctx, name);\n            if (s->token.val == '*') {\n                if (next_token(s))\n                    goto fail;\n                prop_type = PROP_TYPE_ASYNC_STAR;\n            } else {\n                prop_type = PROP_TYPE_ASYNC;\n            }\n        }\n    }\n\n    if (token_is_ident(s->token.val)) {\n        /* variable can only be a non-reserved identifier */\n        is_non_reserved_ident =\n            (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved);\n        /* keywords and reserved words have a valid atom */\n        name = JS_DupAtom(s->ctx, s->token.u.ident.atom);\n        if (next_token(s))\n            goto fail1;\n    ident_found:\n        if (is_non_reserved_ident &&\n            prop_type == PROP_TYPE_IDENT && allow_var) {\n            if (!(s->token.val == ':' ||\n                  (s->token.val == '(' && allow_method))) {\n                prop_type = PROP_TYPE_VAR;\n            }\n        }\n    } else if (s->token.val == TOK_STRING) {\n        name = JS_ValueToAtom(s->ctx, s->token.u.str.str);\n        if (name == JS_ATOM_NULL)\n            goto fail;\n        if (next_token(s))\n            goto fail1;\n    } else if (s->token.val == TOK_NUMBER) {\n        JSValue val;\n        val = s->token.u.num.val;\n#ifdef CONFIG_BIGNUM\n        if (JS_VALUE_GET_TAG(val) == JS_TAG_BIG_FLOAT) {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            val = s->ctx->rt->bigfloat_ops.\n                mul_pow10_to_float64(s->ctx, &p->num,\n                                     s->token.u.num.exponent);\n            if (JS_IsException(val))\n                goto fail;\n            name = JS_ValueToAtom(s->ctx, val);\n            JS_FreeValue(s->ctx, val);\n        } else\n#endif\n        {\n            name = JS_ValueToAtom(s->ctx, val);\n        }\n        if (name == JS_ATOM_NULL)\n            goto fail;\n        if (next_token(s))\n            goto fail1;\n    } else if (s->token.val == '[') {\n        if (next_token(s))\n            goto fail;\n        if (js_parse_expr(s))\n            goto fail;\n        if (js_parse_expect(s, ']'))\n            goto fail;\n        name = JS_ATOM_NULL;\n    } else if (s->token.val == TOK_PRIVATE_NAME && allow_private) {\n        name = JS_DupAtom(s->ctx, s->token.u.ident.atom);\n        if (next_token(s))\n            goto fail1;\n        is_private = PROP_TYPE_PRIVATE;\n    } else {\n        goto invalid_prop;\n    }\n    if (prop_type != PROP_TYPE_IDENT && prop_type != PROP_TYPE_VAR &&\n        s->token.val != '(') {\n        JS_FreeAtom(s->ctx, name);\n    invalid_prop:\n        js_parse_error(s, \"invalid property name\");\n        goto fail;\n    }\n    *pname = name;\n    return prop_type | is_private;\n fail1:\n    JS_FreeAtom(s->ctx, name);\n fail:\n    *pname = JS_ATOM_NULL;\n    return -1;\n}\n\ntypedef struct JSParsePos {\n    int last_line_num;\n    int line_num;\n    BOOL got_lf;\n    const uint8_t *ptr;\n} JSParsePos;\n\nstatic int js_parse_get_pos(JSParseState *s, JSParsePos *sp)\n{\n    sp->last_line_num = s->last_line_num;\n    sp->line_num = s->token.line_num;\n    sp->ptr = s->token.ptr;\n    sp->got_lf = s->got_lf;\n    return 0;\n}\n\nstatic __exception int js_parse_seek_token(JSParseState *s, const JSParsePos *sp)\n{\n    s->token.line_num = sp->last_line_num;\n    s->line_num = sp->line_num;\n    s->buf_ptr = sp->ptr;\n    s->got_lf = sp->got_lf;\n    return next_token(s);\n}\n\n/* return TRUE if a regexp literal is allowed after this token */\nstatic BOOL is_regexp_allowed(int tok)\n{\n    switch (tok) {\n    case TOK_NUMBER:\n    case TOK_STRING:\n    case TOK_REGEXP:\n    case TOK_DEC:\n    case TOK_INC:\n    case TOK_NULL:\n    case TOK_FALSE:\n    case TOK_TRUE:\n    case TOK_THIS:\n    case ')':\n    case ']':\n    case '}': /* XXX: regexp may occur after */\n    case TOK_IDENT:\n        return FALSE;\n    default:\n        return TRUE;\n    }\n}\n\n#define SKIP_HAS_SEMI      (1 << 0)\n#define SKIP_HAS_ELLIPSIS  (1 << 1)\n\n/* XXX: improve speed with early bailout */\n/* XXX: no longer works if regexps are present. Could use previous\n   regexp parsing heuristics to handle most cases */\nstatic int js_parse_skip_parens_token(JSParseState *s, int *pbits, BOOL no_line_terminator)\n{\n    char state[256];\n    size_t level = 0;\n    JSParsePos pos;\n    int last_tok, tok = TOK_EOF;\n    int c, tok_len, bits = 0;\n\n    /* protect from underflow */\n    state[level++] = 0;\n\n    js_parse_get_pos(s, &pos);\n    last_tok = 0;\n    for (;;) {\n        switch(s->token.val) {\n        case '(':\n        case '[':\n        case '{':\n            if (level >= sizeof(state))\n                goto done;\n            state[level++] = s->token.val;\n            break;\n        case ')':\n            if (state[--level] != '(')\n                goto done;\n            break;\n        case ']':\n            if (state[--level] != '[')\n                goto done;\n            break;\n        case '}':\n            c = state[--level];\n            if (c == '`') {\n                /* continue the parsing of the template */\n                free_token(s, &s->token);\n                /* Resume TOK_TEMPLATE parsing (s->token.line_num and\n                 * s->token.ptr are OK) */\n                s->got_lf = FALSE;\n                s->last_line_num = s->token.line_num;\n                if (js_parse_template_part(s, s->buf_ptr))\n                    goto done;\n                goto handle_template;\n            } else if (c != '{') {\n                goto done;\n            }\n            break;\n        case TOK_TEMPLATE:\n        handle_template:\n            if (s->token.u.str.sep != '`') {\n                /* '${' inside the template : closing '}' and continue\n                   parsing the template */\n                if (level >= sizeof(state))\n                    goto done;\n                state[level++] = '`';\n            } \n            break;\n        case TOK_EOF:\n            goto done;\n        case ';':\n            if (level == 2) {\n                bits |= SKIP_HAS_SEMI;\n            }\n            break;\n        case TOK_ELLIPSIS:\n            if (level == 2) {\n                bits |= SKIP_HAS_ELLIPSIS;\n            }\n            break;\n\n        case TOK_DIV_ASSIGN:\n            tok_len = 2;\n            goto parse_regexp;\n        case '/':\n            tok_len = 1;\n        parse_regexp:\n            if (is_regexp_allowed(last_tok)) {\n                s->buf_ptr -= tok_len;\n                if (js_parse_regexp(s)) {\n                    /* XXX: should clear the exception */\n                    goto done;\n                }\n            }\n            break;\n        }\n        /* last_tok is only used to recognize regexps */\n        if (s->token.val == TOK_IDENT &&\n            (token_is_pseudo_keyword(s, JS_ATOM_of) ||\n             token_is_pseudo_keyword(s, JS_ATOM_yield))) {\n            last_tok = TOK_OF;\n        } else {\n            last_tok = s->token.val;\n        }\n        if (next_token(s)) {\n            /* XXX: should clear the exception generated by next_token() */\n            break;\n        }\n        if (level <= 1) {\n            tok = s->token.val;\n            if (token_is_pseudo_keyword(s, JS_ATOM_of))\n                tok = TOK_OF;\n            if (no_line_terminator && s->last_line_num != s->token.line_num)\n                tok = '\\n';\n            break;\n        }\n    }\n done:\n    if (pbits) {\n        *pbits = bits;\n    }\n    if (js_parse_seek_token(s, &pos))\n        return -1;\n    return tok;\n}\n\nstatic void set_object_name(JSParseState *s, JSAtom name)\n{\n    JSFunctionDef *fd = s->cur_func;\n    int opcode;\n\n    opcode = get_prev_opcode(fd);\n    if (opcode == OP_set_name) {\n        /* XXX: should free atom after OP_set_name? */\n        fd->byte_code.size = fd->last_opcode_pos;\n        fd->last_opcode_pos = -1;\n        emit_op(s, OP_set_name);\n        emit_atom(s, name);\n    } else if (opcode == OP_set_class_name) {\n        int define_class_pos;\n        JSAtom atom;\n        define_class_pos = fd->last_opcode_pos + 1 -\n            get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n        assert(fd->byte_code.buf[define_class_pos] == OP_define_class);\n        /* for consistency we free the previous atom which is\n           JS_ATOM_empty_string */\n        atom = get_u32(fd->byte_code.buf + define_class_pos + 1);\n        JS_FreeAtom(s->ctx, atom);\n        put_u32(fd->byte_code.buf + define_class_pos + 1,\n                JS_DupAtom(s->ctx, name));\n        fd->last_opcode_pos = -1;\n    }\n}\n\nstatic void set_object_name_computed(JSParseState *s)\n{\n    JSFunctionDef *fd = s->cur_func;\n    int opcode;\n\n    opcode = get_prev_opcode(fd);\n    if (opcode == OP_set_name) {\n        /* XXX: should free atom after OP_set_name? */\n        fd->byte_code.size = fd->last_opcode_pos;\n        fd->last_opcode_pos = -1;\n        emit_op(s, OP_set_name_computed);\n    } else if (opcode == OP_set_class_name) {\n        int define_class_pos;\n        define_class_pos = fd->last_opcode_pos + 1 -\n            get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n        assert(fd->byte_code.buf[define_class_pos] == OP_define_class);\n        fd->byte_code.buf[define_class_pos] = OP_define_class_computed;\n        fd->last_opcode_pos = -1;\n    }\n}\n\nstatic __exception int js_parse_object_literal(JSParseState *s)\n{\n    JSAtom name = JS_ATOM_NULL;\n    const uint8_t *start_ptr;\n    int start_line, prop_type;\n    BOOL has_proto;\n\n    if (next_token(s))\n        goto fail;\n    /* XXX: add an initial length that will be patched back */\n    emit_op(s, OP_object);\n    has_proto = FALSE;\n    while (s->token.val != '}') {\n        /* specific case for getter/setter */\n        start_ptr = s->token.ptr;\n        start_line = s->token.line_num;\n\n        if (s->token.val == TOK_ELLIPSIS) {\n            if (next_token(s))\n                return -1;\n            if (js_parse_assign_expr(s, TRUE))\n                return -1;\n            emit_op(s, OP_null);  /* dummy excludeList */\n            emit_op(s, OP_copy_data_properties);\n            emit_u8(s, 2 | (1 << 2) | (0 << 5));\n            emit_op(s, OP_drop); /* pop excludeList */\n            emit_op(s, OP_drop); /* pop src object */\n            goto next;\n        }\n\n        prop_type = js_parse_property_name(s, &name, TRUE, TRUE, FALSE);\n        if (prop_type < 0)\n            goto fail;\n\n        if (prop_type == PROP_TYPE_VAR) {\n            /* shortcut for x: x */\n            emit_op(s, OP_scope_get_var);\n            emit_atom(s, name);\n            emit_u16(s, s->cur_func->scope_level);\n            emit_op(s, OP_define_field);\n            emit_atom(s, name);\n        } else if (s->token.val == '(') {\n            BOOL is_getset = (prop_type == PROP_TYPE_GET ||\n                              prop_type == PROP_TYPE_SET);\n            JSParseFunctionEnum func_type;\n            JSFunctionKindEnum func_kind;\n            int op_flags;\n\n            func_kind = JS_FUNC_NORMAL;\n            if (is_getset) {\n                func_type = JS_PARSE_FUNC_GETTER + prop_type - PROP_TYPE_GET;\n            } else {\n                func_type = JS_PARSE_FUNC_METHOD;\n                if (prop_type == PROP_TYPE_STAR)\n                    func_kind = JS_FUNC_GENERATOR;\n                else if (prop_type == PROP_TYPE_ASYNC)\n                    func_kind = JS_FUNC_ASYNC;\n                else if (prop_type == PROP_TYPE_ASYNC_STAR)\n                    func_kind = JS_FUNC_ASYNC_GENERATOR;\n            }\n            if (js_parse_function_decl(s, func_type, func_kind, JS_ATOM_NULL,\n                                       start_ptr, start_line))\n                goto fail;\n            if (name == JS_ATOM_NULL) {\n                emit_op(s, OP_define_method_computed);\n            } else {\n                emit_op(s, OP_define_method);\n                emit_atom(s, name);\n            }\n            if (is_getset) {\n                op_flags = OP_DEFINE_METHOD_GETTER +\n                    prop_type - PROP_TYPE_GET;\n            } else {\n                op_flags = OP_DEFINE_METHOD_METHOD;\n            }\n            emit_u8(s, op_flags | OP_DEFINE_METHOD_ENUMERABLE);\n        } else {\n            if (js_parse_expect(s, ':'))\n                goto fail;\n            if (js_parse_assign_expr(s, TRUE))\n                goto fail;\n            if (name == JS_ATOM_NULL) {\n                set_object_name_computed(s);\n                emit_op(s, OP_define_array_el);\n                emit_op(s, OP_drop);\n            } else if (name == JS_ATOM___proto__) {\n                if (has_proto) {\n                    js_parse_error(s, \"duplicate __proto__ property name\");\n                    goto fail;\n                }\n                emit_op(s, OP_set_proto);\n                has_proto = TRUE;\n            } else {\n                set_object_name(s, name);\n                emit_op(s, OP_define_field);\n                emit_atom(s, name);\n            }\n        }\n        JS_FreeAtom(s->ctx, name);\n    next:\n        name = JS_ATOM_NULL;\n        if (s->token.val != ',')\n            break;\n        if (next_token(s))\n            goto fail;\n    }\n    if (js_parse_expect(s, '}'))\n        goto fail;\n    return 0;\n fail:\n    JS_FreeAtom(s->ctx, name);\n    return -1;\n}\n\nstatic __exception int js_parse_postfix_expr(JSParseState *s,\n                                             BOOL accept_lparen);\n\n/* XXX: is there is nicer solution ? */\nstatic __exception int js_parse_class_default_ctor(JSParseState *s,\n                                                   BOOL has_super,\n                                                   JSFunctionDef **pfd)\n{\n    JSParsePos pos;\n    const char *str;\n    int ret, line_num;\n    JSParseFunctionEnum func_type;\n    const uint8_t *saved_buf_end;\n    \n    js_parse_get_pos(s, &pos);\n    if (has_super) {\n        str = \"(...a){super(...a);}\";\n        func_type = JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR;\n    } else {\n        str = \"(){}\";\n        func_type = JS_PARSE_FUNC_CLASS_CONSTRUCTOR;\n    }\n    line_num = s->token.line_num;\n    saved_buf_end = s->buf_end;\n    s->buf_ptr = (uint8_t *)str;\n    s->buf_end = (uint8_t *)(str + strlen(str));\n    ret = next_token(s);\n    if (!ret) {\n        ret = js_parse_function_decl2(s, func_type, JS_FUNC_NORMAL,\n                                      JS_ATOM_NULL, (uint8_t *)str,\n                                      line_num, JS_PARSE_EXPORT_NONE, pfd);\n    }\n    s->buf_end = saved_buf_end;\n    ret |= js_parse_seek_token(s, &pos);\n    return ret;\n}\n\n/* find field in the current scope */\nstatic int find_private_class_field(JSContext *ctx, JSFunctionDef *fd,\n                                    JSAtom name, int scope_level)\n{\n    int idx;\n    idx = fd->scopes[scope_level].first;\n    while (idx != -1) {\n        if (fd->vars[idx].scope_level != scope_level)\n            break;\n        if (fd->vars[idx].var_name == name)\n            return idx;\n        idx = fd->vars[idx].scope_next;\n    }\n    return -1;\n}\n\n/* initialize the class fields, called by the constructor. Note:\n   super() can be called in an arrow function, so <this> and\n   <class_fields_init> can be variable references */\nstatic void emit_class_field_init(JSParseState *s)\n{\n    int label_next;\n    \n    emit_op(s, OP_scope_get_var);\n    emit_atom(s, JS_ATOM_class_fields_init);\n    emit_u16(s, s->cur_func->scope_level);\n\n    /* no need to call the class field initializer if not defined */\n    emit_op(s, OP_dup);\n    label_next = emit_goto(s, OP_if_false, -1);\n    \n    emit_op(s, OP_scope_get_var);\n    emit_atom(s, JS_ATOM_this);\n    emit_u16(s, 0);\n    \n    emit_op(s, OP_swap);\n    \n    emit_op(s, OP_call_method);\n    emit_u16(s, 0);\n\n    emit_label(s, label_next);\n    emit_op(s, OP_drop);\n}\n\n/* build a private setter function name from the private getter name */\nstatic JSAtom get_private_setter_name(JSContext *ctx, JSAtom name)\n{\n    return js_atom_concat_str(ctx, name, \"<set>\");\n}\n\ntypedef struct {\n    JSFunctionDef *fields_init_fd;\n    int computed_fields_count;\n    BOOL has_brand;\n    int brand_push_pos;\n} ClassFieldsDef;\n\nstatic __exception int emit_class_init_start(JSParseState *s,\n                                             ClassFieldsDef *cf)\n{\n    int label_add_brand;\n    \n    cf->fields_init_fd = js_parse_function_class_fields_init(s);\n    if (!cf->fields_init_fd)\n        return -1;\n\n    s->cur_func = cf->fields_init_fd;\n    \n    /* XXX: would be better to add the code only if needed, maybe in a\n       later pass */\n    emit_op(s, OP_push_false); /* will be patched later */\n    cf->brand_push_pos = cf->fields_init_fd->last_opcode_pos;\n    label_add_brand = emit_goto(s, OP_if_false, -1);\n    \n    emit_op(s, OP_scope_get_var);\n    emit_atom(s, JS_ATOM_this);\n    emit_u16(s, 0);\n    \n    emit_op(s, OP_scope_get_var);\n    emit_atom(s, JS_ATOM_home_object);\n    emit_u16(s, 0);\n    \n    emit_op(s, OP_add_brand);\n    \n    emit_label(s, label_add_brand);\n\n    s->cur_func = s->cur_func->parent;\n    return 0;\n}\n\nstatic __exception int add_brand(JSParseState *s, ClassFieldsDef *cf)\n{\n    if (!cf->has_brand) {\n        /* define the brand field in 'this' of the initializer */\n        if (!cf->fields_init_fd) {\n            if (emit_class_init_start(s, cf))\n                return -1;\n        }\n        /* patch the start of the function to enable the OP_add_brand code */\n        cf->fields_init_fd->byte_code.buf[cf->brand_push_pos] = OP_push_true;\n        \n        cf->has_brand = TRUE;\n    }\n    return 0;\n}\n\nstatic void emit_class_init_end(JSParseState *s, ClassFieldsDef *cf)\n{\n    int cpool_idx;\n        \n    s->cur_func = cf->fields_init_fd;\n    emit_op(s, OP_return_undef);\n    s->cur_func = s->cur_func->parent;\n    \n    cpool_idx = cpool_add(s, JS_NULL);\n    cf->fields_init_fd->parent_cpool_idx = cpool_idx;\n    emit_op(s, OP_fclosure);\n    emit_u32(s, cpool_idx);\n    emit_op(s, OP_set_home_object);\n}\n\n\nstatic __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,\n                                      JSParseExportEnum export_flag)\n{\n    JSContext *ctx = s->ctx;\n    JSFunctionDef *fd = s->cur_func;\n    JSAtom name = JS_ATOM_NULL, class_name = JS_ATOM_NULL, class_name1;\n    JSAtom class_var_name = JS_ATOM_NULL;\n    JSFunctionDef *method_fd, *ctor_fd;\n    int saved_js_mode, class_name_var_idx, prop_type, ctor_cpool_offset;\n    int class_flags = 0, i, define_class_offset;\n    BOOL is_static, is_private;\n    const uint8_t *class_start_ptr = s->token.ptr;\n    const uint8_t *start_ptr;\n    ClassFieldsDef class_fields[2];\n        \n    /* classes are parsed and executed in strict mode */\n    saved_js_mode = fd->js_mode;\n    fd->js_mode |= JS_MODE_STRICT;\n    if (next_token(s))\n        goto fail;\n    if (s->token.val == TOK_IDENT) {\n        if (s->token.u.ident.is_reserved) {\n            js_parse_error_reserved_identifier(s);\n            goto fail;\n        }\n        class_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n        if (next_token(s))\n            goto fail;\n    } else if (!is_class_expr && export_flag != JS_PARSE_EXPORT_DEFAULT) {\n        js_parse_error(s, \"class statement requires a name\");\n        goto fail;\n    }\n    if (!is_class_expr) {\n        if (class_name == JS_ATOM_NULL)\n            class_var_name = JS_ATOM__default_; /* export default */\n        else\n            class_var_name = class_name;\n        class_var_name = JS_DupAtom(ctx, class_var_name);\n    }\n\n    push_scope(s);\n\n    if (s->token.val == TOK_EXTENDS) {\n        class_flags = JS_DEFINE_CLASS_HAS_HERITAGE;\n        if (next_token(s))\n            goto fail;\n        /* XXX: the grammar only allows LeftHandSideExpression */\n        if (js_parse_postfix_expr(s, TRUE))\n            goto fail;\n    } else {\n        emit_op(s, OP_undefined);\n    }\n\n    /* add a 'const' definition for the class name */\n    if (class_name != JS_ATOM_NULL) {\n        class_name_var_idx = define_var(s, fd, class_name, JS_VAR_DEF_CONST);\n        if (class_name_var_idx < 0)\n            goto fail;\n    }\n\n    if (js_parse_expect(s, '{'))\n        goto fail;\n\n    /* this scope contains the private fields */\n    push_scope(s);\n\n    emit_op(s, OP_push_const);\n    ctor_cpool_offset = fd->byte_code.size;\n    emit_u32(s, 0); /* will be patched at the end of the class parsing */\n\n    if (class_name == JS_ATOM_NULL) {\n        if (class_var_name != JS_ATOM_NULL)\n            class_name1 = JS_ATOM_default;\n        else\n            class_name1 = JS_ATOM_empty_string;\n    } else {\n        class_name1 = class_name;\n    }\n    \n    emit_op(s, OP_define_class);\n    emit_atom(s, class_name1);\n    emit_u8(s, class_flags);\n    define_class_offset = fd->last_opcode_pos;\n\n    for(i = 0; i < 2; i++) {\n        ClassFieldsDef *cf = &class_fields[i];\n        cf->fields_init_fd = NULL;\n        cf->computed_fields_count = 0;\n        cf->has_brand = FALSE;\n    }\n    \n    ctor_fd = NULL;\n    while (s->token.val != '}') {\n        if (s->token.val == ';') {\n            if (next_token(s))\n                goto fail;\n            continue;\n        }\n        is_static = (s->token.val == TOK_STATIC);\n        prop_type = -1;\n        if (is_static) {\n            if (next_token(s))\n                goto fail;\n            /* allow \"static\" field name */\n            if (s->token.val == ';' || s->token.val == '=') {\n                is_static = FALSE;\n                name = JS_DupAtom(ctx, JS_ATOM_static);\n                prop_type = PROP_TYPE_IDENT;\n            }\n        }\n        if (is_static)\n            emit_op(s, OP_swap);\n        start_ptr = s->token.ptr;\n        if (prop_type < 0) {\n            prop_type = js_parse_property_name(s, &name, TRUE, FALSE, TRUE);\n            if (prop_type < 0)\n                goto fail;\n        }\n        is_private = prop_type & PROP_TYPE_PRIVATE;\n        prop_type &= ~PROP_TYPE_PRIVATE;\n        \n        if ((name == JS_ATOM_constructor && !is_static &&\n             prop_type != PROP_TYPE_IDENT) ||\n            (name == JS_ATOM_prototype && is_static) ||\n            name == JS_ATOM_hash_constructor) {\n            js_parse_error(s, \"invalid method name\");\n            goto fail;\n        }\n        if (prop_type == PROP_TYPE_GET || prop_type == PROP_TYPE_SET) {\n            BOOL is_set = prop_type - PROP_TYPE_GET;\n            JSFunctionDef *method_fd;\n\n            if (is_private) {\n                int idx, var_kind;\n                idx = find_private_class_field(ctx, fd, name, fd->scope_level);\n                if (idx >= 0) {\n                    var_kind = fd->vars[idx].var_kind;\n                    if (var_kind == JS_VAR_PRIVATE_FIELD ||\n                        var_kind == JS_VAR_PRIVATE_METHOD ||\n                        var_kind == JS_VAR_PRIVATE_GETTER_SETTER ||\n                        var_kind == (JS_VAR_PRIVATE_GETTER + is_set)) {\n                        goto private_field_already_defined;\n                    }\n                    fd->vars[idx].var_kind = JS_VAR_PRIVATE_GETTER_SETTER;\n                } else {\n                    if (add_private_class_field(s, fd, name,\n                                                JS_VAR_PRIVATE_GETTER + is_set) < 0)\n                        goto fail;\n                }\n                if (add_brand(s, &class_fields[is_static]) < 0)\n                    goto fail;\n            }\n\n            if (js_parse_function_decl2(s, JS_PARSE_FUNC_GETTER + is_set,\n                                        JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                        start_ptr, s->token.line_num,\n                                        JS_PARSE_EXPORT_NONE, &method_fd))\n                goto fail;\n            if (is_private) {\n                method_fd->need_home_object = TRUE; /* needed for brand check */\n                emit_op(s, OP_set_home_object);\n                /* XXX: missing function name */\n                emit_op(s, OP_scope_put_var_init);\n                if (is_set) {\n                    JSAtom setter_name;\n                    int ret;\n                    \n                    setter_name = get_private_setter_name(ctx, name);\n                    if (setter_name == JS_ATOM_NULL)\n                        goto fail;\n                    emit_atom(s, setter_name);\n                    ret = add_private_class_field(s, fd, setter_name,\n                                                  JS_VAR_PRIVATE_SETTER);\n                    JS_FreeAtom(ctx, setter_name);\n                    if (ret < 0)\n                        goto fail;\n                } else {\n                    emit_atom(s, name);\n                }\n                emit_u16(s, s->cur_func->scope_level);\n            } else {\n                if (name == JS_ATOM_NULL) {\n                    emit_op(s, OP_define_method_computed);\n                } else {\n                    emit_op(s, OP_define_method);\n                    emit_atom(s, name);\n                }\n                emit_u8(s, OP_DEFINE_METHOD_GETTER + is_set);\n            }\n        } else if (prop_type == PROP_TYPE_IDENT && s->token.val != '(') {\n            ClassFieldsDef *cf = &class_fields[is_static];\n            JSAtom field_var_name = JS_ATOM_NULL;\n            \n            /* class field */\n\n            /* XXX: spec: not consistent with method name checks */\n            if (name == JS_ATOM_constructor || name == JS_ATOM_prototype) {\n                js_parse_error(s, \"invalid field name\");\n                goto fail;\n            }\n            \n            if (is_private) {\n                if (find_private_class_field(ctx, fd, name,\n                                             fd->scope_level) >= 0) {\n                    goto private_field_already_defined;\n                }\n                if (add_private_class_field(s, fd, name,\n                                            JS_VAR_PRIVATE_FIELD) < 0)\n                    goto fail;\n                emit_op(s, OP_private_symbol);\n                emit_atom(s, name);\n                emit_op(s, OP_scope_put_var_init);\n                emit_atom(s, name);\n                emit_u16(s, s->cur_func->scope_level);\n            }\n\n            if (!cf->fields_init_fd) {\n                if (emit_class_init_start(s, cf))\n                    goto fail;\n            }\n            if (name == JS_ATOM_NULL ) {\n                /* save the computed field name into a variable */\n                field_var_name = js_atom_concat_num(ctx, JS_ATOM_computed_field + is_static, cf->computed_fields_count);\n                if (field_var_name == JS_ATOM_NULL)\n                    goto fail;\n                if (define_var(s, fd, field_var_name, JS_VAR_DEF_CONST) < 0) {\n                    JS_FreeAtom(ctx, field_var_name);\n                    goto fail;\n                }\n                emit_op(s, OP_to_propkey);\n                emit_op(s, OP_scope_put_var_init);\n                emit_atom(s, field_var_name);\n                emit_u16(s, s->cur_func->scope_level);\n            }\n            s->cur_func = cf->fields_init_fd;\n            emit_op(s, OP_scope_get_var);\n            emit_atom(s, JS_ATOM_this);\n            emit_u16(s, 0);\n\n            if (name == JS_ATOM_NULL) {\n                emit_op(s, OP_scope_get_var);\n                emit_atom(s, field_var_name);\n                emit_u16(s, s->cur_func->scope_level);\n                cf->computed_fields_count++;\n                JS_FreeAtom(ctx, field_var_name);\n            } else if (is_private) {\n                emit_op(s, OP_scope_get_var);\n                emit_atom(s, name);\n                emit_u16(s, s->cur_func->scope_level);\n            }\n            \n            if (s->token.val == '=') {\n                if (next_token(s))\n                    goto fail;\n                if (js_parse_assign_expr(s, TRUE))\n                    goto fail;\n            } else {\n                emit_op(s, OP_undefined);\n            }\n            if (is_private) {\n                set_object_name_computed(s);\n                emit_op(s, OP_define_private_field);\n            } else if (name == JS_ATOM_NULL) {\n                set_object_name_computed(s);\n                emit_op(s, OP_define_array_el);\n                emit_op(s, OP_drop);\n            } else {\n                set_object_name(s, name);\n                emit_op(s, OP_define_field);\n                emit_atom(s, name);\n            }\n            s->cur_func = s->cur_func->parent;\n            if (js_parse_expect_semi(s))\n                goto fail;\n        } else {\n            JSParseFunctionEnum func_type;\n            JSFunctionKindEnum func_kind;\n            \n            func_type = JS_PARSE_FUNC_METHOD;\n            func_kind = JS_FUNC_NORMAL;\n            if (prop_type == PROP_TYPE_STAR) {\n                func_kind = JS_FUNC_GENERATOR;\n            } else if (prop_type == PROP_TYPE_ASYNC) {\n                func_kind = JS_FUNC_ASYNC;\n            } else if (prop_type == PROP_TYPE_ASYNC_STAR) {\n                func_kind = JS_FUNC_ASYNC_GENERATOR;\n            } else if (name == JS_ATOM_constructor && !is_static) {\n                if (ctor_fd) {\n                    js_parse_error(s, \"property constructor appears more than once\");\n                    goto fail;\n                }\n                if (class_flags & JS_DEFINE_CLASS_HAS_HERITAGE)\n                    func_type = JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR;\n                else\n                    func_type = JS_PARSE_FUNC_CLASS_CONSTRUCTOR;\n            }\n            if (is_private) {\n                if (add_brand(s, &class_fields[is_static]) < 0)\n                    goto fail;\n            }\n            if (js_parse_function_decl2(s, func_type, func_kind, JS_ATOM_NULL, start_ptr, s->token.line_num, JS_PARSE_EXPORT_NONE, &method_fd))\n                goto fail;\n            if (func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR ||\n                func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR) {\n                ctor_fd = method_fd;\n            } else if (is_private) {\n                method_fd->need_home_object = TRUE; /* needed for brand check */\n                if (find_private_class_field(ctx, fd, name,\n                                             fd->scope_level) >= 0) {\n                private_field_already_defined:\n                    js_parse_error(s, \"private class field is already defined\");\n                    goto fail;\n                }\n                if (add_private_class_field(s, fd, name,\n                                            JS_VAR_PRIVATE_METHOD) < 0)\n                    goto fail;\n                emit_op(s, OP_set_home_object);\n                emit_op(s, OP_set_name);\n                emit_atom(s, name);\n                emit_op(s, OP_scope_put_var_init);\n                emit_atom(s, name);\n                emit_u16(s, s->cur_func->scope_level);\n            } else {\n                if (name == JS_ATOM_NULL) {\n                    emit_op(s, OP_define_method_computed);\n                } else {\n                    emit_op(s, OP_define_method);\n                    emit_atom(s, name);\n                }\n                emit_u8(s, OP_DEFINE_METHOD_METHOD);\n            }\n        }\n        if (is_static)\n            emit_op(s, OP_swap);\n        JS_FreeAtom(ctx, name);\n        name = JS_ATOM_NULL;\n    }\n\n    if (s->token.val != '}') {\n        js_parse_error(s, \"expecting '%c'\", '}');\n        goto fail;\n    }\n\n    if (!ctor_fd) {\n        if (js_parse_class_default_ctor(s, class_flags & JS_DEFINE_CLASS_HAS_HERITAGE, &ctor_fd))\n            goto fail;\n    }\n    /* patch the constant pool index for the constructor */\n    put_u32(fd->byte_code.buf + ctor_cpool_offset, ctor_fd->parent_cpool_idx);\n\n    /* store the class source code in the constructor. */\n    if (!(fd->js_mode & JS_MODE_STRIP)) {\n        js_free(ctx, ctor_fd->source);\n        ctor_fd->source_len = s->buf_ptr - class_start_ptr;\n        ctor_fd->source = js_strndup(ctx, (const char *)class_start_ptr,\n                                     ctor_fd->source_len);\n        if (!ctor_fd->source)\n            goto fail;\n    }\n\n    /* consume the '}' */\n    if (next_token(s))\n        goto fail;\n\n    /* store the function to initialize the fields to that it can be\n       referenced by the constructor */\n    {\n        ClassFieldsDef *cf = &class_fields[0];\n        int var_idx;\n        \n        var_idx = define_var(s, fd, JS_ATOM_class_fields_init,\n                             JS_VAR_DEF_CONST);\n        if (var_idx < 0)\n            goto fail;\n        if (cf->fields_init_fd) {\n            emit_class_init_end(s, cf);\n        } else {\n            emit_op(s, OP_undefined);\n        }\n        emit_op(s, OP_scope_put_var_init);\n        emit_atom(s, JS_ATOM_class_fields_init);\n        emit_u16(s, s->cur_func->scope_level);\n    }\n\n    /* drop the prototype */\n    emit_op(s, OP_drop);\n\n    /* initialize the static fields */\n    if (class_fields[1].fields_init_fd != NULL) {\n        ClassFieldsDef *cf = &class_fields[1];\n        emit_op(s, OP_dup);\n        emit_class_init_end(s, cf);\n        emit_op(s, OP_call_method);\n        emit_u16(s, 0);\n        emit_op(s, OP_drop);\n    }\n    \n    if (class_name != JS_ATOM_NULL) {\n        /* store the class name in the scoped class name variable (it\n           is independent from the class statement variable\n           definition) */\n        emit_op(s, OP_dup);\n        emit_op(s, OP_scope_put_var_init);\n        emit_atom(s, class_name);\n        emit_u16(s, fd->scope_level);\n    }\n    pop_scope(s);\n    pop_scope(s);\n\n    /* the class statements have a block level scope */\n    if (class_var_name != JS_ATOM_NULL) {\n        if (define_var(s, fd, class_var_name, JS_VAR_DEF_LET) < 0)\n            goto fail;\n        emit_op(s, OP_scope_put_var_init);\n        emit_atom(s, class_var_name);\n        emit_u16(s, fd->scope_level);\n    } else {\n        if (class_name == JS_ATOM_NULL) {\n            /* cannot use OP_set_name because the name of the class\n               must be defined before the static initializers are\n               executed */\n            emit_op(s, OP_set_class_name);\n            emit_u32(s, fd->last_opcode_pos + 1 - define_class_offset);\n        }\n    }\n\n    if (export_flag != JS_PARSE_EXPORT_NONE) {\n        if (!add_export_entry(s, fd->module,\n                              class_var_name,\n                              export_flag == JS_PARSE_EXPORT_NAMED ? class_var_name : JS_ATOM_default,\n                              JS_EXPORT_TYPE_LOCAL))\n            goto fail;\n    }\n\n    JS_FreeAtom(ctx, class_name);\n    JS_FreeAtom(ctx, class_var_name);\n    fd->js_mode = saved_js_mode;\n    return 0;\n fail:\n    JS_FreeAtom(ctx, name);\n    JS_FreeAtom(ctx, class_name);\n    JS_FreeAtom(ctx, class_var_name);\n    fd->js_mode = saved_js_mode;\n    return -1;\n}\n\nstatic __exception int js_parse_array_literal(JSParseState *s)\n{\n    uint32_t idx;\n    BOOL need_length;\n\n    if (next_token(s))\n        return -1;\n    /* small regular arrays are created on the stack */\n    idx = 0;\n    while (s->token.val != ']' && idx < 32) {\n        if (s->token.val == ',' || s->token.val == TOK_ELLIPSIS)\n            break;\n        if (js_parse_assign_expr(s, TRUE))\n            return -1;\n        idx++;\n        /* accept trailing comma */\n        if (s->token.val == ',') {\n            if (next_token(s))\n                return -1;\n        } else\n        if (s->token.val != ']')\n            goto done;\n    }\n    emit_op(s, OP_array_from);\n    emit_u16(s, idx);\n\n    /* larger arrays and holes are handled with explicit indices */\n    need_length = FALSE;\n    while (s->token.val != ']' && idx < 0x7fffffff) {\n        if (s->token.val == TOK_ELLIPSIS)\n            break;\n        need_length = TRUE;\n        if (s->token.val != ',') {\n            if (js_parse_assign_expr(s, TRUE))\n                return -1;\n            emit_op(s, OP_define_field);\n            emit_u32(s, __JS_AtomFromUInt32(idx));\n            need_length = FALSE;\n        }\n        idx++;\n        /* accept trailing comma */\n        if (s->token.val == ',') {\n            if (next_token(s))\n                return -1;\n        }\n    }\n    if (s->token.val == ']') {\n        if (need_length) {\n            /* Set the length: Cannot use OP_define_field because\n               length is not configurable */\n            emit_op(s, OP_dup);\n            emit_op(s, OP_push_i32);\n            emit_u32(s, idx);\n            emit_op(s, OP_put_field);\n            emit_atom(s, JS_ATOM_length);\n        }\n        goto done;\n    }\n\n    /* huge arrays and spread elements require a dynamic index on the stack */\n    emit_op(s, OP_push_i32);\n    emit_u32(s, idx);\n\n    /* stack has array, index */\n    while (s->token.val != ']') {\n        if (s->token.val == TOK_ELLIPSIS) {\n            if (next_token(s))\n                return -1;\n            if (js_parse_assign_expr(s, TRUE))\n                return -1;\n#if 1\n            emit_op(s, OP_append);\n#else\n            int label_next, label_done;\n            label_next = new_label(s);\n            label_done = new_label(s);\n            /* enumerate object */\n            emit_op(s, OP_for_of_start);\n            emit_op(s, OP_rot5l);\n            emit_op(s, OP_rot5l);\n            emit_label(s, label_next);\n            /* on stack: enum_rec array idx */\n            emit_op(s, OP_for_of_next);\n            emit_u8(s, 2);\n            emit_goto(s, OP_if_true, label_done);\n            /* append element */\n            /* enum_rec array idx val -> enum_rec array new_idx */\n            emit_op(s, OP_define_array_el);\n            emit_op(s, OP_inc);\n            emit_goto(s, OP_goto, label_next);\n            emit_label(s, label_done);\n            /* close enumeration */\n            emit_op(s, OP_drop); /* drop undef val */\n            emit_op(s, OP_nip1); /* drop enum_rec */\n            emit_op(s, OP_nip1);\n            emit_op(s, OP_nip1);\n#endif\n        } else {\n            need_length = TRUE;\n            if (s->token.val != ',') {\n                if (js_parse_assign_expr(s, TRUE))\n                    return -1;\n                /* a idx val */\n                emit_op(s, OP_define_array_el);\n                need_length = FALSE;\n            }\n            emit_op(s, OP_inc);\n        }\n        if (s->token.val != ',')\n            break;\n        if (next_token(s))\n            return -1;\n    }\n    if (need_length) {\n        /* Set the length: cannot use OP_define_field because\n           length is not configurable */\n        emit_op(s, OP_dup1);    /* array length - array array length */\n        emit_op(s, OP_put_field);\n        emit_atom(s, JS_ATOM_length);\n    } else {\n        emit_op(s, OP_drop);    /* array length - array */\n    }\ndone:\n    return js_parse_expect(s, ']');\n}\n\n/* XXX: remove */\nstatic BOOL has_with_scope(JSFunctionDef *s, int scope_level)\n{\n    /* check if scope chain contains a with statement */\n    while (s) {\n        int scope_idx = s->scopes[scope_level].first;\n        while (scope_idx >= 0) {\n            JSVarDef *vd = &s->vars[scope_idx];\n\n            if (vd->var_name == JS_ATOM__with_)\n                return TRUE;\n            scope_idx = vd->scope_next;\n        }\n        /* check parent scopes */\n        scope_level = s->parent_scope_level;\n        s = s->parent;\n    }\n    return FALSE;\n}\n\ntypedef struct JSLValue {\n    int opcode;\n    int scope;\n    int label;\n    int depth;\n    int tok;\n    JSAtom name;\n} JSLValue;\n\nstatic __exception int get_lvalue(JSParseState *s, int *popcode, int *pscope,\n                                  JSAtom *pname, int *plabel, int *pdepth, BOOL keep,\n                                  int tok)\n{\n    JSFunctionDef *fd;\n    int opcode, scope, label, depth;\n    JSAtom name;\n\n    /* we check the last opcode to get the lvalue type */\n    fd = s->cur_func;\n    scope = 0;\n    name = JS_ATOM_NULL;\n    label = -1;\n    depth = 0;\n    switch(opcode = get_prev_opcode(fd)) {\n    case OP_scope_get_var:\n        name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n        scope = get_u16(fd->byte_code.buf + fd->last_opcode_pos + 5);\n        if ((name == JS_ATOM_arguments || name == JS_ATOM_eval) &&\n            (fd->js_mode & JS_MODE_STRICT)) {\n            return js_parse_error(s, \"invalid lvalue in strict mode\");\n        }\n        if (name == JS_ATOM_this || name == JS_ATOM_new_target)\n            goto invalid_lvalue;\n        depth = 2;  /* will generate OP_get_ref_value */\n        break;\n    case OP_get_field:\n        name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n        depth = 1;\n        break;\n    case OP_scope_get_private_field:\n        name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n        scope = get_u16(fd->byte_code.buf + fd->last_opcode_pos + 5);\n        depth = 1;\n        break;\n    case OP_get_array_el:\n        depth = 2;\n        break;\n    case OP_get_super_value:\n        depth = 3;\n        break;\n    default:\n    invalid_lvalue:\n        if (tok == TOK_FOR) {\n            return js_parse_error(s, \"invalid for in/of left hand-side\");\n        } else if (tok == TOK_INC || tok == TOK_DEC) {\n            return js_parse_error(s, \"invalid increment/decrement operand\");\n        } else if (tok == '[' || tok == '{') {\n            return js_parse_error(s, \"invalid destructuring target\");\n        } else {\n            return js_parse_error(s, \"invalid assignment left-hand side\");\n        }\n    }\n    /* remove the last opcode */\n    fd->byte_code.size = fd->last_opcode_pos;\n    fd->last_opcode_pos = -1;\n\n    if (keep) {\n        /* get the value but keep the object/fields on the stack */\n        switch(opcode) {\n        case OP_scope_get_var:\n            label = new_label(s);\n            emit_op(s, OP_scope_make_ref);\n            emit_atom(s, name);\n            emit_u32(s, label);\n            emit_u16(s, scope);\n            update_label(fd, label, 1);\n            emit_op(s, OP_get_ref_value);\n            opcode = OP_get_ref_value;\n            break;\n        case OP_get_field:\n            emit_op(s, OP_get_field2);\n            emit_atom(s, name);\n            break;\n        case OP_scope_get_private_field:\n            emit_op(s, OP_scope_get_private_field2);\n            emit_atom(s, name);\n            emit_u16(s, scope);\n            break;\n        case OP_get_array_el:\n            /* XXX: replace by a single opcode ? */\n            emit_op(s, OP_to_propkey2);\n            emit_op(s, OP_dup2);\n            emit_op(s, OP_get_array_el);\n            break;\n        case OP_get_super_value:\n            emit_op(s, OP_to_propkey);\n            emit_op(s, OP_dup3);\n            emit_op(s, OP_get_super_value);\n            break;\n        default:\n            abort();\n        }\n    } else {\n        switch(opcode) {\n        case OP_scope_get_var:\n            label = new_label(s);\n            emit_op(s, OP_scope_make_ref);\n            emit_atom(s, name);\n            emit_u32(s, label);\n            emit_u16(s, scope);\n            update_label(fd, label, 1);\n            opcode = OP_get_ref_value;\n            break;\n        case OP_get_array_el:\n            emit_op(s, OP_to_propkey2);\n            break;\n        case OP_get_super_value:\n            emit_op(s, OP_to_propkey);\n            break;\n        }\n    }\n\n    *popcode = opcode;\n    *pscope = scope;\n    /* name has refcount for OP_get_field and OP_get_ref_value,\n       and JS_ATOM_NULL for other opcodes */\n    *pname = name;\n    *plabel = label;\n    if (pdepth)\n        *pdepth = depth;\n    return 0;\n}\n\n/* if special = TRUE: specific post inc/dec case */\n/* name has a live reference */\nstatic void put_lvalue(JSParseState *s, int opcode, int scope,\n                       JSAtom name, int label, BOOL special)\n{\n    switch(opcode) {\n    case OP_get_field:\n        if (!special)\n            emit_op(s, OP_insert2); /* obj v -> v obj v */\n        else\n            emit_op(s, OP_perm3); /* obj v0 v -> v0 obj v */\n        emit_op(s, OP_put_field);\n        emit_u32(s, name);  /* name has refcount */\n        break;\n    case OP_scope_get_private_field:\n        if (!special)\n            emit_op(s, OP_insert2); /* obj v -> v obj v */\n        else\n            emit_op(s, OP_perm3); /* obj v0 v -> v0 obj v */\n        emit_op(s, OP_scope_put_private_field);\n        emit_u32(s, name);  /* name has refcount */\n        emit_u16(s, scope);\n        break;\n    case OP_get_array_el:\n        if (!special)\n            emit_op(s, OP_insert3); /* obj prop v -> v obj prop v */\n        else\n            emit_op(s, OP_perm4); /* obj prop v0 v -> v0 obj prop v */\n        emit_op(s, OP_put_array_el);\n        break;\n    case OP_get_ref_value:\n        JS_FreeAtom(s->ctx, name);\n        emit_label(s, label);\n        if (!special)\n            emit_op(s, OP_insert3); /* obj prop v -> v obj prop v */\n        else\n            emit_op(s, OP_perm4); /* obj prop v0 v -> v0 obj prop v */\n        emit_op(s, OP_put_ref_value);\n        break;\n    case OP_get_super_value:\n        if (!special)\n            emit_op(s, OP_insert4); /* this obj prop v -> v this obj prop v */\n        else\n            emit_op(s, OP_perm5); /* this obj prop v0 v -> v0 this obj prop v */\n        emit_op(s, OP_put_super_value);\n        break;\n    default:\n        abort();\n    }\n}\n\nstatic void put_lvalue_nokeep(JSParseState *s, int opcode, int scope,\n                              JSAtom name, int label, int var_tok)\n{\n    switch(opcode) {\n    case OP_scope_get_var:  /* val -- */\n        emit_op(s, (var_tok == TOK_CONST || var_tok == TOK_LET) ?\n                OP_scope_put_var_init : OP_scope_put_var);\n        emit_u32(s, name);  /* has refcount */\n        emit_u16(s, scope);\n        break;\n    case OP_get_field:      /* obj val -- */\n        emit_op(s, OP_put_field);\n        emit_u32(s, name);  /* has refcount */\n        break;\n    case OP_scope_get_private_field:\n        emit_op(s, OP_scope_put_private_field);\n        emit_u32(s, name);  /* has refcount */\n        emit_u16(s, scope);\n        break;\n    case OP_get_array_el:   /* obj prop val -- */\n        emit_op(s, OP_put_array_el);\n        break;\n    case OP_get_ref_value:   /* obj prop val -- */\n        /* XXX: currently this reference is never optimized */\n        JS_FreeAtom(s->ctx, name);\n        emit_label(s, label);\n        //emit_op(s, OP_nop);   /* emit 2 bytes for optimizer */\n        emit_op(s, OP_put_ref_value);\n        break;\n    case OP_get_super_value:\n        emit_op(s, OP_put_super_value);\n        break;\n    default:\n        abort();\n    }\n}\n\nstatic __exception int js_parse_expr_paren(JSParseState *s)\n{\n    if (js_parse_expect(s, '('))\n        return -1;\n    if (js_parse_expr(s))\n        return -1;\n    if (js_parse_expect(s, ')'))\n        return -1;\n    return 0;\n}\n\nstatic int js_unsupported_keyword(JSParseState *s, JSAtom atom)\n{\n    char buf[ATOM_GET_STR_BUF_SIZE];\n    return js_parse_error(s, \"unsupported keyword: %s\",\n                          JS_AtomGetStr(s->ctx, buf, sizeof(buf), atom));\n}\n\nstatic __exception int js_define_var(JSParseState *s, JSAtom name, int tok)\n{\n    JSFunctionDef *fd = s->cur_func;\n    JSVarDefEnum var_def_type;\n    \n    if (name == JS_ATOM_yield && fd->func_kind == JS_FUNC_GENERATOR) {\n        return js_parse_error(s, \"yield is a reserved identifier\");\n    }\n    if ((name == JS_ATOM_arguments || name == JS_ATOM_eval)\n    &&  (fd->js_mode & JS_MODE_STRICT)) {\n        return js_parse_error(s, \"invalid variable name in strict mode\");\n    }\n    if ((name == JS_ATOM_let || name == JS_ATOM_undefined)\n    &&  (tok == TOK_LET || tok == TOK_CONST)) {\n        return js_parse_error(s, \"invalid lexical variable name\");\n    }\n    switch(tok) {\n    case TOK_LET:\n        var_def_type = JS_VAR_DEF_LET;\n        break;\n    case TOK_CONST:\n        var_def_type = JS_VAR_DEF_CONST;\n        break;\n    case TOK_VAR:\n        var_def_type = JS_VAR_DEF_VAR;\n        break;\n    case TOK_CATCH:\n        var_def_type = JS_VAR_DEF_CATCH;\n        break;\n    default:\n        abort();\n    }\n    if (define_var(s, fd, name, var_def_type) < 0)\n        return -1;\n    return 0;\n}\n\nstatic void js_emit_spread_code(JSParseState *s, int depth)\n{\n    int label_rest_next, label_rest_done;\n\n    /* XXX: could check if enum object is an actual array and optimize\n       slice extraction. enumeration record and target array are in a\n       different order from OP_append case. */\n    /* enum_rec xxx -- enum_rec xxx array 0 */\n    emit_op(s, OP_array_from);\n    emit_u16(s, 0);\n    emit_op(s, OP_push_i32);\n    emit_u32(s, 0);\n    emit_label(s, label_rest_next = new_label(s));\n    emit_op(s, OP_for_of_next);\n    emit_u8(s, 2 + depth);\n    label_rest_done = emit_goto(s, OP_if_true, -1);\n    /* array idx val -- array idx */\n    emit_op(s, OP_define_array_el);\n    emit_op(s, OP_inc);\n    emit_goto(s, OP_goto, label_rest_next);\n    emit_label(s, label_rest_done);\n    /* enum_rec xxx array idx undef -- enum_rec xxx array */\n    emit_op(s, OP_drop);\n    emit_op(s, OP_drop);\n}\n\nstatic int js_parse_check_duplicate_parameter(JSParseState *s, JSAtom name)\n{\n    /* Check for duplicate parameter names */\n    JSFunctionDef *fd = s->cur_func;\n    int i;\n    for (i = 0; i < fd->arg_count; i++) {\n        if (fd->args[i].var_name == name)\n            goto duplicate;\n    }\n    for (i = 0; i < fd->var_count; i++) {\n        if (fd->vars[i].var_name == name)\n            goto duplicate;\n    }\n    return 0;\n\nduplicate:\n    return js_parse_error(s, \"duplicate parameter names not allowed in this context\");\n}\n\nstatic JSAtom js_parse_destructuring_var(JSParseState *s, int tok, int is_arg)\n{\n    JSAtom name;\n\n    if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)\n    ||  ((s->cur_func->js_mode & JS_MODE_STRICT) &&\n         (s->token.u.ident.atom == JS_ATOM_eval || s->token.u.ident.atom == JS_ATOM_arguments))) {\n        js_parse_error(s, \"invalid destructuring target\");\n        return JS_ATOM_NULL;\n    }\n    name = JS_DupAtom(s->ctx, s->token.u.ident.atom);\n    if (is_arg && js_parse_check_duplicate_parameter(s, name))\n        goto fail;\n    if (next_token(s))\n        goto fail;\n\n    return name;\nfail:\n    JS_FreeAtom(s->ctx, name);\n    return JS_ATOM_NULL;\n}\n\nstatic int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,\n                                        int hasval, int has_ellipsis,\n                                        BOOL allow_initializer)\n{\n    int label_parse, label_assign, label_done, label_lvalue, depth_lvalue;\n    int start_addr, assign_addr;\n    JSAtom prop_name, var_name;\n    int opcode, scope, tok1, skip_bits;\n\n    if (has_ellipsis < 0) {\n        /* pre-parse destructuration target for spread detection */\n        js_parse_skip_parens_token(s, &skip_bits, FALSE);\n        has_ellipsis = skip_bits & SKIP_HAS_ELLIPSIS;\n    }\n\n    label_parse = new_label(s);\n    label_assign = new_label(s);\n\n    start_addr = s->cur_func->byte_code.size;\n    if (hasval) {\n        /* consume value from the stack */\n        emit_op(s, OP_dup);\n        emit_op(s, OP_undefined);\n        emit_op(s, OP_strict_eq);\n        emit_goto(s, OP_if_true, label_parse);\n        emit_label(s, label_assign);\n    } else {\n        emit_goto(s, OP_goto, label_parse);\n        emit_label(s, label_assign);\n        /* leave value on the stack */\n        emit_op(s, OP_dup);\n    }\n    assign_addr = s->cur_func->byte_code.size;\n    if (s->token.val == '{') {\n        if (next_token(s))\n            return -1;\n        /* throw an exception if the value cannot be converted to an object */\n        emit_op(s, OP_to_object);\n        if (has_ellipsis) {\n            /* add excludeList on stack just below src object */\n            emit_op(s, OP_object);\n            emit_op(s, OP_swap);\n        }\n        while (s->token.val != '}') {\n            int prop_type;\n            if (s->token.val == TOK_ELLIPSIS) {\n                if (!has_ellipsis) {\n                    JS_ThrowInternalError(s->ctx, \"unexpected ellipsis token\");\n                    return -1;\n                }\n                if (next_token(s))\n                    return -1;\n                if (tok) {\n                    var_name = js_parse_destructuring_var(s, tok, is_arg);\n                    if (var_name == JS_ATOM_NULL)\n                        return -1;\n                    opcode = OP_scope_get_var;\n                    scope = s->cur_func->scope_level;\n                    label_lvalue = -1;\n                    depth_lvalue = 0;\n                } else {\n                    if (js_parse_postfix_expr(s, TRUE))\n                        return -1;\n\n                    if (get_lvalue(s, &opcode, &scope, &var_name,\n                                   &label_lvalue, &depth_lvalue, FALSE, '{'))\n                        return -1;\n                }\n                if (s->token.val != '}') {\n                    js_parse_error(s, \"assignment rest property must be last\");\n                    goto var_error;\n                }\n                emit_op(s, OP_object);  /* target */\n                emit_op(s, OP_copy_data_properties);\n                emit_u8(s, 0 | ((depth_lvalue + 1) << 2) | ((depth_lvalue + 2) << 5));\n                goto set_val;\n            }\n            prop_type = js_parse_property_name(s, &prop_name, FALSE, TRUE, FALSE);\n            if (prop_type < 0)\n                return -1;\n            var_name = JS_ATOM_NULL;\n            opcode = OP_scope_get_var;\n            scope = s->cur_func->scope_level;\n            label_lvalue = -1;\n            depth_lvalue = 0;\n            if (prop_type == PROP_TYPE_IDENT) {\n                if (next_token(s))\n                    goto prop_error;\n                if ((s->token.val == '[' || s->token.val == '{')\n                    &&  ((tok1 = js_parse_skip_parens_token(s, &skip_bits, FALSE)) == ',' ||\n                         tok1 == '=' || tok1 == '}')) {\n                    if (prop_name == JS_ATOM_NULL) {\n                        /* computed property name on stack */\n                        if (has_ellipsis) {\n                            /* define the property in excludeList */\n                            emit_op(s, OP_to_propkey); /* avoid calling ToString twice */\n                            emit_op(s, OP_perm3); /* TOS: src excludeList prop */\n                            emit_op(s, OP_null); /* TOS: src excludeList prop null */\n                            emit_op(s, OP_define_array_el); /* TOS: src excludeList prop */\n                            emit_op(s, OP_perm3); /* TOS: excludeList src prop */\n                        }\n                        /* get the computed property from the source object */\n                        emit_op(s, OP_get_array_el2);\n                    } else {\n                        /* named property */\n                        if (has_ellipsis) {\n                            /* define the property in excludeList */\n                            emit_op(s, OP_swap); /* TOS: src excludeList */\n                            emit_op(s, OP_null); /* TOS: src excludeList null */\n                            emit_op(s, OP_define_field); /* TOS: src excludeList */\n                            emit_atom(s, prop_name);\n                            emit_op(s, OP_swap); /* TOS: excludeList src */\n                        }\n                        /* get the named property from the source object */\n                        emit_op(s, OP_get_field2);\n                        emit_u32(s, prop_name);\n                    }\n                    if (js_parse_destructuring_element(s, tok, is_arg, TRUE, -1, TRUE))\n                        return -1;\n                    if (s->token.val == '}')\n                        break;\n                    /* accept a trailing comma before the '}' */\n                    if (js_parse_expect(s, ','))\n                        return -1;\n                    continue;\n                }\n                if (prop_name == JS_ATOM_NULL) {\n                    emit_op(s, OP_to_propkey2);\n                    if (has_ellipsis) {\n                        /* define the property in excludeList */\n                        emit_op(s, OP_perm3);\n                        emit_op(s, OP_null);\n                        emit_op(s, OP_define_array_el);\n                        emit_op(s, OP_perm3);\n                    }\n                    /* source prop -- source source prop */\n                    emit_op(s, OP_dup1);\n                } else {\n                    if (has_ellipsis) {\n                        /* define the property in excludeList */\n                        emit_op(s, OP_swap);\n                        emit_op(s, OP_null);\n                        emit_op(s, OP_define_field);\n                        emit_atom(s, prop_name);\n                        emit_op(s, OP_swap);\n                    }\n                    /* source -- source source */\n                    emit_op(s, OP_dup);\n                }\n                if (tok) {\n                    var_name = js_parse_destructuring_var(s, tok, is_arg);\n                    if (var_name == JS_ATOM_NULL)\n                        goto prop_error;\n                } else {\n                    if (js_parse_postfix_expr(s, TRUE))\n                        goto prop_error;\n                lvalue:\n                    if (get_lvalue(s, &opcode, &scope, &var_name,\n                                   &label_lvalue, &depth_lvalue, FALSE, '{'))\n                        goto prop_error;\n                    /* swap ref and lvalue object if any */\n                    if (prop_name == JS_ATOM_NULL) {\n                        switch(depth_lvalue) {\n                        case 1:\n                            /* source prop x -> x source prop */\n                            emit_op(s, OP_rot3r);\n                            break;\n                        case 2:\n                            /* source prop x y -> x y source prop */\n                            emit_op(s, OP_swap2);   /* t p2 s p1 */\n                            break;\n                        case 3:\n                            /* source prop x y z -> x y z source prop */\n                            emit_op(s, OP_rot5l);\n                            emit_op(s, OP_rot5l);\n                            break;\n                        }\n                    } else {\n                        switch(depth_lvalue) {\n                        case 1:\n                            /* source x -> x source */\n                            emit_op(s, OP_swap);\n                            break;\n                        case 2:\n                            /* source x y -> x y source */\n                            emit_op(s, OP_rot3l);\n                            break;\n                        case 3:\n                            /* source x y z -> x y z source */\n                            emit_op(s, OP_rot4l);\n                            break;\n                        }\n                    }\n                }\n                if (prop_name == JS_ATOM_NULL) {\n                    /* computed property name on stack */\n                    /* XXX: should have OP_get_array_el2x with depth */\n                    /* source prop -- val */\n                    emit_op(s, OP_get_array_el);\n                } else {\n                    /* named property */\n                    /* XXX: should have OP_get_field2x with depth */\n                    /* source -- val */\n                    emit_op(s, OP_get_field);\n                    emit_u32(s, prop_name);\n                }\n            } else {\n                /* prop_type = PROP_TYPE_VAR, cannot be a computed property */\n                if (is_arg && js_parse_check_duplicate_parameter(s, prop_name))\n                    goto prop_error;\n                if ((s->cur_func->js_mode & JS_MODE_STRICT) &&\n                    (prop_name == JS_ATOM_eval || prop_name == JS_ATOM_arguments)) {\n                    js_parse_error(s, \"invalid destructuring target\");\n                    goto prop_error;\n                }\n                if (has_ellipsis) {\n                    /* define the property in excludeList */\n                    emit_op(s, OP_swap);\n                    emit_op(s, OP_null);\n                    emit_op(s, OP_define_field);\n                    emit_atom(s, prop_name);\n                    emit_op(s, OP_swap);\n                }\n                if (!tok || tok == TOK_VAR) {\n                    /* generate reference */\n                    /* source -- source source */\n                    emit_op(s, OP_dup);\n                    emit_op(s, OP_scope_get_var);\n                    emit_atom(s, prop_name);\n                    emit_u16(s, s->cur_func->scope_level);\n                    goto lvalue;\n                }\n                var_name = JS_DupAtom(s->ctx, prop_name);\n                /* source -- source val */\n                emit_op(s, OP_get_field2);\n                emit_u32(s, prop_name);\n            }\n        set_val:\n            if (tok) {\n                if (js_define_var(s, var_name, tok))\n                    goto var_error;\n                scope = s->cur_func->scope_level;\n            }\n            if (s->token.val == '=') {  /* handle optional default value */\n                int label_hasval;\n                emit_op(s, OP_dup);\n                emit_op(s, OP_undefined);\n                emit_op(s, OP_strict_eq);\n                label_hasval = emit_goto(s, OP_if_false, -1);\n                if (next_token(s))\n                    goto var_error;\n                emit_op(s, OP_drop);\n                if (js_parse_assign_expr(s, TRUE))\n                    goto var_error;\n                if (opcode == OP_scope_get_var || opcode == OP_get_ref_value)\n                    set_object_name(s, var_name);\n                emit_label(s, label_hasval);\n            }\n            /* store value into lvalue object */\n            put_lvalue_nokeep(s, opcode, scope, var_name, label_lvalue, tok);\n            if (s->token.val == '}')\n                break;\n            /* accept a trailing comma before the '}' */\n            if (js_parse_expect(s, ','))\n                return -1;\n        }\n        /* drop the source object */\n        emit_op(s, OP_drop);\n        if (has_ellipsis) {\n            emit_op(s, OP_drop); /* pop excludeList */\n        }\n        if (next_token(s))\n            return -1;\n    } else if (s->token.val == '[') {\n        BOOL has_spread;\n        int enum_depth;\n        BlockEnv block_env;\n\n        if (next_token(s))\n            return -1;\n        /* the block environment is only needed in generators in case\n           'yield' triggers a 'return' */\n        push_break_entry(s->cur_func, &block_env,\n                         JS_ATOM_NULL, -1, -1, 2);\n        block_env.has_iterator = TRUE;\n        emit_op(s, OP_for_of_start);\n        has_spread = FALSE;\n        while (s->token.val != ']') {\n            /* get the next value */\n            if (s->token.val == TOK_ELLIPSIS) {\n                if (next_token(s))\n                    return -1;\n                if (s->token.val == ',' || s->token.val == ']')\n                    return js_parse_error(s, \"missing binding pattern...\");\n                has_spread = TRUE;\n            }\n            if (s->token.val == ',') {\n                /* do nothing, skip the value, has_spread is false */\n                emit_op(s, OP_for_of_next);\n                emit_u8(s, 0);\n                emit_op(s, OP_drop);\n                emit_op(s, OP_drop);\n            } else if ((s->token.val == '[' || s->token.val == '{')\n                   &&  ((tok1 = js_parse_skip_parens_token(s, &skip_bits, FALSE)) == ',' ||\n                        tok1 == '=' || tok1 == ']')) {\n                if (has_spread) {\n                    if (tok1 == '=')\n                        return js_parse_error(s, \"rest element cannot have a default value\");\n                    js_emit_spread_code(s, 0);\n                } else {\n                    emit_op(s, OP_for_of_next);\n                    emit_u8(s, 0);\n                    emit_op(s, OP_drop);\n                }\n                if (js_parse_destructuring_element(s, tok, is_arg, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE))\n                    return -1;\n            } else {\n                var_name = JS_ATOM_NULL;\n                enum_depth = 0;\n                if (tok) {\n                    var_name = js_parse_destructuring_var(s, tok, is_arg);\n                    if (var_name == JS_ATOM_NULL)\n                        goto var_error;\n                    if (js_define_var(s, var_name, tok))\n                        goto var_error;\n                    opcode = OP_scope_get_var;\n                    scope = s->cur_func->scope_level;\n                } else {\n                    if (js_parse_postfix_expr(s, TRUE))\n                        return -1;\n                    if (get_lvalue(s, &opcode, &scope, &var_name,\n                                   &label_lvalue, &enum_depth, FALSE, '[')) {\n                        return -1;\n                    }\n                }\n                if (has_spread) {\n                    js_emit_spread_code(s, enum_depth);\n                } else {\n                    emit_op(s, OP_for_of_next);\n                    emit_u8(s, enum_depth);\n                    emit_op(s, OP_drop);\n                }\n                if (s->token.val == '=' && !has_spread) {\n                    /* handle optional default value */\n                    int label_hasval;\n                    emit_op(s, OP_dup);\n                    emit_op(s, OP_undefined);\n                    emit_op(s, OP_strict_eq);\n                    label_hasval = emit_goto(s, OP_if_false, -1);\n                    if (next_token(s))\n                        goto var_error;\n                    emit_op(s, OP_drop);\n                    if (js_parse_assign_expr(s, TRUE))\n                        goto var_error;\n                    if (opcode == OP_scope_get_var || opcode == OP_get_ref_value)\n                        set_object_name(s, var_name);\n                    emit_label(s, label_hasval);\n                }\n                /* store value into lvalue object */\n                put_lvalue_nokeep(s, opcode, scope, var_name,\n                                  label_lvalue, tok);\n            }\n            if (s->token.val == ']')\n                break;\n            if (has_spread)\n                return js_parse_error(s, \"rest element must be the last one\");\n            /* accept a trailing comma before the ']' */\n            if (js_parse_expect(s, ','))\n                return -1;\n        }\n        /* close iterator object:\n           if completed, enum_obj has been replaced by undefined */\n        emit_op(s, OP_iterator_close);\n        pop_break_entry(s->cur_func);\n        if (next_token(s))\n            return -1;\n    } else {\n        return js_parse_error(s, \"invalid assignment syntax\");\n    }\n    if (s->token.val == '=' && allow_initializer) {\n        label_done = emit_goto(s, OP_goto, -1);\n        if (next_token(s))\n            return -1;\n        emit_label(s, label_parse);\n        if (hasval)\n            emit_op(s, OP_drop);\n        if (js_parse_assign_expr(s, TRUE))\n            return -1;\n        emit_goto(s, OP_goto, label_assign);\n        emit_label(s, label_done);\n    } else {\n        /* normally hasval is true except if\n           js_parse_skip_parens_token() was wrong in the parsing */\n        //        assert(hasval);\n        if (!hasval) {\n            js_parse_error(s, \"too complicated destructuring expression\");\n            return -1;\n        }\n        /* remove test and decrement label ref count */\n        memset(s->cur_func->byte_code.buf + start_addr, OP_nop,\n               assign_addr - start_addr);\n        s->cur_func->label_slots[label_parse].ref_count--;\n    }\n    return 0;\n\n prop_error:\n    JS_FreeAtom(s->ctx, prop_name);\n var_error:\n    JS_FreeAtom(s->ctx, var_name);\n    return -1;\n}\n\ntypedef enum FuncCallType {\n    FUNC_CALL_NORMAL,\n    FUNC_CALL_NEW,\n    FUNC_CALL_SUPER_CTOR,\n    FUNC_CALL_TEMPLATE,\n} FuncCallType;\n\nstatic void optional_chain_test(JSParseState *s, int *poptional_chaining_label,\n                                int drop_count)\n{\n    int label_next, i;\n    if (*poptional_chaining_label < 0)\n        *poptional_chaining_label = new_label(s);\n   /* XXX: could be more efficient with a specific opcode */\n    emit_op(s, OP_dup);\n    emit_op(s, OP_is_undefined_or_null);\n    label_next = emit_goto(s, OP_if_false, -1);\n    for(i = 0; i < drop_count; i++)\n        emit_op(s, OP_drop);\n    emit_op(s, OP_undefined);\n    emit_goto(s, OP_goto, *poptional_chaining_label);\n    emit_label(s, label_next);\n}\n\nstatic __exception int js_parse_postfix_expr(JSParseState *s, BOOL accept_lparen)\n{\n    FuncCallType call_type;\n    int optional_chaining_label;\n    \n    call_type = FUNC_CALL_NORMAL;\n    switch(s->token.val) {\n    case TOK_NUMBER:\n        {\n            JSValue val;\n            val = s->token.u.num.val;\n\n            if (JS_VALUE_GET_TAG(val) == JS_TAG_INT) {\n                emit_op(s, OP_push_i32);\n                emit_u32(s, JS_VALUE_GET_INT(val));\n            } else\n#ifdef CONFIG_BIGNUM\n            if (JS_VALUE_GET_TAG(val) == JS_TAG_BIG_FLOAT) {\n                slimb_t e;\n                int ret;\n\n                /* need a runtime conversion */\n                /* XXX: could add a cache and/or do it once at\n                   the start of the function */\n                if (emit_push_const(s, val, 0) < 0)\n                    return -1;\n                e = s->token.u.num.exponent;\n                if (e == (int32_t)e) {\n                    emit_op(s, OP_push_i32);\n                    emit_u32(s, e);\n                } else {\n                    val = JS_NewBigInt64_1(s->ctx, e);\n                    if (JS_IsException(val))\n                        return -1;\n                    ret = emit_push_const(s, val, 0);\n                    JS_FreeValue(s->ctx, val);\n                    if (ret < 0)\n                        return -1;\n                }\n                emit_op(s, OP_mul_pow10);\n            } else\n#endif\n            {\n                if (emit_push_const(s, val, 0) < 0)\n                    return -1;\n            }\n        }\n        if (next_token(s))\n            return -1;\n        break;\n    case TOK_TEMPLATE:\n        if (js_parse_template(s, 0, NULL))\n            return -1;\n        break;\n    case TOK_STRING:\n        if (emit_push_const(s, s->token.u.str.str, 1))\n            return -1;\n        if (next_token(s))\n            return -1;\n        break;\n        \n    case TOK_DIV_ASSIGN:\n        s->buf_ptr -= 2;\n        goto parse_regexp;\n    case '/':\n        s->buf_ptr--;\n    parse_regexp:\n        {\n            JSValue str;\n            int ret, backtrace_flags;\n            if (!s->ctx->compile_regexp)\n                return js_parse_error(s, \"RegExp are not supported\");\n            /* the previous token is '/' or '/=', so no need to free */\n            if (js_parse_regexp(s))\n                return -1;\n            ret = emit_push_const(s, s->token.u.regexp.body, 0);\n            str = s->ctx->compile_regexp(s->ctx, s->token.u.regexp.body,\n                                         s->token.u.regexp.flags);\n            if (JS_IsException(str)) {\n                /* add the line number info */\n                backtrace_flags = 0;\n                if (s->cur_func && s->cur_func->backtrace_barrier)\n                    backtrace_flags = JS_BACKTRACE_FLAG_SINGLE_LEVEL;\n                build_backtrace(s->ctx, s->ctx->rt->current_exception,\n                                s->filename, s->token.line_num,\n                                backtrace_flags);\n                return -1;\n            }\n            ret = emit_push_const(s, str, 0);\n            JS_FreeValue(s->ctx, str);\n            if (ret)\n                return -1;\n            /* we use a specific opcode to be sure the correct\n               function is called (otherwise the bytecode would have\n               to be verified by the RegExp constructor) */\n            emit_op(s, OP_regexp);\n            if (next_token(s))\n                return -1;\n        }\n        break;\n    case '(':\n        if (js_parse_skip_parens_token(s, NULL, TRUE) == TOK_ARROW) {\n            if (js_parse_function_decl(s, JS_PARSE_FUNC_ARROW,\n                                       JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                       s->token.ptr, s->token.line_num))\n                return -1;\n        } else {\n            if (js_parse_expr_paren(s))\n                return -1;\n        }\n        break;\n    case TOK_FUNCTION:\n        if (js_parse_function_decl(s, JS_PARSE_FUNC_EXPR,\n                                   JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                   s->token.ptr, s->token.line_num))\n            return -1;\n        break;\n    case TOK_CLASS:\n        if (js_parse_class(s, TRUE, JS_PARSE_EXPORT_NONE))\n            return -1;\n        break;\n    case TOK_NULL:\n        if (next_token(s))\n            return -1;\n        emit_op(s, OP_null);\n        break;\n    case TOK_THIS:\n        if (next_token(s))\n            return -1;\n        emit_op(s, OP_scope_get_var);\n        emit_atom(s, JS_ATOM_this);\n        emit_u16(s, 0);\n        break;\n    case TOK_FALSE:\n        if (next_token(s))\n            return -1;\n        emit_op(s, OP_push_false);\n        break;\n    case TOK_TRUE:\n        if (next_token(s))\n            return -1;\n        emit_op(s, OP_push_true);\n        break;\n    case TOK_IDENT:\n        {\n            JSAtom name;\n            if (s->token.u.ident.is_reserved) {\n                return js_parse_error_reserved_identifier(s);\n            }\n            if (peek_token(s, TRUE) == TOK_ARROW) {\n                if (js_parse_function_decl(s, JS_PARSE_FUNC_ARROW,\n                                           JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                           s->token.ptr, s->token.line_num))\n                    return -1;\n            } else if (token_is_pseudo_keyword(s, JS_ATOM_async) &&\n                       peek_token(s, TRUE) != '\\n') {\n                const uint8_t *source_ptr;\n                int source_line_num;\n\n                source_ptr = s->token.ptr;\n                source_line_num = s->token.line_num;\n                if (next_token(s))\n                    return -1;\n                if (s->token.val == TOK_FUNCTION) {\n                    if (js_parse_function_decl(s, JS_PARSE_FUNC_EXPR,\n                                               JS_FUNC_ASYNC, JS_ATOM_NULL,\n                                               source_ptr, source_line_num))\n                        return -1;\n                } else if ((s->token.val == '(' &&\n                            js_parse_skip_parens_token(s, NULL, TRUE) == TOK_ARROW) ||\n                           (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved &&\n                            peek_token(s, TRUE) == TOK_ARROW)) {\n                    if (js_parse_function_decl(s, JS_PARSE_FUNC_ARROW,\n                                               JS_FUNC_ASYNC, JS_ATOM_NULL,\n                                               source_ptr, source_line_num))\n                        return -1;\n                } else {\n                    name = JS_DupAtom(s->ctx, JS_ATOM_async);\n                    goto do_get_var;\n                }\n            } else {\n                if (s->token.u.ident.atom == JS_ATOM_arguments &&\n                    !s->cur_func->arguments_allowed) {\n                    js_parse_error(s, \"'arguments' identifier is not allowed in class field initializer\");\n                    return -1;\n                }\n                name = JS_DupAtom(s->ctx, s->token.u.ident.atom);\n                if (next_token(s))  /* update line number before emitting code */\n                    return -1;\n            do_get_var:\n                emit_op(s, OP_scope_get_var);\n                emit_u32(s, name);\n                emit_u16(s, s->cur_func->scope_level);\n            }\n        }\n        break;\n    case '{':\n    case '[':\n        {\n            int skip_bits;\n            if (js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') {\n                if (js_parse_destructuring_element(s, 0, 0, FALSE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE))\n                    return -1;\n            } else {\n                if (s->token.val == '{') {\n                    if (js_parse_object_literal(s))\n                        return -1;\n                } else {\n                    if (js_parse_array_literal(s))\n                        return -1;\n                }\n            }\n        }\n        break;\n    case TOK_NEW:\n        if (next_token(s))\n            return -1;\n        if (s->token.val == '.') {\n            if (next_token(s))\n                return -1;\n            if (!token_is_pseudo_keyword(s, JS_ATOM_target))\n                return js_parse_error(s, \"expecting target\");\n            if (!s->cur_func->new_target_allowed)\n                return js_parse_error(s, \"new.target only allowed within functions\");\n            if (next_token(s))\n                return -1;\n            emit_op(s, OP_scope_get_var);\n            emit_atom(s, JS_ATOM_new_target);\n            emit_u16(s, 0);\n        } else {\n            if (js_parse_postfix_expr(s, FALSE))\n                return -1;\n            accept_lparen = TRUE;\n            if (s->token.val != '(') {\n                /* new operator on an object */\n                emit_op(s, OP_dup);\n                emit_op(s, OP_call_constructor);\n                emit_u16(s, 0);\n            } else {\n                call_type = FUNC_CALL_NEW;\n            }\n        }\n        break;\n    case TOK_SUPER:\n        if (next_token(s))\n            return -1;\n        if (s->token.val == '(') {\n            if (!s->cur_func->super_call_allowed)\n                return js_parse_error(s, \"super() is only valid in a derived class constructor\");\n            call_type = FUNC_CALL_SUPER_CTOR;\n        } else if (s->token.val == '.' || s->token.val == '[') {\n            if (!s->cur_func->super_allowed)\n                return js_parse_error(s, \"'super' is only valid in a method\");\n            emit_op(s, OP_scope_get_var);\n            emit_atom(s, JS_ATOM_this);\n            emit_u16(s, 0);\n            emit_op(s, OP_scope_get_var);\n            emit_atom(s, JS_ATOM_home_object);\n            emit_u16(s, 0);\n            emit_op(s, OP_get_super);\n        } else {\n            return js_parse_error(s, \"invalid use of 'super'\");\n        }\n        break;\n    case TOK_IMPORT:\n        if (next_token(s))\n            return -1;\n        if (s->token.val == '.') {\n            if (next_token(s))\n                return -1;\n            if (!token_is_pseudo_keyword(s, JS_ATOM_meta))\n                return js_parse_error(s, \"meta expected\");\n            if (!s->is_module)\n                return js_parse_error(s, \"import.meta only valid in module code\");\n            if (next_token(s))\n                return -1;\n            emit_op(s, OP_special_object);\n            emit_u8(s, OP_SPECIAL_OBJECT_IMPORT_META);\n        } else {\n            if (js_parse_expect(s, '('))\n                return -1;\n            if (!accept_lparen)\n                return js_parse_error(s, \"invalid use of 'import()'\");\n            if (js_parse_assign_expr(s, TRUE))\n                return -1;\n            if (js_parse_expect(s, ')'))\n                return -1;\n            emit_op(s, OP_import);\n        }\n        break;\n    default:\n        return js_parse_error(s, \"unexpected token in expression: '%.*s'\",\n                              (int)(s->buf_ptr - s->token.ptr), s->token.ptr);\n    }\n\n    optional_chaining_label = -1;\n    for(;;) {\n        JSFunctionDef *fd = s->cur_func;\n        BOOL has_optional_chain = FALSE;\n        \n        if (s->token.val == TOK_QUESTION_MARK_DOT) {\n            /* optional chaining */\n            if (next_token(s))\n                return -1;\n            has_optional_chain = TRUE;\n            if (s->token.val == '(' && accept_lparen) {\n                goto parse_func_call;\n            } else if (s->token.val == '[') {\n                goto parse_array_access;\n            } else {\n                goto parse_property;\n            }\n        } else if (s->token.val == TOK_TEMPLATE &&\n                   call_type == FUNC_CALL_NORMAL) {\n            if (optional_chaining_label >= 0) {\n                return js_parse_error(s, \"template literal cannot appear in an optional chain\");\n            }\n            call_type = FUNC_CALL_TEMPLATE;\n            goto parse_func_call2;\n        } else if (s->token.val == '(' && accept_lparen) {\n            int opcode, arg_count, drop_count;\n\n            /* function call */\n        parse_func_call:\n            if (next_token(s))\n                return -1;\n\n            if (call_type == FUNC_CALL_NORMAL) {\n            parse_func_call2:\n                switch(opcode = get_prev_opcode(fd)) {\n                case OP_get_field:\n                    /* keep the object on the stack */\n                    fd->byte_code.buf[fd->last_opcode_pos] = OP_get_field2;\n                    drop_count = 2;\n                    break;\n                case OP_scope_get_private_field:\n                    /* keep the object on the stack */\n                    fd->byte_code.buf[fd->last_opcode_pos] = OP_scope_get_private_field2;\n                    drop_count = 2;\n                    break;\n                case OP_get_array_el:\n                    /* keep the object on the stack */\n                    fd->byte_code.buf[fd->last_opcode_pos] = OP_get_array_el2;\n                    drop_count = 2;\n                    break;\n                case OP_scope_get_var:\n                    {\n                        JSAtom name;\n                        int scope;\n                        name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n                        scope = get_u16(fd->byte_code.buf + fd->last_opcode_pos + 5);\n                        if (name == JS_ATOM_eval && call_type == FUNC_CALL_NORMAL && !has_optional_chain) {\n                            /* direct 'eval' */\n                            opcode = OP_eval;\n                        } else {\n                            /* verify if function name resolves to a simple\n                               get_loc/get_arg: a function call inside a `with`\n                               statement can resolve to a method call of the\n                               `with` context object\n                             */\n                            /* XXX: always generate the OP_scope_get_ref\n                               and remove it in variable resolution\n                               pass ? */\n                            if (has_with_scope(fd, scope)) {\n                                opcode = OP_scope_get_ref;\n                                fd->byte_code.buf[fd->last_opcode_pos] = opcode;\n                            }\n                        }\n                        drop_count = 1;\n                    }\n                    break;\n                case OP_get_super_value:\n                    fd->byte_code.buf[fd->last_opcode_pos] = OP_get_array_el;\n                    /* on stack: this func_obj */\n                    opcode = OP_get_array_el;\n                    drop_count = 2;\n                    break;\n                default:\n                    opcode = OP_invalid;\n                    drop_count = 1;\n                    break;\n                }\n                if (has_optional_chain) {\n                    optional_chain_test(s, &optional_chaining_label,\n                                        drop_count);\n                }\n            } else {\n                opcode = OP_invalid;\n            }\n\n            if (call_type == FUNC_CALL_TEMPLATE) {\n                if (js_parse_template(s, 1, &arg_count))\n                    return -1;\n                goto emit_func_call;\n            } else if (call_type == FUNC_CALL_SUPER_CTOR) {\n                emit_op(s, OP_scope_get_var);\n                emit_atom(s, JS_ATOM_this_active_func);\n                emit_u16(s, 0);\n\n                emit_op(s, OP_get_super);\n\n                emit_op(s, OP_scope_get_var);\n                emit_atom(s, JS_ATOM_new_target);\n                emit_u16(s, 0);\n            } else if (call_type == FUNC_CALL_NEW) {\n                emit_op(s, OP_dup); /* new.target = function */\n            }\n\n            /* parse arguments */\n            arg_count = 0;\n            while (s->token.val != ')') {\n                if (arg_count >= 65535) {\n                    return js_parse_error(s, \"Too many call arguments\");\n                }\n                if (s->token.val == TOK_ELLIPSIS)\n                    break;\n                if (js_parse_assign_expr(s, TRUE))\n                    return -1;\n                arg_count++;\n                if (s->token.val == ')')\n                    break;\n                /* accept a trailing comma before the ')' */\n                if (js_parse_expect(s, ','))\n                    return -1;\n            }\n            if (s->token.val == TOK_ELLIPSIS) {\n                emit_op(s, OP_array_from);\n                emit_u16(s, arg_count);\n                emit_op(s, OP_push_i32);\n                emit_u32(s, arg_count);\n\n                /* on stack: array idx */\n                while (s->token.val != ')') {\n                    if (s->token.val == TOK_ELLIPSIS) {\n                        if (next_token(s))\n                            return -1;\n                        if (js_parse_assign_expr(s, TRUE))\n                            return -1;\n#if 1\n                        /* XXX: could pass is_last indicator? */\n                        emit_op(s, OP_append);\n#else\n                        int label_next, label_done;\n                        label_next = new_label(s);\n                        label_done = new_label(s);\n                        /* push enumerate object below array/idx pair */\n                        emit_op(s, OP_for_of_start);\n                        emit_op(s, OP_rot5l);\n                        emit_op(s, OP_rot5l);\n                        emit_label(s, label_next);\n                        /* on stack: enum_rec array idx */\n                        emit_op(s, OP_for_of_next);\n                        emit_u8(s, 2);\n                        emit_goto(s, OP_if_true, label_done);\n                        /* append element */\n                        /* enum_rec array idx val -> enum_rec array new_idx */\n                        emit_op(s, OP_define_array_el);\n                        emit_op(s, OP_inc);\n                        emit_goto(s, OP_goto, label_next);\n                        emit_label(s, label_done);\n                        /* close enumeration, drop enum_rec and idx */\n                        emit_op(s, OP_drop); /* drop undef */\n                        emit_op(s, OP_nip1); /* drop enum_rec */\n                        emit_op(s, OP_nip1);\n                        emit_op(s, OP_nip1);\n#endif\n                    } else {\n                        if (js_parse_assign_expr(s, TRUE))\n                            return -1;\n                        /* array idx val */\n                        emit_op(s, OP_define_array_el);\n                        emit_op(s, OP_inc);\n                    }\n                    if (s->token.val == ')')\n                        break;\n                    /* accept a trailing comma before the ')' */\n                    if (js_parse_expect(s, ','))\n                        return -1;\n                }\n                if (next_token(s))\n                    return -1;\n                /* drop the index */\n                emit_op(s, OP_drop);\n\n                /* apply function call */\n                switch(opcode) {\n                case OP_get_field:\n                case OP_scope_get_private_field:\n                case OP_get_array_el:\n                case OP_scope_get_ref:\n                    /* obj func array -> func obj array */\n                    emit_op(s, OP_perm3);\n                    emit_op(s, OP_apply);\n                    emit_u16(s, call_type == FUNC_CALL_NEW);\n                    break;\n                case OP_eval:\n                    emit_op(s, OP_apply_eval);\n                    emit_u16(s, fd->scope_level);\n                    fd->has_eval_call = TRUE;\n                    break;\n                default:\n                    if (call_type == FUNC_CALL_SUPER_CTOR) {\n                        emit_op(s, OP_apply);\n                        emit_u16(s, 1);\n                        /* set the 'this' value */\n                        emit_op(s, OP_dup);\n                        emit_op(s, OP_scope_put_var_init);\n                        emit_atom(s, JS_ATOM_this);\n                        emit_u16(s, 0);\n\n                        emit_class_field_init(s);\n                    } else if (call_type == FUNC_CALL_NEW) {\n                        /* obj func array -> func obj array */\n                        emit_op(s, OP_perm3);\n                        emit_op(s, OP_apply);\n                        emit_u16(s, 1);\n                    } else {\n                        /* func array -> func undef array */\n                        emit_op(s, OP_undefined);\n                        emit_op(s, OP_swap);\n                        emit_op(s, OP_apply);\n                        emit_u16(s, 0);\n                    }\n                    break;\n                }\n            } else {\n                if (next_token(s))\n                    return -1;\n            emit_func_call:\n                switch(opcode) {\n                case OP_get_field:\n                case OP_scope_get_private_field:\n                case OP_get_array_el:\n                case OP_scope_get_ref:\n                    emit_op(s, OP_call_method);\n                    emit_u16(s, arg_count);\n                    break;\n                case OP_eval:\n                    emit_op(s, OP_eval);\n                    emit_u16(s, arg_count);\n                    emit_u16(s, fd->scope_level);\n                    fd->has_eval_call = TRUE;\n                    break;\n                default:\n                    if (call_type == FUNC_CALL_SUPER_CTOR) {\n                        emit_op(s, OP_call_constructor);\n                        emit_u16(s, arg_count);\n\n                        /* set the 'this' value */\n                        emit_op(s, OP_dup);\n                        emit_op(s, OP_scope_put_var_init);\n                        emit_atom(s, JS_ATOM_this);\n                        emit_u16(s, 0);\n\n                        emit_class_field_init(s);\n                    } else if (call_type == FUNC_CALL_NEW) {\n                        emit_op(s, OP_call_constructor);\n                        emit_u16(s, arg_count);\n                    } else {\n                        emit_op(s, OP_call);\n                        emit_u16(s, arg_count);\n                    }\n                    break;\n                }\n            }\n            call_type = FUNC_CALL_NORMAL;\n        } else if (s->token.val == '.') {\n            if (next_token(s))\n                return -1;\n            if (s->token.val == TOK_PRIVATE_NAME) {\n                /* private class field */\n                if (get_prev_opcode(fd) == OP_get_super) {\n                    return js_parse_error(s, \"private class field forbidden after super\");\n                }\n                emit_op(s, OP_scope_get_private_field);\n                emit_atom(s, s->token.u.ident.atom);\n                emit_u16(s, s->cur_func->scope_level);\n            } else {\n            parse_property:\n                if (!token_is_ident(s->token.val)) {\n                    return js_parse_error(s, \"expecting field name\");\n                }\n                if (get_prev_opcode(fd) == OP_get_super) {\n                    JSValue val;\n                    int ret;\n                    val = JS_AtomToValue(s->ctx, s->token.u.ident.atom);\n                    ret = emit_push_const(s, val, 1);\n                    JS_FreeValue(s->ctx, val);\n                    if (ret)\n                        return -1;\n                    emit_op(s, OP_get_super_value);\n                } else {\n                    if (has_optional_chain) {\n                        optional_chain_test(s, &optional_chaining_label, 1);\n                    }\n                    emit_op(s, OP_get_field);\n                    emit_atom(s, s->token.u.ident.atom);\n                }\n            }\n            if (next_token(s))\n                return -1;\n        } else if (s->token.val == '[') {\n            int prev_op;\n\n        parse_array_access:\n            prev_op = get_prev_opcode(fd);\n            if (has_optional_chain) {\n                optional_chain_test(s, &optional_chaining_label, 1);\n            }\n            if (next_token(s))\n                return -1;\n            if (js_parse_expr(s))\n                return -1;\n            if (js_parse_expect(s, ']'))\n                return -1;\n            if (prev_op == OP_get_super) {\n                emit_op(s, OP_get_super_value);\n            } else {\n                emit_op(s, OP_get_array_el);\n            }\n        } else {\n            break;\n        }\n    }\n    if (optional_chaining_label >= 0)\n        emit_label(s, optional_chaining_label);\n    return 0;\n}\n\nstatic __exception int js_parse_delete(JSParseState *s)\n{\n    JSFunctionDef *fd = s->cur_func;\n    JSAtom name;\n    int opcode;\n\n    if (next_token(s))\n        return -1;\n    if (js_parse_unary(s, -1))\n        return -1;\n    switch(opcode = get_prev_opcode(fd)) {\n    case OP_get_field:\n        {\n            JSValue val;\n            int ret;\n\n            name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n            fd->byte_code.size = fd->last_opcode_pos;\n            fd->last_opcode_pos = -1;\n            val = JS_AtomToValue(s->ctx, name);\n            ret = emit_push_const(s, val, 1);\n            JS_FreeValue(s->ctx, val);\n            JS_FreeAtom(s->ctx, name);\n            if (ret)\n                return ret;\n        }\n        goto do_delete;\n    case OP_get_array_el:\n        fd->byte_code.size = fd->last_opcode_pos;\n        fd->last_opcode_pos = -1;\n    do_delete:\n        emit_op(s, OP_delete);\n        break;\n    case OP_scope_get_var:\n        /* 'delete this': this is not a reference */\n        name = get_u32(fd->byte_code.buf + fd->last_opcode_pos + 1);\n        if (name == JS_ATOM_this || name == JS_ATOM_new_target)\n            goto ret_true;\n        if (fd->js_mode & JS_MODE_STRICT) {\n            return js_parse_error(s, \"cannot delete a direct reference in strict mode\");\n        } else {\n            fd->byte_code.buf[fd->last_opcode_pos] = OP_scope_delete_var;\n        }\n        break;\n    case OP_scope_get_private_field:\n        return js_parse_error(s, \"cannot delete a private class field\");\n    case OP_get_super_value:\n        emit_op(s, OP_throw_var);\n        emit_atom(s, JS_ATOM_NULL);\n        emit_u8(s, JS_THROW_VAR_DELETE_SUPER);\n        break;\n    default:\n    ret_true:\n        emit_op(s, OP_drop);\n        emit_op(s, OP_push_true);\n        break;\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_unary(JSParseState *s, int exponentiation_flag)\n{\n    int op;\n\n    switch(s->token.val) {\n    case '+':\n    case '-':\n    case '!':\n    case '~':\n    case TOK_VOID:\n        op = s->token.val;\n        if (next_token(s))\n            return -1;\n        if (js_parse_unary(s, -1))\n            return -1;\n        switch(op) {\n        case '-':\n            emit_op(s, OP_neg);\n            break;\n        case '+':\n            emit_op(s, OP_plus);\n            break;\n        case '!':\n            emit_op(s, OP_lnot);\n            break;\n        case '~':\n            emit_op(s, OP_not);\n            break;\n        case TOK_VOID:\n            emit_op(s, OP_drop);\n            emit_op(s, OP_undefined);\n            break;\n        default:\n            abort();\n        }\n        exponentiation_flag = 0;\n        break;\n    case TOK_DEC:\n    case TOK_INC:\n        {\n            int opcode, op, scope, label;\n            JSAtom name;\n            op = s->token.val;\n            if (next_token(s))\n                return -1;\n            /* XXX: should parse LeftHandSideExpression */\n            if (js_parse_unary(s, 0))\n                return -1;\n            if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, TRUE, op))\n                return -1;\n            emit_op(s, OP_dec + op - TOK_DEC);\n            put_lvalue(s, opcode, scope, name, label, FALSE);\n        }\n        break;\n    case TOK_TYPEOF:\n        {\n            JSFunctionDef *fd;\n            if (next_token(s))\n                return -1;\n            if (js_parse_unary(s, -1))\n                return -1;\n            /* reference access should not return an exception, so we\n               patch the get_var */\n            fd = s->cur_func;\n            if (get_prev_opcode(fd) == OP_scope_get_var) {\n                fd->byte_code.buf[fd->last_opcode_pos] = OP_scope_get_var_undef;\n            }\n            emit_op(s, OP_typeof);\n            exponentiation_flag = 0;\n        }\n        break;\n    case TOK_DELETE:\n        if (js_parse_delete(s))\n            return -1;\n        exponentiation_flag = 0;\n        break;\n    case TOK_AWAIT:\n        if (!(s->cur_func->func_kind & JS_FUNC_ASYNC))\n            return js_parse_error(s, \"unexpected 'await' keyword\");\n        if (!s->cur_func->in_function_body)\n            return js_parse_error(s, \"await in default expression\");\n        if (next_token(s))\n            return -1;\n        if (js_parse_unary(s, -1))\n            return -1;\n        emit_op(s, OP_await);\n        exponentiation_flag = 0;\n        break;\n    default:\n        if (js_parse_postfix_expr(s, TRUE))\n            return -1;\n        if (!s->got_lf &&\n            (s->token.val == TOK_DEC || s->token.val == TOK_INC)) {\n            int opcode, op, scope, label;\n            JSAtom name;\n            op = s->token.val;\n            if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, TRUE, op))\n                return -1;\n            emit_op(s, OP_post_dec + op - TOK_DEC);\n            put_lvalue(s, opcode, scope, name, label, TRUE);\n            if (next_token(s))\n                return -1;        \n        }\n        break;\n    }\n    if (exponentiation_flag) {\n#ifdef CONFIG_BIGNUM\n        if (s->token.val == TOK_POW || s->token.val == TOK_MATH_POW) {\n            /* Extended exponentiation syntax rules: we extend the ES7\n               grammar in order to have more intuitive semantics:\n               -2**2 evaluates to -4. */\n            if (!(s->cur_func->js_mode & JS_MODE_MATH)) {\n                if (exponentiation_flag < 0) {\n                    JS_ThrowSyntaxError(s->ctx, \"unparenthesized unary expression can't appear on the left-hand side of '**'\");\n                    return -1;\n                }\n            }\n            if (next_token(s))\n                return -1;\n            if (js_parse_unary(s, 1))\n                return -1;\n            emit_op(s, OP_pow);\n        }\n#else\n        if (s->token.val == TOK_POW) {\n            /* Strict ES7 exponentiation syntax rules: To solve\n               conficting semantics between different implementations\n               regarding the precedence of prefix operators and the\n               postifx exponential, ES7 specifies that -2**2 is a\n               syntax error. */\n            if (exponentiation_flag < 0) {\n                JS_ThrowSyntaxError(s->ctx, \"unparenthesized unary expression can't appear on the left-hand side of '**'\");\n                return -1;\n            }\n            if (next_token(s))\n                return -1;\n            if (js_parse_unary(s, 1))\n                return -1;\n            emit_op(s, OP_pow);\n        }\n#endif\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_expr_binary(JSParseState *s, int level,\n                                            BOOL in_accepted)\n{\n    int op, opcode;\n\n    if (level == 0) {\n        return js_parse_unary(s, 1);\n    }\n    if (js_parse_expr_binary(s, level - 1, in_accepted))\n        return -1;\n    for(;;) {\n        op = s->token.val;\n        switch(level) {\n        case 1:\n            switch(op) {\n            case '*':\n                opcode = OP_mul;\n                break;\n            case '/':\n                opcode = OP_div;\n                break;\n            case '%':\n#ifdef CONFIG_BIGNUM\n                if (s->cur_func->js_mode & JS_MODE_MATH)\n                    opcode = OP_math_mod;\n                else\n#endif\n                    opcode = OP_mod;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 2:\n            switch(op) {\n            case '+':\n                opcode = OP_add;\n                break;\n            case '-':\n                opcode = OP_sub;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 3:\n            switch(op) {\n            case TOK_SHL:\n                opcode = OP_shl;\n                break;\n            case TOK_SAR:\n                opcode = OP_sar;\n                break;\n            case TOK_SHR:\n                opcode = OP_shr;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 4:\n            switch(op) {\n            case '<':\n                opcode = OP_lt;\n                break;\n            case '>':\n                opcode = OP_gt;\n                break;\n            case TOK_LTE:\n                opcode = OP_lte;\n                break;\n            case TOK_GTE:\n                opcode = OP_gte;\n                break;\n            case TOK_INSTANCEOF:\n                opcode = OP_instanceof;\n                break;\n            case TOK_IN:\n                if (in_accepted) {\n                    opcode = OP_in;\n                } else {\n                    return 0;\n                }\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 5:\n            switch(op) {\n            case TOK_EQ:\n                opcode = OP_eq;\n                break;\n            case TOK_NEQ:\n                opcode = OP_neq;\n                break;\n            case TOK_STRICT_EQ:\n                opcode = OP_strict_eq;\n                break;\n            case TOK_STRICT_NEQ:\n                opcode = OP_strict_neq;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 6:\n            switch(op) {\n            case '&':\n                opcode = OP_and;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 7:\n            switch(op) {\n            case '^':\n                opcode = OP_xor;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        case 8:\n            switch(op) {\n            case '|':\n                opcode = OP_or;\n                break;\n            default:\n                return 0;\n            }\n            break;\n        default:\n            abort();\n        }\n        if (next_token(s))\n            return -1;\n        if (js_parse_expr_binary(s, level - 1, in_accepted))\n            return -1;\n        emit_op(s, opcode);\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_logical_and_or(JSParseState *s, int op,\n                                               BOOL in_accepted)\n{\n    int label1;\n\n    if (op == TOK_LAND) {\n        if (js_parse_expr_binary(s, 8, in_accepted))\n            return -1;\n    } else {\n        if (js_parse_logical_and_or(s, TOK_LAND, in_accepted))\n            return -1;\n    }\n    if (s->token.val == op) {\n        label1 = new_label(s);\n\n        for(;;) {\n            if (next_token(s))\n                return -1;\n            emit_op(s, OP_dup);\n            emit_goto(s, op == TOK_LAND ? OP_if_false : OP_if_true, label1);\n            emit_op(s, OP_drop);\n\n            if (op == TOK_LAND) {\n                if (js_parse_expr_binary(s, 8, in_accepted))\n                    return -1;\n            } else {\n                if (js_parse_logical_and_or(s, TOK_LAND, in_accepted))\n                    return -1;\n            }\n            if (s->token.val != op) {\n                if (s->token.val == TOK_DOUBLE_QUESTION_MARK)\n                    return js_parse_error(s, \"cannot mix ?? with && or ||\");\n                break;\n            }\n        }\n\n        emit_label(s, label1);\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_coalesce_expr(JSParseState *s, BOOL in_accepted)\n{\n    int label1;\n    \n    if (js_parse_logical_and_or(s, TOK_LOR, in_accepted))\n        return -1;\n    if (s->token.val == TOK_DOUBLE_QUESTION_MARK) {\n        label1 = new_label(s);\n        for(;;) {\n            if (next_token(s))\n                return -1;\n            \n            emit_op(s, OP_dup);\n            emit_op(s, OP_is_undefined_or_null);\n            emit_goto(s, OP_if_false, label1);\n            emit_op(s, OP_drop);\n            \n            if (js_parse_expr_binary(s, 8, in_accepted))\n                return -1;\n            if (s->token.val != TOK_DOUBLE_QUESTION_MARK)\n                break;\n        }\n        emit_label(s, label1);\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_cond_expr(JSParseState *s, BOOL in_accepted)\n{\n    int label1, label2;\n\n    if (js_parse_coalesce_expr(s, in_accepted))\n        return -1;\n    if (s->token.val == '?') {\n        if (next_token(s))\n            return -1;\n        label1 = emit_goto(s, OP_if_false, -1);\n\n        if (js_parse_assign_expr(s, TRUE))\n            return -1;\n        if (js_parse_expect(s, ':'))\n            return -1;\n\n        label2 = emit_goto(s, OP_goto, -1);\n\n        emit_label(s, label1);\n\n        if (js_parse_assign_expr(s, in_accepted))\n            return -1;\n\n        emit_label(s, label2);\n    }\n    return 0;\n}\n\nstatic void emit_return(JSParseState *s, BOOL hasval);\n\nstatic __exception int js_parse_assign_expr(JSParseState *s, BOOL in_accepted)\n{\n    int opcode, op, scope;\n    JSAtom name0 = JS_ATOM_NULL;\n    JSAtom name;\n\n    if (s->token.val == TOK_YIELD) {\n        BOOL is_star = FALSE;\n        if (!(s->cur_func->func_kind & JS_FUNC_GENERATOR))\n            return js_parse_error(s, \"unexpected 'yield' keyword\");\n        if (!s->cur_func->in_function_body)\n            return js_parse_error(s, \"yield in default expression\");\n        if (next_token(s))\n            return -1;\n        /* XXX: is there a better method to detect 'yield' without\n           parameters ? */\n        if (s->token.val != ';' && s->token.val != ')' &&\n            s->token.val != ']' && s->token.val != '}' &&\n            s->token.val != ',' && s->token.val != ':' && !s->got_lf) {\n            if (s->token.val == '*') {\n                is_star = TRUE;\n                if (next_token(s))\n                    return -1;\n            }\n            if (js_parse_assign_expr(s, in_accepted))\n                return -1;\n        } else {\n            emit_op(s, OP_undefined);\n        }\n        if (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR) {\n            int label_loop, label_return, label_next;\n            int label_return1, label_yield, label_throw, label_throw1;\n            int label_throw2;\n\n            if (is_star) {\n                label_loop = new_label(s);\n                label_yield = new_label(s);\n\n                emit_op(s, OP_for_await_of_start);\n\n                /* remove the catch offset (XXX: could avoid pushing back\n                   undefined) */\n                emit_op(s, OP_drop);\n                emit_op(s, OP_undefined);\n\n                emit_op(s, OP_undefined); /* initial value */\n\n                emit_label(s, label_loop);\n                emit_op(s, OP_async_iterator_next);\n                emit_op(s, OP_await);\n                emit_op(s, OP_iterator_get_value_done);\n                label_next = emit_goto(s, OP_if_true, -1); /* end of loop */\n                emit_op(s, OP_await);\n                emit_label(s, label_yield);\n                emit_op(s, OP_async_yield_star);\n                emit_op(s, OP_dup);\n                label_return = emit_goto(s, OP_if_true, -1);\n                emit_op(s, OP_drop);\n                emit_goto(s, OP_goto, label_loop);\n\n                emit_label(s, label_return);\n                emit_op(s, OP_push_i32);\n                emit_u32(s, 2);\n                emit_op(s, OP_strict_eq);\n                label_throw = emit_goto(s, OP_if_true, -1);\n\n                /* return handling */\n                emit_op(s, OP_await);\n                emit_op(s, OP_async_iterator_get);\n                emit_u8(s, 0);\n                label_return1 = emit_goto(s, OP_if_true, -1);\n                emit_op(s, OP_await);\n                emit_op(s, OP_iterator_get_value_done);\n                /* XXX: the spec does not indicate that an await should be\n                   performed in case done = true, but the tests assume it */\n                emit_goto(s, OP_if_false, label_yield);\n\n                emit_label(s, label_return1);\n                emit_op(s, OP_nip);\n                emit_op(s, OP_nip);\n                emit_op(s, OP_nip);\n                emit_return(s, TRUE);\n\n                /* throw handling */\n                emit_label(s, label_throw);\n                emit_op(s, OP_async_iterator_get);\n                emit_u8(s, 1);\n                label_throw1 = emit_goto(s, OP_if_true, -1);\n                emit_op(s, OP_await);\n                emit_op(s, OP_iterator_get_value_done);\n                emit_goto(s, OP_if_false, label_yield);\n                /* XXX: the spec does not indicate that an await should be\n                   performed in case done = true, but the tests assume it */\n                emit_op(s, OP_await);\n                emit_goto(s, OP_goto, label_next);\n                /* close the iterator and throw a type error exception */\n                emit_label(s, label_throw1);\n                emit_op(s, OP_async_iterator_get);\n                emit_u8(s, 0);\n                label_throw2 = emit_goto(s, OP_if_true, -1);\n                emit_op(s, OP_await);\n                emit_label(s, label_throw2);\n                emit_op(s, OP_async_iterator_get);\n                emit_u8(s, 2); /* throw the type error exception */\n                emit_op(s, OP_drop); /* never reached */\n\n                emit_label(s, label_next);\n                emit_op(s, OP_nip); /* keep the value associated with\n                                       done = true */\n                emit_op(s, OP_nip);\n                emit_op(s, OP_nip);\n            } else {\n                emit_op(s, OP_await);\n                emit_op(s, OP_yield);\n                label_next = emit_goto(s, OP_if_false, -1);\n                emit_return(s, TRUE);\n                emit_label(s, label_next);\n            }\n        } else {\n            int label_next;\n            if (is_star) {\n                emit_op(s, OP_for_of_start);\n                emit_op(s, OP_drop);    /* drop the catch offset */\n                emit_op(s, OP_yield_star);\n            } else {\n                emit_op(s, OP_yield);\n            }\n            label_next = emit_goto(s, OP_if_false, -1);\n            emit_return(s, TRUE);\n            emit_label(s, label_next);\n        }\n        return 0;\n    }\n    if (s->token.val == TOK_IDENT) {\n        /* name0 is used to check for OP_set_name pattern, not duplicated */\n        name0 = s->token.u.ident.atom;\n    }\n    if (js_parse_cond_expr(s, in_accepted))\n        return -1;\n\n    op = s->token.val;\n    if (op == '=' || (op >= TOK_MUL_ASSIGN && op <= TOK_POW_ASSIGN)) {\n        int label;\n        if (next_token(s))\n            return -1;\n        if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, (op != '='), op) < 0)\n            return -1;\n\n        if (js_parse_assign_expr(s, in_accepted)) {\n            JS_FreeAtom(s->ctx, name);\n            return -1;\n        }\n\n        if (op == '=') {\n            if (opcode == OP_get_ref_value && name == name0) {\n                set_object_name(s, name);\n            }\n        } else {\n            static const uint8_t assign_opcodes[] = {\n                OP_mul, OP_div, OP_mod, OP_add, OP_sub,\n                OP_shl, OP_sar, OP_shr, OP_and, OP_xor, OP_or,\n#ifdef CONFIG_BIGNUM\n                OP_pow,\n#endif\n                OP_pow,\n            };\n            op = assign_opcodes[op - TOK_MUL_ASSIGN];\n#ifdef CONFIG_BIGNUM\n            if (s->cur_func->js_mode & JS_MODE_MATH) {\n                if (op == OP_mod)\n                    op = OP_math_mod;\n            }\n#endif\n            emit_op(s, op);\n        }\n        put_lvalue(s, opcode, scope, name, label, FALSE);\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_expr2(JSParseState *s, BOOL in_accepted)\n{\n    BOOL comma = FALSE;\n    for(;;) {\n        if (js_parse_assign_expr(s, in_accepted))\n            return -1;\n        if (comma) {\n            /* prevent get_lvalue from using the last expression\n               as an lvalue. This also prevents the conversion of\n               of get_var to get_ref for method lookup in function\n               call inside `with` statement.\n             */\n            s->cur_func->last_opcode_pos = -1;\n        }\n        if (s->token.val != ',')\n            break;\n        comma = TRUE;\n        if (next_token(s))\n            return -1;\n        emit_op(s, OP_drop);\n    }\n    return 0;\n}\n\nstatic __exception int js_parse_expr(JSParseState *s)\n{\n    return js_parse_expr2(s, TRUE);\n}\n\nstatic void push_break_entry(JSFunctionDef *fd, BlockEnv *be,\n                             JSAtom label_name,\n                             int label_break, int label_cont,\n                             int drop_count)\n{\n    be->prev = fd->top_break;\n    fd->top_break = be;\n    be->label_name = label_name;\n    be->label_break = label_break;\n    be->label_cont = label_cont;\n    be->drop_count = drop_count;\n    be->label_finally = -1;\n    be->scope_level = fd->scope_level;\n    be->has_iterator = FALSE;\n}\n\nstatic void pop_break_entry(JSFunctionDef *fd)\n{\n    BlockEnv *be;\n    be = fd->top_break;\n    fd->top_break = be->prev;\n}\n\nstatic __exception int emit_break(JSParseState *s, JSAtom name, int is_cont)\n{\n    BlockEnv *top;\n    int i, scope_level;\n\n    scope_level = s->cur_func->scope_level;\n    top = s->cur_func->top_break;\n    while (top != NULL) {\n        close_scopes(s, scope_level, top->scope_level);\n        scope_level = top->scope_level;\n        if (is_cont &&\n            top->label_cont != -1 &&\n            (name == JS_ATOM_NULL || top->label_name == name)) {\n            /* continue stays inside the same block */\n            emit_goto(s, OP_goto, top->label_cont);\n            return 0;\n        }\n        if (!is_cont &&\n            top->label_break != -1 &&\n            (name == JS_ATOM_NULL || top->label_name == name)) {\n            emit_goto(s, OP_goto, top->label_break);\n            return 0;\n        }\n        i = 0;\n        if (top->has_iterator) {\n            emit_op(s, OP_iterator_close);\n            i += 3;\n        }\n        for(; i < top->drop_count; i++)\n            emit_op(s, OP_drop);\n        if (top->label_finally != -1) {\n            /* must push dummy value to keep same stack depth */\n            emit_op(s, OP_undefined);\n            emit_goto(s, OP_gosub, top->label_finally);\n            emit_op(s, OP_drop);\n        }\n        top = top->prev;\n    }\n    if (name == JS_ATOM_NULL) {\n        if (is_cont)\n            return js_parse_error(s, \"continue must be inside loop\");\n        else\n            return js_parse_error(s, \"break must be inside loop or switch\");\n    } else {\n        return js_parse_error(s, \"break/continue label not found\");\n    }\n}\n\n/* execute the finally blocks before return */\nstatic void emit_return(JSParseState *s, BOOL hasval)\n{\n    BlockEnv *top;\n    int drop_count;\n\n    drop_count = 0;\n    top = s->cur_func->top_break;\n    while (top != NULL) {\n        /* XXX: emit the appropriate OP_leave_scope opcodes? Probably not\n           required as all local variables will be closed upon returning\n           from JS_CallInternal, but not in the same order. */\n        if (top->has_iterator) {\n            /* with 'yield', the exact number of OP_drop to emit is\n               unknown, so we use a specific operation to look for\n               the catch offset */\n            if (!hasval) {\n                emit_op(s, OP_undefined);\n                hasval = TRUE;\n            }\n            emit_op(s, OP_iterator_close_return);\n            if (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR) {\n                int label_next;\n                emit_op(s, OP_async_iterator_close);\n                label_next = emit_goto(s, OP_if_true, -1);\n                emit_op(s, OP_await);\n                emit_label(s, label_next);\n                emit_op(s, OP_drop);\n            } else {\n                emit_op(s, OP_iterator_close);\n            }\n            drop_count = -3;\n        }\n        drop_count += top->drop_count;\n        if (top->label_finally != -1) {\n            while(drop_count) {\n                /* must keep the stack top if hasval */\n                emit_op(s, hasval ? OP_nip : OP_drop);\n                drop_count--;\n            }\n            if (!hasval) {\n                /* must push return value to keep same stack size */\n                emit_op(s, OP_undefined);\n                hasval = TRUE;\n            }\n            emit_goto(s, OP_gosub, top->label_finally);\n        }\n        top = top->prev;\n    }\n    if (s->cur_func->is_derived_class_constructor) {\n        int label_return;\n\n        /* 'this' can be uninitialized, so it may be accessed only if\n           the derived class constructor does not return an object */\n        if (hasval) {\n            emit_op(s, OP_check_ctor_return);\n            label_return = emit_goto(s, OP_if_false, -1);\n            emit_op(s, OP_drop);\n        } else {\n            label_return = -1;\n        }\n\n        /* XXX: if this is not initialized, should throw the\n           ReferenceError in the caller realm */\n        emit_op(s, OP_scope_get_var);\n        emit_atom(s, JS_ATOM_this);\n        emit_u16(s, 0);\n\n        emit_label(s, label_return);\n        emit_op(s, OP_return);\n    } else if (s->cur_func->func_kind != JS_FUNC_NORMAL) {\n        if (!hasval) {\n            emit_op(s, OP_undefined);\n        } else if (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR) {\n            emit_op(s, OP_await);\n        }\n        emit_op(s, OP_return_async);\n    } else {\n        emit_op(s, hasval ? OP_return : OP_return_undef);\n    }\n}\n\n#define DECL_MASK_FUNC  (1 << 0) /* allow normal function declaration */\n/* ored with DECL_MASK_FUNC if function declarations are allowed with a label */\n#define DECL_MASK_FUNC_WITH_LABEL (1 << 1)\n#define DECL_MASK_OTHER (1 << 2) /* all other declarations */\n#define DECL_MASK_ALL   (DECL_MASK_FUNC | DECL_MASK_FUNC_WITH_LABEL | DECL_MASK_OTHER)\n\nstatic __exception int js_parse_statement_or_decl(JSParseState *s,\n                                                  int decl_mask);\n\nstatic __exception int js_parse_statement(JSParseState *s)\n{\n    return js_parse_statement_or_decl(s, 0);\n}\n\nstatic __exception int js_parse_block(JSParseState *s)\n{\n    if (js_parse_expect(s, '{'))\n        return -1;\n    if (s->token.val != '}') {\n        push_scope(s);\n        for(;;) {\n            if (js_parse_statement_or_decl(s, DECL_MASK_ALL))\n                return -1;\n            if (s->token.val == '}')\n                break;\n        }\n        pop_scope(s);\n    }\n    if (next_token(s))\n        return -1;\n    return 0;\n}\n\nstatic __exception int js_parse_var(JSParseState *s, BOOL in_accepted, int tok,\n                                    BOOL export_flag)\n{\n    JSContext *ctx = s->ctx;\n    JSFunctionDef *fd = s->cur_func;\n    JSAtom name = JS_ATOM_NULL;\n\n    for (;;) {\n        if (s->token.val == TOK_IDENT) {\n            if (s->token.u.ident.is_reserved) {\n                return js_parse_error_reserved_identifier(s);\n            }\n            name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            if (name == JS_ATOM_let && (tok == TOK_LET || tok == TOK_CONST)) {\n                js_parse_error(s, \"'let' is not a valid lexical identifier\");\n                goto var_error;\n            }\n            if (next_token(s))\n                goto var_error;\n            if (js_define_var(s, name, tok))\n                goto var_error;\n            if (export_flag) {\n                if (!add_export_entry(s, s->cur_func->module, name, name,\n                                      JS_EXPORT_TYPE_LOCAL))\n                    goto var_error;\n            }\n\n            if (s->token.val == '=') {\n                if (next_token(s))\n                    goto var_error;\n                if (tok == TOK_VAR) {\n                    /* Must make a reference for proper `with` semantics */\n                    int opcode, scope, label;\n                    JSAtom name1;\n\n                    emit_op(s, OP_scope_get_var);\n                    emit_atom(s, name);\n                    emit_u16(s, fd->scope_level);\n                    if (get_lvalue(s, &opcode, &scope, &name1, &label, NULL, FALSE, '=') < 0)\n                        goto var_error;\n                    if (js_parse_assign_expr(s, in_accepted)) {\n                        JS_FreeAtom(ctx, name1);\n                        goto var_error;\n                    }\n                    set_object_name(s, name);\n                    put_lvalue(s, opcode, scope, name1, label, FALSE);\n                    emit_op(s, OP_drop);\n                } else {\n                    if (js_parse_assign_expr(s, in_accepted))\n                        goto var_error;\n                    set_object_name(s, name);\n                    emit_op(s, (tok == TOK_CONST || tok == TOK_LET) ?\n                        OP_scope_put_var_init : OP_scope_put_var);\n                    emit_atom(s, name);\n                    emit_u16(s, fd->scope_level);\n                }\n            } else {\n                if (tok == TOK_CONST) {\n                    js_parse_error(s, \"missing initializer for const variable\");\n                    goto var_error;\n                }\n                if (tok == TOK_LET) {\n                    /* initialize lexical variable upon entering its scope */\n                    emit_op(s, OP_undefined);\n                    emit_op(s, OP_scope_put_var_init);\n                    emit_atom(s, name);\n                    emit_u16(s, fd->scope_level);\n                }\n            }\n            JS_FreeAtom(ctx, name);\n        } else {\n            int skip_bits;\n            if ((s->token.val == '[' || s->token.val == '{')\n            &&  js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') {\n                emit_op(s, OP_undefined);\n                if (js_parse_destructuring_element(s, tok, 0, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE))\n                    return -1;\n            } else {\n                return js_parse_error(s, \"variable name expected\");\n            }\n        }\n        if (s->token.val != ',')\n            break;\n        if (next_token(s))\n            return -1;\n    }\n    return 0;\n\n var_error:\n    JS_FreeAtom(ctx, name);\n    return -1;\n}\n\n/* test if the current token is a label. Use simplistic look-ahead scanner */\nstatic BOOL is_label(JSParseState *s)\n{\n    return (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved &&\n            peek_token(s, FALSE) == ':');\n}\n\n/* test if the current token is a let keyword. Use simplistic look-ahead scanner */\nstatic int is_let(JSParseState *s, int decl_mask)\n{\n    int res = FALSE;\n\n    if (token_is_pseudo_keyword(s, JS_ATOM_let)) {\n#if 1\n        JSParsePos pos;\n        js_parse_get_pos(s, &pos);\n        for (;;) {\n            if (next_token(s)) {\n                res = -1;\n                break;\n            }\n            if (s->token.val == '[') {\n                /* let [ is a syntax restriction:\n                   it never introduces an ExpressionStatement */\n                res = TRUE;\n                break;\n            }\n            if (s->token.val == '{' ||\n                (s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved) ||\n                s->token.val == TOK_LET ||\n                s->token.val == TOK_YIELD ||\n                s->token.val == TOK_AWAIT) {\n                /* Check for possible ASI if not scanning for Declaration */\n                /* XXX: should also check that `{` introduces a BindingPattern,\n                   but Firefox does not and rejects eval(\"let=1;let\\n{if(1)2;}\") */\n                if (s->last_line_num == s->token.line_num || (decl_mask & DECL_MASK_OTHER)) {\n                    res = TRUE;\n                    break;\n                }\n                break;\n            }\n            break;\n        }\n        if (js_parse_seek_token(s, &pos)) {\n            res = -1;\n        }\n#else\n        int tok = peek_token(s, TRUE);\n        if (tok == '{' || tok == TOK_IDENT || peek_token(s, FALSE) == '[') {\n            res = TRUE;\n        }\n#endif\n    }\n    return res;\n}\n\n/* XXX: handle IteratorClose when exiting the loop before the\n   enumeration is done */\nstatic __exception int js_parse_for_in_of(JSParseState *s, int label_name,\n                                          BOOL is_async)\n{\n    JSContext *ctx = s->ctx;\n    JSFunctionDef *fd = s->cur_func;\n    JSAtom var_name;\n    BOOL has_initializer, is_for_of, has_destructuring;\n    int tok, tok1, opcode, scope, block_scope_level;\n    int label_next, label_expr, label_cont, label_body, label_break;\n    int pos_next, pos_expr;\n    BlockEnv break_entry;\n\n    has_initializer = FALSE;\n    has_destructuring = FALSE;\n    is_for_of = FALSE;\n    block_scope_level = fd->scope_level;\n    label_cont = new_label(s);\n    label_body = new_label(s);\n    label_break = new_label(s);\n    label_next = new_label(s);\n\n    /* create scope for the lexical variables declared in the enumeration\n       expressions. XXX: Not completely correct because of weird capturing\n       semantics in `for (i of o) a.push(function(){return i})` */\n    push_scope(s);\n\n    /* local for_in scope starts here so individual elements\n       can be closed in statement. */\n    push_break_entry(s->cur_func, &break_entry,\n                     label_name, label_break, label_cont, 1);\n    break_entry.scope_level = block_scope_level;\n\n    label_expr = emit_goto(s, OP_goto, -1);\n\n    pos_next = s->cur_func->byte_code.size;\n    emit_label(s, label_next);\n\n    tok = s->token.val;\n    switch (is_let(s, DECL_MASK_OTHER)) {\n    case TRUE:\n        tok = TOK_LET;\n        break;\n    case FALSE:\n        break;\n    default:\n        return -1;\n    }\n    if (tok == TOK_VAR || tok == TOK_LET || tok == TOK_CONST) {\n        if (next_token(s))\n            return -1;\n\n        if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {\n            if (s->token.val == '[' || s->token.val == '{') {\n                if (js_parse_destructuring_element(s, tok, 0, TRUE, -1, FALSE))\n                    return -1;\n                has_destructuring = TRUE;\n            } else {\n                return js_parse_error(s, \"variable name expected\");\n            }\n            var_name = JS_ATOM_NULL;\n        } else {\n            var_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            if (next_token(s)) {\n                JS_FreeAtom(s->ctx, var_name);\n                return -1;\n            }\n            if (js_define_var(s, var_name, tok)) {\n                JS_FreeAtom(s->ctx, var_name);\n                return -1;\n            }\n            emit_op(s, (tok == TOK_CONST || tok == TOK_LET) ?\n                    OP_scope_put_var_init : OP_scope_put_var);\n            emit_atom(s, var_name);\n            emit_u16(s, fd->scope_level);\n        }\n    } else {\n        int skip_bits;\n        if ((s->token.val == '[' || s->token.val == '{')\n        &&  ((tok1 = js_parse_skip_parens_token(s, &skip_bits, FALSE)) == TOK_IN || tok1 == TOK_OF)) {\n            if (js_parse_destructuring_element(s, 0, 0, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE))\n                return -1;\n        } else {\n            int lvalue_label, depth;\n            if (js_parse_postfix_expr(s, TRUE))\n                return -1;\n            if (get_lvalue(s, &opcode, &scope, &var_name, &lvalue_label,\n                           &depth, FALSE, TOK_FOR))\n                return -1;\n            /* swap value and lvalue object and store it into lvalue object */\n            /* enum_rec val [depth] -- enum_rec */\n            switch(depth) {\n            case 1:\n                emit_op(s, OP_swap);\n                break;\n            case 2:\n                emit_op(s, OP_rot3l);\n                break;\n            case 3:\n                emit_op(s, OP_rot4l);\n                break;\n            default:\n                abort();\n            }\n            put_lvalue_nokeep(s, opcode, scope, var_name, lvalue_label,\n                              TOK_FOR /* not used */);\n        }\n        var_name = JS_ATOM_NULL;\n    }\n    emit_goto(s, OP_goto, label_body);\n\n    pos_expr = s->cur_func->byte_code.size;\n    emit_label(s, label_expr);\n    if (s->token.val == '=') {\n        /* XXX: potential scoping issue if inside `with` statement */\n        has_initializer = TRUE;\n        /* parse and evaluate initializer prior to evaluating the\n           object (only used with \"for in\" with a non lexical variable\n           in non strict mode */\n        if (next_token(s) || js_parse_assign_expr(s, FALSE)) {\n            JS_FreeAtom(ctx, var_name);\n            return -1;\n        }\n        if (var_name != JS_ATOM_NULL) {\n            emit_op(s, OP_scope_put_var);\n            emit_atom(s, var_name);\n            emit_u16(s, fd->scope_level);\n        }\n    }\n    JS_FreeAtom(ctx, var_name);\n\n    if (token_is_pseudo_keyword(s, JS_ATOM_of)) {\n        break_entry.has_iterator = is_for_of = TRUE;\n        break_entry.drop_count += 2;\n        if (has_initializer)\n            goto initializer_error;\n    } else if (s->token.val == TOK_IN) {\n        if (is_async)\n            return js_parse_error(s, \"'for await' loop should be used with 'of'\");\n        if (has_initializer &&\n            (tok != TOK_VAR || (fd->js_mode & JS_MODE_STRICT) ||\n             has_destructuring)) {\n        initializer_error:\n            return js_parse_error(s, \"a declaration in the head of a for-%s loop can't have an initializer\",\n                                  is_for_of ? \"of\" : \"in\");\n        }\n    } else {\n        return js_parse_error(s, \"expected 'of' or 'in' in for control expression\");\n    }\n    if (next_token(s))\n        return -1;\n    if (is_for_of) {\n        if (js_parse_assign_expr(s, TRUE))\n            return -1;\n    } else {\n        if (js_parse_expr(s))\n            return -1;\n    }\n    /* close the scope after having evaluated the expression so that\n       the TDZ values are in the closures */\n    close_scopes(s, s->cur_func->scope_level, block_scope_level);\n    if (is_for_of) {\n        if (is_async)\n            emit_op(s, OP_for_await_of_start);\n        else\n            emit_op(s, OP_for_of_start);\n        /* on stack: enum_rec */\n    } else {\n        emit_op(s, OP_for_in_start);\n        /* on stack: enum_obj */\n    }\n    emit_goto(s, OP_goto, label_cont);\n\n    if (js_parse_expect(s, ')'))\n        return -1;\n\n    if (OPTIMIZE) {\n        /* move the `next` code here */\n        DynBuf *bc = &s->cur_func->byte_code;\n        int chunk_size = pos_expr - pos_next;\n        int offset = bc->size - pos_next;\n        int i;\n        dbuf_realloc(bc, bc->size + chunk_size);\n        dbuf_put(bc, bc->buf + pos_next, chunk_size);\n        memset(bc->buf + pos_next, OP_nop, chunk_size);\n        /* `next` part ends with a goto */\n        s->cur_func->last_opcode_pos = bc->size - 5;\n        /* relocate labels */\n        for (i = label_cont; i < s->cur_func->label_count; i++) {\n            LabelSlot *ls = &s->cur_func->label_slots[i];\n            if (ls->pos >= pos_next && ls->pos < pos_expr)\n                ls->pos += offset;\n        }\n    }\n\n    emit_label(s, label_body);\n    if (js_parse_statement(s))\n        return -1;\n\n    close_scopes(s, s->cur_func->scope_level, block_scope_level);\n\n    emit_label(s, label_cont);\n    if (is_for_of) {\n        if (is_async) {\n            /* call the next method */\n            emit_op(s, OP_for_await_of_next);\n            /* get the result of the promise */\n            emit_op(s, OP_await);\n            /* unwrap the value and done values */\n            emit_op(s, OP_iterator_get_value_done);\n        } else {\n            emit_op(s, OP_for_of_next);\n            emit_u8(s, 0);\n        }\n    } else {\n        emit_op(s, OP_for_in_next);\n    }\n    /* on stack: enum_rec / enum_obj value bool */\n    emit_goto(s, OP_if_false, label_next);\n    /* drop the undefined value from for_xx_next */\n    emit_op(s, OP_drop);\n\n    emit_label(s, label_break);\n    if (is_for_of) {\n        /* close and drop enum_rec */\n        emit_op(s, OP_iterator_close);\n    } else {\n        emit_op(s, OP_drop);\n    }\n    pop_break_entry(s->cur_func);\n    pop_scope(s);\n    return 0;\n}\n\nstatic void set_eval_ret_undefined(JSParseState *s)\n{\n    if (s->cur_func->eval_ret_idx >= 0) {\n        emit_op(s, OP_undefined);\n        emit_op(s, OP_put_loc);\n        emit_u16(s, s->cur_func->eval_ret_idx);\n    }\n}\n\nstatic __exception int js_parse_statement_or_decl(JSParseState *s,\n                                                  int decl_mask)\n{\n    JSContext *ctx = s->ctx;\n    JSAtom label_name;\n    int tok;\n\n    /* specific label handling */\n    /* XXX: support multiple labels on loop statements */\n    label_name = JS_ATOM_NULL;\n    if (is_label(s)) {\n        BlockEnv *be;\n\n        label_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n\n        for (be = s->cur_func->top_break; be; be = be->prev) {\n            if (be->label_name == label_name) {\n                js_parse_error(s, \"duplicate label name\");\n                goto fail;\n            }\n        }\n\n        if (next_token(s))\n            goto fail;\n        if (js_parse_expect(s, ':'))\n            goto fail;\n        if (s->token.val != TOK_FOR\n        &&  s->token.val != TOK_DO\n        &&  s->token.val != TOK_WHILE) {\n            /* labelled regular statement */\n            int label_break, mask;\n            BlockEnv break_entry;\n\n            label_break = new_label(s);\n            push_break_entry(s->cur_func, &break_entry,\n                             label_name, label_break, -1, 0);\n            if (!(s->cur_func->js_mode & JS_MODE_STRICT) &&\n                (decl_mask & DECL_MASK_FUNC_WITH_LABEL)) {\n                mask = DECL_MASK_FUNC | DECL_MASK_FUNC_WITH_LABEL;\n            } else {\n                mask = 0;\n            }\n            if (js_parse_statement_or_decl(s, mask))\n                goto fail;\n            emit_label(s, label_break);\n            pop_break_entry(s->cur_func);\n            goto done;\n        }\n    }\n\n    switch(tok = s->token.val) {\n    case '{':\n        if (js_parse_block(s))\n            goto fail;\n        break;\n    case TOK_RETURN:\n        if (s->cur_func->is_eval) {\n            js_parse_error(s, \"return not in a function\");\n            goto fail;\n        }\n        if (next_token(s))\n            goto fail;\n        if (s->token.val != ';' && s->token.val != '}' && !s->got_lf) {\n            if (js_parse_expr(s))\n                goto fail;\n            emit_return(s, TRUE);\n        } else {\n            emit_return(s, FALSE);\n        }\n        if (js_parse_expect_semi(s))\n            goto fail;\n        break;\n    case TOK_THROW:\n        if (next_token(s))\n            goto fail;\n        if (s->got_lf) {\n            js_parse_error(s, \"line terminator not allowed after throw\");\n            goto fail;\n        }\n        if (js_parse_expr(s))\n            goto fail;\n        emit_op(s, OP_throw);\n        if (js_parse_expect_semi(s))\n            goto fail;\n        break;\n    case TOK_LET:\n    case TOK_CONST:\n    haslet:\n        if (!(decl_mask & DECL_MASK_OTHER)) {\n            js_parse_error(s, \"lexical declarations can't appear in single-statement context\");\n            goto fail;\n        }\n        /* fall thru */\n    case TOK_VAR:\n        if (next_token(s))\n            goto fail;\n        if (js_parse_var(s, TRUE, tok, FALSE))\n            goto fail;\n        if (js_parse_expect_semi(s))\n            goto fail;\n        break;\n    case TOK_IF:\n        {\n            int label1, label2, mask;\n            if (next_token(s))\n                goto fail;\n            /* create a new scope for `let f;if(1) function f(){}` */\n            push_scope(s);\n            set_eval_ret_undefined(s);\n            if (js_parse_expr_paren(s))\n                goto fail;\n            label1 = emit_goto(s, OP_if_false, -1);\n            if (s->cur_func->js_mode & JS_MODE_STRICT)\n                mask = 0;\n            else\n                mask = DECL_MASK_FUNC; /* Annex B.3.4 */\n\n            if (js_parse_statement_or_decl(s, mask))\n                goto fail;\n\n            if (s->token.val == TOK_ELSE) {\n                label2 = emit_goto(s, OP_goto, -1);\n                if (next_token(s))\n                    goto fail;\n\n                emit_label(s, label1);\n                if (js_parse_statement_or_decl(s, mask))\n                    goto fail;\n\n                label1 = label2;\n            }\n            emit_label(s, label1);\n            pop_scope(s);\n        }\n        break;\n    case TOK_WHILE:\n        {\n            int label_cont, label_break;\n            BlockEnv break_entry;\n\n            label_cont = new_label(s);\n            label_break = new_label(s);\n\n            push_break_entry(s->cur_func, &break_entry,\n                             label_name, label_break, label_cont, 0);\n\n            if (next_token(s))\n                goto fail;\n\n            set_eval_ret_undefined(s);\n\n            emit_label(s, label_cont);\n            if (js_parse_expr_paren(s))\n                goto fail;\n            emit_goto(s, OP_if_false, label_break);\n\n            if (js_parse_statement(s))\n                goto fail;\n            emit_goto(s, OP_goto, label_cont);\n\n            emit_label(s, label_break);\n\n            pop_break_entry(s->cur_func);\n        }\n        break;\n    case TOK_DO:\n        {\n            int label_cont, label_break, label1;\n            BlockEnv break_entry;\n\n            label_cont = new_label(s);\n            label_break = new_label(s);\n            label1 = new_label(s);\n\n            push_break_entry(s->cur_func, &break_entry,\n                             label_name, label_break, label_cont, 0);\n\n            if (next_token(s))\n                goto fail;\n\n            emit_label(s, label1);\n\n            set_eval_ret_undefined(s);\n\n            if (js_parse_statement(s))\n                goto fail;\n\n            emit_label(s, label_cont);\n            if (js_parse_expect(s, TOK_WHILE))\n                goto fail;\n            if (js_parse_expr_paren(s))\n                goto fail;\n            /* Insert semicolon if missing */\n            if (s->token.val == ';') {\n                if (next_token(s))\n                    goto fail;\n            }\n            emit_goto(s, OP_if_true, label1);\n\n            emit_label(s, label_break);\n\n            pop_break_entry(s->cur_func);\n        }\n        break;\n    case TOK_FOR:\n        {\n            int label_cont, label_break, label_body, label_test;\n            int pos_cont, pos_body, block_scope_level;\n            BlockEnv break_entry;\n            int tok, bits;\n            BOOL is_async;\n\n            if (next_token(s))\n                goto fail;\n\n            set_eval_ret_undefined(s);\n            bits = 0;\n            is_async = FALSE;\n            if (s->token.val == '(') {\n                js_parse_skip_parens_token(s, &bits, FALSE);\n            } else if (s->token.val == TOK_AWAIT) {\n                if (!(s->cur_func->func_kind & JS_FUNC_ASYNC)) {\n                    js_parse_error(s, \"for await is only valid in asynchronous functions\");\n                    goto fail;\n                }\n                is_async = TRUE;\n                if (next_token(s))\n                    goto fail;\n            }\n            if (js_parse_expect(s, '('))\n                goto fail;\n\n            if (!(bits & SKIP_HAS_SEMI)) {\n                /* parse for/in or for/of */\n                if (js_parse_for_in_of(s, label_name, is_async))\n                    goto fail;\n                break;\n            }\n            block_scope_level = s->cur_func->scope_level;\n\n            /* create scope for the lexical variables declared in the initial,\n               test and increment expressions */\n            push_scope(s);\n            /* initial expression */\n            tok = s->token.val;\n            if (tok != ';') {\n                switch (is_let(s, DECL_MASK_OTHER)) {\n                case TRUE:\n                    tok = TOK_LET;\n                    break;\n                case FALSE:\n                    break;\n                default:\n                    goto fail;\n                }\n                if (tok == TOK_VAR || tok == TOK_LET || tok == TOK_CONST) {\n                    if (next_token(s))\n                        goto fail;\n                    if (js_parse_var(s, FALSE, tok, FALSE))\n                        goto fail;\n                } else {\n                    if (js_parse_expr2(s, FALSE))\n                        goto fail;\n                    emit_op(s, OP_drop);\n                }\n\n                /* close the closures before the first iteration */\n                close_scopes(s, s->cur_func->scope_level, block_scope_level);\n            }\n            if (js_parse_expect(s, ';'))\n                goto fail;\n\n            label_test = new_label(s);\n            label_cont = new_label(s);\n            label_body = new_label(s);\n            label_break = new_label(s);\n\n            push_break_entry(s->cur_func, &break_entry,\n                             label_name, label_break, label_cont, 0);\n\n            /* test expression */\n            if (s->token.val == ';') {\n                /* no test expression */\n                label_test = label_body;\n            } else {\n                emit_label(s, label_test);\n                if (js_parse_expr(s))\n                    goto fail;\n                emit_goto(s, OP_if_false, label_break);\n            }\n            if (js_parse_expect(s, ';'))\n                goto fail;\n\n            if (s->token.val == ')') {\n                /* no end expression */\n                break_entry.label_cont = label_cont = label_test;\n                pos_cont = 0; /* avoid warning */\n            } else {\n                /* skip the end expression */\n                emit_goto(s, OP_goto, label_body);\n\n                pos_cont = s->cur_func->byte_code.size;\n                emit_label(s, label_cont);\n                if (js_parse_expr(s))\n                    goto fail;\n                emit_op(s, OP_drop);\n                if (label_test != label_body)\n                    emit_goto(s, OP_goto, label_test);\n            }\n            if (js_parse_expect(s, ')'))\n                goto fail;\n\n            pos_body = s->cur_func->byte_code.size;\n            emit_label(s, label_body);\n            if (js_parse_statement(s))\n                goto fail;\n\n            /* close the closures before the next iteration */\n            /* XXX: check continue case */\n            close_scopes(s, s->cur_func->scope_level, block_scope_level);\n\n            if (OPTIMIZE && label_test != label_body && label_cont != label_test) {\n                /* move the increment code here */\n                DynBuf *bc = &s->cur_func->byte_code;\n                int chunk_size = pos_body - pos_cont;\n                int offset = bc->size - pos_cont;\n                int i;\n                dbuf_realloc(bc, bc->size + chunk_size);\n                dbuf_put(bc, bc->buf + pos_cont, chunk_size);\n                memset(bc->buf + pos_cont, OP_nop, chunk_size);\n                /* increment part ends with a goto */\n                s->cur_func->last_opcode_pos = bc->size - 5;\n                /* relocate labels */\n                for (i = label_cont; i < s->cur_func->label_count; i++) {\n                    LabelSlot *ls = &s->cur_func->label_slots[i];\n                    if (ls->pos >= pos_cont && ls->pos < pos_body)\n                        ls->pos += offset;\n                }\n            } else {\n                emit_goto(s, OP_goto, label_cont);\n            }\n\n            emit_label(s, label_break);\n\n            pop_break_entry(s->cur_func);\n            pop_scope(s);\n        }\n        break;\n    case TOK_BREAK:\n    case TOK_CONTINUE:\n        {\n            int is_cont = s->token.val - TOK_BREAK;\n            int label;\n\n            if (next_token(s))\n                goto fail;\n            if (!s->got_lf && s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)\n                label = s->token.u.ident.atom;\n            else\n                label = JS_ATOM_NULL;\n            if (emit_break(s, label, is_cont))\n                goto fail;\n            if (label != JS_ATOM_NULL) {\n                if (next_token(s))\n                    goto fail;\n            }\n            if (js_parse_expect_semi(s))\n                goto fail;\n        }\n        break;\n    case TOK_SWITCH:\n        {\n            int label_case, label_break, label1;\n            int default_label_pos;\n            BlockEnv break_entry;\n\n            if (next_token(s))\n                goto fail;\n\n            set_eval_ret_undefined(s);\n            if (js_parse_expr_paren(s))\n                goto fail;\n\n            push_scope(s);\n            label_break = new_label(s);\n            push_break_entry(s->cur_func, &break_entry,\n                             label_name, label_break, -1, 1);\n\n            if (js_parse_expect(s, '{'))\n                goto fail;\n\n            default_label_pos = -1;\n            label_case = -1;\n            while (s->token.val != '}') {\n                if (s->token.val == TOK_CASE) {\n                    label1 = -1;\n                    if (label_case >= 0) {\n                        /* skip the case if needed */\n                        label1 = emit_goto(s, OP_goto, -1);\n                    }\n                    emit_label(s, label_case);\n                    label_case = -1;\n                    for (;;) {\n                        /* parse a sequence of case clauses */\n                        if (next_token(s))\n                            goto fail;\n                        emit_op(s, OP_dup);\n                        if (js_parse_expr(s))\n                            goto fail;\n                        if (js_parse_expect(s, ':'))\n                            goto fail;\n                        emit_op(s, OP_strict_eq);\n                        if (s->token.val == TOK_CASE) {\n                            label1 = emit_goto(s, OP_if_true, label1);\n                        } else {\n                            label_case = emit_goto(s, OP_if_false, -1);\n                            emit_label(s, label1);\n                            break;\n                        }\n                    }\n                } else if (s->token.val == TOK_DEFAULT) {\n                    if (next_token(s))\n                        goto fail;\n                    if (js_parse_expect(s, ':'))\n                        goto fail;\n                    if (default_label_pos >= 0) {\n                        js_parse_error(s, \"duplicate default\");\n                        goto fail;\n                    }\n                    if (label_case < 0) {\n                        /* falling thru direct from switch expression */\n                        label_case = emit_goto(s, OP_goto, -1);\n                    }\n                    /* Emit a dummy label opcode. Label will be patched after\n                       the end of the switch body. Do not use emit_label(s, 0)\n                       because it would clobber label 0 address, preventing\n                       proper optimizer operation.\n                     */\n                    emit_op(s, OP_label);\n                    emit_u32(s, 0);\n                    default_label_pos = s->cur_func->byte_code.size - 4;\n                } else {\n                    if (label_case < 0) {\n                        /* falling thru direct from switch expression */\n                        js_parse_error(s, \"invalid switch statement\");\n                        goto fail;\n                    }\n                    if (js_parse_statement_or_decl(s, DECL_MASK_ALL))\n                        goto fail;\n                }\n            }\n            if (js_parse_expect(s, '}'))\n                goto fail;\n            if (default_label_pos >= 0) {\n                /* Ugly patch for the the `default` label, shameful and risky */\n                put_u32(s->cur_func->byte_code.buf + default_label_pos,\n                        label_case);\n                s->cur_func->label_slots[label_case].pos = default_label_pos + 4;\n            } else {\n                emit_label(s, label_case);\n            }\n            emit_label(s, label_break);\n            emit_op(s, OP_drop); /* drop the switch expression */\n\n            pop_break_entry(s->cur_func);\n            pop_scope(s);\n        }\n        break;\n    case TOK_TRY:\n        {\n            int label_catch, label_catch2, label_finally, label_end;\n            JSAtom name;\n            BlockEnv block_env;\n\n            set_eval_ret_undefined(s);\n            if (next_token(s))\n                goto fail;\n            label_catch = new_label(s);\n            label_catch2 = new_label(s);\n            label_finally = new_label(s);\n            label_end = new_label(s);\n\n            emit_goto(s, OP_catch, label_catch);\n\n            push_break_entry(s->cur_func, &block_env,\n                             JS_ATOM_NULL, -1, -1, 1);\n            block_env.label_finally = label_finally;\n\n            if (js_parse_block(s))\n                goto fail;\n\n            pop_break_entry(s->cur_func);\n\n            if (js_is_live_code(s)) {\n                /* drop the catch offset */\n                emit_op(s, OP_drop);\n                /* must push dummy value to keep same stack size */\n                emit_op(s, OP_undefined);\n                emit_goto(s, OP_gosub, label_finally);\n                emit_op(s, OP_drop);\n\n                emit_goto(s, OP_goto, label_end);\n            }\n\n            if (s->token.val == TOK_CATCH) {\n                if (next_token(s))\n                    goto fail;\n\n                push_scope(s);  /* catch variable */\n                emit_label(s, label_catch);\n\n                if (s->token.val == '{') {\n                    /* support optional-catch-binding feature */\n                    emit_op(s, OP_drop);    /* pop the exception object */\n                } else {\n                    if (js_parse_expect(s, '('))\n                        goto fail;\n                    if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {\n                        if (s->token.val == '[' || s->token.val == '{') {\n                            /* XXX: TOK_LET is not completely correct */\n                            if (js_parse_destructuring_element(s, TOK_LET, 0, TRUE, -1, TRUE))\n                                goto fail;\n                        } else {\n                            js_parse_error(s, \"identifier expected\");\n                            goto fail;\n                        }\n                    } else {\n                        name = JS_DupAtom(ctx, s->token.u.ident.atom);\n                        if (next_token(s)\n                        ||  js_define_var(s, name, TOK_CATCH) < 0) {\n                            JS_FreeAtom(ctx, name);\n                            goto fail;\n                        }\n                        /* store the exception value in the catch variable */\n                        emit_op(s, OP_scope_put_var);\n                        emit_u32(s, name);\n                        emit_u16(s, s->cur_func->scope_level);\n                    }\n                    if (js_parse_expect(s, ')'))\n                        goto fail;\n                }\n                /* XXX: should keep the address to nop it out if there is no finally block */\n                emit_goto(s, OP_catch, label_catch2);\n\n                push_scope(s);  /* catch block */\n                push_break_entry(s->cur_func, &block_env, JS_ATOM_NULL,\n                                 -1, -1, 1);\n                block_env.label_finally = label_finally;\n\n                if (js_parse_block(s))\n                    goto fail;\n\n                pop_break_entry(s->cur_func);\n                pop_scope(s);  /* catch block */\n                pop_scope(s);  /* catch variable */\n\n                if (js_is_live_code(s)) {\n                    /* drop the catch2 offset */\n                    emit_op(s, OP_drop);\n                    /* XXX: should keep the address to nop it out if there is no finally block */\n                    /* must push dummy value to keep same stack size */\n                    emit_op(s, OP_undefined);\n                    emit_goto(s, OP_gosub, label_finally);\n                    emit_op(s, OP_drop);\n                    emit_goto(s, OP_goto, label_end);\n                }\n                /* catch exceptions thrown in the catch block to execute the\n                 * finally clause and rethrow the exception */\n                emit_label(s, label_catch2);\n                /* catch value is at TOS, no need to push undefined */\n                emit_goto(s, OP_gosub, label_finally);\n                emit_op(s, OP_throw);\n\n            } else if (s->token.val == TOK_FINALLY) {\n                /* finally without catch : execute the finally clause\n                 * and rethrow the exception */\n                emit_label(s, label_catch);\n                /* catch value is at TOS, no need to push undefined */\n                emit_goto(s, OP_gosub, label_finally);\n                emit_op(s, OP_throw);\n            } else {\n                js_parse_error(s, \"expecting catch or finally\");\n                goto fail;\n            }\n            emit_label(s, label_finally);\n            if (s->token.val == TOK_FINALLY) {\n                int saved_eval_ret_idx;\n                if (next_token(s))\n                    goto fail;\n                /* on the stack: ret_value gosub_ret_value */\n                push_break_entry(s->cur_func, &block_env, JS_ATOM_NULL,\n                                 -1, -1, 2);\n                saved_eval_ret_idx = s->cur_func->eval_ret_idx;\n                s->cur_func->eval_ret_idx = -1;\n                /* 'finally' does not update eval_ret */\n                if (js_parse_block(s))\n                    goto fail;\n                s->cur_func->eval_ret_idx = saved_eval_ret_idx;\n                pop_break_entry(s->cur_func);\n            }\n            emit_op(s, OP_ret);\n            emit_label(s, label_end);\n        }\n        break;\n    case ';':\n        /* empty statement */\n        if (next_token(s))\n            goto fail;\n        break;\n    case TOK_WITH:\n        if (s->cur_func->js_mode & JS_MODE_STRICT) {\n            js_parse_error(s, \"invalid keyword: with\");\n            goto fail;\n        } else {\n            int with_idx;\n\n            if (next_token(s))\n                goto fail;\n\n            if (js_parse_expr_paren(s))\n                goto fail;\n\n            push_scope(s);\n            with_idx = define_var(s, s->cur_func, JS_ATOM__with_,\n                                  JS_VAR_DEF_WITH);\n            if (with_idx < 0)\n                goto fail;\n            emit_op(s, OP_to_object);\n            emit_op(s, OP_put_loc);\n            emit_u16(s, with_idx);\n\n            set_eval_ret_undefined(s);\n            if (js_parse_statement(s))\n                goto fail;\n\n            /* Popping scope drops lexical context for the with object variable */\n            pop_scope(s);\n        }\n        break;\n    case TOK_FUNCTION:\n        /* ES6 Annex B.3.2 and B.3.3 semantics */\n        if (!(decl_mask & DECL_MASK_FUNC))\n            goto func_decl_error;\n        if (!(decl_mask & DECL_MASK_OTHER) && peek_token(s, FALSE) == '*')\n            goto func_decl_error;\n        goto parse_func_var;\n    case TOK_IDENT:\n        if (s->token.u.ident.is_reserved) {\n            js_parse_error_reserved_identifier(s);\n            goto fail;\n        }\n        /* Determine if `let` introduces a Declaration or an ExpressionStatement */\n        switch (is_let(s, decl_mask)) {\n        case TRUE:\n            tok = TOK_LET;\n            goto haslet;\n        case FALSE:\n            break;\n        default:\n            goto fail;\n        }\n        if (token_is_pseudo_keyword(s, JS_ATOM_async) &&\n            peek_token(s, TRUE) == TOK_FUNCTION) {\n            if (!(decl_mask & DECL_MASK_OTHER)) {\n            func_decl_error:\n                js_parse_error(s, \"function declarations can't appear in single-statement context\");\n                goto fail;\n            }\n        parse_func_var:\n            if (js_parse_function_decl(s, JS_PARSE_FUNC_VAR,\n                                       JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                       s->token.ptr, s->token.line_num))\n                goto fail;\n            break;\n        }\n        goto hasexpr;\n\n    case TOK_CLASS:\n        if (!(decl_mask & DECL_MASK_OTHER)) {\n            js_parse_error(s, \"class declarations can't appear in single-statement context\");\n            goto fail;\n        }\n        if (js_parse_class(s, FALSE, JS_PARSE_EXPORT_NONE))\n            return -1;\n        break;\n\n    case TOK_DEBUGGER:\n        /* currently no debugger, so just skip the keyword */\n        if (next_token(s))\n            goto fail;\n        if (js_parse_expect_semi(s))\n            goto fail;\n        break;\n        \n    case TOK_ENUM:\n    case TOK_EXPORT:\n    case TOK_EXTENDS:\n        js_unsupported_keyword(s, s->token.u.ident.atom);\n        goto fail;\n\n    default:\n    hasexpr:\n        if (js_parse_expr(s))\n            goto fail;\n        if (s->cur_func->eval_ret_idx >= 0) {\n            /* store the expression value so that it can be returned\n               by eval() */\n            emit_op(s, OP_put_loc);\n            emit_u16(s, s->cur_func->eval_ret_idx);\n        } else {\n            emit_op(s, OP_drop); /* drop the result */\n        }\n        if (js_parse_expect_semi(s))\n            goto fail;\n        break;\n    }\ndone:\n    JS_FreeAtom(ctx, label_name);\n    return 0;\nfail:\n    JS_FreeAtom(ctx, label_name);\n    return -1;\n}\n\n/* 'name' is freed */\nstatic JSModuleDef *js_new_module_def(JSContext *ctx, JSAtom name)\n{\n    JSModuleDef *m;\n    m = js_mallocz(ctx, sizeof(*m));\n    if (!m) {\n        JS_FreeAtom(ctx, name);\n        return NULL;\n    }\n    m->header.ref_count = 1;\n    m->module_name = name;\n    m->module_ns = JS_UNDEFINED;\n    m->func_obj = JS_UNDEFINED;\n    m->eval_exception = JS_UNDEFINED;\n    m->meta_obj = JS_UNDEFINED;\n    list_add_tail(&m->link, &ctx->loaded_modules);\n    return m;\n}\n\nstatic void js_mark_module_def(JSRuntime *rt, JSModuleDef *m,\n                               JS_MarkFunc *mark_func)\n{\n    int i;\n\n    for(i = 0; i < m->export_entries_count; i++) {\n        JSExportEntry *me = &m->export_entries[i];\n        if (me->export_type == JS_EXPORT_TYPE_LOCAL &&\n            me->u.local.var_ref) {\n            mark_func(rt, &me->u.local.var_ref->header);\n        }\n    }\n\n    JS_MarkValue(rt, m->module_ns, mark_func);\n    JS_MarkValue(rt, m->func_obj, mark_func);\n    JS_MarkValue(rt, m->eval_exception, mark_func);\n    JS_MarkValue(rt, m->meta_obj, mark_func);\n}\n\nstatic void js_free_module_def(JSContext *ctx, JSModuleDef *m)\n{\n    int i;\n\n    JS_FreeAtom(ctx, m->module_name);\n\n    for(i = 0; i < m->req_module_entries_count; i++) {\n        JSReqModuleEntry *rme = &m->req_module_entries[i];\n        JS_FreeAtom(ctx, rme->module_name);\n    }\n    js_free(ctx, m->req_module_entries);\n\n    for(i = 0; i < m->export_entries_count; i++) {\n        JSExportEntry *me = &m->export_entries[i];\n        if (me->export_type == JS_EXPORT_TYPE_LOCAL)\n            free_var_ref(ctx->rt, me->u.local.var_ref);\n        JS_FreeAtom(ctx, me->export_name);\n        JS_FreeAtom(ctx, me->local_name);\n    }\n    js_free(ctx, m->export_entries);\n\n    js_free(ctx, m->star_export_entries);\n\n    for(i = 0; i < m->import_entries_count; i++) {\n        JSImportEntry *mi = &m->import_entries[i];\n        JS_FreeAtom(ctx, mi->import_name);\n    }\n    js_free(ctx, m->import_entries);\n\n    JS_FreeValue(ctx, m->module_ns);\n    JS_FreeValue(ctx, m->func_obj);\n    JS_FreeValue(ctx, m->eval_exception);\n    JS_FreeValue(ctx, m->meta_obj);\n    list_del(&m->link);\n    js_free(ctx, m);\n}\n\nstatic int add_req_module_entry(JSContext *ctx, JSModuleDef *m,\n                                JSAtom module_name)\n{\n    JSReqModuleEntry *rme;\n    int i;\n\n    /* no need to add the module request if it is already present */\n    for(i = 0; i < m->req_module_entries_count; i++) {\n        rme = &m->req_module_entries[i];\n        if (rme->module_name == module_name)\n            return i;\n    }\n\n    if (js_resize_array(ctx, (void **)&m->req_module_entries,\n                        sizeof(JSReqModuleEntry),\n                        &m->req_module_entries_size,\n                        m->req_module_entries_count + 1))\n        return -1;\n    rme = &m->req_module_entries[m->req_module_entries_count++];\n    rme->module_name = JS_DupAtom(ctx, module_name);\n    rme->module = NULL;\n    return i;\n}\n\nstatic JSExportEntry *find_export_entry(JSContext *ctx, JSModuleDef *m,\n                                        JSAtom export_name)\n{\n    JSExportEntry *me;\n    int i;\n    for(i = 0; i < m->export_entries_count; i++) {\n        me = &m->export_entries[i];\n        if (me->export_name == export_name)\n            return me;\n    }\n    return NULL;\n}\n\nstatic JSExportEntry *add_export_entry2(JSContext *ctx,\n                                        JSParseState *s, JSModuleDef *m,\n                                       JSAtom local_name, JSAtom export_name,\n                                       JSExportTypeEnum export_type)\n{\n    JSExportEntry *me;\n\n    if (find_export_entry(ctx, m, export_name)) {\n        char buf1[ATOM_GET_STR_BUF_SIZE];\n        if (s) {\n            js_parse_error(s, \"duplicate exported name '%s'\",\n                           JS_AtomGetStr(ctx, buf1, sizeof(buf1), export_name));\n        } else {\n            JS_ThrowSyntaxErrorAtom(ctx, \"duplicate exported name '%s'\", export_name);\n        }\n        return NULL;\n    }\n\n    if (js_resize_array(ctx, (void **)&m->export_entries,\n                        sizeof(JSExportEntry),\n                        &m->export_entries_size,\n                        m->export_entries_count + 1))\n        return NULL;\n    me = &m->export_entries[m->export_entries_count++];\n    memset(me, 0, sizeof(*me));\n    me->local_name = JS_DupAtom(ctx, local_name);\n    me->export_name = JS_DupAtom(ctx, export_name);\n    me->export_type = export_type;\n    return me;\n}\n\nstatic JSExportEntry *add_export_entry(JSParseState *s, JSModuleDef *m,\n                                       JSAtom local_name, JSAtom export_name,\n                                       JSExportTypeEnum export_type)\n{\n    return add_export_entry2(s->ctx, s, m, local_name, export_name,\n                             export_type);\n}\n\nstatic int add_star_export_entry(JSContext *ctx, JSModuleDef *m,\n                                 int req_module_idx)\n{\n    JSStarExportEntry *se;\n\n    if (js_resize_array(ctx, (void **)&m->star_export_entries,\n                        sizeof(JSStarExportEntry),\n                        &m->star_export_entries_size,\n                        m->star_export_entries_count + 1))\n        return -1;\n    se = &m->star_export_entries[m->star_export_entries_count++];\n    se->req_module_idx = req_module_idx;\n    return 0;\n}\n\n/* create a C module */\nJSModuleDef *JS_NewCModule(JSContext *ctx, const char *name_str,\n                           JSModuleInitFunc *func)\n{\n    JSModuleDef *m;\n    JSAtom name;\n    name = JS_NewAtom(ctx, name_str);\n    if (name == JS_ATOM_NULL)\n        return NULL;\n    m = js_new_module_def(ctx, name);\n    m->init_func = func;\n    return m;\n}\n\nint JS_AddModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name)\n{\n    JSExportEntry *me;\n    JSAtom name;\n    name = JS_NewAtom(ctx, export_name);\n    if (name == JS_ATOM_NULL)\n        return -1;\n    me = add_export_entry2(ctx, NULL, m, JS_ATOM_NULL, name,\n                           JS_EXPORT_TYPE_LOCAL);\n    JS_FreeAtom(ctx, name);\n    if (!me)\n        return -1;\n    else\n        return 0;\n}\n\nint JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,\n                       JSValue val)\n{\n    JSExportEntry *me;\n    JSAtom name;\n    name = JS_NewAtom(ctx, export_name);\n    if (name == JS_ATOM_NULL)\n        goto fail;\n    me = find_export_entry(ctx, m, name);\n    JS_FreeAtom(ctx, name);\n    if (!me)\n        goto fail;\n    set_value(ctx, me->u.local.var_ref->pvalue, val);\n    return 0;\n fail:\n    JS_FreeValue(ctx, val);\n    return -1;\n}\n\nvoid JS_SetModuleLoaderFunc(JSRuntime *rt,\n                            JSModuleNormalizeFunc *module_normalize,\n                            JSModuleLoaderFunc *module_loader, void *opaque)\n{\n    rt->module_normalize_func = module_normalize;\n    rt->module_loader_func = module_loader;\n    rt->module_loader_opaque = opaque;\n}\n\n/* default module filename normalizer */\nstatic char *js_default_module_normalize_name(JSContext *ctx,\n                                              const char *base_name,\n                                              const char *name)\n{\n    char *filename, *p;\n    const char *r;\n    int len;\n\n    if (name[0] != '.') {\n        /* if no initial dot, the module name is not modified */\n        return js_strdup(ctx, name);\n    }\n\n    p = strrchr(base_name, '/');\n    if (p)\n        len = p - base_name;\n    else\n        len = 0;\n\n    filename = js_malloc(ctx, len + strlen(name) + 1 + 1);\n    if (!filename)\n        return NULL;\n    memcpy(filename, base_name, len);\n    filename[len] = '\\0';\n\n    /* we only normalize the leading '..' or '.' */\n    r = name;\n    for(;;) {\n        if (r[0] == '.' && r[1] == '/') {\n            r += 2;\n        } else if (r[0] == '.' && r[1] == '.' && r[2] == '/') {\n            /* remove the last path element of filename, except if \".\"\n               or \"..\" */\n            if (filename[0] == '\\0')\n                break;\n            p = strrchr(filename, '/');\n            if (!p)\n                p = filename;\n            else\n                p++;\n            if (!strcmp(p, \".\") || !strcmp(p, \"..\"))\n                break;\n            if (p > filename)\n                p--;\n            *p = '\\0';\n            r += 3;\n        } else {\n            break;\n        }\n    }\n    if (filename[0] != '\\0')\n        strcat(filename, \"/\");\n    strcat(filename, r);\n    //    printf(\"normalize: %s %s -> %s\\n\", base_name, name, filename);\n    return filename;\n}\n\nstatic JSModuleDef *js_find_loaded_module(JSContext *ctx, JSAtom name)\n{\n    struct list_head *el;\n    JSModuleDef *m;\n    \n    /* first look at the loaded modules */\n    list_for_each(el, &ctx->loaded_modules) {\n        m = list_entry(el, JSModuleDef, link);\n        if (m->module_name == name)\n            return m;\n    }\n    return NULL;\n}\n\n/* return NULL in case of exception (e.g. module could not be loaded) */\nstatic JSModuleDef *js_host_resolve_imported_module(JSContext *ctx,\n                                                    JSAtom base_module_name,\n                                                    JSAtom module_name1)\n{\n    JSRuntime *rt = ctx->rt;\n    JSModuleDef *m;\n    char *cname;\n    const char *base_cname, *cname1;\n    JSAtom module_name;\n\n    base_cname = JS_AtomToCString(ctx, base_module_name);\n    if (!base_cname)\n        return NULL;\n    cname1 = JS_AtomToCString(ctx, module_name1);\n    if (!cname1) {\n        JS_FreeCString(ctx, base_cname);\n        return NULL;\n    }\n\n    if (!rt->module_normalize_func) {\n        cname = js_default_module_normalize_name(ctx, base_cname, cname1);\n    } else {\n        cname = rt->module_normalize_func(ctx, base_cname, cname1,\n                                          rt->module_loader_opaque);\n    }\n    JS_FreeCString(ctx, base_cname);\n    JS_FreeCString(ctx, cname1);\n    if (!cname)\n        return NULL;\n\n    module_name = JS_NewAtom(ctx, cname);\n    if (module_name == JS_ATOM_NULL) {\n        js_free(ctx, cname);\n        return NULL;\n    }\n\n    /* first look at the loaded modules */\n    m = js_find_loaded_module(ctx, module_name);\n    if (m) {\n        js_free(ctx, cname);\n        JS_FreeAtom(ctx, module_name);\n        return m;\n    }\n\n    JS_FreeAtom(ctx, module_name);\n\n    /* load the module */\n    if (!rt->module_loader_func) {\n        /* XXX: use a syntax error ? */\n        JS_ThrowReferenceError(ctx, \"could not load module '%s'\",\n                               cname);\n        js_free(ctx, cname);\n        return NULL;\n    }\n\n    m = rt->module_loader_func(ctx, cname, rt->module_loader_opaque);\n    js_free(ctx, cname);\n    return m;\n}\n\ntypedef struct JSResolveEntry {\n    JSModuleDef *module;\n    JSAtom name;\n} JSResolveEntry;\n\ntypedef struct JSResolveState {\n    JSResolveEntry *array;\n    int size;\n    int count;\n} JSResolveState;\n\nstatic int find_resolve_entry(JSResolveState *s,\n                              JSModuleDef *m, JSAtom name)\n{\n    int i;\n    for(i = 0; i < s->count; i++) {\n        JSResolveEntry *re = &s->array[i];\n        if (re->module == m && re->name == name)\n            return i;\n    }\n    return -1;\n}\n\nstatic int add_resolve_entry(JSContext *ctx, JSResolveState *s,\n                             JSModuleDef *m, JSAtom name)\n{\n    JSResolveEntry *re;\n\n    if (js_resize_array(ctx, (void **)&s->array,\n                        sizeof(JSResolveEntry),\n                        &s->size, s->count + 1))\n        return -1;\n    re = &s->array[s->count++];\n    re->module = m;\n    re->name = JS_DupAtom(ctx, name);\n    return 0;\n}\n\ntypedef enum JSResolveResultEnum {\n    JS_RESOLVE_RES_EXCEPTION = -1, /* memory alloc error */\n    JS_RESOLVE_RES_FOUND = 0,\n    JS_RESOLVE_RES_NOT_FOUND,\n    JS_RESOLVE_RES_CIRCULAR,\n    JS_RESOLVE_RES_AMBIGUOUS,\n} JSResolveResultEnum;\n\nstatic JSResolveResultEnum js_resolve_export1(JSContext *ctx,\n                                              JSModuleDef **pmodule,\n                                              JSExportEntry **pme,\n                                              JSModuleDef *m,\n                                              JSAtom export_name,\n                                              JSResolveState *s)\n{\n    JSExportEntry *me;\n\n    *pmodule = NULL;\n    *pme = NULL;\n    if (find_resolve_entry(s, m, export_name) >= 0)\n        return JS_RESOLVE_RES_CIRCULAR;\n    if (add_resolve_entry(ctx, s, m, export_name) < 0)\n        return JS_RESOLVE_RES_EXCEPTION;\n    me = find_export_entry(ctx, m, export_name);\n    if (me) {\n        if (me->export_type == JS_EXPORT_TYPE_LOCAL) {\n            /* local export */\n            *pmodule = m;\n            *pme = me;\n            return JS_RESOLVE_RES_FOUND;\n        } else {\n            /* indirect export */\n            JSModuleDef *m1;\n            m1 = m->req_module_entries[me->u.req_module_idx].module;\n            if (me->local_name == JS_ATOM__star_) {\n                /* export ns from */\n                *pmodule = m;\n                *pme = me;\n                return JS_RESOLVE_RES_FOUND;\n            } else {\n                return js_resolve_export1(ctx, pmodule, pme, m1,\n                                          me->local_name, s);\n            }\n        }\n    } else {\n        if (export_name != JS_ATOM_default) {\n            /* not found in direct or indirect exports: try star exports */\n            int i;\n\n            for(i = 0; i < m->star_export_entries_count; i++) {\n                JSStarExportEntry *se = &m->star_export_entries[i];\n                JSModuleDef *m1, *res_m;\n                JSExportEntry *res_me;\n                JSResolveResultEnum ret;\n\n                m1 = m->req_module_entries[se->req_module_idx].module;\n                ret = js_resolve_export1(ctx, &res_m, &res_me, m1,\n                                         export_name, s);\n                if (ret == JS_RESOLVE_RES_AMBIGUOUS ||\n                    ret == JS_RESOLVE_RES_EXCEPTION) {\n                    return ret;\n                } else if (ret == JS_RESOLVE_RES_FOUND) {\n                    if (*pme != NULL) {\n                        if (*pmodule != res_m ||\n                            res_me->local_name != (*pme)->local_name) {\n                            *pmodule = NULL;\n                            *pme = NULL;\n                            return JS_RESOLVE_RES_AMBIGUOUS;\n                        }\n                    } else {\n                        *pmodule = res_m;\n                        *pme = res_me;\n                    }\n                }\n            }\n            if (*pme != NULL)\n                return JS_RESOLVE_RES_FOUND;\n        }\n        return JS_RESOLVE_RES_NOT_FOUND;\n    }\n}\n\n/* If the return value is JS_RESOLVE_RES_FOUND, return the module\n  (*pmodule) and the corresponding local export entry\n  (*pme). Otherwise return (NULL, NULL) */\nstatic JSResolveResultEnum js_resolve_export(JSContext *ctx,\n                                             JSModuleDef **pmodule,\n                                             JSExportEntry **pme,\n                                             JSModuleDef *m,\n                                             JSAtom export_name)\n{\n    JSResolveState ss, *s = &ss;\n    int i;\n    JSResolveResultEnum ret;\n\n    s->array = NULL;\n    s->size = 0;\n    s->count = 0;\n\n    ret = js_resolve_export1(ctx, pmodule, pme, m, export_name, s);\n\n    for(i = 0; i < s->count; i++)\n        JS_FreeAtom(ctx, s->array[i].name);\n    js_free(ctx, s->array);\n\n    return ret;\n}\n\nstatic void js_resolve_export_throw_error(JSContext *ctx,\n                                          JSResolveResultEnum res,\n                                          JSModuleDef *m, JSAtom export_name)\n{\n    char buf1[ATOM_GET_STR_BUF_SIZE];\n    char buf2[ATOM_GET_STR_BUF_SIZE];\n    switch(res) {\n    case JS_RESOLVE_RES_EXCEPTION:\n        break;\n    default:\n    case JS_RESOLVE_RES_NOT_FOUND:\n        JS_ThrowSyntaxError(ctx, \"Could not find export '%s' in module '%s'\",\n                            JS_AtomGetStr(ctx, buf1, sizeof(buf1), export_name),\n                            JS_AtomGetStr(ctx, buf2, sizeof(buf2), m->module_name));\n        break;\n    case JS_RESOLVE_RES_CIRCULAR:\n        JS_ThrowSyntaxError(ctx, \"circular reference when looking for export '%s' in module '%s'\",\n                            JS_AtomGetStr(ctx, buf1, sizeof(buf1), export_name),\n                            JS_AtomGetStr(ctx, buf2, sizeof(buf2), m->module_name));\n        break;\n    case JS_RESOLVE_RES_AMBIGUOUS:\n        JS_ThrowSyntaxError(ctx, \"export '%s' in module '%s' is ambiguous\",\n                            JS_AtomGetStr(ctx, buf1, sizeof(buf1), export_name),\n                            JS_AtomGetStr(ctx, buf2, sizeof(buf2), m->module_name));\n        break;\n    }\n}\n\n\ntypedef enum {\n    EXPORTED_NAME_AMBIGUOUS,\n    EXPORTED_NAME_NORMAL,\n    EXPORTED_NAME_NS,\n} ExportedNameEntryEnum;\n\ntypedef struct ExportedNameEntry {\n    JSAtom export_name;\n    ExportedNameEntryEnum export_type;\n    union {\n        JSExportEntry *me; /* using when the list is built */\n        JSVarRef *var_ref; /* EXPORTED_NAME_NORMAL */\n        JSModuleDef *module; /* for EXPORTED_NAME_NS */\n    } u;\n} ExportedNameEntry;\n\ntypedef struct GetExportNamesState {\n    JSModuleDef **modules;\n    int modules_size;\n    int modules_count;\n\n    ExportedNameEntry *exported_names;\n    int exported_names_size;\n    int exported_names_count;\n} GetExportNamesState;\n\nstatic int find_exported_name(GetExportNamesState *s, JSAtom name)\n{\n    int i;\n    for(i = 0; i < s->exported_names_count; i++) {\n        if (s->exported_names[i].export_name == name)\n            return i;\n    }\n    return -1;\n}\n\nstatic __exception int get_exported_names(JSContext *ctx,\n                                          GetExportNamesState *s,\n                                          JSModuleDef *m, BOOL from_star)\n{\n    ExportedNameEntry *en;\n    int i, j;\n\n    /* check circular reference */\n    for(i = 0; i < s->modules_count; i++) {\n        if (s->modules[i] == m)\n            return 0;\n    }\n    if (js_resize_array(ctx, (void **)&s->modules, sizeof(s->modules[0]),\n                        &s->modules_size, s->modules_count + 1))\n        return -1;\n    s->modules[s->modules_count++] = m;\n\n    for(i = 0; i < m->export_entries_count; i++) {\n        JSExportEntry *me = &m->export_entries[i];\n        if (from_star && me->export_name == JS_ATOM_default)\n            continue;\n        j = find_exported_name(s, me->export_name);\n        if (j < 0) {\n            if (js_resize_array(ctx, (void **)&s->exported_names, sizeof(s->exported_names[0]),\n                                &s->exported_names_size,\n                                s->exported_names_count + 1))\n                return -1;\n            en = &s->exported_names[s->exported_names_count++];\n            en->export_name = me->export_name;\n            /* avoid a second lookup for simple module exports */\n            if (from_star || me->export_type != JS_EXPORT_TYPE_LOCAL)\n                en->u.me = NULL;\n            else\n                en->u.me = me;\n        } else {\n            en = &s->exported_names[j];\n            en->u.me = NULL;\n        }\n    }\n    for(i = 0; i < m->star_export_entries_count; i++) {\n        JSStarExportEntry *se = &m->star_export_entries[i];\n        JSModuleDef *m1;\n        m1 = m->req_module_entries[se->req_module_idx].module;\n        if (get_exported_names(ctx, s, m1, TRUE))\n            return -1;\n    }\n    return 0;\n}\n\n/* Unfortunately, the spec gives a different behavior from GetOwnProperty ! */\nstatic int js_module_ns_has(JSContext *ctx, JSValueConst obj, JSAtom atom)\n{\n    return (find_own_property1(JS_VALUE_GET_OBJ(obj), atom) != NULL);\n}\n\nstatic const JSClassExoticMethods js_module_ns_exotic_methods = {\n    .has_property = js_module_ns_has,\n};\n\nstatic int exported_names_cmp(const void *p1, const void *p2, void *opaque)\n{\n    JSContext *ctx = opaque;\n    const ExportedNameEntry *me1 = p1;\n    const ExportedNameEntry *me2 = p2;\n    JSValue str1, str2;\n    int ret;\n\n    /* XXX: should avoid allocation memory in atom comparison */\n    str1 = JS_AtomToString(ctx, me1->export_name);\n    str2 = JS_AtomToString(ctx, me2->export_name);\n    if (JS_IsException(str1) || JS_IsException(str2)) {\n        /* XXX: raise an error ? */\n        ret = 0;\n    } else {\n        ret = js_string_compare(ctx, JS_VALUE_GET_STRING(str1),\n                                JS_VALUE_GET_STRING(str2));\n    }\n    JS_FreeValue(ctx, str1);\n    JS_FreeValue(ctx, str2);\n    return ret;\n}\n\nstatic JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m);\n\nstatic int js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,\n                                 void *opaque)\n{\n    JSModuleDef *m = opaque;\n    JSValue val, this_val = JS_MKPTR(JS_TAG_OBJECT, p);\n    \n    val = js_get_module_ns(ctx, m);\n    if (JS_IsException(val))\n        return -1;\n    if (JS_DefinePropertyValue(ctx, this_val, atom, val,\n                               JS_PROP_ENUMERABLE | JS_PROP_WRITABLE) < 0)\n        return -1;\n    return 0;\n}\n\nstatic JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)\n{\n    JSValue obj;\n    JSObject *p;\n    GetExportNamesState s_s, *s = &s_s;\n    int i, ret;\n    JSProperty *pr;\n\n    obj = JS_NewObjectClass(ctx, JS_CLASS_MODULE_NS);\n    if (JS_IsException(obj))\n        return obj;\n    p = JS_VALUE_GET_OBJ(obj);\n\n    memset(s, 0, sizeof(*s));\n    ret = get_exported_names(ctx, s, m, FALSE);\n    js_free(ctx, s->modules);\n    if (ret)\n        goto fail;\n\n    /* Resolve the exported names. The ambiguous exports are removed */\n    for(i = 0; i < s->exported_names_count; i++) {\n        ExportedNameEntry *en = &s->exported_names[i];\n        JSResolveResultEnum res;\n        JSExportEntry *res_me;\n        JSModuleDef *res_m;\n\n        if (en->u.me) {\n            res_me = en->u.me; /* fast case: no resolution needed */\n            res_m = m;\n            res = JS_RESOLVE_RES_FOUND;\n        } else {\n            res = js_resolve_export(ctx, &res_m, &res_me, m,\n                                    en->export_name);\n        }\n        if (res != JS_RESOLVE_RES_FOUND) {\n            if (res != JS_RESOLVE_RES_AMBIGUOUS) {\n                js_resolve_export_throw_error(ctx, res, m, en->export_name);\n                goto fail;\n            }\n            en->export_type = EXPORTED_NAME_AMBIGUOUS;\n        } else {\n            if (res_me->local_name == JS_ATOM__star_) {\n                en->export_type = EXPORTED_NAME_NS;\n                en->u.module = res_m->req_module_entries[res_me->u.req_module_idx].module;\n            } else {\n                en->export_type = EXPORTED_NAME_NORMAL;\n                if (res_me->u.local.var_ref) {\n                    en->u.var_ref = res_me->u.local.var_ref;\n                } else {\n                    JSObject *p1 = JS_VALUE_GET_OBJ(res_m->func_obj);\n                    p1 = JS_VALUE_GET_OBJ(res_m->func_obj);\n                    en->u.var_ref = p1->u.func.var_refs[res_me->u.local.var_idx];\n                }\n            }\n        }\n    }\n\n    /* sort the exported names */\n    rqsort(s->exported_names, s->exported_names_count,\n           sizeof(s->exported_names[0]), exported_names_cmp, ctx);\n\n    for(i = 0; i < s->exported_names_count; i++) {\n        ExportedNameEntry *en = &s->exported_names[i];\n        switch(en->export_type) {\n        case EXPORTED_NAME_NORMAL:\n            {\n                JSVarRef *var_ref = en->u.var_ref;\n                pr = add_property(ctx, p, en->export_name,\n                                  JS_PROP_ENUMERABLE | JS_PROP_WRITABLE |\n                                  JS_PROP_VARREF);\n                if (!pr)\n                    goto fail;\n                var_ref->header.ref_count++;\n                pr->u.var_ref = var_ref;\n            }\n            break;\n        case EXPORTED_NAME_NS:\n            /* the exported namespace must be created on demand */\n            if (JS_DefineAutoInitProperty(ctx, obj,\n                                          en->export_name,\n                                          JS_AUTOINIT_ID_MODULE_NS,\n                                          en->u.module, JS_PROP_ENUMERABLE | JS_PROP_WRITABLE) < 0)\n                goto fail;\n            break;\n        default:\n            break;\n        }\n    }\n\n    js_free(ctx, s->exported_names);\n\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_Symbol_toStringTag,\n                           JS_AtomToString(ctx, JS_ATOM_Module),\n                           0);\n\n    p->extensible = FALSE;\n    return obj;\n fail:\n    js_free(ctx, s->exported_names);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m)\n{\n    if (JS_IsUndefined(m->module_ns)) {\n        JSValue val;\n        val = js_build_module_ns(ctx, m);\n        if (JS_IsException(val))\n            return JS_EXCEPTION;\n        m->module_ns = val;\n    }\n    return JS_DupValue(ctx, m->module_ns);\n}\n\n/* Load all the required modules for module 'm' */\nstatic int js_resolve_module(JSContext *ctx, JSModuleDef *m)\n{\n    int i;\n    JSModuleDef *m1;\n\n    if (m->resolved)\n        return 0;\n#ifdef DUMP_MODULE_RESOLVE\n    {\n        char buf1[ATOM_GET_STR_BUF_SIZE];\n        printf(\"resolving module '%s':\\n\", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));\n    }\n#endif\n    m->resolved = TRUE;\n    /* resolve each requested module */\n    for(i = 0; i < m->req_module_entries_count; i++) {\n        JSReqModuleEntry *rme = &m->req_module_entries[i];\n        m1 = js_host_resolve_imported_module(ctx, m->module_name,\n                                             rme->module_name);\n        if (!m1)\n            return -1;\n        rme->module = m1;\n        /* already done in js_host_resolve_imported_module() except if\n           the module was loaded with JS_EvalBinary() */\n        if (js_resolve_module(ctx, m1) < 0)\n            return -1;\n    }\n    return 0;\n}\n\nstatic JSVarRef *js_create_module_var(JSContext *ctx, BOOL is_lexical)\n{\n    JSVarRef *var_ref;\n    var_ref = js_malloc(ctx, sizeof(JSVarRef));\n    if (!var_ref)\n        return NULL;\n    var_ref->header.ref_count = 1;\n    if (is_lexical)\n        var_ref->value = JS_UNINITIALIZED;\n    else\n        var_ref->value = JS_UNDEFINED;\n    var_ref->pvalue = &var_ref->value;\n    var_ref->is_detached = TRUE;\n    add_gc_object(ctx->rt, &var_ref->header, JS_GC_OBJ_TYPE_VAR_REF);\n    return var_ref;\n}\n\n/* Create the <eval> function associated with the module */\nstatic int js_create_module_bytecode_function(JSContext *ctx, JSModuleDef *m)\n{\n    JSFunctionBytecode *b;\n    int i;\n    JSVarRef **var_refs;\n    JSValue func_obj, bfunc;\n    JSObject *p;\n\n    bfunc = m->func_obj;\n    func_obj = JS_NewObjectProtoClass(ctx, ctx->function_proto,\n                                      JS_CLASS_BYTECODE_FUNCTION);\n\n    if (JS_IsException(func_obj))\n        return -1;\n    b = JS_VALUE_GET_PTR(bfunc);\n\n    p = JS_VALUE_GET_OBJ(func_obj);\n    p->u.func.function_bytecode = b;\n    b->header.ref_count++;\n    p->u.func.home_object = NULL;\n    p->u.func.var_refs = NULL;\n    if (b->closure_var_count) {\n        var_refs = js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count);\n        if (!var_refs)\n            goto fail;\n        p->u.func.var_refs = var_refs;\n\n        /* create the global variables. The other variables are\n           imported from other modules */\n        for(i = 0; i < b->closure_var_count; i++) {\n            JSClosureVar *cv = &b->closure_var[i];\n            JSVarRef *var_ref;\n            if (cv->is_local) {\n                var_ref = js_create_module_var(ctx, cv->is_lexical);\n                if (!var_ref)\n                    goto fail;\n#ifdef DUMP_MODULE_RESOLVE\n                printf(\"local %d: %p\\n\", i, var_ref);\n#endif\n                var_refs[i] = var_ref;\n            }\n        }\n    }\n    m->func_obj = func_obj;\n    JS_FreeValue(ctx, bfunc);\n    return 0;\n fail:\n    JS_FreeValue(ctx, func_obj);\n    return -1;\n}\n\n/* must be done before js_instantiate_module() because of cyclic references */\nstatic int js_create_module_function(JSContext *ctx, JSModuleDef *m)\n{\n    BOOL is_c_module;\n    int i;\n    JSVarRef *var_ref;\n    \n    if (m->func_created)\n        return 0;\n\n    is_c_module = (m->init_func != NULL);\n\n    if (is_c_module) {\n        /* initialize the exported variables */\n        for(i = 0; i < m->export_entries_count; i++) {\n            JSExportEntry *me = &m->export_entries[i];\n            if (me->export_type == JS_EXPORT_TYPE_LOCAL) {\n                var_ref = js_create_module_var(ctx, FALSE);\n                if (!var_ref)\n                    return -1;\n                me->u.local.var_ref = var_ref;\n            }\n        }\n    } else {\n        if (js_create_module_bytecode_function(ctx, m))\n            return -1;\n    }\n    m->func_created = TRUE;\n\n    /* do it on the dependencies */\n    \n    for(i = 0; i < m->req_module_entries_count; i++) {\n        JSReqModuleEntry *rme = &m->req_module_entries[i];\n        if (js_create_module_function(ctx, rme->module) < 0)\n            return -1;\n    }\n\n    return 0;\n}    \n\n    \n/* Prepare a module to be executed by resolving all the imported\n   variables. */\nstatic int js_instantiate_module(JSContext *ctx, JSModuleDef *m)\n{\n    int i;\n    JSImportEntry *mi;\n    JSModuleDef *m1;\n    JSVarRef **var_refs, *var_ref;\n    JSObject *p;\n    BOOL is_c_module;\n\n    if (m->instantiated)\n        return 0;\n    m->instantiated = TRUE;\n\n#ifdef DUMP_MODULE_RESOLVE\n    {\n        char buf1[ATOM_GET_STR_BUF_SIZE];\n        printf(\"start instantiating module '%s':\\n\", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));\n    }\n#endif\n\n    for(i = 0; i < m->req_module_entries_count; i++) {\n        JSReqModuleEntry *rme = &m->req_module_entries[i];\n        if (js_instantiate_module(ctx, rme->module) < 0)\n            goto fail;\n    }\n\n#ifdef DUMP_MODULE_RESOLVE\n    {\n        char buf1[ATOM_GET_STR_BUF_SIZE];\n        printf(\"instantiating module '%s':\\n\", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));\n    }\n#endif\n    /* check the indirect exports */\n    for(i = 0; i < m->export_entries_count; i++) {\n        JSExportEntry *me = &m->export_entries[i];\n        if (me->export_type == JS_EXPORT_TYPE_INDIRECT &&\n            me->local_name != JS_ATOM__star_) {\n            JSResolveResultEnum ret;\n            JSExportEntry *res_me;\n            JSModuleDef *res_m, *m1;\n            m1 = m->req_module_entries[me->u.req_module_idx].module;\n            ret = js_resolve_export(ctx, &res_m, &res_me, m1, me->local_name);\n            if (ret != JS_RESOLVE_RES_FOUND) {\n                js_resolve_export_throw_error(ctx, ret, m, me->export_name);\n                goto fail;\n            }\n        }\n    }\n\n#ifdef DUMP_MODULE_RESOLVE\n    {\n        printf(\"exported bindings:\\n\");\n        for(i = 0; i < m->export_entries_count; i++) {\n            JSExportEntry *me = &m->export_entries[i];\n            printf(\" name=\"); print_atom(ctx, me->export_name);\n            printf(\" local=\"); print_atom(ctx, me->local_name);\n            printf(\" type=%d idx=%d\\n\", me->export_type, me->u.local.var_idx);\n        }\n    }\n#endif\n\n    is_c_module = (m->init_func != NULL);\n\n    if (!is_c_module) {\n        p = JS_VALUE_GET_OBJ(m->func_obj);\n        var_refs = p->u.func.var_refs;\n\n        for(i = 0; i < m->import_entries_count; i++) {\n            mi = &m->import_entries[i];\n#ifdef DUMP_MODULE_RESOLVE\n            printf(\"import var_idx=%d name=\", mi->var_idx);\n            print_atom(ctx, mi->import_name);\n            printf(\": \");\n#endif\n            m1 = m->req_module_entries[mi->req_module_idx].module;\n            if (mi->import_name == JS_ATOM__star_) {\n                JSValue val;\n                /* name space import */\n                val = js_get_module_ns(ctx, m1);\n                if (JS_IsException(val))\n                    goto fail;\n                set_value(ctx, &var_refs[mi->var_idx]->value, val);\n#ifdef DUMP_MODULE_RESOLVE\n                printf(\"namespace\\n\");\n#endif\n            } else {\n                JSResolveResultEnum ret;\n                JSExportEntry *res_me;\n                JSModuleDef *res_m;\n                JSObject *p1;\n\n                ret = js_resolve_export(ctx, &res_m,\n                                        &res_me, m1, mi->import_name);\n                if (ret != JS_RESOLVE_RES_FOUND) {\n                    js_resolve_export_throw_error(ctx, ret, m1, mi->import_name);\n                    goto fail;\n                }\n                if (res_me->local_name == JS_ATOM__star_) {\n                    JSValue val;\n                    JSModuleDef *m2;\n                    /* name space import from */\n                    m2 = res_m->req_module_entries[res_me->u.req_module_idx].module;\n                    val = js_get_module_ns(ctx, m2);\n                    if (JS_IsException(val))\n                        goto fail;\n                    var_ref = js_create_module_var(ctx, TRUE);\n                    if (!var_ref) {\n                        JS_FreeValue(ctx, val);\n                        goto fail;\n                    }\n                    set_value(ctx, &var_ref->value, val);\n                    var_refs[mi->var_idx] = var_ref;\n#ifdef DUMP_MODULE_RESOLVE\n                    printf(\"namespace from\\n\");\n#endif\n                } else {\n                    var_ref = res_me->u.local.var_ref;\n                    if (!var_ref) {\n                        p1 = JS_VALUE_GET_OBJ(res_m->func_obj);\n                        var_ref = p1->u.func.var_refs[res_me->u.local.var_idx];\n                    }\n                    var_ref->header.ref_count++;\n                    var_refs[mi->var_idx] = var_ref;\n#ifdef DUMP_MODULE_RESOLVE\n                    printf(\"local export (var_ref=%p)\\n\", var_ref);\n#endif\n                }\n            }\n        }\n\n        /* keep the exported variables in the module export entries (they\n           are used when the eval function is deleted and cannot be\n           initialized before in case imports are exported) */\n        for(i = 0; i < m->export_entries_count; i++) {\n            JSExportEntry *me = &m->export_entries[i];\n            if (me->export_type == JS_EXPORT_TYPE_LOCAL) {\n                var_ref = var_refs[me->u.local.var_idx];\n                var_ref->header.ref_count++;\n                me->u.local.var_ref = var_ref;\n            }\n        }\n    }\n\n#ifdef DUMP_MODULE_RESOLVE\n    printf(\"done instantiate\\n\");\n#endif\n    return 0;\n fail:\n    return -1;\n}\n\n/* warning: the returned atom is not allocated */\nstatic JSAtom js_get_script_or_module_name(JSContext *ctx)\n{\n    JSStackFrame *sf;\n    JSFunctionBytecode *b;\n    JSObject *p;\n    /* XXX: currently we just use the filename of the englobing\n       function. It does not work for eval(). Need to add a\n       ScriptOrModule info in JSFunctionBytecode */\n    sf = ctx->rt->current_stack_frame;\n    assert(sf != NULL);\n    assert(JS_VALUE_GET_TAG(sf->cur_func) == JS_TAG_OBJECT);\n    p = JS_VALUE_GET_OBJ(sf->cur_func);\n    assert(js_class_has_bytecode(p->class_id));\n    b = p->u.func.function_bytecode;\n    if (!b->has_debug)\n        return JS_ATOM_NULL;\n    return b->debug.filename;\n}\n\nJSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m)\n{\n    return JS_DupAtom(ctx, m->module_name);\n}\n\nJSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m)\n{\n    JSValue obj;\n    /* allocate meta_obj only if requested to save memory */\n    obj = m->meta_obj;\n    if (JS_IsUndefined(obj)) {\n        obj = JS_NewObjectProto(ctx, JS_NULL);\n        if (JS_IsException(obj))\n            return JS_EXCEPTION;\n        m->meta_obj = obj;\n    }\n    return JS_DupValue(ctx, obj);\n}\n\nstatic JSValue js_import_meta(JSContext *ctx)\n{\n    JSAtom filename;\n    JSModuleDef *m;\n    \n    filename = js_get_script_or_module_name(ctx);\n    if (filename == JS_ATOM_NULL)\n        goto fail;\n\n    /* XXX: inefficient, need to add a module or script pointer in\n       JSFunctionBytecode */\n    m = js_find_loaded_module(ctx, filename);\n    if (!m) {\n    fail:\n        JS_ThrowTypeError(ctx, \"import.meta not supported in this context\");\n        return JS_EXCEPTION;\n    }\n    return JS_GetImportMeta(ctx, m);\n}\n\nstatic JSValue js_dynamic_import_job(JSContext *ctx,\n                                     int argc, JSValueConst *argv)\n{\n    JSValueConst *resolving_funcs = argv;\n    JSValueConst basename_val = argv[2];\n    JSValueConst specifier = argv[3];\n    JSModuleDef *m;\n    JSAtom basename = JS_ATOM_NULL, filename;\n    JSValue specifierString, ret, func_obj, err, ns;\n\n    if (!JS_IsString(basename_val)) {\n        JS_ThrowTypeError(ctx, \"no function filename for import()\");\n        goto exception;\n    }\n    basename = JS_ValueToAtom(ctx, basename_val);\n    if (basename == JS_ATOM_NULL)\n        goto exception;\n\n    specifierString = JS_ToString(ctx, specifier);\n    if (JS_IsException(specifierString))\n        goto exception;\n    filename = JS_ValueToAtom(ctx, specifierString);\n    JS_FreeValue(ctx, specifierString);\n    if (filename == JS_ATOM_NULL)\n        goto exception;\n                     \n    m = js_host_resolve_imported_module(ctx, basename, filename);\n    JS_FreeAtom(ctx, filename);\n    if (!m) {\n        goto exception;\n    }\n    \n    if (js_resolve_module(ctx, m) < 0) {\n        js_free_modules(ctx, JS_FREE_MODULE_NOT_RESOLVED);\n        goto exception;\n    }\n\n    /* Evaluate the module code */\n    func_obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m));\n    ret = JS_EvalFunction(ctx, func_obj);\n    if (JS_IsException(ret))\n        goto exception;\n    JS_FreeValue(ctx, ret);\n\n    /* return the module namespace */\n    ns = js_get_module_ns(ctx, m);\n    if (JS_IsException(ret))\n        goto exception;\n\n    ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED,\n                   1, (JSValueConst *)&ns);\n    JS_FreeValue(ctx, ret); /* XXX: what to do if exception ? */\n    JS_FreeValue(ctx, ns);\n    JS_FreeAtom(ctx, basename);\n    return JS_UNDEFINED;\n exception:\n\n    err = JS_GetException(ctx);\n    ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED,\n                   1, (JSValueConst *)&err);\n    JS_FreeValue(ctx, ret); /* XXX: what to do if exception ? */\n    JS_FreeValue(ctx, err);\n    JS_FreeAtom(ctx, basename);\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier)\n{\n    JSAtom basename;\n    JSValue promise, resolving_funcs[2], basename_val;\n    JSValueConst args[4];\n\n    basename = js_get_script_or_module_name(ctx);\n    if (basename == JS_ATOM_NULL)\n        basename_val = JS_NULL;\n    else\n        basename_val = JS_AtomToValue(ctx, basename);\n    if (JS_IsException(basename_val))\n        return basename_val;\n    \n    promise = JS_NewPromiseCapability(ctx, resolving_funcs);\n    if (JS_IsException(promise)) {\n        JS_FreeValue(ctx, basename_val);\n        return promise;\n    }\n\n    args[0] = resolving_funcs[0];\n    args[1] = resolving_funcs[1];\n    args[2] = basename_val;\n    args[3] = specifier;\n    \n    JS_EnqueueJob(ctx, js_dynamic_import_job, 4, args);\n\n    JS_FreeValue(ctx, basename_val);\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    return promise;\n}\n\n/* Run the <eval> function of the module and of all its requested\n   modules. */\nstatic JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)\n{\n    JSModuleDef *m1;\n    int i;\n    JSValue ret_val;\n\n    if (m->eval_mark)\n        return JS_UNDEFINED; /* avoid cycles */\n\n    if (m->evaluated) {\n        /* if the module was already evaluated, rethrow the exception\n           it raised */\n        if (m->eval_has_exception) {\n            return JS_Throw(ctx, JS_DupValue(ctx, m->eval_exception));\n        } else {\n            return JS_UNDEFINED;\n        }\n    }\n\n    m->eval_mark = TRUE;\n\n    for(i = 0; i < m->req_module_entries_count; i++) {\n        JSReqModuleEntry *rme = &m->req_module_entries[i];\n        m1 = rme->module;\n        if (!m1->eval_mark) {\n            ret_val = js_evaluate_module(ctx, m1);\n            if (JS_IsException(ret_val)) {\n                m->eval_mark = FALSE;\n                return ret_val;\n            }\n            JS_FreeValue(ctx, ret_val);\n        }\n    }\n\n    if (m->init_func) {\n        /* C module init */\n        if (m->init_func(ctx, m) < 0)\n            ret_val = JS_EXCEPTION;\n        else\n            ret_val = JS_UNDEFINED;\n    } else {\n        ret_val = JS_CallFree(ctx, m->func_obj, JS_UNDEFINED, 0, NULL);\n        m->func_obj = JS_UNDEFINED;\n    }\n    if (JS_IsException(ret_val)) {\n        /* save the thrown exception value */\n        m->eval_has_exception = TRUE;\n        m->eval_exception = JS_DupValue(ctx, ctx->rt->current_exception);\n    }\n    m->eval_mark = FALSE;\n    m->evaluated = TRUE;\n    return ret_val;\n}\n\nstatic __exception JSAtom js_parse_from_clause(JSParseState *s)\n{\n    JSAtom module_name;\n    if (!token_is_pseudo_keyword(s, JS_ATOM_from)) {\n        js_parse_error(s, \"from clause expected\");\n        return JS_ATOM_NULL;\n    }\n    if (next_token(s))\n        return JS_ATOM_NULL;\n    if (s->token.val != TOK_STRING) {\n        js_parse_error(s, \"string expected\");\n        return JS_ATOM_NULL;\n    }\n    module_name = JS_ValueToAtom(s->ctx, s->token.u.str.str);\n    if (module_name == JS_ATOM_NULL)\n        return JS_ATOM_NULL;\n    if (next_token(s)) {\n        JS_FreeAtom(s->ctx, module_name);\n        return JS_ATOM_NULL;\n    }\n    return module_name;\n}\n\nstatic __exception int js_parse_export(JSParseState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSModuleDef *m = s->cur_func->module;\n    JSAtom local_name, export_name;\n    int first_export, idx, i, tok;\n    JSAtom module_name;\n    JSExportEntry *me;\n\n    if (next_token(s))\n        return -1;\n\n    tok = s->token.val;\n    if (tok == TOK_CLASS) {\n        return js_parse_class(s, FALSE, JS_PARSE_EXPORT_NAMED);\n    } else if (tok == TOK_FUNCTION ||\n               (token_is_pseudo_keyword(s, JS_ATOM_async) &&\n                peek_token(s, TRUE) == TOK_FUNCTION)) {\n        return js_parse_function_decl2(s, JS_PARSE_FUNC_STATEMENT,\n                                       JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                       s->token.ptr, s->token.line_num,\n                                       JS_PARSE_EXPORT_NAMED, NULL);\n    }\n\n    if (next_token(s))\n        return -1;\n\n    switch(tok) {\n    case '{':\n        first_export = m->export_entries_count;\n        while (s->token.val != '}') {\n            if (!token_is_ident(s->token.val)) {\n                js_parse_error(s, \"identifier expected\");\n                return -1;\n            }\n            local_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            export_name = JS_ATOM_NULL;\n            if (next_token(s))\n                goto fail;\n            if (token_is_pseudo_keyword(s, JS_ATOM_as)) {\n                if (next_token(s))\n                    goto fail;\n                if (!token_is_ident(s->token.val)) {\n                    js_parse_error(s, \"identifier expected\");\n                    goto fail;\n                }\n                export_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n                if (next_token(s)) {\n                fail:\n                    JS_FreeAtom(ctx, local_name);\n                fail1:\n                    JS_FreeAtom(ctx, export_name);\n                    return -1;\n                }\n            } else {\n                export_name = JS_DupAtom(ctx, local_name);\n            }\n            me = add_export_entry(s, m, local_name, export_name,\n                                  JS_EXPORT_TYPE_LOCAL);\n            JS_FreeAtom(ctx, local_name);\n            JS_FreeAtom(ctx, export_name);\n            if (!me)\n                return -1;\n            if (s->token.val != ',')\n                break;\n            if (next_token(s))\n                return -1;\n        }\n        if (js_parse_expect(s, '}'))\n            return -1;\n        if (token_is_pseudo_keyword(s, JS_ATOM_from)) {\n            module_name = js_parse_from_clause(s);\n            if (module_name == JS_ATOM_NULL)\n                return -1;\n            idx = add_req_module_entry(ctx, m, module_name);\n            JS_FreeAtom(ctx, module_name);\n            if (idx < 0)\n                return -1;\n            for(i = first_export; i < m->export_entries_count; i++) {\n                me = &m->export_entries[i];\n                me->export_type = JS_EXPORT_TYPE_INDIRECT;\n                me->u.req_module_idx = idx;\n            }\n        }\n        break;\n    case '*':\n        if (token_is_pseudo_keyword(s, JS_ATOM_as)) {\n            /* export ns from */\n            if (next_token(s))\n                return -1;\n            if (!token_is_ident(s->token.val)) {\n                js_parse_error(s, \"identifier expected\");\n                return -1;\n            }\n            export_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            if (next_token(s))\n                goto fail1;\n            module_name = js_parse_from_clause(s);\n            if (module_name == JS_ATOM_NULL)\n                goto fail1;\n            idx = add_req_module_entry(ctx, m, module_name);\n            JS_FreeAtom(ctx, module_name);\n            if (idx < 0)\n                goto fail1;\n            me = add_export_entry(s, m, JS_ATOM__star_, export_name,\n                                  JS_EXPORT_TYPE_INDIRECT);\n            JS_FreeAtom(ctx, export_name);\n            if (!me)\n                return -1;\n            me->u.req_module_idx = idx;\n        } else {\n            module_name = js_parse_from_clause(s);\n            if (module_name == JS_ATOM_NULL)\n                return -1;\n            idx = add_req_module_entry(ctx, m, module_name);\n            JS_FreeAtom(ctx, module_name);\n            if (idx < 0)\n                return -1;\n            if (add_star_export_entry(ctx, m, idx) < 0)\n                return -1;\n        }\n        break;\n    case TOK_DEFAULT:\n        if (s->token.val == TOK_CLASS) {\n            return js_parse_class(s, FALSE, JS_PARSE_EXPORT_DEFAULT);\n        } else if (s->token.val == TOK_FUNCTION ||\n                   (token_is_pseudo_keyword(s, JS_ATOM_async) &&\n                    peek_token(s, TRUE) == TOK_FUNCTION)) {\n            return js_parse_function_decl2(s, JS_PARSE_FUNC_STATEMENT,\n                                           JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                           s->token.ptr, s->token.line_num,\n                                           JS_PARSE_EXPORT_DEFAULT, NULL);\n        } else {\n            if (js_parse_assign_expr(s, TRUE))\n                return -1;\n        }\n        /* set the name of anonymous functions */\n        set_object_name(s, JS_ATOM_default);\n\n        /* store the value in the _default_ global variable and export\n           it */\n        local_name = JS_ATOM__default_;\n        if (define_var(s, s->cur_func, local_name, JS_VAR_DEF_LET) < 0)\n            return -1;\n        emit_op(s, OP_scope_put_var_init);\n        emit_atom(s, local_name);\n        emit_u16(s, 0);\n\n        if (!add_export_entry(s, m, local_name, JS_ATOM_default,\n                              JS_EXPORT_TYPE_LOCAL))\n            return -1;\n        break;\n    case TOK_VAR:\n    case TOK_LET:\n    case TOK_CONST:\n        return js_parse_var(s, TRUE, tok, TRUE);\n    default:\n        return js_parse_error(s, \"invalid export syntax\");\n    }\n    return js_parse_expect_semi(s);\n}\n\nstatic int add_closure_var(JSContext *ctx, JSFunctionDef *s,\n                           BOOL is_local, BOOL is_arg,\n                           int var_idx, JSAtom var_name,\n                           BOOL is_const, BOOL is_lexical,\n                           JSVarKindEnum var_kind);\n\nstatic int add_import(JSParseState *s, JSModuleDef *m,\n                      JSAtom local_name, JSAtom import_name)\n{\n    JSContext *ctx = s->ctx;\n    int i, var_idx;\n    JSImportEntry *mi;\n    BOOL is_local;\n\n    if (local_name == JS_ATOM_arguments || local_name == JS_ATOM_eval)\n        return js_parse_error(s, \"invalid import binding\");\n\n    if (local_name != JS_ATOM_default) {\n        for (i = 0; i < s->cur_func->closure_var_count; i++) {\n            if (s->cur_func->closure_var[i].var_name == local_name)\n                return js_parse_error(s, \"duplicate import binding\");\n        }\n    }\n\n    is_local = (import_name == JS_ATOM__star_);\n    var_idx = add_closure_var(ctx, s->cur_func, is_local, FALSE,\n                              m->import_entries_count,\n                              local_name, TRUE, TRUE, FALSE);\n    if (var_idx < 0)\n        return -1;\n    if (js_resize_array(ctx, (void **)&m->import_entries,\n                        sizeof(JSImportEntry),\n                        &m->import_entries_size,\n                        m->import_entries_count + 1))\n        return -1;\n    mi = &m->import_entries[m->import_entries_count++];\n    mi->import_name = JS_DupAtom(ctx, import_name);\n    mi->var_idx = var_idx;\n    return 0;\n}\n\nstatic __exception int js_parse_import(JSParseState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSModuleDef *m = s->cur_func->module;\n    JSAtom local_name, import_name, module_name;\n    int first_import, i, idx;\n\n    if (next_token(s))\n        return -1;\n\n    first_import = m->import_entries_count;\n    if (s->token.val == TOK_STRING) {\n        module_name = JS_ValueToAtom(ctx, s->token.u.str.str);\n        if (module_name == JS_ATOM_NULL)\n            return -1;\n        if (next_token(s)) {\n            JS_FreeAtom(ctx, module_name);\n            return -1;\n        }\n    } else {\n        if (s->token.val == TOK_IDENT) {\n            if (s->token.u.ident.is_reserved) {\n                return js_parse_error_reserved_identifier(s);\n            }\n            /* \"default\" import */\n            local_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            import_name = JS_ATOM_default;\n            if (next_token(s))\n                goto fail;\n            if (add_import(s, m, local_name, import_name))\n                goto fail;\n            JS_FreeAtom(ctx, local_name);\n\n            if (s->token.val != ',')\n                goto end_import_clause;\n            if (next_token(s))\n                return -1;\n        }\n\n        if (s->token.val == '*') {\n            /* name space import */\n            if (next_token(s))\n                return -1;\n            if (!token_is_pseudo_keyword(s, JS_ATOM_as))\n                return js_parse_error(s, \"expecting 'as'\");\n            if (next_token(s))\n                return -1;\n            if (!token_is_ident(s->token.val)) {\n                js_parse_error(s, \"identifier expected\");\n                return -1;\n            }\n            local_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            import_name = JS_ATOM__star_;\n            if (next_token(s))\n                goto fail;\n            if (add_import(s, m, local_name, import_name))\n                goto fail;\n            JS_FreeAtom(ctx, local_name);\n        } else if (s->token.val == '{') {\n            if (next_token(s))\n                return -1;\n\n            while (s->token.val != '}') {\n                if (!token_is_ident(s->token.val)) {\n                    js_parse_error(s, \"identifier expected\");\n                    return -1;\n                }\n                import_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n                local_name = JS_ATOM_NULL;\n                if (next_token(s))\n                    goto fail;\n                if (token_is_pseudo_keyword(s, JS_ATOM_as)) {\n                    if (next_token(s))\n                        goto fail;\n                    if (!token_is_ident(s->token.val)) {\n                        js_parse_error(s, \"identifier expected\");\n                        goto fail;\n                    }\n                    local_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n                    if (next_token(s)) {\n                    fail:\n                        JS_FreeAtom(ctx, local_name);\n                        JS_FreeAtom(ctx, import_name);\n                        return -1;\n                    }\n                } else {\n                    local_name = JS_DupAtom(ctx, import_name);\n                }\n                if (add_import(s, m, local_name, import_name))\n                    goto fail;\n                JS_FreeAtom(ctx, local_name);\n                JS_FreeAtom(ctx, import_name);\n                if (s->token.val != ',')\n                    break;\n                if (next_token(s))\n                    return -1;\n            }\n            if (js_parse_expect(s, '}'))\n                return -1;\n        }\n    end_import_clause:\n        module_name = js_parse_from_clause(s);\n        if (module_name == JS_ATOM_NULL)\n            return -1;\n    }\n    idx = add_req_module_entry(ctx, m, module_name);\n    JS_FreeAtom(ctx, module_name);\n    if (idx < 0)\n        return -1;\n    for(i = first_import; i < m->import_entries_count; i++)\n        m->import_entries[i].req_module_idx = idx;\n\n    return js_parse_expect_semi(s);\n}\n\nstatic __exception int js_parse_source_element(JSParseState *s)\n{\n    JSFunctionDef *fd = s->cur_func;\n    int tok;\n    \n    if (s->token.val == TOK_FUNCTION ||\n        (token_is_pseudo_keyword(s, JS_ATOM_async) &&\n         peek_token(s, TRUE) == TOK_FUNCTION)) {\n        if (js_parse_function_decl(s, JS_PARSE_FUNC_STATEMENT,\n                                   JS_FUNC_NORMAL, JS_ATOM_NULL,\n                                   s->token.ptr, s->token.line_num))\n            return -1;\n    } else if (s->token.val == TOK_EXPORT && fd->module) {\n        if (js_parse_export(s))\n            return -1;\n    } else if (s->token.val == TOK_IMPORT && fd->module &&\n               ((tok = peek_token(s, FALSE)) != '(' && tok != '.'))  {\n        /* the peek_token is needed to avoid confusion with ImportCall\n           (dynamic import) or import.meta */\n        if (js_parse_import(s))\n            return -1;\n    } else {\n        if (js_parse_statement_or_decl(s, DECL_MASK_ALL))\n            return -1;\n    }\n    return 0;\n}\n\nstatic JSFunctionDef *js_new_function_def(JSContext *ctx,\n                                          JSFunctionDef *parent,\n                                          BOOL is_eval,\n                                          BOOL is_func_expr,\n                                          const char *filename, int line_num)\n{\n    JSFunctionDef *fd;\n\n    fd = js_mallocz(ctx, sizeof(*fd));\n    if (!fd)\n        return NULL;\n\n    fd->ctx = ctx;\n    init_list_head(&fd->child_list);\n\n    /* insert in parent list */\n    fd->parent = parent;\n    fd->parent_cpool_idx = -1;\n    if (parent) {\n        list_add_tail(&fd->link, &parent->child_list);\n        fd->js_mode = parent->js_mode;\n        fd->parent_scope_level = parent->scope_level;\n    }\n\n    fd->is_eval = is_eval;\n    fd->is_func_expr = is_func_expr;\n    js_dbuf_init(ctx, &fd->byte_code);\n    fd->last_opcode_pos = -1;\n    fd->func_name = JS_ATOM_NULL;\n    fd->var_object_idx = -1;\n    fd->arguments_var_idx = -1;\n    fd->func_var_idx = -1;\n    fd->eval_ret_idx = -1;\n    fd->this_var_idx = -1;\n    fd->new_target_var_idx = -1;\n    fd->this_active_func_var_idx = -1;\n    fd->home_object_var_idx = -1;\n\n    /* XXX: should distinguish arg, var and var object and body scopes */\n    fd->scope_level = 0;  /* 0: var/arg scope, 1:body scope */\n    fd->scope_first = -1;\n    fd->scopes = fd->def_scope_array;\n    fd->scope_size = countof(fd->def_scope_array);\n    fd->scope_count = 1;\n    fd->scopes[0].first = -1;\n    fd->scopes[0].parent = -1;\n\n    fd->filename = JS_NewAtom(ctx, filename);\n    fd->line_num = line_num;\n\n    js_dbuf_init(ctx, &fd->pc2line);\n    //fd->pc2line_last_line_num = line_num;\n    //fd->pc2line_last_pc = 0;\n    fd->last_opcode_line_num = line_num;\n\n    return fd;\n}\n\nstatic void free_bytecode_atoms(JSRuntime *rt,\n                                const uint8_t *bc_buf, int bc_len,\n                                BOOL use_short_opcodes)\n{\n    int pos, len, op;\n    JSAtom atom;\n    const JSOpCode *oi;\n    \n    pos = 0;\n    while (pos < bc_len) {\n        op = bc_buf[pos];\n        if (use_short_opcodes)\n            oi = &short_opcode_info(op);\n        else\n            oi = &opcode_info[op];\n            \n        len = oi->size;\n        switch(oi->fmt) {\n        case OP_FMT_atom:\n        case OP_FMT_atom_u8:\n        case OP_FMT_atom_u16:\n        case OP_FMT_atom_label_u8:\n        case OP_FMT_atom_label_u16:\n            atom = get_u32(bc_buf + pos + 1);\n            JS_FreeAtomRT(rt, atom);\n            break;\n        default:\n            break;\n        }\n        pos += len;\n    }\n}\n\nstatic void js_free_function_def(JSContext *ctx, JSFunctionDef *fd)\n{\n    int i;\n    struct list_head *el, *el1;\n\n    /* free the child functions */\n    list_for_each_safe(el, el1, &fd->child_list) {\n        JSFunctionDef *fd1;\n        fd1 = list_entry(el, JSFunctionDef, link);\n        js_free_function_def(ctx, fd1);\n    }\n\n    free_bytecode_atoms(ctx->rt, fd->byte_code.buf, fd->byte_code.size,\n                        fd->use_short_opcodes);\n    dbuf_free(&fd->byte_code);\n    js_free(ctx, fd->jump_slots);\n    js_free(ctx, fd->label_slots);\n    js_free(ctx, fd->line_number_slots);\n\n    for(i = 0; i < fd->cpool_count; i++) {\n        JS_FreeValue(ctx, fd->cpool[i]);\n    }\n    js_free(ctx, fd->cpool);\n\n    JS_FreeAtom(ctx, fd->func_name);\n\n    for(i = 0; i < fd->var_count; i++) {\n        JS_FreeAtom(ctx, fd->vars[i].var_name);\n    }\n    js_free(ctx, fd->vars);\n    for(i = 0; i < fd->arg_count; i++) {\n        JS_FreeAtom(ctx, fd->args[i].var_name);\n    }\n    js_free(ctx, fd->args);\n\n    for(i = 0; i < fd->hoisted_def_count; i++) {\n        JS_FreeAtom(ctx, fd->hoisted_def[i].var_name);\n    }\n    js_free(ctx, fd->hoisted_def);\n\n    for(i = 0; i < fd->closure_var_count; i++) {\n        JSClosureVar *cv = &fd->closure_var[i];\n        JS_FreeAtom(ctx, cv->var_name);\n    }\n    js_free(ctx, fd->closure_var);\n\n    if (fd->scopes != fd->def_scope_array)\n        js_free(ctx, fd->scopes);\n\n    JS_FreeAtom(ctx, fd->filename);\n    dbuf_free(&fd->pc2line);\n\n    js_free(ctx, fd->source);\n\n    if (fd->parent) {\n        /* remove in parent list */\n        list_del(&fd->link);\n    }\n    js_free(ctx, fd);\n}\n\n#ifdef DUMP_BYTECODE\nstatic const char *skip_lines(const char *p, int n) {\n    while (n-- > 0 && *p) {\n        while (*p && *p++ != '\\n')\n            continue;\n    }\n    return p;\n}\n\nstatic void print_lines(const char *source, int line, int line1) {\n    const char *s = source;\n    const char *p = skip_lines(s, line);\n    if (*p) {\n        while (line++ < line1) {\n            p = skip_lines(s = p, 1);\n            printf(\";; %.*s\", (int)(p - s), s);\n            if (!*p) {\n                if (p[-1] != '\\n')\n                    printf(\"\\n\");\n                break;\n            }\n        }\n    }\n}\n\nstatic void dump_byte_code(JSContext *ctx, int pass,\n                           const uint8_t *tab, int len,\n                           const JSVarDef *args, int arg_count,\n                           const JSVarDef *vars, int var_count,\n                           const JSClosureVar *closure_var, int closure_var_count,\n                           const JSValue *cpool, uint32_t cpool_count,\n                           const char *source, int line_num,\n                           const LabelSlot *label_slots, JSFunctionBytecode *b)\n{\n    const JSOpCode *oi;\n    int pos, pos_next, op, size, idx, addr, line, line1, in_source;\n    uint8_t *bits = js_mallocz(ctx, len * sizeof(*bits));\n    BOOL use_short_opcodes = (b != NULL);\n\n    /* scan for jump targets */\n    for (pos = 0; pos < len; pos = pos_next) {\n        op = tab[pos];\n        if (use_short_opcodes)\n            oi = &short_opcode_info(op);\n        else\n            oi = &opcode_info[op];\n        pos_next = pos + oi->size;\n        if (op < OP_COUNT) {\n            switch (oi->fmt) {\n#if SHORT_OPCODES\n            case OP_FMT_label8:\n                pos++;\n                addr = (int8_t)tab[pos];\n                goto has_addr;\n            case OP_FMT_label16:\n                pos++;\n                addr = (int16_t)get_u16(tab + pos);\n                goto has_addr;\n#endif\n            case OP_FMT_atom_label_u8:\n            case OP_FMT_atom_label_u16:\n                pos += 4;\n                /* fall thru */\n            case OP_FMT_label:\n            case OP_FMT_label_u16:\n                pos++;\n                addr = get_u32(tab + pos);\n                goto has_addr;\n            has_addr:\n                if (pass == 1)\n                    addr = label_slots[addr].pos;\n                if (pass == 2)\n                    addr = label_slots[addr].pos2;\n                if (pass == 3)\n                    addr += pos;\n                if (addr >= 0 && addr < len)\n                    bits[addr] |= 1;\n                break;\n            }\n        }\n    }\n    in_source = 0;\n    if (source) {\n        /* Always print first line: needed if single line */\n        print_lines(source, 0, 1);\n        in_source = 1;\n    }\n    line1 = line = 1;\n    pos = 0;\n    while (pos < len) {\n        op = tab[pos];\n        if (source) {\n            if (b) {\n                line1 = find_line_num(ctx, b, pos) - line_num + 1;\n            } else if (op == OP_line_num) {\n                line1 = get_u32(tab + pos + 1) - line_num + 1;\n            }\n            if (line1 > line) {\n                if (!in_source)\n                    printf(\"\\n\");\n                in_source = 1;\n                print_lines(source, line, line1);\n                line = line1;\n                //bits[pos] |= 2;\n            }\n        }\n        if (in_source)\n            printf(\"\\n\");\n        in_source = 0;\n        if (op >= OP_COUNT) {\n            printf(\"invalid opcode (0x%02x)\\n\", op);\n            pos++;\n            continue;\n        }\n        if (use_short_opcodes)\n            oi = &short_opcode_info(op);\n        else\n            oi = &opcode_info[op];\n        size = oi->size;\n        if (pos + size > len) {\n            printf(\"truncated opcode (0x%02x)\\n\", op);\n            break;\n        }\n#if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 16)\n        {\n            int i, x, x0;\n            x = x0 = printf(\"%5d \", pos);\n            for (i = 0; i < size; i++) {\n                if (i == 6) {\n                    printf(\"\\n%*s\", x = x0, \"\");\n                }\n                x += printf(\" %02X\", tab[pos + i]);\n            }\n            printf(\"%*s\", x0 + 20 - x, \"\");\n        }\n#endif\n        if (bits[pos]) {\n            printf(\"%5d:  \", pos);\n        } else {\n            printf(\"        \");\n        }\n        printf(\"%s\", oi->name);\n        pos++;\n        switch(oi->fmt) {\n        case OP_FMT_none_int:\n            printf(\" %d\", op - OP_push_0);\n            break;\n        case OP_FMT_npopx:\n            printf(\" %d\", op - OP_call0);\n            break;\n        case OP_FMT_u8:\n            printf(\" %u\", get_u8(tab + pos));\n            break;\n        case OP_FMT_i8:\n            printf(\" %d\", get_i8(tab + pos));\n            break;\n        case OP_FMT_u16:\n        case OP_FMT_npop:\n            printf(\" %u\", get_u16(tab + pos));\n            break;\n        case OP_FMT_npop_u16:\n            printf(\" %u,%u\", get_u16(tab + pos), get_u16(tab + pos + 2));\n            break;\n        case OP_FMT_i16:\n            printf(\" %d\", get_i16(tab + pos));\n            break;\n        case OP_FMT_i32:\n            printf(\" %d\", get_i32(tab + pos));\n            break;\n        case OP_FMT_u32:\n            printf(\" %u\", get_u32(tab + pos));\n            break;\n#if SHORT_OPCODES\n        case OP_FMT_label8:\n            addr = get_i8(tab + pos);\n            goto has_addr1;\n        case OP_FMT_label16:\n            addr = get_i16(tab + pos);\n            goto has_addr1;\n#endif\n        case OP_FMT_label:\n            addr = get_u32(tab + pos);\n            goto has_addr1;\n        has_addr1:\n            if (pass == 1)\n                printf(\" %u:%u\", addr, label_slots[addr].pos);\n            if (pass == 2)\n                printf(\" %u:%u\", addr, label_slots[addr].pos2);\n            if (pass == 3)\n                printf(\" %u\", addr + pos);\n            break;\n        case OP_FMT_label_u16:\n            addr = get_u32(tab + pos);\n            if (pass == 1)\n                printf(\" %u:%u\", addr, label_slots[addr].pos);\n            if (pass == 2)\n                printf(\" %u:%u\", addr, label_slots[addr].pos2);\n            if (pass == 3)\n                printf(\" %u\", addr + pos);\n            printf(\",%u\", get_u16(tab + pos + 4));\n            break;\n#if SHORT_OPCODES\n        case OP_FMT_const8:\n            idx = get_u8(tab + pos);\n            goto has_pool_idx;\n#endif\n        case OP_FMT_const:\n            idx = get_u32(tab + pos);\n            goto has_pool_idx;\n        has_pool_idx:\n            printf(\" %u: \", idx);\n            if (idx < cpool_count) {\n                JS_DumpValue(ctx, cpool[idx]);\n            }\n            break;\n        case OP_FMT_atom:\n            printf(\" \");\n            print_atom(ctx, get_u32(tab + pos));\n            break;\n        case OP_FMT_atom_u8:\n            printf(\" \");\n            print_atom(ctx, get_u32(tab + pos));\n            printf(\",%d\", get_u8(tab + pos + 4));\n            break;\n        case OP_FMT_atom_u16:\n            printf(\" \");\n            print_atom(ctx, get_u32(tab + pos));\n            printf(\",%d\", get_u16(tab + pos + 4));\n            break;\n        case OP_FMT_atom_label_u8:\n        case OP_FMT_atom_label_u16:\n            printf(\" \");\n            print_atom(ctx, get_u32(tab + pos));\n            addr = get_u32(tab + pos + 4);\n            if (pass == 1)\n                printf(\",%u:%u\", addr, label_slots[addr].pos);\n            if (pass == 2)\n                printf(\",%u:%u\", addr, label_slots[addr].pos2);\n            if (pass == 3)\n                printf(\",%u\", addr + pos + 4);\n            if (oi->fmt == OP_FMT_atom_label_u8)\n                printf(\",%u\", get_u8(tab + pos + 8));\n            else\n                printf(\",%u\", get_u16(tab + pos + 8));\n            break;\n        case OP_FMT_none_loc:\n            idx = (op - OP_get_loc0) % 4;\n            goto has_loc;\n        case OP_FMT_loc8:\n            idx = get_u8(tab + pos);\n            goto has_loc;\n        case OP_FMT_loc:\n            idx = get_u16(tab + pos);\n        has_loc:\n            printf(\" %d: \", idx);\n            if (idx < var_count) {\n                print_atom(ctx, vars[idx].var_name);\n            }\n            break;\n        case OP_FMT_none_arg:\n            idx = (op - OP_get_arg0) % 4;\n            goto has_arg;\n        case OP_FMT_arg:\n            idx = get_u16(tab + pos);\n        has_arg:\n            printf(\" %d: \", idx);\n            if (idx < arg_count) {\n                print_atom(ctx, args[idx].var_name);\n            }\n            break;\n        case OP_FMT_none_var_ref:\n            idx = (op - OP_get_var_ref0) % 4;\n            goto has_var_ref;\n        case OP_FMT_var_ref:\n            idx = get_u16(tab + pos);\n        has_var_ref:\n            printf(\" %d: \", idx);\n            if (idx < closure_var_count) {\n                print_atom(ctx, closure_var[idx].var_name);\n            }\n            break;\n        default:\n            break;\n        }\n        printf(\"\\n\");\n        pos += oi->size - 1;\n    }\n    if (source) {\n        if (!in_source)\n            printf(\"\\n\");\n        print_lines(source, line, INT32_MAX);\n    }\n    js_free(ctx, bits);\n}\n\nstatic __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *buf, int len,\n                                                 int line_num)\n{\n    const uint8_t *p_end, *p_next, *p;\n    int pc, v;\n    unsigned int op;\n\n    if (len <= 0)\n        return;\n\n    printf(\"%5s %5s\\n\", \"PC\", \"LINE\");\n\n    p = buf;\n    p_end = buf + len;\n    pc = 0;\n    while (p < p_end) {\n        op = *p++;\n        if (op == 0) {\n            v = unicode_from_utf8(p, p_end - p, &p_next);\n            if (v < 0)\n                goto fail;\n            pc += v;\n            p = p_next;\n            v = unicode_from_utf8(p, p_end - p, &p_next);\n            if (v < 0) {\n            fail:\n                printf(\"invalid pc2line encode pos=%d\\n\", (int)(p - buf));\n                return;\n            }\n            if (!(v & 1)) {\n                v = v >> 1;\n            } else {\n                v = -(v >> 1) - 1;\n            }\n            line_num += v;\n            p = p_next;\n        } else {\n            op -= PC2LINE_OP_FIRST;\n            pc += (op / PC2LINE_RANGE);\n            line_num += (op % PC2LINE_RANGE) + PC2LINE_BASE;\n        }\n        printf(\"%5d %5d\\n\", pc, line_num);\n    }\n}\n\nstatic __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionBytecode *b)\n{\n    int i;\n    char atom_buf[ATOM_GET_STR_BUF_SIZE];\n    const char *str;\n\n    if (b->has_debug && b->debug.filename != JS_ATOM_NULL) {\n        str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), b->debug.filename);\n        printf(\"%s:%d: \", str, b->debug.line_num);\n    }\n\n    str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), b->func_name);\n    printf(\"function: %s%s\\n\", &\"*\"[b->func_kind != JS_FUNC_GENERATOR], str);\n    if (b->js_mode) {\n        printf(\"  mode:\");\n        if (b->js_mode & JS_MODE_STRICT)\n            printf(\" strict\");\n#ifdef CONFIG_BIGNUM\n        if (b->js_mode & JS_MODE_MATH)\n            printf(\" math\");\n#endif\n        printf(\"\\n\");\n    }\n    if (b->arg_count && b->vardefs) {\n        printf(\"  args:\");\n        for(i = 0; i < b->arg_count; i++) {\n            printf(\" %s\", JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf),\n                                        b->vardefs[i].var_name));\n        }\n        printf(\"\\n\");\n    }\n    if (b->var_count && b->vardefs) {\n        printf(\"  locals:\\n\");\n        for(i = 0; i < b->var_count; i++) {\n            JSVarDef *vd = &b->vardefs[b->arg_count + i];\n            printf(\"%5d: %s %s\", i,\n                   vd->var_kind == JS_VAR_CATCH ? \"catch\" :\n                   (vd->var_kind == JS_VAR_FUNCTION_DECL ||\n                    vd->var_kind == JS_VAR_NEW_FUNCTION_DECL) ? \"function\" :\n                   vd->is_const ? \"const\" :\n                   vd->is_lexical ? \"let\" : \"var\",\n                   JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), vd->var_name));\n            if (vd->scope_level)\n                printf(\" [level:%d next:%d]\", vd->scope_level, vd->scope_next);\n            printf(\"\\n\");\n        }\n    }\n    if (b->closure_var_count) {\n        printf(\"  closure vars:\\n\");\n        for(i = 0; i < b->closure_var_count; i++) {\n            JSClosureVar *cv = &b->closure_var[i];\n            printf(\"%5d: %s %s:%s%d %s\\n\", i,\n                   JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), cv->var_name),\n                   cv->is_local ? \"local\" : \"parent\",\n                   cv->is_arg ? \"arg\" : \"loc\", cv->var_idx,\n                   cv->is_const ? \"const\" :\n                   cv->is_lexical ? \"let\" : \"var\");\n        }\n    }\n    printf(\"  stack_size: %d\\n\", b->stack_size);\n    printf(\"  opcodes:\\n\");\n    dump_byte_code(ctx, 3, b->byte_code_buf, b->byte_code_len,\n                   b->vardefs, b->arg_count,\n                   b->vardefs ? b->vardefs + b->arg_count : NULL, b->var_count,\n                   b->closure_var, b->closure_var_count,\n                   b->cpool, b->cpool_count,\n                   b->has_debug ? b->debug.source : NULL,\n                   b->has_debug ? b->debug.line_num : -1, NULL, b);\n#if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 32)\n    if (b->has_debug)\n        dump_pc2line(ctx, b->debug.pc2line_buf, b->debug.pc2line_len, b->debug.line_num);\n#endif\n    printf(\"\\n\");\n}\n#endif\n\nstatic int add_closure_var(JSContext *ctx, JSFunctionDef *s,\n                           BOOL is_local, BOOL is_arg,\n                           int var_idx, JSAtom var_name,\n                           BOOL is_const, BOOL is_lexical,\n                           JSVarKindEnum var_kind)\n{\n    JSClosureVar *cv;\n\n    /* the closure variable indexes are currently stored on 16 bits */\n    if (s->closure_var_count >= JS_MAX_LOCAL_VARS) {\n        JS_ThrowInternalError(ctx, \"too many closure variables\");\n        return -1;\n    }\n\n    if (js_resize_array(ctx, (void **)&s->closure_var,\n                        sizeof(s->closure_var[0]),\n                        &s->closure_var_size, s->closure_var_count + 1))\n        return -1;\n    cv = &s->closure_var[s->closure_var_count++];\n    cv->is_local = is_local;\n    cv->is_arg = is_arg;\n    cv->is_const = is_const;\n    cv->is_lexical = is_lexical;\n    cv->var_kind = var_kind;\n    cv->var_idx = var_idx;\n    cv->var_name = JS_DupAtom(ctx, var_name);\n    return s->closure_var_count - 1;\n}\n\nstatic int find_closure_var(JSContext *ctx, JSFunctionDef *s,\n                            JSAtom var_name)\n{\n    int i;\n    for(i = 0; i < s->closure_var_count; i++) {\n        JSClosureVar *cv = &s->closure_var[i];\n        if (cv->var_name == var_name)\n            return i;\n    }\n    return -1;\n}\n\n/* 'fd' must be a parent of 's'. Create in 's' a closure referencing a\n   local variable (is_local = TRUE) or a closure (is_local = FALSE) in\n   'fd' */\nstatic int get_closure_var2(JSContext *ctx, JSFunctionDef *s,\n                            JSFunctionDef *fd, BOOL is_local,\n                            BOOL is_arg, int var_idx, JSAtom var_name,\n                            BOOL is_const, BOOL is_lexical,\n                            JSVarKindEnum var_kind)\n{\n    int i;\n\n    if (fd != s->parent) {\n        var_idx = get_closure_var2(ctx, s->parent, fd, is_local,\n                                   is_arg, var_idx, var_name,\n                                   is_const, is_lexical, var_kind);\n        if (var_idx < 0)\n            return -1;\n        is_local = FALSE;\n    }\n    for(i = 0; i < s->closure_var_count; i++) {\n        JSClosureVar *cv = &s->closure_var[i];\n        if (cv->var_idx == var_idx && cv->is_arg == is_arg &&\n            cv->is_local == is_local)\n            return i;\n    }\n    return add_closure_var(ctx, s, is_local, is_arg, var_idx, var_name,\n                           is_const, is_lexical, var_kind);\n}\n\nstatic int get_closure_var(JSContext *ctx, JSFunctionDef *s,\n                           JSFunctionDef *fd, BOOL is_arg,\n                           int var_idx, JSAtom var_name,\n                           BOOL is_const, BOOL is_lexical,\n                           JSVarKindEnum var_kind)\n{\n    return get_closure_var2(ctx, s, fd, TRUE, is_arg,\n                            var_idx, var_name, is_const, is_lexical,\n                            var_kind);\n}\n\nstatic int get_with_scope_opcode(int op)\n{\n    if (op == OP_scope_get_var_undef)\n        return OP_with_get_var;\n    else\n        return OP_with_get_var + (op - OP_scope_get_var);\n}\n\nstatic BOOL can_opt_put_ref_value(const uint8_t *bc_buf, int pos)\n{\n    int opcode = bc_buf[pos];\n    return (bc_buf[pos + 1] == OP_put_ref_value &&\n            (opcode == OP_insert3 ||\n             opcode == OP_perm4 ||\n             //opcode == OP_nop ||\n             opcode == OP_rot3l));\n}\n\nstatic BOOL can_opt_put_global_ref_value(const uint8_t *bc_buf, int pos)\n{\n    int opcode = bc_buf[pos];\n    return (bc_buf[pos + 1] == OP_put_ref_value &&\n            (opcode == OP_insert3 ||\n             opcode == OP_perm4 ||\n             //opcode == OP_nop ||\n             opcode == OP_rot3l));\n}\n\nstatic int optimize_scope_make_ref(JSContext *ctx, JSFunctionDef *s,\n                                   DynBuf *bc, uint8_t *bc_buf,\n                                   LabelSlot *ls, int pos_next,\n                                   int get_op, int var_idx)\n{\n    int label_pos, end_pos, pos;\n\n    /* XXX: should optimize `loc(a) += expr` as `expr add_loc(a)`\n       but only if expr does not modify `a`.\n       should scan the code between pos_next and label_pos\n       for operations that can potentially change `a`:\n       OP_scope_make_ref(a), function calls, jumps and gosub.\n     */\n    /* replace the reference get/put with normal variable\n       accesses */\n    if (bc_buf[pos_next] == OP_get_ref_value) {\n        dbuf_putc(bc, get_op);\n        dbuf_put_u16(bc, var_idx);\n        pos_next++;\n    }\n    /* remove the OP_label to make room for replacement */\n    /* label should have a refcount of 0 anyway */\n    /* XXX: should avoid this patch by inserting nops in phase 1 */\n    label_pos = ls->pos;\n    pos = label_pos - 5;\n    assert(bc_buf[pos] == OP_label);\n    /* label points to an instruction pair:\n       - insert3 / put_ref_value\n       - perm4 / put_ref_value\n       - rot3l / put_ref_value\n       - nop / put_ref_value\n     */\n    end_pos = label_pos + 2;\n    if (bc_buf[label_pos] == OP_insert3)\n        bc_buf[pos++] = OP_dup;\n    bc_buf[pos] = get_op + 1;\n    put_u16(bc_buf + pos + 1, var_idx);\n    pos += 3;\n    /* pad with OP_nop */\n    while (pos < end_pos)\n        bc_buf[pos++] = OP_nop;\n    return pos_next;\n}\n\nstatic int optimize_scope_make_global_ref(JSContext *ctx, JSFunctionDef *s,\n                                          DynBuf *bc, uint8_t *bc_buf,\n                                          LabelSlot *ls, int pos_next,\n                                          JSAtom var_name)\n{\n    int label_pos, end_pos, pos, op;\n    BOOL is_strict;\n    is_strict = ((s->js_mode & JS_MODE_STRICT) != 0);\n\n    /* replace the reference get/put with normal variable\n       accesses */\n    if (is_strict) {\n        /* need to check if the variable exists before evaluating the right\n           expression */\n        /* XXX: need an extra OP_true if destructuring an array */\n        dbuf_putc(bc, OP_check_var);\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n    } else {\n        /* XXX: need 2 extra OP_true if destructuring an array */\n    }\n    if (bc_buf[pos_next] == OP_get_ref_value) {\n        dbuf_putc(bc, OP_get_var);\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        pos_next++;\n    }\n    /* remove the OP_label to make room for replacement */\n    /* label should have a refcount of 0 anyway */\n    /* XXX: should have emitted several OP_nop to avoid this kludge */\n    label_pos = ls->pos;\n    pos = label_pos - 5;\n    assert(bc_buf[pos] == OP_label);\n    end_pos = label_pos + 2;\n    op = bc_buf[label_pos];\n    if (is_strict) {\n        switch(op) {\n        case OP_insert3:\n            op = OP_insert2;\n            break;\n        case OP_perm4:\n            op = OP_perm3;\n            break;\n        case OP_rot3l:\n            op = OP_swap;\n            break;\n        default:\n            abort();\n        }\n        bc_buf[pos++] = op;\n    } else {\n        if (op == OP_insert3)\n            bc_buf[pos++] = OP_dup;\n    }\n    if (is_strict) {\n        bc_buf[pos] = OP_put_var_strict;\n        /* XXX: need 1 extra OP_drop if destructuring an array */\n    } else {\n        bc_buf[pos] = OP_put_var;\n        /* XXX: need 2 extra OP_drop if destructuring an array */\n    }\n    put_u32(bc_buf + pos + 1, JS_DupAtom(ctx, var_name));\n    pos += 5;\n    /* pad with OP_nop */\n    while (pos < end_pos)\n        bc_buf[pos++] = OP_nop;\n    return pos_next;\n}\n\nstatic int add_var_this(JSContext *ctx, JSFunctionDef *fd)\n{\n    int idx;\n    idx = add_var(ctx, fd, JS_ATOM_this);\n    if (idx >= 0 && fd->is_derived_class_constructor) {\n        JSVarDef *vd = &fd->vars[idx];\n        /* XXX: should have is_this flag or var type */\n        vd->is_lexical = 1; /* used to trigger 'uninitialized' checks\n                               in a derived class constructor */\n    }\n    return idx;\n}\n\nstatic int resolve_pseudo_var(JSContext *ctx, JSFunctionDef *s,\n                               JSAtom var_name)\n{\n    int var_idx;\n\n    if (!s->has_this_binding)\n        return -1;\n    switch(var_name) {\n    case JS_ATOM_home_object:\n        /* 'home_object' pseudo variable */\n        var_idx = s->home_object_var_idx = add_var(ctx, s, var_name);\n        break;\n    case JS_ATOM_this_active_func:\n        /* 'this.active_func' pseudo variable */\n        var_idx = s->this_active_func_var_idx = add_var(ctx, s, var_name);\n        break;\n    case JS_ATOM_new_target:\n        /* 'new.target' pseudo variable */\n        var_idx = s->new_target_var_idx = add_var(ctx, s, var_name);\n        break;\n    case JS_ATOM_this:\n        /* 'this' pseudo variable */\n        var_idx = s->this_var_idx = add_var_this(ctx, s);\n        break;\n    default:\n        var_idx = -1;\n        break;\n    }\n    return var_idx;\n}\n\n/* return the position of the next opcode */\nstatic int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,\n                             JSAtom var_name, int scope_level, int op,\n                             DynBuf *bc, uint8_t *bc_buf,\n                             LabelSlot *ls, int pos_next, int arg_valid)\n{\n    int idx, var_idx, is_put;\n    int label_done;\n    BOOL is_func_var = FALSE;\n    JSFunctionDef *fd;\n    JSVarDef *vd;\n    BOOL is_pseudo_var;\n\n    label_done = -1;\n\n    /* XXX: could be simpler to use a specific function to\n       resolve the pseudo variables */\n    is_pseudo_var = (var_name == JS_ATOM_home_object ||\n                     var_name == JS_ATOM_this_active_func ||\n                     var_name == JS_ATOM_new_target ||\n                     var_name == JS_ATOM_this);\n\n    /* resolve local scoped variables */\n    var_idx = -1;\n    for (idx = s->scopes[scope_level].first; idx >= 0;) {\n        vd = &s->vars[idx];\n        if (vd->var_name == var_name) {\n            if (op == OP_scope_put_var || op == OP_scope_make_ref) {\n                if (vd->is_const) {\n                    dbuf_putc(bc, OP_throw_var);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                    dbuf_putc(bc, JS_THROW_VAR_RO);\n                    goto done;\n                }\n                is_func_var = vd->is_func_var;\n            }\n            var_idx = idx;\n            break;\n        } else\n        if (vd->var_name == JS_ATOM__with_ && !is_pseudo_var) {\n            dbuf_putc(bc, OP_get_loc);\n            dbuf_put_u16(bc, idx);\n            dbuf_putc(bc, get_with_scope_opcode(op));\n            dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n            label_done = new_label_fd(s, label_done);\n            dbuf_put_u32(bc, label_done);\n            dbuf_putc(bc, 1);\n            update_label(s, label_done, 1);\n            s->jump_size++;\n        }\n        idx = vd->scope_next;\n    }\n    if (var_idx < 0) {\n        /* XXX: scoping issues:\n           should not resolve vars from the function body during argument parse,\n           `arguments` and function-name should not be hidden by later vars.\n         */\n        var_idx = find_var(ctx, s, var_name);\n        if (var_idx >= 0) {\n            if (scope_level == 0\n            &&  (var_idx & ARGUMENT_VAR_OFFSET)\n            &&  (var_idx - ARGUMENT_VAR_OFFSET) >= arg_valid) {\n                /* referring to an uninitialized argument */\n                dbuf_putc(bc, OP_throw_var);\n                dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                dbuf_putc(bc, JS_THROW_VAR_UNINITIALIZED);\n            }\n            if (!(var_idx & ARGUMENT_VAR_OFFSET))\n                is_func_var = s->vars[var_idx].is_func_var;\n        }\n\n        if (var_idx < 0 && is_pseudo_var)\n            var_idx = resolve_pseudo_var(ctx, s, var_name);\n\n        if (var_idx < 0 && var_name == JS_ATOM_arguments &&\n            s->has_arguments_binding) {\n            /* 'arguments' pseudo variable */\n            var_idx = add_arguments_var(ctx, s, var_name);\n        }\n        if (var_idx < 0 && s->is_func_expr && var_name == s->func_name) {\n            /* add a new variable with the function name */\n            var_idx = add_func_var(ctx, s, var_name);\n            is_func_var = TRUE;\n        }\n    }\n    if (var_idx >= 0) {\n        /* OP_scope_put_var_init is only used to initialize a\n           lexical variable, so it is never used in a with or var object. It\n           can be used with a closure (module global variable case). */\n        switch (op) {\n        case OP_scope_make_ref:\n            if (is_func_var) {\n                /* Create a dummy object reference for the func_var */\n                dbuf_putc(bc, OP_object);\n                dbuf_putc(bc, OP_get_loc);\n                dbuf_put_u16(bc, var_idx);\n                dbuf_putc(bc, OP_define_field);\n                dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                dbuf_putc(bc, OP_push_atom_value);\n                dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n            } else\n            if (label_done == -1 && can_opt_put_ref_value(bc_buf, ls->pos)) {\n                int get_op;\n                if (var_idx & ARGUMENT_VAR_OFFSET) {\n                    get_op = OP_get_arg;\n                    var_idx -= ARGUMENT_VAR_OFFSET;\n                } else {\n                    if (s->vars[var_idx].is_lexical)\n                        get_op = OP_get_loc_check;\n                    else\n                        get_op = OP_get_loc;\n                }\n                pos_next = optimize_scope_make_ref(ctx, s, bc, bc_buf, ls,\n                                                   pos_next, get_op, var_idx);\n            } else {\n                /* Create a dummy object with a named slot that is\n                   a reference to the local variable */\n                if (var_idx & ARGUMENT_VAR_OFFSET) {\n                    dbuf_putc(bc, OP_make_arg_ref);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                    dbuf_put_u16(bc, var_idx - ARGUMENT_VAR_OFFSET);\n                } else {\n                    dbuf_putc(bc, OP_make_loc_ref);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                    dbuf_put_u16(bc, var_idx);\n                }\n            }\n            break;\n        case OP_scope_get_ref:\n            dbuf_putc(bc, OP_undefined);\n            /* fall thru */\n        case OP_scope_get_var_undef:\n        case OP_scope_get_var:\n        case OP_scope_put_var:\n        case OP_scope_put_var_init:\n            is_put = (op == OP_scope_put_var || op == OP_scope_put_var_init);\n            if (var_idx & ARGUMENT_VAR_OFFSET) {\n                dbuf_putc(bc, OP_get_arg + is_put);\n                dbuf_put_u16(bc, var_idx - ARGUMENT_VAR_OFFSET);\n                /* XXX: should test if argument reference needs TDZ check */\n            } else {\n                if (is_put) {\n                    if (s->vars[var_idx].is_lexical) {\n                        if (op == OP_scope_put_var_init) {\n                            /* 'this' can only be initialized once */\n                            if (var_name == JS_ATOM_this)\n                                dbuf_putc(bc, OP_put_loc_check_init);\n                            else\n                                dbuf_putc(bc, OP_put_loc);\n                        } else {\n                            dbuf_putc(bc, OP_put_loc_check);\n                        }\n                    } else {\n                        dbuf_putc(bc, OP_put_loc);\n                    }\n                } else {\n                    if (s->vars[var_idx].is_lexical) {\n                        dbuf_putc(bc, OP_get_loc_check);\n                    } else {\n                        dbuf_putc(bc, OP_get_loc);\n                    }\n                }\n                dbuf_put_u16(bc, var_idx);\n            }\n            break;\n        case OP_scope_delete_var:\n            dbuf_putc(bc, OP_push_false);\n            break;\n        }\n        goto done;\n    }\n    /* check eval object */\n    if (s->var_object_idx >= 0 && !is_pseudo_var) {\n        dbuf_putc(bc, OP_get_loc);\n        dbuf_put_u16(bc, s->var_object_idx);\n        dbuf_putc(bc, get_with_scope_opcode(op));\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        label_done = new_label_fd(s, label_done);\n        dbuf_put_u32(bc, label_done);\n        dbuf_putc(bc, 0);\n        update_label(s, label_done, 1);\n        s->jump_size++;\n    }\n    /* check parent scopes */\n    for (fd = s; fd->parent;) {\n        scope_level = fd->parent_scope_level;\n        fd = fd->parent;\n        if (scope_level == 0) {\n            /* function is defined as part of the argument parsing: hide vars\n               from the function body.\n               XXX: variables created from argument destructuring might need\n               to be visible, should refine this method.\n             */\n            var_idx = find_arg(ctx, fd, var_name);\n            goto check_idx;\n        }\n        for (idx = fd->scopes[scope_level].first; idx >= 0;) {\n            vd = &fd->vars[idx];\n            if (vd->var_name == var_name) {\n                if (op == OP_scope_put_var || op == OP_scope_make_ref) {\n                    if (vd->is_const) {\n                        dbuf_putc(bc, OP_throw_var);\n                        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                        dbuf_putc(bc, JS_THROW_VAR_RO);\n                        goto done;\n                    }\n                    is_func_var = vd->is_func_var;\n                }\n                var_idx = idx;\n                break;\n            } else if (vd->var_name == JS_ATOM__with_ && !is_pseudo_var) {\n                vd->is_captured = 1;\n                idx = get_closure_var(ctx, s, fd, FALSE, idx, vd->var_name, FALSE, FALSE, JS_VAR_NORMAL);\n                if (idx >= 0) {\n                    dbuf_putc(bc, OP_get_var_ref);\n                    dbuf_put_u16(bc, idx);\n                    dbuf_putc(bc, get_with_scope_opcode(op));\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                    label_done = new_label_fd(s, label_done);\n                    dbuf_put_u32(bc, label_done);\n                    dbuf_putc(bc, 1);\n                    update_label(s, label_done, 1);\n                    s->jump_size++;\n                }\n            }\n            idx = vd->scope_next;\n        }\n        if (var_idx >= 0)\n            break;\n\n        var_idx = find_var(ctx, fd, var_name);\n    check_idx:\n        if (var_idx >= 0) {\n            if (!(var_idx & ARGUMENT_VAR_OFFSET))\n                is_func_var = fd->vars[var_idx].is_func_var;\n            break;\n        }\n        if (is_pseudo_var) {\n            var_idx = resolve_pseudo_var(ctx, fd, var_name);\n            if (var_idx >= 0)\n                break;\n        }\n        if (var_name == JS_ATOM_arguments && fd->has_arguments_binding) {\n            var_idx = add_arguments_var(ctx, fd, var_name);\n            break;\n        }\n        if (fd->is_func_expr && fd->func_name == var_name) {\n            /* add a new variable with the function name */\n            var_idx = add_func_var(ctx, fd, var_name);\n            is_func_var = TRUE;\n            break;\n        }\n\n        /* check eval object */\n        if (fd->var_object_idx >= 0 && !is_pseudo_var) {\n            fd->vars[fd->var_object_idx].is_captured = 1;\n            idx = get_closure_var(ctx, s, fd, FALSE,\n                                  fd->var_object_idx, JS_ATOM__var_,\n                                  FALSE, FALSE, JS_VAR_NORMAL);\n            dbuf_putc(bc, OP_get_var_ref);\n            dbuf_put_u16(bc, idx);\n            dbuf_putc(bc, get_with_scope_opcode(op));\n            dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n            label_done = new_label_fd(s, label_done);\n            dbuf_put_u32(bc, label_done);\n            dbuf_putc(bc, 0);\n            update_label(s, label_done, 1);\n            s->jump_size++;\n        }\n\n        if (fd->is_eval)\n            break; /* it it necessarily the top level function */\n    }\n\n    /* check direct eval scope (in the closure of the eval function\n       which is necessarily at the top level) */\n    if (!fd)\n        fd = s;\n    if (var_idx < 0 && fd->is_eval) {\n        int idx1;\n        for (idx1 = 0; idx1 < fd->closure_var_count; idx1++) {\n            JSClosureVar *cv = &fd->closure_var[idx1];\n            if (var_name == cv->var_name) {\n                if (fd != s) {\n                    idx = get_closure_var2(ctx, s, fd,\n                                           FALSE,\n                                           cv->is_arg, idx1,\n                                           cv->var_name, cv->is_const,\n                                           cv->is_lexical, cv->var_kind);\n                } else {\n                    idx = idx1;\n                }\n                goto has_idx;\n            } else if ((cv->var_name == JS_ATOM__var_ ||\n                        cv->var_name == JS_ATOM__with_) && !is_pseudo_var) {\n                int is_with = (cv->var_name == JS_ATOM__with_);\n                if (fd != s) {\n                    idx = get_closure_var2(ctx, s, fd,\n                                           FALSE,\n                                           cv->is_arg, idx1,\n                                           cv->var_name, FALSE, FALSE,\n                                           JS_VAR_NORMAL);\n                } else {\n                    idx = idx1;\n                }\n                dbuf_putc(bc, OP_get_var_ref);\n                dbuf_put_u16(bc, idx);\n                dbuf_putc(bc, get_with_scope_opcode(op));\n                dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                label_done = new_label_fd(s, label_done);\n                dbuf_put_u32(bc, label_done);\n                dbuf_putc(bc, is_with);\n                update_label(s, label_done, 1);\n                s->jump_size++;\n            }\n        }\n    }\n\n    if (var_idx >= 0) {\n        /* find the corresponding closure variable */\n        if (var_idx & ARGUMENT_VAR_OFFSET) {\n            fd->args[var_idx - ARGUMENT_VAR_OFFSET].is_captured = 1;\n            idx = get_closure_var(ctx, s, fd,\n                                  TRUE, var_idx - ARGUMENT_VAR_OFFSET,\n                                  var_name, FALSE, FALSE, JS_VAR_NORMAL);\n        } else {\n            fd->vars[var_idx].is_captured = 1;\n            idx = get_closure_var(ctx, s, fd,\n                                  FALSE, var_idx,\n                                  var_name,\n                                  fd->vars[var_idx].is_const,\n                                  fd->vars[var_idx].is_lexical,\n                                  fd->vars[var_idx].var_kind);\n        }\n        if (idx >= 0) {\n        has_idx:\n            if ((op == OP_scope_put_var || op == OP_scope_make_ref) &&\n                s->closure_var[idx].is_const) {\n                dbuf_putc(bc, OP_throw_var);\n                dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                dbuf_putc(bc, JS_THROW_VAR_RO);\n                goto done;\n            }\n            switch (op) {\n            case OP_scope_make_ref:\n                if (is_func_var) {\n                    /* Create a dummy object reference for the func_var */\n                    dbuf_putc(bc, OP_object);\n                    dbuf_putc(bc, OP_get_var_ref);\n                    dbuf_put_u16(bc, idx);\n                    dbuf_putc(bc, OP_define_field);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                    dbuf_putc(bc, OP_push_atom_value);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                } else\n                if (label_done == -1 &&\n                    can_opt_put_ref_value(bc_buf, ls->pos)) {\n                    int get_op;\n                    if (s->closure_var[idx].is_lexical)\n                        get_op = OP_get_var_ref_check;\n                    else\n                        get_op = OP_get_var_ref;\n                    pos_next = optimize_scope_make_ref(ctx, s, bc, bc_buf, ls,\n                                                       pos_next,\n                                                       get_op, idx);\n                } else {\n                    /* Create a dummy object with a named slot that is\n                       a reference to the closure variable */\n                    dbuf_putc(bc, OP_make_var_ref_ref);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n                    dbuf_put_u16(bc, idx);\n                }\n                break;\n            case OP_scope_get_ref:\n                /* XXX: should create a dummy object with a named slot that is\n                   a reference to the closure variable */\n                dbuf_putc(bc, OP_undefined);\n                /* fall thru */\n            case OP_scope_get_var_undef:\n            case OP_scope_get_var:\n            case OP_scope_put_var:\n            case OP_scope_put_var_init:\n                is_put = (op == OP_scope_put_var ||\n                          op == OP_scope_put_var_init);\n                if (is_put) {\n                    if (s->closure_var[idx].is_lexical) {\n                        if (op == OP_scope_put_var_init) {\n                            /* 'this' can only be initialized once */\n                            if (var_name == JS_ATOM_this)\n                                dbuf_putc(bc, OP_put_var_ref_check_init);\n                            else\n                                dbuf_putc(bc, OP_put_var_ref);\n                        } else {\n                            dbuf_putc(bc, OP_put_var_ref_check);\n                        }\n                    } else {\n                        dbuf_putc(bc, OP_put_var_ref);\n                    }\n                } else {\n                    if (s->closure_var[idx].is_lexical) {\n                        dbuf_putc(bc, OP_get_var_ref_check);\n                    } else {\n                        dbuf_putc(bc, OP_get_var_ref);\n                    }\n                }\n                dbuf_put_u16(bc, idx);\n                break;\n            case OP_scope_delete_var:\n                dbuf_putc(bc, OP_push_false);\n                break;\n            }\n            goto done;\n        }\n    }\n\n    /* global variable access */\n\n    switch (op) {\n    case OP_scope_make_ref:\n        if (label_done == -1 && can_opt_put_global_ref_value(bc_buf, ls->pos)) {\n            pos_next = optimize_scope_make_global_ref(ctx, s, bc, bc_buf, ls,\n                                                      pos_next, var_name);\n        } else {\n            dbuf_putc(bc, OP_make_var_ref);\n            dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        }\n        break;\n    case OP_scope_get_ref:\n        /* XXX: should create a dummy object with a named slot that is\n           a reference to the global variable */\n        dbuf_putc(bc, OP_undefined);\n        dbuf_putc(bc, OP_get_var);\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        break;\n    case OP_scope_get_var_undef:\n    case OP_scope_get_var:\n    case OP_scope_put_var:\n        dbuf_putc(bc, OP_get_var_undef + (op - OP_scope_get_var_undef));\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        break;\n    case OP_scope_put_var_init:\n        dbuf_putc(bc, OP_put_var_init);\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        break;\n    case OP_scope_delete_var:\n        dbuf_putc(bc, OP_delete_var);\n        dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n        break;\n    }\ndone:\n    if (label_done >= 0) {\n        dbuf_putc(bc, OP_label);\n        dbuf_put_u32(bc, label_done);\n        s->label_slots[label_done].pos2 = bc->size;\n    }\n    return pos_next;\n}\n\n/* search in all scopes */\nstatic int find_private_class_field_all(JSContext *ctx, JSFunctionDef *fd,\n                                        JSAtom name, int scope_level)\n{\n    int idx;\n\n    idx = fd->scopes[scope_level].first;\n    while (idx >= 0) {\n        if (fd->vars[idx].var_name == name)\n            return idx;\n        idx = fd->vars[idx].scope_next;\n    }\n    return -1;\n}\n\nstatic void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx)\n{\n    /* if the field is not initialized, the error is catched when\n       accessing it */\n    if (is_ref) \n        dbuf_putc(bc, OP_get_var_ref);\n    else\n        dbuf_putc(bc, OP_get_loc);\n    dbuf_put_u16(bc, idx);\n}\n\nstatic int resolve_scope_private_field1(JSContext *ctx,\n                                        BOOL *pis_ref, int *pvar_kind,\n                                        JSFunctionDef *s,\n                                        JSAtom var_name, int scope_level)\n{\n    int idx, var_kind;\n    JSFunctionDef *fd;\n    BOOL is_ref;\n    \n    fd = s;\n    is_ref = FALSE;\n    for(;;) {\n        idx = find_private_class_field_all(ctx, fd, var_name, scope_level);\n        if (idx >= 0) {\n            var_kind = fd->vars[idx].var_kind;\n            if (is_ref) {\n                idx = get_closure_var(ctx, s, fd, FALSE, idx, var_name,\n                                      TRUE, TRUE, JS_VAR_NORMAL);\n                if (idx < 0)\n                    return -1;\n            }\n            break;\n        }\n        scope_level = fd->parent_scope_level;\n        if (!fd->parent) {\n            if (fd->is_eval) {\n                /* closure of the eval function (top level) */\n                for (idx = 0; idx < fd->closure_var_count; idx++) {\n                    JSClosureVar *cv = &fd->closure_var[idx];\n                    if (cv->var_name == var_name) {\n                        var_kind = cv->var_kind;\n                        is_ref = TRUE;\n                        if (fd != s) {\n                            idx = get_closure_var2(ctx, s, fd,\n                                                   FALSE,\n                                                   cv->is_arg, idx,\n                                                   cv->var_name, cv->is_const,\n                                                   cv->is_lexical,\n                                                   cv->var_kind);\n                            if (idx < 0)\n                                return -1;\n                        }\n                        goto done;\n                    }\n                }\n            }\n            /* XXX: no line number info */\n            JS_ThrowSyntaxErrorAtom(ctx, \"undefined private field '%s'\",\n                                    var_name);\n            return -1;\n        } else {\n            fd = fd->parent;\n        }\n        is_ref = TRUE;\n    }\n done:\n    *pis_ref = is_ref;\n    *pvar_kind = var_kind;\n    return idx;\n}\n\n/* return 0 if OK or -1 if the private field could not be resolved */\nstatic int resolve_scope_private_field(JSContext *ctx, JSFunctionDef *s,\n                                       JSAtom var_name, int scope_level, int op,\n                                       DynBuf *bc)\n{\n    int idx, var_kind;\n    BOOL is_ref;\n\n    idx = resolve_scope_private_field1(ctx, &is_ref, &var_kind, s,\n                                       var_name, scope_level);\n    if (idx < 0)\n        return -1;\n    assert(var_kind != JS_VAR_NORMAL);\n    switch (op) {\n    case OP_scope_get_private_field:\n    case OP_scope_get_private_field2:\n        switch(var_kind) {\n        case JS_VAR_PRIVATE_FIELD:\n            if (op == OP_scope_get_private_field2)\n                dbuf_putc(bc, OP_dup);\n            get_loc_or_ref(bc, is_ref, idx);\n            dbuf_putc(bc, OP_get_private_field);\n            break;\n        case JS_VAR_PRIVATE_METHOD:\n            get_loc_or_ref(bc, is_ref, idx);\n            dbuf_putc(bc, OP_check_brand);\n            if (op != OP_scope_get_private_field2)\n                dbuf_putc(bc, OP_nip);\n            break;\n        case JS_VAR_PRIVATE_GETTER:\n        case JS_VAR_PRIVATE_GETTER_SETTER:\n            if (op == OP_scope_get_private_field2)\n                dbuf_putc(bc, OP_dup);\n            get_loc_or_ref(bc, is_ref, idx);\n            dbuf_putc(bc, OP_check_brand);\n            dbuf_putc(bc, OP_call_method);\n            dbuf_put_u16(bc, 0);\n            break;\n        case JS_VAR_PRIVATE_SETTER:\n            /* XXX: add clearer error message */\n            dbuf_putc(bc, OP_throw_var);\n            dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n            dbuf_putc(bc, JS_THROW_VAR_RO);\n            break;\n        default:\n            abort();\n        }\n        break;\n    case OP_scope_put_private_field:\n        switch(var_kind) {\n        case JS_VAR_PRIVATE_FIELD:\n            get_loc_or_ref(bc, is_ref, idx);\n            dbuf_putc(bc, OP_put_private_field);\n            break;\n        case JS_VAR_PRIVATE_METHOD:\n        case JS_VAR_PRIVATE_GETTER:\n            /* XXX: add clearer error message */\n            dbuf_putc(bc, OP_throw_var);\n            dbuf_put_u32(bc, JS_DupAtom(ctx, var_name));\n            dbuf_putc(bc, JS_THROW_VAR_RO);\n            break;\n        case JS_VAR_PRIVATE_SETTER:\n        case JS_VAR_PRIVATE_GETTER_SETTER:\n            {\n                JSAtom setter_name = get_private_setter_name(ctx, var_name);\n                if (setter_name == JS_ATOM_NULL)\n                    return -1;\n                idx = resolve_scope_private_field1(ctx, &is_ref,\n                                                   &var_kind, s,\n                                                   setter_name, scope_level);\n                JS_FreeAtom(ctx, setter_name);\n                if (idx < 0)\n                    return -1;\n                assert(var_kind == JS_VAR_PRIVATE_SETTER);\n                get_loc_or_ref(bc, is_ref, idx);\n                dbuf_putc(bc, OP_swap);\n                /* obj func value */\n                dbuf_putc(bc, OP_rot3r);\n                /* value obj func */\n                dbuf_putc(bc, OP_check_brand);\n                dbuf_putc(bc, OP_rot3l);\n                /* obj func value */\n                dbuf_putc(bc, OP_call_method);\n                dbuf_put_u16(bc, 1);\n            }\n            break;\n        default:\n            abort();\n        }\n        break;\n    default:\n        abort();\n    }\n    return 0;\n}\n\nstatic void mark_eval_captured_variables(JSContext *ctx, JSFunctionDef *s,\n                                         int scope_level)\n{\n    int idx;\n    JSVarDef *vd;\n\n    for (idx = s->scopes[scope_level].first; idx >= 0;) {\n        vd = &s->vars[idx];\n        vd->is_captured = 1;\n        idx = vd->scope_next;\n    }\n}\n\nstatic void add_eval_variables(JSContext *ctx, JSFunctionDef *s)\n{\n    JSFunctionDef *fd;\n    JSVarDef *vd;\n    int i, scope_level, scope_idx;\n    BOOL has_arguments_binding, has_this_binding;\n\n    /* in non strict mode, variables are created in the caller's\n       environment object */\n    if (!s->is_eval && !(s->js_mode & JS_MODE_STRICT)) {\n        s->var_object_idx = add_var(ctx, s, JS_ATOM__var_);\n    }\n\n    /* eval can potentially use 'arguments' so we must define it */\n    has_this_binding = s->has_this_binding;\n    if (has_this_binding) {\n        if (s->this_var_idx < 0)\n            s->this_var_idx = add_var_this(ctx, s);\n        if (s->new_target_var_idx < 0)\n            s->new_target_var_idx = add_var(ctx, s, JS_ATOM_new_target);\n        if (s->is_derived_class_constructor && s->this_active_func_var_idx < 0)\n            s->this_active_func_var_idx = add_var(ctx, s, JS_ATOM_this_active_func);\n        if (s->has_home_object && s->home_object_var_idx < 0)\n            s->home_object_var_idx = add_var(ctx, s, JS_ATOM_home_object);\n    }\n    has_arguments_binding = s->has_arguments_binding;\n    if (has_arguments_binding)\n        add_arguments_var(ctx, s, JS_ATOM_arguments);\n    if (s->is_func_expr && s->func_name != JS_ATOM_NULL)\n        add_func_var(ctx, s, s->func_name);\n\n    /* eval can use all the variables of the enclosing functions, so\n       they must be all put in the closure. The closure variables are\n       ordered by scope. It works only because no closure are created\n       before. */\n    assert(s->is_eval || s->closure_var_count == 0);\n\n    /* XXX: inefficient, but eval performance is less critical */\n    fd = s;\n    for(;;) {\n        scope_level = fd->parent_scope_level;\n        fd = fd->parent;\n        if (!fd)\n            break;\n        scope_idx = fd->scopes[scope_level].first;\n        /* add 'this' if it was not previously added */\n        if (!has_this_binding && fd->has_this_binding) {\n            if (fd->this_var_idx < 0)\n                fd->this_var_idx = add_var_this(ctx, fd);\n            if (fd->new_target_var_idx < 0)\n                fd->new_target_var_idx = add_var(ctx, fd, JS_ATOM_new_target);\n            if (fd->is_derived_class_constructor && fd->this_active_func_var_idx < 0)\n                fd->this_active_func_var_idx = add_var(ctx, fd, JS_ATOM_this_active_func);\n            if (fd->has_home_object && fd->home_object_var_idx < 0)\n                fd->home_object_var_idx = add_var(ctx, fd, JS_ATOM_home_object);\n            has_this_binding = TRUE;\n        }\n        /* add 'arguments' if it was not previously added */\n        if (!has_arguments_binding && fd->has_arguments_binding) {\n            add_arguments_var(ctx, fd, JS_ATOM_arguments);\n            has_arguments_binding = TRUE;\n        }\n        /* add function name */\n        if (fd->is_func_expr && fd->func_name != JS_ATOM_NULL)\n            add_func_var(ctx, fd, fd->func_name);\n\n        /* add lexical variables */\n        while (scope_idx >= 0) {\n            vd = &fd->vars[scope_idx];\n            vd->is_captured = 1;\n            get_closure_var(ctx, s, fd, FALSE, scope_idx,\n                            vd->var_name, vd->is_const, vd->is_lexical, vd->var_kind);\n            scope_idx = vd->scope_next;\n        }\n        /* add unscoped variables */\n        for(i = 0; i < fd->arg_count; i++) {\n            vd = &fd->args[i];\n            if (vd->var_name != JS_ATOM_NULL) {\n                get_closure_var(ctx, s, fd,\n                                TRUE, i, vd->var_name, FALSE, FALSE,\n                                JS_VAR_NORMAL);\n            }\n        }\n        for(i = 0; i < fd->var_count; i++) {\n            vd = &fd->vars[i];\n            /* do not close top level last result */\n            if (vd->scope_level == 0 &&\n                vd->var_name != JS_ATOM__ret_ &&\n                vd->var_name != JS_ATOM_NULL) {\n                get_closure_var(ctx, s, fd,\n                                FALSE, i, vd->var_name, FALSE, FALSE,\n                                JS_VAR_NORMAL);\n            }\n        }\n        if (fd->is_eval) {\n            int idx;\n            /* add direct eval variables (we are necessarily at the\n               top level) */\n            for (idx = 0; idx < fd->closure_var_count; idx++) {\n                JSClosureVar *cv = &fd->closure_var[idx];\n                get_closure_var2(ctx, s, fd,\n                                 FALSE, cv->is_arg,\n                                 idx, cv->var_name, cv->is_const,\n                                 cv->is_lexical, cv->var_kind);\n            }\n        }\n    }\n}\n\n/* for direct eval compilation: add references to the variables of the\n   calling function */\nstatic __exception int add_closure_variables(JSContext *ctx, JSFunctionDef *s,\n                                             JSFunctionBytecode *b, int scope_idx)\n{\n    int i, count;\n    JSVarDef *vd;\n\n    count = b->arg_count + b->var_count + b->closure_var_count;\n    s->closure_var = NULL;\n    s->closure_var_count = 0;\n    s->closure_var_size = count;\n    if (count == 0)\n        return 0;\n    s->closure_var = js_malloc(ctx, sizeof(s->closure_var[0]) * count);\n    if (!s->closure_var)\n        return -1;\n    /* Add lexical variables in scope at the point of evaluation */\n    for (i = scope_idx; i >= 0;) {\n        vd = &b->vardefs[b->arg_count + i];\n        if (vd->scope_level > 0) {\n            JSClosureVar *cv = &s->closure_var[s->closure_var_count++];\n            cv->is_local = TRUE;\n            cv->is_arg = FALSE;\n            cv->is_const = vd->is_const;\n            cv->is_lexical = vd->is_lexical;\n            cv->var_kind = vd->var_kind;\n            cv->var_idx = i;\n            cv->var_name = JS_DupAtom(ctx, vd->var_name);\n        }\n        i = vd->scope_next;\n    }\n    /* Add argument variables */\n    for(i = 0; i < b->arg_count; i++) {\n        JSClosureVar *cv = &s->closure_var[s->closure_var_count++];\n        vd = &b->vardefs[i];\n        cv->is_local = TRUE;\n        cv->is_arg = TRUE;\n        cv->is_const = FALSE;\n        cv->is_lexical = FALSE;\n        cv->var_kind = JS_VAR_NORMAL;\n        cv->var_idx = i;\n        cv->var_name = JS_DupAtom(ctx, vd->var_name);\n    }\n    /* Add local non lexical variables */\n    for(i = 0; i < b->var_count; i++) {\n        vd = &b->vardefs[b->arg_count + i];\n        if (vd->scope_level == 0 && vd->var_name != JS_ATOM__ret_) {\n            JSClosureVar *cv = &s->closure_var[s->closure_var_count++];\n            cv->is_local = TRUE;\n            cv->is_arg = FALSE;\n            cv->is_const = FALSE;\n            cv->is_lexical = FALSE;\n            cv->var_kind = JS_VAR_NORMAL;\n            cv->var_idx = i;\n            cv->var_name = JS_DupAtom(ctx, vd->var_name);\n        }\n    }\n    for(i = 0; i < b->closure_var_count; i++) {\n        JSClosureVar *cv0 = &b->closure_var[i];\n        JSClosureVar *cv = &s->closure_var[s->closure_var_count++];\n        cv->is_local = FALSE;\n        cv->is_arg = cv0->is_arg;\n        cv->is_const = cv0->is_const;\n        cv->is_lexical = cv0->is_lexical;\n        cv->var_kind = cv0->var_kind;\n        cv->var_idx = i;\n        cv->var_name = JS_DupAtom(ctx, cv0->var_name);\n    }\n    return 0;\n}\n\ntypedef struct CodeContext {\n    const uint8_t *bc_buf; /* code buffer */\n    int bc_len;   /* length of the code buffer */\n    int pos;      /* position past the matched code pattern */\n    int line_num; /* last visited OP_line_num parameter or -1 */\n    int op;\n    int idx;\n    int label;\n    int val;\n    JSAtom atom;\n} CodeContext;\n\n#define M2(op1, op2)            ((op1) | ((op2) << 8))\n#define M3(op1, op2, op3)       ((op1) | ((op2) << 8) | ((op3) << 16))\n#define M4(op1, op2, op3, op4)  ((op1) | ((op2) << 8) | ((op3) << 16) | ((op4) << 24))\n\nstatic BOOL code_match(CodeContext *s, int pos, ...)\n{\n    const uint8_t *tab = s->bc_buf;\n    int op, len, op1, line_num, pos_next;\n    va_list ap;\n    BOOL ret = FALSE;\n\n    line_num = -1;\n    va_start(ap, pos);\n\n    for(;;) {\n        op1 = va_arg(ap, int);\n        if (op1 == -1) {\n            s->pos = pos;\n            s->line_num = line_num;\n            ret = TRUE;\n            break;\n        }\n        for (;;) {\n            if (pos >= s->bc_len)\n                goto done;\n            op = tab[pos];\n            len = opcode_info[op].size;\n            pos_next = pos + len;\n            if (pos_next > s->bc_len)\n                goto done;\n            if (op == OP_line_num) {\n                line_num = get_u32(tab + pos + 1);\n                pos = pos_next;\n            } else {\n                break;\n            }\n        }\n        if (op != op1) {\n            if (op1 == (uint8_t)op1 || !op)\n                break;\n            if (op != (uint8_t)op1\n            &&  op != (uint8_t)(op1 >> 8)\n            &&  op != (uint8_t)(op1 >> 16)\n            &&  op != (uint8_t)(op1 >> 24)) {\n                break;\n            }\n            s->op = op;\n        }\n\n        pos++;\n        switch(opcode_info[op].fmt) {\n        case OP_FMT_loc8:\n        case OP_FMT_u8:\n            {\n                int idx = tab[pos];\n                int arg = va_arg(ap, int);\n                if (arg == -1) {\n                    s->idx = idx;\n                } else {\n                    if (arg != idx)\n                        goto done;\n                }\n                break;\n            }\n        case OP_FMT_u16:\n        case OP_FMT_npop:\n        case OP_FMT_loc:\n        case OP_FMT_arg:\n        case OP_FMT_var_ref:\n            {\n                int idx = get_u16(tab + pos);\n                int arg = va_arg(ap, int);\n                if (arg == -1) {\n                    s->idx = idx;\n                } else {\n                    if (arg != idx)\n                        goto done;\n                }\n                break;\n            }\n        case OP_FMT_i32:\n        case OP_FMT_u32:\n        case OP_FMT_label:\n        case OP_FMT_const:\n            {\n                s->label = get_u32(tab + pos);\n                break;\n            }\n        case OP_FMT_label_u16:\n            {\n                s->label = get_u32(tab + pos);\n                s->val = get_u16(tab + pos + 4);\n                break;\n            }\n        case OP_FMT_atom:\n            {\n                s->atom = get_u32(tab + pos);\n                break;\n            }\n        case OP_FMT_atom_u8:\n            {\n                s->atom = get_u32(tab + pos);\n                s->val = get_u8(tab + pos + 4);\n                break;\n            }\n        case OP_FMT_atom_u16:\n            {\n                s->atom = get_u32(tab + pos);\n                s->val = get_u16(tab + pos + 4);\n                break;\n            }\n        case OP_FMT_atom_label_u8:\n            {\n                s->atom = get_u32(tab + pos);\n                s->label = get_u32(tab + pos + 4);\n                s->val = get_u8(tab + pos + 8);\n                break;\n            }\n        default:\n            break;\n        }\n        pos = pos_next;\n    }\n done:\n    va_end(ap);\n    return ret;\n}\n\nstatic void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, DynBuf *bc)\n{\n    int i, idx, var_idx;\n\n    /* add the hoisted functions and variables */\n    for(i = 0; i < s->hoisted_def_count; i++) {\n        JSHoistedDef *hf = &s->hoisted_def[i];\n        int has_closure = 0;\n        BOOL force_init = hf->force_init;\n        if (s->is_global_var && hf->var_name != JS_ATOM_NULL) {\n            /* we are in an eval, so the closure contains all the\n               enclosing variables */\n            /* If the outer function has a variable environment,\n               create a property for the variable there */\n            for(idx = 0; idx < s->closure_var_count; idx++) {\n                JSClosureVar *cv = &s->closure_var[idx];\n                if (cv->var_name == hf->var_name) {\n                    has_closure = 2;\n                    force_init = FALSE;\n                    break;\n                }\n                if (cv->var_name == JS_ATOM__var_) {\n                    dbuf_putc(bc, OP_get_var_ref);\n                    dbuf_put_u16(bc, idx);\n                    has_closure = 1;\n                    force_init = TRUE;\n                    break;\n                }\n            }\n            if (!has_closure) {\n                int flags;\n\n                flags = 0;\n                if (s->eval_type != JS_EVAL_TYPE_GLOBAL)\n                    flags |= JS_PROP_CONFIGURABLE;\n                if (hf->cpool_idx >= 0 && !hf->is_lexical) {\n                    /* global function definitions need a specific handling */\n                    dbuf_putc(bc, OP_fclosure);\n                    dbuf_put_u32(bc, hf->cpool_idx);\n\n                    dbuf_putc(bc, OP_define_func);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, hf->var_name));\n                    dbuf_putc(bc, flags);\n\n                    goto done_hoisted_def;\n                } else {\n                    if (hf->is_lexical) {\n                        flags |= DEFINE_GLOBAL_LEX_VAR;\n                        if (!hf->is_const)\n                            flags |= JS_PROP_WRITABLE;\n                    }\n                    dbuf_putc(bc, OP_define_var);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, hf->var_name));\n                    dbuf_putc(bc, flags);\n                }\n            }\n        }\n        if (hf->cpool_idx >= 0 || force_init) {\n            if (hf->cpool_idx >= 0) {\n                dbuf_putc(bc, OP_fclosure);\n                dbuf_put_u32(bc, hf->cpool_idx);\n                if (hf->var_name == JS_ATOM__default_) {\n                    /* set default export function name */\n                    dbuf_putc(bc, OP_set_name);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, JS_ATOM_default));\n                }\n            } else {\n                dbuf_putc(bc, OP_undefined);\n            }\n            if (s->is_global_var) {\n                if (has_closure == 2) {\n                    dbuf_putc(bc, OP_put_var_ref);\n                    dbuf_put_u16(bc, idx);\n                } else if (has_closure == 1) {\n                    dbuf_putc(bc, OP_define_field);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, hf->var_name));\n                    dbuf_putc(bc, OP_drop);\n                } else {\n                    /* XXX: Check if variable is writable and enumerable */\n                    dbuf_putc(bc, OP_put_var);\n                    dbuf_put_u32(bc, JS_DupAtom(ctx, hf->var_name));\n                }\n            } else {\n                var_idx = hf->var_idx;\n                if (var_idx & ARGUMENT_VAR_OFFSET) {\n                    dbuf_putc(bc, OP_put_arg);\n                    dbuf_put_u16(bc, var_idx - ARGUMENT_VAR_OFFSET);\n                } else {\n                    dbuf_putc(bc, OP_put_loc);\n                    dbuf_put_u16(bc, var_idx);\n                }\n            }\n        }\n    done_hoisted_def:\n        JS_FreeAtom(ctx, hf->var_name);\n    }\n    js_free(ctx, s->hoisted_def);\n    s->hoisted_def = NULL;\n    s->hoisted_def_count = 0;\n    s->hoisted_def_size = 0;\n}\n\nstatic int skip_dead_code(JSFunctionDef *s, const uint8_t *bc_buf, int bc_len,\n                          int pos, int *linep)\n{\n    int op, len, label;\n\n    for (; pos < bc_len; pos += len) {\n        op = bc_buf[pos];\n        len = opcode_info[op].size;\n        if (op == OP_line_num) {\n            *linep = get_u32(bc_buf + pos + 1);\n        } else\n        if (op == OP_label) {\n            label = get_u32(bc_buf + pos + 1);\n            if (update_label(s, label, 0) > 0)\n                break;\n#if 0\n            if (s->label_slots[label].first_reloc) {\n                printf(\"line %d: unreferenced label %d:%d has relocations\\n\",\n                       *linep, label, s->label_slots[label].pos2);\n            }\n#endif\n            assert(s->label_slots[label].first_reloc == NULL);\n        } else {\n            /* XXX: output a warning for unreachable code? */\n            JSAtom atom;\n            switch(opcode_info[op].fmt) {\n            case OP_FMT_label:\n            case OP_FMT_label_u16:\n                label = get_u32(bc_buf + pos + 1);\n                update_label(s, label, -1);\n                break;\n            case OP_FMT_atom_label_u8:\n            case OP_FMT_atom_label_u16:\n                label = get_u32(bc_buf + pos + 5);\n                update_label(s, label, -1);\n                /* fall thru */\n            case OP_FMT_atom:\n            case OP_FMT_atom_u8:\n            case OP_FMT_atom_u16:\n                atom = get_u32(bc_buf + pos + 1);\n                JS_FreeAtom(s->ctx, atom);\n                break;\n            default:\n                break;\n            }\n        }\n    }\n    return pos;\n}\n\nstatic int get_label_pos(JSFunctionDef *s, int label)\n{\n    int i, pos;\n    for (i = 0; i < 20; i++) {\n        pos = s->label_slots[label].pos;\n        for (;;) {\n            switch (s->byte_code.buf[pos]) {\n            case OP_line_num:\n            case OP_label:\n                pos += 5;\n                continue;\n            case OP_goto:\n                label = get_u32(s->byte_code.buf + pos + 1);\n                break;\n            default:\n                return pos;\n            }\n            break;\n        }\n    }\n    return pos;\n}\n\n/* convert global variable accesses to local variables or closure\n   variables when necessary */\nstatic __exception int resolve_variables(JSContext *ctx, JSFunctionDef *s)\n{\n    int pos, pos_next, bc_len, op, len, i, idx, arg_valid, line_num;\n    uint8_t *bc_buf;\n    JSAtom var_name;\n    DynBuf bc_out;\n    CodeContext cc;\n    int scope;\n\n    cc.bc_buf = bc_buf = s->byte_code.buf;\n    cc.bc_len = bc_len = s->byte_code.size;\n    js_dbuf_init(ctx, &bc_out);\n\n    /* first pass for runtime checks (must be done before the\n       variables are created) */\n    if (s->is_global_var) {\n        for(i = 0; i < s->hoisted_def_count; i++) {\n            JSHoistedDef *hf = &s->hoisted_def[i];\n            int flags;\n\n            if (hf->var_name != JS_ATOM_NULL) {\n                /* check if global variable (XXX: simplify) */\n                for(idx = 0; idx < s->closure_var_count; idx++) {\n                    JSClosureVar *cv = &s->closure_var[idx];\n                    if (cv->var_name == hf->var_name) {\n                        if (s->eval_type == JS_EVAL_TYPE_DIRECT &&\n                            cv->is_lexical) {\n                            /* Check if a lexical variable is\n                               redefined as 'var'. XXX: Could abort\n                               compilation here, but for consistency\n                               with the other checks, we delay the\n                               error generation. */\n                            dbuf_putc(&bc_out, OP_throw_var);\n                            dbuf_put_u32(&bc_out, JS_DupAtom(ctx, hf->var_name));\n                            dbuf_putc(&bc_out, JS_THROW_VAR_REDECL);\n                        }\n                        goto next;\n                    }\n                    if (cv->var_name == JS_ATOM__var_)\n                        goto next;\n                }\n\n                dbuf_putc(&bc_out, OP_check_define_var);\n                dbuf_put_u32(&bc_out, JS_DupAtom(ctx, hf->var_name));\n                flags = 0;\n                if (hf->is_lexical)\n                    flags |= DEFINE_GLOBAL_LEX_VAR;\n                if (hf->cpool_idx >= 0)\n                    flags |= DEFINE_GLOBAL_FUNC_VAR;\n                dbuf_putc(&bc_out, flags);\n            }\n        next: ;\n        }\n    }\n\n    arg_valid = 0;\n    line_num = 0; /* avoid warning */\n    for (pos = 0; pos < bc_len; pos = pos_next) {\n        op = bc_buf[pos];\n        len = opcode_info[op].size;\n        pos_next = pos + len;\n        switch(op) {\n        case OP_line_num:\n            line_num = get_u32(bc_buf + pos + 1);\n            s->line_number_size++;\n            goto no_change;\n\n        case OP_set_arg_valid_upto:\n            arg_valid = get_u16(bc_buf + pos + 1);\n            break;\n        case OP_eval: /* convert scope index to adjusted variable index */\n            {\n                int call_argc = get_u16(bc_buf + pos + 1);\n                scope = get_u16(bc_buf + pos + 1 + 2);\n                mark_eval_captured_variables(ctx, s, scope);\n                dbuf_putc(&bc_out, op);\n                dbuf_put_u16(&bc_out, call_argc);\n                dbuf_put_u16(&bc_out, s->scopes[scope].first + 1);\n            }\n            break;\n        case OP_apply_eval: /* convert scope index to adjusted variable index */\n            scope = get_u16(bc_buf + pos + 1);\n            mark_eval_captured_variables(ctx, s, scope);\n            dbuf_putc(&bc_out, op);\n            dbuf_put_u16(&bc_out, s->scopes[scope].first + 1);\n            break;\n        case OP_scope_get_var_undef:\n        case OP_scope_get_var:\n        case OP_scope_put_var:\n        case OP_scope_delete_var:\n        case OP_scope_get_ref:\n        case OP_scope_put_var_init:\n            var_name = get_u32(bc_buf + pos + 1);\n            scope = get_u16(bc_buf + pos + 5);\n            pos_next = resolve_scope_var(ctx, s, var_name, scope, op, &bc_out,\n                                         NULL, NULL, pos_next, arg_valid);\n            JS_FreeAtom(ctx, var_name);\n            break;\n        case OP_scope_make_ref:\n            {\n                int label;\n                LabelSlot *ls;\n                var_name = get_u32(bc_buf + pos + 1);\n                label = get_u32(bc_buf + pos + 5);\n                scope = get_u16(bc_buf + pos + 9);\n                ls = &s->label_slots[label];\n                ls->ref_count--;  /* always remove label reference */\n                pos_next = resolve_scope_var(ctx, s, var_name, scope, op, &bc_out,\n                                             bc_buf, ls, pos_next, arg_valid);\n                JS_FreeAtom(ctx, var_name);\n            }\n            break;\n        case OP_scope_get_private_field:\n        case OP_scope_get_private_field2:\n        case OP_scope_put_private_field:\n            {\n                int ret;\n                var_name = get_u32(bc_buf + pos + 1);\n                scope = get_u16(bc_buf + pos + 5);\n                ret = resolve_scope_private_field(ctx, s, var_name, scope, op, &bc_out);\n                if (ret < 0)\n                    goto fail;\n                JS_FreeAtom(ctx, var_name);\n            }\n            break;\n        case OP_gosub:\n            s->jump_size++;\n            if (OPTIMIZE) {\n                /* remove calls to empty finalizers  */\n                int label;\n                LabelSlot *ls;\n\n                label = get_u32(bc_buf + pos + 1);\n                assert(label >= 0 && label < s->label_count);\n                ls = &s->label_slots[label];\n                if (code_match(&cc, ls->pos, OP_ret, -1)) {\n                    ls->ref_count--;\n                    break;\n                }\n            }\n            goto no_change;\n        case OP_drop:\n            if (0) {\n                /* remove drops before return_undef */\n                /* do not perform this optimization in pass2 because\n                   it breaks patterns recognised in resolve_labels */\n                int pos1 = pos_next;\n                int line1 = line_num;\n                while (code_match(&cc, pos1, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line1 = cc.line_num;\n                    pos1 = cc.pos;\n                }\n                if (code_match(&cc, pos1, OP_return_undef, -1)) {\n                    pos_next = pos1;\n                    if (line1 != -1 && line1 != line_num) {\n                        line_num = line1;\n                        s->line_number_size++;\n                        dbuf_putc(&bc_out, OP_line_num);\n                        dbuf_put_u32(&bc_out, line_num);\n                    }\n                    break;\n                }\n            }\n            goto no_change;\n        case OP_insert3:\n            if (OPTIMIZE) {\n                /* Transformation: insert3 put_array_el|put_ref_value drop -> put_array_el|put_ref_value */\n                if (code_match(&cc, pos_next, M2(OP_put_array_el, OP_put_ref_value), OP_drop, -1)) {\n                    dbuf_putc(&bc_out, cc.op);\n                    pos_next = cc.pos;\n                    if (cc.line_num != -1 && cc.line_num != line_num) {\n                        line_num = cc.line_num;\n                        s->line_number_size++;\n                        dbuf_putc(&bc_out, OP_line_num);\n                        dbuf_put_u32(&bc_out, line_num);\n                    }\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_goto:\n            s->jump_size++;\n            /* fall thru */\n        case OP_tail_call:\n        case OP_tail_call_method:\n        case OP_return:\n        case OP_return_undef:\n        case OP_throw:\n        case OP_throw_var:\n        case OP_ret:\n            if (OPTIMIZE) {\n                /* remove dead code */\n                int line = -1;\n                dbuf_put(&bc_out, bc_buf + pos, len);\n                pos = skip_dead_code(s, bc_buf, bc_len, pos + len, &line);\n                pos_next = pos;\n                if (pos < bc_len && line >= 0 && line_num != line) {\n                    line_num = line;\n                    s->line_number_size++;\n                    dbuf_putc(&bc_out, OP_line_num);\n                    dbuf_put_u32(&bc_out, line_num);\n                }\n                break;\n            }\n            goto no_change;\n\n        case OP_label:\n            {\n                int label;\n                LabelSlot *ls;\n\n                label = get_u32(bc_buf + pos + 1);\n                assert(label >= 0 && label < s->label_count);\n                ls = &s->label_slots[label];\n                ls->pos2 = bc_out.size + opcode_info[op].size;\n            }\n            goto no_change;\n\n        case OP_enter_scope:\n            {\n                int scope_idx, scope = get_u16(bc_buf + pos + 1);\n\n                if (scope == 1) {\n                    instantiate_hoisted_definitions(ctx, s, &bc_out);\n                }\n\n                for(scope_idx = s->scopes[scope].first; scope_idx >= 0;) {\n                    JSVarDef *vd = &s->vars[scope_idx];\n                    if (vd->scope_level == scope) {\n                        if (vd->var_kind == JS_VAR_FUNCTION_DECL ||\n                            vd->var_kind == JS_VAR_NEW_FUNCTION_DECL) {\n                            /* Initialize lexical variable upon entering scope */\n                            dbuf_putc(&bc_out, OP_fclosure);\n                            dbuf_put_u32(&bc_out, vd->func_pool_or_scope_idx);\n                            dbuf_putc(&bc_out, OP_put_loc);\n                            dbuf_put_u16(&bc_out, scope_idx);\n                        } else {\n                            /* XXX: should check if variable can be used\n                               before initialization */\n                            dbuf_putc(&bc_out, OP_set_loc_uninitialized);\n                            dbuf_put_u16(&bc_out, scope_idx);\n                        }\n                        scope_idx = vd->scope_next;\n                    } else {\n                        break;\n                    }\n                }\n            }\n            break;\n\n        case OP_leave_scope:\n            {\n                int scope_idx, scope = get_u16(bc_buf + pos + 1);\n\n                for(scope_idx = s->scopes[scope].first; scope_idx >= 0;) {\n                    JSVarDef *vd = &s->vars[scope_idx];\n                    if (vd->scope_level == scope) {\n                        if (vd->is_captured) {\n                            dbuf_putc(&bc_out, OP_close_loc);\n                            dbuf_put_u16(&bc_out, scope_idx);\n                        }\n                        scope_idx = vd->scope_next;\n                    } else {\n                        break;\n                    }\n                }\n            }\n            break;\n\n        case OP_set_name:\n            {\n                /* remove dummy set_name opcodes */\n                JSAtom name = get_u32(bc_buf + pos + 1);\n                if (name == JS_ATOM_NULL)\n                    break;\n            }\n            goto no_change;\n\n        case OP_if_false:\n        case OP_if_true:\n        case OP_catch:\n            s->jump_size++;\n            goto no_change;\n\n        case OP_dup:\n            if (OPTIMIZE) {\n                /* Transformation: dup if_false(l1) drop, l1: if_false(l2) -> if_false(l2) */\n                /* Transformation: dup if_true(l1) drop, l1: if_true(l2) -> if_true(l2) */\n                if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), OP_drop, -1)) {\n                    int lab0, lab1, op1, pos1, line1, pos2;\n                    lab0 = lab1 = cc.label;\n                    assert(lab1 >= 0 && lab1 < s->label_count);\n                    op1 = cc.op;\n                    pos1 = cc.pos;\n                    line1 = cc.line_num;\n                    while (code_match(&cc, (pos2 = get_label_pos(s, lab1)), OP_dup, op1, OP_drop, -1)) {\n                        lab1 = cc.label;\n                    }\n                    if (code_match(&cc, pos2, op1, -1)) {\n                        s->jump_size++;\n                        update_label(s, lab0, -1);\n                        update_label(s, cc.label, +1);\n                        dbuf_putc(&bc_out, op1);\n                        dbuf_put_u32(&bc_out, cc.label);\n                        pos_next = pos1;\n                        if (line1 != -1 && line1 != line_num) {\n                            line_num = line1;\n                            s->line_number_size++;\n                            dbuf_putc(&bc_out, OP_line_num);\n                            dbuf_put_u32(&bc_out, line_num);\n                        }\n                        break;\n                    }\n                }\n            }\n            goto no_change;\n\n        case OP_nop:\n            /* remove erased code */\n            break;\n        case OP_set_class_name:\n            /* only used during parsing */\n            break;\n            \n        default:\n        no_change:\n            dbuf_put(&bc_out, bc_buf + pos, len);\n            break;\n        }\n    }\n\n    /* set the new byte code */\n    dbuf_free(&s->byte_code);\n    s->byte_code = bc_out;\n    if (dbuf_error(&s->byte_code)) {\n        JS_ThrowOutOfMemory(ctx);\n        return -1;\n    }\n    return 0;\n fail:\n    /* continue the copy to keep the atom refcounts consistent */\n    /* XXX: find a better solution ? */\n    for (; pos < bc_len; pos = pos_next) {\n        op = bc_buf[pos];\n        len = opcode_info[op].size;\n        pos_next = pos + len;\n        dbuf_put(&bc_out, bc_buf + pos, len);\n    }\n    dbuf_free(&s->byte_code);\n    s->byte_code = bc_out;\n    return -1;\n}\n\n/* the pc2line table gives a line number for each PC value */\nstatic void add_pc2line_info(JSFunctionDef *s, uint32_t pc, int line_num)\n{\n    if (s->line_number_slots != NULL\n    &&  s->line_number_count < s->line_number_size\n    &&  pc >= s->line_number_last_pc\n    &&  line_num != s->line_number_last) {\n        s->line_number_slots[s->line_number_count].pc = pc;\n        s->line_number_slots[s->line_number_count].line_num = line_num;\n        s->line_number_count++;\n        s->line_number_last_pc = pc;\n        s->line_number_last = line_num;\n    }\n}\n\nstatic void compute_pc2line_info(JSFunctionDef *s)\n{\n    if (!(s->js_mode & JS_MODE_STRIP) && s->line_number_slots) {\n        int last_line_num = s->line_num;\n        uint32_t last_pc = 0;\n        int i;\n\n        js_dbuf_init(s->ctx, &s->pc2line);\n        for (i = 0; i < s->line_number_count; i++) {\n            uint32_t pc = s->line_number_slots[i].pc;\n            int line_num = s->line_number_slots[i].line_num;\n            int diff_pc, diff_line;\n\n            if (line_num < 0)\n                continue;\n\n            diff_pc = pc - last_pc;\n            diff_line = line_num - last_line_num;\n            if (diff_line == 0 || diff_pc < 0)\n                continue;\n\n            if (diff_line >= PC2LINE_BASE &&\n                diff_line < PC2LINE_BASE + PC2LINE_RANGE &&\n                diff_pc <= PC2LINE_DIFF_PC_MAX) {\n                dbuf_putc(&s->pc2line, (diff_line - PC2LINE_BASE) +\n                          diff_pc * PC2LINE_RANGE + PC2LINE_OP_FIRST);\n            } else {\n                /* longer encoding */\n                dbuf_putc(&s->pc2line, 0);\n                dbuf_put_leb128(&s->pc2line, diff_pc);\n                dbuf_put_sleb128(&s->pc2line, diff_line);\n            }\n            last_pc = pc;\n            last_line_num = line_num;\n        }\n    }\n}\n\nstatic RelocEntry *add_reloc(JSContext *ctx, LabelSlot *ls, uint32_t addr, int size)\n{\n    RelocEntry *re;\n    re = js_malloc(ctx, sizeof(*re));\n    if (!re)\n        return NULL;\n    re->addr = addr;\n    re->size = size;\n    re->next = ls->first_reloc;\n    ls->first_reloc = re;\n    return re;\n}\n\nstatic BOOL code_has_label(CodeContext *s, int pos, int label)\n{\n    while (pos < s->bc_len) {\n        int op = s->bc_buf[pos];\n        if (op == OP_line_num) {\n            pos += 5;\n            continue;\n        }\n        if (op == OP_label) {\n            int lab = get_u32(s->bc_buf + pos + 1);\n            if (lab == label)\n                return TRUE;\n            pos += 5;\n            continue;\n        }\n        if (op == OP_goto) {\n            int lab = get_u32(s->bc_buf + pos + 1);\n            if (lab == label)\n                return TRUE;\n        }\n        break;\n    }\n    return FALSE;\n}\n\n/* return the target label, following the OP_goto jumps\n   the first opcode at destination is stored in *pop\n */\nstatic int find_jump_target(JSFunctionDef *s, int label, int *pop, int *pline)\n{\n    int i, pos, op;\n\n    update_label(s, label, -1);\n    for (i = 0; i < 10; i++) {\n        assert(label >= 0 && label < s->label_count);\n        pos = s->label_slots[label].pos2;\n        for (;;) {\n            switch(op = s->byte_code.buf[pos]) {\n            case OP_line_num:\n                if (pline)\n                    *pline = get_u32(s->byte_code.buf + pos + 1);\n                /* fall thru */\n            case OP_label:\n                pos += opcode_info[op].size;\n                continue;\n            case OP_goto:\n                label = get_u32(s->byte_code.buf + pos + 1);\n                break;\n            case OP_drop:\n                /* ignore drop opcodes if followed by OP_return_undef */\n                while (s->byte_code.buf[++pos] == OP_drop)\n                    continue;\n                if (s->byte_code.buf[pos] == OP_return_undef)\n                    op = OP_return_undef;\n                /* fall thru */\n            default:\n                goto done;\n            }\n            break;\n        }\n    }\n    /* cycle detected, could issue a warning */\n done:\n    *pop = op;\n    update_label(s, label, +1);\n    return label;\n}\n\nstatic void push_short_int(DynBuf *bc_out, int val)\n{\n#if SHORT_OPCODES\n    if (val >= -1 && val <= 7) {\n        dbuf_putc(bc_out, OP_push_0 + val);\n        return;\n    }\n    if (val == (int8_t)val) {\n        dbuf_putc(bc_out, OP_push_i8);\n        dbuf_putc(bc_out, val);\n        return;\n    }\n    if (val == (int16_t)val) {\n        dbuf_putc(bc_out, OP_push_i16);\n        dbuf_put_u16(bc_out, val);\n        return;\n    }\n#endif\n    dbuf_putc(bc_out, OP_push_i32);\n    dbuf_put_u32(bc_out, val);\n}\n\nstatic void put_short_code(DynBuf *bc_out, int op, int idx)\n{\n#if SHORT_OPCODES\n    if (idx < 4) {\n        switch (op) {\n        case OP_get_loc:\n            dbuf_putc(bc_out, OP_get_loc0 + idx);\n            return;\n        case OP_put_loc:\n            dbuf_putc(bc_out, OP_put_loc0 + idx);\n            return;\n        case OP_set_loc:\n            dbuf_putc(bc_out, OP_set_loc0 + idx);\n            return;\n        case OP_get_arg:\n            dbuf_putc(bc_out, OP_get_arg0 + idx);\n            return;\n        case OP_put_arg:\n            dbuf_putc(bc_out, OP_put_arg0 + idx);\n            return;\n        case OP_set_arg:\n            dbuf_putc(bc_out, OP_set_arg0 + idx);\n            return;\n        case OP_get_var_ref:\n            dbuf_putc(bc_out, OP_get_var_ref0 + idx);\n            return;\n        case OP_put_var_ref:\n            dbuf_putc(bc_out, OP_put_var_ref0 + idx);\n            return;\n        case OP_set_var_ref:\n            dbuf_putc(bc_out, OP_set_var_ref0 + idx);\n            return;\n        case OP_call:\n            dbuf_putc(bc_out, OP_call0 + idx);\n            return;\n        }\n    }\n    if (idx < 256) {\n        switch (op) {\n        case OP_get_loc:\n            dbuf_putc(bc_out, OP_get_loc8);\n            dbuf_putc(bc_out, idx);\n            return;\n        case OP_put_loc:\n            dbuf_putc(bc_out, OP_put_loc8);\n            dbuf_putc(bc_out, idx);\n            return;\n        case OP_set_loc:\n            dbuf_putc(bc_out, OP_set_loc8);\n            dbuf_putc(bc_out, idx);\n            return;\n        }\n    }\n#endif\n    dbuf_putc(bc_out, op);\n    dbuf_put_u16(bc_out, idx);\n}\n\n/* peephole optimizations and resolve goto/labels */\nstatic __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)\n{\n    int pos, pos_next, bc_len, op, op1, len, i, line_num;\n    const uint8_t *bc_buf;\n    DynBuf bc_out;\n    LabelSlot *label_slots, *ls;\n    RelocEntry *re, *re_next;\n    CodeContext cc;\n    int label;\n#if SHORT_OPCODES\n    JumpSlot *jp;\n#endif\n\n    label_slots = s->label_slots;\n\n    line_num = s->line_num;\n\n    cc.bc_buf = bc_buf = s->byte_code.buf;\n    cc.bc_len = bc_len = s->byte_code.size;\n    js_dbuf_init(ctx, &bc_out);\n\n#if SHORT_OPCODES\n    if (s->jump_size) {\n        s->jump_slots = js_mallocz(s->ctx, sizeof(*s->jump_slots) * s->jump_size);\n        if (s->jump_slots == NULL)\n            return -1;\n    }\n#endif\n    /* XXX: Should skip this phase if not generating SHORT_OPCODES */\n    if (s->line_number_size && !(s->js_mode & JS_MODE_STRIP)) {\n        s->line_number_slots = js_mallocz(s->ctx, sizeof(*s->line_number_slots) * s->line_number_size);\n        if (s->line_number_slots == NULL)\n            return -1;\n        s->line_number_last = s->line_num;\n        s->line_number_last_pc = 0;\n    }\n\n    /* initialize the 'home_object' variable if needed */\n    if (s->home_object_var_idx >= 0) {\n        dbuf_putc(&bc_out, OP_special_object);\n        dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_HOME_OBJECT);\n        put_short_code(&bc_out, OP_put_loc, s->home_object_var_idx);\n    }\n    /* initialize the 'this.active_func' variable if needed */\n    if (s->this_active_func_var_idx >= 0) {\n        dbuf_putc(&bc_out, OP_special_object);\n        dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_THIS_FUNC);\n        put_short_code(&bc_out, OP_put_loc, s->this_active_func_var_idx);\n    }\n    /* initialize the 'new.target' variable if needed */\n    if (s->new_target_var_idx >= 0) {\n        dbuf_putc(&bc_out, OP_special_object);\n        dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_NEW_TARGET);\n        put_short_code(&bc_out, OP_put_loc, s->new_target_var_idx);\n    }\n    /* initialize the 'this' variable if needed. In a derived class\n       constructor, this is initially uninitialized. */\n    if (s->this_var_idx >= 0) {\n        if (s->is_derived_class_constructor) {\n            dbuf_putc(&bc_out, OP_set_loc_uninitialized);\n            dbuf_put_u16(&bc_out, s->this_var_idx);\n        } else {\n            dbuf_putc(&bc_out, OP_push_this);\n            put_short_code(&bc_out, OP_put_loc, s->this_var_idx);\n        }\n    }\n    /* initialize the 'arguments' variable if needed */\n    if (s->arguments_var_idx >= 0) {\n        if ((s->js_mode & JS_MODE_STRICT) || !s->has_simple_parameter_list) {\n            dbuf_putc(&bc_out, OP_special_object);\n            dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_ARGUMENTS);\n        } else {\n            dbuf_putc(&bc_out, OP_special_object);\n            dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_MAPPED_ARGUMENTS);\n        }\n        put_short_code(&bc_out, OP_put_loc, s->arguments_var_idx);\n    }\n    /* initialize a reference to the current function if needed */\n    if (s->func_var_idx >= 0) {\n        dbuf_putc(&bc_out, OP_special_object);\n        dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_THIS_FUNC);\n        put_short_code(&bc_out, OP_put_loc, s->func_var_idx);\n    }\n    /* initialize the variable environment object if needed */\n    if (s->var_object_idx >= 0) {\n        dbuf_putc(&bc_out, OP_special_object);\n        dbuf_putc(&bc_out, OP_SPECIAL_OBJECT_VAR_OBJECT);\n        put_short_code(&bc_out, OP_put_loc, s->var_object_idx);\n    }\n\n    for (pos = 0; pos < bc_len; pos = pos_next) {\n        int val;\n        op = bc_buf[pos];\n        len = opcode_info[op].size;\n        pos_next = pos + len;\n        switch(op) {\n        case OP_line_num:\n            /* line number info (for debug). We put it in a separate\n               compressed table to reduce memory usage and get better\n               performance */\n            line_num = get_u32(bc_buf + pos + 1);\n            break;\n\n        case OP_label:\n            {\n                label = get_u32(bc_buf + pos + 1);\n                assert(label >= 0 && label < s->label_count);\n                ls = &label_slots[label];\n                assert(ls->addr == -1);\n                ls->addr = bc_out.size;\n                /* resolve the relocation entries */\n                for(re = ls->first_reloc; re != NULL; re = re_next) {\n                    int diff = ls->addr - re->addr;\n                    re_next = re->next;\n                    switch (re->size) {\n                    case 4:\n                        put_u32(bc_out.buf + re->addr, diff);\n                        break;\n                    case 2:\n                        assert(diff == (int16_t)diff);\n                        put_u16(bc_out.buf + re->addr, diff);\n                        break;\n                    case 1:\n                        assert(diff == (int8_t)diff);\n                        put_u8(bc_out.buf + re->addr, diff);\n                        break;\n                    }\n                    js_free(ctx, re);\n                }\n                ls->first_reloc = NULL;\n            }\n            break;\n\n        case OP_call:\n        case OP_call_method:\n            {\n                /* detect and transform tail calls */\n                int argc;\n                argc = get_u16(bc_buf + pos + 1);\n                if (code_match(&cc, pos_next, OP_return, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    put_short_code(&bc_out, op + 1, argc);\n                    pos_next = skip_dead_code(s, bc_buf, bc_len, cc.pos, &line_num);\n                    break;\n                }\n                add_pc2line_info(s, bc_out.size, line_num);\n                put_short_code(&bc_out, op, argc);\n                break;\n            }\n            goto no_change;\n\n        case OP_return:\n        case OP_return_undef:\n        case OP_return_async:\n        case OP_throw:\n        case OP_throw_var:\n            pos_next = skip_dead_code(s, bc_buf, bc_len, pos_next, &line_num);\n            goto no_change;\n\n        case OP_goto:\n            label = get_u32(bc_buf + pos + 1);\n        has_goto:\n            if (OPTIMIZE) {\n                int line1 = -1;\n                /* Use custom matcher because multiple labels can follow */\n                label = find_jump_target(s, label, &op1, &line1);\n                if (code_has_label(&cc, pos_next, label)) {\n                    /* jump to next instruction: remove jump */\n                    update_label(s, label, -1);\n                    break;\n                }\n                if (op1 == OP_return || op1 == OP_return_undef || op1 == OP_throw) {\n                    /* jump to return/throw: remove jump, append return/throw */\n                    /* updating the line number obfuscates assembly listing */\n                    //if (line1 >= 0) line_num = line1;\n                    update_label(s, label, -1);\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, op1);\n                    pos_next = skip_dead_code(s, bc_buf, bc_len, pos_next, &line_num);\n                    break;\n                }\n                /* XXX: should duplicate single instructions followed by goto or return */\n                /* For example, can match one of these followed by return:\n                   push_i32 / push_const / push_atom_value / get_var /\n                   undefined / null / push_false / push_true / get_ref_value /\n                   get_loc / get_arg / get_var_ref\n                 */\n            }\n            goto has_label;\n\n        case OP_gosub:\n            label = get_u32(bc_buf + pos + 1);\n            if (0 && OPTIMIZE) {\n                label = find_jump_target(s, label, &op1, NULL);\n                if (op1 == OP_ret) {\n                    update_label(s, label, -1);\n                    /* empty finally clause: remove gosub */\n                    break;\n                }\n            }\n            goto has_label;\n\n        case OP_catch:\n            label = get_u32(bc_buf + pos + 1);\n            goto has_label;\n\n        case OP_if_true:\n        case OP_if_false:\n            label = get_u32(bc_buf + pos + 1);\n            if (OPTIMIZE) {\n                label = find_jump_target(s, label, &op1, NULL);\n                /* transform if_false/if_true(l1) label(l1) -> drop label(l1) */\n                if (code_has_label(&cc, pos_next, label)) {\n                    update_label(s, label, -1);\n                    dbuf_putc(&bc_out, OP_drop);\n                    break;\n                }\n                /* transform if_false(l1) goto(l2) label(l1) -> if_false(l2) label(l1) */\n                if (code_match(&cc, pos_next, OP_goto, -1)) {\n                    int pos1 = cc.pos;\n                    int line1 = cc.line_num;\n                    if (code_has_label(&cc, pos1, label)) {\n                        if (line1 >= 0) line_num = line1;\n                        pos_next = pos1;\n                        update_label(s, label, -1);\n                        label = cc.label;\n                        op ^= OP_if_true ^ OP_if_false;\n                    }\n                }\n            }\n        has_label:\n            add_pc2line_info(s, bc_out.size, line_num);\n            if (op == OP_goto) {\n                pos_next = skip_dead_code(s, bc_buf, bc_len, pos_next, &line_num);\n            }\n            assert(label >= 0 && label < s->label_count);\n            ls = &label_slots[label];\n#if SHORT_OPCODES\n            jp = &s->jump_slots[s->jump_count++];\n            jp->op = op;\n            jp->size = 4;\n            jp->pos = bc_out.size + 1;\n            jp->label = label;\n\n            if (ls->addr == -1) {\n                int diff = ls->pos2 - pos - 1;\n                if (diff < 128 && (op == OP_if_false || op == OP_if_true || op == OP_goto)) {\n                    jp->size = 1;\n                    jp->op = OP_if_false8 + (op - OP_if_false);\n                    dbuf_putc(&bc_out, OP_if_false8 + (op - OP_if_false));\n                    dbuf_putc(&bc_out, 0);\n                    if (!add_reloc(ctx, ls, bc_out.size - 1, 1))\n                        goto fail;\n                    break;\n                }\n                if (diff < 32768 && op == OP_goto) {\n                    jp->size = 2;\n                    jp->op = OP_goto16;\n                    dbuf_putc(&bc_out, OP_goto16);\n                    dbuf_put_u16(&bc_out, 0);\n                    if (!add_reloc(ctx, ls, bc_out.size - 2, 2))\n                        goto fail;\n                    break;\n                }\n            } else {\n                int diff = ls->addr - bc_out.size - 1;\n                if (diff == (int8_t)diff && (op == OP_if_false || op == OP_if_true || op == OP_goto)) {\n                    jp->size = 1;\n                    jp->op = OP_if_false8 + (op - OP_if_false);\n                    dbuf_putc(&bc_out, OP_if_false8 + (op - OP_if_false));\n                    dbuf_putc(&bc_out, diff);\n                    break;\n                }\n                if (diff == (int16_t)diff && op == OP_goto) {\n                    jp->size = 2;\n                    jp->op = OP_goto16;\n                    dbuf_putc(&bc_out, OP_goto16);\n                    dbuf_put_u16(&bc_out, diff);\n                    break;\n                }\n            }\n#endif\n            dbuf_putc(&bc_out, op);\n            dbuf_put_u32(&bc_out, ls->addr - bc_out.size);\n            if (ls->addr == -1) {\n                /* unresolved yet: create a new relocation entry */\n                if (!add_reloc(ctx, ls, bc_out.size - 4, 4))\n                    goto fail;\n            }\n            break;\n        case OP_with_get_var:\n        case OP_with_put_var:\n        case OP_with_delete_var:\n        case OP_with_make_ref:\n        case OP_with_get_ref:\n        case OP_with_get_ref_undef:\n            {\n                JSAtom atom;\n                int is_with;\n\n                atom = get_u32(bc_buf + pos + 1);\n                label = get_u32(bc_buf + pos + 5);\n                is_with = bc_buf[pos + 9];\n                if (OPTIMIZE) {\n                    label = find_jump_target(s, label, &op1, NULL);\n                }\n                assert(label >= 0 && label < s->label_count);\n                ls = &label_slots[label];\n                add_pc2line_info(s, bc_out.size, line_num);\n#if SHORT_OPCODES\n                jp = &s->jump_slots[s->jump_count++];\n                jp->op = op;\n                jp->size = 4;\n                jp->pos = bc_out.size + 5;\n                jp->label = label;\n#endif\n                dbuf_putc(&bc_out, op);\n                dbuf_put_u32(&bc_out, atom);\n                dbuf_put_u32(&bc_out, ls->addr - bc_out.size);\n                if (ls->addr == -1) {\n                    /* unresolved yet: create a new relocation entry */\n                    if (!add_reloc(ctx, ls, bc_out.size - 4, 4))\n                        goto fail;\n                }\n                dbuf_putc(&bc_out, is_with);\n            }\n            break;\n\n        case OP_drop:\n            if (OPTIMIZE) {\n                /* remove useless drops before return */\n                if (code_match(&cc, pos_next, OP_return_undef, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_null:\n#if SHORT_OPCODES\n            if (OPTIMIZE) {\n                /* transform null strict_eq into is_null */\n                if (code_match(&cc, pos_next, OP_strict_eq, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_is_null);\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transform null strict_neq if_false/if_true -> is_null if_true/if_false */\n                if (code_match(&cc, pos_next, OP_strict_neq, M2(OP_if_false, OP_if_true), -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_is_null);\n                    pos_next = cc.pos;\n                    label = cc.label;\n                    op = cc.op ^ OP_if_false ^ OP_if_true;\n                    goto has_label;\n                }\n            }\n#endif\n            /* fall thru */\n        case OP_push_false:\n        case OP_push_true:\n            if (OPTIMIZE) {\n                val = (op == OP_push_true);\n                if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) {\n                has_constant_test:\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    if (val == cc.op - OP_if_false) {\n                        /* transform null if_false(l1) -> goto l1 */\n                        /* transform false if_false(l1) -> goto l1 */\n                        /* transform true if_true(l1) -> goto l1 */\n                        pos_next = cc.pos;\n                        op = OP_goto;\n                        label = cc.label;\n                        goto has_goto;\n                    } else {\n                        /* transform null if_true(l1) -> nop */\n                        /* transform false if_true(l1) -> nop */\n                        /* transform true if_false(l1) -> nop */\n                        pos_next = cc.pos;\n                        update_label(s, cc.label, -1);\n                        break;\n                    }\n                }\n            }\n            goto no_change;\n\n        case OP_push_i32:\n            if (OPTIMIZE) {\n                /* transform i32(val) neg -> i32(-val) */\n                val = get_i32(bc_buf + pos + 1);\n                if ((val != INT32_MIN && val != 0)\n                &&  code_match(&cc, pos_next, OP_neg, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    if (code_match(&cc, cc.pos, OP_drop, -1)) {\n                        if (cc.line_num >= 0) line_num = cc.line_num;\n                    } else {\n                        add_pc2line_info(s, bc_out.size, line_num);\n                        push_short_int(&bc_out, -val);\n                    }\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* remove push/drop pairs generated by the parser */\n                if (code_match(&cc, pos_next, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* Optimize constant tests: `if (0)`, `if (1)`, `if (!0)`... */\n                if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) {\n                    val = (val != 0);\n                    goto has_constant_test;\n                }\n                add_pc2line_info(s, bc_out.size, line_num);\n                push_short_int(&bc_out, val);\n                break;\n            }\n            goto no_change;\n\n#if SHORT_OPCODES\n        case OP_push_const:\n        case OP_fclosure:\n            if (OPTIMIZE) {\n                int idx = get_u32(bc_buf + pos + 1);\n                if (idx < 256) {\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_push_const8 + op - OP_push_const);\n                    dbuf_putc(&bc_out, idx);\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_get_field:\n            if (OPTIMIZE) {\n                JSAtom atom = get_u32(bc_buf + pos + 1);\n                if (atom == JS_ATOM_length) {\n                    JS_FreeAtom(ctx, atom);\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_get_length);\n                    break;\n                }\n            }\n            goto no_change;\n#endif\n        case OP_push_atom_value:\n            if (OPTIMIZE) {\n                JSAtom atom = get_u32(bc_buf + pos + 1);\n                /* remove push/drop pairs generated by the parser */\n                if (code_match(&cc, pos_next, OP_drop, -1)) {\n                    JS_FreeAtom(ctx, atom);\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    pos_next = cc.pos;\n                    break;\n                }\n#if SHORT_OPCODES\n                if (atom == JS_ATOM_empty_string) {\n                    JS_FreeAtom(ctx, atom);\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_push_empty_string);\n                    break;\n                }\n#endif\n            }\n            goto no_change;\n\n        case OP_to_propkey:\n        case OP_to_propkey2:\n            if (OPTIMIZE) {\n                /* remove redundant to_propkey/to_propkey2 opcodes when storing simple data */\n                if (code_match(&cc, pos_next, M3(OP_get_loc, OP_get_arg, OP_get_var_ref), -1, OP_put_array_el, -1)\n                ||  code_match(&cc, pos_next, M3(OP_push_i32, OP_push_const, OP_push_atom_value), OP_put_array_el, -1)\n                ||  code_match(&cc, pos_next, M4(OP_undefined, OP_null, OP_push_true, OP_push_false), OP_put_array_el, -1)) {\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_undefined:\n            if (OPTIMIZE) {\n                /* remove push/drop pairs generated by the parser */\n                if (code_match(&cc, pos_next, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transform undefined return -> return_undefined */\n                if (code_match(&cc, pos_next, OP_return, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_return_undef);\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transform undefined if_true(l1)/if_false(l1) -> nop/goto(l1) */\n                if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) {\n                    val = 0;\n                    goto has_constant_test;\n                }\n#if SHORT_OPCODES\n                /* transform undefined strict_eq -> is_undefined */\n                if (code_match(&cc, pos_next, OP_strict_eq, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_is_undefined);\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transform undefined strict_neq if_false/if_true -> is_undefined if_true/if_false */\n                if (code_match(&cc, pos_next, OP_strict_neq, M2(OP_if_false, OP_if_true), -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_is_undefined);\n                    pos_next = cc.pos;\n                    label = cc.label;\n                    op = cc.op ^ OP_if_false ^ OP_if_true;\n                    goto has_label;\n                }\n#endif\n            }\n            goto no_change;\n\n        case OP_insert2:\n            if (OPTIMIZE) {\n                /* Transformation:\n                   insert2 put_field(a) drop -> put_field(a)\n                   insert2 put_var_strict(a) drop -> put_var_strict(a)\n                */\n                if (code_match(&cc, pos_next, M2(OP_put_field, OP_put_var_strict), OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, cc.op);\n                    dbuf_put_u32(&bc_out, cc.atom);\n                    pos_next = cc.pos;\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_dup:\n            if (OPTIMIZE) {\n                /* Transformation: dup put_x(n) drop -> put_x(n) */\n                int op1, line2 = -1;\n                /* Transformation: dup put_x(n) -> set_x(n) */\n                if (code_match(&cc, pos_next, M3(OP_put_loc, OP_put_arg, OP_put_var_ref), -1, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    op1 = cc.op + 1;  /* put_x -> set_x */\n                    pos_next = cc.pos;\n                    if (code_match(&cc, cc.pos, OP_drop, -1)) {\n                        if (cc.line_num >= 0) line_num = cc.line_num;\n                        op1 -= 1; /* set_x drop -> put_x */\n                        pos_next = cc.pos;\n                        if (code_match(&cc, cc.pos, op1 - 1, cc.idx, -1)) {\n                            line2 = cc.line_num; /* delay line number update */\n                            op1 += 1;   /* put_x(n) get_x(n) -> set_x(n) */\n                            pos_next = cc.pos;\n                        }\n                    }\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    put_short_code(&bc_out, op1, cc.idx);\n                    if (line2 >= 0) line_num = line2;\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_get_loc:\n            if (OPTIMIZE) {\n                /* transformation:\n                   get_loc(n) post_dec put_loc(n) drop -> dec_loc(n)\n                   get_loc(n) post_inc put_loc(n) drop -> inc_loc(n)\n                   get_loc(n) dec dup put_loc(n) drop -> dec_loc(n)\n                   get_loc(n) inc dup put_loc(n) drop -> inc_loc(n)\n                 */\n                int idx;\n                idx = get_u16(bc_buf + pos + 1);\n                if (idx >= 256)\n                    goto no_change;\n                if (code_match(&cc, pos_next, M2(OP_post_dec, OP_post_inc), OP_put_loc, idx, OP_drop, -1) ||\n                    code_match(&cc, pos_next, M2(OP_dec, OP_inc), OP_dup, OP_put_loc, idx, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, (cc.op == OP_inc || cc.op == OP_post_inc) ? OP_inc_loc : OP_dec_loc);\n                    dbuf_putc(&bc_out, idx);\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transformation:\n                   get_loc(n) push_atom_value(x) add dup put_loc(n) drop -> push_atom_value(x) add_loc(n)\n                 */\n                if (code_match(&cc, pos_next, OP_push_atom_value, OP_add, OP_dup, OP_put_loc, idx, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n#if SHORT_OPCODES\n                    if (cc.atom == JS_ATOM_empty_string) {\n                        JS_FreeAtom(ctx, cc.atom);\n                        dbuf_putc(&bc_out, OP_push_empty_string);\n                    } else\n#endif\n                    {\n                        dbuf_putc(&bc_out, OP_push_atom_value);\n                        dbuf_put_u32(&bc_out, cc.atom);\n                    }\n                    dbuf_putc(&bc_out, OP_add_loc);\n                    dbuf_putc(&bc_out, idx);\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transformation:\n                   get_loc(n) push_i32(x) add dup put_loc(n) drop -> push_i32(x) add_loc(n)\n                 */\n                if (code_match(&cc, pos_next, OP_push_i32, OP_add, OP_dup, OP_put_loc, idx, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    push_short_int(&bc_out, cc.label);\n                    dbuf_putc(&bc_out, OP_add_loc);\n                    dbuf_putc(&bc_out, idx);\n                    pos_next = cc.pos;\n                    break;\n                }\n                /* transformation: XXX: also do these:\n                   get_loc(n) get_loc(x) add dup put_loc(n) drop -> get_loc(x) add_loc(n)\n                   get_loc(n) get_arg(x) add dup put_loc(n) drop -> get_arg(x) add_loc(n)\n                   get_loc(n) get_var_ref(x) add dup put_loc(n) drop -> get_var_ref(x) add_loc(n)\n                 */\n                if (code_match(&cc, pos_next, M3(OP_get_loc, OP_get_arg, OP_get_var_ref), -1, OP_add, OP_dup, OP_put_loc, idx, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    put_short_code(&bc_out, cc.op, cc.idx);\n                    dbuf_putc(&bc_out, OP_add_loc);\n                    dbuf_putc(&bc_out, idx);\n                    pos_next = cc.pos;\n                    break;\n                }\n                add_pc2line_info(s, bc_out.size, line_num);\n                put_short_code(&bc_out, op, idx);\n                break;\n            }\n            goto no_change;\n#if SHORT_OPCODES\n        case OP_get_arg:\n        case OP_get_var_ref:\n            if (OPTIMIZE) {\n                int idx;\n                idx = get_u16(bc_buf + pos + 1);\n                add_pc2line_info(s, bc_out.size, line_num);\n                put_short_code(&bc_out, op, idx);\n                break;\n            }\n            goto no_change;\n#endif\n        case OP_put_loc:\n        case OP_put_arg:\n        case OP_put_var_ref:\n            if (OPTIMIZE) {\n                /* transformation: put_x(n) get_x(n) -> set_x(n) */\n                int idx;\n                idx = get_u16(bc_buf + pos + 1);\n                if (code_match(&cc, pos_next, op - 1, idx, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    put_short_code(&bc_out, op + 1, idx);\n                    pos_next = cc.pos;\n                    break;\n                }\n                add_pc2line_info(s, bc_out.size, line_num);\n                put_short_code(&bc_out, op, idx);\n                break;\n            }\n            goto no_change;\n\n        case OP_post_inc:\n        case OP_post_dec:\n            if (OPTIMIZE) {\n                /* transformation:\n                   post_inc put_x drop -> inc put_x\n                   post_inc perm3 put_field drop -> inc put_field\n                   post_inc perm3 put_var_strict drop -> inc put_var_strict\n                   post_inc perm4 put_array_el drop -> inc put_array_el\n                 */\n                int op1, idx;\n                if (code_match(&cc, pos_next, M3(OP_put_loc, OP_put_arg, OP_put_var_ref), -1, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    op1 = cc.op;\n                    idx = cc.idx;\n                    pos_next = cc.pos;\n                    if (code_match(&cc, cc.pos, op1 - 1, idx, -1)) {\n                        if (cc.line_num >= 0) line_num = cc.line_num;\n                        op1 += 1;   /* put_x(n) get_x(n) -> set_x(n) */\n                        pos_next = cc.pos;\n                    }\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_dec + (op - OP_post_dec));\n                    put_short_code(&bc_out, op1, idx);\n                    break;\n                }\n                if (code_match(&cc, pos_next, OP_perm3, M2(OP_put_field, OP_put_var_strict), OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_dec + (op - OP_post_dec));\n                    dbuf_putc(&bc_out, cc.op);\n                    dbuf_put_u32(&bc_out, cc.atom);\n                    pos_next = cc.pos;\n                    break;\n                }\n                if (code_match(&cc, pos_next, OP_perm4, OP_put_array_el, OP_drop, -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    add_pc2line_info(s, bc_out.size, line_num);\n                    dbuf_putc(&bc_out, OP_dec + (op - OP_post_dec));\n                    dbuf_putc(&bc_out, OP_put_array_el);\n                    pos_next = cc.pos;\n                    break;\n                }\n            }\n            goto no_change;\n\n        case OP_typeof:\n            if (OPTIMIZE) {\n                /* simplify typeof tests */\n                if (code_match(&cc, pos_next, OP_push_atom_value, M4(OP_strict_eq, OP_strict_neq, OP_eq, OP_neq), -1)) {\n                    if (cc.line_num >= 0) line_num = cc.line_num;\n                    int op1 = (cc.op == OP_strict_eq || cc.op == OP_eq) ? OP_strict_eq : OP_strict_neq;\n#if SHORT_OPCODES\n                    int op2 = -1;\n                    switch (cc.atom) {\n                    case JS_ATOM_undefined:\n                        op2 = OP_is_undefined;\n                        break;\n                    case JS_ATOM_function:\n                        op2 = OP_is_function;\n                        break;\n                    }\n                    if (op2 >= 0) {\n                        /* transform typeof(s) == \"<type>\" into is_<type> */\n                        if (op1 == OP_strict_eq) {\n                            add_pc2line_info(s, bc_out.size, line_num);\n                            dbuf_putc(&bc_out, op2);\n                            JS_FreeAtom(ctx, cc.atom);\n                            pos_next = cc.pos;\n                            break;\n                        }\n                        if (op1 == OP_strict_neq && code_match(&cc, cc.pos, OP_if_false, -1)) {\n                            /* transform typeof(s) != \"<type>\" if_false into is_<type> if_true */\n                            if (cc.line_num >= 0) line_num = cc.line_num;\n                            add_pc2line_info(s, bc_out.size, line_num);\n                            dbuf_putc(&bc_out, op2);\n                            JS_FreeAtom(ctx, cc.atom);\n                            pos_next = cc.pos;\n                            label = cc.label;\n                            op = OP_if_true;\n                            goto has_label;\n                        }\n                    }\n#endif\n                    if (cc.atom == JS_ATOM_undefined) {\n                        /* transform typeof(s) == \"undefined\" into s === void 0 */\n                        add_pc2line_info(s, bc_out.size, line_num);\n                        dbuf_putc(&bc_out, OP_undefined);\n                        dbuf_putc(&bc_out, op1);\n                        JS_FreeAtom(ctx, cc.atom);\n                        pos_next = cc.pos;\n                        break;\n                    }\n                }\n            }\n            goto no_change;\n\n        default:\n        no_change:\n            add_pc2line_info(s, bc_out.size, line_num);\n            dbuf_put(&bc_out, bc_buf + pos, len);\n            break;\n        }\n    }\n\n    /* check that there were no missing labels */\n    for(i = 0; i < s->label_count; i++) {\n        assert(label_slots[i].first_reloc == NULL);\n    }\n#if SHORT_OPCODES\n    if (OPTIMIZE) {\n        /* more jump optimizations */\n        int patch_offsets = 0;\n        for (i = 0, jp = s->jump_slots; i < s->jump_count; i++, jp++) {\n            LabelSlot *ls;\n            JumpSlot *jp1;\n            int j, pos, diff, delta;\n\n            delta = 3;\n            switch (op = jp->op) {\n            case OP_goto16:\n                delta = 1;\n                /* fall thru */\n            case OP_if_false:\n            case OP_if_true:\n            case OP_goto:\n                pos = jp->pos;\n                diff = s->label_slots[jp->label].addr - pos;\n                if (diff >= -128 && diff <= 127 + delta) {\n                    //put_u8(bc_out.buf + pos, diff);\n                    jp->size = 1;\n                    if (op == OP_goto16) {\n                        bc_out.buf[pos - 1] = jp->op = OP_goto8;\n                    } else {\n                        bc_out.buf[pos - 1] = jp->op = OP_if_false8 + (op - OP_if_false);\n                    }\n                    goto shrink;\n                } else\n                if (diff == (int16_t)diff && op == OP_goto) {\n                    //put_u16(bc_out.buf + pos, diff);\n                    jp->size = 2;\n                    delta = 2;\n                    bc_out.buf[pos - 1] = jp->op = OP_goto16;\n                shrink:\n                    /* XXX: should reduce complexity, using 2 finger copy scheme */\n                    memmove(bc_out.buf + pos + jp->size, bc_out.buf + pos + jp->size + delta,\n                            bc_out.size - pos - jp->size - delta);\n                    bc_out.size -= delta;\n                    patch_offsets++;\n                    for (j = 0, ls = s->label_slots; j < s->label_count; j++, ls++) {\n                        if (ls->addr > pos)\n                            ls->addr -= delta;\n                    }\n                    for (j = i + 1, jp1 = jp + 1; j < s->jump_count; j++, jp1++) {\n                        if (jp1->pos > pos)\n                            jp1->pos -= delta;\n                    }\n                    for (j = 0; j < s->line_number_count; j++) {\n                        if (s->line_number_slots[j].pc > pos)\n                            s->line_number_slots[j].pc -= delta;\n                    }\n                    continue;\n                }\n                break;\n            }\n        }\n        if (patch_offsets) {\n            JumpSlot *jp1;\n            int j;\n            for (j = 0, jp1 = s->jump_slots; j < s->jump_count; j++, jp1++) {\n                int diff1 = s->label_slots[jp1->label].addr - jp1->pos;\n                switch (jp1->size) {\n                case 1:\n                    put_u8(bc_out.buf + jp1->pos, diff1);\n                    break;\n                case 2:\n                    put_u16(bc_out.buf + jp1->pos, diff1);\n                    break;\n                case 4:\n                    put_u32(bc_out.buf + jp1->pos, diff1);\n                    break;\n                }\n            }\n        }\n    }\n    js_free(ctx, s->jump_slots);\n    s->jump_slots = NULL;\n#endif\n    js_free(ctx, s->label_slots);\n    s->label_slots = NULL;\n    /* XXX: should delay until copying to runtime bytecode function */\n    compute_pc2line_info(s);\n    js_free(ctx, s->line_number_slots);\n    s->line_number_slots = NULL;\n    /* set the new byte code */\n    dbuf_free(&s->byte_code);\n    s->byte_code = bc_out;\n    s->use_short_opcodes = TRUE;\n    if (dbuf_error(&s->byte_code)) {\n        JS_ThrowOutOfMemory(ctx);\n        return -1;\n    }\n    return 0;\n fail:\n    /* XXX: not safe */\n    dbuf_free(&bc_out);\n    return -1;\n}\n\n/* compute the maximum stack size needed by the function */\n\ntypedef struct StackSizeState {\n    int stack_len_max;\n    uint16_t *stack_level_tab;\n} StackSizeState;\n\nstatic __exception int compute_stack_size_rec(JSContext *ctx,\n                                              JSFunctionDef *fd,\n                                              StackSizeState *s,\n                                              int pos, int op, int stack_len)\n{\n    int bc_len, diff, n_pop, pos_next;\n    const JSOpCode *oi;\n    const uint8_t *bc_buf;\n\n    if (stack_len > s->stack_len_max) {\n        s->stack_len_max = stack_len;\n        if (s->stack_len_max > JS_STACK_SIZE_MAX)\n            goto stack_overflow;\n    }\n    bc_buf = fd->byte_code.buf;\n    bc_len = fd->byte_code.size;\n    for(;;) {\n        if ((unsigned)pos >= bc_len)\n            goto buf_overflow;\n#if 0\n        printf(\"%5d: %d\\n\", pos, stack_len);\n#endif\n        if (s->stack_level_tab[pos] != 0xffff) {\n            /* already explored: check that the stack size is consistent */\n            if (s->stack_level_tab[pos] != stack_len) {\n                JS_ThrowInternalError(ctx, \"unconsistent stack size: %d %d (pc=%d)\",\n                                      s->stack_level_tab[pos], stack_len, pos);\n                return -1;\n            } else {\n                return 0;\n            }\n        } else {\n            s->stack_level_tab[pos] = stack_len;\n        }\n\n        op = bc_buf[pos];\n        if (op == 0 || op >= OP_COUNT) {\n            JS_ThrowInternalError(ctx, \"invalid opcode (op=%d, pc=%d)\", op, pos);\n            return -1;\n        }\n        oi = &short_opcode_info(op);\n        pos_next = pos + oi->size;\n        if (pos_next > bc_len) {\n        buf_overflow:\n            JS_ThrowInternalError(ctx, \"bytecode buffer overflow (op=%d, pc=%d)\", op, pos);\n            return -1;\n        }\n        n_pop = oi->n_pop;\n        /* call pops a variable number of arguments */\n        if (oi->fmt == OP_FMT_npop || oi->fmt == OP_FMT_npop_u16) {\n            n_pop += get_u16(bc_buf + pos + 1);\n        } else {\n#if SHORT_OPCODES\n            if (oi->fmt == OP_FMT_npopx) {\n                n_pop += op - OP_call0;\n            }\n#endif\n        }\n\n        if (stack_len < n_pop) {\n            JS_ThrowInternalError(ctx, \"stack underflow (op=%d, pc=%d)\", op, pos);\n            return -1;\n        }\n        stack_len += oi->n_push - n_pop;\n        if (stack_len > s->stack_len_max) {\n            s->stack_len_max = stack_len;\n            if (s->stack_len_max > JS_STACK_SIZE_MAX)\n                goto stack_overflow;\n        }\n        switch(op) {\n        case OP_tail_call:\n        case OP_tail_call_method:\n        case OP_return:\n        case OP_return_undef:\n        case OP_return_async:\n        case OP_throw:\n        case OP_throw_var:\n        case OP_ret:\n            goto done;\n        case OP_goto:\n            diff = get_u32(bc_buf + pos + 1);\n            pos_next = pos + 1 + diff;\n            break;\n#if SHORT_OPCODES\n        case OP_goto16:\n            diff = (int16_t)get_u16(bc_buf + pos + 1);\n            pos_next = pos + 1 + diff;\n            break;\n        case OP_goto8:\n            diff = (int8_t)bc_buf[pos + 1];\n            pos_next = pos + 1 + diff;\n            break;\n        case OP_if_true8:\n        case OP_if_false8:\n            diff = (int8_t)bc_buf[pos + 1];\n            if (compute_stack_size_rec(ctx, fd, s, pos + 1 + diff, op, stack_len))\n                return -1;\n            break;\n#endif\n        case OP_if_true:\n        case OP_if_false:\n        case OP_catch:\n            diff = get_u32(bc_buf + pos + 1);\n            if (compute_stack_size_rec(ctx, fd, s, pos + 1 + diff, op, stack_len))\n                return -1;\n            break;\n        case OP_gosub:\n            diff = get_u32(bc_buf + pos + 1);\n            if (compute_stack_size_rec(ctx, fd, s, pos + 1 + diff, op, stack_len + 1))\n                return -1;\n            break;\n        case OP_with_get_var:\n        case OP_with_delete_var:\n            diff = get_u32(bc_buf + pos + 5);\n            if (compute_stack_size_rec(ctx, fd, s, pos + 5 + diff, op, stack_len + 1))\n                return -1;\n            break;\n        case OP_with_make_ref:\n        case OP_with_get_ref:\n        case OP_with_get_ref_undef:\n            diff = get_u32(bc_buf + pos + 5);\n            if (compute_stack_size_rec(ctx, fd, s, pos + 5 + diff, op, stack_len + 2))\n                return -1;\n            break;\n        case OP_with_put_var:\n            diff = get_u32(bc_buf + pos + 5);\n            if (compute_stack_size_rec(ctx, fd, s, pos + 5 + diff, op, stack_len - 1))\n                return -1;\n            break;\n\n        default:\n            break;\n        }\n        pos = pos_next;\n    }\n done:\n    return 0;\n\n stack_overflow:\n    JS_ThrowInternalError(ctx, \"stack overflow (op=%d, pc=%d)\", op, pos);\n    return -1;\n}\n\nstatic __exception int compute_stack_size(JSContext *ctx,\n                                          JSFunctionDef *fd,\n                                          int *pstack_size)\n{\n    StackSizeState s_s, *s = &s_s;\n    int bc_len, i, ret;\n\n    bc_len = fd->byte_code.size;\n    /* bc_len > 0 */\n    s->stack_level_tab = js_malloc(ctx, sizeof(s->stack_level_tab[0]) * bc_len);\n    if (!s->stack_level_tab)\n        return -1;\n    for(i = 0; i < bc_len; i++)\n        s->stack_level_tab[i] = 0xffff;\n    s->stack_len_max = 0;\n    ret = compute_stack_size_rec(ctx, fd, s, 0, OP_invalid, 0);\n    js_free(ctx, s->stack_level_tab);\n    *pstack_size = s->stack_len_max;\n    return ret;\n}\n\nstatic int add_module_variables(JSContext *ctx, JSFunctionDef *fd)\n{\n    int i, idx;\n    JSModuleDef *m = fd->module;\n    JSExportEntry *me;\n    JSHoistedDef *hf;\n\n    /* The imported global variables were added as closure variables\n       in js_parse_import(). We add here the module global\n       variables. */\n\n    for(i = 0; i < fd->hoisted_def_count; i++) {\n        hf = &fd->hoisted_def[i];\n        if (add_closure_var(ctx, fd, TRUE, FALSE, i, hf->var_name, hf->is_const,\n                            hf->is_lexical, FALSE) < 0)\n            return -1;\n    }\n\n    /* resolve the variable names of the local exports */\n    for(i = 0; i < m->export_entries_count; i++) {\n        me = &m->export_entries[i];\n        if (me->export_type == JS_EXPORT_TYPE_LOCAL) {\n            idx = find_closure_var(ctx, fd, me->local_name);\n            if (idx < 0) {\n                JS_ThrowSyntaxErrorAtom(ctx, \"exported variable '%s' does not exist\",\n                                        me->local_name);\n                return -1;\n            }\n            me->u.local.var_idx = idx;\n        }\n    }\n    return 0;\n}\n\n/* create a function object from a function definition. The function\n   definition is freed. All the child functions are also created. It\n   must be done this way to resolve all the variables. */\nstatic JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)\n{\n    JSValue func_obj;\n    JSFunctionBytecode *b;\n    struct list_head *el, *el1;\n    int stack_size, scope, idx;\n    int function_size, byte_code_offset, cpool_offset;\n    int closure_var_offset, vardefs_offset;\n\n    /* recompute scope linkage */\n    for (scope = 0; scope < fd->scope_count; scope++) {\n        fd->scopes[scope].first = -1;\n    }\n    for (idx = 0; idx < fd->var_count; idx++) {\n        JSVarDef *vd = &fd->vars[idx];\n        vd->scope_next = fd->scopes[vd->scope_level].first;\n        fd->scopes[vd->scope_level].first = idx;\n    }\n    for (scope = 2; scope < fd->scope_count; scope++) {\n        JSVarScope *sd = &fd->scopes[scope];\n        if (sd->first == -1)\n            sd->first = fd->scopes[sd->parent].first;\n    }\n    for (idx = 0; idx < fd->var_count; idx++) {\n        JSVarDef *vd = &fd->vars[idx];\n        if (vd->scope_next == -1 && vd->scope_level > 1) {\n            scope = fd->scopes[vd->scope_level].parent;\n            vd->scope_next = fd->scopes[scope].first;\n        }\n    }\n\n    /* if the function contains an eval call, the closure variables\n       are used to compile the eval and they must be ordered by scope,\n       so it is necessary to create the closure variables before any\n       other variable lookup is done. */\n    if (fd->has_eval_call)\n        add_eval_variables(ctx, fd);\n\n    /* add the module global variables in the closure */\n    if (fd->module) {\n        if (add_module_variables(ctx, fd))\n            goto fail;\n    }\n\n    /* first create all the child functions */\n    list_for_each_safe(el, el1, &fd->child_list) {\n        JSFunctionDef *fd1;\n        int cpool_idx;\n\n        fd1 = list_entry(el, JSFunctionDef, link);\n        cpool_idx = fd1->parent_cpool_idx;\n        func_obj = js_create_function(ctx, fd1);\n        if (JS_IsException(func_obj))\n            goto fail;\n        /* save it in the constant pool */\n        assert(cpool_idx >= 0);\n        fd->cpool[cpool_idx] = func_obj;\n    }\n\n#if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 4)\n    if (!(fd->js_mode & JS_MODE_STRIP)) {\n        printf(\"pass 1\\n\");\n        dump_byte_code(ctx, 1, fd->byte_code.buf, fd->byte_code.size,\n                       fd->args, fd->arg_count, fd->vars, fd->var_count,\n                       fd->closure_var, fd->closure_var_count,\n                       fd->cpool, fd->cpool_count, fd->source, fd->line_num,\n                       fd->label_slots, NULL);\n        printf(\"\\n\");\n    }\n#endif\n\n    if (resolve_variables(ctx, fd))\n        goto fail;\n\n#if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 2)\n    if (!(fd->js_mode & JS_MODE_STRIP)) {\n        printf(\"pass 2\\n\");\n        dump_byte_code(ctx, 2, fd->byte_code.buf, fd->byte_code.size,\n                       fd->args, fd->arg_count, fd->vars, fd->var_count,\n                       fd->closure_var, fd->closure_var_count,\n                       fd->cpool, fd->cpool_count, fd->source, fd->line_num,\n                       fd->label_slots, NULL);\n        printf(\"\\n\");\n    }\n#endif\n\n    if (resolve_labels(ctx, fd))\n        goto fail;\n\n    if (compute_stack_size(ctx, fd, &stack_size) < 0)\n        goto fail;\n\n    if (fd->js_mode & JS_MODE_STRIP) {\n        function_size = offsetof(JSFunctionBytecode, debug);\n    } else {\n        function_size = sizeof(*b);\n    }\n    cpool_offset = function_size;\n    function_size += fd->cpool_count * sizeof(*fd->cpool);\n    vardefs_offset = function_size;\n    if (!(fd->js_mode & JS_MODE_STRIP) || fd->has_eval_call) {\n        function_size += (fd->arg_count + fd->var_count) * sizeof(*b->vardefs);\n    }\n    closure_var_offset = function_size;\n    function_size += fd->closure_var_count * sizeof(*fd->closure_var);\n    byte_code_offset = function_size;\n    function_size += fd->byte_code.size;\n\n    b = js_mallocz(ctx, function_size);\n    if (!b)\n        goto fail;\n    b->header.ref_count = 1;\n\n    b->byte_code_buf = (void *)((uint8_t*)b + byte_code_offset);\n    b->byte_code_len = fd->byte_code.size;\n    memcpy(b->byte_code_buf, fd->byte_code.buf, fd->byte_code.size);\n    js_free(ctx, fd->byte_code.buf);\n    fd->byte_code.buf = NULL;\n\n    b->func_name = fd->func_name;\n    if (fd->arg_count + fd->var_count > 0) {\n        if ((fd->js_mode & JS_MODE_STRIP) && !fd->has_eval_call) {\n            /* Strip variable definitions not needed at runtime */\n            int i;\n            for(i = 0; i < fd->var_count; i++) {\n                JS_FreeAtom(ctx, fd->vars[i].var_name);\n            }\n            for(i = 0; i < fd->arg_count; i++) {\n                JS_FreeAtom(ctx, fd->args[i].var_name);\n            }\n            for(i = 0; i < fd->closure_var_count; i++) {\n                JS_FreeAtom(ctx, fd->closure_var[i].var_name);\n                fd->closure_var[i].var_name = JS_ATOM_NULL;\n            }\n        } else {\n            b->vardefs = (void *)((uint8_t*)b + vardefs_offset);\n            memcpy(b->vardefs, fd->args, fd->arg_count * sizeof(fd->args[0]));\n            memcpy(b->vardefs + fd->arg_count, fd->vars, fd->var_count * sizeof(fd->vars[0]));\n        }\n        b->var_count = fd->var_count;\n        b->arg_count = fd->arg_count;\n        b->defined_arg_count = fd->defined_arg_count;\n        js_free(ctx, fd->args);\n        js_free(ctx, fd->vars);\n    }\n    b->cpool_count = fd->cpool_count;\n    if (b->cpool_count) {\n        b->cpool = (void *)((uint8_t*)b + cpool_offset);\n        memcpy(b->cpool, fd->cpool, b->cpool_count * sizeof(*b->cpool));\n    }\n    js_free(ctx, fd->cpool);\n    fd->cpool = NULL;\n\n    b->stack_size = stack_size;\n\n    if (fd->js_mode & JS_MODE_STRIP) {\n        JS_FreeAtom(ctx, fd->filename);\n        dbuf_free(&fd->pc2line);    // probably useless\n    } else {\n        /* XXX: source and pc2line info should be packed at the end of the\n           JSFunctionBytecode structure, avoiding allocation overhead\n         */\n        b->has_debug = 1;\n        b->debug.filename = fd->filename;\n        b->debug.line_num = fd->line_num;\n\n        //DynBuf pc2line;\n        //compute_pc2line_info(fd, &pc2line);\n        //js_free(ctx, fd->line_number_slots)\n        b->debug.pc2line_buf = js_realloc(ctx, fd->pc2line.buf, fd->pc2line.size);\n        if (!b->debug.pc2line_buf)\n            b->debug.pc2line_buf = fd->pc2line.buf;\n        b->debug.pc2line_len = fd->pc2line.size;\n        b->debug.source = fd->source;\n        b->debug.source_len = fd->source_len;\n    }\n    if (fd->scopes != fd->def_scope_array)\n        js_free(ctx, fd->scopes);\n\n    b->closure_var_count = fd->closure_var_count;\n    if (b->closure_var_count) {\n        b->closure_var = (void *)((uint8_t*)b + closure_var_offset);\n        memcpy(b->closure_var, fd->closure_var, b->closure_var_count * sizeof(*b->closure_var));\n    }\n    js_free(ctx, fd->closure_var);\n    fd->closure_var = NULL;\n\n    b->has_prototype = fd->has_prototype;\n    b->has_simple_parameter_list = fd->has_simple_parameter_list;\n    b->js_mode = fd->js_mode;\n    b->is_derived_class_constructor = fd->is_derived_class_constructor;\n    b->func_kind = fd->func_kind;\n    b->need_home_object = (fd->home_object_var_idx >= 0 ||\n                           fd->need_home_object);\n    b->new_target_allowed = fd->new_target_allowed;\n    b->super_call_allowed = fd->super_call_allowed;\n    b->super_allowed = fd->super_allowed;\n    b->arguments_allowed = fd->arguments_allowed;\n    b->backtrace_barrier = fd->backtrace_barrier;\n    b->realm = JS_DupContext(ctx);\n\n    add_gc_object(ctx->rt, &b->header, JS_GC_OBJ_TYPE_FUNCTION_BYTECODE);\n    \n#if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 1)\n    if (!(fd->js_mode & JS_MODE_STRIP)) {\n        js_dump_function_bytecode(ctx, b);\n    }\n#endif\n\n    if (fd->parent) {\n        /* remove from parent list */\n        list_del(&fd->link);\n    }\n\n    js_free(ctx, fd);\n    return JS_MKPTR(JS_TAG_FUNCTION_BYTECODE, b);\n fail:\n    js_free_function_def(ctx, fd);\n    return JS_EXCEPTION;\n}\n\nstatic void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b)\n{\n    int i;\n\n#if 0\n    {\n        char buf[ATOM_GET_STR_BUF_SIZE];\n        printf(\"freeing %s\\n\",\n               JS_AtomGetStrRT(rt, buf, sizeof(buf), b->func_name));\n    }\n#endif\n    free_bytecode_atoms(rt, b->byte_code_buf, b->byte_code_len, TRUE);\n\n    if (b->vardefs) {\n        for(i = 0; i < b->arg_count + b->var_count; i++) {\n            JS_FreeAtomRT(rt, b->vardefs[i].var_name);\n        }\n    }\n    for(i = 0; i < b->cpool_count; i++)\n        JS_FreeValueRT(rt, b->cpool[i]);\n\n    for(i = 0; i < b->closure_var_count; i++) {\n        JSClosureVar *cv = &b->closure_var[i];\n        JS_FreeAtomRT(rt, cv->var_name);\n    }\n    if (b->realm)\n        JS_FreeContext(b->realm);\n\n    JS_FreeAtomRT(rt, b->func_name);\n    if (b->has_debug) {\n        JS_FreeAtomRT(rt, b->debug.filename);\n        js_free_rt(rt, b->debug.pc2line_buf);\n        js_free_rt(rt, b->debug.source);\n    }\n\n    remove_gc_object(&b->header);\n    if (rt->gc_phase == JS_GC_PHASE_REMOVE_CYCLES && b->header.ref_count != 0) {\n        list_add_tail(&b->header.link, &rt->gc_zero_ref_count_list);\n    } else {\n        js_free_rt(rt, b);\n    }\n}\n\nstatic __exception int js_parse_directives(JSParseState *s)\n{\n    char str[20];\n    JSParsePos pos;\n    BOOL has_semi;\n\n    if (s->token.val != TOK_STRING)\n        return 0;\n\n    js_parse_get_pos(s, &pos);\n\n    while(s->token.val == TOK_STRING) {\n        /* Copy actual source string representation */\n        snprintf(str, sizeof str, \"%.*s\",\n                 (int)(s->buf_ptr - s->token.ptr - 2), s->token.ptr + 1);\n\n        if (next_token(s))\n            return -1;\n\n        has_semi = FALSE;\n        switch (s->token.val) {\n        case ';':\n            if (next_token(s))\n                return -1;\n            has_semi = TRUE;\n            break;\n        case '}':\n        case TOK_EOF:\n            has_semi = TRUE;\n            break;\n        case TOK_NUMBER:\n        case TOK_STRING:\n        case TOK_TEMPLATE:\n        case TOK_IDENT:\n        case TOK_REGEXP:\n        case TOK_DEC:\n        case TOK_INC:\n        case TOK_NULL:\n        case TOK_FALSE:\n        case TOK_TRUE:\n        case TOK_IF:\n        case TOK_RETURN:\n        case TOK_VAR:\n        case TOK_THIS:\n        case TOK_DELETE:\n        case TOK_TYPEOF:\n        case TOK_NEW:\n        case TOK_DO:\n        case TOK_WHILE:\n        case TOK_FOR:\n        case TOK_SWITCH:\n        case TOK_THROW:\n        case TOK_TRY:\n        case TOK_FUNCTION:\n        case TOK_DEBUGGER:\n        case TOK_WITH:\n        case TOK_CLASS:\n        case TOK_CONST:\n        case TOK_ENUM:\n        case TOK_EXPORT:\n        case TOK_IMPORT:\n        case TOK_SUPER:\n        case TOK_INTERFACE:\n        case TOK_LET:\n        case TOK_PACKAGE:\n        case TOK_PRIVATE:\n        case TOK_PROTECTED:\n        case TOK_PUBLIC:\n        case TOK_STATIC:\n            /* automatic insertion of ';' */\n            if (s->got_lf)\n                has_semi = TRUE;\n            break;\n        default:\n            break;\n        }\n        if (!has_semi)\n            break;\n        if (!strcmp(str, \"use strict\")) {\n            s->cur_func->has_use_strict = TRUE;\n            s->cur_func->js_mode |= JS_MODE_STRICT;\n        }\n#if !defined(DUMP_BYTECODE) || !(DUMP_BYTECODE & 8)\n        else if (!strcmp(str, \"use strip\")) {\n            s->cur_func->js_mode |= JS_MODE_STRIP;\n        }\n#endif\n#ifdef CONFIG_BIGNUM\n        else if (s->ctx->bignum_ext && !strcmp(str, \"use math\")) {\n            s->cur_func->js_mode |= JS_MODE_MATH;\n        }\n#endif\n    }\n    return js_parse_seek_token(s, &pos);\n}\n\nstatic int js_parse_function_check_names(JSParseState *s, JSFunctionDef *fd,\n                                         JSAtom func_name)\n{\n    JSAtom name;\n    int i, idx;\n\n    if (fd->js_mode & JS_MODE_STRICT) {\n        if (!fd->has_simple_parameter_list && fd->has_use_strict) {\n            return js_parse_error(s, \"\\\"use strict\\\" not allowed in function with default or destructuring parameter\");\n        }\n        if (func_name == JS_ATOM_eval || func_name == JS_ATOM_arguments) {\n            return js_parse_error(s, \"invalid function name in strict code\");\n        }\n        for (idx = 0; idx < fd->arg_count; idx++) {\n            name = fd->args[idx].var_name;\n\n            if (name == JS_ATOM_eval || name == JS_ATOM_arguments) {\n                return js_parse_error(s, \"invalid argument name in strict code\");\n            }\n        }\n    }\n    /* check async_generator case */\n    if ((fd->js_mode & JS_MODE_STRICT)\n    ||  !fd->has_simple_parameter_list\n    ||  (fd->func_type == JS_PARSE_FUNC_METHOD && fd->func_kind == JS_FUNC_ASYNC)\n    ||  fd->func_type == JS_PARSE_FUNC_ARROW\n    ||  fd->func_type == JS_PARSE_FUNC_METHOD) {\n        for (idx = 0; idx < fd->arg_count; idx++) {\n            name = fd->args[idx].var_name;\n            if (name != JS_ATOM_NULL) {\n                for (i = 0; i < idx; i++) {\n                    if (fd->args[i].var_name == name)\n                        goto duplicate;\n                }\n                /* Check if argument name duplicates a destructuring parameter */\n                /* XXX: should have a flag for such variables */\n                for (i = 0; i < fd->var_count; i++) {\n                    if (fd->vars[i].var_name == name)\n                        goto duplicate;\n                }\n            }\n        }\n    }\n    return 0;\n\nduplicate:\n    return js_parse_error(s, \"duplicate argument names not allowed in this context\");\n}\n\n/* create a function to initialize class fields */\nstatic JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s)\n{\n    JSFunctionDef *fd;\n    \n    fd = js_new_function_def(s->ctx, s->cur_func, FALSE, FALSE,\n                             s->filename, 0);\n    if (!fd)\n        return NULL;\n    fd->func_name = JS_ATOM_NULL;\n    fd->has_prototype = FALSE;\n    fd->has_home_object = TRUE;\n    \n    fd->has_arguments_binding = FALSE;\n    fd->has_this_binding = TRUE;\n    fd->is_derived_class_constructor = FALSE;\n    fd->new_target_allowed = TRUE;\n    fd->super_call_allowed = FALSE;\n    fd->super_allowed = fd->has_home_object;\n    fd->arguments_allowed = FALSE;\n    \n    fd->func_kind = JS_FUNC_NORMAL;\n    fd->func_type = JS_PARSE_FUNC_METHOD;\n    return fd;\n}\n\n/* func_name must be JS_ATOM_NULL for JS_PARSE_FUNC_STATEMENT and\n   JS_PARSE_FUNC_EXPR, JS_PARSE_FUNC_ARROW and JS_PARSE_FUNC_VAR */\nstatic __exception int js_parse_function_decl2(JSParseState *s,\n                                               JSParseFunctionEnum func_type,\n                                               JSFunctionKindEnum func_kind,\n                                               JSAtom func_name,\n                                               const uint8_t *ptr,\n                                               int function_line_num,\n                                               JSParseExportEnum export_flag,\n                                               JSFunctionDef **pfd)\n{\n    JSContext *ctx = s->ctx;\n    JSFunctionDef *fd = s->cur_func;\n    BOOL is_expr;\n    int func_idx, lexical_func_idx = -1;\n    BOOL has_opt_arg;\n    BOOL create_func_var = FALSE;\n\n    is_expr = (func_type != JS_PARSE_FUNC_STATEMENT &&\n               func_type != JS_PARSE_FUNC_VAR);\n\n    if (func_type == JS_PARSE_FUNC_STATEMENT ||\n        func_type == JS_PARSE_FUNC_VAR ||\n        func_type == JS_PARSE_FUNC_EXPR) {\n        if (func_kind == JS_FUNC_NORMAL &&\n            token_is_pseudo_keyword(s, JS_ATOM_async) &&\n            peek_token(s, TRUE) != '\\n') {\n            if (next_token(s))\n                return -1;\n            func_kind = JS_FUNC_ASYNC;\n        }\n        if (next_token(s))\n            return -1;\n        if (s->token.val == '*') {\n            if (next_token(s))\n                return -1;\n            func_kind |= JS_FUNC_GENERATOR;\n        }\n\n        if (s->token.val == TOK_IDENT) {\n            if (s->token.u.ident.is_reserved ||\n                (s->token.u.ident.atom == JS_ATOM_yield &&\n                 func_type == JS_PARSE_FUNC_EXPR &&\n                 (func_kind & JS_FUNC_GENERATOR)) ||\n                (s->token.u.ident.atom == JS_ATOM_await &&\n                 func_type == JS_PARSE_FUNC_EXPR &&\n                 (func_kind & JS_FUNC_ASYNC))) {\n                return js_parse_error_reserved_identifier(s);\n            }\n        }\n        if (s->token.val == TOK_IDENT ||\n            (((s->token.val == TOK_YIELD && !(fd->js_mode & JS_MODE_STRICT)) ||\n             (s->token.val == TOK_AWAIT && !s->is_module)) &&\n             func_type == JS_PARSE_FUNC_EXPR)) {\n            func_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n            if (next_token(s)) {\n                JS_FreeAtom(ctx, func_name);\n                return -1;\n            }\n        } else {\n            if (func_type != JS_PARSE_FUNC_EXPR &&\n                export_flag != JS_PARSE_EXPORT_DEFAULT) {\n                return js_parse_error(s, \"function name expected\");\n            }\n        }\n    } else if (func_type != JS_PARSE_FUNC_ARROW) {\n        func_name = JS_DupAtom(ctx, func_name);\n    }\n\n    if (fd->is_eval && fd->eval_type == JS_EVAL_TYPE_MODULE &&\n        (func_type == JS_PARSE_FUNC_STATEMENT || func_type == JS_PARSE_FUNC_VAR)) {\n        JSHoistedDef *hf;\n        hf = find_hoisted_def(fd, func_name);\n        /* XXX: should check scope chain */\n        if (hf && hf->scope_level == fd->scope_level) {\n            js_parse_error(s, \"invalid redefinition of global identifier in module code\");\n            JS_FreeAtom(ctx, func_name);\n            return -1;\n        }\n    }\n\n    if (func_type == JS_PARSE_FUNC_VAR) {\n        /* Create lexical name here so function closure contains it */\n        if (!(fd->js_mode & JS_MODE_STRICT)\n        &&  find_lexical_decl(ctx, fd, func_name, fd->scope_first, FALSE) < 0\n        &&  !((func_idx = find_var(ctx, fd, func_name)) >= 0 && (func_idx & ARGUMENT_VAR_OFFSET))\n        &&  !(func_name == JS_ATOM_arguments && fd->has_arguments_binding)) {\n            create_func_var = TRUE;\n        }\n        if (fd->is_eval &&\n            (fd->eval_type == JS_EVAL_TYPE_GLOBAL ||\n             fd->eval_type == JS_EVAL_TYPE_MODULE) &&\n            fd->scope_level == 1) {\n            /* avoid creating a lexical variable in the global\n               scope. XXX: check annex B */\n            JSHoistedDef *hf;\n            hf = find_hoisted_def(fd, func_name);\n            /* XXX: should check scope chain */\n            if (hf && hf->scope_level == fd->scope_level) {\n                js_parse_error(s, \"invalid redefinition of global identifier\");\n                JS_FreeAtom(ctx, func_name);\n                return -1;\n            }\n        } else {\n            /* Always create a lexical name, fail if at the same scope as\n               existing name */\n            /* Lexical variable will be initialized upon entering scope */\n            lexical_func_idx = define_var(s, fd, func_name,\n                                          func_kind != JS_FUNC_NORMAL ?\n                                          JS_VAR_DEF_NEW_FUNCTION_DECL :\n                                          JS_VAR_DEF_FUNCTION_DECL);\n            if (lexical_func_idx < 0) {\n                JS_FreeAtom(ctx, func_name);\n                return -1;\n            }\n        }\n    }\n\n    fd = js_new_function_def(ctx, fd, FALSE, is_expr,\n                             s->filename, function_line_num);\n    if (!fd) {\n        JS_FreeAtom(ctx, func_name);\n        return -1;\n    }\n    if (pfd)\n        *pfd = fd;\n    s->cur_func = fd;\n    fd->func_name = func_name;\n    /* XXX: test !fd->is_generator is always false */\n    fd->has_prototype = (func_type == JS_PARSE_FUNC_STATEMENT ||\n                         func_type == JS_PARSE_FUNC_VAR ||\n                         func_type == JS_PARSE_FUNC_EXPR) &&\n                        func_kind == JS_FUNC_NORMAL;\n    fd->has_home_object = (func_type == JS_PARSE_FUNC_METHOD ||\n                           func_type == JS_PARSE_FUNC_GETTER ||\n                           func_type == JS_PARSE_FUNC_SETTER ||\n                           func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR ||\n                           func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR);\n    fd->has_arguments_binding = (func_type != JS_PARSE_FUNC_ARROW);\n    fd->has_this_binding = fd->has_arguments_binding;\n    fd->is_derived_class_constructor = (func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR);\n    if (func_type == JS_PARSE_FUNC_ARROW) {\n        fd->new_target_allowed = fd->parent->new_target_allowed;\n        fd->super_call_allowed = fd->parent->super_call_allowed;\n        fd->super_allowed = fd->parent->super_allowed;\n        fd->arguments_allowed = fd->parent->arguments_allowed;\n    } else {\n        fd->new_target_allowed = TRUE;\n        fd->super_call_allowed = fd->is_derived_class_constructor;\n        fd->super_allowed = fd->has_home_object;\n        fd->arguments_allowed = TRUE;\n    }\n\n    /* fd->in_function_body == FALSE prevents yield/await during the parsing\n       of the arguments in generator/async functions. They are parsed as\n       regular identifiers for other function kinds. */\n    fd->func_kind = func_kind;\n    fd->func_type = func_type;\n\n    if (func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR ||\n        func_type == JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR) {\n        /* error if not invoked as a constructor */\n        emit_op(s, OP_check_ctor);\n    }\n\n    if (func_type == JS_PARSE_FUNC_CLASS_CONSTRUCTOR) {\n        emit_class_field_init(s);\n    }\n    \n    /* parse arguments */\n    fd->has_simple_parameter_list = TRUE;\n    has_opt_arg = FALSE;\n    if (func_type == JS_PARSE_FUNC_ARROW && s->token.val == TOK_IDENT) {\n        JSAtom name;\n        if (s->token.u.ident.is_reserved) {\n            js_parse_error_reserved_identifier(s);\n            goto fail;\n        }\n        name = s->token.u.ident.atom;\n        if (add_arg(ctx, fd, name) < 0)\n            goto fail;\n        fd->defined_arg_count = 1;\n    } else {\n        if (js_parse_expect(s, '('))\n            goto fail;\n\n        while (s->token.val != ')') {\n            JSAtom name;\n            BOOL rest = FALSE;\n            int idx;\n\n            if (s->token.val == TOK_ELLIPSIS) {\n                fd->has_simple_parameter_list = FALSE;\n                rest = TRUE;\n                if (next_token(s))\n                    goto fail;\n            }\n            if (s->token.val == '[' || s->token.val == '{') {\n                fd->has_simple_parameter_list = FALSE;\n                if (rest) {\n                    emit_op(s, OP_rest);\n                    emit_u16(s, fd->arg_count);\n                } else {\n                    /* unnamed arg for destructuring */\n                    idx = add_arg(ctx, fd, JS_ATOM_NULL);\n                    emit_op(s, OP_get_arg);\n                    emit_u16(s, idx);\n                }\n                if (js_parse_destructuring_element(s, TOK_VAR, 1, TRUE, -1, TRUE))\n                    goto fail;\n            } else if (s->token.val == TOK_IDENT) {\n                if (s->token.u.ident.is_reserved) {\n                    js_parse_error_reserved_identifier(s);\n                    goto fail;\n                }\n                name = s->token.u.ident.atom;\n                if (name == JS_ATOM_yield && fd->func_kind == JS_FUNC_GENERATOR) {\n                    js_parse_error_reserved_identifier(s);\n                    goto fail;\n                }\n                idx = add_arg(ctx, fd, name);\n                if (idx < 0)\n                    goto fail;\n                if (next_token(s))\n                    goto fail;\n                if (rest) {\n                    emit_op(s, OP_rest);\n                    emit_u16(s, idx);\n                    emit_op(s, OP_put_arg);\n                    emit_u16(s, idx);\n                    fd->has_simple_parameter_list = FALSE;\n                    has_opt_arg = TRUE;\n                } else if (s->token.val == '=') {\n                    fd->has_simple_parameter_list = FALSE;\n                    has_opt_arg = TRUE;\n\n                    if (next_token(s))\n                        goto fail;\n\n                    /* optimize `x = void 0` default value: no code needed */\n                    if (s->token.val == TOK_VOID) {\n                        JSParsePos pos;\n                        js_parse_get_pos(s, &pos);\n                        if (next_token(s))\n                            goto fail;\n                        if (s->token.val == TOK_NUMBER) {\n                            if (next_token(s))\n                                goto fail;\n                            if (s->token.val == ',') {\n                                if (next_token(s))\n                                    goto fail;\n                                continue;\n                            }\n                            if (s->token.val == ')') {\n                                continue;\n                            }\n                        }\n                        if (js_parse_seek_token(s, &pos))\n                            goto fail;\n                    }\n#if 0\n                    /* XXX: not correct for eval code */\n                    /* Check for a default value of `undefined`\n                       to omit default argument processing */\n                    if (s->token.val == TOK_IDENT &&\n                        s->token.u.ident.atom == JS_ATOM_undefined &&\n                        fd->parent == NULL &&\n                        ((tok = peek_token(s, FALSE)) == ',' || tok == ')')) {\n                        if (next_token(s))  /* ignore undefined token */\n                            goto fail;\n                    } else\n#endif\n                    {\n                        int label = new_label(s);\n                        if (idx > 0) {\n                            emit_op(s, OP_set_arg_valid_upto);\n                            emit_u16(s, idx);\n                        }\n                        emit_op(s, OP_get_arg);\n                        emit_u16(s, idx);\n                        emit_op(s, OP_undefined);\n                        emit_op(s, OP_strict_eq);\n                        emit_goto(s, OP_if_false, label);\n                        if (js_parse_assign_expr(s, TRUE))\n                            goto fail;\n                        set_object_name(s, name);\n                        emit_op(s, OP_put_arg);\n                        emit_u16(s, idx);\n                        emit_label(s, label);\n                    }\n                } else if (!has_opt_arg) {\n                    fd->defined_arg_count++;\n                }\n            } else {\n                js_parse_error(s, \"missing formal parameter\");\n                goto fail;\n            }\n            if (rest && s->token.val != ')') {\n                js_parse_expect(s, ')');\n                goto fail;\n            }\n            if (s->token.val == ')')\n                break;\n            if (js_parse_expect(s, ','))\n                goto fail;\n        }\n        if ((func_type == JS_PARSE_FUNC_GETTER && fd->arg_count != 0) ||\n            (func_type == JS_PARSE_FUNC_SETTER && fd->arg_count != 1)) {\n            js_parse_error(s, \"invalid number of arguments for getter or setter\");\n            goto fail;\n        }\n    }\n\n    if (next_token(s))\n        goto fail;\n\n    /* generator function: yield after the parameters are evaluated */\n    if (func_kind == JS_FUNC_GENERATOR ||\n        func_kind == JS_FUNC_ASYNC_GENERATOR)\n        emit_op(s, OP_initial_yield);\n\n    /* in generators, yield expression is forbidden during the parsing\n       of the arguments */\n    fd->in_function_body = TRUE;\n    push_scope(s);  /* enter body scope: fd->scope_level = 1 */\n\n    if (s->token.val == TOK_ARROW) {\n        if (next_token(s))\n            goto fail;\n\n        if (s->token.val != '{') {\n            if (js_parse_function_check_names(s, fd, func_name))\n                goto fail;\n\n            if (js_parse_assign_expr(s, TRUE))\n                goto fail;\n\n            if (func_kind != JS_FUNC_NORMAL)\n                emit_op(s, OP_return_async);\n            else\n                emit_op(s, OP_return);\n\n            if (!(fd->js_mode & JS_MODE_STRIP)) {\n                /* save the function source code */\n                /* the end of the function source code is after the last\n                   token of the function source stored into s->last_ptr */\n                fd->source_len = s->last_ptr - ptr;\n                fd->source = js_strndup(ctx, (const char *)ptr, fd->source_len);\n                if (!fd->source)\n                    goto fail;\n            }\n            goto done;\n        }\n    }\n\n    if (js_parse_expect(s, '{'))\n        goto fail;\n\n    if (js_parse_directives(s))\n        goto fail;\n\n    /* in strict_mode, check function and argument names */\n    if (js_parse_function_check_names(s, fd, func_name))\n        goto fail;\n\n    while (s->token.val != '}') {\n        if (js_parse_source_element(s))\n            goto fail;\n    }\n    if (!(fd->js_mode & JS_MODE_STRIP)) {\n        /* save the function source code */\n        fd->source_len = s->buf_ptr - ptr;\n        fd->source = js_strndup(ctx, (const char *)ptr, fd->source_len);\n        if (!fd->source)\n            goto fail;\n    }\n\n    if (next_token(s)) {\n        /* consume the '}' */\n        goto fail;\n    }\n\n    /* in case there is no return, add one */\n    if (js_is_live_code(s)) {\n        emit_return(s, FALSE);\n    }\ndone:\n    s->cur_func = fd->parent;\n\n    /* create the function object */\n    {\n        int idx;\n        JSAtom func_name = fd->func_name;\n\n        /* the real object will be set at the end of the compilation */\n        idx = cpool_add(s, JS_NULL);\n        fd->parent_cpool_idx = idx;\n\n        if (is_expr) {\n            /* for constructors, no code needs to be generated here */\n            if (func_type != JS_PARSE_FUNC_CLASS_CONSTRUCTOR &&\n                func_type != JS_PARSE_FUNC_DERIVED_CLASS_CONSTRUCTOR) {\n                /* OP_fclosure creates the function object from the bytecode\n                   and adds the scope information */\n                emit_op(s, OP_fclosure);\n                emit_u32(s, idx);\n                if (func_name == JS_ATOM_NULL) {\n                    emit_op(s, OP_set_name);\n                    emit_u32(s, JS_ATOM_NULL);\n                }\n            }\n        } else if (func_type == JS_PARSE_FUNC_VAR) {\n            emit_op(s, OP_fclosure);\n            emit_u32(s, idx);\n            if (create_func_var) {\n                if (s->cur_func->is_global_var) {\n                    JSHoistedDef *hf;\n                    /* the global variable must be defined at the start of the\n                       function */\n                    hf = add_hoisted_def(ctx, s->cur_func, -1, func_name, -1, FALSE);\n                    if (!hf)\n                        goto fail;\n                    /* it is considered as defined at the top level\n                       (needed for annex B.3.3.4 and B.3.3.5\n                       checks) */\n                    hf->scope_level = 0; \n                    hf->force_init = ((s->cur_func->js_mode & JS_MODE_STRICT) != 0);\n                    /* store directly into global var, bypass lexical scope */\n                    emit_op(s, OP_dup);\n                    emit_op(s, OP_scope_put_var);\n                    emit_atom(s, func_name);\n                    emit_u16(s, 0);\n                } else {\n                    /* do not call define_var to bypass lexical scope check */\n                    func_idx = find_var(ctx, s->cur_func, func_name);\n                    if (func_idx < 0) {\n                        func_idx = add_var(ctx, s->cur_func, func_name);\n                        if (func_idx < 0)\n                            goto fail;\n                    }\n                    /* store directly into local var, bypass lexical catch scope */\n                    emit_op(s, OP_dup);\n                    emit_op(s, OP_scope_put_var);\n                    emit_atom(s, func_name);\n                    emit_u16(s, 0);\n                }\n            }\n            if (lexical_func_idx >= 0) {\n                /* lexical variable will be initialized upon entering scope */\n                s->cur_func->vars[lexical_func_idx].func_pool_or_scope_idx = idx;\n                emit_op(s, OP_drop);\n            } else {\n                /* store function object into its lexical name */\n                /* XXX: could use OP_put_loc directly */\n                emit_op(s, OP_scope_put_var_init);\n                emit_atom(s, func_name);\n                emit_u16(s, s->cur_func->scope_level);\n            }\n        } else {\n            if (!s->cur_func->is_global_var) {\n                int var_idx = define_var(s, s->cur_func, func_name, JS_VAR_DEF_VAR);\n\n                if (var_idx < 0)\n                    goto fail;\n                /* the variable will be assigned at the top of the function */\n                if (!add_hoisted_def(ctx, s->cur_func, idx, JS_ATOM_NULL, var_idx, FALSE))\n                    goto fail;\n            } else {\n                JSAtom func_var_name;\n                if (func_name == JS_ATOM_NULL)\n                    func_var_name = JS_ATOM__default_; /* export default */\n                else\n                    func_var_name = func_name;\n                /* the variable will be assigned at the top of the function */\n                if (!add_hoisted_def(ctx, s->cur_func, idx, func_var_name, -1, FALSE))\n                    goto fail;\n                if (export_flag != JS_PARSE_EXPORT_NONE) {\n                    if (!add_export_entry(s, s->cur_func->module, func_var_name,\n                                          export_flag == JS_PARSE_EXPORT_NAMED ? func_var_name : JS_ATOM_default, JS_EXPORT_TYPE_LOCAL))\n                        goto fail;\n                }\n            }\n        }\n    }\n    return 0;\n fail:\n    s->cur_func = fd->parent;\n    js_free_function_def(ctx, fd);\n    if (pfd)\n        *pfd = NULL;\n    return -1;\n}\n\nstatic __exception int js_parse_function_decl(JSParseState *s,\n                                              JSParseFunctionEnum func_type,\n                                              JSFunctionKindEnum func_kind,\n                                              JSAtom func_name,\n                                              const uint8_t *ptr,\n                                              int function_line_num)\n{\n    return js_parse_function_decl2(s, func_type, func_kind, func_name, ptr,\n                                   function_line_num, JS_PARSE_EXPORT_NONE,\n                                   NULL);\n}\n\nstatic __exception int js_parse_program(JSParseState *s)\n{\n    JSFunctionDef *fd = s->cur_func;\n    int idx;\n\n    if (next_token(s))\n        return -1;\n\n    if (js_parse_directives(s))\n        return -1;\n\n    fd->is_global_var = (fd->eval_type == JS_EVAL_TYPE_GLOBAL) ||\n        (fd->eval_type == JS_EVAL_TYPE_MODULE) ||\n        !(fd->js_mode & JS_MODE_STRICT);\n\n    if (!s->is_module) {\n        /* hidden variable for the return value */\n        fd->eval_ret_idx = idx = add_var(s->ctx, fd, JS_ATOM__ret_);\n        if (idx < 0)\n            return -1;\n    }\n\n    while (s->token.val != TOK_EOF) {\n        if (js_parse_source_element(s))\n            return -1;\n    }\n\n    if (!s->is_module) {\n        /* return the value of the hidden variable eval_ret_idx  */\n        emit_op(s, OP_get_loc);\n        emit_u16(s, fd->eval_ret_idx);\n\n        emit_op(s, OP_return);\n    } else {\n        emit_op(s, OP_return_undef);\n    }\n\n    return 0;\n}\n\nstatic void js_parse_init(JSContext *ctx, JSParseState *s,\n                          const char *input, size_t input_len,\n                          const char *filename)\n{\n    memset(s, 0, sizeof(*s));\n    s->ctx = ctx;\n    s->filename = filename;\n    s->line_num = 1;\n    s->buf_ptr = (const uint8_t *)input;\n    s->buf_end = s->buf_ptr + input_len;\n    s->token.val = ' ';\n    s->token.line_num = 1;\n}\n\nstatic JSValue JS_EvalFunctionInternal(JSContext *ctx, JSValue fun_obj,\n                                       JSValueConst this_obj,\n                                       JSVarRef **var_refs, JSStackFrame *sf)\n{\n    JSValue ret_val;\n    uint32_t tag;\n\n    tag = JS_VALUE_GET_TAG(fun_obj);\n    if (tag == JS_TAG_FUNCTION_BYTECODE) {\n        fun_obj = js_closure(ctx, fun_obj, var_refs, sf);\n        ret_val = JS_CallFree(ctx, fun_obj, this_obj, 0, NULL);\n    } else if (tag == JS_TAG_MODULE) {\n        JSModuleDef *m;\n        m = JS_VALUE_GET_PTR(fun_obj);\n        /* the module refcount should be >= 2 */\n        JS_FreeValue(ctx, fun_obj);\n        if (js_create_module_function(ctx, m) < 0)\n            goto fail;\n        if (js_instantiate_module(ctx, m) < 0)\n            goto fail;\n        ret_val = js_evaluate_module(ctx, m);\n        if (JS_IsException(ret_val)) {\n        fail:\n            js_free_modules(ctx, JS_FREE_MODULE_NOT_EVALUATED);\n            return JS_EXCEPTION;\n        }\n    } else {\n        JS_FreeValue(ctx, fun_obj);\n        ret_val = JS_ThrowTypeError(ctx, \"bytecode function expected\");\n    }\n    return ret_val;\n}\n\nJSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj)\n{\n    return JS_EvalFunctionInternal(ctx, fun_obj, ctx->global_obj, NULL, NULL);\n}\n\nstatic void skip_shebang(JSParseState *s)\n{\n    const uint8_t *p = s->buf_ptr;\n    int c;\n\n    if (p[0] == '#' && p[1] == '!') {\n        p += 2;\n        while (p < s->buf_end) {\n            if (*p == '\\n' || *p == '\\r') {\n                break;\n            } else if (*p >= 0x80) {\n                c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p);\n                if (c == CP_LS || c == CP_PS) {\n                    break;\n                } else if (c == -1) {\n                    p++; /* skip invalid UTF-8 */\n                }\n            } else {\n                p++;\n            }\n        }\n        s->buf_ptr = p;\n    }\n}\n\n/* 'input' must be zero terminated i.e. input[input_len] = '\\0'. */\nstatic JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,\n                                 const char *input, size_t input_len,\n                                 const char *filename, int flags, int scope_idx)\n{\n    JSParseState s1, *s = &s1;\n    int err, js_mode, eval_type;\n    JSValue fun_obj, ret_val;\n    JSStackFrame *sf;\n    JSVarRef **var_refs;\n    JSFunctionBytecode *b;\n    JSFunctionDef *fd;\n    JSModuleDef *m;\n\n    js_parse_init(ctx, s, input, input_len, filename);\n    skip_shebang(s);\n\n    eval_type = flags & JS_EVAL_TYPE_MASK;\n    m = NULL;\n    if (eval_type == JS_EVAL_TYPE_DIRECT) {\n        JSObject *p;\n        sf = ctx->rt->current_stack_frame;\n        assert(sf != NULL);\n        assert(JS_VALUE_GET_TAG(sf->cur_func) == JS_TAG_OBJECT);\n        p = JS_VALUE_GET_OBJ(sf->cur_func);\n        assert(js_class_has_bytecode(p->class_id));\n        b = p->u.func.function_bytecode;\n        var_refs = p->u.func.var_refs;\n        js_mode = b->js_mode;\n    } else {\n        sf = NULL;\n        b = NULL;\n        var_refs = NULL;\n        js_mode = 0;\n        if (flags & JS_EVAL_FLAG_STRICT)\n            js_mode |= JS_MODE_STRICT;\n        if (flags & JS_EVAL_FLAG_STRIP)\n            js_mode |= JS_MODE_STRIP;\n        if (eval_type == JS_EVAL_TYPE_MODULE) {\n            JSAtom module_name = JS_NewAtom(ctx, filename);\n            if (module_name == JS_ATOM_NULL)\n                return JS_EXCEPTION;\n            m = js_new_module_def(ctx, module_name);\n            if (!m)\n                return JS_EXCEPTION;\n            js_mode |= JS_MODE_STRICT;\n        }\n    }\n    fd = js_new_function_def(ctx, NULL, TRUE, FALSE, filename, 1);\n    if (!fd)\n        goto fail1;\n    s->cur_func = fd;\n    fd->eval_type = eval_type;\n    fd->has_this_binding = (eval_type != JS_EVAL_TYPE_DIRECT);\n    fd->backtrace_barrier = ((flags & JS_EVAL_FLAG_BACKTRACE_BARRIER) != 0);\n    if (eval_type == JS_EVAL_TYPE_DIRECT) {\n        fd->new_target_allowed = b->new_target_allowed;\n        fd->super_call_allowed = b->super_call_allowed;\n        fd->super_allowed = b->super_allowed;\n        fd->arguments_allowed = b->arguments_allowed;\n    } else {\n        fd->new_target_allowed = FALSE;\n        fd->super_call_allowed = FALSE;\n        fd->super_allowed = FALSE;\n        fd->arguments_allowed = TRUE;\n    }\n    fd->js_mode = js_mode;\n    fd->func_name = JS_DupAtom(ctx, JS_ATOM__eval_);\n    if (b) {\n        if (add_closure_variables(ctx, fd, b, scope_idx))\n            goto fail;\n    }\n    fd->module = m;\n    s->is_module = (m != NULL);\n    s->allow_html_comments = !s->is_module;\n\n    push_scope(s); /* body scope */\n\n    err = js_parse_program(s);\n    if (err) {\n    fail:\n        free_token(s, &s->token);\n        js_free_function_def(ctx, fd);\n        goto fail1;\n    }\n\n    /* create the function object and all the enclosed functions */\n    fun_obj = js_create_function(ctx, fd);\n    if (JS_IsException(fun_obj))\n        goto fail1;\n    /* Could add a flag to avoid resolution if necessary */\n    if (m) {\n        m->func_obj = fun_obj;\n        if (js_resolve_module(ctx, m) < 0)\n            goto fail1;\n        fun_obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m));\n    }\n    if (flags & JS_EVAL_FLAG_COMPILE_ONLY) {\n        ret_val = fun_obj;\n    } else {\n        ret_val = JS_EvalFunctionInternal(ctx, fun_obj, this_obj, var_refs, sf);\n    }\n    return ret_val;\n fail1:\n    /* XXX: should free all the unresolved dependencies */\n    if (m)\n        js_free_module_def(ctx, m);\n    return JS_EXCEPTION;\n}\n\n/* the indirection is needed to make 'eval' optional */\nstatic JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,\n                               const char *input, size_t input_len,\n                               const char *filename, int flags, int scope_idx)\n{\n    if (unlikely(!ctx->eval_internal)) {\n        return JS_ThrowTypeError(ctx, \"eval is not supported\");\n    }\n    return ctx->eval_internal(ctx, this_obj, input, input_len, filename,\n                              flags, scope_idx);\n}\n\nstatic JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj,\n                             JSValueConst val, int flags, int scope_idx)\n{\n    JSValue ret;\n    const char *str;\n    size_t len;\n\n    if (!JS_IsString(val))\n        return JS_DupValue(ctx, val);\n    str = JS_ToCStringLen(ctx, &len, val);\n    if (!str)\n        return JS_EXCEPTION;\n    ret = JS_EvalInternal(ctx, this_obj, str, len, \"<input>\", flags, scope_idx);\n    JS_FreeCString(ctx, str);\n    return ret;\n\n}\n\nJSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,\n                const char *filename, int eval_flags)\n{\n    int eval_type = eval_flags & JS_EVAL_TYPE_MASK;\n    JSValue ret;\n\n    assert(eval_type == JS_EVAL_TYPE_GLOBAL ||\n           eval_type == JS_EVAL_TYPE_MODULE);\n    ret = JS_EvalInternal(ctx, ctx->global_obj, input, input_len, filename,\n                          eval_flags, -1);\n    return ret;\n}\n\nint JS_ResolveModule(JSContext *ctx, JSValueConst obj)\n{\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) {\n        JSModuleDef *m = JS_VALUE_GET_PTR(obj);\n        if (js_resolve_module(ctx, m) < 0) {\n            js_free_modules(ctx, JS_FREE_MODULE_NOT_RESOLVED);\n            return -1;\n        }\n    }\n    return 0;\n}\n\n/*******************************************************************/\n/* object list */\n\ntypedef struct {\n    JSObject *obj;\n    uint32_t hash_next; /* -1 if no next entry */\n} JSObjectListEntry;\n\n/* XXX: reuse it to optimize weak references */\ntypedef struct {\n    JSObjectListEntry *object_tab;\n    int object_count;\n    int object_size;\n    uint32_t *hash_table;\n    uint32_t hash_size;\n} JSObjectList;\n\nstatic void js_object_list_init(JSObjectList *s)\n{\n    memset(s, 0, sizeof(*s));\n}\n\nstatic uint32_t js_object_list_get_hash(JSObject *p, uint32_t hash_size)\n{\n    return ((uintptr_t)p * 3163) & (hash_size - 1);\n}\n\nstatic int js_object_list_resize_hash(JSContext *ctx, JSObjectList *s,\n                                 uint32_t new_hash_size)\n{\n    JSObjectListEntry *e;\n    uint32_t i, h, *new_hash_table;\n\n    new_hash_table = js_malloc(ctx, sizeof(new_hash_table[0]) * new_hash_size);\n    if (!new_hash_table)\n        return -1;\n    js_free(ctx, s->hash_table);\n    s->hash_table = new_hash_table;\n    s->hash_size = new_hash_size;\n    \n    for(i = 0; i < s->hash_size; i++) {\n        s->hash_table[i] = -1;\n    }\n    for(i = 0; i < s->object_count; i++) {\n        e = &s->object_tab[i];\n        h = js_object_list_get_hash(e->obj, s->hash_size); \n        e->hash_next = s->hash_table[h];\n        s->hash_table[h] = i;\n    }\n    return 0;\n}\n\n/* the reference count of 'obj' is not modified. Return 0 if OK, -1 if\n   memory error */\nstatic int js_object_list_add(JSContext *ctx, JSObjectList *s, JSObject *obj)\n{\n    JSObjectListEntry *e;\n    uint32_t h, new_hash_size;\n    \n    if (js_resize_array(ctx, (void *)&s->object_tab,\n                        sizeof(s->object_tab[0]),\n                        &s->object_size, s->object_count + 1))\n        return -1;\n    if (unlikely((s->object_count + 1) >= s->hash_size)) {\n        new_hash_size = max_uint32(s->hash_size, 4);\n        while (new_hash_size <= s->object_count)\n            new_hash_size *= 2;\n        if (js_object_list_resize_hash(ctx, s, new_hash_size))\n            return -1;\n    }\n    e = &s->object_tab[s->object_count++];\n    h = js_object_list_get_hash(obj, s->hash_size); \n    e->obj = obj;\n    e->hash_next = s->hash_table[h];\n    s->hash_table[h] = s->object_count - 1;\n    return 0;\n}\n\n/* return -1 if not present or the object index */\nstatic int js_object_list_find(JSContext *ctx, JSObjectList *s, JSObject *obj)\n{\n    JSObjectListEntry *e;\n    uint32_t h, p;\n\n    /* must test empty size because there is no hash table */\n    if (s->object_count == 0)\n        return -1;\n    h = js_object_list_get_hash(obj, s->hash_size); \n    p = s->hash_table[h];\n    while (p != -1) {\n        e = &s->object_tab[p];\n        if (e->obj == obj)\n            return p;\n        p = e->hash_next;\n    }\n    return -1;\n}\n\nstatic void js_object_list_end(JSContext *ctx, JSObjectList *s)\n{\n    js_free(ctx, s->object_tab);\n    js_free(ctx, s->hash_table);\n}\n\n/*******************************************************************/\n/* binary object writer & reader */\n\ntypedef enum BCTagEnum {\n    BC_TAG_NULL = 1,\n    BC_TAG_UNDEFINED,\n    BC_TAG_BOOL_FALSE,\n    BC_TAG_BOOL_TRUE,\n    BC_TAG_INT32,\n    BC_TAG_FLOAT64,\n    BC_TAG_STRING,\n    BC_TAG_OBJECT,\n    BC_TAG_ARRAY,\n    BC_TAG_BIG_INT,\n    BC_TAG_BIG_FLOAT,\n    BC_TAG_BIG_DECIMAL,\n    BC_TAG_TEMPLATE_OBJECT,\n    BC_TAG_FUNCTION_BYTECODE,\n    BC_TAG_MODULE,\n    BC_TAG_TYPED_ARRAY,\n    BC_TAG_ARRAY_BUFFER,\n    BC_TAG_SHARED_ARRAY_BUFFER,\n    BC_TAG_DATE,\n    BC_TAG_OBJECT_VALUE,\n    BC_TAG_OBJECT_REFERENCE,\n} BCTagEnum;\n\n#ifdef CONFIG_BIGNUM\n#define BC_BASE_VERSION 2\n#else\n#define BC_BASE_VERSION 1\n#endif\n#define BC_BE_VERSION 0x40\n#ifdef WORDS_BIGENDIAN\n#define BC_VERSION (BC_BASE_VERSION | BC_BE_VERSION)\n#else\n#define BC_VERSION BC_BASE_VERSION\n#endif\n\ntypedef struct BCWriterState {\n    JSContext *ctx;\n    DynBuf dbuf;\n    BOOL byte_swap : 8;\n    BOOL allow_bytecode : 8;\n    BOOL allow_sab : 8;\n    BOOL allow_reference : 8;\n    uint32_t first_atom;\n    uint32_t *atom_to_idx;\n    int atom_to_idx_size;\n    JSAtom *idx_to_atom;\n    int idx_to_atom_count;\n    int idx_to_atom_size;\n    uint8_t **sab_tab;\n    int sab_tab_len;\n    int sab_tab_size;\n    /* list of referenced objects (used if allow_reference = TRUE) */\n    JSObjectList object_list;\n} BCWriterState;\n\n#ifdef DUMP_READ_OBJECT\nstatic const char * const bc_tag_str[] = {\n    \"invalid\",\n    \"null\",\n    \"undefined\",\n    \"false\",\n    \"true\",\n    \"int32\",\n    \"float64\",\n    \"string\",\n    \"object\",\n    \"array\",\n    \"bigint\",\n    \"bigfloat\",\n    \"bigdecimal\",\n    \"template\",\n    \"function\",\n    \"module\",\n    \"TypedArray\",\n    \"ArrayBuffer\",\n    \"SharedArrayBuffer\",\n    \"Date\",\n    \"ObjectValue\",\n    \"ObjectReference\",\n};\n#endif\n\nstatic void bc_put_u8(BCWriterState *s, uint8_t v)\n{\n    dbuf_putc(&s->dbuf, v);\n}\n\nstatic void bc_put_u16(BCWriterState *s, uint16_t v)\n{\n    if (s->byte_swap)\n        v = bswap16(v);\n    dbuf_put_u16(&s->dbuf, v);\n}\n\nstatic __maybe_unused void bc_put_u32(BCWriterState *s, uint32_t v)\n{\n    if (s->byte_swap)\n        v = bswap32(v);\n    dbuf_put_u32(&s->dbuf, v);\n}\n\nstatic void bc_put_u64(BCWriterState *s, uint64_t v)\n{\n    if (s->byte_swap)\n        v = bswap64(v);\n    dbuf_put(&s->dbuf, (uint8_t *)&v, sizeof(v));\n}\n\nstatic void bc_put_leb128(BCWriterState *s, uint32_t v)\n{\n    dbuf_put_leb128(&s->dbuf, v);\n}\n\nstatic void bc_put_sleb128(BCWriterState *s, int32_t v)\n{\n    dbuf_put_sleb128(&s->dbuf, v);\n}\n\nstatic void bc_set_flags(uint32_t *pflags, int *pidx, uint32_t val, int n)\n{\n    *pflags = *pflags | (val << *pidx);\n    *pidx += n;\n}\n\nstatic int bc_atom_to_idx(BCWriterState *s, uint32_t *pres, JSAtom atom)\n{\n    uint32_t v;\n\n    if (atom < s->first_atom || __JS_AtomIsTaggedInt(atom)) {\n        *pres = atom;\n        return 0;\n    }\n    atom -= s->first_atom;\n    if (atom < s->atom_to_idx_size && s->atom_to_idx[atom] != 0) {\n        *pres = s->atom_to_idx[atom];\n        return 0;\n    }\n    if (atom >= s->atom_to_idx_size) {\n        int old_size, i;\n        old_size = s->atom_to_idx_size;\n        if (js_resize_array(s->ctx, (void **)&s->atom_to_idx,\n                            sizeof(s->atom_to_idx[0]), &s->atom_to_idx_size,\n                            atom + 1))\n            return -1;\n        /* XXX: could add a specific js_resize_array() function to do it */\n        for(i = old_size; i < s->atom_to_idx_size; i++)\n            s->atom_to_idx[i] = 0;\n    }\n    if (js_resize_array(s->ctx, (void **)&s->idx_to_atom,\n                        sizeof(s->idx_to_atom[0]),\n                        &s->idx_to_atom_size, s->idx_to_atom_count + 1))\n        goto fail;\n\n    v = s->idx_to_atom_count++;\n    s->idx_to_atom[v] = atom + s->first_atom;\n    v += s->first_atom;\n    s->atom_to_idx[atom] = v;\n    *pres = v;\n    return 0;\n fail:\n    *pres = 0;\n    return -1;\n}\n\nstatic int bc_put_atom(BCWriterState *s, JSAtom atom)\n{\n    uint32_t v;\n\n    if (__JS_AtomIsTaggedInt(atom)) {\n        v = (__JS_AtomToUInt32(atom) << 1) | 1;\n    } else {\n        if (bc_atom_to_idx(s, &v, atom))\n            return -1;\n        v <<= 1;\n    }\n    bc_put_leb128(s, v);\n    return 0;\n}\n\nstatic void bc_byte_swap(uint8_t *bc_buf, int bc_len)\n{\n    int pos, len, op, fmt;\n\n    pos = 0;\n    while (pos < bc_len) {\n        op = bc_buf[pos];\n        len = short_opcode_info(op).size;\n        fmt = short_opcode_info(op).fmt;\n        switch(fmt) {\n        case OP_FMT_u16:\n        case OP_FMT_i16:\n        case OP_FMT_label16:\n        case OP_FMT_npop:\n        case OP_FMT_loc:\n        case OP_FMT_arg:\n        case OP_FMT_var_ref:\n            put_u16(bc_buf + pos + 1,\n                    bswap16(get_u16(bc_buf + pos + 1)));\n            break;\n        case OP_FMT_i32:\n        case OP_FMT_u32:\n        case OP_FMT_const:\n        case OP_FMT_label:\n        case OP_FMT_atom:\n        case OP_FMT_atom_u8:\n            put_u32(bc_buf + pos + 1,\n                    bswap32(get_u32(bc_buf + pos + 1)));\n            break;\n        case OP_FMT_atom_u16:\n        case OP_FMT_label_u16:\n            put_u32(bc_buf + pos + 1,\n                    bswap32(get_u32(bc_buf + pos + 1)));\n            put_u16(bc_buf + pos + 1 + 4,\n                    bswap16(get_u16(bc_buf + pos + 1 + 4)));\n            break;\n        case OP_FMT_atom_label_u8:\n        case OP_FMT_atom_label_u16:\n            put_u32(bc_buf + pos + 1,\n                    bswap32(get_u32(bc_buf + pos + 1)));\n            put_u32(bc_buf + pos + 1 + 4,\n                    bswap32(get_u32(bc_buf + pos + 1 + 4)));\n            if (fmt == OP_FMT_atom_label_u16) {\n                put_u16(bc_buf + pos + 1 + 4 + 4,\n                        bswap16(get_u16(bc_buf + pos + 1 + 4 + 4)));\n            }\n            break;\n        case OP_FMT_npop_u16:\n            put_u16(bc_buf + pos + 1,\n                    bswap16(get_u16(bc_buf + pos + 1)));\n            put_u16(bc_buf + pos + 1 + 2,\n                    bswap16(get_u16(bc_buf + pos + 1 + 2)));\n            break;\n        default:\n            break;\n        }\n        pos += len;\n    }\n}\n\nstatic int JS_WriteFunctionBytecode(BCWriterState *s,\n                                    const uint8_t *bc_buf1, int bc_len)\n{\n    int pos, len, op;\n    JSAtom atom;\n    uint8_t *bc_buf;\n    uint32_t val;\n\n    bc_buf = js_malloc(s->ctx, bc_len);\n    if (!bc_buf)\n        return -1;\n    memcpy(bc_buf, bc_buf1, bc_len);\n\n    pos = 0;\n    while (pos < bc_len) {\n        op = bc_buf[pos];\n        len = short_opcode_info(op).size;\n        switch(short_opcode_info(op).fmt) {\n        case OP_FMT_atom:\n        case OP_FMT_atom_u8:\n        case OP_FMT_atom_u16:\n        case OP_FMT_atom_label_u8:\n        case OP_FMT_atom_label_u16:\n            atom = get_u32(bc_buf + pos + 1);\n            if (bc_atom_to_idx(s, &val, atom))\n                goto fail;\n            put_u32(bc_buf + pos + 1, val);\n            break;\n        default:\n            break;\n        }\n        pos += len;\n    }\n\n    if (s->byte_swap)\n        bc_byte_swap(bc_buf, bc_len);\n\n    dbuf_put(&s->dbuf, bc_buf, bc_len);\n\n    js_free(s->ctx, bc_buf);\n    return 0;\n fail:\n    js_free(s->ctx, bc_buf);\n    return -1;\n}\n\nstatic void JS_WriteString(BCWriterState *s, JSString *p)\n{\n    int i;\n    bc_put_leb128(s, ((uint32_t)p->len << 1) | p->is_wide_char);\n    if (p->is_wide_char) {\n        for(i = 0; i < p->len; i++)\n            bc_put_u16(s, p->u.str16[i]);\n    } else {\n        dbuf_put(&s->dbuf, p->u.str8, p->len);\n    }\n}\n\n#ifdef CONFIG_BIGNUM\nstatic int JS_WriteBigNum(BCWriterState *s, JSValueConst obj)\n{\n    uint32_t tag, tag1;\n    int64_t e;\n    JSBigFloat *bf = JS_VALUE_GET_PTR(obj);\n    bf_t *a = &bf->num;\n    size_t len, i, n1, j;\n    limb_t v;\n\n    tag = JS_VALUE_GET_TAG(obj);\n    switch(tag) {\n    case JS_TAG_BIG_INT:\n        tag1 = BC_TAG_BIG_INT;\n        break;\n    case JS_TAG_BIG_FLOAT:\n        tag1 = BC_TAG_BIG_FLOAT;\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        tag1 = BC_TAG_BIG_DECIMAL;\n        break;\n    default:\n        abort();\n    }\n    bc_put_u8(s, tag1);\n\n    /* sign + exponent */\n    if (a->expn == BF_EXP_ZERO)\n        e = 0;\n    else if (a->expn == BF_EXP_INF)\n        e = 1;\n    else if (a->expn == BF_EXP_NAN)\n        e = 2;\n    else if (a->expn >= 0)\n        e = a->expn + 3;\n    else\n        e = a->expn;\n    e = (e << 1) | a->sign;\n    if (e < INT32_MIN || e > INT32_MAX) {\n        JS_ThrowInternalError(s->ctx, \"bignum exponent is too large\");\n        return -1;\n    }\n    bc_put_sleb128(s, e);\n\n    /* mantissa */\n    if (a->len != 0) {\n        if (tag != JS_TAG_BIG_DECIMAL) {\n            i = 0;\n            while (i < a->len && a->tab[i] == 0)\n                i++;\n            assert(i < a->len);\n            v = a->tab[i];\n            n1 = sizeof(limb_t);\n            while ((v & 0xff) == 0) {\n                n1--;\n                v >>= 8;\n            }\n            i++;\n            len = (a->len - i) * sizeof(limb_t) + n1;\n            if (len > INT32_MAX) {\n                JS_ThrowInternalError(s->ctx, \"bignum is too large\");\n                return -1;\n            }\n            bc_put_leb128(s, len);\n            /* always saved in byte based little endian representation */\n            for(j = 0; j < n1; j++) {\n                dbuf_putc(&s->dbuf, v >> (j * 8));\n            }\n            for(; i < a->len; i++) {\n                limb_t v = a->tab[i];\n#if LIMB_BITS == 32\n#ifdef WORDS_BIGENDIAN\n                v = bswap32(v);\n#endif\n                dbuf_put_u32(&s->dbuf, v);\n#else\n#ifdef WORDS_BIGENDIAN\n                v = bswap64(v);\n#endif\n                dbuf_put_u64(&s->dbuf, v);\n#endif\n            }\n        } else {\n            int bpos, d;\n            uint8_t v8;\n            size_t i0;\n            \n            /* little endian BCD */\n            i = 0;\n            while (i < a->len && a->tab[i] == 0)\n                i++;\n            assert(i < a->len);\n            len = a->len * LIMB_DIGITS;\n            v = a->tab[i];\n            j = 0;\n            while ((v % 10) == 0) {\n                j++;\n                v /= 10;\n            }\n            len -= j;\n            assert(len > 0);\n            if (len > INT32_MAX) {\n                JS_ThrowInternalError(s->ctx, \"bignum is too large\");\n                return -1;\n            }\n            bc_put_leb128(s, len);\n            \n            bpos = 0;\n            v8 = 0;\n            i0 = i;\n            for(; i < a->len; i++) {\n                if (i != i0) {\n                    v = a->tab[i];\n                    j = 0;\n                }\n                for(; j < LIMB_DIGITS; j++) {\n                    d = v % 10;\n                    v /= 10;\n                    if (bpos == 0) {\n                        v8 = d;\n                        bpos = 1;\n                    } else {\n                        dbuf_putc(&s->dbuf, v8 | (d << 4));\n                        bpos = 0;\n                    }\n                }\n            }\n            /* flush the last digit */\n            if (bpos) {\n                dbuf_putc(&s->dbuf, v8);\n            }\n        }\n    }\n    return 0;\n}\n#endif /* CONFIG_BIGNUM */\n\nstatic int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj);\n\nstatic int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj)\n{\n    JSFunctionBytecode *b = JS_VALUE_GET_PTR(obj);\n    uint32_t flags;\n    int idx, i;\n    \n    bc_put_u8(s, BC_TAG_FUNCTION_BYTECODE);\n    flags = idx = 0;\n    bc_set_flags(&flags, &idx, b->has_prototype, 1);\n    bc_set_flags(&flags, &idx, b->has_simple_parameter_list, 1);\n    bc_set_flags(&flags, &idx, b->is_derived_class_constructor, 1);\n    bc_set_flags(&flags, &idx, b->need_home_object, 1);\n    bc_set_flags(&flags, &idx, b->func_kind, 2);\n    bc_set_flags(&flags, &idx, b->new_target_allowed, 1);\n    bc_set_flags(&flags, &idx, b->super_call_allowed, 1);\n    bc_set_flags(&flags, &idx, b->super_allowed, 1);\n    bc_set_flags(&flags, &idx, b->arguments_allowed, 1);\n    bc_set_flags(&flags, &idx, b->has_debug, 1);\n    bc_set_flags(&flags, &idx, b->backtrace_barrier, 1);\n    assert(idx <= 16);\n    bc_put_u16(s, flags);\n    bc_put_u8(s, b->js_mode);\n    bc_put_atom(s, b->func_name);\n    \n    bc_put_leb128(s, b->arg_count);\n    bc_put_leb128(s, b->var_count);\n    bc_put_leb128(s, b->defined_arg_count);\n    bc_put_leb128(s, b->stack_size);\n    bc_put_leb128(s, b->closure_var_count);\n    bc_put_leb128(s, b->cpool_count);\n    bc_put_leb128(s, b->byte_code_len);\n    if (b->vardefs) {\n        bc_put_leb128(s, b->arg_count + b->var_count);\n        for(i = 0; i < b->arg_count + b->var_count; i++) {\n            JSVarDef *vd = &b->vardefs[i];\n            bc_put_atom(s, vd->var_name);\n            bc_put_leb128(s, vd->scope_level);\n            bc_put_leb128(s, vd->scope_next + 1);\n            flags = idx = 0;\n            bc_set_flags(&flags, &idx, vd->var_kind, 4);\n            bc_set_flags(&flags, &idx, vd->is_func_var, 1);\n            bc_set_flags(&flags, &idx, vd->is_const, 1);\n            bc_set_flags(&flags, &idx, vd->is_lexical, 1);\n            bc_set_flags(&flags, &idx, vd->is_captured, 1);\n            assert(idx <= 8);\n            bc_put_u8(s, flags);\n        }\n    } else {\n        bc_put_leb128(s, 0);\n    }\n    \n    for(i = 0; i < b->closure_var_count; i++) {\n        JSClosureVar *cv = &b->closure_var[i];\n        bc_put_atom(s, cv->var_name);\n        bc_put_leb128(s, cv->var_idx);\n        flags = idx = 0;\n        bc_set_flags(&flags, &idx, cv->is_local, 1);\n        bc_set_flags(&flags, &idx, cv->is_arg, 1);\n        bc_set_flags(&flags, &idx, cv->is_const, 1);\n        bc_set_flags(&flags, &idx, cv->is_lexical, 1);\n        bc_set_flags(&flags, &idx, cv->var_kind, 4);\n        assert(idx <= 8);\n        bc_put_u8(s, flags);\n    }\n    \n    if (JS_WriteFunctionBytecode(s, b->byte_code_buf, b->byte_code_len))\n        goto fail;\n    \n    if (b->has_debug) {\n        bc_put_atom(s, b->debug.filename);\n        bc_put_leb128(s, b->debug.line_num);\n        bc_put_leb128(s, b->debug.pc2line_len);\n        dbuf_put(&s->dbuf, b->debug.pc2line_buf, b->debug.pc2line_len);\n    }\n    \n    for(i = 0; i < b->cpool_count; i++) {\n        if (JS_WriteObjectRec(s, b->cpool[i]))\n            goto fail;\n    }\n    return 0;\n fail:\n    return -1;\n}\n\nstatic int JS_WriteModule(BCWriterState *s, JSValueConst obj)\n{\n    JSModuleDef *m = JS_VALUE_GET_PTR(obj);\n    int i;\n    \n    bc_put_u8(s, BC_TAG_MODULE);\n    bc_put_atom(s, m->module_name);\n    \n    bc_put_leb128(s, m->req_module_entries_count);\n    for(i = 0; i < m->req_module_entries_count; i++) {\n        JSReqModuleEntry *rme = &m->req_module_entries[i];\n        bc_put_atom(s, rme->module_name);\n    }\n    \n    bc_put_leb128(s, m->export_entries_count);\n    for(i = 0; i < m->export_entries_count; i++) {\n        JSExportEntry *me = &m->export_entries[i];\n        bc_put_u8(s, me->export_type);\n        if (me->export_type == JS_EXPORT_TYPE_LOCAL) {\n            bc_put_leb128(s, me->u.local.var_idx);\n        } else {\n            bc_put_leb128(s, me->u.req_module_idx);\n            bc_put_atom(s, me->local_name);\n        }\n        bc_put_atom(s, me->export_name);\n    }\n    \n    bc_put_leb128(s, m->star_export_entries_count);\n    for(i = 0; i < m->star_export_entries_count; i++) {\n        JSStarExportEntry *se = &m->star_export_entries[i];\n        bc_put_leb128(s, se->req_module_idx);\n    }\n    \n    bc_put_leb128(s, m->import_entries_count);\n    for(i = 0; i < m->import_entries_count; i++) {\n        JSImportEntry *mi = &m->import_entries[i];\n        bc_put_leb128(s, mi->var_idx);\n        bc_put_atom(s, mi->import_name);\n        bc_put_leb128(s, mi->req_module_idx);\n    }\n    \n    if (JS_WriteObjectRec(s, m->func_obj))\n        goto fail;\n    return 0;\n fail:\n    return -1;\n}\n\nstatic int JS_WriteArray(BCWriterState *s, JSValueConst obj)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(obj);\n    uint32_t i, len;\n    JSValue val;\n    int ret;\n    BOOL is_template;\n    \n    if (s->allow_bytecode && !p->extensible) {\n        /* not extensible array: we consider it is a\n           template when we are saving bytecode */\n        bc_put_u8(s, BC_TAG_TEMPLATE_OBJECT);\n        is_template = TRUE;\n    } else {\n        bc_put_u8(s, BC_TAG_ARRAY);\n        is_template = FALSE;\n    }\n    if (js_get_length32(s->ctx, &len, obj))\n        goto fail1;\n    bc_put_leb128(s, len);\n    for(i = 0; i < len; i++) {\n        val = JS_GetPropertyUint32(s->ctx, obj, i);\n        if (JS_IsException(val))\n            goto fail1;\n        ret = JS_WriteObjectRec(s, val);\n        JS_FreeValue(s->ctx, val);\n        if (ret)\n            goto fail1;\n    }\n    if (is_template) {\n        val = JS_GetProperty(s->ctx, obj, JS_ATOM_raw);\n        if (JS_IsException(val))\n            goto fail1;\n        ret = JS_WriteObjectRec(s, val);\n        JS_FreeValue(s->ctx, val);\n        if (ret)\n            goto fail1;\n    }\n    return 0;\n fail1:\n    return -1;\n}\n\nstatic int JS_WriteObjectTag(BCWriterState *s, JSValueConst obj)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(obj);\n    uint32_t i, prop_count;\n    JSShape *sh;\n    JSShapeProperty *pr;\n    int pass;\n    JSAtom atom;\n\n    bc_put_u8(s, BC_TAG_OBJECT);\n    prop_count = 0;\n    sh = p->shape;\n    for(pass = 0; pass < 2; pass++) {\n        if (pass == 1)\n            bc_put_leb128(s, prop_count);\n        for(i = 0, pr = get_shape_prop(sh); i < sh->prop_count; i++, pr++) {\n            atom = pr->atom;\n            if (atom != JS_ATOM_NULL &&\n                JS_AtomIsString(s->ctx, atom) &&\n                (pr->flags & JS_PROP_ENUMERABLE)) {\n                if (pr->flags & JS_PROP_TMASK) {\n                    JS_ThrowTypeError(s->ctx, \"only value properties are supported\");\n                    goto fail;\n                }\n                if (pass == 0) {\n                    prop_count++;\n                } else {\n                    bc_put_atom(s, atom);\n                    if (JS_WriteObjectRec(s, p->prop[i].u.value))\n                        goto fail;\n                }\n            }\n        }\n    }\n    return 0;\n fail:\n    return -1;\n}\n\nstatic int JS_WriteTypedArray(BCWriterState *s, JSValueConst obj)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(obj);\n    JSTypedArray *ta = p->u.typed_array;\n\n    bc_put_u8(s, BC_TAG_TYPED_ARRAY);\n    bc_put_u8(s, p->class_id - JS_CLASS_UINT8C_ARRAY);\n    bc_put_leb128(s, p->u.array.count);\n    bc_put_leb128(s, ta->offset);\n    if (JS_WriteObjectRec(s, JS_MKPTR(JS_TAG_OBJECT, ta->buffer)))\n        return -1;\n    return 0;\n}\n\nstatic int JS_WriteArrayBuffer(BCWriterState *s, JSValueConst obj)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(obj);\n    JSArrayBuffer *abuf = p->u.array_buffer;\n    if (abuf->detached) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(s->ctx);\n        return -1;\n    }\n    bc_put_u8(s, BC_TAG_ARRAY_BUFFER);\n    bc_put_leb128(s, abuf->byte_length);\n    dbuf_put(&s->dbuf, abuf->data, abuf->byte_length);\n    return 0;\n}\n\nstatic int JS_WriteSharedArrayBuffer(BCWriterState *s, JSValueConst obj)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(obj);\n    JSArrayBuffer *abuf = p->u.array_buffer;\n    assert(!abuf->detached); /* SharedArrayBuffer are never detached */\n    bc_put_u8(s, BC_TAG_SHARED_ARRAY_BUFFER);\n    bc_put_leb128(s, abuf->byte_length);\n    bc_put_u64(s, (uintptr_t)abuf->data);\n    if (js_resize_array(s->ctx, (void **)&s->sab_tab, sizeof(s->sab_tab[0]),\n                        &s->sab_tab_size, s->sab_tab_len + 1))\n        return -1;\n    /* keep the SAB pointer so that the user can clone it or free it */\n    s->sab_tab[s->sab_tab_len++] = abuf->data;\n    return 0;\n}\n\nstatic int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj)\n{\n    uint32_t tag;\n\n    if (js_check_stack_overflow(s->ctx->rt, 0)) {\n        JS_ThrowStackOverflow(s->ctx);\n        return -1;\n    }\n\n    tag = JS_VALUE_GET_NORM_TAG(obj);\n    switch(tag) {\n    case JS_TAG_NULL:\n        bc_put_u8(s, BC_TAG_NULL);\n        break;\n    case JS_TAG_UNDEFINED:\n        bc_put_u8(s, BC_TAG_UNDEFINED);\n        break;\n    case JS_TAG_BOOL:\n        bc_put_u8(s, BC_TAG_BOOL_FALSE + JS_VALUE_GET_INT(obj));\n        break;\n    case JS_TAG_INT:\n        bc_put_u8(s, BC_TAG_INT32);\n        bc_put_sleb128(s, JS_VALUE_GET_INT(obj));\n        break;\n    case JS_TAG_FLOAT64:\n        {\n            JSFloat64Union u;\n            bc_put_u8(s, BC_TAG_FLOAT64);\n            u.d = JS_VALUE_GET_FLOAT64(obj);\n            bc_put_u64(s, u.u64);\n        }\n        break;\n    case JS_TAG_STRING:\n        {\n            JSString *p = JS_VALUE_GET_STRING(obj);\n            bc_put_u8(s, BC_TAG_STRING);\n            JS_WriteString(s, p);\n        }\n        break;\n    case JS_TAG_FUNCTION_BYTECODE:\n        if (!s->allow_bytecode)\n            goto invalid_tag;\n        if (JS_WriteFunctionTag(s, obj))\n            goto fail;\n        break;\n    case JS_TAG_MODULE:\n        if (!s->allow_bytecode)\n            goto invalid_tag;\n        if (JS_WriteModule(s, obj))\n            goto fail;\n        break;\n    case JS_TAG_OBJECT:\n        {\n            JSObject *p = JS_VALUE_GET_OBJ(obj);\n            int ret, idx;\n            \n            if (s->allow_reference) {\n                idx = js_object_list_find(s->ctx, &s->object_list, p);\n                if (idx >= 0) {\n                    bc_put_u8(s, BC_TAG_OBJECT_REFERENCE);\n                    bc_put_leb128(s, idx);\n                    break;\n                } else {\n                    if (js_object_list_add(s->ctx, &s->object_list, p))\n                        goto fail;\n                }\n            } else {\n                if (p->tmp_mark) {\n                    JS_ThrowTypeError(s->ctx, \"circular reference\");\n                    goto fail;\n                }\n                p->tmp_mark = 1;\n            }\n            switch(p->class_id) {\n            case JS_CLASS_ARRAY:\n                ret = JS_WriteArray(s, obj);\n                break;\n            case JS_CLASS_OBJECT:\n                ret = JS_WriteObjectTag(s, obj);\n                break;\n            case JS_CLASS_ARRAY_BUFFER:\n                ret = JS_WriteArrayBuffer(s, obj);\n                break;\n            case JS_CLASS_SHARED_ARRAY_BUFFER:\n                if (!s->allow_sab)\n                    goto invalid_tag;\n                ret = JS_WriteSharedArrayBuffer(s, obj);\n                break;\n            case JS_CLASS_DATE:\n                bc_put_u8(s, BC_TAG_DATE);\n                ret = JS_WriteObjectRec(s, p->u.object_data);\n                break;\n            case JS_CLASS_NUMBER:\n            case JS_CLASS_STRING:\n            case JS_CLASS_BOOLEAN:\n#ifdef CONFIG_BIGNUM\n            case JS_CLASS_BIG_INT:\n            case JS_CLASS_BIG_FLOAT:\n            case JS_CLASS_BIG_DECIMAL:\n#endif\n                bc_put_u8(s, BC_TAG_OBJECT_VALUE);\n                ret = JS_WriteObjectRec(s, p->u.object_data);\n                break;\n            default:\n                if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                    p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                    ret = JS_WriteTypedArray(s, obj);\n                } else {\n                    JS_ThrowTypeError(s->ctx, \"unsupported object class\");\n                    ret = -1;\n                }\n                break;\n            }\n            p->tmp_mark = 0;\n            if (ret)\n                goto fail;\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n    case JS_TAG_BIG_DECIMAL:\n        if (JS_WriteBigNum(s, obj))\n            goto fail;\n        break;\n#endif\n    default:\n    invalid_tag:\n        JS_ThrowInternalError(s->ctx, \"unsupported tag (%d)\", tag);\n        goto fail;\n    }\n    return 0;\n\n fail:\n    return -1;\n}\n\n/* create the atom table */\nstatic int JS_WriteObjectAtoms(BCWriterState *s)\n{\n    JSRuntime *rt = s->ctx->rt;\n    DynBuf dbuf1;\n    int i, atoms_size;\n    uint8_t version;\n\n    dbuf1 = s->dbuf;\n    js_dbuf_init(s->ctx, &s->dbuf);\n\n    version = BC_VERSION;\n    if (s->byte_swap)\n        version ^= BC_BE_VERSION;\n    bc_put_u8(s, version);\n\n    bc_put_leb128(s, s->idx_to_atom_count);\n    for(i = 0; i < s->idx_to_atom_count; i++) {\n        JSAtomStruct *p = rt->atom_array[s->idx_to_atom[i]];\n        JS_WriteString(s, p);\n    }\n    /* XXX: should check for OOM in above phase */\n\n    /* move the atoms at the start */\n    /* XXX: could just append dbuf1 data, but it uses more memory if\n       dbuf1 is larger than dbuf */\n    atoms_size = s->dbuf.size;\n    if (dbuf_realloc(&dbuf1, dbuf1.size + atoms_size))\n        goto fail;\n    memmove(dbuf1.buf + atoms_size, dbuf1.buf, dbuf1.size);\n    memcpy(dbuf1.buf, s->dbuf.buf, atoms_size);\n    dbuf1.size += atoms_size;\n    dbuf_free(&s->dbuf);\n    s->dbuf = dbuf1;\n    return 0;\n fail:\n    dbuf_free(&dbuf1);\n    return -1;\n}\n\nuint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,\n                         int flags, uint8_t ***psab_tab, size_t *psab_tab_len)\n{\n    BCWriterState ss, *s = &ss;\n\n    memset(s, 0, sizeof(*s));\n    s->ctx = ctx;\n    /* XXX: byte swapped output is untested */\n    s->byte_swap = ((flags & JS_WRITE_OBJ_BSWAP) != 0);\n    s->allow_bytecode = ((flags & JS_WRITE_OBJ_BYTECODE) != 0);\n    s->allow_sab = ((flags & JS_WRITE_OBJ_SAB) != 0);\n    s->allow_reference = ((flags & JS_WRITE_OBJ_REFERENCE) != 0);\n    /* XXX: could use a different version when bytecode is included */\n    if (s->allow_bytecode)\n        s->first_atom = JS_ATOM_END;\n    else\n        s->first_atom = 1;\n    js_dbuf_init(ctx, &s->dbuf);\n    js_object_list_init(&s->object_list);\n    \n    if (JS_WriteObjectRec(s, obj))\n        goto fail;\n    if (JS_WriteObjectAtoms(s))\n        goto fail;\n    js_object_list_end(ctx, &s->object_list);\n    js_free(ctx, s->atom_to_idx);\n    js_free(ctx, s->idx_to_atom);\n    *psize = s->dbuf.size;\n    if (psab_tab)\n        *psab_tab = s->sab_tab;\n    if (psab_tab_len)\n        *psab_tab_len = s->sab_tab_len;\n    return s->dbuf.buf;\n fail:\n    js_object_list_end(ctx, &s->object_list);\n    js_free(ctx, s->atom_to_idx);\n    js_free(ctx, s->idx_to_atom);\n    dbuf_free(&s->dbuf);\n    *psize = 0;\n    if (psab_tab)\n        *psab_tab = NULL;\n    if (psab_tab_len)\n        *psab_tab_len = 0;\n    return NULL;\n}\n\nuint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj,\n                        int flags)\n{\n    return JS_WriteObject2(ctx, psize, obj, flags, NULL, NULL);\n}\n\ntypedef struct BCReaderState {\n    JSContext *ctx;\n    const uint8_t *buf_start, *ptr, *buf_end;\n    uint32_t first_atom;\n    uint32_t idx_to_atom_count;\n    JSAtom *idx_to_atom;\n    int error_state;\n    BOOL allow_sab : 8;\n    BOOL allow_bytecode : 8;\n    BOOL is_rom_data : 8;\n    BOOL allow_reference : 8;\n    /* object references */\n    JSObject **objects;\n    int objects_count;\n    int objects_size;\n    \n#ifdef DUMP_READ_OBJECT\n    const uint8_t *ptr_last;\n    int level;\n#endif\n} BCReaderState;\n\n#ifdef DUMP_READ_OBJECT\nstatic void __attribute__((format(printf, 2, 3))) bc_read_trace(BCReaderState *s, const char *fmt, ...) {\n    va_list ap;\n    int i, n, n0;\n\n    if (!s->ptr_last)\n        s->ptr_last = s->buf_start;\n\n    n = n0 = 0;\n    if (s->ptr > s->ptr_last || s->ptr == s->buf_start) {\n        n0 = printf(\"%04x: \", (int)(s->ptr_last - s->buf_start));\n        n += n0;\n    }\n    for (i = 0; s->ptr_last < s->ptr; i++) {\n        if ((i & 7) == 0 && i > 0) {\n            printf(\"\\n%*s\", n0, \"\");\n            n = n0;\n        }\n        n += printf(\" %02x\", *s->ptr_last++);\n    }\n    if (*fmt == '}')\n        s->level--;\n    if (n < 32 + s->level * 2) {\n        printf(\"%*s\", 32 + s->level * 2 - n, \"\");\n    }\n    va_start(ap, fmt);\n    vfprintf(stdout, fmt, ap);\n    va_end(ap);\n    if (strchr(fmt, '{'))\n        s->level++;\n}\n#else\n#define bc_read_trace(...)\n#endif\n\nstatic int bc_read_error_end(BCReaderState *s)\n{\n    if (!s->error_state) {\n        JS_ThrowSyntaxError(s->ctx, \"read after the end of the buffer\");\n    }\n    return s->error_state = -1;\n}\n\nstatic int bc_get_u8(BCReaderState *s, uint8_t *pval)\n{\n    if (unlikely(s->buf_end - s->ptr < 1)) {\n        *pval = 0; /* avoid warning */\n        return bc_read_error_end(s);\n    }\n    *pval = *s->ptr++;\n    return 0;\n}\n\nstatic int bc_get_u16(BCReaderState *s, uint16_t *pval)\n{\n    if (unlikely(s->buf_end - s->ptr < 2)) {\n        *pval = 0; /* avoid warning */\n        return bc_read_error_end(s);\n    }\n    *pval = get_u16(s->ptr);\n    s->ptr += 2;\n    return 0;\n}\n\nstatic __maybe_unused int bc_get_u32(BCReaderState *s, uint32_t *pval)\n{\n    if (unlikely(s->buf_end - s->ptr < 4)) {\n        *pval = 0; /* avoid warning */\n        return bc_read_error_end(s);\n    }\n    *pval = get_u32(s->ptr);\n    s->ptr += 4;\n    return 0;\n}\n\nstatic int bc_get_u64(BCReaderState *s, uint64_t *pval)\n{\n    if (unlikely(s->buf_end - s->ptr < 8)) {\n        *pval = 0; /* avoid warning */\n        return bc_read_error_end(s);\n    }\n    *pval = get_u64(s->ptr);\n    s->ptr += 8;\n    return 0;\n}\n\nstatic int bc_get_leb128(BCReaderState *s, uint32_t *pval)\n{\n    int ret;\n    ret = get_leb128(pval, s->ptr, s->buf_end);\n    if (unlikely(ret < 0))\n        return bc_read_error_end(s);\n    s->ptr += ret;\n    return 0;\n}\n\nstatic int bc_get_sleb128(BCReaderState *s, int32_t *pval)\n{\n    int ret;\n    ret = get_sleb128(pval, s->ptr, s->buf_end);\n    if (unlikely(ret < 0))\n        return bc_read_error_end(s);\n    s->ptr += ret;\n    return 0;\n}\n\n/* XXX: used to read an `int` with a positive value */\nstatic int bc_get_leb128_int(BCReaderState *s, int *pval)\n{\n    return bc_get_leb128(s, (uint32_t *)pval);\n}\n\nstatic int bc_get_leb128_u16(BCReaderState *s, uint16_t *pval)\n{\n    uint32_t val;\n    if (bc_get_leb128(s, &val)) {\n        *pval = 0;\n        return -1;\n    }\n    *pval = val;\n    return 0;\n}\n\nstatic int bc_get_buf(BCReaderState *s, uint8_t *buf, uint32_t buf_len)\n{\n    if (buf_len != 0) {\n        if (unlikely(!buf || s->buf_end - s->ptr < buf_len))\n            return bc_read_error_end(s);\n        memcpy(buf, s->ptr, buf_len);\n        s->ptr += buf_len;\n    }\n    return 0;\n}\n\nstatic int bc_idx_to_atom(BCReaderState *s, JSAtom *patom, uint32_t idx)\n{\n    JSAtom atom;\n\n    if (__JS_AtomIsTaggedInt(idx)) {\n        atom = idx;\n    } else if (idx < s->first_atom) {\n        atom = JS_DupAtom(s->ctx, idx);\n    } else {\n        idx -= s->first_atom;\n        if (idx >= s->idx_to_atom_count) {\n            JS_ThrowSyntaxError(s->ctx, \"invalid atom index (pos=%u)\",\n                                (unsigned int)(s->ptr - s->buf_start));\n            *patom = JS_ATOM_NULL;\n            return s->error_state = -1;\n        }\n        atom = JS_DupAtom(s->ctx, s->idx_to_atom[idx]);\n    }\n    *patom = atom;\n    return 0;\n}\n\nstatic int bc_get_atom(BCReaderState *s, JSAtom *patom)\n{\n    uint32_t v;\n    if (bc_get_leb128(s, &v))\n        return -1;\n    if (v & 1) {\n        *patom = __JS_AtomFromUInt32(v >> 1);\n        return 0;\n    } else {\n        return bc_idx_to_atom(s, patom, v >> 1);\n    }\n}\n\nstatic JSString *JS_ReadString(BCReaderState *s)\n{\n    uint32_t len;\n    size_t size;\n    BOOL is_wide_char;\n    JSString *p;\n\n    if (bc_get_leb128(s, &len))\n        return NULL;\n    is_wide_char = len & 1;\n    len >>= 1;\n    p = js_alloc_string(s->ctx, len, is_wide_char);\n    if (!p) {\n        s->error_state = -1;\n        return NULL;\n    }\n    size = (size_t)len << is_wide_char;\n    if ((s->buf_end - s->ptr) < size) {\n        bc_read_error_end(s);\n        js_free_string(s->ctx->rt, p);\n        return NULL;\n    }\n    memcpy(p->u.str8, s->ptr, size);\n    s->ptr += size;\n    if (!is_wide_char) {\n        p->u.str8[size] = '\\0'; /* add the trailing zero for 8 bit strings */\n    }\n#ifdef DUMP_READ_OBJECT\n    JS_DumpString(s->ctx->rt, p); printf(\"\\n\");\n#endif\n    return p;\n}\n\nstatic uint32_t bc_get_flags(uint32_t flags, int *pidx, int n)\n{\n    uint32_t val;\n    /* XXX: this does not work for n == 32 */\n    val = (flags >> *pidx) & ((1U << n) - 1);\n    *pidx += n;\n    return val;\n}\n\nstatic int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b,\n                                   int byte_code_offset, uint32_t bc_len)\n{\n    uint8_t *bc_buf;\n    int pos, len, op;\n    JSAtom atom;\n    uint32_t idx;\n\n    if (s->is_rom_data) {\n        /* directly use the input buffer */\n        if (unlikely(s->buf_end - s->ptr < bc_len))\n            return bc_read_error_end(s);\n        bc_buf = (uint8_t *)s->ptr;\n        s->ptr += bc_len;\n    } else {\n        bc_buf = (void *)((uint8_t*)b + byte_code_offset);\n        if (bc_get_buf(s, bc_buf, bc_len))\n            return -1;\n    }\n    b->byte_code_buf = bc_buf;\n\n    pos = 0;\n    while (pos < bc_len) {\n        op = bc_buf[pos];\n        len = short_opcode_info(op).size;\n        switch(short_opcode_info(op).fmt) {\n        case OP_FMT_atom:\n        case OP_FMT_atom_u8:\n        case OP_FMT_atom_u16:\n        case OP_FMT_atom_label_u8:\n        case OP_FMT_atom_label_u16:\n            idx = get_u32(bc_buf + pos + 1);\n            if (s->is_rom_data) {\n                /* just increment the reference count of the atom */\n                JS_DupAtom(s->ctx, (JSAtom)idx);\n            } else {\n                if (bc_idx_to_atom(s, &atom, idx)) {\n                    /* Note: the atoms will be freed up to this position */\n                    b->byte_code_len = pos;\n                    return -1;\n                }\n                put_u32(bc_buf + pos + 1, atom);\n#ifdef DUMP_READ_OBJECT\n                bc_read_trace(s, \"at %d, fixup atom: \", pos + 1); print_atom(s->ctx, atom); printf(\"\\n\");\n#endif\n            }\n            break;\n        default:\n            break;\n        }\n        pos += len;\n    }\n    return 0;\n}\n\n#ifdef CONFIG_BIGNUM\nstatic JSValue JS_ReadBigNum(BCReaderState *s, int tag)\n{\n    JSValue obj = JS_UNDEFINED;\n    uint8_t v8;\n    int32_t e;\n    uint32_t len;\n    limb_t l, i, n, j;\n    JSBigFloat *p;\n    limb_t v;\n    bf_t *a;\n    int bpos, d;\n    \n    p = js_new_bf(s->ctx);\n    if (!p)\n        goto fail;\n    switch(tag) {\n    case BC_TAG_BIG_INT:\n        obj = JS_MKPTR(JS_TAG_BIG_INT, p);\n        break;\n    case BC_TAG_BIG_FLOAT:\n        obj = JS_MKPTR(JS_TAG_BIG_FLOAT, p);\n        break;\n    case BC_TAG_BIG_DECIMAL:\n        obj = JS_MKPTR(JS_TAG_BIG_DECIMAL, p);\n        break;\n    default:\n        abort();\n    }\n\n    /* sign + exponent */\n    if (bc_get_sleb128(s, &e))\n        goto fail;\n\n    a = &p->num;\n    a->sign = e & 1;\n    e >>= 1;\n    if (e == 0)\n        a->expn = BF_EXP_ZERO;\n    else if (e == 1)\n        a->expn = BF_EXP_INF;\n    else if (e == 2)\n        a->expn = BF_EXP_NAN;\n    else if (e >= 3)\n        a->expn = e - 3;\n    else\n        a->expn = e;\n\n    /* mantissa */\n    if (a->expn != BF_EXP_ZERO &&\n        a->expn != BF_EXP_INF &&\n        a->expn != BF_EXP_NAN) {\n        if (bc_get_leb128(s, &len))\n            goto fail;\n        bc_read_trace(s, \"len=%\" PRId64 \"\\n\", (int64_t)len);\n        if (len == 0) {\n            JS_ThrowInternalError(s->ctx, \"invalid bignum length\");\n            goto fail;\n        }\n        if (tag != BC_TAG_BIG_DECIMAL)\n            l = (len + sizeof(limb_t) - 1) / sizeof(limb_t);\n        else\n            l = (len + LIMB_DIGITS - 1) / LIMB_DIGITS;\n        if (bf_resize(a, l)) {\n            JS_ThrowOutOfMemory(s->ctx);\n            goto fail;\n        }\n        if (tag != BC_TAG_BIG_DECIMAL) {\n            n = len & (sizeof(limb_t) - 1);\n            if (n != 0) {\n                v = 0;\n                for(i = 0; i < n; i++) {\n                    if (bc_get_u8(s, &v8))\n                        goto fail;\n                    v |= (limb_t)v8 << ((sizeof(limb_t) - n + i) * 8);\n                }\n                a->tab[0] = v;\n                i = 1;\n            } else {\n                i = 0;\n            }\n            for(; i < l; i++) {\n#if LIMB_BITS == 32\n                if (bc_get_u32(s, &v))\n                    goto fail;\n#ifdef WORDS_BIGENDIAN\n                v = bswap32(v);\n#endif\n#else\n                if (bc_get_u64(s, &v))\n                    goto fail;\n#ifdef WORDS_BIGENDIAN\n                v = bswap64(v);\n#endif\n#endif\n                a->tab[i] = v;\n            }\n        } else {\n            bpos = 0;\n            for(i = 0; i < l; i++) {\n                if (i == 0 && (n = len % LIMB_DIGITS) != 0) {\n                    j = LIMB_DIGITS - n;\n                } else {\n                    j = 0;\n                }\n                v = 0;\n                for(; j < LIMB_DIGITS; j++) {\n                    if (bpos == 0) {\n                        if (bc_get_u8(s, &v8))\n                            goto fail;\n                        d = v8 & 0xf;\n                        bpos = 1;\n                    } else {\n                        d = v8 >> 4;\n                        bpos = 0;\n                    }\n                    if (d >= 10) {\n                        JS_ThrowInternalError(s->ctx, \"invalid digit\");\n                        goto fail;\n                    }\n                    v += mp_pow_dec[j] * d;\n                }\n                a->tab[i] = v;\n            }\n        }\n    }\n    bc_read_trace(s, \"}\\n\");\n    return obj;\n fail:\n    JS_FreeValue(s->ctx, obj);\n    return JS_EXCEPTION;\n}\n#endif /* CONFIG_BIGNUM */\n\nstatic JSValue JS_ReadObjectRec(BCReaderState *s);\n\nstatic int BC_add_object_ref1(BCReaderState *s, JSObject *p)\n{\n    if (s->allow_reference) {\n        if (js_resize_array(s->ctx, (void *)&s->objects,\n                            sizeof(s->objects[0]),\n                            &s->objects_size, s->objects_count + 1))\n            return -1;\n        s->objects[s->objects_count++] = p;\n    }\n    return 0;\n}\n\nstatic int BC_add_object_ref(BCReaderState *s, JSValueConst obj)\n{\n    return BC_add_object_ref1(s, JS_VALUE_GET_OBJ(obj));\n}\n\nstatic JSValue JS_ReadFunctionTag(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSFunctionBytecode bc, *b;\n    JSValue obj = JS_UNDEFINED;\n    uint16_t v16;\n    uint8_t v8;\n    int idx, i, local_count;\n    int function_size, cpool_offset, byte_code_offset;\n    int closure_var_offset, vardefs_offset;\n\n    memset(&bc, 0, sizeof(bc));\n    bc.header.ref_count = 1;\n    //bc.gc_header.mark = 0;\n\n    if (bc_get_u16(s, &v16))\n        goto fail;\n    idx = 0;\n    bc.has_prototype = bc_get_flags(v16, &idx, 1);\n    bc.has_simple_parameter_list = bc_get_flags(v16, &idx, 1);\n    bc.is_derived_class_constructor = bc_get_flags(v16, &idx, 1);\n    bc.need_home_object = bc_get_flags(v16, &idx, 1);\n    bc.func_kind = bc_get_flags(v16, &idx, 2);\n    bc.new_target_allowed = bc_get_flags(v16, &idx, 1);\n    bc.super_call_allowed = bc_get_flags(v16, &idx, 1);\n    bc.super_allowed = bc_get_flags(v16, &idx, 1);\n    bc.arguments_allowed = bc_get_flags(v16, &idx, 1);\n    bc.has_debug = bc_get_flags(v16, &idx, 1);\n    bc.backtrace_barrier = bc_get_flags(v16, &idx, 1);\n    bc.read_only_bytecode = s->is_rom_data;\n    if (bc_get_u8(s, &v8))\n        goto fail;\n    bc.js_mode = v8;\n    if (bc_get_atom(s, &bc.func_name))  //@ atom leak if failure\n        goto fail;\n    if (bc_get_leb128_u16(s, &bc.arg_count))\n        goto fail;\n    if (bc_get_leb128_u16(s, &bc.var_count))\n        goto fail;\n    if (bc_get_leb128_u16(s, &bc.defined_arg_count))\n        goto fail;\n    if (bc_get_leb128_u16(s, &bc.stack_size))\n        goto fail;\n    if (bc_get_leb128_int(s, &bc.closure_var_count))\n        goto fail;\n    if (bc_get_leb128_int(s, &bc.cpool_count))\n        goto fail;\n    if (bc_get_leb128_int(s, &bc.byte_code_len))\n        goto fail;\n    if (bc_get_leb128_int(s, &local_count))\n        goto fail;\n\n    if (bc.has_debug) {\n        function_size = sizeof(*b);\n    } else {\n        function_size = offsetof(JSFunctionBytecode, debug);\n    }\n    cpool_offset = function_size;\n    function_size += bc.cpool_count * sizeof(*bc.cpool);\n    vardefs_offset = function_size;\n    function_size += local_count * sizeof(*bc.vardefs);\n    closure_var_offset = function_size;\n    function_size += bc.closure_var_count * sizeof(*bc.closure_var);\n    byte_code_offset = function_size;\n    if (!bc.read_only_bytecode) {\n        function_size += bc.byte_code_len;\n    }\n\n    b = js_mallocz(ctx, function_size);\n    if (!b)\n        return JS_EXCEPTION;\n            \n    memcpy(b, &bc, offsetof(JSFunctionBytecode, debug));\n    b->header.ref_count = 1;\n    add_gc_object(ctx->rt, &b->header, JS_GC_OBJ_TYPE_FUNCTION_BYTECODE);\n            \n    obj = JS_MKPTR(JS_TAG_FUNCTION_BYTECODE, b);\n\n#ifdef DUMP_READ_OBJECT\n    bc_read_trace(s, \"name: \"); print_atom(s->ctx, b->func_name); printf(\"\\n\");\n#endif\n    bc_read_trace(s, \"args=%d vars=%d defargs=%d closures=%d cpool=%d\\n\",\n                  b->arg_count, b->var_count, b->defined_arg_count,\n                  b->closure_var_count, b->cpool_count);\n    bc_read_trace(s, \"stack=%d bclen=%d locals=%d\\n\",\n                  b->stack_size, b->byte_code_len, local_count);\n\n    if (local_count != 0) {\n        bc_read_trace(s, \"vars {\\n\");\n        b->vardefs = (void *)((uint8_t*)b + vardefs_offset);\n        for(i = 0; i < local_count; i++) {\n            JSVarDef *vd = &b->vardefs[i];\n            if (bc_get_atom(s, &vd->var_name))\n                goto fail;\n            if (bc_get_leb128_int(s, &vd->scope_level))\n                goto fail;\n            if (bc_get_leb128_int(s, &vd->scope_next))\n                goto fail;\n            vd->scope_next--;\n            if (bc_get_u8(s, &v8))\n                goto fail;\n            idx = 0;\n            vd->var_kind = bc_get_flags(v8, &idx, 4);\n            vd->is_func_var = bc_get_flags(v8, &idx, 1);\n            vd->is_const = bc_get_flags(v8, &idx, 1);\n            vd->is_lexical = bc_get_flags(v8, &idx, 1);\n            vd->is_captured = bc_get_flags(v8, &idx, 1);\n#ifdef DUMP_READ_OBJECT\n            bc_read_trace(s, \"name: \"); print_atom(s->ctx, vd->var_name); printf(\"\\n\");\n#endif\n        }\n        bc_read_trace(s, \"}\\n\");\n    }\n    if (b->closure_var_count != 0) {\n        bc_read_trace(s, \"closure vars {\\n\");\n        b->closure_var = (void *)((uint8_t*)b + closure_var_offset);\n        for(i = 0; i < b->closure_var_count; i++) {\n            JSClosureVar *cv = &b->closure_var[i];\n            int var_idx;\n            if (bc_get_atom(s, &cv->var_name))\n                goto fail;\n            if (bc_get_leb128_int(s, &var_idx))\n                goto fail;\n            cv->var_idx = var_idx;\n            if (bc_get_u8(s, &v8))\n                goto fail;\n            idx = 0;\n            cv->is_local = bc_get_flags(v8, &idx, 1);\n            cv->is_arg = bc_get_flags(v8, &idx, 1);\n            cv->is_const = bc_get_flags(v8, &idx, 1);\n            cv->is_lexical = bc_get_flags(v8, &idx, 1);\n            cv->var_kind = bc_get_flags(v8, &idx, 4);\n#ifdef DUMP_READ_OBJECT\n            bc_read_trace(s, \"name: \"); print_atom(s->ctx, cv->var_name); printf(\"\\n\");\n#endif\n        }\n        bc_read_trace(s, \"}\\n\");\n    }\n    {\n        bc_read_trace(s, \"bytecode {\\n\");\n        if (JS_ReadFunctionBytecode(s, b, byte_code_offset, b->byte_code_len))\n            goto fail;\n        bc_read_trace(s, \"}\\n\");\n    }\n    if (b->has_debug) {\n        /* read optional debug information */\n        bc_read_trace(s, \"debug {\\n\");\n        if (bc_get_atom(s, &b->debug.filename))\n            goto fail;\n        if (bc_get_leb128_int(s, &b->debug.line_num))\n            goto fail;\n        if (bc_get_leb128_int(s, &b->debug.pc2line_len))\n            goto fail;\n        if (b->debug.pc2line_len) {\n            b->debug.pc2line_buf = js_mallocz(ctx, b->debug.pc2line_len);\n            if (!b->debug.pc2line_buf)\n                goto fail;\n            if (bc_get_buf(s, b->debug.pc2line_buf, b->debug.pc2line_len))\n                goto fail;\n        }\n#ifdef DUMP_READ_OBJECT\n        bc_read_trace(s, \"filename: \"); print_atom(s->ctx, b->debug.filename); printf(\"\\n\");\n#endif\n        bc_read_trace(s, \"}\\n\");\n    }\n    if (b->cpool_count != 0) {\n        bc_read_trace(s, \"cpool {\\n\");\n        b->cpool = (void *)((uint8_t*)b + cpool_offset);\n        for(i = 0; i < b->cpool_count; i++) {\n            JSValue val;\n            val = JS_ReadObjectRec(s);\n            if (JS_IsException(val))\n                goto fail;\n            b->cpool[i] = val;\n        }\n        bc_read_trace(s, \"}\\n\");\n    }\n    b->realm = JS_DupContext(ctx);\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadModule(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSValue obj;\n    JSModuleDef *m = NULL;\n    JSAtom module_name;\n    int i;\n    uint8_t v8;\n    \n    if (bc_get_atom(s, &module_name))\n        goto fail;\n#ifdef DUMP_READ_OBJECT\n    bc_read_trace(s, \"name: \"); print_atom(s->ctx, module_name); printf(\"\\n\");\n#endif\n    m = js_new_module_def(ctx, module_name);\n    if (!m)\n        goto fail;\n    obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_MODULE, m));\n    if (bc_get_leb128_int(s, &m->req_module_entries_count))\n        goto fail;\n    if (m->req_module_entries_count != 0) {\n        m->req_module_entries_size = m->req_module_entries_count;\n        m->req_module_entries = js_mallocz(ctx, sizeof(m->req_module_entries[0]) * m->req_module_entries_size);\n        if (!m->req_module_entries)\n            goto fail;\n        for(i = 0; i < m->req_module_entries_count; i++) {\n            JSReqModuleEntry *rme = &m->req_module_entries[i];\n            if (bc_get_atom(s, &rme->module_name))\n                goto fail;\n        }\n    }\n\n    if (bc_get_leb128_int(s, &m->export_entries_count))\n        goto fail;\n    if (m->export_entries_count != 0) {\n        m->export_entries_size = m->export_entries_count;\n        m->export_entries = js_mallocz(ctx, sizeof(m->export_entries[0]) * m->export_entries_size);\n        if (!m->export_entries)\n            goto fail;\n        for(i = 0; i < m->export_entries_count; i++) {\n            JSExportEntry *me = &m->export_entries[i];\n            if (bc_get_u8(s, &v8))\n                goto fail;\n            me->export_type = v8;\n            if (me->export_type == JS_EXPORT_TYPE_LOCAL) {\n                if (bc_get_leb128_int(s, &me->u.local.var_idx))\n                    goto fail;\n            } else {\n                if (bc_get_leb128_int(s, &me->u.req_module_idx))\n                    goto fail;\n                if (bc_get_atom(s, &me->local_name))\n                    goto fail;\n            }\n            if (bc_get_atom(s, &me->export_name))\n                goto fail;\n        }\n    }\n\n    if (bc_get_leb128_int(s, &m->star_export_entries_count))\n        goto fail;\n    if (m->star_export_entries_count != 0) {\n        m->star_export_entries_size = m->star_export_entries_count;\n        m->star_export_entries = js_mallocz(ctx, sizeof(m->star_export_entries[0]) * m->star_export_entries_size);\n        if (!m->star_export_entries)\n            goto fail;\n        for(i = 0; i < m->star_export_entries_count; i++) {\n            JSStarExportEntry *se = &m->star_export_entries[i];\n            if (bc_get_leb128_int(s, &se->req_module_idx))\n                goto fail;\n        }\n    }\n\n    if (bc_get_leb128_int(s, &m->import_entries_count))\n        goto fail;\n    if (m->import_entries_count != 0) {\n        m->import_entries_size = m->import_entries_count;\n        m->import_entries = js_mallocz(ctx, sizeof(m->import_entries[0]) * m->import_entries_size);\n        if (!m->import_entries)\n            goto fail;\n        for(i = 0; i < m->import_entries_count; i++) {\n            JSImportEntry *mi = &m->import_entries[i];\n            if (bc_get_leb128_int(s, &mi->var_idx))\n                goto fail;\n            if (bc_get_atom(s, &mi->import_name))\n                goto fail;\n            if (bc_get_leb128_int(s, &mi->req_module_idx))\n                goto fail;\n        }\n    }\n\n    m->func_obj = JS_ReadObjectRec(s);\n    if (JS_IsException(m->func_obj))\n        goto fail;\n    return obj;\n fail:\n    if (m) {\n        js_free_module_def(ctx, m);\n    }\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadObjectTag(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSValue obj;\n    uint32_t prop_count, i;\n    JSAtom atom;\n    JSValue val;\n    int ret;\n    \n    obj = JS_NewObject(ctx);\n    if (BC_add_object_ref(s, obj))\n        goto fail;\n    if (bc_get_leb128(s, &prop_count))\n        goto fail;\n    for(i = 0; i < prop_count; i++) {\n        if (bc_get_atom(s, &atom))\n            goto fail;\n#ifdef DUMP_READ_OBJECT\n        bc_read_trace(s, \"propname: \"); print_atom(s->ctx, atom); printf(\"\\n\");\n#endif\n        val = JS_ReadObjectRec(s);\n        if (JS_IsException(val)) {\n            JS_FreeAtom(ctx, atom);\n            goto fail;\n        }\n        ret = JS_DefinePropertyValue(ctx, obj, atom, val, JS_PROP_C_W_E);\n        JS_FreeAtom(ctx, atom);\n        if (ret < 0)\n            goto fail;\n    }\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadArray(BCReaderState *s, int tag)\n{\n    JSContext *ctx = s->ctx;\n    JSValue obj;\n    uint32_t len, i;\n    JSValue val;\n    int ret, prop_flags;\n    BOOL is_template;\n\n    obj = JS_NewArray(ctx);\n    if (BC_add_object_ref(s, obj))\n        goto fail;\n    is_template = (tag == BC_TAG_TEMPLATE_OBJECT);\n    if (bc_get_leb128(s, &len))\n        goto fail;\n    for(i = 0; i < len; i++) {\n        val = JS_ReadObjectRec(s);\n        if (JS_IsException(val))\n            goto fail;\n        if (is_template)\n            prop_flags = JS_PROP_ENUMERABLE;\n        else\n            prop_flags = JS_PROP_C_W_E;\n        ret = JS_DefinePropertyValueUint32(ctx, obj, i, val,\n                                           prop_flags);\n        if (ret < 0)\n            goto fail;\n    }\n    if (is_template) {\n        val = JS_ReadObjectRec(s);\n        if (JS_IsException(val))\n            goto fail;\n        if (!JS_IsUndefined(val)) {\n            ret = JS_DefinePropertyValue(ctx, obj, JS_ATOM_raw, val, 0);\n            if (ret < 0)\n                goto fail;\n        }\n        JS_PreventExtensions(ctx, obj);\n    }\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadTypedArray(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSValue obj = JS_UNDEFINED, array_buffer = JS_UNDEFINED;\n    uint8_t array_tag;\n    JSValueConst args[3];\n    uint32_t offset, len, idx;\n    \n    if (bc_get_u8(s, &array_tag))\n        return JS_EXCEPTION;\n    if (array_tag >= JS_TYPED_ARRAY_COUNT)\n        return JS_ThrowTypeError(ctx, \"invalid typed array\");\n    if (bc_get_leb128(s, &len))\n        return JS_EXCEPTION;\n    if (bc_get_leb128(s, &offset))\n        return JS_EXCEPTION;\n    /* XXX: this hack could be avoided if the typed array could be\n       created before the array buffer */\n    idx = s->objects_count;\n    if (BC_add_object_ref1(s, NULL))\n        goto fail;\n    array_buffer = JS_ReadObjectRec(s);\n    if (JS_IsException(array_buffer))\n        return JS_EXCEPTION;\n    if (!js_get_array_buffer(ctx, array_buffer)) {\n        JS_FreeValue(ctx, array_buffer);\n        return JS_EXCEPTION;\n    }\n    args[0] = array_buffer;\n    args[1] = JS_NewInt64(ctx, offset);\n    args[2] = JS_NewInt64(ctx, len);\n    obj = js_typed_array_constructor(ctx, JS_UNDEFINED,\n                                     3, args,\n                                     JS_CLASS_UINT8C_ARRAY + array_tag);\n    if (JS_IsException(obj))\n        goto fail;\n    if (s->allow_reference) {\n        s->objects[idx] = JS_VALUE_GET_OBJ(obj);\n    }\n    JS_FreeValue(ctx, array_buffer);\n    return obj;\n fail:\n    JS_FreeValue(ctx, array_buffer);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadArrayBuffer(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    uint32_t byte_length;\n    JSValue obj;\n    \n    if (bc_get_leb128(s, &byte_length))\n        return JS_EXCEPTION;\n    if (unlikely(s->buf_end - s->ptr < byte_length)) {\n        bc_read_error_end(s);\n        return JS_EXCEPTION;\n    }\n    obj = JS_NewArrayBufferCopy(ctx, s->ptr, byte_length);\n    if (JS_IsException(obj))\n        goto fail;\n    if (BC_add_object_ref(s, obj))\n        goto fail;\n    s->ptr += byte_length;\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadSharedArrayBuffer(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    uint32_t byte_length;\n    uint8_t *data_ptr;\n    JSValue obj;\n    uint64_t u64;\n    \n    if (bc_get_leb128(s, &byte_length))\n        return JS_EXCEPTION;\n    if (bc_get_u64(s, &u64))\n        return JS_EXCEPTION;\n    data_ptr = (uint8_t *)(uintptr_t)u64;\n    /* the SharedArrayBuffer is cloned */\n    obj = js_array_buffer_constructor3(ctx, JS_UNDEFINED, byte_length,\n                                       JS_CLASS_SHARED_ARRAY_BUFFER,\n                                       data_ptr,\n                                       NULL, NULL, FALSE);\n    if (JS_IsException(obj))\n        goto fail;\n    if (BC_add_object_ref(s, obj))\n        goto fail;\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadDate(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSValue val, obj = JS_UNDEFINED;\n\n    val = JS_ReadObjectRec(s);\n    if (JS_IsException(val))\n        goto fail;\n    if (!JS_IsNumber(val)) {\n        JS_ThrowTypeError(ctx, \"Number tag expected for date\");\n        goto fail;\n    }\n    obj = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_DATE],\n                                 JS_CLASS_DATE);\n    if (JS_IsException(obj))\n        goto fail;\n    if (BC_add_object_ref(s, obj))\n        goto fail;\n    JS_SetObjectData(ctx, obj, val);\n    return obj;\n fail:\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadObjectValue(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSValue val, obj = JS_UNDEFINED;\n\n    val = JS_ReadObjectRec(s);\n    if (JS_IsException(val))\n        goto fail;\n    obj = JS_ToObject(ctx, val);\n    if (JS_IsException(obj))\n        goto fail;\n    if (BC_add_object_ref(s, obj))\n        goto fail;\n    JS_FreeValue(ctx, val);\n    return obj;\n fail:\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_ReadObjectRec(BCReaderState *s)\n{\n    JSContext *ctx = s->ctx;\n    uint8_t tag;\n    JSValue obj = JS_UNDEFINED;\n\n    if (js_check_stack_overflow(ctx->rt, 0))\n        return JS_ThrowStackOverflow(ctx);\n\n    if (bc_get_u8(s, &tag))\n        return JS_EXCEPTION;\n\n    bc_read_trace(s, \"%s {\\n\", bc_tag_str[tag]);\n\n    switch(tag) {\n    case BC_TAG_NULL:\n        obj = JS_NULL;\n        break;\n    case BC_TAG_UNDEFINED:\n        obj = JS_UNDEFINED;\n        break;\n    case BC_TAG_BOOL_FALSE:\n    case BC_TAG_BOOL_TRUE:\n        obj = JS_NewBool(ctx, tag - BC_TAG_BOOL_FALSE);\n        break;\n    case BC_TAG_INT32:\n        {\n            int32_t val;\n            if (bc_get_sleb128(s, &val))\n                return JS_EXCEPTION;\n            bc_read_trace(s, \"%d\\n\", val);\n            obj = JS_NewInt32(ctx, val);\n        }\n        break;\n    case BC_TAG_FLOAT64:\n        {\n            JSFloat64Union u;\n            if (bc_get_u64(s, &u.u64))\n                return JS_EXCEPTION;\n            bc_read_trace(s, \"%g\\n\", u.d);\n            obj = __JS_NewFloat64(ctx, u.d);\n        }\n        break;\n    case BC_TAG_STRING:\n        {\n            JSString *p;\n            p = JS_ReadString(s);\n            if (!p)\n                return JS_EXCEPTION;\n            obj = JS_MKPTR(JS_TAG_STRING, p);\n        }\n        break;\n    case BC_TAG_FUNCTION_BYTECODE:\n        if (!s->allow_bytecode)\n            goto invalid_tag;\n        obj = JS_ReadFunctionTag(s);\n        break;\n    case BC_TAG_MODULE:\n        if (!s->allow_bytecode)\n            goto invalid_tag;\n        obj = JS_ReadModule(s);\n        break;\n    case BC_TAG_OBJECT:\n        obj = JS_ReadObjectTag(s);\n        break;\n    case BC_TAG_ARRAY:\n    case BC_TAG_TEMPLATE_OBJECT:\n        obj = JS_ReadArray(s, tag);\n        break;\n    case BC_TAG_TYPED_ARRAY:\n        obj = JS_ReadTypedArray(s);\n        break;\n    case BC_TAG_ARRAY_BUFFER:\n        obj = JS_ReadArrayBuffer(s);\n        break;\n    case BC_TAG_SHARED_ARRAY_BUFFER:\n        if (!s->allow_sab || !ctx->rt->sab_funcs.sab_dup)\n            goto invalid_tag;\n        obj = JS_ReadSharedArrayBuffer(s);\n        break;\n    case BC_TAG_DATE:\n        obj = JS_ReadDate(s);\n        break;\n    case BC_TAG_OBJECT_VALUE:\n        obj = JS_ReadObjectValue(s);\n        break;\n#ifdef CONFIG_BIGNUM\n    case BC_TAG_BIG_INT:\n    case BC_TAG_BIG_FLOAT:\n    case BC_TAG_BIG_DECIMAL:\n        obj = JS_ReadBigNum(s, tag);\n        break;\n#endif\n    case BC_TAG_OBJECT_REFERENCE:\n        {\n            uint32_t val;\n            if (!s->allow_reference)\n                return JS_ThrowSyntaxError(ctx, \"object references are not allowed\");\n            if (bc_get_leb128(s, &val))\n                return JS_EXCEPTION;\n            bc_read_trace(s, \"%u\\n\", val);\n            if (val >= s->objects_count) {\n                return JS_ThrowSyntaxError(ctx, \"invalid object reference (%u >= %u)\",\n                                           val, s->objects_count);\n            }\n            obj = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, s->objects[val]));\n        }\n        break;\n    default:\n    invalid_tag:\n        return JS_ThrowSyntaxError(ctx, \"invalid tag (tag=%d pos=%u)\",\n                                   tag, (unsigned int)(s->ptr - s->buf_start));\n    }\n    bc_read_trace(s, \"}\\n\");\n    return obj;\n}\n\nstatic int JS_ReadObjectAtoms(BCReaderState *s)\n{\n    uint8_t v8;\n    JSString *p;\n    int i;\n    JSAtom atom;\n\n    if (bc_get_u8(s, &v8))\n        return -1;\n    /* XXX: could support byte swapped input */\n    if (v8 != BC_VERSION) {\n        JS_ThrowSyntaxError(s->ctx, \"invalid version (%d expected=%d)\",\n                            v8, BC_VERSION);\n        return -1;\n    }\n    if (bc_get_leb128(s, &s->idx_to_atom_count))\n        return -1;\n\n    bc_read_trace(s, \"%d atom indexes {\\n\", s->idx_to_atom_count);\n\n    if (s->idx_to_atom_count != 0) {\n        s->idx_to_atom = js_mallocz(s->ctx, s->idx_to_atom_count *\n                                    sizeof(s->idx_to_atom[0]));\n        if (!s->idx_to_atom)\n            return s->error_state = -1;\n    }\n    for(i = 0; i < s->idx_to_atom_count; i++) {\n        p = JS_ReadString(s);\n        if (!p)\n            return -1;\n        atom = JS_NewAtomStr(s->ctx, p);\n        if (atom == JS_ATOM_NULL)\n            return s->error_state = -1;\n        s->idx_to_atom[i] = atom;\n        if (s->is_rom_data && (atom != (i + s->first_atom)))\n            s->is_rom_data = FALSE; /* atoms must be relocated */\n    }\n    bc_read_trace(s, \"}\\n\");\n    return 0;\n}\n\nstatic void bc_reader_free(BCReaderState *s)\n{\n    int i;\n    if (s->idx_to_atom) {\n        for(i = 0; i < s->idx_to_atom_count; i++) {\n            JS_FreeAtom(s->ctx, s->idx_to_atom[i]);\n        }\n        js_free(s->ctx, s->idx_to_atom);\n    }\n    js_free(s->ctx, s->objects);\n}\n\nJSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,\n                       int flags)\n{\n    BCReaderState ss, *s = &ss;\n    JSValue obj;\n\n    ctx->binary_object_count += 1;\n    ctx->binary_object_size += buf_len;\n\n    memset(s, 0, sizeof(*s));\n    s->ctx = ctx;\n    s->buf_start = buf;\n    s->buf_end = buf + buf_len;\n    s->ptr = buf;\n    s->allow_bytecode = ((flags & JS_READ_OBJ_BYTECODE) != 0);\n    s->is_rom_data = ((flags & JS_READ_OBJ_ROM_DATA) != 0);\n    s->allow_sab = ((flags & JS_READ_OBJ_SAB) != 0);\n    s->allow_reference = ((flags & JS_READ_OBJ_REFERENCE) != 0);\n    if (s->allow_bytecode)\n        s->first_atom = JS_ATOM_END;\n    else\n        s->first_atom = 1;\n    if (JS_ReadObjectAtoms(s)) {\n        obj = JS_EXCEPTION;\n    } else {\n        obj = JS_ReadObjectRec(s);\n    }\n    bc_reader_free(s);\n    return obj;\n}\n\n/*******************************************************************/\n/* runtime functions & objects */\n\nstatic JSValue js_string_constructor(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv);\nstatic JSValue js_boolean_constructor(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv);\nstatic JSValue js_number_constructor(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv);\n\nstatic int check_function(JSContext *ctx, JSValueConst obj)\n{\n    if (likely(JS_IsFunction(ctx, obj)))\n        return 0;\n    JS_ThrowTypeError(ctx, \"not a function\");\n    return -1;\n}\n\nstatic int check_exception_free(JSContext *ctx, JSValue obj)\n{\n    JS_FreeValue(ctx, obj);\n    return JS_IsException(obj);\n}\n\nstatic JSAtom find_atom(JSContext *ctx, const char *name)\n{\n    JSAtom atom;\n    int len;\n\n    if (*name == '[') {\n        name++;\n        len = strlen(name) - 1;\n        /* We assume 8 bit non null strings, which is the case for these\n           symbols */\n        for(atom = JS_ATOM_Symbol_toPrimitive; atom < JS_ATOM_END; atom++) {\n            JSAtomStruct *p = ctx->rt->atom_array[atom];\n            JSString *str = p;\n            if (str->len == len && !memcmp(str->u.str8, name, len))\n                return JS_DupAtom(ctx, atom);\n        }\n        abort();\n    } else {\n        atom = JS_NewAtom(ctx, name);\n    }\n    return atom;\n}\n\nstatic int JS_InstantiateFunctionListItem(JSContext *ctx, JSObject *p,\n                                          JSAtom atom, void *opaque)\n{\n    const JSCFunctionListEntry *e = opaque;\n    JSValueConst obj = JS_MKPTR(JS_TAG_OBJECT, p);\n    JSValue val;\n    int prop_flags = e->prop_flags;\n\n    switch(e->def_type) {\n    case JS_DEF_ALIAS:\n        {\n            JSAtom atom1 = find_atom(ctx, e->u.alias.name);\n            switch (e->u.alias.base) {\n            case -1:\n                val = JS_GetProperty(ctx, obj, atom1);\n                break;\n            case 0:\n                val = JS_GetProperty(ctx, ctx->global_obj, atom1);\n                break;\n            case 1:\n                val = JS_GetProperty(ctx, ctx->class_proto[JS_CLASS_ARRAY], atom1);\n                break;\n            default:\n                abort();\n            }\n            JS_FreeAtom(ctx, atom1);\n            goto setval;\n        }\n    case JS_DEF_CFUNC:\n        val = JS_NewCFunction2(ctx, e->u.func.cfunc.generic,\n                               e->name, e->u.func.length, e->u.func.cproto, e->magic);\n    setval:\n        if (atom == JS_ATOM_Symbol_toPrimitive) {\n            /* Symbol.toPrimitive functions are not writable */\n            prop_flags = JS_PROP_CONFIGURABLE;\n        } else if (atom == JS_ATOM_Symbol_hasInstance) {\n            /* Function.prototype[Symbol.hasInstance] is not writable nor configurable */\n            prop_flags = 0;\n        }\n        break;\n    case JS_DEF_CGETSET:\n    case JS_DEF_CGETSET_MAGIC:\n        {\n            JSValue getter, setter;\n            char buf[64];\n\n            getter = JS_UNDEFINED;\n            if (e->u.getset.get.generic) {\n                snprintf(buf, sizeof(buf), \"get %s\", e->name);\n                getter = JS_NewCFunction2(ctx, e->u.getset.get.generic,\n                                          buf, 0, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_getter_magic : JS_CFUNC_getter,\n                                          e->magic);\n            }\n            setter = JS_UNDEFINED;\n            if (e->u.getset.set.generic) {\n                snprintf(buf, sizeof(buf), \"set %s\", e->name);\n                setter = JS_NewCFunction2(ctx, e->u.getset.set.generic,\n                                          buf, 1, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_setter_magic : JS_CFUNC_setter,\n                                          e->magic);\n            }\n            JS_DefinePropertyGetSet(ctx, obj, atom, getter, setter, prop_flags);\n            return 0;\n        }\n        break;\n    case JS_DEF_PROP_STRING:\n        val = JS_NewAtomString(ctx, e->u.str);\n        break;\n    case JS_DEF_PROP_INT32:\n        val = JS_NewInt32(ctx, e->u.i32);\n        break;\n    case JS_DEF_PROP_INT64:\n        val = JS_NewInt64(ctx, e->u.i64);\n        break;\n    case JS_DEF_PROP_DOUBLE:\n        val = __JS_NewFloat64(ctx, e->u.f64);\n        break;\n    case JS_DEF_PROP_UNDEFINED:\n        val = JS_UNDEFINED;\n        break;\n    case JS_DEF_OBJECT:\n        val = JS_NewObject(ctx);\n        JS_SetPropertyFunctionList(ctx, val, e->u.prop_list.tab, e->u.prop_list.len);\n        break;\n    default:\n        abort();\n    }\n    JS_DefinePropertyValue(ctx, obj, atom, val, prop_flags);\n    return 0;\n}\n\nvoid JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,\n                                const JSCFunctionListEntry *tab, int len)\n{\n    int i, prop_flags;\n\n    for (i = 0; i < len; i++) {\n        const JSCFunctionListEntry *e = &tab[i];\n        JSAtom atom = find_atom(ctx, e->name);\n\n        switch (e->def_type) {\n        case JS_DEF_CFUNC:\n        case JS_DEF_CGETSET:\n        case JS_DEF_CGETSET_MAGIC:\n        case JS_DEF_PROP_STRING:\n        case JS_DEF_ALIAS:\n        case JS_DEF_OBJECT:\n            prop_flags = JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE | (e->prop_flags & JS_PROP_ENUMERABLE);\n            JS_DefineAutoInitProperty(ctx, obj, atom,\n                                      JS_AUTOINIT_ID_PROP,\n                                      (void *)e, prop_flags);\n            break;\n        case JS_DEF_PROP_INT32:\n        case JS_DEF_PROP_INT64:\n        case JS_DEF_PROP_DOUBLE:\n        case JS_DEF_PROP_UNDEFINED:\n            {\n                JSObject *p = JS_VALUE_GET_OBJ(obj);\n                JS_InstantiateFunctionListItem(ctx, p, atom, (void *)e);\n            }\n            break;\n        default:\n            abort();\n        }\n        JS_FreeAtom(ctx, atom);\n    }\n}\n\nint JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m,\n                           const JSCFunctionListEntry *tab, int len)\n{\n    int i;\n    for(i = 0; i < len; i++) {\n        if (JS_AddModuleExport(ctx, m, tab[i].name))\n            return -1;\n    }\n    return 0;\n}\n\nint JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,\n                           const JSCFunctionListEntry *tab, int len)\n{\n    int i;\n    JSValue val;\n\n    for(i = 0; i < len; i++) {\n        const JSCFunctionListEntry *e = &tab[i];\n        switch(e->def_type) {\n        case JS_DEF_CFUNC:\n            val = JS_NewCFunction2(ctx, e->u.func.cfunc.generic,\n                                   e->name, e->u.func.length, e->u.func.cproto, e->magic);\n            break;\n        case JS_DEF_PROP_STRING:\n            val = JS_NewString(ctx, e->u.str);\n            break;\n        case JS_DEF_PROP_INT32:\n            val = JS_NewInt32(ctx, e->u.i32);\n            break;\n        case JS_DEF_PROP_INT64:\n            val = JS_NewInt64(ctx, e->u.i64);\n            break;\n        case JS_DEF_PROP_DOUBLE:\n            val = __JS_NewFloat64(ctx, e->u.f64);\n            break;\n        case JS_DEF_OBJECT:\n            val = JS_NewObject(ctx);\n            JS_SetPropertyFunctionList(ctx, val, e->u.prop_list.tab, e->u.prop_list.len);\n            break;\n        default:\n            abort();\n        }\n        if (JS_SetModuleExport(ctx, m, e->name, val))\n            return -1;\n    }\n    return 0;\n}\n\n/* Note: 'func_obj' is not necessarily a constructor */\nstatic void JS_SetConstructor2(JSContext *ctx,\n                               JSValueConst func_obj,\n                               JSValueConst proto,\n                               int proto_flags, int ctor_flags)\n{\n    JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_prototype,\n                           JS_DupValue(ctx, proto), proto_flags);\n    JS_DefinePropertyValue(ctx, proto, JS_ATOM_constructor,\n                           JS_DupValue(ctx, func_obj),\n                           ctor_flags);\n    set_cycle_flag(ctx, func_obj);\n    set_cycle_flag(ctx, proto);\n}\n\nvoid JS_SetConstructor(JSContext *ctx, JSValueConst func_obj, \n                       JSValueConst proto)\n{\n    JS_SetConstructor2(ctx, func_obj, proto,\n                       0, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n}\n\nstatic void JS_NewGlobalCConstructor2(JSContext *ctx,\n                                      JSValue func_obj,\n                                      const char *name,\n                                      JSValueConst proto)\n{\n    JS_DefinePropertyValueStr(ctx, ctx->global_obj, name,\n                           JS_DupValue(ctx, func_obj),\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    JS_SetConstructor(ctx, func_obj, proto);\n    JS_FreeValue(ctx, func_obj);\n}\n\nstatic JSValueConst JS_NewGlobalCConstructor(JSContext *ctx, const char *name,\n                                             JSCFunction *func, int length,\n                                             JSValueConst proto)\n{\n    JSValue func_obj;\n    func_obj = JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_constructor_or_func, 0);\n    JS_NewGlobalCConstructor2(ctx, func_obj, name, proto);\n    return func_obj;\n}\n\nstatic JSValueConst JS_NewGlobalCConstructorOnly(JSContext *ctx, const char *name,\n                                                 JSCFunction *func, int length,\n                                                 JSValueConst proto)\n{\n    JSValue func_obj;\n    func_obj = JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_constructor, 0);\n    JS_NewGlobalCConstructor2(ctx, func_obj, name, proto);\n    return func_obj;\n}\n\nstatic JSValue js_global_eval(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    return JS_EvalObject(ctx, ctx->global_obj, argv[0], JS_EVAL_TYPE_INDIRECT, -1);\n}\n\nstatic JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    double d;\n\n    /* XXX: does this work for bigfloat? */\n    if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))\n        return JS_EXCEPTION;\n    return JS_NewBool(ctx, isnan(d));\n}\n\nstatic JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    BOOL res;\n    double d;\n    if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))\n        return JS_EXCEPTION;\n    res = isfinite(d);\n    return JS_NewBool(ctx, res);\n}\n\n/* Object class */\n\nstatic JSValue JS_ToObject(JSContext *ctx, JSValueConst val)\n{\n    int tag = JS_VALUE_GET_NORM_TAG(val);\n    JSValue obj;\n\n    switch(tag) {\n    default:\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n        return JS_ThrowTypeError(ctx, \"cannot convert to object\");\n    case JS_TAG_OBJECT:\n    case JS_TAG_EXCEPTION:\n        return JS_DupValue(ctx, val);\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        obj = JS_NewObjectClass(ctx, JS_CLASS_BIG_INT);\n        goto set_value;\n    case JS_TAG_BIG_FLOAT:\n        obj = JS_NewObjectClass(ctx, JS_CLASS_BIG_FLOAT);\n        goto set_value;\n    case JS_TAG_BIG_DECIMAL:\n        obj = JS_NewObjectClass(ctx, JS_CLASS_BIG_DECIMAL);\n        goto set_value;\n#endif\n    case JS_TAG_INT:\n    case JS_TAG_FLOAT64:\n        obj = JS_NewObjectClass(ctx, JS_CLASS_NUMBER);\n        goto set_value;\n    case JS_TAG_STRING:\n        /* XXX: should call the string constructor */\n        {\n            JSString *p1 = JS_VALUE_GET_STRING(val);\n            obj = JS_NewObjectClass(ctx, JS_CLASS_STRING);\n            JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, JS_NewInt32(ctx, p1->len), 0);\n        }\n        goto set_value;\n    case JS_TAG_BOOL:\n        obj = JS_NewObjectClass(ctx, JS_CLASS_BOOLEAN);\n        goto set_value;\n    case JS_TAG_SYMBOL:\n        obj = JS_NewObjectClass(ctx, JS_CLASS_SYMBOL);\n    set_value:\n        if (!JS_IsException(obj))\n            JS_SetObjectData(ctx, obj, JS_DupValue(ctx, val));\n        return obj;\n    }\n}\n\nstatic JSValue JS_ToObjectFree(JSContext *ctx, JSValue val)\n{\n    JSValue obj = JS_ToObject(ctx, val);\n    JS_FreeValue(ctx, val);\n    return obj;\n}\n\nstatic int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,\n                          JSValueConst desc)\n{\n    JSValue val, getter, setter;\n    int flags;\n\n    if (!JS_IsObject(desc)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    flags = 0;\n    val = JS_UNDEFINED;\n    getter = JS_UNDEFINED;\n    setter = JS_UNDEFINED;\n    if (JS_HasProperty(ctx, desc, JS_ATOM_configurable)) {\n        JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_configurable);\n        if (JS_IsException(prop))\n            goto fail;\n        flags |= JS_PROP_HAS_CONFIGURABLE;\n        if (JS_ToBoolFree(ctx, prop))\n            flags |= JS_PROP_CONFIGURABLE;\n    }\n    if (JS_HasProperty(ctx, desc, JS_ATOM_writable)) {\n        JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_writable);\n        if (JS_IsException(prop))\n            goto fail;\n        flags |= JS_PROP_HAS_WRITABLE;\n        if (JS_ToBoolFree(ctx, prop))\n            flags |= JS_PROP_WRITABLE;\n    }\n    if (JS_HasProperty(ctx, desc, JS_ATOM_enumerable)) {\n        JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_enumerable);\n        if (JS_IsException(prop))\n            goto fail;\n        flags |= JS_PROP_HAS_ENUMERABLE;\n        if (JS_ToBoolFree(ctx, prop))\n            flags |= JS_PROP_ENUMERABLE;\n    }\n    if (JS_HasProperty(ctx, desc, JS_ATOM_value)) {\n        flags |= JS_PROP_HAS_VALUE;\n        val = JS_GetProperty(ctx, desc, JS_ATOM_value);\n        if (JS_IsException(val))\n            goto fail;\n    }\n    if (JS_HasProperty(ctx, desc, JS_ATOM_get)) {\n        flags |= JS_PROP_HAS_GET;\n        getter = JS_GetProperty(ctx, desc, JS_ATOM_get);\n        if (JS_IsException(getter) ||\n            !(JS_IsUndefined(getter) || JS_IsFunction(ctx, getter))) {\n            JS_ThrowTypeError(ctx, \"invalid getter\");\n            goto fail;\n        }\n    }\n    if (JS_HasProperty(ctx, desc, JS_ATOM_set)) {\n        flags |= JS_PROP_HAS_SET;\n        setter = JS_GetProperty(ctx, desc, JS_ATOM_set);\n        if (JS_IsException(setter) ||\n            !(JS_IsUndefined(setter) || JS_IsFunction(ctx, setter))) {\n            JS_ThrowTypeError(ctx, \"invalid setter\");\n            goto fail;\n        }\n    }\n    if ((flags & (JS_PROP_HAS_SET | JS_PROP_HAS_GET)) &&\n        (flags & (JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE))) {\n        JS_ThrowTypeError(ctx, \"cannot have setter/getter and value or writable\");\n        goto fail;\n    }\n    d->flags = flags;\n    d->value = val;\n    d->getter = getter;\n    d->setter = setter;\n    return 0;\n fail:\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, getter);\n    JS_FreeValue(ctx, setter);\n    return -1;\n}\n\nstatic __exception int JS_DefinePropertyDesc(JSContext *ctx, JSValueConst obj,\n                                             JSAtom prop, JSValueConst desc,\n                                             int flags)\n{\n    JSPropertyDescriptor d;\n    int ret;\n\n    if (js_obj_to_desc(ctx, &d, desc) < 0)\n        return -1;\n\n    ret = JS_DefineProperty(ctx, obj, prop,\n                            d.value, d.getter, d.setter, d.flags | flags);\n    js_free_desc(ctx, &d);\n    return ret;\n}\n\nstatic __exception int JS_ObjectDefineProperties(JSContext *ctx,\n                                                 JSValueConst obj,\n                                                 JSValueConst properties)\n{\n    JSValue props, desc;\n    JSObject *p;\n    JSPropertyEnum *atoms;\n    uint32_t len, i;\n    int ret = -1;\n\n    if (!JS_IsObject(obj)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    desc = JS_UNDEFINED;\n    props = JS_ToObject(ctx, properties);\n    if (JS_IsException(props))\n        return -1;\n    p = JS_VALUE_GET_OBJ(props);\n    if (JS_GetOwnPropertyNamesInternal(ctx, &atoms, &len, p, JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK) < 0)\n        goto exception;\n    for(i = 0; i < len; i++) {\n        JS_FreeValue(ctx, desc);\n        desc = JS_GetProperty(ctx, props, atoms[i].atom);\n        if (JS_IsException(desc))\n            goto exception;\n        if (JS_DefinePropertyDesc(ctx, obj, atoms[i].atom, desc, JS_PROP_THROW) < 0)\n            goto exception;\n    }\n    ret = 0;\n\nexception:\n    js_free_prop_enum(ctx, atoms, len);\n    JS_FreeValue(ctx, props);\n    JS_FreeValue(ctx, desc);\n    return ret;\n}\n\nstatic JSValue js_object_constructor(JSContext *ctx, JSValueConst new_target,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue ret;\n    if (!JS_IsUndefined(new_target) &&\n        JS_VALUE_GET_OBJ(new_target) !=\n        JS_VALUE_GET_OBJ(JS_GetActiveFunction(ctx))) {\n        ret = js_create_from_ctor(ctx, new_target, JS_CLASS_OBJECT);\n    } else {\n        int tag = JS_VALUE_GET_NORM_TAG(argv[0]);\n        switch(tag) {\n        case JS_TAG_NULL:\n        case JS_TAG_UNDEFINED:\n            ret = JS_NewObject(ctx);\n            break;\n        default:\n            ret = JS_ToObject(ctx, argv[0]);\n            break;\n        }\n    }\n    return ret;\n}\n\nstatic JSValue js_object_create(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValueConst proto, props;\n    JSValue obj;\n\n    proto = argv[0];\n    if (!JS_IsObject(proto) && !JS_IsNull(proto))\n        return JS_ThrowTypeError(ctx, \"not a prototype\");\n    obj = JS_NewObjectProto(ctx, proto);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    props = argv[1];\n    if (!JS_IsUndefined(props)) {\n        if (JS_ObjectDefineProperties(ctx, obj, props)) {\n            JS_FreeValue(ctx, obj);\n            return JS_EXCEPTION;\n        }\n    }\n    return obj;\n}\n\nstatic JSValue js_object_getPrototypeOf(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv, int magic)\n{\n    JSValueConst val;\n\n    val = argv[0];\n    if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT) {\n        /* ES6 feature non compatible with ES5.1: primitive types are\n           accepted */\n        if (magic || JS_VALUE_GET_TAG(val) == JS_TAG_NULL ||\n            JS_VALUE_GET_TAG(val) == JS_TAG_UNDEFINED)\n            return JS_ThrowTypeErrorNotAnObject(ctx);\n    }\n    return JS_GetPrototype(ctx, val);\n}\n\nstatic JSValue js_object_setPrototypeOf(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    JSValueConst obj;\n    obj = argv[0];\n    if (JS_SetPrototypeInternal(ctx, obj, argv[1], TRUE) < 0)\n        return JS_EXCEPTION;\n    return JS_DupValue(ctx, obj);\n}\n\n/* magic = 1 if called as Reflect.defineProperty */\nstatic JSValue js_object_defineProperty(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv, int magic)\n{\n    JSValueConst obj, prop, desc;\n    int ret, flags;\n    JSAtom atom;\n\n    obj = argv[0];\n    prop = argv[1];\n    desc = argv[2];\n\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    atom = JS_ValueToAtom(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return JS_EXCEPTION;\n    flags = 0;\n    if (!magic)\n        flags |= JS_PROP_THROW;\n    ret = JS_DefinePropertyDesc(ctx, obj, atom, desc, flags);\n    JS_FreeAtom(ctx, atom);\n    if (ret < 0) {\n        return JS_EXCEPTION;\n    } else if (magic) {\n        return JS_NewBool(ctx, ret);\n    } else {\n        return JS_DupValue(ctx, obj);\n    }\n}\n\nstatic JSValue js_object_defineProperties(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv)\n{\n    // defineProperties(obj, properties)\n    JSValueConst obj = argv[0];\n\n    if (JS_ObjectDefineProperties(ctx, obj, argv[1]))\n        return JS_EXCEPTION;\n    else\n        return JS_DupValue(ctx, obj);\n}\n\n/* magic = 1 if called as __defineSetter__ */\nstatic JSValue js_object___defineGetter__(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv, int magic)\n{\n    JSValue obj;\n    JSValueConst prop, value, get, set;\n    int ret, flags;\n    JSAtom atom;\n\n    prop = argv[0];\n    value = argv[1];\n\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n\n    if (check_function(ctx, value)) {\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    atom = JS_ValueToAtom(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL)) {\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    flags = JS_PROP_THROW |\n        JS_PROP_HAS_ENUMERABLE | JS_PROP_ENUMERABLE |\n        JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE;\n    if (magic) {\n        get = JS_UNDEFINED;\n        set = value;\n        flags |= JS_PROP_HAS_SET;\n    } else {\n        get = value;\n        set = JS_UNDEFINED;\n        flags |= JS_PROP_HAS_GET;\n    }\n    ret = JS_DefineProperty(ctx, obj, atom, JS_UNDEFINED, get, set, flags);\n    JS_FreeValue(ctx, obj);\n    JS_FreeAtom(ctx, atom);\n    if (ret < 0) {\n        return JS_EXCEPTION;\n    } else {\n        return JS_UNDEFINED;\n    }\n}\n\nstatic JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst this_val,\n                                                  int argc, JSValueConst *argv, int magic)\n{\n    JSValueConst prop;\n    JSAtom atom;\n    JSValue ret, obj;\n    JSPropertyDescriptor desc;\n    int res, flags;\n\n    if (magic) {\n        /* Reflect.getOwnPropertyDescriptor case */\n        if (JS_VALUE_GET_TAG(argv[0]) != JS_TAG_OBJECT)\n            return JS_ThrowTypeErrorNotAnObject(ctx);\n        obj = JS_DupValue(ctx, argv[0]);\n    } else {\n        obj = JS_ToObject(ctx, argv[0]);\n        if (JS_IsException(obj))\n            return obj;\n    }\n    prop = argv[1];\n    atom = JS_ValueToAtom(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL))\n        goto exception;\n    ret = JS_UNDEFINED;\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        res = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(obj), atom);\n        if (res < 0)\n            goto exception;\n        if (res) {\n            ret = JS_NewObject(ctx);\n            if (JS_IsException(ret))\n                goto exception1;\n            flags = JS_PROP_C_W_E | JS_PROP_THROW;\n            if (desc.flags & JS_PROP_GETSET) {\n                if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_get, JS_DupValue(ctx, desc.getter), flags) < 0\n                ||  JS_DefinePropertyValue(ctx, ret, JS_ATOM_set, JS_DupValue(ctx, desc.setter), flags) < 0)\n                    goto exception1;\n            } else {\n                if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, desc.value), flags) < 0\n                ||  JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable,\n                                           JS_NewBool(ctx, (desc.flags & JS_PROP_WRITABLE) != 0), flags) < 0)\n                    goto exception1;\n            }\n            if (JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable,\n                                       JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0), flags) < 0\n            ||  JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable,\n                                       JS_NewBool(ctx, (desc.flags & JS_PROP_CONFIGURABLE) != 0), flags) < 0)\n                goto exception1;\n            js_free_desc(ctx, &desc);\n        }\n    }\n    JS_FreeAtom(ctx, atom);\n    JS_FreeValue(ctx, obj);\n    return ret;\n\nexception1:\n    js_free_desc(ctx, &desc);\n    JS_FreeValue(ctx, ret);\nexception:\n    JS_FreeAtom(ctx, atom);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValueConst this_val,\n                                                   int argc, JSValueConst *argv)\n{\n    //getOwnPropertyDescriptors(obj)\n    JSValue obj, r;\n    JSObject *p;\n    JSPropertyEnum *props;\n    uint32_t len, i;\n\n    r = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, argv[0]);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n\n    p = JS_VALUE_GET_OBJ(obj);\n    if (JS_GetOwnPropertyNamesInternal(ctx, &props, &len, p,\n                               JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK))\n        goto exception;\n    r = JS_NewObject(ctx);\n    if (JS_IsException(r))\n        goto exception;\n    for(i = 0; i < len; i++) {\n        JSValue atomValue, desc;\n        JSValueConst args[2];\n\n        atomValue = JS_AtomToValue(ctx, props[i].atom);\n        if (JS_IsException(atomValue))\n            goto exception;\n        args[0] = obj;\n        args[1] = atomValue;\n        desc = js_object_getOwnPropertyDescriptor(ctx, JS_UNDEFINED, 2, args, 0);\n        JS_FreeValue(ctx, atomValue);\n        if (JS_IsException(desc))\n            goto exception;\n        if (!JS_IsUndefined(desc)) {\n            if (JS_DefinePropertyValue(ctx, r, props[i].atom, desc,\n                                       JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                goto exception;\n        }\n    }\n    js_free_prop_enum(ctx, props, len);\n    JS_FreeValue(ctx, obj);\n    return r;\n\nexception:\n    js_free_prop_enum(ctx, props, len);\n    JS_FreeValue(ctx, obj);\n    JS_FreeValue(ctx, r);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1,\n                                       int flags, int kind)\n{\n    JSValue obj, r, val, key, value;\n    JSObject *p;\n    JSPropertyEnum *atoms;\n    uint32_t len, i, j;\n\n    r = JS_UNDEFINED;\n    val = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, obj1);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (JS_GetOwnPropertyNamesInternal(ctx, &atoms, &len, p, flags & ~JS_GPN_ENUM_ONLY))\n        goto exception;\n    r = JS_NewArray(ctx);\n    if (JS_IsException(r))\n        goto exception;\n    for(j = i = 0; i < len; i++) {\n        JSAtom atom = atoms[i].atom;\n        if (flags & JS_GPN_ENUM_ONLY) {\n            JSPropertyDescriptor desc;\n            int res;\n\n            /* Check if property is still enumerable */\n            res = JS_GetOwnPropertyInternal(ctx, &desc, p, atom);\n            if (res < 0)\n                goto exception;\n            if (!res)\n                continue;\n            js_free_desc(ctx, &desc);\n            if (!(desc.flags & JS_PROP_ENUMERABLE))\n                continue;\n        }\n        switch(kind) {\n        default:\n        case JS_ITERATOR_KIND_KEY:\n            val = JS_AtomToValue(ctx, atom);\n            if (JS_IsException(val))\n                goto exception;\n            break;\n        case JS_ITERATOR_KIND_VALUE:\n            val = JS_GetProperty(ctx, obj, atom);\n            if (JS_IsException(val))\n                goto exception;\n            break;\n        case JS_ITERATOR_KIND_KEY_AND_VALUE:\n            val = JS_NewArray(ctx);\n            if (JS_IsException(val))\n                goto exception;\n            key = JS_AtomToValue(ctx, atom);\n            if (JS_IsException(key))\n                goto exception1;\n            if (JS_CreateDataPropertyUint32(ctx, val, 0, key, JS_PROP_THROW) < 0)\n                goto exception1;\n            value = JS_GetProperty(ctx, obj, atom);\n            if (JS_IsException(value))\n                goto exception1;\n            if (JS_CreateDataPropertyUint32(ctx, val, 1, value, JS_PROP_THROW) < 0)\n                goto exception1;\n            break;\n        }\n        if (JS_CreateDataPropertyUint32(ctx, r, j++, val, 0) < 0)\n            goto exception;\n    }\n    goto done;\n\nexception1:\n    JS_FreeValue(ctx, val);\nexception:\n    JS_FreeValue(ctx, r);\n    r = JS_EXCEPTION;\ndone:\n    js_free_prop_enum(ctx, atoms, len);\n    JS_FreeValue(ctx, obj);\n    return r;\n}\n\nstatic JSValue js_object_getOwnPropertyNames(JSContext *ctx, JSValueConst this_val,\n                                             int argc, JSValueConst *argv)\n{\n    return JS_GetOwnPropertyNames2(ctx, argv[0],\n                                   JS_GPN_STRING_MASK, JS_ITERATOR_KIND_KEY);\n}\n\nstatic JSValue js_object_getOwnPropertySymbols(JSContext *ctx, JSValueConst this_val,\n                                             int argc, JSValueConst *argv)\n{\n    return JS_GetOwnPropertyNames2(ctx, argv[0],\n                                   JS_GPN_SYMBOL_MASK, JS_ITERATOR_KIND_KEY);\n}\n\nstatic JSValue js_object_keys(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int kind)\n{\n    return JS_GetOwnPropertyNames2(ctx, argv[0],\n                                   JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK, kind);\n}\n\nstatic JSValue js_object_isExtensible(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv, int reflect)\n{\n    JSValueConst obj;\n    int ret;\n\n    obj = argv[0];\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {\n        if (reflect)\n            return JS_ThrowTypeErrorNotAnObject(ctx);\n        else\n            return JS_FALSE;\n    }\n    ret = JS_IsExtensible(ctx, obj);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst this_val,\n                                           int argc, JSValueConst *argv, int reflect)\n{\n    JSValueConst obj;\n    int ret;\n\n    obj = argv[0];\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) {\n        if (reflect)\n            return JS_ThrowTypeErrorNotAnObject(ctx);\n        else\n            return JS_DupValue(ctx, obj);\n    }\n    ret = JS_PreventExtensions(ctx, obj);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    if (reflect) {\n        return JS_NewBool(ctx, ret);\n    } else {\n        if (!ret)\n            return JS_ThrowTypeError(ctx, \"proxy preventExtensions handler returned false\");\n        return JS_DupValue(ctx, obj);\n    }\n}\n\nstatic JSValue js_object_hasOwnProperty(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    JSValue obj;\n    JSAtom atom;\n    JSObject *p;\n    BOOL ret;\n\n    atom = JS_ValueToAtom(ctx, argv[0]); /* must be done first */\n    if (unlikely(atom == JS_ATOM_NULL))\n        return JS_EXCEPTION;\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj)) {\n        JS_FreeAtom(ctx, atom);\n        return obj;\n    }\n    p = JS_VALUE_GET_OBJ(obj);\n    ret = JS_GetOwnPropertyInternal(ctx, NULL, p, atom);\n    JS_FreeAtom(ctx, atom);\n    JS_FreeValue(ctx, obj);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_object_valueOf(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    return JS_ToObject(ctx, this_val);\n}\n\nstatic JSValue js_object_toString(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValue obj, tag;\n    int is_array;\n    JSAtom atom;\n    JSObject *p;\n\n    if (JS_IsNull(this_val)) {\n        tag = JS_NewString(ctx, \"Null\");\n    } else if (JS_IsUndefined(this_val)) {\n        tag = JS_NewString(ctx, \"Undefined\");\n    } else {\n        obj = JS_ToObject(ctx, this_val);\n        if (JS_IsException(obj))\n            return obj;\n        is_array = JS_IsArray(ctx, obj);\n        if (is_array < 0) {\n            JS_FreeValue(ctx, obj);\n            return JS_EXCEPTION;\n        }\n        if (is_array) {\n            atom = JS_ATOM_Array;\n        } else if (JS_IsFunction(ctx, obj)) {\n            atom = JS_ATOM_Function;\n        } else {\n            p = JS_VALUE_GET_OBJ(obj);\n            switch(p->class_id) {\n            case JS_CLASS_STRING:\n            case JS_CLASS_ARGUMENTS:\n            case JS_CLASS_MAPPED_ARGUMENTS:\n            case JS_CLASS_ERROR:\n            case JS_CLASS_BOOLEAN:\n            case JS_CLASS_NUMBER:\n            case JS_CLASS_DATE:\n            case JS_CLASS_REGEXP:\n                atom = ctx->rt->class_array[p->class_id].class_name;\n                break;\n            default:\n                atom = JS_ATOM_Object;\n                break;\n            }\n        }\n        tag = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_toStringTag);\n        JS_FreeValue(ctx, obj);\n        if (JS_IsException(tag))\n            return JS_EXCEPTION;\n        if (!JS_IsString(tag)) {\n            JS_FreeValue(ctx, tag);\n            tag = JS_AtomToString(ctx, atom);\n        }\n    }\n    return JS_ConcatString3(ctx, \"[object \", tag, \"]\");\n}\n\nstatic JSValue js_object_toLocaleString(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    return JS_Invoke(ctx, this_val, JS_ATOM_toString, 0, NULL);\n}\n\nstatic JSValue js_object_assign(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    // Object.assign(obj, source1)\n    JSValue obj, s;\n    int i;\n\n    s = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, argv[0]);\n    if (JS_IsException(obj))\n        goto exception;\n    for (i = 1; i < argc; i++) {\n        if (!JS_IsNull(argv[i]) && !JS_IsUndefined(argv[i])) {\n            s = JS_ToObject(ctx, argv[i]);\n            if (JS_IsException(s))\n                goto exception;\n            if (JS_CopyDataProperties(ctx, obj, s, JS_UNDEFINED, TRUE))\n                goto exception;\n            JS_FreeValue(ctx, s);\n        }\n    }\n    return obj;\nexception:\n    JS_FreeValue(ctx, obj);\n    JS_FreeValue(ctx, s);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_object_seal(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int freeze_flag)\n{\n    JSValueConst obj = argv[0];\n    JSObject *p;\n    JSPropertyEnum *props;\n    uint32_t len, i;\n    int flags, desc_flags, res;\n\n    if (!JS_IsObject(obj))\n        return JS_DupValue(ctx, obj);\n\n    res = JS_PreventExtensions(ctx, obj);\n    if (res < 0)\n        return JS_EXCEPTION;\n    if (!res) {\n        return JS_ThrowTypeError(ctx, \"proxy preventExtensions handler returned false\");\n    }\n    \n    p = JS_VALUE_GET_OBJ(obj);\n    flags = JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK;\n    if (JS_GetOwnPropertyNamesInternal(ctx, &props, &len, p, flags))\n        return JS_EXCEPTION;\n\n    for(i = 0; i < len; i++) {\n        JSPropertyDescriptor desc;\n        JSAtom prop = props[i].atom;\n\n        desc_flags = JS_PROP_THROW | JS_PROP_HAS_CONFIGURABLE;\n        if (freeze_flag) {\n            res = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);\n            if (res < 0)\n                goto exception;\n            if (res) {\n                if (desc.flags & JS_PROP_WRITABLE)\n                    desc_flags |= JS_PROP_HAS_WRITABLE;\n                js_free_desc(ctx, &desc);\n            }\n        }\n        if (JS_DefineProperty(ctx, obj, prop, JS_UNDEFINED,\n                              JS_UNDEFINED, JS_UNDEFINED, desc_flags) < 0)\n            goto exception;\n    }\n    js_free_prop_enum(ctx, props, len);\n    return JS_DupValue(ctx, obj);\n\n exception:\n    js_free_prop_enum(ctx, props, len);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv, int is_frozen)\n{\n    JSValueConst obj = argv[0];\n    JSObject *p;\n    JSPropertyEnum *props;\n    uint32_t len, i;\n    int flags, res;\n    \n    if (!JS_IsObject(obj))\n        return JS_TRUE;\n\n    p = JS_VALUE_GET_OBJ(obj);\n    flags = JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK;\n    if (JS_GetOwnPropertyNamesInternal(ctx, &props, &len, p, flags))\n        return JS_EXCEPTION;\n\n    for(i = 0; i < len; i++) {\n        JSPropertyDescriptor desc;\n        JSAtom prop = props[i].atom;\n\n        res = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);\n        if (res < 0)\n            goto exception;\n        if (res) {\n            js_free_desc(ctx, &desc);\n            if ((desc.flags & JS_PROP_CONFIGURABLE)\n            ||  (is_frozen && (desc.flags & JS_PROP_WRITABLE))) {\n                res = FALSE;\n                goto done;\n            }\n        }\n    }\n    res = JS_IsExtensible(ctx, obj);\n    if (res < 0)\n        return JS_EXCEPTION;\n    res ^= 1;\ndone:        \n    js_free_prop_enum(ctx, props, len);\n    return JS_NewBool(ctx, res);\n\nexception:\n    js_free_prop_enum(ctx, props, len);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue obj, iter, next_method = JS_UNDEFINED;\n    JSValueConst iterable;\n    BOOL done;\n\n    /*  RequireObjectCoercible() not necessary because it is tested in\n        JS_GetIterator() by JS_GetProperty() */\n    iterable = argv[0];\n\n    obj = JS_NewObject(ctx);\n    if (JS_IsException(obj))\n        return obj;\n    \n    iter = JS_GetIterator(ctx, iterable, FALSE);\n    if (JS_IsException(iter))\n        goto fail;\n    next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);\n    if (JS_IsException(next_method))\n        goto fail;\n    \n    for(;;) {\n        JSValue key, value, item;\n        item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);\n        if (JS_IsException(item))\n            goto fail;\n        if (done) {\n            JS_FreeValue(ctx, item);\n            break;\n        }\n        \n        key = JS_UNDEFINED;\n        value = JS_UNDEFINED;\n        if (!JS_IsObject(item)) {\n            JS_ThrowTypeErrorNotAnObject(ctx);\n            goto fail1;\n        }\n        key = JS_GetPropertyUint32(ctx, item, 0);\n        if (JS_IsException(key))\n            goto fail1;\n        value = JS_GetPropertyUint32(ctx, item, 1);\n        if (JS_IsException(value)) {\n            JS_FreeValue(ctx, key);\n            goto fail1;\n        }\n        if (JS_DefinePropertyValueValue(ctx, obj, key, value,\n                                        JS_PROP_C_W_E | JS_PROP_THROW) < 0) {\n        fail1:\n            JS_FreeValue(ctx, item);\n            goto fail;\n        }\n        JS_FreeValue(ctx, item);\n    }\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    return obj;\n fail:\n    if (JS_IsObject(iter)) {\n        /* close the iterator object, preserving pending exception */\n        JS_IteratorClose(ctx, iter, TRUE);\n    }\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\n#if 0\n/* Note: corresponds to ECMA spec: CreateDataPropertyOrThrow() */\nstatic JSValue js_object___setOwnProperty(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv)\n{\n    int ret;\n    ret = JS_DefinePropertyValueValue(ctx, argv[0], JS_DupValue(ctx, argv[1]),\n                                      JS_DupValue(ctx, argv[2]),\n                                      JS_PROP_C_W_E | JS_PROP_THROW);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_object___toObject(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    return JS_ToObject(ctx, argv[0]);\n}\n\nstatic JSValue js_object___toPrimitive(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    int hint = HINT_NONE;\n\n    if (JS_VALUE_GET_TAG(argv[1]) == JS_TAG_INT)\n        hint = JS_VALUE_GET_INT(argv[1]);\n\n    return JS_ToPrimitive(ctx, argv[0], hint);\n}\n#endif\n\n/* return an empty string if not an object */\nstatic JSValue js_object___getClass(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSAtom atom;\n    JSObject *p;\n    uint32_t tag;\n    int class_id;\n\n    tag = JS_VALUE_GET_NORM_TAG(argv[0]);\n    if (tag == JS_TAG_OBJECT) {\n        p = JS_VALUE_GET_OBJ(argv[0]);\n        class_id = p->class_id;\n        if (class_id == JS_CLASS_PROXY && JS_IsFunction(ctx, argv[0]))\n            class_id = JS_CLASS_BYTECODE_FUNCTION;\n        atom = ctx->rt->class_array[class_id].class_name;\n    } else {\n        atom = JS_ATOM_empty_string;\n    }\n    return JS_AtomToString(ctx, atom);\n}\n\nstatic JSValue js_object_is(JSContext *ctx, JSValueConst this_val,\n                            int argc, JSValueConst *argv)\n{\n    return JS_NewBool(ctx, js_same_value(ctx, argv[0], argv[1]));\n}\n\n#if 0\nstatic JSValue js_object___getObjectData(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    return JS_GetObjectData(ctx, argv[0]);\n}\n\nstatic JSValue js_object___setObjectData(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    if (JS_SetObjectData(ctx, argv[0], JS_DupValue(ctx, argv[1])))\n        return JS_EXCEPTION;\n    return JS_DupValue(ctx, argv[1]);\n}\n\nstatic JSValue js_object___toPropertyKey(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    return JS_ToPropertyKey(ctx, argv[0]);\n}\n\nstatic JSValue js_object___isObject(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    return JS_NewBool(ctx, JS_IsObject(argv[0]));\n}\n\nstatic JSValue js_object___isSameValueZero(JSContext *ctx, JSValueConst this_val,\n                                           int argc, JSValueConst *argv)\n{\n    return JS_NewBool(ctx, js_same_value_zero(ctx, argv[0], argv[1]));\n}\n\nstatic JSValue js_object___isConstructor(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    return JS_NewBool(ctx, JS_IsConstructor(ctx, argv[0]));\n}\n#endif\n\nstatic JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj,\n                                     JSValueConst defaultConstructor)\n{\n    JSValue ctor, species;\n\n    if (!JS_IsObject(obj))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    ctor = JS_GetProperty(ctx, obj, JS_ATOM_constructor);\n    if (JS_IsException(ctor))\n        return ctor;\n    if (JS_IsUndefined(ctor))\n        return JS_DupValue(ctx, defaultConstructor);\n    if (!JS_IsObject(ctor)) {\n        JS_FreeValue(ctx, ctor);\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    }\n    species = JS_GetProperty(ctx, ctor, JS_ATOM_Symbol_species);\n    JS_FreeValue(ctx, ctor);\n    if (JS_IsException(species))\n        return species;\n    if (JS_IsUndefined(species) || JS_IsNull(species))\n        return JS_DupValue(ctx, defaultConstructor);\n    if (!JS_IsConstructor(ctx, species)) {\n        JS_FreeValue(ctx, species);\n        return JS_ThrowTypeError(ctx, \"not a constructor\");\n    }\n    return species;\n}\n\n#if 0\nstatic JSValue js_object___speciesConstructor(JSContext *ctx, JSValueConst this_val,\n                                              int argc, JSValueConst *argv)\n{\n    return JS_SpeciesConstructor(ctx, argv[0], argv[1]);\n}\n#endif\n\nstatic JSValue js_object_get___proto__(JSContext *ctx, JSValueConst this_val)\n{\n    JSValue val, ret;\n\n    val = JS_ToObject(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    ret = JS_GetPrototype(ctx, val);\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic JSValue js_object_set___proto__(JSContext *ctx, JSValueConst this_val,\n                                       JSValueConst proto)\n{\n    if (JS_IsUndefined(this_val) || JS_IsNull(this_val))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    if (!JS_IsObject(proto) && !JS_IsNull(proto))\n        return JS_UNDEFINED;\n    if (JS_SetPrototypeInternal(ctx, this_val, proto, TRUE) < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_UNDEFINED;\n}\n\nstatic JSValue js_object_isPrototypeOf(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValue obj, v1;\n    JSValueConst v;\n    int res;\n\n    v = argv[0];\n    if (!JS_IsObject(v))\n        return JS_FALSE;\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    v1 = JS_DupValue(ctx, v);\n    for(;;) {\n        v1 = JS_GetPrototypeFree(ctx, v1);\n        if (JS_IsException(v1))\n            goto exception;\n        if (JS_IsNull(v1)) {\n            res = FALSE;\n            break;\n        }\n        if (JS_VALUE_GET_OBJ(obj) == JS_VALUE_GET_OBJ(v1)) {\n            res = TRUE;\n            break;\n        }\n        /* avoid infinite loop (possible with proxies) */\n        if (js_poll_interrupts(ctx))\n            goto exception;\n    }\n    JS_FreeValue(ctx, v1);\n    JS_FreeValue(ctx, obj);\n    return JS_NewBool(ctx, res);\n\nexception:\n    JS_FreeValue(ctx, v1);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueConst this_val,\n                                              int argc, JSValueConst *argv)\n{\n    JSValue obj, res = JS_EXCEPTION;\n    JSAtom prop = JS_ATOM_NULL;\n    JSPropertyDescriptor desc;\n    int has_prop;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj))\n        goto exception;\n    prop = JS_ValueToAtom(ctx, argv[0]);\n    if (unlikely(prop == JS_ATOM_NULL))\n        goto exception;\n\n    has_prop = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(obj), prop);\n    if (has_prop < 0)\n        goto exception;\n    if (has_prop) {\n        res = JS_NewBool(ctx, (desc.flags & JS_PROP_ENUMERABLE) != 0);\n        js_free_desc(ctx, &desc);\n    } else {\n        res = JS_FALSE;\n    }\n\nexception:\n    JS_FreeAtom(ctx, prop);\n    JS_FreeValue(ctx, obj);\n    return res;\n}\n\nstatic JSValue js_object___lookupGetter__(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv, int setter)\n{\n    JSValue obj, res = JS_EXCEPTION;\n    JSAtom prop = JS_ATOM_NULL;\n    JSPropertyDescriptor desc;\n    int has_prop;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj))\n        goto exception;\n    prop = JS_ValueToAtom(ctx, argv[0]);\n    if (unlikely(prop == JS_ATOM_NULL))\n        goto exception;\n\n    for (;;) {\n        has_prop = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(obj), prop);\n        if (has_prop < 0)\n            goto exception;\n        if (has_prop) {\n            if (desc.flags & JS_PROP_GETSET)\n                res = JS_DupValue(ctx, setter ? desc.setter : desc.getter);\n            else\n                res = JS_UNDEFINED;\n            js_free_desc(ctx, &desc);\n            break;\n        }\n        obj = JS_GetPrototypeFree(ctx, obj);\n        if (JS_IsException(obj))\n            goto exception;\n        if (JS_IsNull(obj)) {\n            res = JS_UNDEFINED;\n            break;\n        }\n        /* avoid infinite loop (possible with proxies) */\n        if (js_poll_interrupts(ctx))\n            goto exception;\n    }\n\nexception:\n    JS_FreeAtom(ctx, prop);\n    JS_FreeValue(ctx, obj);\n    return res;\n}\n\nstatic const JSCFunctionListEntry js_object_funcs[] = {\n    JS_CFUNC_DEF(\"create\", 2, js_object_create ),\n    JS_CFUNC_MAGIC_DEF(\"getPrototypeOf\", 1, js_object_getPrototypeOf, 0 ),\n    JS_CFUNC_DEF(\"setPrototypeOf\", 2, js_object_setPrototypeOf ),\n    JS_CFUNC_MAGIC_DEF(\"defineProperty\", 3, js_object_defineProperty, 0 ),\n    JS_CFUNC_DEF(\"defineProperties\", 2, js_object_defineProperties ),\n    JS_CFUNC_DEF(\"getOwnPropertyNames\", 1, js_object_getOwnPropertyNames ),\n    JS_CFUNC_DEF(\"getOwnPropertySymbols\", 1, js_object_getOwnPropertySymbols ),\n    JS_CFUNC_MAGIC_DEF(\"keys\", 1, js_object_keys, JS_ITERATOR_KIND_KEY ),\n    JS_CFUNC_MAGIC_DEF(\"values\", 1, js_object_keys, JS_ITERATOR_KIND_VALUE ),\n    JS_CFUNC_MAGIC_DEF(\"entries\", 1, js_object_keys, JS_ITERATOR_KIND_KEY_AND_VALUE ),\n    JS_CFUNC_MAGIC_DEF(\"isExtensible\", 1, js_object_isExtensible, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"preventExtensions\", 1, js_object_preventExtensions, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"getOwnPropertyDescriptor\", 2, js_object_getOwnPropertyDescriptor, 0 ),\n    JS_CFUNC_DEF(\"getOwnPropertyDescriptors\", 1, js_object_getOwnPropertyDescriptors ),\n    JS_CFUNC_DEF(\"is\", 2, js_object_is ),\n    JS_CFUNC_DEF(\"assign\", 2, js_object_assign ),\n    JS_CFUNC_MAGIC_DEF(\"seal\", 1, js_object_seal, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"freeze\", 1, js_object_seal, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"isSealed\", 1, js_object_isSealed, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"isFrozen\", 1, js_object_isSealed, 1 ),\n    JS_CFUNC_DEF(\"__getClass\", 1, js_object___getClass ),\n    //JS_CFUNC_DEF(\"__isObject\", 1, js_object___isObject ),\n    //JS_CFUNC_DEF(\"__isConstructor\", 1, js_object___isConstructor ),\n    //JS_CFUNC_DEF(\"__toObject\", 1, js_object___toObject ),\n    //JS_CFUNC_DEF(\"__setOwnProperty\", 3, js_object___setOwnProperty ),\n    //JS_CFUNC_DEF(\"__toPrimitive\", 2, js_object___toPrimitive ),\n    //JS_CFUNC_DEF(\"__toPropertyKey\", 1, js_object___toPropertyKey ),\n    //JS_CFUNC_DEF(\"__speciesConstructor\", 2, js_object___speciesConstructor ),\n    //JS_CFUNC_DEF(\"__isSameValueZero\", 2, js_object___isSameValueZero ),\n    //JS_CFUNC_DEF(\"__getObjectData\", 1, js_object___getObjectData ),\n    //JS_CFUNC_DEF(\"__setObjectData\", 2, js_object___setObjectData ),\n    JS_CFUNC_DEF(\"fromEntries\", 1, js_object_fromEntries ),\n};\n\nstatic const JSCFunctionListEntry js_object_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_object_toString ),\n    JS_CFUNC_DEF(\"toLocaleString\", 0, js_object_toLocaleString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_object_valueOf ),\n    JS_CFUNC_DEF(\"hasOwnProperty\", 1, js_object_hasOwnProperty ),\n    JS_CFUNC_DEF(\"isPrototypeOf\", 1, js_object_isPrototypeOf ),\n    JS_CFUNC_DEF(\"propertyIsEnumerable\", 1, js_object_propertyIsEnumerable ),\n    JS_CGETSET_DEF(\"__proto__\", js_object_get___proto__, js_object_set___proto__ ),\n    JS_CFUNC_MAGIC_DEF(\"__defineGetter__\", 2, js_object___defineGetter__, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"__defineSetter__\", 2, js_object___defineGetter__, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"__lookupGetter__\", 1, js_object___lookupGetter__, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"__lookupSetter__\", 1, js_object___lookupGetter__, 1 ),\n};\n\n/* Function class */\n\nstatic JSValue js_function_proto(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    return JS_UNDEFINED;\n}\n\n/* XXX: add a specific eval mode so that Function(\"}), ({\") is rejected */\nstatic JSValue js_function_constructor(JSContext *ctx, JSValueConst new_target,\n                                       int argc, JSValueConst *argv, int magic)\n{\n    JSFunctionKindEnum func_kind = magic;\n    int i, n, ret;\n    JSValue s, proto, obj = JS_UNDEFINED;\n    StringBuffer b_s, *b = &b_s;\n\n    string_buffer_init(ctx, b, 0);\n    string_buffer_putc8(b, '(');\n    \n    if (func_kind == JS_FUNC_ASYNC || func_kind == JS_FUNC_ASYNC_GENERATOR) {\n        string_buffer_puts8(b, \"async \");\n    }\n    string_buffer_puts8(b, \"function\");\n\n    if (func_kind == JS_FUNC_GENERATOR || func_kind == JS_FUNC_ASYNC_GENERATOR) {\n        string_buffer_putc8(b, '*');\n    }\n    string_buffer_puts8(b, \" anonymous(\");\n\n    n = argc - 1;\n    for(i = 0; i < n; i++) {\n        if (i != 0) {\n            string_buffer_putc8(b, ',');\n        }\n        if (string_buffer_concat_value(b, argv[i]))\n            goto fail;\n    }\n    string_buffer_puts8(b, \"\\n) {\\n\");\n    if (n >= 0) {\n        if (string_buffer_concat_value(b, argv[n]))\n            goto fail;\n    }\n    string_buffer_puts8(b, \"\\n})\");\n    s = string_buffer_end(b);\n    if (JS_IsException(s))\n        goto fail1;\n\n    obj = JS_EvalObject(ctx, ctx->global_obj, s, JS_EVAL_TYPE_INDIRECT, -1);\n    JS_FreeValue(ctx, s);\n    if (JS_IsException(obj))\n        goto fail1;\n    if (!JS_IsUndefined(new_target)) {\n        /* set the prototype */\n        proto = JS_GetProperty(ctx, new_target, JS_ATOM_prototype);\n        if (JS_IsException(proto))\n            goto fail1;\n        if (!JS_IsObject(proto)) {\n            JSContext *realm;\n            JS_FreeValue(ctx, proto);\n            realm = JS_GetFunctionRealm(ctx, new_target);\n            if (!realm)\n                goto fail1;\n            proto = JS_DupValue(ctx, realm->class_proto[func_kind_to_class_id[func_kind]]);\n        }\n        ret = JS_SetPrototypeInternal(ctx, obj, proto, TRUE);\n        JS_FreeValue(ctx, proto);\n        if (ret < 0)\n            goto fail1;\n    }\n    return obj;\n\n fail:\n    string_buffer_free(b);\n fail1:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic __exception int js_get_length32(JSContext *ctx, uint32_t *pres,\n                                       JSValueConst obj)\n{\n    JSValue len_val;\n    len_val = JS_GetProperty(ctx, obj, JS_ATOM_length);\n    if (JS_IsException(len_val)) {\n        *pres = 0;\n        return -1;\n    }\n    return JS_ToUint32Free(ctx, pres, len_val);\n}\n\nstatic __exception int js_get_length64(JSContext *ctx, int64_t *pres,\n                                       JSValueConst obj)\n{\n    JSValue len_val;\n    len_val = JS_GetProperty(ctx, obj, JS_ATOM_length);\n    if (JS_IsException(len_val)) {\n        *pres = 0;\n        return -1;\n    }\n    return JS_ToLengthFree(ctx, pres, len_val);\n}\n\nstatic void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len)\n{\n    uint32_t i;\n    for(i = 0; i < len; i++) {\n        JS_FreeValue(ctx, tab[i]);\n    }\n    js_free(ctx, tab);\n}\n\n/* XXX: should use ValueArray */\nstatic JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,\n                               JSValueConst array_arg)\n{\n    uint32_t len, i;\n    JSValue *tab, ret;\n    JSObject *p;\n\n    if (JS_VALUE_GET_TAG(array_arg) != JS_TAG_OBJECT) {\n        JS_ThrowTypeError(ctx, \"not a object\");\n        return NULL;\n    }\n    if (js_get_length32(ctx, &len, array_arg))\n        return NULL;\n    /* avoid allocating 0 bytes */\n    tab = js_mallocz(ctx, sizeof(tab[0]) * max_uint32(1, len));\n    if (!tab)\n        return NULL;\n    p = JS_VALUE_GET_OBJ(array_arg);\n    if ((p->class_id == JS_CLASS_ARRAY || p->class_id == JS_CLASS_ARGUMENTS) &&\n        p->fast_array &&\n        len == p->u.array.count) {\n        for(i = 0; i < len; i++) {\n            tab[i] = JS_DupValue(ctx, p->u.array.u.values[i]);\n        }\n    } else {\n        for(i = 0; i < len; i++) {\n            ret = JS_GetPropertyUint32(ctx, array_arg, i);\n            if (JS_IsException(ret)) {\n                free_arg_list(ctx, tab, i);\n                return NULL;\n            }\n            tab[i] = ret;\n        }\n    }\n    *plen = len;\n    return tab;\n}\n\nstatic JSValue js_function_apply(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv, int magic)\n{\n    JSValueConst this_arg, array_arg;\n    uint32_t len;\n    JSValue *tab, ret;\n\n    if (check_function(ctx, this_val))\n        return JS_EXCEPTION;\n    this_arg = argv[0];\n    array_arg = argv[1];\n    if (JS_VALUE_GET_TAG(array_arg) == JS_TAG_UNDEFINED ||\n        JS_VALUE_GET_TAG(array_arg) == JS_TAG_NULL) {\n        return JS_Call(ctx, this_val, this_arg, 0, NULL);\n    }\n    tab = build_arg_list(ctx, &len, array_arg);\n    if (!tab)\n        return JS_EXCEPTION;\n    if (magic) {\n        ret = JS_CallConstructor2(ctx, this_val, this_arg, len, (JSValueConst *)tab);\n    } else {\n        ret = JS_Call(ctx, this_val, this_arg, len, (JSValueConst *)tab);\n    }\n    free_arg_list(ctx, tab, len);\n    return ret;\n}\n\nstatic JSValue js_function_call(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    if (argc <= 0) {\n        return JS_Call(ctx, this_val, JS_UNDEFINED, 0, NULL);\n    } else {\n        return JS_Call(ctx, this_val, argv[0], argc - 1, argv + 1);\n    }\n}\n\nstatic JSValue js_function_bind(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSBoundFunction *bf;\n    JSValue func_obj, name1;\n    JSObject *p;\n    int arg_count, i;\n    uint32_t len1;\n\n    if (check_function(ctx, this_val))\n        return JS_EXCEPTION;\n\n    func_obj = JS_NewObjectProtoClass(ctx, ctx->function_proto,\n                                 JS_CLASS_BOUND_FUNCTION);\n    if (JS_IsException(func_obj))\n        return JS_EXCEPTION;\n    p = JS_VALUE_GET_OBJ(func_obj);\n    p->is_constructor = JS_IsConstructor(ctx, this_val);\n    arg_count = max_int(0, argc - 1);\n    bf = js_malloc(ctx, sizeof(*bf) + arg_count * sizeof(JSValue));\n    if (!bf)\n        goto exception;\n    bf->func_obj = JS_DupValue(ctx, this_val);\n    bf->this_val = JS_DupValue(ctx, argv[0]);\n    bf->argc = arg_count;\n    for(i = 0; i < arg_count; i++) {\n        bf->argv[i] = JS_DupValue(ctx, argv[i + 1]);\n    }\n    p->u.bound_function = bf;\n\n    name1 = JS_GetProperty(ctx, this_val, JS_ATOM_name);\n    if (JS_IsException(name1))\n        goto exception;\n    if (!JS_IsString(name1)) {\n        JS_FreeValue(ctx, name1);\n        name1 = JS_AtomToString(ctx, JS_ATOM_empty_string);\n    }\n    name1 = JS_ConcatString3(ctx, \"bound \", name1, \"\");\n    if (JS_IsException(name1))\n        goto exception;\n    JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_name, name1,\n                           JS_PROP_CONFIGURABLE);\n    if (js_get_length32(ctx, &len1, this_val))\n        goto exception;\n    if (len1 <= (uint32_t)arg_count)\n        len1 = 0;\n    else\n        len1 -= arg_count;\n    JS_DefinePropertyValue(ctx, func_obj, JS_ATOM_length,\n                           JS_NewUint32(ctx, len1),\n                           JS_PROP_CONFIGURABLE);\n    return func_obj;\n exception:\n    JS_FreeValue(ctx, func_obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_function_toString(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    JSFunctionKindEnum func_kind = JS_FUNC_NORMAL;\n\n    if (check_function(ctx, this_val))\n        return JS_EXCEPTION;\n\n    p = JS_VALUE_GET_OBJ(this_val);\n    if (js_class_has_bytecode(p->class_id)) {\n        JSFunctionBytecode *b = p->u.func.function_bytecode;\n        if (b->has_debug && b->debug.source) {\n            return JS_NewStringLen(ctx, b->debug.source, b->debug.source_len);\n        }\n        func_kind = b->func_kind;\n    }\n    {\n        JSValue name;\n        const char *pref, *suff;\n\n        switch(func_kind) {\n        default:\n        case JS_FUNC_NORMAL:\n            pref = \"function \";\n            break;\n        case JS_FUNC_GENERATOR:\n            pref = \"function *\";\n            break;\n        case JS_FUNC_ASYNC:\n            pref = \"async function \";\n            break;\n        case JS_FUNC_ASYNC_GENERATOR:\n            pref = \"async function *\";\n            break;\n        }\n        suff = \"() {\\n    [native code]\\n}\";\n        name = JS_GetProperty(ctx, this_val, JS_ATOM_name);\n        if (JS_IsUndefined(name))\n            name = JS_AtomToString(ctx, JS_ATOM_empty_string);\n        return JS_ConcatString3(ctx, pref, name, suff);\n    }\n}\n\nstatic JSValue js_function_hasInstance(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    int ret;\n    ret = JS_OrdinaryIsInstanceOf(ctx, argv[0], this_val);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic const JSCFunctionListEntry js_function_proto_funcs[] = {\n    JS_CFUNC_DEF(\"call\", 1, js_function_call ),\n    JS_CFUNC_MAGIC_DEF(\"apply\", 2, js_function_apply, 0 ),\n    JS_CFUNC_DEF(\"bind\", 1, js_function_bind ),\n    JS_CFUNC_DEF(\"toString\", 0, js_function_toString ),\n    JS_CFUNC_DEF(\"[Symbol.hasInstance]\", 1, js_function_hasInstance ),\n    JS_CGETSET_DEF(\"fileName\", js_function_proto_fileName, NULL ),\n    JS_CGETSET_DEF(\"lineNumber\", js_function_proto_lineNumber, NULL ),\n};\n\n/* Error class */\n\nstatic JSValue iterator_to_array(JSContext *ctx, JSValueConst items)\n{\n    JSValue iter, next_method = JS_UNDEFINED;\n    JSValue v, r = JS_UNDEFINED;\n    int64_t k;\n    BOOL done;\n    \n    iter = JS_GetIterator(ctx, items, FALSE);\n    if (JS_IsException(iter))\n        goto exception;\n    next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);\n    if (JS_IsException(next_method))\n        goto exception;\n    r = JS_NewArray(ctx);\n    if (JS_IsException(r))\n        goto exception;\n    for (k = 0;; k++) {\n        v = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);\n        if (JS_IsException(v))\n            goto exception_close;\n        if (done)\n            break;\n        if (JS_DefinePropertyValueInt64(ctx, r, k, v,\n                                        JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n            goto exception_close;\n    }\n done:\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    return r;\n exception_close:\n    JS_IteratorClose(ctx, iter, TRUE);\n exception:\n    JS_FreeValue(ctx, r);\n    r = JS_EXCEPTION;\n    goto done;\n}\n\nstatic JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target,\n                                    int argc, JSValueConst *argv, int magic)\n{\n    JSValue obj, msg, proto;\n    JSValueConst message;\n\n    if (JS_IsUndefined(new_target))\n        new_target = JS_GetActiveFunction(ctx);\n    proto = JS_GetProperty(ctx, new_target, JS_ATOM_prototype);\n    if (JS_IsException(proto))\n        return proto;\n    if (!JS_IsObject(proto)) {\n        JSContext *realm;\n        JSValueConst proto1;\n        \n        JS_FreeValue(ctx, proto);\n        realm = JS_GetFunctionRealm(ctx, new_target);\n        if (!realm)\n            return JS_EXCEPTION;\n        if (magic < 0) {\n            proto1 = realm->class_proto[JS_CLASS_ERROR];\n        } else {\n            proto1 = realm->native_error_proto[magic];\n        }\n        proto = JS_DupValue(ctx, proto1);\n    }\n    obj = JS_NewObjectProtoClass(ctx, proto, JS_CLASS_ERROR);\n    JS_FreeValue(ctx, proto);\n    if (JS_IsException(obj))\n        return obj;\n    if (magic == JS_AGGREGATE_ERROR) {\n        message = argv[1];\n    } else {\n        message = argv[0];\n    }\n\n    if (!JS_IsUndefined(message)) {\n        msg = JS_ToString(ctx, message);\n        if (unlikely(JS_IsException(msg)))\n            goto exception;\n        JS_DefinePropertyValue(ctx, obj, JS_ATOM_message, msg,\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    }\n\n    if (magic == JS_AGGREGATE_ERROR) {\n        JSValue error_list = iterator_to_array(ctx, argv[0]);\n        if (JS_IsException(error_list))\n            goto exception;\n        JS_DefinePropertyValue(ctx, obj, JS_ATOM_errors, error_list,\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    }\n\n    /* skip the Error() function in the backtrace */\n    build_backtrace(ctx, obj, NULL, 0, JS_BACKTRACE_FLAG_SKIP_FIRST_LEVEL);\n    return obj;\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_error_toString(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue name, msg;\n\n    if (!JS_IsObject(this_val))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    name = JS_GetProperty(ctx, this_val, JS_ATOM_name);\n    if (JS_IsUndefined(name))\n        name = JS_AtomToString(ctx, JS_ATOM_Error);\n    else\n        name = JS_ToStringFree(ctx, name);\n    if (JS_IsException(name))\n        return JS_EXCEPTION;\n\n    msg = JS_GetProperty(ctx, this_val, JS_ATOM_message);\n    if (JS_IsUndefined(msg))\n        msg = JS_AtomToString(ctx, JS_ATOM_empty_string);\n    else\n        msg = JS_ToStringFree(ctx, msg);\n    if (JS_IsException(msg)) {\n        JS_FreeValue(ctx, name);\n        return JS_EXCEPTION;\n    }\n    if (!JS_IsEmptyString(name) && !JS_IsEmptyString(msg))\n        name = JS_ConcatString3(ctx, \"\", name, \": \");\n    return JS_ConcatString(ctx, name, msg);\n}\n\nstatic const JSCFunctionListEntry js_error_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_error_toString ),\n    JS_PROP_STRING_DEF(\"name\", \"Error\", JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),\n    JS_PROP_STRING_DEF(\"message\", \"\", JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),\n};\n\n/* AggregateError */\n\n/* used by C code. */\nstatic JSValue js_aggregate_error_constructor(JSContext *ctx,\n                                              JSValueConst errors)\n{\n    JSValue obj;\n    \n    obj = JS_NewObjectProtoClass(ctx,\n                                 ctx->native_error_proto[JS_AGGREGATE_ERROR],\n                                 JS_CLASS_ERROR);\n    if (JS_IsException(obj))\n        return obj;\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_errors, JS_DupValue(ctx, errors),\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    return obj;\n}\n\n/* Array */\n\nstatic int JS_CopySubArray(JSContext *ctx,\n                           JSValueConst obj, int64_t to_pos,\n                           int64_t from_pos, int64_t count, int dir)\n{\n    int64_t i, from, to;\n    JSValue val;\n    int fromPresent;\n\n    /* XXX: should special case fast arrays */\n    for (i = 0; i < count; i++) {\n        if (dir < 0) {\n            from = from_pos + count - i - 1;\n            to = to_pos + count - i - 1;\n        } else {\n            from = from_pos + i;\n            to = to_pos + i;\n        }\n        fromPresent = JS_TryGetPropertyInt64(ctx, obj, from, &val);\n        if (fromPresent < 0)\n            goto exception;\n\n        if (fromPresent) {\n            if (JS_SetPropertyInt64(ctx, obj, to, val) < 0)\n                goto exception;\n        } else {\n            if (JS_DeletePropertyInt64(ctx, obj, to, JS_PROP_THROW) < 0)\n                goto exception;\n        }\n    }\n    return 0;\n\n exception:\n    return -1;\n}\n\nstatic JSValue js_array_constructor(JSContext *ctx, JSValueConst new_target,\n                                    int argc, JSValueConst *argv)\n{\n    JSValue obj;\n    int i;\n\n    obj = js_create_from_ctor(ctx, new_target, JS_CLASS_ARRAY);\n    if (JS_IsException(obj))\n        return obj;\n    if (argc == 1 && JS_IsNumber(argv[0])) {\n        uint32_t len;\n        if (JS_ToArrayLengthFree(ctx, &len, JS_DupValue(ctx, argv[0])))\n            goto fail;\n        if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewUint32(ctx, len)) < 0)\n            goto fail;\n    } else {\n        for(i = 0; i < argc; i++) {\n            if (JS_SetPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i])) < 0)\n                goto fail;\n        }\n    }\n    return obj;\nfail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_from(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    // from(items, mapfn = void 0, this_arg = void 0)\n    JSValueConst items = argv[0], mapfn, this_arg;\n    JSValueConst args[2];\n    JSValue stack[2];\n    JSValue iter, r, v, v2, arrayLike;\n    int64_t k, len;\n    int done, mapping;\n\n    mapping = FALSE;\n    mapfn = JS_UNDEFINED;\n    this_arg = JS_UNDEFINED;\n    r = JS_UNDEFINED;\n    arrayLike = JS_UNDEFINED;\n    stack[0] = JS_UNDEFINED;\n    stack[1] = JS_UNDEFINED;\n\n    if (argc > 1) {\n        mapfn = argv[1];\n        if (!JS_IsUndefined(mapfn)) {\n            if (check_function(ctx, mapfn))\n                goto exception;\n            mapping = 1;\n            if (argc > 2)\n                this_arg = argv[2];\n        }\n    }\n    iter = JS_GetProperty(ctx, items, JS_ATOM_Symbol_iterator);\n    if (JS_IsException(iter))\n        goto exception;\n    if (!JS_IsUndefined(iter)) {\n        JS_FreeValue(ctx, iter);\n        if (JS_IsConstructor(ctx, this_val))\n            r = JS_CallConstructor(ctx, this_val, 0, NULL);\n        else\n            r = JS_NewArray(ctx);\n        if (JS_IsException(r))\n            goto exception;\n        stack[0] = JS_DupValue(ctx, items);\n        if (js_for_of_start(ctx, &stack[1], FALSE))\n            goto exception;\n        for (k = 0;; k++) {\n            v = JS_IteratorNext(ctx, stack[0], stack[1], 0, NULL, &done);\n            if (JS_IsException(v))\n                goto exception_close;\n            if (done)\n                break;\n            if (mapping) {\n                args[0] = v;\n                args[1] = JS_NewInt32(ctx, k);\n                v2 = JS_Call(ctx, mapfn, this_arg, 2, args);\n                JS_FreeValue(ctx, v);\n                v = v2;\n                if (JS_IsException(v))\n                    goto exception_close;\n            }\n            if (JS_DefinePropertyValueInt64(ctx, r, k, v,\n                                            JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                goto exception_close;\n        }\n    } else {\n        arrayLike = JS_ToObject(ctx, items);\n        if (JS_IsException(arrayLike))\n            goto exception;\n        if (js_get_length64(ctx, &len, arrayLike) < 0)\n            goto exception;\n        v = JS_NewInt64(ctx, len);\n        args[0] = v;\n        if (JS_IsConstructor(ctx, this_val)) {\n            r = JS_CallConstructor(ctx, this_val, 1, args);\n        } else {\n            r = js_array_constructor(ctx, JS_UNDEFINED, 1, args);\n        }\n        JS_FreeValue(ctx, v);\n        if (JS_IsException(r))\n            goto exception;\n        for(k = 0; k < len; k++) {\n            v = JS_GetPropertyInt64(ctx, arrayLike, k);\n            if (JS_IsException(v))\n                goto exception;\n            if (mapping) {\n                args[0] = v;\n                args[1] = JS_NewInt32(ctx, k);\n                v2 = JS_Call(ctx, mapfn, this_arg, 2, args);\n                JS_FreeValue(ctx, v);\n                v = v2;\n                if (JS_IsException(v))\n                    goto exception;\n            }\n            if (JS_DefinePropertyValueInt64(ctx, r, k, v,\n                                            JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                goto exception;\n        }\n    }\n    if (JS_SetProperty(ctx, r, JS_ATOM_length, JS_NewUint32(ctx, k)) < 0)\n        goto exception;\n    goto done;\n\n exception_close:\n    if (!JS_IsUndefined(stack[0]))\n        JS_IteratorClose(ctx, stack[0], TRUE);\n exception:\n    JS_FreeValue(ctx, r);\n    r = JS_EXCEPTION;\n done:\n    JS_FreeValue(ctx, arrayLike);\n    JS_FreeValue(ctx, stack[0]);\n    JS_FreeValue(ctx, stack[1]);\n    return r;\n}\n\nstatic JSValue js_array_of(JSContext *ctx, JSValueConst this_val,\n                           int argc, JSValueConst *argv)\n{\n    JSValue obj, args[1];\n    int i;\n\n    if (JS_IsConstructor(ctx, this_val)) {\n        args[0] = JS_NewInt32(ctx, argc);\n        obj = JS_CallConstructor(ctx, this_val, 1, (JSValueConst *)args);\n    } else {\n        obj = JS_NewArray(ctx);\n    }\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    for(i = 0; i < argc; i++) {\n        if (JS_CreateDataPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i]),\n                                        JS_PROP_THROW) < 0) {\n            goto fail;\n        }\n    }\n    if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewUint32(ctx, argc)) < 0) {\n    fail:\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    return obj;\n}\n\nstatic JSValue js_array_isArray(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    int ret;\n    ret = JS_IsArray(ctx, argv[0]);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_get_this(JSContext *ctx,\n                           JSValueConst this_val)\n{\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj,\n                                     JSValueConst len_val)\n{\n    JSValue ctor, ret, species;\n    int res;\n    JSContext *realm;\n    \n    res = JS_IsArray(ctx, obj);\n    if (res < 0)\n        return JS_EXCEPTION;\n    if (!res)\n        return js_array_constructor(ctx, JS_UNDEFINED, 1, &len_val);\n    ctor = JS_GetProperty(ctx, obj, JS_ATOM_constructor);\n    if (JS_IsException(ctor))\n        return ctor;\n    if (JS_IsConstructor(ctx, ctor)) {\n        /* legacy web compatibility */\n        realm = JS_GetFunctionRealm(ctx, ctor);\n        if (!realm) {\n            JS_FreeValue(ctx, ctor);\n            return JS_EXCEPTION;\n        }\n        if (realm != ctx &&\n            js_same_value(ctx, ctor, realm->array_ctor)) {\n            JS_FreeValue(ctx, ctor);\n            ctor = JS_UNDEFINED;\n        }\n    }\n    if (JS_IsObject(ctor)) {\n        species = JS_GetProperty(ctx, ctor, JS_ATOM_Symbol_species);\n        JS_FreeValue(ctx, ctor);\n        if (JS_IsException(species))\n            return species;\n        ctor = species;\n        if (JS_IsNull(ctor))\n            ctor = JS_UNDEFINED;\n    }\n    if (JS_IsUndefined(ctor)) {\n        return js_array_constructor(ctx, JS_UNDEFINED, 1, &len_val);\n    } else {\n        ret = JS_CallConstructor(ctx, ctor, 1, &len_val);\n        JS_FreeValue(ctx, ctor);\n        return ret;\n    }\n}\n\nstatic const JSCFunctionListEntry js_array_funcs[] = {\n    JS_CFUNC_DEF(\"isArray\", 1, js_array_isArray ),\n    JS_CFUNC_DEF(\"from\", 1, js_array_from ),\n    JS_CFUNC_DEF(\"of\", 0, js_array_of ),\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL ),\n};\n\nstatic int JS_isConcatSpreadable(JSContext *ctx, JSValueConst obj)\n{\n    JSValue val;\n\n    if (!JS_IsObject(obj))\n        return FALSE;\n    val = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_isConcatSpreadable);\n    if (JS_IsException(val))\n        return -1;\n    if (!JS_IsUndefined(val))\n        return JS_ToBoolFree(ctx, val);\n    return JS_IsArray(ctx, obj);\n}\n\nstatic JSValue js_array_concat(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    JSValue obj, arr, val;\n    JSValueConst e;\n    int64_t len, k, n;\n    int i, res;\n\n    arr = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj))\n        goto exception;\n\n    arr = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0));\n    if (JS_IsException(arr))\n        goto exception;\n    n = 0;\n    for (i = -1; i < argc; i++) {\n        if (i < 0)\n            e = obj;\n        else\n            e = argv[i];\n\n        res = JS_isConcatSpreadable(ctx, e);\n        if (res < 0)\n            goto exception;\n        if (res) {\n            if (js_get_length64(ctx, &len, e))\n                goto exception;\n            if (n + len > MAX_SAFE_INTEGER) {\n                JS_ThrowTypeError(ctx, \"Array loo long\");\n                goto exception;\n            }\n            for (k = 0; k < len; k++, n++) {\n                res = JS_TryGetPropertyInt64(ctx, e, k, &val);\n                if (res < 0)\n                    goto exception;\n                if (res) {\n                    if (JS_DefinePropertyValueInt64(ctx, arr, n, val,\n                                                    JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                        goto exception;\n                }\n            }\n        } else {\n            if (n >= MAX_SAFE_INTEGER) {\n                JS_ThrowTypeError(ctx, \"Array loo long\");\n                goto exception;\n            }\n            if (JS_DefinePropertyValueInt64(ctx, arr, n, JS_DupValue(ctx, e),\n                                            JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                goto exception;\n            n++;\n        }\n    }\n    if (JS_SetProperty(ctx, arr, JS_ATOM_length, JS_NewInt64(ctx, n)) < 0)\n        goto exception;\n\n    JS_FreeValue(ctx, obj);\n    return arr;\n\nexception:\n    JS_FreeValue(ctx, arr);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\n#define special_every    0\n#define special_some     1\n#define special_forEach  2\n#define special_map      3\n#define special_filter   4\n#define special_TA       8\n\nstatic int js_typed_array_get_length_internal(JSContext *ctx, JSValueConst obj);\n\nstatic JSValue js_typed_array___speciesCreate(JSContext *ctx,\n                                              JSValueConst this_val,\n                                              int argc, JSValueConst *argv);\n\nstatic JSValue js_array_every(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int special)\n{\n    JSValue obj, val, index_val, res, ret;\n    JSValueConst args[3];\n    JSValueConst func, this_arg;\n    int64_t len, k, n;\n    int present;\n\n    ret = JS_UNDEFINED;\n    val = JS_UNDEFINED;\n    if (special & special_TA) {\n        obj = JS_DupValue(ctx, this_val);\n        len = js_typed_array_get_length_internal(ctx, obj);\n        if (len < 0)\n            goto exception;\n    } else {\n        obj = JS_ToObject(ctx, this_val);\n        if (js_get_length64(ctx, &len, obj))\n            goto exception;\n    }\n    func = argv[0];\n    this_arg = JS_UNDEFINED;\n    if (argc > 1)\n        this_arg = argv[1];\n        \n    if (check_function(ctx, func))\n        goto exception;\n\n    switch (special) {\n    case special_every:\n    case special_every | special_TA:\n        ret = JS_TRUE;\n        break;\n    case special_some:\n    case special_some | special_TA:\n        ret = JS_FALSE;\n        break;\n    case special_map:\n        /* XXX: JS_ArraySpeciesCreate should take int64_t */\n        ret = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt64(ctx, len));\n        if (JS_IsException(ret))\n            goto exception;\n        break;\n    case special_filter:\n        ret = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0));\n        if (JS_IsException(ret))\n            goto exception;\n        break;\n    case special_map | special_TA:\n        args[0] = obj;\n        args[1] = JS_NewInt32(ctx, len);\n        ret = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 2, args);\n        if (JS_IsException(ret))\n            goto exception;\n        break;\n    case special_filter | special_TA:\n        ret = JS_NewArray(ctx);\n        if (JS_IsException(ret))\n            goto exception;\n        break;\n    }\n    n = 0;\n\n    for(k = 0; k < len; k++) {\n        present = JS_TryGetPropertyInt64(ctx, obj, k, &val);\n        if (present < 0)\n            goto exception;\n        if (present) {\n            index_val = JS_NewInt64(ctx, k);\n            if (JS_IsException(index_val))\n                goto exception;\n            args[0] = val;\n            args[1] = index_val;\n            args[2] = obj;\n            res = JS_Call(ctx, func, this_arg, 3, args);\n            JS_FreeValue(ctx, index_val);\n            if (JS_IsException(res))\n                goto exception;\n            switch (special) {\n            case special_every:\n            case special_every | special_TA:\n                if (!JS_ToBoolFree(ctx, res)) {\n                    ret = JS_FALSE;\n                    goto done;\n                }\n                break;\n            case special_some:\n            case special_some | special_TA:\n                if (JS_ToBoolFree(ctx, res)) {\n                    ret = JS_TRUE;\n                    goto done;\n                }\n                break;\n            case special_map:\n                if (JS_DefinePropertyValueInt64(ctx, ret, k, res,\n                                                JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                    goto exception;\n                break;\n            case special_map | special_TA:\n                if (JS_SetPropertyValue(ctx, ret, JS_NewInt32(ctx, k), res, JS_PROP_THROW) < 0)\n                    goto exception;\n                break;\n            case special_filter:\n            case special_filter | special_TA:\n                if (JS_ToBoolFree(ctx, res)) {\n                    if (JS_DefinePropertyValueInt64(ctx, ret, n++, JS_DupValue(ctx, val),\n                                                    JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                        goto exception;\n                }\n                break;\n            default:\n                JS_FreeValue(ctx, res);\n                break;\n            }\n            JS_FreeValue(ctx, val);\n            val = JS_UNDEFINED;\n        }\n    }\ndone:\n    if (special == (special_filter | special_TA)) {\n        JSValue arr;\n        args[0] = obj;\n        args[1] = JS_NewInt32(ctx, n);\n        arr = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 2, args);\n        if (JS_IsException(arr))\n            goto exception;\n        args[0] = ret;\n        res = JS_Invoke(ctx, arr, JS_ATOM_set, 1, args);\n        if (check_exception_free(ctx, res))\n            goto exception;\n        JS_FreeValue(ctx, ret);\n        ret = arr;\n    }\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, obj);\n    return ret;\n\nexception:\n    JS_FreeValue(ctx, ret);\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\n#define special_reduce       0\n#define special_reduceRight  1\n\nstatic JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv, int special)\n{\n    JSValue obj, val, index_val, acc, acc1;\n    JSValueConst args[4];\n    JSValueConst func;\n    int64_t len, k, k1;\n    int present;\n\n    acc = JS_UNDEFINED;\n    val = JS_UNDEFINED;\n    if (special & special_TA) {\n        obj = JS_DupValue(ctx, this_val);\n        len = js_typed_array_get_length_internal(ctx, obj);\n        if (len < 0)\n            goto exception;\n    } else {\n        obj = JS_ToObject(ctx, this_val);\n        if (js_get_length64(ctx, &len, obj))\n            goto exception;\n    }\n    func = argv[0];\n\n    if (check_function(ctx, func))\n        goto exception;\n\n    k = 0;\n    if (argc > 1) {\n        acc = JS_DupValue(ctx, argv[1]);\n    } else {\n        for(;;) {\n            if (k >= len) {\n                JS_ThrowTypeError(ctx, \"empty array\");\n                goto exception;\n            }\n            k1 = (special & special_reduceRight) ? len - k - 1 : k;\n            k++;\n            present = JS_TryGetPropertyInt64(ctx, obj, k1, &acc);\n            if (present < 0)\n                goto exception;\n            if (present)\n                break;\n        }\n    }\n    for (; k < len; k++) {\n        k1 = (special & special_reduceRight) ? len - k - 1 : k;\n        present = JS_TryGetPropertyInt64(ctx, obj, k1, &val);\n        if (present < 0)\n            goto exception;\n        if (present) {\n            index_val = JS_NewInt64(ctx, k1);\n            if (JS_IsException(index_val))\n                goto exception;\n            args[0] = acc;\n            args[1] = val;\n            args[2] = index_val;\n            args[3] = obj;\n            acc1 = JS_Call(ctx, func, JS_UNDEFINED, 4, args);\n            JS_FreeValue(ctx, index_val);\n            JS_FreeValue(ctx, val);\n            val = JS_UNDEFINED;\n            if (JS_IsException(acc1))\n                goto exception;\n            JS_FreeValue(ctx, acc);\n            acc = acc1;\n        }\n    }\n    JS_FreeValue(ctx, obj);\n    return acc;\n\nexception:\n    JS_FreeValue(ctx, acc);\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_fill(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    JSValue obj;\n    int64_t len, start, end;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    start = 0;\n    if (argc > 1 && !JS_IsUndefined(argv[1])) {\n        if (JS_ToInt64Clamp(ctx, &start, argv[1], 0, len, len))\n            goto exception;\n    }\n\n    end = len;\n    if (argc > 2 && !JS_IsUndefined(argv[2])) {\n        if (JS_ToInt64Clamp(ctx, &end, argv[2], 0, len, len))\n            goto exception;\n    }\n\n    /* XXX: should special case fast arrays */\n    while (start < end) {\n        if (JS_SetPropertyInt64(ctx, obj, start,\n                                JS_DupValue(ctx, argv[0])) < 0)\n            goto exception;\n        start++;\n    }\n    return obj;\n\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue obj, val;\n    int64_t len, n, res;\n    JSValue *arrp;\n    uint32_t count;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    res = FALSE;\n    if (len > 0) {\n        n = 0;\n        if (argc > 1) {\n            if (JS_ToInt64Clamp(ctx, &n, argv[1], 0, len, len))\n                goto exception;\n        }\n        if (js_get_fast_array(ctx, obj, &arrp, &count)) {\n            for (; n < count; n++) {\n                if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]),\n                                  JS_DupValue(ctx, arrp[n]),\n                                  JS_EQ_SAME_VALUE_ZERO)) {\n                    res = TRUE;\n                    goto done;\n                }\n            }\n        }\n        for (; n < len; n++) {\n            val = JS_GetPropertyInt64(ctx, obj, n);\n            if (JS_IsException(val))\n                goto exception;\n            if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), val,\n                              JS_EQ_SAME_VALUE_ZERO)) {\n                res = TRUE;\n                break;\n            }\n        }\n    }\n done:\n    JS_FreeValue(ctx, obj);\n    return JS_NewBool(ctx, res);\n\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue obj, val;\n    int64_t len, n, res;\n    JSValue *arrp;\n    uint32_t count;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    res = -1;\n    if (len > 0) {\n        n = 0;\n        if (argc > 1) {\n            if (JS_ToInt64Clamp(ctx, &n, argv[1], 0, len, len))\n                goto exception;\n        }\n        if (js_get_fast_array(ctx, obj, &arrp, &count)) {\n            for (; n < count; n++) {\n                if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]),\n                                  JS_DupValue(ctx, arrp[n]), JS_EQ_STRICT)) {\n                    res = n;\n                    goto done;\n                }\n            }\n        }\n        for (; n < len; n++) {\n            int present = JS_TryGetPropertyInt64(ctx, obj, n, &val);\n            if (present < 0)\n                goto exception;\n            if (present) {\n                if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), val, JS_EQ_STRICT)) {\n                    res = n;\n                    break;\n                }\n            }\n        }\n    }\n done:\n    JS_FreeValue(ctx, obj);\n    return JS_NewInt64(ctx, res);\n\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValue obj, val;\n    int64_t len, n, res;\n    int present;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    res = -1;\n    if (len > 0) {\n        n = len - 1;\n        if (argc > 1) {\n            if (JS_ToInt64Clamp(ctx, &n, argv[1], -1, len - 1, len))\n                goto exception;\n        }\n        /* XXX: should special case fast arrays */\n        for (; n >= 0; n--) {\n            present = JS_TryGetPropertyInt64(ctx, obj, n, &val);\n            if (present < 0)\n                goto exception;\n            if (present) {\n                if (js_strict_eq2(ctx, JS_DupValue(ctx, argv[0]), val, JS_EQ_STRICT)) {\n                    res = n;\n                    break;\n                }\n            }\n        }\n    }\n    JS_FreeValue(ctx, obj);\n    return JS_NewInt64(ctx, res);\n\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_find(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv, int findIndex)\n{\n    JSValueConst func, this_arg;\n    JSValueConst args[3];\n    JSValue obj, val, index_val, res;\n    int64_t len, k;\n\n    index_val = JS_UNDEFINED;\n    val = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    func = argv[0];\n    if (check_function(ctx, func))\n        goto exception;\n\n    this_arg = JS_UNDEFINED;\n    if (argc > 1)\n        this_arg = argv[1];\n\n    for(k = 0; k < len; k++) {\n        index_val = JS_NewInt64(ctx, k);\n        if (JS_IsException(index_val))\n            goto exception;\n        val = JS_GetPropertyValue(ctx, obj, index_val);\n        if (JS_IsException(val))\n            goto exception;\n        args[0] = val;\n        args[1] = index_val;\n        args[2] = this_val;\n        res = JS_Call(ctx, func, this_arg, 3, args);\n        if (JS_IsException(res))\n            goto exception;\n        if (JS_ToBoolFree(ctx, res)) {\n            if (findIndex) {\n                JS_FreeValue(ctx, val);\n                JS_FreeValue(ctx, obj);\n                return index_val;\n            } else {\n                JS_FreeValue(ctx, index_val);\n                JS_FreeValue(ctx, obj);\n                return val;\n            }\n        }\n        JS_FreeValue(ctx, val);\n        JS_FreeValue(ctx, index_val);\n    }\n    JS_FreeValue(ctx, obj);\n    if (findIndex)\n        return JS_NewInt32(ctx, -1);\n    else\n        return JS_UNDEFINED;\n\nexception:\n    JS_FreeValue(ctx, index_val);\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_toString(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue obj, method, ret;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    method = JS_GetProperty(ctx, obj, JS_ATOM_join);\n    if (JS_IsException(method)) {\n        ret = JS_EXCEPTION;\n    } else\n    if (!JS_IsFunction(ctx, method)) {\n        /* Use intrinsic Object.prototype.toString */\n        JS_FreeValue(ctx, method);\n        ret = js_object_toString(ctx, obj, 0, NULL);\n    } else {\n        ret = JS_CallFree(ctx, method, obj, 0, NULL);\n    }\n    JS_FreeValue(ctx, obj);\n    return ret;\n}\n\nstatic JSValue js_array_join(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv, int toLocaleString)\n{\n    JSValue obj, sep = JS_UNDEFINED, el;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p = NULL;\n    int64_t i, n;\n    int c;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &n, obj))\n        goto exception;\n\n    c = ',';    /* default separator */\n    if (!toLocaleString && argc > 0 && !JS_IsUndefined(argv[0])) {\n        sep = JS_ToString(ctx, argv[0]);\n        if (JS_IsException(sep))\n            goto exception;\n        p = JS_VALUE_GET_STRING(sep);\n        if (p->len == 1 && !p->is_wide_char)\n            c = p->u.str8[0];\n        else\n            c = -1;\n    }\n    string_buffer_init(ctx, b, 0);\n\n    for(i = 0; i < n; i++) {\n        if (i > 0) {\n            if (c >= 0) {\n                string_buffer_putc8(b, c);\n            } else {\n                string_buffer_concat(b, p, 0, p->len);\n            }\n        }\n        el = JS_GetPropertyUint32(ctx, obj, i);\n        if (JS_IsException(el))\n            goto fail;\n        if (!JS_IsNull(el) && !JS_IsUndefined(el)) {\n            if (toLocaleString) {\n                el = JS_ToLocaleStringFree(ctx, el);\n            }\n            if (string_buffer_concat_value_free(b, el))\n                goto fail;\n        }\n    }\n    JS_FreeValue(ctx, sep);\n    JS_FreeValue(ctx, obj);\n    return string_buffer_end(b);\n\nfail:\n    string_buffer_free(b);\n    JS_FreeValue(ctx, sep);\nexception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_pop(JSContext *ctx, JSValueConst this_val,\n                            int argc, JSValueConst *argv, int shift)\n{\n    JSValue obj, res = JS_UNDEFINED;\n    int64_t len, newLen;\n    JSValue *arrp;\n    uint32_t count32;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n    newLen = 0;\n    if (len > 0) {\n        newLen = len - 1;\n        /* Special case fast arrays */\n        if (js_get_fast_array(ctx, obj, &arrp, &count32) && count32 == len) {\n            JSObject *p = JS_VALUE_GET_OBJ(obj);\n            if (shift) {\n                res = arrp[0];\n                memmove(arrp, arrp + 1, (count32 - 1) * sizeof(*arrp));\n                p->u.array.count--;\n            } else {\n                res = arrp[count32 - 1];\n                p->u.array.count--;\n            }\n        } else {\n            if (shift) {\n                res = JS_GetPropertyInt64(ctx, obj, 0);\n                if (JS_IsException(res))\n                    goto exception;\n                if (JS_CopySubArray(ctx, obj, 0, 1, len - 1, +1))\n                    goto exception;\n            } else {\n                res = JS_GetPropertyInt64(ctx, obj, newLen);\n                if (JS_IsException(res))\n                    goto exception;\n            }\n            if (JS_DeletePropertyInt64(ctx, obj, newLen, JS_PROP_THROW) < 0)\n                goto exception;\n        }\n    }\n    if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewInt64(ctx, newLen)) < 0)\n        goto exception;\n\n    JS_FreeValue(ctx, obj);\n    return res;\n\n exception:\n    JS_FreeValue(ctx, res);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_push(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv, int unshift)\n{\n    JSValue obj;\n    int i;\n    int64_t len, from, newLen;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n    newLen = len + argc;\n    if (newLen > MAX_SAFE_INTEGER) {\n        JS_ThrowTypeError(ctx, \"Array loo long\");\n        goto exception;\n    }\n    from = len;\n    if (unshift && argc > 0) {\n        if (JS_CopySubArray(ctx, obj, argc, 0, len, -1))\n            goto exception;\n        from = 0;\n    }\n    for(i = 0; i < argc; i++) {\n        if (JS_SetPropertyInt64(ctx, obj, from + i,\n                                JS_DupValue(ctx, argv[i])) < 0)\n            goto exception;\n    }\n    if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewInt64(ctx, newLen)) < 0)\n        goto exception;\n\n    JS_FreeValue(ctx, obj);\n    return JS_NewInt64(ctx, newLen);\n\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_reverse(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue obj, lval, hval;\n    JSValue *arrp;\n    int64_t len, l, h;\n    int l_present, h_present;\n    uint32_t count32;\n\n    lval = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    /* Special case fast arrays */\n    if (js_get_fast_array(ctx, obj, &arrp, &count32) && count32 == len) {\n        uint32_t ll, hh;\n\n        if (count32 > 1) {\n            for (ll = 0, hh = count32 - 1; ll < hh; ll++, hh--) {\n                lval = arrp[ll];\n                arrp[ll] = arrp[hh];\n                arrp[hh] = lval;\n            }\n        }\n        return obj;\n    }\n\n    for (l = 0, h = len - 1; l < h; l++, h--) {\n        l_present = JS_TryGetPropertyInt64(ctx, obj, l, &lval);\n        if (l_present < 0)\n            goto exception;\n        h_present = JS_TryGetPropertyInt64(ctx, obj, h, &hval);\n        if (h_present < 0)\n            goto exception;\n        if (h_present) {\n            if (JS_SetPropertyInt64(ctx, obj, l, hval) < 0)\n                goto exception;\n\n            if (l_present) {\n                if (JS_SetPropertyInt64(ctx, obj, h, lval) < 0) {\n                    lval = JS_UNDEFINED;\n                    goto exception;\n                }\n                lval = JS_UNDEFINED;\n            } else {\n                if (JS_DeletePropertyInt64(ctx, obj, h, JS_PROP_THROW) < 0)\n                    goto exception;\n            }\n        } else {\n            if (l_present) {\n                if (JS_DeletePropertyInt64(ctx, obj, l, JS_PROP_THROW) < 0)\n                    goto exception;\n                if (JS_SetPropertyInt64(ctx, obj, h, lval) < 0) {\n                    lval = JS_UNDEFINED;\n                    goto exception;\n                }\n                lval = JS_UNDEFINED;\n            }\n        }\n    }\n    return obj;\n\n exception:\n    JS_FreeValue(ctx, lval);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_slice(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int splice)\n{\n    JSValue obj, arr, val, len_val;\n    int64_t len, start, k, final, n, count, del_count, new_len;\n    int kPresent;\n    JSValue *arrp;\n    uint32_t count32, i, item_count;\n\n    arr = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    if (JS_ToInt64Clamp(ctx, &start, argv[0], 0, len, len))\n        goto exception;\n\n    if (splice) {\n        if (argc == 0) {\n            item_count = 0;\n            del_count = 0;\n        } else\n        if (argc == 1) {\n            item_count = 0;\n            del_count = len - start;\n        } else {\n            item_count = argc - 2;\n            if (JS_ToInt64Clamp(ctx, &del_count, argv[1], 0, len - start, 0))\n                goto exception;\n        }\n        if (len + item_count - del_count > MAX_SAFE_INTEGER) {\n            JS_ThrowTypeError(ctx, \"Array loo long\");\n            goto exception;\n        }\n        count = del_count;\n    } else {\n        item_count = 0; /* avoid warning */\n        final = len;\n        if (!JS_IsUndefined(argv[1])) {\n            if (JS_ToInt64Clamp(ctx, &final, argv[1], 0, len, len))\n                goto exception;\n        }\n        count = max_int64(final - start, 0);\n    }\n    len_val = JS_NewInt64(ctx, count);\n    arr = JS_ArraySpeciesCreate(ctx, obj, len_val);\n    JS_FreeValue(ctx, len_val);\n    if (JS_IsException(arr))\n        goto exception;\n\n    k = start;\n    final = start + count;\n    n = 0;\n    /* The fast array test on arr ensures that\n       JS_CreateDataPropertyUint32() won't modify obj in case arr is\n       an exotic object */\n    /* Special case fast arrays */\n    if (js_get_fast_array(ctx, obj, &arrp, &count32) &&\n        js_is_fast_array(ctx, arr)) {\n        /* XXX: should share code with fast array constructor */\n        for (; k < final && k < count32; k++, n++) {\n            if (JS_CreateDataPropertyUint32(ctx, arr, n, JS_DupValue(ctx, arrp[k]), JS_PROP_THROW) < 0)\n                goto exception;\n        }\n    }\n    /* Copy the remaining elements if any (handle case of inherited properties) */\n    for (; k < final; k++, n++) {\n        kPresent = JS_TryGetPropertyInt64(ctx, obj, k, &val);\n        if (kPresent < 0)\n            goto exception;\n        if (kPresent) {\n            if (JS_CreateDataPropertyUint32(ctx, arr, n, val, JS_PROP_THROW) < 0)\n                goto exception;\n        }\n    }\n    if (JS_SetProperty(ctx, arr, JS_ATOM_length, JS_NewInt64(ctx, n)) < 0)\n        goto exception;\n\n    if (splice) {\n        new_len = len + item_count - del_count;\n        if (item_count != del_count) {\n            if (JS_CopySubArray(ctx, obj, start + item_count,\n                                start + del_count, len - (start + del_count),\n                                item_count <= del_count ? +1 : -1) < 0)\n                goto exception;\n\n            for (k = len; k-- > new_len; ) {\n                if (JS_DeletePropertyInt64(ctx, obj, k, JS_PROP_THROW) < 0)\n                    goto exception;\n            }\n        }\n        for (i = 0; i < item_count; i++) {\n            if (JS_SetPropertyInt64(ctx, obj, start + i, JS_DupValue(ctx, argv[i + 2])) < 0)\n                goto exception;\n        }\n        if (JS_SetProperty(ctx, obj, JS_ATOM_length, JS_NewInt64(ctx, new_len)) < 0)\n            goto exception;\n    }\n    JS_FreeValue(ctx, obj);\n    return arr;\n\n exception:\n    JS_FreeValue(ctx, obj);\n    JS_FreeValue(ctx, arr);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_copyWithin(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    JSValue obj;\n    int64_t len, from, to, final, count;\n\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    if (JS_ToInt64Clamp(ctx, &to, argv[0], 0, len, len))\n        goto exception;\n\n    if (JS_ToInt64Clamp(ctx, &from, argv[1], 0, len, len))\n        goto exception;\n\n    final = len;\n    if (argc > 2 && !JS_IsUndefined(argv[2])) {\n        if (JS_ToInt64Clamp(ctx, &final, argv[2], 0, len, len))\n            goto exception;\n    }\n\n    count = min_int64(final - from, len - to);\n\n    if (JS_CopySubArray(ctx, obj, to, from, count,\n                        (from < to && to < from + count) ? -1 : +1))\n        goto exception;\n\n    return obj;\n\n exception:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target,\n                                   JSValueConst source, int64_t sourceLen,\n                                   int64_t targetIndex, int depth,\n                                   JSValueConst mapperFunction,\n                                   JSValueConst thisArg)\n{\n    JSValue element;\n    int64_t sourceIndex, elementLen;\n    int present, is_array;\n\n    for (sourceIndex = 0; sourceIndex < sourceLen; sourceIndex++) {\n        present = JS_TryGetPropertyInt64(ctx, source, sourceIndex, &element);\n        if (present < 0)\n            return -1;\n        if (!present)\n            continue;\n        if (!JS_IsUndefined(mapperFunction)) {\n            JSValueConst args[3] = { element, JS_NewInt64(ctx, sourceIndex), source };\n            element = JS_Call(ctx, mapperFunction, thisArg, 3, args);\n            JS_FreeValue(ctx, (JSValue)args[0]);\n            JS_FreeValue(ctx, (JSValue)args[1]);\n            if (JS_IsException(element))\n                return -1;\n        }\n        if (depth > 0) {\n            is_array = JS_IsArray(ctx, element);\n            if (is_array < 0)\n                goto fail;\n            if (is_array) {\n                if (js_get_length64(ctx, &elementLen, element) < 0)\n                    goto fail;\n                targetIndex = JS_FlattenIntoArray(ctx, target, element,\n                                                  elementLen, targetIndex,\n                                                  depth - 1,\n                                                  JS_UNDEFINED, JS_UNDEFINED);\n                if (targetIndex < 0)\n                    goto fail;\n                JS_FreeValue(ctx, element);\n                continue;\n            }\n        }\n        if (targetIndex >= MAX_SAFE_INTEGER) {\n            JS_ThrowTypeError(ctx, \"Array too long\");\n            goto fail;\n        }\n        if (JS_DefinePropertyValueInt64(ctx, target, targetIndex, element,\n                                        JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n            return -1;\n        targetIndex++;\n    }\n    return targetIndex;\n\nfail:\n    JS_FreeValue(ctx, element);\n    return -1;\n}\n\nstatic JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv, int map)\n{\n    JSValue obj, arr;\n    JSValueConst mapperFunction, thisArg;\n    int64_t sourceLen;\n    int depthNum;\n\n    arr = JS_UNDEFINED;\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &sourceLen, obj))\n        goto exception;\n\n    depthNum = 1;\n    mapperFunction = JS_UNDEFINED;\n    thisArg = JS_UNDEFINED;\n    if (map) {\n        mapperFunction = argv[0];\n        if (argc > 1) {\n            thisArg = argv[1];\n        }\n        if (check_function(ctx, mapperFunction))\n            goto exception;\n    } else {\n        if (argc > 0 && !JS_IsUndefined(argv[0])) {\n            if (JS_ToInt32Sat(ctx, &depthNum, argv[0]) < 0)\n                goto exception;\n        }\n    }\n    arr = JS_ArraySpeciesCreate(ctx, obj, JS_NewInt32(ctx, 0));\n    if (JS_IsException(arr))\n        goto exception;\n    if (JS_FlattenIntoArray(ctx, arr, obj, sourceLen, 0, depthNum,\n                            mapperFunction, thisArg) < 0)\n        goto exception;\n    JS_FreeValue(ctx, obj);\n    return arr;\n\nexception:\n    JS_FreeValue(ctx, obj);\n    JS_FreeValue(ctx, arr);\n    return JS_EXCEPTION;\n}\n\n/* Array sort */\n\ntypedef struct ValueSlot {\n    JSValue val;\n    JSString *str;\n    int64_t pos;\n} ValueSlot;\n\nstruct array_sort_context {\n    JSContext *ctx;\n    int exception;\n    int has_method;\n    JSValueConst method;\n};\n\nstatic int js_array_cmp_generic(const void *a, const void *b, void *opaque) {\n    struct array_sort_context *psc = opaque;\n    JSContext *ctx = psc->ctx;\n    JSValueConst argv[2];\n    JSValue res;\n    ValueSlot *ap = (ValueSlot *)(void *)a;\n    ValueSlot *bp = (ValueSlot *)(void *)b;\n    int cmp;\n\n    if (psc->exception)\n        return 0;\n\n    if (psc->has_method) {\n        /* custom sort function is specified as returning 0 for identical\n         * objects: avoid method call overhead.\n         */\n        if (!memcmp(&ap->val, &bp->val, sizeof(ap->val)))\n            goto cmp_same;\n        argv[0] = ap->val;\n        argv[1] = bp->val;\n        res = JS_Call(ctx, psc->method, JS_UNDEFINED, 2, argv);\n        if (JS_IsException(res))\n            goto exception;\n        if (JS_VALUE_GET_TAG(res) == JS_TAG_INT) {\n            int val = JS_VALUE_GET_INT(res);\n            cmp = (val > 0) - (val < 0);\n        } else {\n            double val;\n            if (JS_ToFloat64Free(ctx, &val, res) < 0)\n                goto exception;\n            cmp = (val > 0) - (val < 0);\n        }\n    } else {\n        /* Not supposed to bypass ToString even for identical objects as\n         * tested in test262/test/built-ins/Array/prototype/sort/bug_596_1.js\n         */\n        if (!ap->str) {\n            JSValue str = JS_ToString(ctx, ap->val);\n            if (JS_IsException(str))\n                goto exception;\n            ap->str = JS_VALUE_GET_STRING(str);\n        }\n        if (!bp->str) {\n            JSValue str = JS_ToString(ctx, bp->val);\n            if (JS_IsException(str))\n                goto exception;\n            bp->str = JS_VALUE_GET_STRING(str);\n        }\n        cmp = js_string_compare(ctx, ap->str, bp->str);\n    }\n    if (cmp != 0)\n        return cmp;\ncmp_same:\n    /* make sort stable: compare array offsets */\n    return (ap->pos > bp->pos) - (ap->pos < bp->pos);\n\nexception:\n    psc->exception = 1;\n    return 0;\n}\n\nstatic JSValue js_array_sort(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    struct array_sort_context asc = { ctx, 0, 0, argv[0] };\n    JSValue obj = JS_UNDEFINED;\n    ValueSlot *array = NULL;\n    size_t array_size = 0, pos = 0, n = 0;\n    int64_t i, len, undefined_count = 0;\n    int present;\n\n    if (!JS_IsUndefined(asc.method)) {\n        if (check_function(ctx, asc.method))\n            goto exception;\n        asc.has_method = 1;\n    }\n    obj = JS_ToObject(ctx, this_val);\n    if (js_get_length64(ctx, &len, obj))\n        goto exception;\n\n    /* XXX: should special case fast arrays */\n    for (i = 0; i < len; i++) {\n        if (pos >= array_size) {\n            size_t new_size, slack;\n            ValueSlot *new_array;\n            new_size = (array_size + (array_size >> 1) + 31) & ~15;\n            new_array = js_realloc2(ctx, array, new_size * sizeof(*array), &slack);\n            if (new_array == NULL)\n                goto exception;\n            new_size += slack / sizeof(*new_array);\n            array = new_array;\n            array_size = new_size;\n        }\n        present = JS_TryGetPropertyInt64(ctx, obj, i, &array[pos].val);\n        if (present < 0)\n            goto exception;\n        if (present == 0)\n            continue;\n        if (JS_IsUndefined(array[pos].val)) {\n            undefined_count++;\n            continue;\n        }\n        array[pos].str = NULL;\n        array[pos].pos = i;\n        pos++;\n    }\n    rqsort(array, pos, sizeof(*array), js_array_cmp_generic, &asc);\n    if (asc.exception)\n        goto exception;\n\n    /* XXX: should special case fast arrays */\n    while (n < pos) {\n        if (array[n].str)\n            JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, array[n].str));\n        if (array[n].pos == n) {\n            JS_FreeValue(ctx, array[n].val);\n        } else {\n            if (JS_SetPropertyInt64(ctx, obj, n, array[n].val) < 0) {\n                n++;\n                goto exception;\n            }\n        }\n        n++;\n    }\n    js_free(ctx, array);\n    for (i = n; undefined_count-- > 0; i++) {\n        if (JS_SetPropertyInt64(ctx, obj, i, JS_UNDEFINED) < 0)\n            goto fail;\n    }\n    for (; i < len; i++) {\n        if (JS_DeletePropertyInt64(ctx, obj, i, JS_PROP_THROW) < 0)\n            goto fail;\n    }\n    return obj;\n\nexception:\n    for (; n < pos; n++) {\n        JS_FreeValue(ctx, array[n].val);\n        if (array[n].str)\n            JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, array[n].str));\n    }\n    js_free(ctx, array);\nfail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\ntypedef struct JSArrayIteratorData {\n    JSValue obj;\n    JSIteratorKindEnum kind;\n    uint32_t idx;\n} JSArrayIteratorData;\n\nstatic void js_array_iterator_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSArrayIteratorData *it = p->u.array_iterator_data;\n    if (it) {\n        JS_FreeValueRT(rt, it->obj);\n        js_free_rt(rt, it);\n    }\n}\n\nstatic void js_array_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                   JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSArrayIteratorData *it = p->u.array_iterator_data;\n    if (it) {\n        JS_MarkValue(rt, it->obj, mark_func);\n    }\n}\n\nstatic JSValue js_create_array(JSContext *ctx, int len, JSValueConst *tab)\n{\n    JSValue obj;\n    int i;\n\n    obj = JS_NewArray(ctx);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    for(i = 0; i < len; i++) {\n        if (JS_CreateDataPropertyUint32(ctx, obj, i, JS_DupValue(ctx, tab[i]), 0) < 0) {\n            JS_FreeValue(ctx, obj);\n            return JS_EXCEPTION;\n        }\n    }\n    return obj;\n}\n\nstatic JSValue js_create_array_iterator(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv, int magic)\n{\n    JSValue enum_obj, arr;\n    JSArrayIteratorData *it;\n    JSIteratorKindEnum kind;\n    int class_id;\n\n    kind = magic & 3;\n    if (magic & 4) {\n        /* string iterator case */\n        arr = JS_ToStringCheckObject(ctx, this_val);\n        class_id = JS_CLASS_STRING_ITERATOR;\n    } else {\n        arr = JS_ToObject(ctx, this_val);\n        class_id = JS_CLASS_ARRAY_ITERATOR;\n    }\n    if (JS_IsException(arr))\n        goto fail;\n    enum_obj = JS_NewObjectClass(ctx, class_id);\n    if (JS_IsException(enum_obj))\n        goto fail;\n    it = js_malloc(ctx, sizeof(*it));\n    if (!it)\n        goto fail1;\n    it->obj = arr;\n    it->kind = kind;\n    it->idx = 0;\n    JS_SetOpaque(enum_obj, it);\n    return enum_obj;\n fail1:\n    JS_FreeValue(ctx, enum_obj);\n fail:\n    JS_FreeValue(ctx, arr);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv,\n                                      BOOL *pdone, int magic)\n{\n    JSArrayIteratorData *it;\n    uint32_t len, idx;\n    JSValue val, obj;\n    JSObject *p;\n\n    it = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_ITERATOR);\n    if (!it)\n        goto fail1;\n    if (JS_IsUndefined(it->obj))\n        goto done;\n    p = JS_VALUE_GET_OBJ(it->obj);\n    if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n        p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n        if (typed_array_is_detached(ctx, p)) {\n            JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n            goto fail1;\n        }\n        len = p->u.array.count;\n    } else {\n        if (js_get_length32(ctx, &len, it->obj)) {\n        fail1:\n            *pdone = FALSE;\n            return JS_EXCEPTION;\n        }\n    }\n    idx = it->idx;\n    if (idx >= len) {\n        JS_FreeValue(ctx, it->obj);\n        it->obj = JS_UNDEFINED;\n    done:\n        *pdone = TRUE;\n        return JS_UNDEFINED;\n    }\n    it->idx = idx + 1;\n    *pdone = FALSE;\n    if (it->kind == JS_ITERATOR_KIND_KEY) {\n        return JS_NewUint32(ctx, idx);\n    } else {\n        val = JS_GetPropertyUint32(ctx, it->obj, idx);\n        if (JS_IsException(val))\n            return JS_EXCEPTION;\n        if (it->kind == JS_ITERATOR_KIND_VALUE) {\n            return val;\n        } else {\n            JSValueConst args[2];\n            JSValue num;\n            num = JS_NewUint32(ctx, idx);\n            args[0] = num;\n            args[1] = val;\n            obj = js_create_array(ctx, 2, args);\n            JS_FreeValue(ctx, val);\n            JS_FreeValue(ctx, num);\n            return obj;\n        }\n    }\n}\n\nstatic JSValue js_iterator_proto_iterator(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv)\n{\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic const JSCFunctionListEntry js_iterator_proto_funcs[] = {\n    JS_CFUNC_DEF(\"[Symbol.iterator]\", 0, js_iterator_proto_iterator ),\n};\n\nstatic const JSCFunctionListEntry js_array_proto_funcs[] = {\n    JS_CFUNC_DEF(\"concat\", 1, js_array_concat ),\n    JS_CFUNC_MAGIC_DEF(\"every\", 1, js_array_every, special_every ),\n    JS_CFUNC_MAGIC_DEF(\"some\", 1, js_array_every, special_some ),\n    JS_CFUNC_MAGIC_DEF(\"forEach\", 1, js_array_every, special_forEach ),\n    JS_CFUNC_MAGIC_DEF(\"map\", 1, js_array_every, special_map ),\n    JS_CFUNC_MAGIC_DEF(\"filter\", 1, js_array_every, special_filter ),\n    JS_CFUNC_MAGIC_DEF(\"reduce\", 1, js_array_reduce, special_reduce ),\n    JS_CFUNC_MAGIC_DEF(\"reduceRight\", 1, js_array_reduce, special_reduceRight ),\n    JS_CFUNC_DEF(\"fill\", 1, js_array_fill ),\n    JS_CFUNC_MAGIC_DEF(\"find\", 1, js_array_find, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"findIndex\", 1, js_array_find, 1 ),\n    JS_CFUNC_DEF(\"indexOf\", 1, js_array_indexOf ),\n    JS_CFUNC_DEF(\"lastIndexOf\", 1, js_array_lastIndexOf ),\n    JS_CFUNC_DEF(\"includes\", 1, js_array_includes ),\n    JS_CFUNC_MAGIC_DEF(\"join\", 1, js_array_join, 0 ),\n    JS_CFUNC_DEF(\"toString\", 0, js_array_toString ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleString\", 0, js_array_join, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"pop\", 0, js_array_pop, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"push\", 1, js_array_push, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"shift\", 0, js_array_pop, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"unshift\", 1, js_array_push, 1 ),\n    JS_CFUNC_DEF(\"reverse\", 0, js_array_reverse ),\n    JS_CFUNC_DEF(\"sort\", 1, js_array_sort ),\n    JS_CFUNC_MAGIC_DEF(\"slice\", 2, js_array_slice, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"splice\", 2, js_array_slice, 1 ),\n    JS_CFUNC_DEF(\"copyWithin\", 2, js_array_copyWithin ),\n    JS_CFUNC_MAGIC_DEF(\"flatMap\", 1, js_array_flatten, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"flat\", 0, js_array_flatten, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"values\", 0, js_create_array_iterator, JS_ITERATOR_KIND_VALUE ),\n    JS_ALIAS_DEF(\"[Symbol.iterator]\", \"values\" ),\n    JS_CFUNC_MAGIC_DEF(\"keys\", 0, js_create_array_iterator, JS_ITERATOR_KIND_KEY ),\n    JS_CFUNC_MAGIC_DEF(\"entries\", 0, js_create_array_iterator, JS_ITERATOR_KIND_KEY_AND_VALUE ),\n};\n\nstatic const JSCFunctionListEntry js_array_iterator_proto_funcs[] = {\n    JS_ITERATOR_NEXT_DEF(\"next\", 0, js_array_iterator_next, 0 ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Array Iterator\", JS_PROP_CONFIGURABLE ),\n};\n\n/* Number */\n\nstatic JSValue js_number_constructor(JSContext *ctx, JSValueConst new_target,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, obj;\n    if (argc == 0) {\n        val = JS_NewInt32(ctx, 0);\n    } else {\n        val = JS_ToNumeric(ctx, argv[0]);\n        if (JS_IsException(val))\n            return val;\n        switch(JS_VALUE_GET_TAG(val)) {\n#ifdef CONFIG_BIGNUM\n        case JS_TAG_BIG_INT:\n        case JS_TAG_BIG_FLOAT:\n            {\n                JSBigFloat *p = JS_VALUE_GET_PTR(val);\n                double d;\n                bf_get_float64(&p->num, &d, BF_RNDN);\n                JS_FreeValue(ctx, val);\n                val = __JS_NewFloat64(ctx, d);\n            }\n            break;\n        case JS_TAG_BIG_DECIMAL:\n            val = JS_ToStringFree(ctx, val);\n            if (JS_IsException(val))\n                return val;\n            val = JS_ToNumberFree(ctx, val);\n            if (JS_IsException(val))\n                return val;\n            break;\n#endif\n        default:\n            break;\n        }\n    }\n    if (!JS_IsUndefined(new_target)) {\n        obj = js_create_from_ctor(ctx, new_target, JS_CLASS_NUMBER);\n        if (!JS_IsException(obj))\n            JS_SetObjectData(ctx, obj, val);\n        return obj;\n    } else {\n        return val;\n    }\n}\n\n#if 0\nstatic JSValue js_number___toInteger(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    return JS_ToIntegerFree(ctx, JS_DupValue(ctx, argv[0]));\n}\n\nstatic JSValue js_number___toLength(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    int64_t v;\n    if (JS_ToLengthFree(ctx, &v, JS_DupValue(ctx, argv[0])))\n        return JS_EXCEPTION;\n    return JS_NewInt64(ctx, v);\n}\n#endif\n\nstatic JSValue js_number_isNaN(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    if (!JS_IsNumber(argv[0]))\n        return JS_FALSE;\n    return js_global_isNaN(ctx, this_val, argc, argv);\n}\n\nstatic JSValue js_number_isFinite(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    if (!JS_IsNumber(argv[0]))\n        return JS_FALSE;\n    return js_global_isFinite(ctx, this_val, argc, argv);\n}\n\nstatic JSValue js_number_isInteger(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    int ret;\n    ret = JS_NumberIsInteger(ctx, argv[0]);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_number_isSafeInteger(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    double d;\n    if (!JS_IsNumber(argv[0]))\n        return JS_FALSE;\n    if (unlikely(JS_ToFloat64(ctx, &d, argv[0])))\n        return JS_EXCEPTION;\n    return JS_NewBool(ctx, is_safe_integer(d));\n}\n\nstatic const JSCFunctionListEntry js_number_funcs[] = {\n    /* global ParseInt and parseFloat should be defined already or delayed */\n    JS_ALIAS_BASE_DEF(\"parseInt\", \"parseInt\", 0 ),\n    JS_ALIAS_BASE_DEF(\"parseFloat\", \"parseFloat\", 0 ),\n    JS_CFUNC_DEF(\"isNaN\", 1, js_number_isNaN ),\n    JS_CFUNC_DEF(\"isFinite\", 1, js_number_isFinite ),\n    JS_CFUNC_DEF(\"isInteger\", 1, js_number_isInteger ),\n    JS_CFUNC_DEF(\"isSafeInteger\", 1, js_number_isSafeInteger ),\n    JS_PROP_DOUBLE_DEF(\"MAX_VALUE\", 1.7976931348623157e+308, 0 ),\n    JS_PROP_DOUBLE_DEF(\"MIN_VALUE\", 5e-324, 0 ),\n    JS_PROP_DOUBLE_DEF(\"NaN\", NAN, 0 ),\n    JS_PROP_DOUBLE_DEF(\"NEGATIVE_INFINITY\", -INFINITY, 0 ),\n    JS_PROP_DOUBLE_DEF(\"POSITIVE_INFINITY\", INFINITY, 0 ),\n    JS_PROP_DOUBLE_DEF(\"EPSILON\", 2.220446049250313e-16, 0 ), /* ES6 */\n    JS_PROP_DOUBLE_DEF(\"MAX_SAFE_INTEGER\", 9007199254740991.0, 0 ), /* ES6 */\n    JS_PROP_DOUBLE_DEF(\"MIN_SAFE_INTEGER\", -9007199254740991.0, 0 ), /* ES6 */\n    //JS_CFUNC_DEF(\"__toInteger\", 1, js_number___toInteger ),\n    //JS_CFUNC_DEF(\"__toLength\", 1, js_number___toLength ),\n};\n\nstatic JSValue js_thisNumberValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_IsNumber(this_val))\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_NUMBER) {\n            if (JS_IsNumber(p->u.object_data))\n                return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a number\");\n}\n\nstatic JSValue js_number_valueOf(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    return js_thisNumberValue(ctx, this_val);\n}\n\nstatic int js_get_radix(JSContext *ctx, JSValueConst val)\n{\n    int radix;\n    if (JS_ToInt32Sat(ctx, &radix, val))\n        return -1;\n    if (radix < 2 || radix > 36) {\n        JS_ThrowRangeError(ctx, \"radix must be between 2 and 36\");\n        return -1;\n    }\n    return radix;\n}\n\nstatic JSValue js_number_toString(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv, int magic)\n{\n    JSValue val;\n    int base;\n    double d;\n\n    val = js_thisNumberValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (magic || JS_IsUndefined(argv[0])) {\n        base = 10;\n    } else {\n        base = js_get_radix(ctx, argv[0]);\n        if (base < 0)\n            goto fail;\n    }\n    if (JS_ToFloat64Free(ctx, &d, val))\n        return JS_EXCEPTION;\n    return js_dtoa(ctx, d, base, 0, JS_DTOA_VAR_FORMAT);\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_number_toFixed(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue val;\n    int f;\n    double d;\n\n    val = js_thisNumberValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToFloat64Free(ctx, &d, val))\n        return JS_EXCEPTION;\n    if (JS_ToInt32Sat(ctx, &f, argv[0]))\n        return JS_EXCEPTION;\n    if (f < 0 || f > 100)\n        return JS_ThrowRangeError(ctx, \"invalid number of digits\");\n    if (fabs(d) >= 1e21) {\n        return JS_ToStringFree(ctx, __JS_NewFloat64(ctx, d));\n    } else {\n        return js_dtoa(ctx, d, 10, f, JS_DTOA_FRAC_FORMAT);\n    }\n}\n\nstatic JSValue js_number_toExponential(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValue val;\n    int f, flags;\n    double d;\n\n    val = js_thisNumberValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToFloat64Free(ctx, &d, val))\n        return JS_EXCEPTION;\n    if (JS_ToInt32Sat(ctx, &f, argv[0]))\n        return JS_EXCEPTION;\n    if (!isfinite(d)) {\n        return JS_ToStringFree(ctx,  __JS_NewFloat64(ctx, d));\n    }\n    if (JS_IsUndefined(argv[0])) {\n        flags = 0;\n        f = 0;\n    } else {\n        if (f < 0 || f > 100)\n            return JS_ThrowRangeError(ctx, \"invalid number of digits\");\n        f++;\n        flags = JS_DTOA_FIXED_FORMAT;\n    }\n    return js_dtoa(ctx, d, 10, f, flags | JS_DTOA_FORCE_EXP);\n}\n\nstatic JSValue js_number_toPrecision(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val;\n    int p;\n    double d;\n\n    val = js_thisNumberValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToFloat64Free(ctx, &d, val))\n        return JS_EXCEPTION;\n    if (JS_IsUndefined(argv[0]))\n        goto to_string;\n    if (JS_ToInt32Sat(ctx, &p, argv[0]))\n        return JS_EXCEPTION;\n    if (!isfinite(d)) {\n    to_string:\n        return JS_ToStringFree(ctx,  __JS_NewFloat64(ctx, d));\n    }\n    if (p < 1 || p > 100)\n        return JS_ThrowRangeError(ctx, \"invalid number of digits\");\n    return js_dtoa(ctx, d, 10, p, JS_DTOA_FIXED_FORMAT);\n}\n\nstatic const JSCFunctionListEntry js_number_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toExponential\", 1, js_number_toExponential ),\n    JS_CFUNC_DEF(\"toFixed\", 1, js_number_toFixed ),\n    JS_CFUNC_DEF(\"toPrecision\", 1, js_number_toPrecision ),\n    JS_CFUNC_MAGIC_DEF(\"toString\", 1, js_number_toString, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleString\", 0, js_number_toString, 1 ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_number_valueOf ),\n};\n\nstatic JSValue js_parseInt(JSContext *ctx, JSValueConst this_val,\n                           int argc, JSValueConst *argv)\n{\n    const char *str, *p;\n    int radix, flags;\n    JSValue ret;\n\n    str = JS_ToCString(ctx, argv[0]);\n    if (!str)\n        return JS_EXCEPTION;\n    if (JS_ToInt32(ctx, &radix, argv[1])) {\n        JS_FreeCString(ctx, str);\n        return JS_EXCEPTION;\n    }\n    if (radix != 0 && (radix < 2 || radix > 36)) {\n        ret = JS_NAN;\n    } else {\n        p = str;\n        p += skip_spaces(p);\n        flags = ATOD_INT_ONLY | ATOD_ACCEPT_PREFIX_AFTER_SIGN;\n        ret = js_atof(ctx, p, NULL, radix, flags);\n    }\n    JS_FreeCString(ctx, str);\n    return ret;\n}\n\nstatic JSValue js_parseFloat(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    const char *str, *p;\n    JSValue ret;\n\n    str = JS_ToCString(ctx, argv[0]);\n    if (!str)\n        return JS_EXCEPTION;\n    p = str;\n    p += skip_spaces(p);\n    ret = js_atof(ctx, p, NULL, 10, 0);\n    JS_FreeCString(ctx, str);\n    return ret;\n}\n\n/* Boolean */\nstatic JSValue js_boolean_constructor(JSContext *ctx, JSValueConst new_target,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, obj;\n    val = JS_NewBool(ctx, JS_ToBool(ctx, argv[0]));\n    if (!JS_IsUndefined(new_target)) {\n        obj = js_create_from_ctor(ctx, new_target, JS_CLASS_BOOLEAN);\n        if (!JS_IsException(obj))\n            JS_SetObjectData(ctx, obj, val);\n        return obj;\n    } else {\n        return val;\n    }\n}\n\nstatic JSValue js_thisBooleanValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_BOOL)\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_BOOLEAN) {\n            if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_BOOL)\n                return p->u.object_data;\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a boolean\");\n}\n\nstatic JSValue js_boolean_toString(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    JSValue val = js_thisBooleanValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    return JS_AtomToString(ctx, JS_VALUE_GET_BOOL(val) ?\n                       JS_ATOM_true : JS_ATOM_false);\n}\n\nstatic JSValue js_boolean_valueOf(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    return js_thisBooleanValue(ctx, this_val);\n}\n\nstatic const JSCFunctionListEntry js_boolean_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_boolean_toString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_boolean_valueOf ),\n};\n\n/* String */\n\nstatic int js_string_get_own_property(JSContext *ctx,\n                                      JSPropertyDescriptor *desc,\n                                      JSValueConst obj, JSAtom prop)\n{\n    JSObject *p;\n    JSString *p1;\n    uint32_t idx, ch;\n\n    /* This is a class exotic method: obj class_id is JS_CLASS_STRING */\n    if (__JS_AtomIsTaggedInt(prop)) {\n        p = JS_VALUE_GET_OBJ(obj);\n        if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_STRING) {\n            p1 = JS_VALUE_GET_STRING(p->u.object_data);\n            idx = __JS_AtomToUInt32(prop);\n            if (idx < p1->len) {\n                if (desc) {\n                    if (p1->is_wide_char)\n                        ch = p1->u.str16[idx];\n                    else\n                        ch = p1->u.str8[idx];\n                    desc->flags = JS_PROP_ENUMERABLE;\n                    desc->value = js_new_string_char(ctx, ch);\n                    desc->getter = JS_UNDEFINED;\n                    desc->setter = JS_UNDEFINED;\n                }\n                return TRUE;\n            }\n        }\n    }\n    return FALSE;\n}\n\nstatic uint32_t js_string_obj_get_length(JSContext *ctx,\n                                         JSValueConst obj)\n{\n    JSObject *p;\n    JSString *p1;\n    uint32_t len = 0;\n\n    /* This is a class exotic method: obj class_id is JS_CLASS_STRING */\n    p = JS_VALUE_GET_OBJ(obj);\n    if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_STRING) {\n        p1 = JS_VALUE_GET_STRING(p->u.object_data);\n        len = p1->len;\n    }\n    return len;\n}\n\nstatic int js_string_get_own_property_names(JSContext *ctx,\n                                            JSPropertyEnum **ptab,\n                                            uint32_t *plen,\n                                            JSValueConst obj)\n{\n    JSPropertyEnum *tab;\n    uint32_t len, i;\n\n    len = js_string_obj_get_length(ctx, obj);\n    tab = NULL;\n    if (len > 0) {\n        /* do not allocate 0 bytes */\n        tab = js_malloc(ctx, sizeof(JSPropertyEnum) * len);\n        if (!tab)\n            return -1;\n        for(i = 0; i < len; i++) {\n            tab[i].atom = __JS_AtomFromUInt32(i);\n        }\n    }\n    *ptab = tab;\n    *plen = len;\n    return 0;\n}\n\nstatic int js_string_define_own_property(JSContext *ctx,\n                                         JSValueConst this_obj,\n                                         JSAtom prop, JSValueConst val,\n                                         JSValueConst getter,\n                                         JSValueConst setter, int flags)\n{\n    uint32_t idx;\n    JSObject *p;\n    JSString *p1, *p2;\n    \n    if (__JS_AtomIsTaggedInt(prop)) {\n        idx = __JS_AtomToUInt32(prop);\n        p = JS_VALUE_GET_OBJ(this_obj);\n        if (JS_VALUE_GET_TAG(p->u.object_data) != JS_TAG_STRING)\n            goto def;\n        p1 = JS_VALUE_GET_STRING(p->u.object_data);\n        if (idx >= p1->len)\n            goto def;\n        if (!check_define_prop_flags(JS_PROP_ENUMERABLE, flags))\n            goto fail;\n        /* check that the same value is configured */\n        if (flags & JS_PROP_HAS_VALUE) {\n            if (JS_VALUE_GET_TAG(val) != JS_TAG_STRING)\n                goto fail;\n            p2 = JS_VALUE_GET_STRING(val);\n            if (p2->len != 1)\n                goto fail;\n            if (string_get(p1, idx) != string_get(p2, 0)) {\n            fail:\n                return JS_ThrowTypeErrorOrFalse(ctx, flags, \"property is not configurable\");\n            }\n        }\n        return TRUE;\n    } else {\n    def:\n        return JS_DefineProperty(ctx, this_obj, prop, val, getter, setter,\n                                 flags | JS_PROP_NO_EXOTIC);\n    }\n}\n\nstatic int js_string_delete_property(JSContext *ctx,\n                                     JSValueConst obj, JSAtom prop)\n{\n    uint32_t idx;\n\n    if (__JS_AtomIsTaggedInt(prop)) {\n        idx = __JS_AtomToUInt32(prop);\n        if (idx < js_string_obj_get_length(ctx, obj)) {\n            return FALSE;\n        }\n    }\n    return TRUE;\n}\n\nstatic const JSClassExoticMethods js_string_exotic_methods = {\n    .get_own_property = js_string_get_own_property,\n    .get_own_property_names = js_string_get_own_property_names,\n    .define_own_property = js_string_define_own_property,\n    .delete_property = js_string_delete_property,\n};\n\nstatic JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, obj;\n    if (argc == 0) {\n        val = JS_AtomToString(ctx, JS_ATOM_empty_string);\n    } else {\n        if (JS_IsUndefined(new_target) && JS_IsSymbol(argv[0])) {\n            JSAtomStruct *p = JS_VALUE_GET_PTR(argv[0]);\n            val = JS_ConcatString3(ctx, \"Symbol(\", JS_AtomToString(ctx, js_get_atom_index(ctx->rt, p)), \")\");\n        } else {\n            val = JS_ToString(ctx, argv[0]);\n        }\n        if (JS_IsException(val))\n            return val;\n    }\n    if (!JS_IsUndefined(new_target)) {\n        JSString *p1 = JS_VALUE_GET_STRING(val);\n\n        obj = js_create_from_ctor(ctx, new_target, JS_CLASS_STRING);\n        if (!JS_IsException(obj)) {\n            JS_SetObjectData(ctx, obj, val);\n            JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, JS_NewInt32(ctx, p1->len), 0);\n        }\n        return obj;\n    } else {\n        return val;\n    }\n}\n\nstatic JSValue js_thisStringValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_STRING)\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_STRING) {\n            if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_STRING)\n                return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a string\");\n}\n\nstatic JSValue js_string_fromCharCode(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    int i;\n    StringBuffer b_s, *b = &b_s;\n\n    string_buffer_init(ctx, b, argc);\n\n    for(i = 0; i < argc; i++) {\n        int32_t c;\n        if (JS_ToInt32(ctx, &c, argv[i]) || string_buffer_putc16(b, c & 0xffff)) {\n            string_buffer_free(b);\n            return JS_EXCEPTION;\n        }\n    }\n    return string_buffer_end(b);\n}\n\nstatic JSValue js_string_fromCodePoint(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    double d;\n    int i, c;\n    StringBuffer b_s, *b = &b_s;\n\n    /* XXX: could pre-compute string length if all arguments are JS_TAG_INT */\n\n    if (string_buffer_init(ctx, b, argc))\n        goto fail;\n    for(i = 0; i < argc; i++) {\n        if (JS_VALUE_GET_TAG(argv[i]) == JS_TAG_INT) {\n            c = JS_VALUE_GET_INT(argv[i]);\n            if (c < 0 || c > 0x10ffff)\n                goto range_error;\n        } else {\n            if (JS_ToFloat64(ctx, &d, argv[i]))\n                goto fail;\n            if (d < 0 || d > 0x10ffff || (c = (int)d) != d)\n                goto range_error;\n        }\n        if (string_buffer_putc(b, c))\n            goto fail;\n    }\n    return string_buffer_end(b);\n\n range_error:\n    JS_ThrowRangeError(ctx, \"invalid code point\");\n fail:\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_raw(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    // raw(temp,...a)\n    JSValue cooked, val, raw;\n    StringBuffer b_s, *b = &b_s;\n    int64_t i, n;\n\n    string_buffer_init(ctx, b, 0);\n    raw = JS_UNDEFINED;\n    cooked = JS_ToObject(ctx, argv[0]);\n    if (JS_IsException(cooked))\n        goto exception;\n    raw = JS_ToObjectFree(ctx, JS_GetProperty(ctx, cooked, JS_ATOM_raw));\n    if (JS_IsException(raw))\n        goto exception;\n    if (js_get_length64(ctx, &n, raw) < 0)\n        goto exception;\n        \n    for (i = 0; i < n; i++) {\n        val = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, raw, i));\n        if (JS_IsException(val))\n            goto exception;\n        string_buffer_concat_value_free(b, val);\n        if (i < n - 1 && i + 1 < argc) {\n            if (string_buffer_concat_value(b, argv[i + 1]))\n                goto exception;\n        }\n    }\n    JS_FreeValue(ctx, cooked);\n    JS_FreeValue(ctx, raw);\n    return string_buffer_end(b);\n\nexception:\n    JS_FreeValue(ctx, cooked);\n    JS_FreeValue(ctx, raw);\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\n/* only used in test262 */\nJSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    uint32_t start, end, i, n;\n    StringBuffer b_s, *b = &b_s;\n\n    if (JS_ToUint32(ctx, &start, argv[0]) ||\n        JS_ToUint32(ctx, &end, argv[1]))\n        return JS_EXCEPTION;\n    end = min_uint32(end, 0x10ffff + 1);\n\n    if (start > end) {\n        start = end;\n    }\n    n = end - start;\n    if (end > 0x10000) {\n        n += end - max_uint32(start, 0x10000);\n    }\n    if (string_buffer_init2(ctx, b, n, end >= 0x100))\n        return JS_EXCEPTION;\n    for(i = start; i < end; i++) {\n        string_buffer_putc(b, i);\n    }\n    return string_buffer_end(b);\n}\n\n#if 0\nstatic JSValue js_string___isSpace(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    int c;\n    if (JS_ToInt32(ctx, &c, argv[0]))\n        return JS_EXCEPTION;\n    return JS_NewBool(ctx, lre_is_space(c));\n}\n#endif\n\nstatic JSValue js_string_charCodeAt(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    JSString *p;\n    int idx, c;\n\n    val = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_STRING(val);\n    if (JS_ToInt32Sat(ctx, &idx, argv[0])) {\n        JS_FreeValue(ctx, val);\n        return JS_EXCEPTION;\n    }\n    if (idx < 0 || idx >= p->len) {\n        ret = JS_NAN;\n    } else {\n        if (p->is_wide_char)\n            c = p->u.str16[idx];\n        else\n            c = p->u.str8[idx];\n        ret = JS_NewInt32(ctx, c);\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic JSValue js_string_charAt(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    JSString *p;\n    int idx, c;\n\n    val = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_STRING(val);\n    if (JS_ToInt32Sat(ctx, &idx, argv[0])) {\n        JS_FreeValue(ctx, val);\n        return JS_EXCEPTION;\n    }\n    if (idx < 0 || idx >= p->len) {\n        ret = js_new_string8(ctx, NULL, 0);\n    } else {\n        if (p->is_wide_char)\n            c = p->u.str16[idx];\n        else\n            c = p->u.str8[idx];\n        ret = js_new_string_char(ctx, c);\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic JSValue js_string_codePointAt(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    JSString *p;\n    int idx, c;\n\n    val = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_STRING(val);\n    if (JS_ToInt32Sat(ctx, &idx, argv[0])) {\n        JS_FreeValue(ctx, val);\n        return JS_EXCEPTION;\n    }\n    if (idx < 0 || idx >= p->len) {\n        ret = JS_UNDEFINED;\n    } else {\n        c = string_getc(p, &idx);\n        ret = JS_NewInt32(ctx, c);\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic JSValue js_string_concat(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue r;\n    int i;\n\n    /* XXX: Use more efficient method */\n    /* XXX: This method is OK if r has a single refcount */\n    /* XXX: should use string_buffer? */\n    r = JS_ToStringCheckObject(ctx, this_val);\n    for (i = 0; i < argc; i++) {\n        if (JS_IsException(r))\n            break;\n        r = JS_ConcatString(ctx, r, JS_DupValue(ctx, argv[i]));\n    }\n    return r;\n}\n\nstatic int string_cmp(JSString *p1, JSString *p2, int x1, int x2, int len)\n{\n    int i, c1, c2;\n    for (i = 0; i < len; i++) {\n        if ((c1 = string_get(p1, x1 + i)) != (c2 = string_get(p2, x2 + i)))\n            return c1 - c2;\n    }\n    return 0;\n}\n\nstatic int string_indexof_char(JSString *p, int c, int from)\n{\n    /* assuming 0 <= from <= p->len */\n    int i, len = p->len;\n    if (p->is_wide_char) {\n        for (i = from; i < len; i++) {\n            if (p->u.str16[i] == c)\n                return i;\n        }\n    } else {\n        if ((c & ~0xff) == 0) {\n            for (i = from; i < len; i++) {\n                if (p->u.str8[i] == (uint8_t)c)\n                    return i;\n            }\n        }\n    }\n    return -1;\n}\n\nstatic int string_indexof(JSString *p1, JSString *p2, int from)\n{\n    /* assuming 0 <= from <= p1->len */\n    int c, i, j, len1 = p1->len, len2 = p2->len;\n    if (len2 == 0)\n        return from;\n    for (i = from, c = string_get(p2, 0); i + len2 <= len1; i = j + 1) {\n        j = string_indexof_char(p1, c, i);\n        if (j < 0 || j + len2 > len1)\n            break;\n        if (!string_cmp(p1, p2, j + 1, 1, len2 - 1))\n            return j;\n    }\n    return -1;\n}\n\nstatic int64_t string_advance_index(JSString *p, int64_t index, BOOL unicode)\n{\n    if (!unicode || index >= p->len || !p->is_wide_char) {\n        index++;\n    } else {\n        int index32 = (int)index;\n        string_getc(p, &index32);\n        index = index32;\n    }\n    return index;\n}\n\nstatic JSValue js_string_indexOf(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv, int lastIndexOf)\n{\n    JSValue str, v;\n    int i, len, v_len, pos, start, stop, ret, inc;\n    JSString *p;\n    JSString *p1;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return str;\n    v = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(v))\n        goto fail;\n    p = JS_VALUE_GET_STRING(str);\n    p1 = JS_VALUE_GET_STRING(v);\n    len = p->len;\n    v_len = p1->len;\n    if (lastIndexOf) {\n        pos = len - v_len;\n        if (argc > 1) {\n            double d;\n            if (JS_ToFloat64(ctx, &d, argv[1]))\n                goto fail;\n            if (!isnan(d)) {\n                if (d <= 0)\n                    pos = 0;\n                else if (d < pos)\n                    pos = d;\n            }\n        }\n        start = pos;\n        stop = 0;\n        inc = -1;\n    } else {\n        pos = 0;\n        if (argc > 1) {\n            if (JS_ToInt32Clamp(ctx, &pos, argv[1], 0, len, 0))\n                goto fail;\n        }\n        start = pos;\n        stop = len - v_len;\n        inc = 1;\n    }\n    ret = -1;\n    if (len >= v_len && inc * (stop - start) >= 0) {\n        for (i = start;; i += inc) {\n            if (!string_cmp(p, p1, i, 0, v_len)) {\n                ret = i;\n                break;\n            }\n            if (i == stop)\n                break;\n        }\n    }\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, v);\n    return JS_NewInt32(ctx, ret);\n\nfail:\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, v);\n    return JS_EXCEPTION;\n}\n\n/* return < 0 if exception or TRUE/FALSE */\nstatic int js_is_regexp(JSContext *ctx, JSValueConst obj);\n\nstatic JSValue js_string_includes(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv, int magic)\n{\n    JSValue str, v = JS_UNDEFINED;\n    int i, len, v_len, pos, start, stop, ret;\n    JSString *p;\n    JSString *p1;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return str;\n    ret = js_is_regexp(ctx, argv[0]);\n    if (ret) {\n        if (ret > 0)\n            JS_ThrowTypeError(ctx, \"regex not supported\");\n        goto fail;\n    }\n    v = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(v))\n        goto fail;\n    p = JS_VALUE_GET_STRING(str);\n    p1 = JS_VALUE_GET_STRING(v);\n    len = p->len;\n    v_len = p1->len;\n    pos = (magic == 2) ? len : 0;\n    if (argc > 1 && !JS_IsUndefined(argv[1])) {\n        if (JS_ToInt32Clamp(ctx, &pos, argv[1], 0, len, 0))\n            goto fail;\n    }\n    len -= v_len;\n    ret = 0;\n    if (magic == 0) {\n        start = pos;\n        stop = len;\n    } else {\n        if (magic == 1) {\n            if (pos > len)\n                goto done;\n        } else {\n            pos -= v_len;\n        }\n        start = stop = pos;\n    }\n    if (start >= 0 && start <= stop) {\n        for (i = start;; i++) {\n            if (!string_cmp(p, p1, i, 0, v_len)) {\n                ret = 1;\n                break;\n            }\n            if (i == stop)\n                break;\n        }\n    }\n done:\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, v);\n    return JS_NewBool(ctx, ret);\n\nfail:\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, v);\n    return JS_EXCEPTION;\n}\n\nstatic int check_regexp_g_flag(JSContext *ctx, JSValueConst regexp)\n{\n    int ret;\n    JSValue flags;\n    \n    ret = js_is_regexp(ctx, regexp);\n    if (ret < 0)\n        return -1;\n    if (ret) {\n        flags = JS_GetProperty(ctx, regexp, JS_ATOM_flags);\n        if (JS_IsException(flags))\n            return -1;\n        if (JS_IsUndefined(flags) || JS_IsNull(flags)) {\n            JS_ThrowTypeError(ctx, \"cannot convert to object\");\n            return -1;\n        }\n        flags = JS_ToStringFree(ctx, flags);\n        if (JS_IsException(flags))\n            return -1;\n        ret = string_indexof_char(JS_VALUE_GET_STRING(flags), 'g', 0);\n        JS_FreeValue(ctx, flags);\n        if (ret < 0) {\n            JS_ThrowTypeError(ctx, \"regexp must have the 'g' flag\");\n            return -1;\n        }\n    }\n    return 0;\n}\n\nstatic JSValue js_string_match(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv, int atom)\n{\n    // match(rx), search(rx), matchAll(rx)\n    // atom is JS_ATOM_Symbol_match, JS_ATOM_Symbol_search, or JS_ATOM_Symbol_matchAll\n    JSValueConst O = this_val, regexp = argv[0], args[2];\n    JSValue matcher, S, rx, result, str;\n    int args_len;\n\n    if (JS_IsUndefined(O) || JS_IsNull(O))\n        return JS_ThrowTypeError(ctx, \"cannot convert to object\");\n\n    if (!JS_IsUndefined(regexp) && !JS_IsNull(regexp)) {\n        matcher = JS_GetProperty(ctx, regexp, atom);\n        if (JS_IsException(matcher))\n            return JS_EXCEPTION;\n        if (atom == JS_ATOM_Symbol_matchAll) {\n            if (check_regexp_g_flag(ctx, regexp) < 0) {\n                JS_FreeValue(ctx, matcher);\n                return JS_EXCEPTION;\n            }\n        }\n        if (!JS_IsUndefined(matcher) && !JS_IsNull(matcher)) {\n            return JS_CallFree(ctx, matcher, regexp, 1, &O);\n        }\n    }\n    S = JS_ToString(ctx, O);\n    if (JS_IsException(S))\n        return JS_EXCEPTION;\n    args_len = 1;\n    args[0] = regexp;\n    str = JS_UNDEFINED;\n    if (atom == JS_ATOM_Symbol_matchAll) {\n        str = JS_NewString(ctx, \"g\");\n        if (JS_IsException(str))\n            goto fail;\n        args[args_len++] = (JSValueConst)str;\n    }\n    rx = JS_CallConstructor(ctx, ctx->regexp_ctor, args_len, args);\n    JS_FreeValue(ctx, str);\n    if (JS_IsException(rx)) {\n    fail:\n        JS_FreeValue(ctx, S);\n        return JS_EXCEPTION;\n    }\n    result = JS_InvokeFree(ctx, rx, atom, 1, (JSValueConst *)&S);\n    JS_FreeValue(ctx, S);\n    return result;\n}\n\nstatic JSValue js_string___GetSubstitution(JSContext *ctx, JSValueConst this_val,\n                                           int argc, JSValueConst *argv)\n{\n    // GetSubstitution(matched, str, position, captures, namedCaptures, rep)\n    JSValueConst matched, str, captures, namedCaptures, rep;\n    JSValue capture, name, s;\n    uint32_t position, len, matched_len, captures_len;\n    int i, j, j0, k, k1;\n    int c, c1;\n    StringBuffer b_s, *b = &b_s;\n    JSString *sp, *rp;\n\n    matched = argv[0];\n    str = argv[1];\n    captures = argv[3];\n    namedCaptures = argv[4];\n    rep = argv[5];\n\n    if (!JS_IsString(rep) || !JS_IsString(str))\n        return JS_ThrowTypeError(ctx, \"not a string\");\n\n    sp = JS_VALUE_GET_STRING(str);\n    rp = JS_VALUE_GET_STRING(rep);\n\n    string_buffer_init(ctx, b, 0);\n\n    captures_len = 0;\n    if (!JS_IsUndefined(captures)) {\n        if (js_get_length32(ctx, &captures_len, captures))\n            goto exception;\n    }\n    if (js_get_length32(ctx, &matched_len, matched))\n        goto exception;\n    if (JS_ToUint32(ctx, &position, argv[2]) < 0)\n        goto exception;\n\n    len = rp->len;\n    i = 0;\n    for(;;) {\n        j = string_indexof_char(rp, '$', i);\n        if (j < 0 || j + 1 >= len)\n            break;\n        string_buffer_concat(b, rp, i, j);\n        j0 = j++;\n        c = string_get(rp, j++);\n        if (c == '$') {\n            string_buffer_putc8(b, '$');\n        } else if (c == '&') {\n            if (string_buffer_concat_value(b, matched))\n                goto exception;\n        } else if (c == '`') {\n            string_buffer_concat(b, sp, 0, position);\n        } else if (c == '\\'') {\n            string_buffer_concat(b, sp, position + matched_len, sp->len);\n        } else if (c >= '0' && c <= '9') {\n            k = c - '0';\n            c1 = string_get(rp, j);\n            if (c1 >= '0' && c1 <= '9') {\n                /* This behavior is specified in ES6 and refined in ECMA 2019 */\n                /* ECMA 2019 does not have the extra test, but\n                   Test262 S15.5.4.11_A3_T1..3 require this behavior */\n                k1 = k * 10 + c1 - '0';\n                if (k1 >= 1 && k1 < captures_len) {\n                    k = k1;\n                    j++;\n                }\n            }\n            if (k >= 1 && k < captures_len) {\n                s = JS_GetPropertyInt64(ctx, captures, k);\n                if (JS_IsException(s))\n                    goto exception;\n                if (!JS_IsUndefined(s)) {\n                    if (string_buffer_concat_value_free(b, s))\n                        goto exception;\n                }\n            } else {\n                goto norep;\n            }\n        } else if (c == '<' && !JS_IsUndefined(namedCaptures)) {\n            k = string_indexof_char(rp, '>', j);\n            if (k < 0)\n                goto norep;\n            name = js_sub_string(ctx, rp, j, k);\n            if (JS_IsException(name))\n                goto exception;\n            capture = JS_GetPropertyValue(ctx, namedCaptures, name);\n            if (JS_IsException(capture))\n                goto exception;\n            if (!JS_IsUndefined(capture)) {\n                if (string_buffer_concat_value_free(b, capture))\n                    goto exception;\n            }\n            j = k + 1;\n        } else {\n        norep:\n            string_buffer_concat(b, rp, j0, j);\n        }\n        i = j;\n    }\n    string_buffer_concat(b, rp, i, rp->len);\n    return string_buffer_end(b);\nexception:\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_replace(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv,\n                                 int is_replaceAll)\n{\n    // replace(rx, rep)\n    JSValueConst O = this_val, searchValue = argv[0], replaceValue = argv[1];\n    JSValueConst args[6];\n    JSValue str, search_str, replaceValue_str, repl_str;\n    JSString *sp, *searchp;\n    StringBuffer b_s, *b = &b_s;\n    int pos, functionalReplace, endOfLastMatch;\n    BOOL is_first;\n\n    if (JS_IsUndefined(O) || JS_IsNull(O))\n        return JS_ThrowTypeError(ctx, \"cannot convert to object\");\n\n    search_str = JS_UNDEFINED;\n    replaceValue_str = JS_UNDEFINED;\n    repl_str = JS_UNDEFINED;\n\n    if (!JS_IsUndefined(searchValue) && !JS_IsNull(searchValue)) {\n        JSValue replacer;\n        if (is_replaceAll) {\n            if (check_regexp_g_flag(ctx, searchValue) < 0)\n                return JS_EXCEPTION;\n        }\n        replacer = JS_GetProperty(ctx, searchValue, JS_ATOM_Symbol_replace);\n        if (JS_IsException(replacer))\n            return JS_EXCEPTION;\n        if (!JS_IsUndefined(replacer) && !JS_IsNull(replacer)) {\n            args[0] = O;\n            args[1] = replaceValue;\n            return JS_CallFree(ctx, replacer, searchValue, 2, args);\n        }\n    }\n    string_buffer_init(ctx, b, 0);\n\n    str = JS_ToString(ctx, O);\n    if (JS_IsException(str))\n        goto exception;\n    search_str = JS_ToString(ctx, searchValue);\n    if (JS_IsException(search_str))\n        goto exception;\n    functionalReplace = JS_IsFunction(ctx, replaceValue);\n    if (!functionalReplace) {\n        replaceValue_str = JS_ToString(ctx, replaceValue);\n        if (JS_IsException(replaceValue_str))\n            goto exception;\n    }\n\n    sp = JS_VALUE_GET_STRING(str);\n    searchp = JS_VALUE_GET_STRING(search_str);\n    endOfLastMatch = 0;\n    is_first = TRUE;\n    for(;;) {\n        if (unlikely(searchp->len == 0)) {\n            if (is_first)\n                pos = 0;\n            else if (endOfLastMatch >= sp->len)\n                pos = -1;\n            else\n                pos = endOfLastMatch + 1;\n        } else {\n            pos = string_indexof(sp, searchp, endOfLastMatch);\n        }\n        if (pos < 0) {\n            if (is_first) {\n                string_buffer_free(b);\n                JS_FreeValue(ctx, search_str);\n                JS_FreeValue(ctx, replaceValue_str);\n                return str;\n            } else {\n                break;\n            }\n        }\n        if (functionalReplace) {\n            args[0] = search_str;\n            args[1] = JS_NewInt32(ctx, pos);\n            args[2] = str;\n            repl_str = JS_ToStringFree(ctx, JS_Call(ctx, replaceValue, JS_UNDEFINED, 3, args));\n        } else {\n            args[0] = search_str;\n            args[1] = str;\n            args[2] = JS_NewInt32(ctx, pos);\n            args[3] = JS_UNDEFINED;\n            args[4] = JS_UNDEFINED;\n            args[5] = replaceValue_str;\n            repl_str = js_string___GetSubstitution(ctx, JS_UNDEFINED, 6, args);\n        }\n        if (JS_IsException(repl_str))\n            goto exception;\n        \n        string_buffer_concat(b, sp, endOfLastMatch, pos);\n        string_buffer_concat_value_free(b, repl_str);\n        endOfLastMatch = pos + searchp->len;\n        is_first = FALSE;\n        if (!is_replaceAll)\n            break;\n    }\n    string_buffer_concat(b, sp, endOfLastMatch, sp->len);\n    JS_FreeValue(ctx, search_str);\n    JS_FreeValue(ctx, replaceValue_str);\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n\nexception:\n    string_buffer_free(b);\n    JS_FreeValue(ctx, search_str);\n    JS_FreeValue(ctx, replaceValue_str);\n    JS_FreeValue(ctx, str);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_split(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    // split(sep, limit)\n    JSValueConst O = this_val, separator = argv[0], limit = argv[1];\n    JSValueConst args[2];\n    JSValue S, A, R, T;\n    uint32_t lim, lengthA;\n    int64_t p, q, s, r, e;\n    JSString *sp, *rp;\n\n    if (JS_IsUndefined(O) || JS_IsNull(O))\n        return JS_ThrowTypeError(ctx, \"cannot convert to object\");\n\n    S = JS_UNDEFINED;\n    A = JS_UNDEFINED;\n    R = JS_UNDEFINED;\n\n    if (!JS_IsUndefined(separator) && !JS_IsNull(separator)) {\n        JSValue splitter;\n        splitter = JS_GetProperty(ctx, separator, JS_ATOM_Symbol_split);\n        if (JS_IsException(splitter))\n            return JS_EXCEPTION;\n        if (!JS_IsUndefined(splitter) && !JS_IsNull(splitter)) {\n            args[0] = O;\n            args[1] = limit;\n            return JS_CallFree(ctx, splitter, separator, 2, args);\n        }\n    }\n    S = JS_ToString(ctx, O);\n    if (JS_IsException(S))\n        goto exception;\n    A = JS_NewArray(ctx);\n    if (JS_IsException(A))\n        goto exception;\n    lengthA = 0;\n    if (JS_IsUndefined(limit)) {\n        lim = 0xffffffff;\n    } else {\n        if (JS_ToUint32(ctx, &lim, limit) < 0)\n            goto exception;\n    }\n    sp = JS_VALUE_GET_STRING(S);\n    s = sp->len;\n    R = JS_ToString(ctx, separator);\n    if (JS_IsException(R))\n        goto exception;\n    rp = JS_VALUE_GET_STRING(R);\n    r = rp->len;\n    p = 0;\n    if (lim == 0)\n        goto done;\n    if (JS_IsUndefined(separator))\n        goto add_tail;\n    if (s == 0) {\n        if (r != 0)\n            goto add_tail;\n        goto done;\n    }\n    q = p;\n    for (q = p; (q += !r) <= s - r - !r; q = p = e + r) {\n        e = string_indexof(sp, rp, q);\n        if (e < 0)\n            break;\n        T = js_sub_string(ctx, sp, p, e);\n        if (JS_IsException(T))\n            goto exception;\n        if (JS_CreateDataPropertyUint32(ctx, A, lengthA++, T, 0) < 0)\n            goto exception;\n        if (lengthA == lim)\n            goto done;\n    }\nadd_tail:\n    T = js_sub_string(ctx, sp, p, s);\n    if (JS_IsException(T))\n        goto exception;\n    if (JS_CreateDataPropertyUint32(ctx, A, lengthA++, T,0 ) < 0)\n        goto exception;\ndone:\n    JS_FreeValue(ctx, S);\n    JS_FreeValue(ctx, R);\n    return A;\n\nexception:\n    JS_FreeValue(ctx, A);\n    JS_FreeValue(ctx, S);\n    JS_FreeValue(ctx, R);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_substring(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    JSValue str, ret;\n    int a, b, start, end;\n    JSString *p;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return str;\n    p = JS_VALUE_GET_STRING(str);\n    if (JS_ToInt32Clamp(ctx, &a, argv[0], 0, p->len, 0)) {\n        JS_FreeValue(ctx, str);\n        return JS_EXCEPTION;\n    }\n    b = p->len;\n    if (!JS_IsUndefined(argv[1])) {\n        if (JS_ToInt32Clamp(ctx, &b, argv[1], 0, p->len, 0)) {\n            JS_FreeValue(ctx, str);\n            return JS_EXCEPTION;\n        }\n    }\n    if (a < b) {\n        start = a;\n        end = b;\n    } else {\n        start = b;\n        end = a;\n    }\n    ret = js_sub_string(ctx, p, start, end);\n    JS_FreeValue(ctx, str);\n    return ret;\n}\n\nstatic JSValue js_string_substr(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue str, ret;\n    int a, len, n;\n    JSString *p;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return str;\n    p = JS_VALUE_GET_STRING(str);\n    len = p->len;\n    if (JS_ToInt32Clamp(ctx, &a, argv[0], 0, len, len)) {\n        JS_FreeValue(ctx, str);\n        return JS_EXCEPTION;\n    }\n    n = len - a;\n    if (!JS_IsUndefined(argv[1])) {\n        if (JS_ToInt32Clamp(ctx, &n, argv[1], 0, len - a, 0)) {\n            JS_FreeValue(ctx, str);\n            return JS_EXCEPTION;\n        }\n    }\n    ret = js_sub_string(ctx, p, a, a + n);\n    JS_FreeValue(ctx, str);\n    return ret;\n}\n\nstatic JSValue js_string_slice(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    JSValue str, ret;\n    int len, start, end;\n    JSString *p;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return str;\n    p = JS_VALUE_GET_STRING(str);\n    len = p->len;\n    if (JS_ToInt32Clamp(ctx, &start, argv[0], 0, len, len)) {\n        JS_FreeValue(ctx, str);\n        return JS_EXCEPTION;\n    }\n    end = len;\n    if (!JS_IsUndefined(argv[1])) {\n        if (JS_ToInt32Clamp(ctx, &end, argv[1], 0, len, len)) {\n            JS_FreeValue(ctx, str);\n            return JS_EXCEPTION;\n        }\n    }\n    ret = js_sub_string(ctx, p, start, max_int(end, start));\n    JS_FreeValue(ctx, str);\n    return ret;\n}\n\nstatic JSValue js_string_pad(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv, int padEnd)\n{\n    JSValue str, v = JS_UNDEFINED;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p, *p1 = NULL;\n    int n, len, c = ' ';\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        goto fail1;\n    if (JS_ToInt32Sat(ctx, &n, argv[0]))\n        goto fail2;\n    p = JS_VALUE_GET_STRING(str);\n    len = p->len;\n    if (len >= n)\n        return str;\n    if (n > JS_STRING_LEN_MAX) {\n        JS_ThrowInternalError(ctx, \"string too long\");\n        goto fail2;\n    }\n    if (argc > 1 && !JS_IsUndefined(argv[1])) {\n        v = JS_ToString(ctx, argv[1]);\n        if (JS_IsException(v))\n            goto fail2;\n        p1 = JS_VALUE_GET_STRING(v);\n        if (p1->len == 0) {\n            JS_FreeValue(ctx, v);\n            return str;\n        }\n        if (p1->len == 1) {\n            c = string_get(p1, 0);\n            p1 = NULL;\n        }\n    }\n    if (string_buffer_init(ctx, b, n))\n        goto fail3;\n    n -= len;\n    if (padEnd) {\n        if (string_buffer_concat(b, p, 0, len))\n            goto fail;\n    }\n    if (p1) {\n        while (n > 0) {\n            int chunk = min_int(n, p1->len);\n            if (string_buffer_concat(b, p1, 0, chunk))\n                goto fail;\n            n -= chunk;\n        }\n    } else {\n        if (string_buffer_fill(b, c, n))\n            goto fail;\n    }\n    if (!padEnd) {\n        if (string_buffer_concat(b, p, 0, len))\n            goto fail;\n    }\n    JS_FreeValue(ctx, v);\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n\nfail:\n    string_buffer_free(b);\nfail3:\n    JS_FreeValue(ctx, v);\nfail2:\n    JS_FreeValue(ctx, str);\nfail1:\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_repeat(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue str;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p;\n    int64_t val;\n    int n, len;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        goto fail;\n    if (JS_ToInt64Sat(ctx, &val, argv[0]))\n        goto fail;\n    if (val < 0 || val > 2147483647) {\n        JS_ThrowRangeError(ctx, \"invalid repeat count\");\n        goto fail;\n    }\n    n = val;\n    p = JS_VALUE_GET_STRING(str);\n    len = p->len;\n    if (len == 0 || n == 1)\n        return str;\n    if (val * len > JS_STRING_LEN_MAX) {\n        JS_ThrowInternalError(ctx, \"string too long\");\n        goto fail;\n    }\n    if (string_buffer_init2(ctx, b, n * len, p->is_wide_char))\n        goto fail;\n    if (len == 1) {\n        string_buffer_fill(b, string_get(p, 0), n);\n    } else {\n        while (n-- > 0) {\n            string_buffer_concat(b, p, 0, len);\n        }\n    }\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n\nfail:\n    JS_FreeValue(ctx, str);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_trim(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int magic)\n{\n    JSValue str, ret;\n    int a, b, len;\n    JSString *p;\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return str;\n    p = JS_VALUE_GET_STRING(str);\n    a = 0;\n    b = len = p->len;\n    if (magic & 1) {\n        while (a < len && lre_is_space(string_get(p, a)))\n            a++;\n    }\n    if (magic & 2) {\n        while (b > a && lre_is_space(string_get(p, b - 1)))\n            b--;\n    }\n    ret = js_sub_string(ctx, p, a, b);\n    JS_FreeValue(ctx, str);\n    return ret;\n}\n\nstatic JSValue js_string___quote(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    return JS_ToQuotedString(ctx, this_val);\n}\n\n/* return 0 if before the first char */\nstatic int string_prevc(JSString *p, int *pidx)\n{\n    int idx, c, c1;\n\n    idx = *pidx;\n    if (idx <= 0)\n        return 0;\n    idx--;\n    if (p->is_wide_char) {\n        c = p->u.str16[idx];\n        if (c >= 0xdc00 && c < 0xe000 && idx > 0) {\n            c1 = p->u.str16[idx - 1];\n            if (c1 >= 0xd800 && c1 <= 0xdc00) {\n                c = (((c1 & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000;\n                idx--;\n            }\n        }\n    } else {\n        c = p->u.str8[idx];\n    }\n    *pidx = idx;\n    return c;\n}\n\nstatic BOOL test_final_sigma(JSString *p, int sigma_pos)\n{\n    int k, c1;\n\n    /* before C: skip case ignorable chars and check there is\n       a cased letter */\n    k = sigma_pos;\n    for(;;) {\n        c1 = string_prevc(p, &k);\n        if (!lre_is_case_ignorable(c1))\n            break;\n    }\n    if (!lre_is_cased(c1))\n        return FALSE;\n\n    /* after C: skip case ignorable chars and check there is\n       no cased letter */\n    k = sigma_pos + 1;\n    for(;;) {\n        if (k >= p->len)\n            return TRUE;\n        c1 = string_getc(p, &k);\n        if (!lre_is_case_ignorable(c1))\n            break;\n    }\n    return !lre_is_cased(c1);\n}\n\nstatic JSValue js_string_localeCompare(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValue a, b;\n    int cmp;\n\n    a = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(a))\n        return JS_EXCEPTION;\n    b = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(b)) {\n        JS_FreeValue(ctx, a);\n        return JS_EXCEPTION;\n    }\n    cmp = js_string_compare(ctx, JS_VALUE_GET_STRING(a), JS_VALUE_GET_STRING(b));\n    JS_FreeValue(ctx, a);\n    JS_FreeValue(ctx, b);\n    return JS_NewInt32(ctx, cmp);\n}\n\nstatic JSValue js_string_toLowerCase(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv, int to_lower)\n{\n    JSValue val;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p;\n    int i, c, j, l;\n    uint32_t res[LRE_CC_RES_LEN_MAX];\n\n    val = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_STRING(val);\n    if (p->len == 0)\n        return val;\n    if (string_buffer_init(ctx, b, p->len))\n        goto fail;\n    for(i = 0; i < p->len;) {\n        c = string_getc(p, &i);\n        if (c == 0x3a3 && to_lower && test_final_sigma(p, i - 1)) {\n            res[0] = 0x3c2; /* final sigma */\n            l = 1;\n        } else {\n            l = lre_case_conv(res, c, to_lower);\n        }\n        for(j = 0; j < l; j++) {\n            if (string_buffer_putc(b, res[j]))\n                goto fail;\n        }\n    }\n    JS_FreeValue(ctx, val);\n    return string_buffer_end(b);\n fail:\n    JS_FreeValue(ctx, val);\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\n#ifdef CONFIG_ALL_UNICODE\n\n/* return (-1, NULL) if exception, otherwise (len, buf) */\nstatic int JS_ToUTF32String(JSContext *ctx, uint32_t **pbuf, JSValueConst val1)\n{\n    JSValue val;\n    JSString *p;\n    uint32_t *buf;\n    int i, j, len;\n\n    val = JS_ToString(ctx, val1);\n    if (JS_IsException(val))\n        return -1;\n    p = JS_VALUE_GET_STRING(val);\n    len = p->len;\n    /* UTF32 buffer length is len minus the number of correct surrogates pairs */\n    buf = js_malloc(ctx, sizeof(buf[0]) * max_int(len, 1));\n    if (!buf) {\n        JS_FreeValue(ctx, val);\n        goto fail;\n    }\n    for(i = j = 0; i < len;)\n        buf[j++] = string_getc(p, &i);\n    JS_FreeValue(ctx, val);\n    *pbuf = buf;\n    return j;\n fail:\n    *pbuf = NULL;\n    return -1;\n}\n\nstatic JSValue JS_NewUTF32String(JSContext *ctx, const uint32_t *buf, int len)\n{\n    int i;\n    StringBuffer b_s, *b = &b_s;\n    if (string_buffer_init(ctx, b, len))\n        return JS_EXCEPTION;\n    for(i = 0; i < len; i++) {\n        if (string_buffer_putc(b, buf[i]))\n            goto fail;\n    }\n    return string_buffer_end(b);\n fail:\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_string_normalize(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    const char *form, *p;\n    size_t form_len;\n    int is_compat, buf_len, out_len;\n    UnicodeNormalizationEnum n_type;\n    JSValue val;\n    uint32_t *buf, *out_buf;\n\n    val = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    buf_len = JS_ToUTF32String(ctx, &buf, val);\n    JS_FreeValue(ctx, val);\n    if (buf_len < 0)\n        return JS_EXCEPTION;\n\n    if (argc == 0 || JS_IsUndefined(argv[0])) {\n        n_type = UNICODE_NFC;\n    } else {\n        form = JS_ToCStringLen(ctx, &form_len, argv[0]);\n        if (!form)\n            goto fail1;\n        p = form;\n        if (p[0] != 'N' || p[1] != 'F')\n            goto bad_form;\n        p += 2;\n        is_compat = FALSE;\n        if (*p == 'K') {\n            is_compat = TRUE;\n            p++;\n        }\n        if (*p == 'C' || *p == 'D') {\n            n_type = UNICODE_NFC + is_compat * 2 + (*p - 'C');\n            if ((p + 1 - form) != form_len)\n                goto bad_form;\n        } else {\n        bad_form:\n            JS_FreeCString(ctx, form);\n            JS_ThrowRangeError(ctx, \"bad normalization form\");\n        fail1:\n            js_free(ctx, buf);\n            return JS_EXCEPTION;\n        }\n        JS_FreeCString(ctx, form);\n    }\n\n    out_len = unicode_normalize(&out_buf, buf, buf_len, n_type,\n                                ctx->rt, (DynBufReallocFunc *)js_realloc_rt);\n    js_free(ctx, buf);\n    if (out_len < 0)\n        return JS_EXCEPTION;\n    val = JS_NewUTF32String(ctx, out_buf, out_len);\n    js_free(ctx, out_buf);\n    return val;\n}\n#endif /* CONFIG_ALL_UNICODE */\n\n/* also used for String.prototype.valueOf */\nstatic JSValue js_string_toString(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    return js_thisStringValue(ctx, this_val);\n}\n\n#if 0\nstatic JSValue js_string___toStringCheckObject(JSContext *ctx, JSValueConst this_val,\n                                               int argc, JSValueConst *argv)\n{\n    return JS_ToStringCheckObject(ctx, argv[0]);\n}\n\nstatic JSValue js_string___toString(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    return JS_ToString(ctx, argv[0]);\n}\n\nstatic JSValue js_string___advanceStringIndex(JSContext *ctx, JSValueConst\n                                              this_val,\n                                              int argc, JSValueConst *argv)\n{\n    JSValue str;\n    int idx;\n    BOOL is_unicode;\n    JSString *p;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        return str;\n    if (JS_ToInt32Sat(ctx, &idx, argv[1])) {\n        JS_FreeValue(ctx, str);\n        return JS_EXCEPTION;\n    }\n    is_unicode = JS_ToBool(ctx, argv[2]);\n    p = JS_VALUE_GET_STRING(str);\n    if (!is_unicode || (unsigned)idx >= p->len || !p->is_wide_char) {\n        idx++;\n    } else {\n        string_getc(p, &idx);\n    }\n    JS_FreeValue(ctx, str);\n    return JS_NewInt32(ctx, idx);\n}\n#endif\n\n/* String Iterator */\n\nstatic JSValue js_string_iterator_next(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv,\n                                       BOOL *pdone, int magic)\n{\n    JSArrayIteratorData *it;\n    uint32_t idx, c, start;\n    JSString *p;\n\n    it = JS_GetOpaque2(ctx, this_val, JS_CLASS_STRING_ITERATOR);\n    if (!it) {\n        *pdone = FALSE;\n        return JS_EXCEPTION;\n    }\n    if (JS_IsUndefined(it->obj))\n        goto done;\n    p = JS_VALUE_GET_STRING(it->obj);\n    idx = it->idx;\n    if (idx >= p->len) {\n        JS_FreeValue(ctx, it->obj);\n        it->obj = JS_UNDEFINED;\n    done:\n        *pdone = TRUE;\n        return JS_UNDEFINED;\n    }\n\n    start = idx;\n    c = string_getc(p, (int *)&idx);\n    it->idx = idx;\n    *pdone = FALSE;\n    if (c <= 0xffff) {\n        return js_new_string_char(ctx, c);\n    } else {\n        return js_new_string16(ctx, p->u.str16 + start, 2);\n    }\n}\n\n/* ES6 Annex B 2.3.2 etc. */\nenum {\n    magic_string_anchor,\n    magic_string_big,\n    magic_string_blink,\n    magic_string_bold,\n    magic_string_fixed,\n    magic_string_fontcolor,\n    magic_string_fontsize,\n    magic_string_italics,\n    magic_string_link,\n    magic_string_small,\n    magic_string_strike,\n    magic_string_sub,\n    magic_string_sup,\n};\n\nstatic JSValue js_string_CreateHTML(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv, int magic)\n{\n    JSValue str;\n    const JSString *p;\n    StringBuffer b_s, *b = &b_s;\n    static struct { const char *tag, *attr; } const defs[] = {\n        { \"a\", \"name\" }, { \"big\", NULL }, { \"blink\", NULL }, { \"b\", NULL },\n        { \"tt\", NULL }, { \"font\", \"color\" }, { \"font\", \"size\" }, { \"i\", NULL },\n        { \"a\", \"href\" }, { \"small\", NULL }, { \"strike\", NULL }, \n        { \"sub\", NULL }, { \"sup\", NULL },\n    };\n\n    str = JS_ToStringCheckObject(ctx, this_val);\n    if (JS_IsException(str))\n        return JS_EXCEPTION;\n    string_buffer_init(ctx, b, 7);\n    string_buffer_putc8(b, '<');\n    string_buffer_puts8(b, defs[magic].tag);\n    if (defs[magic].attr) {\n        // r += \" \" + attr + \"=\\\"\" + value + \"\\\"\";\n        JSValue value;\n        int i;\n\n        string_buffer_putc8(b, ' ');\n        string_buffer_puts8(b, defs[magic].attr);\n        string_buffer_puts8(b, \"=\\\"\");\n        value = JS_ToStringCheckObject(ctx, argv[0]);\n        if (JS_IsException(value)) {\n            JS_FreeValue(ctx, str);\n            string_buffer_free(b);\n            return JS_EXCEPTION;\n        }\n        p = JS_VALUE_GET_STRING(value);\n        for (i = 0; i < p->len; i++) {\n            int c = string_get(p, i);\n            if (c == '\"') {\n                string_buffer_puts8(b, \"&quot;\");\n            } else {\n                string_buffer_putc16(b, c);\n            }\n        }\n        JS_FreeValue(ctx, value);\n        string_buffer_putc8(b, '\\\"');\n    }\n    // return r + \">\" + str + \"</\" + tag + \">\";\n    string_buffer_putc8(b, '>');\n    string_buffer_concat_value_free(b, str);\n    string_buffer_puts8(b, \"</\");\n    string_buffer_puts8(b, defs[magic].tag);\n    string_buffer_putc8(b, '>');\n    return string_buffer_end(b);\n}\n\nstatic const JSCFunctionListEntry js_string_funcs[] = {\n    JS_CFUNC_DEF(\"fromCharCode\", 1, js_string_fromCharCode ),\n    JS_CFUNC_DEF(\"fromCodePoint\", 1, js_string_fromCodePoint ),\n    JS_CFUNC_DEF(\"raw\", 1, js_string_raw ),\n    //JS_CFUNC_DEF(\"__toString\", 1, js_string___toString ),\n    //JS_CFUNC_DEF(\"__isSpace\", 1, js_string___isSpace ),\n    //JS_CFUNC_DEF(\"__toStringCheckObject\", 1, js_string___toStringCheckObject ),\n    //JS_CFUNC_DEF(\"__advanceStringIndex\", 3, js_string___advanceStringIndex ),\n    //JS_CFUNC_DEF(\"__GetSubstitution\", 6, js_string___GetSubstitution ),\n};\n\nstatic const JSCFunctionListEntry js_string_proto_funcs[] = {\n    JS_PROP_INT32_DEF(\"length\", 0, JS_PROP_CONFIGURABLE ),\n    JS_CFUNC_DEF(\"charCodeAt\", 1, js_string_charCodeAt ),\n    JS_CFUNC_DEF(\"charAt\", 1, js_string_charAt ),\n    JS_CFUNC_DEF(\"concat\", 1, js_string_concat ),\n    JS_CFUNC_DEF(\"codePointAt\", 1, js_string_codePointAt ),\n    JS_CFUNC_MAGIC_DEF(\"indexOf\", 1, js_string_indexOf, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"lastIndexOf\", 1, js_string_indexOf, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"includes\", 1, js_string_includes, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"endsWith\", 1, js_string_includes, 2 ),\n    JS_CFUNC_MAGIC_DEF(\"startsWith\", 1, js_string_includes, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"match\", 1, js_string_match, JS_ATOM_Symbol_match ),\n    JS_CFUNC_MAGIC_DEF(\"matchAll\", 1, js_string_match, JS_ATOM_Symbol_matchAll ),\n    JS_CFUNC_MAGIC_DEF(\"search\", 1, js_string_match, JS_ATOM_Symbol_search ),\n    JS_CFUNC_DEF(\"split\", 2, js_string_split ),\n    JS_CFUNC_DEF(\"substring\", 2, js_string_substring ),\n    JS_CFUNC_DEF(\"substr\", 2, js_string_substr ),\n    JS_CFUNC_DEF(\"slice\", 2, js_string_slice ),\n    JS_CFUNC_DEF(\"repeat\", 1, js_string_repeat ),\n    JS_CFUNC_MAGIC_DEF(\"replace\", 2, js_string_replace, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"replaceAll\", 2, js_string_replace, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"padEnd\", 1, js_string_pad, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"padStart\", 1, js_string_pad, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"trim\", 0, js_string_trim, 3 ),\n    JS_CFUNC_MAGIC_DEF(\"trimEnd\", 0, js_string_trim, 2 ),\n    JS_ALIAS_DEF(\"trimRight\", \"trimEnd\" ),\n    JS_CFUNC_MAGIC_DEF(\"trimStart\", 0, js_string_trim, 1 ),\n    JS_ALIAS_DEF(\"trimLeft\", \"trimStart\" ),\n    JS_CFUNC_DEF(\"toString\", 0, js_string_toString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_string_toString ),\n    JS_CFUNC_DEF(\"__quote\", 1, js_string___quote ),\n    JS_CFUNC_DEF(\"localeCompare\", 1, js_string_localeCompare ),\n    JS_CFUNC_MAGIC_DEF(\"toLowerCase\", 0, js_string_toLowerCase, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"toUpperCase\", 0, js_string_toLowerCase, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleLowerCase\", 0, js_string_toLowerCase, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleUpperCase\", 0, js_string_toLowerCase, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"[Symbol.iterator]\", 0, js_create_array_iterator, JS_ITERATOR_KIND_VALUE | 4 ),\n    /* ES6 Annex B 2.3.2 etc. */\n    JS_CFUNC_MAGIC_DEF(\"anchor\", 1, js_string_CreateHTML, magic_string_anchor ),\n    JS_CFUNC_MAGIC_DEF(\"big\", 0, js_string_CreateHTML, magic_string_big ),\n    JS_CFUNC_MAGIC_DEF(\"blink\", 0, js_string_CreateHTML, magic_string_blink ),\n    JS_CFUNC_MAGIC_DEF(\"bold\", 0, js_string_CreateHTML, magic_string_bold ),\n    JS_CFUNC_MAGIC_DEF(\"fixed\", 0, js_string_CreateHTML, magic_string_fixed ),\n    JS_CFUNC_MAGIC_DEF(\"fontcolor\", 1, js_string_CreateHTML, magic_string_fontcolor ),\n    JS_CFUNC_MAGIC_DEF(\"fontsize\", 1, js_string_CreateHTML, magic_string_fontsize ),\n    JS_CFUNC_MAGIC_DEF(\"italics\", 0, js_string_CreateHTML, magic_string_italics ),\n    JS_CFUNC_MAGIC_DEF(\"link\", 1, js_string_CreateHTML, magic_string_link ),\n    JS_CFUNC_MAGIC_DEF(\"small\", 0, js_string_CreateHTML, magic_string_small ),\n    JS_CFUNC_MAGIC_DEF(\"strike\", 0, js_string_CreateHTML, magic_string_strike ),\n    JS_CFUNC_MAGIC_DEF(\"sub\", 0, js_string_CreateHTML, magic_string_sub ),\n    JS_CFUNC_MAGIC_DEF(\"sup\", 0, js_string_CreateHTML, magic_string_sup ),\n};\n\nstatic const JSCFunctionListEntry js_string_iterator_proto_funcs[] = {\n    JS_ITERATOR_NEXT_DEF(\"next\", 0, js_string_iterator_next, 0 ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"String Iterator\", JS_PROP_CONFIGURABLE ),\n};\n\n#ifdef CONFIG_ALL_UNICODE\nstatic const JSCFunctionListEntry js_string_proto_normalize[] = {\n    JS_CFUNC_DEF(\"normalize\", 0, js_string_normalize ),\n};\n#endif\n\nvoid JS_AddIntrinsicStringNormalize(JSContext *ctx)\n{\n#ifdef CONFIG_ALL_UNICODE\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_STRING], js_string_proto_normalize,\n                               countof(js_string_proto_normalize));\n#endif\n}\n\n/* Math */\n\n/* precondition: a and b are not NaN */\nstatic double js_fmin(double a, double b)\n{\n    if (a == 0 && b == 0) {\n        JSFloat64Union a1, b1;\n        a1.d = a;\n        b1.d = b;\n        a1.u64 |= b1.u64;\n        return a1.d;\n    } else {\n        return fmin(a, b);\n    }\n}\n\n/* precondition: a and b are not NaN */\nstatic double js_fmax(double a, double b)\n{\n    if (a == 0 && b == 0) {\n        JSFloat64Union a1, b1;\n        a1.d = a;\n        b1.d = b;\n        a1.u64 &= b1.u64;\n        return a1.d;\n    } else {\n        return fmax(a, b);\n    }\n}\n\nstatic JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv, int magic)\n{\n    BOOL is_max = magic;\n    double r, a;\n    int i;\n    uint32_t tag;\n\n    if (unlikely(argc == 0)) {\n        return __JS_NewFloat64(ctx, is_max ? -1.0 / 0.0 : 1.0 / 0.0);\n    }\n\n    tag = JS_VALUE_GET_TAG(argv[0]);\n    if (tag == JS_TAG_INT) {\n        int a1, r1 = JS_VALUE_GET_INT(argv[0]);\n        for(i = 1; i < argc; i++) {\n            tag = JS_VALUE_GET_TAG(argv[i]);\n            if (tag != JS_TAG_INT) {\n                r = r1;\n                goto generic_case;\n            }\n            a1 = JS_VALUE_GET_INT(argv[i]);\n            if (is_max)\n                r1 = max_int(r1, a1);\n            else\n                r1 = min_int(r1, a1);\n\n        }\n        return JS_NewInt32(ctx, r1);\n    } else {\n        if (JS_ToFloat64(ctx, &r, argv[0]))\n            return JS_EXCEPTION;\n        i = 1;\n    generic_case:\n        while (i < argc) {\n            if (JS_ToFloat64(ctx, &a, argv[i]))\n                return JS_EXCEPTION;\n            if (!isnan(r)) {\n                if (isnan(a)) {\n                    r = a;\n                } else {\n                    if (is_max)\n                        r = js_fmax(r, a);\n                    else\n                        r = js_fmin(r, a);\n                }\n            }\n            i++;\n        }\n        return JS_NewFloat64(ctx, r);\n    }\n}\n\nstatic double js_math_sign(double a)\n{\n    if (isnan(a) || a == 0.0)\n        return a;\n    if (a < 0)\n        return -1;\n    else\n        return 1;\n}\n\nstatic double js_math_round(double a)\n{\n    JSFloat64Union u;\n    uint64_t frac_mask, one;\n    unsigned int e, s;\n\n    u.d = a;\n    e = (u.u64 >> 52) & 0x7ff;\n    if (e < 1023) {\n        /* abs(a) < 1 */\n        if (e == (1023 - 1) && u.u64 != 0xbfe0000000000000) {\n            /* abs(a) > 0.5 or a = 0.5: return +/-1.0 */\n            u.u64 = (u.u64 & ((uint64_t)1 << 63)) | ((uint64_t)1023 << 52);\n        } else {\n            /* return +/-0.0 */\n            u.u64 &= (uint64_t)1 << 63;\n        }\n    } else if (e < (1023 + 52)) {\n        s = u.u64 >> 63;\n        one = (uint64_t)1 << (52 - (e - 1023));\n        frac_mask = one - 1;\n        u.u64 += (one >> 1) - s;\n        u.u64 &= ~frac_mask; /* truncate to an integer */\n    }\n    /* otherwise: abs(a) >= 2^52, or NaN, +/-Infinity: no change */\n    return u.d;\n}\n\nstatic JSValue js_math_hypot(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    double r, a;\n    int i;\n\n    r = 0;\n    if (argc > 0) {\n        if (JS_ToFloat64(ctx, &r, argv[0]))\n            return JS_EXCEPTION;\n        if (argc == 1) {\n            r = fabs(r);\n        } else {\n            /* use the built-in function to minimize precision loss */\n            for (i = 1; i < argc; i++) {\n                if (JS_ToFloat64(ctx, &a, argv[i]))\n                    return JS_EXCEPTION;\n                r = hypot(r, a);\n            }\n        }\n    }\n    return JS_NewFloat64(ctx, r);\n}\n\nstatic double js_math_fround(double a)\n{\n    return (float)a;\n}\n\nstatic JSValue js_math_imul(JSContext *ctx, JSValueConst this_val,\n                            int argc, JSValueConst *argv)\n{\n    int a, b;\n\n    if (JS_ToInt32(ctx, &a, argv[0]))\n        return JS_EXCEPTION;\n    if (JS_ToInt32(ctx, &b, argv[1]))\n        return JS_EXCEPTION;\n    /* purposely ignoring overflow */\n    return JS_NewInt32(ctx, a * b);\n}\n\nstatic JSValue js_math_clz32(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    uint32_t a, r;\n\n    if (JS_ToUint32(ctx, &a, argv[0]))\n        return JS_EXCEPTION;\n    if (a == 0)\n        r = 32;\n    else\n        r = clz32(a);\n    return JS_NewInt32(ctx, r);\n}\n\n/* xorshift* random number generator by Marsaglia */\nstatic uint64_t xorshift64star(uint64_t *pstate)\n{\n    uint64_t x;\n    x = *pstate;\n    x ^= x >> 12;\n    x ^= x << 25;\n    x ^= x >> 27;\n    *pstate = x;\n    return x * 0x2545F4914F6CDD1D;\n}\n\nstatic void js_random_init(JSContext *ctx)\n{\n    struct timeval tv;\n    gettimeofday(&tv, NULL);\n    ctx->random_state = ((int64_t)tv.tv_sec * 1000000) + tv.tv_usec;\n    /* the state must be non zero */\n    if (ctx->random_state == 0)\n        ctx->random_state = 1;\n}\n\nstatic JSValue js_math_random(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    JSFloat64Union u;\n    uint64_t v;\n\n    v = xorshift64star(&ctx->random_state);\n    /* 1.0 <= u.d < 2 */\n    u.u64 = ((uint64_t)0x3ff << 52) | (v >> 12);\n    return __JS_NewFloat64(ctx, u.d - 1.0);\n}\n\nstatic const JSCFunctionListEntry js_math_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"min\", 2, js_math_min_max, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"max\", 2, js_math_min_max, 1 ),\n    JS_CFUNC_SPECIAL_DEF(\"abs\", 1, f_f, fabs ),\n    JS_CFUNC_SPECIAL_DEF(\"floor\", 1, f_f, floor ),\n    JS_CFUNC_SPECIAL_DEF(\"ceil\", 1, f_f, ceil ),\n    JS_CFUNC_SPECIAL_DEF(\"round\", 1, f_f, js_math_round ),\n    JS_CFUNC_SPECIAL_DEF(\"sqrt\", 1, f_f, sqrt ),\n\n    JS_CFUNC_SPECIAL_DEF(\"acos\", 1, f_f, acos ),\n    JS_CFUNC_SPECIAL_DEF(\"asin\", 1, f_f, asin ),\n    JS_CFUNC_SPECIAL_DEF(\"atan\", 1, f_f, atan ),\n    JS_CFUNC_SPECIAL_DEF(\"atan2\", 2, f_f_f, atan2 ),\n    JS_CFUNC_SPECIAL_DEF(\"cos\", 1, f_f, cos ),\n    JS_CFUNC_SPECIAL_DEF(\"exp\", 1, f_f, exp ),\n    JS_CFUNC_SPECIAL_DEF(\"log\", 1, f_f, log ),\n    JS_CFUNC_SPECIAL_DEF(\"pow\", 2, f_f_f, js_pow ),\n    JS_CFUNC_SPECIAL_DEF(\"sin\", 1, f_f, sin ),\n    JS_CFUNC_SPECIAL_DEF(\"tan\", 1, f_f, tan ),\n    /* ES6 */\n    JS_CFUNC_SPECIAL_DEF(\"trunc\", 1, f_f, trunc ),\n    JS_CFUNC_SPECIAL_DEF(\"sign\", 1, f_f, js_math_sign ),\n    JS_CFUNC_SPECIAL_DEF(\"cosh\", 1, f_f, cosh ),\n    JS_CFUNC_SPECIAL_DEF(\"sinh\", 1, f_f, sinh ),\n    JS_CFUNC_SPECIAL_DEF(\"tanh\", 1, f_f, tanh ),\n    JS_CFUNC_SPECIAL_DEF(\"acosh\", 1, f_f, acosh ),\n    JS_CFUNC_SPECIAL_DEF(\"asinh\", 1, f_f, asinh ),\n    JS_CFUNC_SPECIAL_DEF(\"atanh\", 1, f_f, atanh ),\n    JS_CFUNC_SPECIAL_DEF(\"expm1\", 1, f_f, expm1 ),\n    JS_CFUNC_SPECIAL_DEF(\"log1p\", 1, f_f, log1p ),\n    JS_CFUNC_SPECIAL_DEF(\"log2\", 1, f_f, log2 ),\n    JS_CFUNC_SPECIAL_DEF(\"log10\", 1, f_f, log10 ),\n    JS_CFUNC_SPECIAL_DEF(\"cbrt\", 1, f_f, cbrt ),\n    JS_CFUNC_DEF(\"hypot\", 2, js_math_hypot ),\n    JS_CFUNC_DEF(\"random\", 0, js_math_random ),\n    JS_CFUNC_SPECIAL_DEF(\"fround\", 1, f_f, js_math_fround ),\n    JS_CFUNC_DEF(\"imul\", 2, js_math_imul ),\n    JS_CFUNC_DEF(\"clz32\", 1, js_math_clz32 ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Math\", JS_PROP_CONFIGURABLE ),\n    JS_PROP_DOUBLE_DEF(\"E\", 2.718281828459045, 0 ),\n    JS_PROP_DOUBLE_DEF(\"LN10\", 2.302585092994046, 0 ),\n    JS_PROP_DOUBLE_DEF(\"LN2\", 0.6931471805599453, 0 ),\n    JS_PROP_DOUBLE_DEF(\"LOG2E\", 1.4426950408889634, 0 ),\n    JS_PROP_DOUBLE_DEF(\"LOG10E\", 0.4342944819032518, 0 ),\n    JS_PROP_DOUBLE_DEF(\"PI\", 3.141592653589793, 0 ),\n    JS_PROP_DOUBLE_DEF(\"SQRT1_2\", 0.7071067811865476, 0 ),\n    JS_PROP_DOUBLE_DEF(\"SQRT2\", 1.4142135623730951, 0 ),\n};\n\nstatic const JSCFunctionListEntry js_math_obj[] = {\n    JS_OBJECT_DEF(\"Math\", js_math_funcs, countof(js_math_funcs), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),\n};\n\n/* Date */\n\n#if 0\n/* OS dependent: return the UTC time in ms since 1970. */\nstatic JSValue js___date_now(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    int64_t d;\n    struct timeval tv;\n    gettimeofday(&tv, NULL);\n    d = (int64_t)tv.tv_sec * 1000 + (tv.tv_usec / 1000);\n    return JS_NewInt64(ctx, d);\n}\n#endif\n\n/* OS dependent: return the UTC time in microseconds since 1970. */\nstatic JSValue js___date_clock(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    int64_t d;\n    struct timeval tv;\n    gettimeofday(&tv, NULL);\n    d = (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;\n    return JS_NewInt64(ctx, d);\n}\n\n/* OS dependent. d = argv[0] is in ms from 1970. Return the difference\n   between local time and UTC time 'd' in minutes */\nstatic int getTimezoneOffset(int64_t time) {\n#if defined(_WIN32)\n    /* XXX: TODO */\n    return 0;\n#else\n    time_t ti;\n    struct tm tm;\n\n    time /= 1000; /* convert to seconds */\n    if (sizeof(time_t) == 4) {\n        /* on 32-bit systems, we need to clamp the time value to the\n           range of `time_t`. This is better than truncating values to\n           32 bits and hopefully provides the same result as 64-bit\n           implementation of localtime_r.\n         */\n        if ((time_t)-1 < 0) {\n            if (time < INT32_MIN) {\n                time = INT32_MIN;\n            } else if (time > INT32_MAX) {\n                time = INT32_MAX;\n            }\n        } else {\n            if (time < 0) {\n                time = 0;\n            } else if (time > UINT32_MAX) {\n                time = UINT32_MAX;\n            }\n        }\n    }\n    ti = time;\n    localtime_r(&ti, &tm);\n    return -tm.tm_gmtoff / 60;\n#endif\n}\n\n#if 0\nstatic JSValue js___date_getTimezoneOffset(JSContext *ctx, JSValueConst this_val,\n                                           int argc, JSValueConst *argv)\n{\n    double dd;\n\n    if (JS_ToFloat64(ctx, &dd, argv[0]))\n        return JS_EXCEPTION;\n    if (isnan(dd))\n        return __JS_NewFloat64(ctx, dd);\n    else\n        return JS_NewInt32(ctx, getTimezoneOffset((int64_t)dd));\n}\n\nstatic JSValue js_get_prototype_from_ctor(JSContext *ctx, JSValueConst ctor,\n                                          JSValueConst def_proto)\n{\n    JSValue proto;\n    proto = JS_GetProperty(ctx, ctor, JS_ATOM_prototype);\n    if (JS_IsException(proto))\n        return proto;\n    if (!JS_IsObject(proto)) {\n        JS_FreeValue(ctx, proto);\n        proto = JS_DupValue(ctx, def_proto);\n    }\n    return proto;\n}\n\n/* create a new date object */\nstatic JSValue js___date_create(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue obj, proto;\n    proto = js_get_prototype_from_ctor(ctx, argv[0], argv[1]);\n    if (JS_IsException(proto))\n        return proto;\n    obj = JS_NewObjectProtoClass(ctx, proto, JS_CLASS_DATE);\n    JS_FreeValue(ctx, proto);\n    if (!JS_IsException(obj))\n        JS_SetObjectData(ctx, obj, JS_DupValue(ctx, argv[2]));\n    return obj;\n}\n#endif\n\n/* RegExp */\n\nstatic void js_regexp_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSRegExp *re = &p->u.regexp;\n    JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_STRING, re->bytecode));\n    JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_STRING, re->pattern));\n}\n\n/* create a string containing the RegExp bytecode */\nstatic JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern,\n                                 JSValueConst flags)\n{\n    const char *str;\n    int re_flags, mask;\n    uint8_t *re_bytecode_buf;\n    size_t i, len;\n    int re_bytecode_len;\n    JSValue ret;\n    char error_msg[64];\n\n    re_flags = 0;\n    if (!JS_IsUndefined(flags)) {\n        str = JS_ToCStringLen(ctx, &len, flags);\n        if (!str)\n            return JS_EXCEPTION;\n        /* XXX: re_flags = LRE_FLAG_OCTAL unless strict mode? */\n        for (i = 0; i < len; i++) {\n            switch(str[i]) {\n            case 'g':\n                mask = LRE_FLAG_GLOBAL;\n                break;\n            case 'i':\n                mask = LRE_FLAG_IGNORECASE;\n                break;\n            case 'm':\n                mask = LRE_FLAG_MULTILINE;\n                break;\n            case 's':\n                mask = LRE_FLAG_DOTALL;\n                break;\n            case 'u':\n                mask = LRE_FLAG_UTF16;\n                break;\n            case 'y':\n                mask = LRE_FLAG_STICKY;\n                break;\n            default:\n                goto bad_flags;\n            }\n            if ((re_flags & mask) != 0) {\n            bad_flags:\n                JS_FreeCString(ctx, str);\n                return JS_ThrowSyntaxError(ctx, \"invalid regular expression flags\");\n            }\n            re_flags |= mask;\n        }\n        JS_FreeCString(ctx, str);\n    }\n\n    str = JS_ToCStringLen2(ctx, &len, pattern, !(re_flags & LRE_FLAG_UTF16));\n    if (!str)\n        return JS_EXCEPTION;\n    re_bytecode_buf = lre_compile(&re_bytecode_len, error_msg,\n                                  sizeof(error_msg), str, len, re_flags, ctx);\n    JS_FreeCString(ctx, str);\n    if (!re_bytecode_buf) {\n        JS_ThrowSyntaxError(ctx, \"%s\", error_msg);\n        return JS_EXCEPTION;\n    }\n\n    ret = js_new_string8(ctx, re_bytecode_buf, re_bytecode_len);\n    js_free(ctx, re_bytecode_buf);\n    return ret;\n}\n\n/* create a RegExp object from a string containing the RegExp bytecode\n   and the source pattern */\nstatic JSValue js_regexp_constructor_internal(JSContext *ctx, JSValueConst ctor,\n                                              JSValue pattern, JSValue bc)\n{\n    JSValue obj;\n    JSObject *p;\n    JSRegExp *re;\n\n    /* sanity check */\n    if (JS_VALUE_GET_TAG(bc) != JS_TAG_STRING ||\n        JS_VALUE_GET_TAG(pattern) != JS_TAG_STRING) {\n        JS_ThrowTypeError(ctx, \"string expected\");\n    fail:\n        JS_FreeValue(ctx, bc);\n        JS_FreeValue(ctx, pattern);\n        return JS_EXCEPTION;\n    }\n\n    obj = js_create_from_ctor(ctx, ctor, JS_CLASS_REGEXP);\n    if (JS_IsException(obj))\n        goto fail;\n    p = JS_VALUE_GET_OBJ(obj);\n    re = &p->u.regexp;\n    re->pattern = JS_VALUE_GET_STRING(pattern);\n    re->bytecode = JS_VALUE_GET_STRING(bc);\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0),\n                           JS_PROP_WRITABLE);\n    return obj;\n}\n\nstatic JSRegExp *js_get_regexp(JSContext *ctx, JSValueConst obj, BOOL throw_error)\n{\n    if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(obj);\n        if (p->class_id == JS_CLASS_REGEXP)\n            return &p->u.regexp;\n    }\n    if (throw_error) {\n        JS_ThrowTypeErrorInvalidClass(ctx, JS_CLASS_REGEXP);\n    }\n    return NULL;\n}\n\n/* return < 0 if exception or TRUE/FALSE */\nstatic int js_is_regexp(JSContext *ctx, JSValueConst obj)\n{\n    JSValue m;\n\n    if (!JS_IsObject(obj))\n        return FALSE;\n    m = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_match);\n    if (JS_IsException(m))\n        return -1;\n    if (!JS_IsUndefined(m))\n        return JS_ToBoolFree(ctx, m);\n    return js_get_regexp(ctx, obj, FALSE) != NULL;\n}\n\nstatic JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue pattern, flags, bc, val;\n    JSValueConst pat, flags1;\n    JSRegExp *re;\n    int pat_is_regexp;\n\n    pat = argv[0];\n    flags1 = argv[1];\n    pat_is_regexp = js_is_regexp(ctx, pat);\n    if (pat_is_regexp < 0)\n        return JS_EXCEPTION;\n    if (JS_IsUndefined(new_target)) {\n        /* called as a function */\n        new_target = JS_GetActiveFunction(ctx);\n        if (pat_is_regexp && JS_IsUndefined(flags1)) {\n            JSValue ctor;\n            BOOL res;\n            ctor = JS_GetProperty(ctx, pat, JS_ATOM_constructor);\n            if (JS_IsException(ctor))\n                return ctor;\n            res = js_same_value(ctx, ctor, new_target);\n            JS_FreeValue(ctx, ctor);\n            if (res)\n                return JS_DupValue(ctx, pat);\n        }\n    }\n    re = js_get_regexp(ctx, pat, FALSE);\n    if (re) {\n        pattern = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->pattern));\n        if (JS_IsUndefined(flags1)) {\n            bc = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->bytecode));\n            goto no_compilation;\n        } else {\n            flags = JS_ToString(ctx, flags1);\n            if (JS_IsException(flags))\n                goto fail;\n        }\n    } else {\n        flags = JS_UNDEFINED;\n        if (pat_is_regexp) {\n            pattern = JS_GetProperty(ctx, pat, JS_ATOM_source);\n            if (JS_IsException(pattern))\n                goto fail;\n            if (JS_IsUndefined(flags1)) {\n                flags = JS_GetProperty(ctx, pat, JS_ATOM_flags);\n                if (JS_IsException(flags))\n                    goto fail;\n            } else {\n                flags = JS_DupValue(ctx, flags1);\n            }\n        } else {\n            pattern = JS_DupValue(ctx, pat);\n            flags = JS_DupValue(ctx, flags1);\n        }\n        if (JS_IsUndefined(pattern)) {\n            pattern = JS_AtomToString(ctx, JS_ATOM_empty_string);\n        } else {\n            val = pattern;\n            pattern = JS_ToString(ctx, val);\n            JS_FreeValue(ctx, val);\n            if (JS_IsException(pattern))\n                goto fail;\n        }\n    }\n    bc = js_compile_regexp(ctx, pattern, flags);\n    if (JS_IsException(bc))\n        goto fail;\n    JS_FreeValue(ctx, flags);\n no_compilation:\n    return js_regexp_constructor_internal(ctx, new_target, pattern, bc);\n fail:\n    JS_FreeValue(ctx, pattern);\n    JS_FreeValue(ctx, flags);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSRegExp *re1, *re;\n    JSValueConst pattern1, flags1;\n    JSValue bc, pattern;\n\n    re = js_get_regexp(ctx, this_val, TRUE);\n    if (!re)\n        return JS_EXCEPTION;\n    pattern1 = argv[0];\n    flags1 = argv[1];\n    re1 = js_get_regexp(ctx, pattern1, FALSE);\n    if (re1) {\n        if (!JS_IsUndefined(flags1))\n            return JS_ThrowTypeError(ctx, \"flags must be undefined\");\n        pattern = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re1->pattern));\n        bc = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re1->bytecode));\n    } else {\n        bc = JS_UNDEFINED;\n        if (JS_IsUndefined(pattern1))\n            pattern = JS_AtomToString(ctx, JS_ATOM_empty_string);\n        else\n            pattern = JS_ToString(ctx, pattern1);\n        if (JS_IsException(pattern))\n            goto fail;\n        bc = js_compile_regexp(ctx, pattern, flags1);\n        if (JS_IsException(bc))\n            goto fail;\n    }\n    JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, re->pattern));\n    JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, re->bytecode));\n    re->pattern = JS_VALUE_GET_STRING(pattern);\n    re->bytecode = JS_VALUE_GET_STRING(bc);\n    if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex,\n                       JS_NewInt32(ctx, 0)) < 0)\n        return JS_EXCEPTION;\n    return JS_DupValue(ctx, this_val);\n fail:\n    JS_FreeValue(ctx, pattern);\n    JS_FreeValue(ctx, bc);\n    return JS_EXCEPTION;\n}\n\n#if 0\nstatic JSValue js_regexp_get___source(JSContext *ctx, JSValueConst this_val)\n{\n    JSRegExp *re = js_get_regexp(ctx, this_val, TRUE);\n    if (!re)\n        return JS_EXCEPTION;\n    return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->pattern));\n}\n\nstatic JSValue js_regexp_get___flags(JSContext *ctx, JSValueConst this_val)\n{\n    JSRegExp *re = js_get_regexp(ctx, this_val, TRUE);\n    int flags;\n\n    if (!re)\n        return JS_EXCEPTION;\n    flags = lre_get_flags(re->bytecode->u.str8);\n    return JS_NewInt32(ctx, flags);\n}\n#endif\n\nstatic JSValue js_regexp_get_source(JSContext *ctx, JSValueConst this_val)\n{\n    JSRegExp *re;\n    JSString *p;\n    StringBuffer b_s, *b = &b_s;\n    int i, n, c, c2, bra;\n\n    if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    if (js_same_value(ctx, this_val, ctx->class_proto[JS_CLASS_REGEXP]))\n        goto empty_regex;\n\n    re = js_get_regexp(ctx, this_val, TRUE);\n    if (!re)\n        return JS_EXCEPTION;\n\n    p = re->pattern;\n\n    if (p->len == 0) {\n    empty_regex:\n        return JS_NewString(ctx, \"(?:)\");\n    }    \n    string_buffer_init2(ctx, b, p->len, p->is_wide_char);\n\n    /* Escape '/' and newline sequences as needed */\n    bra = 0;\n    for (i = 0, n = p->len; i < n;) {\n        c2 = -1;\n        switch (c = string_get(p, i++)) {\n        case '\\\\':\n            if (i < n)\n                c2 = string_get(p, i++);\n            break;\n        case ']':\n            bra = 0;\n            break;\n        case '[':\n            if (!bra) {\n                if (i < n && string_get(p, i) == ']')\n                    c2 = string_get(p, i++);\n                bra = 1;\n            }\n            break;\n        case '\\n':\n            c = '\\\\';\n            c2 = 'n';\n            break;\n        case '\\r':\n            c = '\\\\';\n            c2 = 'r';\n            break;\n        case '/':\n            if (!bra) {\n                c = '\\\\';\n                c2 = '/';\n            }\n            break;\n        }\n        string_buffer_putc16(b, c);\n        if (c2 >= 0)\n            string_buffer_putc16(b, c2);\n    }\n    return string_buffer_end(b);\n}\n\nstatic JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val, int mask)\n{\n    JSRegExp *re;\n    int flags;\n\n    if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    re = js_get_regexp(ctx, this_val, FALSE);\n    if (!re) {\n        if (js_same_value(ctx, this_val, ctx->class_proto[JS_CLASS_REGEXP]))\n            return JS_UNDEFINED;\n        else\n            return JS_ThrowTypeErrorInvalidClass(ctx, JS_CLASS_REGEXP);\n    }\n    \n    flags = lre_get_flags(re->bytecode->u.str8);\n    return JS_NewBool(ctx, (flags & mask) != 0);\n}\n\nstatic JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)\n{\n    char str[8], *p = str;\n    int res;\n\n    if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    res = JS_ToBoolFree(ctx, JS_GetProperty(ctx, this_val, JS_ATOM_global));\n    if (res < 0)\n        goto exception;\n    if (res)\n        *p++ = 'g';\n    res = JS_ToBoolFree(ctx, JS_GetPropertyStr(ctx, this_val, \"ignoreCase\"));\n    if (res < 0)\n        goto exception;\n    if (res)\n        *p++ = 'i';\n    res = JS_ToBoolFree(ctx, JS_GetPropertyStr(ctx, this_val, \"multiline\"));\n    if (res < 0)\n        goto exception;\n    if (res)\n        *p++ = 'm';\n    res = JS_ToBoolFree(ctx, JS_GetPropertyStr(ctx, this_val, \"dotAll\"));\n    if (res < 0)\n        goto exception;\n    if (res)\n        *p++ = 's';\n    res = JS_ToBoolFree(ctx, JS_GetProperty(ctx, this_val, JS_ATOM_unicode));\n    if (res < 0)\n        goto exception;\n    if (res)\n        *p++ = 'u';\n    res = JS_ToBoolFree(ctx, JS_GetPropertyStr(ctx, this_val, \"sticky\"));\n    if (res < 0)\n        goto exception;\n    if (res)\n        *p++ = 'y';\n    return JS_NewStringLen(ctx, str, p - str);\n\nexception:\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_regexp_toString(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValue pattern, flags;\n    StringBuffer b_s, *b = &b_s;\n\n    if (!JS_IsObject(this_val))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    string_buffer_init(ctx, b, 0);\n    string_buffer_putc8(b, '/');\n    pattern = JS_GetProperty(ctx, this_val, JS_ATOM_source);\n    if (string_buffer_concat_value_free(b, pattern))\n        goto fail;\n    string_buffer_putc8(b, '/');\n    flags = JS_GetProperty(ctx, this_val, JS_ATOM_flags);\n    if (string_buffer_concat_value_free(b, flags))\n        goto fail;\n    return string_buffer_end(b);\n\nfail:\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nBOOL lre_check_stack_overflow(void *opaque, size_t alloca_size)\n{\n    JSContext *ctx = opaque;\n    return js_check_stack_overflow(ctx->rt, alloca_size);\n}\n\nvoid *lre_realloc(void *opaque, void *ptr, size_t size)\n{\n    JSContext *ctx = opaque;\n    /* No JS exception is raised here */\n    return js_realloc_rt(ctx->rt, ptr, size);\n}\n\nstatic JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    JSRegExp *re = js_get_regexp(ctx, this_val, TRUE);\n    JSString *str;\n    JSValue str_val, obj, val, groups = JS_UNDEFINED;\n    uint8_t *re_bytecode;\n    int ret;\n    uint8_t **capture, *str_buf;\n    int capture_count, shift, i, re_flags;\n    int64_t last_index;\n    const char *group_name_ptr;\n\n    if (!re)\n        return JS_EXCEPTION;\n    str_val = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str_val))\n        return str_val;\n    val = JS_GetProperty(ctx, this_val, JS_ATOM_lastIndex);\n    if (JS_IsException(val) ||\n        JS_ToLengthFree(ctx, &last_index, val)) {\n        JS_FreeValue(ctx, str_val);\n        return JS_EXCEPTION;\n    }\n    re_bytecode = re->bytecode->u.str8;\n    re_flags = lre_get_flags(re_bytecode);\n    if ((re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) == 0) {\n        last_index = 0;\n    }\n    str = JS_VALUE_GET_STRING(str_val);\n    capture_count = lre_get_capture_count(re_bytecode);\n    capture = NULL;\n    if (capture_count > 0) {\n        capture = js_malloc(ctx, sizeof(capture[0]) * capture_count * 2);\n        if (!capture) {\n            JS_FreeValue(ctx, str_val);\n            return JS_EXCEPTION;\n        }\n    }\n    shift = str->is_wide_char;\n    str_buf = str->u.str8;\n    if (last_index > str->len) {\n        ret = 2;\n    } else {\n        ret = lre_exec(capture, re_bytecode,\n                       str_buf, last_index, str->len,\n                       shift, ctx);\n    }\n    obj = JS_NULL;\n    if (ret != 1) {\n        if (ret >= 0) {\n            if (ret == 2 || (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY))) {\n                if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex,\n                                   JS_NewInt32(ctx, 0)) < 0)\n                    goto fail;\n            }\n        } else {\n            JS_ThrowInternalError(ctx, \"out of memory in regexp execution\");\n            goto fail;\n        }\n        JS_FreeValue(ctx, str_val);\n    } else {\n        int prop_flags;\n        if (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) {\n            if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex,\n                               JS_NewInt32(ctx, (capture[1] - str_buf) >> shift)) < 0)\n                goto fail;\n        }\n        obj = JS_NewArray(ctx);\n        if (JS_IsException(obj))\n            goto fail;\n        prop_flags = JS_PROP_C_W_E | JS_PROP_THROW;\n        group_name_ptr = NULL;\n        if (re_flags & LRE_FLAG_NAMED_GROUPS) {\n            uint32_t re_bytecode_len;\n            groups = JS_NewObjectProto(ctx, JS_NULL);\n            if (JS_IsException(groups))\n                goto fail;\n            re_bytecode_len = get_u32(re_bytecode + 3);\n            group_name_ptr = (char *)(re_bytecode + 7 + re_bytecode_len);\n        }\n\n        for(i = 0; i < capture_count; i++) {\n            int start, end;\n            JSValue val;\n            if (capture[2 * i] == NULL ||\n                capture[2 * i + 1] == NULL) {\n                val = JS_UNDEFINED;\n            } else {\n                start = (capture[2 * i] - str_buf) >> shift;\n                end = (capture[2 * i + 1] - str_buf) >> shift;\n                val = js_sub_string(ctx, str, start, end);\n                if (JS_IsException(val))\n                    goto fail;\n            }\n            if (group_name_ptr && i > 0) {\n                if (*group_name_ptr) {\n                    if (JS_DefinePropertyValueStr(ctx, groups, group_name_ptr,\n                                                  JS_DupValue(ctx, val),\n                                                  prop_flags) < 0) {\n                        JS_FreeValue(ctx, val);\n                        goto fail;\n                    }\n                }\n                group_name_ptr += strlen(group_name_ptr) + 1;\n            }\n            if (JS_DefinePropertyValueUint32(ctx, obj, i, val, prop_flags) < 0)\n                goto fail;\n        }\n        if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_groups,\n                                   groups, prop_flags) < 0)\n            goto fail;\n        if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_index,\n                                   JS_NewInt32(ctx, (capture[0] - str_buf) >> shift), prop_flags) < 0)\n            goto fail;\n        if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_input, str_val, prop_flags) < 0)\n            goto fail1;\n    }\n    js_free(ctx, capture);\n    return obj;\nfail:\n    JS_FreeValue(ctx, groups);\n    JS_FreeValue(ctx, str_val);\nfail1:\n    JS_FreeValue(ctx, obj);\n    js_free(ctx, capture);\n    return JS_EXCEPTION;\n}\n\n/* delete portions of a string that match a given regex */\nstatic JSValue JS_RegExpDelete(JSContext *ctx, JSValueConst this_val, JSValueConst arg)\n{\n    JSRegExp *re = js_get_regexp(ctx, this_val, TRUE);\n    JSString *str;\n    JSValue str_val, val;\n    uint8_t *re_bytecode;\n    int ret;\n    uint8_t **capture, *str_buf;\n    int capture_count, shift, re_flags;\n    int next_src_pos, start, end;\n    int64_t last_index;\n    StringBuffer b_s, *b = &b_s;\n\n    if (!re)\n        return JS_EXCEPTION;\n\n    string_buffer_init(ctx, b, 0);\n\n    capture = NULL;\n    str_val = JS_ToString(ctx, arg);\n    if (JS_IsException(str_val))\n        goto fail;\n    str = JS_VALUE_GET_STRING(str_val);\n    re_bytecode = re->bytecode->u.str8;\n    re_flags = lre_get_flags(re_bytecode);\n    if ((re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY)) == 0) {\n        last_index = 0;\n    } else {\n        val = JS_GetProperty(ctx, this_val, JS_ATOM_lastIndex);\n        if (JS_IsException(val) || JS_ToLengthFree(ctx, &last_index, val))\n            goto fail;\n    }\n    capture_count = lre_get_capture_count(re_bytecode);\n    if (capture_count > 0) {\n        capture = js_malloc(ctx, sizeof(capture[0]) * capture_count * 2);\n        if (!capture)\n            goto fail;\n    }\n    shift = str->is_wide_char;\n    str_buf = str->u.str8;\n    next_src_pos = 0;\n    for (;;) {\n        if (last_index > str->len)\n            break;\n\n        ret = lre_exec(capture, re_bytecode,\n                       str_buf, last_index, str->len, shift, ctx);\n        if (ret != 1) {\n            if (ret >= 0) {\n                if (ret == 2 || (re_flags & (LRE_FLAG_GLOBAL | LRE_FLAG_STICKY))) {\n                    if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex,\n                                       JS_NewInt32(ctx, 0)) < 0)\n                        goto fail;\n                }\n            } else {\n                JS_ThrowInternalError(ctx, \"out of memory in regexp execution\");\n                goto fail;\n            }\n            break;\n        }\n        start = (capture[0] - str_buf) >> shift;\n        end = (capture[1] - str_buf) >> shift;\n        last_index = end;\n        if (next_src_pos < start) {\n            if (string_buffer_concat(b, str, next_src_pos, start))\n                goto fail;\n        }\n        next_src_pos = end;\n        if (!(re_flags & LRE_FLAG_GLOBAL)) {\n            if (JS_SetProperty(ctx, this_val, JS_ATOM_lastIndex,\n                               JS_NewInt32(ctx, end)) < 0)\n                goto fail;\n            break;\n        }\n        if (end == start) {\n            if (!(re_flags & LRE_FLAG_UTF16) || (unsigned)end >= str->len || !str->is_wide_char) {\n                end++;\n            } else {\n                string_getc(str, &end);\n            }\n        }\n        last_index = end;\n    }\n    if (string_buffer_concat(b, str, next_src_pos, str->len))\n        goto fail;\n    JS_FreeValue(ctx, str_val);\n    js_free(ctx, capture);\n    return string_buffer_end(b);\nfail:\n    JS_FreeValue(ctx, str_val);\n    js_free(ctx, capture);\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue JS_RegExpExec(JSContext *ctx, JSValueConst r, JSValueConst s)\n{\n    JSValue method, ret;\n\n    method = JS_GetProperty(ctx, r, JS_ATOM_exec);\n    if (JS_IsException(method))\n        return method;\n    if (JS_IsFunction(ctx, method)) {\n        ret = JS_CallFree(ctx, method, r, 1, &s);\n        if (JS_IsException(ret))\n            return ret;\n        if (!JS_IsObject(ret) && !JS_IsNull(ret)) {\n            JS_FreeValue(ctx, ret);\n            return JS_ThrowTypeError(ctx, \"RegExp exec method must return an object or null\");\n        }\n        return ret;\n    }\n    JS_FreeValue(ctx, method);\n    return js_regexp_exec(ctx, r, 1, &s);\n}\n\n#if 0\nstatic JSValue js_regexp___RegExpExec(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    return JS_RegExpExec(ctx, argv[0], argv[1]);\n}\nstatic JSValue js_regexp___RegExpDelete(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    return JS_RegExpDelete(ctx, argv[0], argv[1]);\n}\n#endif\n\nstatic JSValue js_regexp_test(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    JSValue val;\n    BOOL ret;\n\n    val = JS_RegExpExec(ctx, this_val, argv[0]);\n    if (JS_IsException(val))\n        return JS_EXCEPTION;\n    ret = !JS_IsNull(val);\n    JS_FreeValue(ctx, val);\n    return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    // [Symbol.match](str)\n    JSValueConst rx = this_val;\n    JSValue A, S, result, matchStr;\n    int global, n, fullUnicode, isEmpty;\n    JSString *p;\n\n    if (!JS_IsObject(rx))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    A = JS_UNDEFINED;\n    result = JS_UNDEFINED;\n    matchStr = JS_UNDEFINED;\n    S = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(S))\n        goto exception;\n\n    global = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_global));\n    if (global < 0)\n        goto exception;\n\n    if (!global) {\n        A = JS_RegExpExec(ctx, rx, S);\n    } else {\n        fullUnicode = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_unicode));\n        if (fullUnicode < 0)\n            goto exception;\n\n        if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0)) < 0)\n            goto exception;\n        A = JS_NewArray(ctx);\n        if (JS_IsException(A))\n            goto exception;\n        n = 0;\n        for(;;) {\n            JS_FreeValue(ctx, result);\n            result = JS_RegExpExec(ctx, rx, S);\n            if (JS_IsException(result))\n                goto exception;\n            if (JS_IsNull(result))\n                break;\n            matchStr = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, result, 0));\n            if (JS_IsException(matchStr))\n                goto exception;\n            isEmpty = JS_IsEmptyString(matchStr);\n            if (JS_SetPropertyInt64(ctx, A, n++, matchStr) < 0)\n                goto exception;\n            if (isEmpty) {\n                int64_t thisIndex, nextIndex;\n                if (JS_ToLengthFree(ctx, &thisIndex,\n                                    JS_GetProperty(ctx, rx, JS_ATOM_lastIndex)) < 0)\n                    goto exception;\n                p = JS_VALUE_GET_STRING(S);\n                nextIndex = string_advance_index(p, thisIndex, fullUnicode);\n                if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt64(ctx, nextIndex)) < 0)\n                    goto exception;\n            }\n        }\n        if (n == 0) {\n            JS_FreeValue(ctx, A);\n            A = JS_NULL;\n        }\n    }\n    JS_FreeValue(ctx, result);\n    JS_FreeValue(ctx, S);\n    return A;\n\nexception:\n    JS_FreeValue(ctx, A);\n    JS_FreeValue(ctx, result);\n    JS_FreeValue(ctx, S);\n    return JS_EXCEPTION;\n}\n\ntypedef struct JSRegExpStringIteratorData {\n    JSValue iterating_regexp;\n    JSValue iterated_string;\n    BOOL global;\n    BOOL unicode;\n    BOOL done;\n} JSRegExpStringIteratorData;\n\nstatic void js_regexp_string_iterator_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSRegExpStringIteratorData *it = p->u.regexp_string_iterator_data;\n    if (it) {\n        JS_FreeValueRT(rt, it->iterating_regexp);\n        JS_FreeValueRT(rt, it->iterated_string);\n        js_free_rt(rt, it);\n    }\n}\n\nstatic void js_regexp_string_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                           JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSRegExpStringIteratorData *it = p->u.regexp_string_iterator_data;\n    if (it) {\n        JS_MarkValue(rt, it->iterating_regexp, mark_func);\n        JS_MarkValue(rt, it->iterated_string, mark_func);\n    }\n}\n\nstatic JSValue js_regexp_string_iterator_next(JSContext *ctx,\n                                              JSValueConst this_val,\n                                              int argc, JSValueConst *argv,\n                                              BOOL *pdone, int magic)\n{\n    JSRegExpStringIteratorData *it;\n    JSValueConst R, S;\n    JSValue matchStr = JS_UNDEFINED, match = JS_UNDEFINED;\n    JSString *sp;\n\n    it = JS_GetOpaque2(ctx, this_val, JS_CLASS_REGEXP_STRING_ITERATOR);\n    if (!it)\n        goto exception;\n    if (it->done) {\n        *pdone = TRUE;\n        return JS_UNDEFINED;\n    }\n    R = it->iterating_regexp;\n    S = it->iterated_string;\n    match = JS_RegExpExec(ctx, R, S);\n    if (JS_IsException(match))\n        goto exception;\n    if (JS_IsNull(match)) {\n        it->done = TRUE;\n        *pdone = TRUE;\n        return JS_UNDEFINED;\n    } else if (it->global) {\n        matchStr = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, match, 0));\n        if (JS_IsException(matchStr))\n            goto exception;\n        if (JS_IsEmptyString(matchStr)) {\n            int64_t thisIndex, nextIndex;\n            if (JS_ToLengthFree(ctx, &thisIndex,\n                                JS_GetProperty(ctx, R, JS_ATOM_lastIndex)) < 0)\n                goto exception;\n            sp = JS_VALUE_GET_STRING(S);\n            nextIndex = string_advance_index(sp, thisIndex, it->unicode);\n            if (JS_SetProperty(ctx, R, JS_ATOM_lastIndex,\n                               JS_NewInt64(ctx, nextIndex)) < 0)\n                goto exception;\n        }\n        JS_FreeValue(ctx, matchStr);\n    } else {\n        it->done = TRUE;\n    }\n    *pdone = FALSE;\n    return match;\n exception:\n    JS_FreeValue(ctx, match);\n    JS_FreeValue(ctx, matchStr);\n    *pdone = FALSE;\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    // [Symbol.matchAll](str)\n    JSValueConst R = this_val;\n    JSValue S, C, flags, matcher, iter;\n    JSValueConst args[2];\n    JSString *strp;\n    int64_t lastIndex;\n    JSRegExpStringIteratorData *it;\n    \n    if (!JS_IsObject(R))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    C = JS_UNDEFINED;\n    flags = JS_UNDEFINED;\n    matcher = JS_UNDEFINED;\n    iter = JS_UNDEFINED;\n    \n    S = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(S))\n        goto exception;\n    C = JS_SpeciesConstructor(ctx, R, ctx->regexp_ctor);\n    if (JS_IsException(C))\n        goto exception;\n    flags = JS_ToStringFree(ctx, JS_GetProperty(ctx, R, JS_ATOM_flags));\n    if (JS_IsException(flags))\n        goto exception;\n    args[0] = R;\n    args[1] = flags;\n    matcher = JS_CallConstructor(ctx, C, 2, args);\n    if (JS_IsException(matcher))\n        goto exception;\n    if (JS_ToLengthFree(ctx, &lastIndex,\n                        JS_GetProperty(ctx, R, JS_ATOM_lastIndex)))\n        goto exception;\n    if (JS_SetProperty(ctx, matcher, JS_ATOM_lastIndex,\n                       JS_NewInt64(ctx, lastIndex)) < 0)\n        goto exception;\n    \n    iter = JS_NewObjectClass(ctx, JS_CLASS_REGEXP_STRING_ITERATOR);\n    if (JS_IsException(iter))\n        goto exception;\n    it = js_malloc(ctx, sizeof(*it));\n    if (!it)\n        goto exception;\n    it->iterating_regexp = matcher;\n    it->iterated_string = S;\n    strp = JS_VALUE_GET_STRING(flags);\n    it->global = string_indexof_char(strp, 'g', 0) >= 0;\n    it->unicode = string_indexof_char(strp, 'u', 0) >= 0;\n    it->done = FALSE;\n    JS_SetOpaque(iter, it);\n\n    JS_FreeValue(ctx, C);\n    JS_FreeValue(ctx, flags);\n    return iter;\n exception:\n    JS_FreeValue(ctx, S);\n    JS_FreeValue(ctx, C);\n    JS_FreeValue(ctx, flags);\n    JS_FreeValue(ctx, matcher);\n    JS_FreeValue(ctx, iter);\n    return JS_EXCEPTION;\n}\n\ntypedef struct ValueBuffer {\n    JSContext *ctx;\n    JSValue *arr;\n    JSValue def[4];\n    int len;\n    int size;\n    int error_status;\n} ValueBuffer;\n\nstatic int value_buffer_init(JSContext *ctx, ValueBuffer *b)\n{\n    b->ctx = ctx;\n    b->len = 0;\n    b->size = 4;\n    b->error_status = 0;\n    b->arr = b->def;\n    return 0;\n}\n\nstatic void value_buffer_free(ValueBuffer *b)\n{\n    while (b->len > 0)\n        JS_FreeValue(b->ctx, b->arr[--b->len]);\n    if (b->arr != b->def)\n        js_free(b->ctx, b->arr);\n    b->arr = b->def;\n    b->size = 4;\n}\n\nstatic int value_buffer_append(ValueBuffer *b, JSValue val)\n{\n    if (b->error_status)\n        return -1;\n\n    if (b->len >= b->size) {\n        int new_size = (b->len + (b->len >> 1) + 31) & ~16;\n        size_t slack;\n        JSValue *new_arr;\n\n        if (b->arr == b->def) {\n            new_arr = js_realloc2(b->ctx, NULL, sizeof(*b->arr) * new_size, &slack);\n            if (new_arr)\n                memcpy(new_arr, b->def, sizeof b->def);\n        } else {\n            new_arr = js_realloc2(b->ctx, b->arr, sizeof(*b->arr) * new_size, &slack);\n        }\n        if (!new_arr) {\n            value_buffer_free(b);\n            JS_FreeValue(b->ctx, val);\n            b->error_status = -1;\n            return -1;\n        }\n        new_size += slack / sizeof(*new_arr);\n        b->arr = new_arr;\n        b->size = new_size;\n    }\n    b->arr[b->len++] = val;\n    return 0;\n}\n\nstatic int js_is_standard_regexp(JSContext *ctx, JSValueConst rx)\n{\n    JSValue val;\n    int res;\n\n    val = JS_GetProperty(ctx, rx, JS_ATOM_constructor);\n    if (JS_IsException(val))\n        return -1;\n    // rx.constructor === RegExp\n    res = js_same_value(ctx, val, ctx->regexp_ctor);\n    JS_FreeValue(ctx, val);\n    if (res) {\n        val = JS_GetProperty(ctx, rx, JS_ATOM_exec);\n        if (JS_IsException(val))\n            return -1;\n        // rx.exec === RE_exec\n        res = JS_IsCFunction(ctx, val, js_regexp_exec, 0);\n        JS_FreeValue(ctx, val);\n    }\n    return res;\n}\n\nstatic JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    // [Symbol.replace](str, rep)\n    JSValueConst rx = this_val, rep = argv[1];\n    JSValueConst args[6];\n    JSValue str, rep_val, matched, tab, rep_str, namedCaptures, res;\n    JSString *sp, *rp;\n    StringBuffer b_s, *b = &b_s;\n    ValueBuffer v_b, *results = &v_b;\n    int nextSourcePosition, n, j, functionalReplace, is_global, fullUnicode;\n    uint32_t nCaptures;\n    int64_t position;\n\n    if (!JS_IsObject(rx))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    string_buffer_init(ctx, b, 0);\n    value_buffer_init(ctx, results);\n\n    rep_val = JS_UNDEFINED;\n    matched = JS_UNDEFINED;\n    tab = JS_UNDEFINED;\n    rep_str = JS_UNDEFINED;\n    namedCaptures = JS_UNDEFINED;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        goto exception;\n        \n    sp = JS_VALUE_GET_STRING(str);\n    rp = NULL;\n    functionalReplace = JS_IsFunction(ctx, rep);\n    if (!functionalReplace) {\n        rep_val = JS_ToString(ctx, rep);\n        if (JS_IsException(rep_val))\n            goto exception;\n        rp = JS_VALUE_GET_STRING(rep_val);\n    }\n    fullUnicode = 0;\n    is_global = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_global));\n    if (is_global < 0)\n        goto exception;\n    if (is_global) {\n        fullUnicode = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_unicode));\n        if (fullUnicode < 0)\n            goto exception;\n        if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0)) < 0)\n            goto exception;\n    }\n\n    if (rp && rp->len == 0 && is_global && js_is_standard_regexp(ctx, rx)) {\n        /* use faster version for simple cases */\n        res = JS_RegExpDelete(ctx, rx, str);\n        goto done;\n    }\n    for(;;) {\n        JSValue result;\n        result = JS_RegExpExec(ctx, rx, str);\n        if (JS_IsException(result))\n            goto exception;\n        if (JS_IsNull(result))\n            break;\n        if (value_buffer_append(results, result) < 0)\n            goto exception;\n        if (!is_global)\n            break;\n        JS_FreeValue(ctx, matched);\n        matched = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, result, 0));\n        if (JS_IsException(matched))\n            goto exception;\n        if (JS_IsEmptyString(matched)) {\n            /* always advance of at least one char */\n            int64_t thisIndex, nextIndex;\n            if (JS_ToLengthFree(ctx, &thisIndex, JS_GetProperty(ctx, rx, JS_ATOM_lastIndex)) < 0)\n                goto exception;\n            nextIndex = string_advance_index(sp, thisIndex, fullUnicode);\n            if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt64(ctx, nextIndex)) < 0)\n                goto exception;\n        }\n    }\n    nextSourcePosition = 0;\n    for(j = 0; j < results->len; j++) {\n        JSValueConst result;\n        result = results->arr[j];\n        if (js_get_length32(ctx, &nCaptures, result) < 0)\n            goto exception;\n        JS_FreeValue(ctx, matched);\n        matched = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, result, 0));\n        if (JS_IsException(matched))\n            goto exception;\n        if (JS_ToLengthFree(ctx, &position, JS_GetProperty(ctx, result, JS_ATOM_index)))\n            goto exception;\n        if (position > sp->len)\n            position = sp->len;\n        else if (position < 0)\n            position = 0;\n        /* ignore substition if going backward (can happen\n           with custom regexp object) */\n        JS_FreeValue(ctx, tab);\n        tab = JS_NewArray(ctx);\n        if (JS_IsException(tab))\n            goto exception;\n        if (JS_SetPropertyInt64(ctx, tab, 0, JS_DupValue(ctx, matched)) < 0)\n            goto exception;\n        for(n = 1; n < nCaptures; n++) {\n            JSValue capN;\n            capN = JS_GetPropertyInt64(ctx, result, n);\n            if (JS_IsException(capN))\n                goto exception;\n            if (!JS_IsUndefined(capN)) {\n                capN = JS_ToStringFree(ctx, capN);\n                if (JS_IsException(capN))\n                    goto exception;\n            }\n            if (JS_SetPropertyInt64(ctx, tab, n, capN) < 0)\n                goto exception;\n        }\n        JS_FreeValue(ctx, namedCaptures);\n        namedCaptures = JS_GetProperty(ctx, result, JS_ATOM_groups);\n        if (JS_IsException(namedCaptures))\n            goto exception;\n        if (functionalReplace) {\n            if (JS_SetPropertyInt64(ctx, tab, n++, JS_NewInt32(ctx, position)) < 0)\n                goto exception;\n            if (JS_SetPropertyInt64(ctx, tab, n++, JS_DupValue(ctx, str)) < 0)\n                goto exception;\n            if (!JS_IsUndefined(namedCaptures)) {\n                if (JS_SetPropertyInt64(ctx, tab, n++, JS_DupValue(ctx, namedCaptures)) < 0)\n                    goto exception;\n            }\n            args[0] = JS_UNDEFINED;\n            args[1] = tab;\n            JS_FreeValue(ctx, rep_str);\n            rep_str = JS_ToStringFree(ctx, js_function_apply(ctx, rep, 2, args, 0));\n        } else {\n            JSValue namedCaptures1;\n            if (!JS_IsUndefined(namedCaptures)) {\n                namedCaptures1 = JS_ToObject(ctx, namedCaptures);\n                if (JS_IsException(namedCaptures1))\n                    goto exception;\n            } else {\n                namedCaptures1 = JS_UNDEFINED;\n            }\n            args[0] = matched;\n            args[1] = str;\n            args[2] = JS_NewInt32(ctx, position);\n            args[3] = tab;\n            args[4] = namedCaptures1;\n            args[5] = rep_val;\n            JS_FreeValue(ctx, rep_str);\n            rep_str = js_string___GetSubstitution(ctx, JS_UNDEFINED, 6, args);\n            JS_FreeValue(ctx, namedCaptures1);\n        }\n        if (JS_IsException(rep_str))\n            goto exception;\n        if (position >= nextSourcePosition) {\n            string_buffer_concat(b, sp, nextSourcePosition, position);\n            string_buffer_concat_value(b, rep_str);\n            nextSourcePosition = position + JS_VALUE_GET_STRING(matched)->len;\n        }\n    }\n    string_buffer_concat(b, sp, nextSourcePosition, sp->len);\n    res = string_buffer_end(b);\n    goto done1;\n\nexception:\n    res = JS_EXCEPTION;\ndone:\n    string_buffer_free(b);\ndone1:\n    value_buffer_free(results);\n    JS_FreeValue(ctx, rep_val);\n    JS_FreeValue(ctx, matched);\n    JS_FreeValue(ctx, tab);\n    JS_FreeValue(ctx, rep_str);\n    JS_FreeValue(ctx, namedCaptures);\n    JS_FreeValue(ctx, str);\n    return res;\n}\n\nstatic JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValueConst rx = this_val;\n    JSValue str, previousLastIndex, currentLastIndex, result, index;\n\n    if (!JS_IsObject(rx))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    result = JS_UNDEFINED;\n    currentLastIndex = JS_UNDEFINED;\n    previousLastIndex = JS_UNDEFINED;\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        goto exception;\n\n    previousLastIndex = JS_GetProperty(ctx, rx, JS_ATOM_lastIndex);\n    if (JS_IsException(previousLastIndex))\n        goto exception;\n\n    if (!js_same_value(ctx, previousLastIndex, JS_NewInt32(ctx, 0))) {\n        if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, JS_NewInt32(ctx, 0)) < 0) {\n            goto exception;\n        }\n    }\n    result = JS_RegExpExec(ctx, rx, str);\n    if (JS_IsException(result))\n        goto exception;\n    currentLastIndex = JS_GetProperty(ctx, rx, JS_ATOM_lastIndex);\n    if (JS_IsException(currentLastIndex))\n        goto exception;\n    if (js_same_value(ctx, currentLastIndex, previousLastIndex)) {\n        JS_FreeValue(ctx, previousLastIndex);\n    } else {\n        if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, previousLastIndex) < 0)\n            goto exception;\n    }\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, currentLastIndex);\n\n    if (JS_IsNull(result)) {\n        return JS_NewInt32(ctx, -1);\n    } else {\n        index = JS_GetProperty(ctx, result, JS_ATOM_index);\n        JS_FreeValue(ctx, result);\n        return index;\n    }\n\nexception:\n    JS_FreeValue(ctx, result);\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, currentLastIndex);\n    JS_FreeValue(ctx, previousLastIndex);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_regexp_Symbol_split(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    // [Symbol.split](str, limit)\n    JSValueConst rx = this_val;\n    JSValueConst args[2];\n    JSValue str, ctor, splitter, A, flags, z, sub;\n    JSString *strp;\n    uint32_t lim, size, p, q;\n    int unicodeMatching;\n    int64_t lengthA, e, numberOfCaptures, i;\n\n    if (!JS_IsObject(rx))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    ctor = JS_UNDEFINED;\n    splitter = JS_UNDEFINED;\n    A = JS_UNDEFINED;\n    flags = JS_UNDEFINED;\n    z = JS_UNDEFINED;\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        goto exception;\n    ctor = JS_SpeciesConstructor(ctx, rx, ctx->regexp_ctor);\n    if (JS_IsException(ctor))\n        goto exception;\n    flags = JS_ToStringFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_flags));\n    if (JS_IsException(flags))\n        goto exception;\n    strp = JS_VALUE_GET_STRING(flags);\n    unicodeMatching = string_indexof_char(strp, 'u', 0) >= 0;\n    if (string_indexof_char(strp, 'y', 0) < 0) {\n        flags = JS_ConcatString3(ctx, \"\", flags, \"y\");\n        if (JS_IsException(flags))\n            goto exception;\n    }\n    args[0] = rx;\n    args[1] = flags;\n    splitter = JS_CallConstructor(ctx, ctor, 2, args);\n    if (JS_IsException(splitter))\n        goto exception;\n    A = JS_NewArray(ctx);\n    if (JS_IsException(A))\n        goto exception;\n    lengthA = 0;\n    if (JS_IsUndefined(argv[1])) {\n        lim = 0xffffffff;\n    } else {\n        if (JS_ToUint32(ctx, &lim, argv[1]) < 0)\n            goto exception;\n        if (lim == 0)\n            goto done;\n    }\n    strp = JS_VALUE_GET_STRING(str);\n    p = q = 0;\n    size = strp->len;\n    if (size == 0) {\n        z = JS_RegExpExec(ctx, splitter, str);\n        if (JS_IsException(z))\n            goto exception;\n        if (JS_IsNull(z))\n            goto add_tail;\n        goto done;\n    }\n    while (q < size) {\n        if (JS_SetProperty(ctx, splitter, JS_ATOM_lastIndex, JS_NewInt32(ctx, q)) < 0)\n            goto exception;\n        JS_FreeValue(ctx, z);    \n        z = JS_RegExpExec(ctx, splitter, str);\n        if (JS_IsException(z))\n            goto exception;\n        if (JS_IsNull(z)) {\n            q = string_advance_index(strp, q, unicodeMatching);\n        } else {\n            if (JS_ToLengthFree(ctx, &e, JS_GetProperty(ctx, splitter, JS_ATOM_lastIndex)))\n                goto exception;\n            if (e > size)\n                e = size;\n            if (e == p) {\n                q = string_advance_index(strp, q, unicodeMatching);\n            } else {\n                sub = js_sub_string(ctx, strp, p, q);\n                if (JS_IsException(sub))\n                    goto exception;\n                if (JS_SetPropertyInt64(ctx, A, lengthA++, sub) < 0)\n                    goto exception;\n                if (lengthA == lim)\n                    goto done;\n                p = e;\n                if (js_get_length64(ctx, &numberOfCaptures, z))\n                    goto exception;\n                for(i = 1; i < numberOfCaptures; i++) {\n                    sub = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, z, i));\n                    if (JS_IsException(sub))\n                        goto exception;\n                    if (JS_SetPropertyInt64(ctx, A, lengthA++, sub) < 0)\n                        goto exception;\n                    if (lengthA == lim)\n                        goto done;\n                }\n                q = p;\n            }\n        }\n    }\nadd_tail:\n    if (p > size)\n        p = size;\n    sub = js_sub_string(ctx, strp, p, size);\n    if (JS_IsException(sub))\n        goto exception;\n    if (JS_SetPropertyInt64(ctx, A, lengthA++, sub) < 0)\n        goto exception;\n    goto done;\nexception:\n    JS_FreeValue(ctx, A);\n    A = JS_EXCEPTION;\ndone:\n    JS_FreeValue(ctx, str);\n    JS_FreeValue(ctx, ctor);\n    JS_FreeValue(ctx, splitter);\n    JS_FreeValue(ctx, flags);\n    JS_FreeValue(ctx, z);    \n    return A;\n}\n\nstatic const JSCFunctionListEntry js_regexp_funcs[] = {\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL ),\n    //JS_CFUNC_DEF(\"__RegExpExec\", 2, js_regexp___RegExpExec ),\n    //JS_CFUNC_DEF(\"__RegExpDelete\", 2, js_regexp___RegExpDelete ),\n};\n\nstatic const JSCFunctionListEntry js_regexp_proto_funcs[] = {\n    JS_CGETSET_DEF(\"flags\", js_regexp_get_flags, NULL ),\n    JS_CGETSET_DEF(\"source\", js_regexp_get_source, NULL ),\n    JS_CGETSET_MAGIC_DEF(\"global\", js_regexp_get_flag, NULL, 1 ),\n    JS_CGETSET_MAGIC_DEF(\"ignoreCase\", js_regexp_get_flag, NULL, 2 ),\n    JS_CGETSET_MAGIC_DEF(\"multiline\", js_regexp_get_flag, NULL, 4 ),\n    JS_CGETSET_MAGIC_DEF(\"dotAll\", js_regexp_get_flag, NULL, 8 ),\n    JS_CGETSET_MAGIC_DEF(\"unicode\", js_regexp_get_flag, NULL, 16 ),\n    JS_CGETSET_MAGIC_DEF(\"sticky\", js_regexp_get_flag, NULL, 32 ),\n    JS_CFUNC_DEF(\"exec\", 1, js_regexp_exec ),\n    JS_CFUNC_DEF(\"compile\", 2, js_regexp_compile ),\n    JS_CFUNC_DEF(\"test\", 1, js_regexp_test ),\n    JS_CFUNC_DEF(\"toString\", 0, js_regexp_toString ),\n    JS_CFUNC_DEF(\"[Symbol.replace]\", 2, js_regexp_Symbol_replace ),\n    JS_CFUNC_DEF(\"[Symbol.match]\", 1, js_regexp_Symbol_match ),\n    JS_CFUNC_DEF(\"[Symbol.matchAll]\", 1, js_regexp_Symbol_matchAll ),\n    JS_CFUNC_DEF(\"[Symbol.search]\", 1, js_regexp_Symbol_search ),\n    JS_CFUNC_DEF(\"[Symbol.split]\", 2, js_regexp_Symbol_split ),\n    //JS_CGETSET_DEF(\"__source\", js_regexp_get___source, NULL ),\n    //JS_CGETSET_DEF(\"__flags\", js_regexp_get___flags, NULL ),\n};\n\nstatic const JSCFunctionListEntry js_regexp_string_iterator_proto_funcs[] = {\n    JS_ITERATOR_NEXT_DEF(\"next\", 0, js_regexp_string_iterator_next, 0 ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"RegExp String Iterator\", JS_PROP_CONFIGURABLE ),\n};\n\nvoid JS_AddIntrinsicRegExpCompiler(JSContext *ctx)\n{\n    ctx->compile_regexp = js_compile_regexp;\n}\n\nvoid JS_AddIntrinsicRegExp(JSContext *ctx)\n{\n    JSValueConst obj;\n\n    JS_AddIntrinsicRegExpCompiler(ctx);\n\n    ctx->class_proto[JS_CLASS_REGEXP] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_REGEXP], js_regexp_proto_funcs,\n                               countof(js_regexp_proto_funcs));\n    obj = JS_NewGlobalCConstructor(ctx, \"RegExp\", js_regexp_constructor, 2,\n                                   ctx->class_proto[JS_CLASS_REGEXP]);\n    ctx->regexp_ctor = JS_DupValue(ctx, obj);\n    JS_SetPropertyFunctionList(ctx, obj, js_regexp_funcs, countof(js_regexp_funcs));\n\n    ctx->class_proto[JS_CLASS_REGEXP_STRING_ITERATOR] =\n        JS_NewObjectProto(ctx, ctx->iterator_proto);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_REGEXP_STRING_ITERATOR],\n                               js_regexp_string_iterator_proto_funcs,\n                               countof(js_regexp_string_iterator_proto_funcs));\n}\n\n/* JSON */\n\nstatic int json_parse_expect(JSParseState *s, int tok)\n{\n    if (s->token.val != tok) {\n        /* XXX: dump token correctly in all cases */\n        return js_parse_error(s, \"expecting '%c'\", tok);\n    }\n    return json_next_token(s);\n}\n\nstatic JSValue json_parse_value(JSParseState *s)\n{\n    JSContext *ctx = s->ctx;\n    JSValue val = JS_NULL;\n    int ret;\n\n    switch(s->token.val) {\n    case '{':\n        {\n            JSValue prop_val;\n            JSAtom prop_name;\n            \n            if (json_next_token(s))\n                goto fail;\n            val = JS_NewObject(ctx);\n            if (JS_IsException(val))\n                goto fail;\n            if (s->token.val != '}') {\n                for(;;) {\n                    if (s->token.val == TOK_STRING) {\n                        prop_name = JS_ValueToAtom(ctx, s->token.u.str.str);\n                        if (prop_name == JS_ATOM_NULL)\n                            goto fail;\n                    } else if (s->ext_json && s->token.val == TOK_IDENT) {\n                        prop_name = JS_DupAtom(ctx, s->token.u.ident.atom);\n                    } else {\n                        js_parse_error(s, \"expecting property name\");\n                        goto fail;\n                    }\n                    if (json_next_token(s))\n                        goto fail1;\n                    if (json_parse_expect(s, ':'))\n                        goto fail1;\n                    prop_val = json_parse_value(s);\n                    if (JS_IsException(prop_val)) {\n                    fail1:\n                        JS_FreeAtom(ctx, prop_name);\n                        goto fail;\n                    }\n                    ret = JS_DefinePropertyValue(ctx, val, prop_name,\n                                                 prop_val, JS_PROP_C_W_E);\n                    JS_FreeAtom(ctx, prop_name);\n                    if (ret < 0)\n                        goto fail;\n\n                    if (s->token.val != ',')\n                        break;\n                    if (json_next_token(s))\n                        goto fail;\n                    if (s->ext_json && s->token.val == '}')\n                        break;\n                }\n            }\n            if (json_parse_expect(s, '}'))\n                goto fail;\n        }\n        break;\n    case '[':\n        {\n            JSValue el;\n            uint32_t idx;\n\n            if (json_next_token(s))\n                goto fail;\n            val = JS_NewArray(ctx);\n            if (JS_IsException(val))\n                goto fail;\n            if (s->token.val != ']') {\n                idx = 0;\n                for(;;) {\n                    el = json_parse_value(s);\n                    if (JS_IsException(el))\n                        goto fail;\n                    ret = JS_DefinePropertyValueUint32(ctx, val, idx, el, JS_PROP_C_W_E);\n                    if (ret < 0)\n                        goto fail;\n                    if (s->token.val != ',')\n                        break;\n                    if (json_next_token(s))\n                        goto fail;\n                    idx++;\n                    if (s->ext_json && s->token.val == ']')\n                        break;\n                }\n            }\n            if (json_parse_expect(s, ']'))\n                goto fail;\n        }\n        break;\n    case TOK_STRING:\n        val = JS_DupValue(ctx, s->token.u.str.str);\n        if (json_next_token(s))\n            goto fail;\n        break;\n    case TOK_NUMBER:\n        val = s->token.u.num.val;\n        if (json_next_token(s))\n            goto fail;\n        break;\n    case TOK_IDENT:\n        if (s->token.u.ident.atom == JS_ATOM_false ||\n            s->token.u.ident.atom == JS_ATOM_true) {\n            val = JS_NewBool(ctx, (s->token.u.ident.atom == JS_ATOM_true));\n        } else if (s->token.u.ident.atom == JS_ATOM_null) {\n            val = JS_NULL;\n        } else {\n            goto def_token;\n        }\n        if (json_next_token(s))\n            goto fail;\n        break;\n    default:\n    def_token:\n        if (s->token.val == TOK_EOF) {\n            js_parse_error(s, \"unexpected end of input\");\n        } else {\n            js_parse_error(s, \"unexpected token: '%.*s'\",\n                           (int)(s->buf_ptr - s->token.ptr), s->token.ptr);\n        }\n        goto fail;\n    }\n    return val;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nJSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,\n                      const char *filename, int flags)\n{\n    JSParseState s1, *s = &s1;\n    JSValue val = JS_UNDEFINED;\n\n    js_parse_init(ctx, s, buf, buf_len, filename);\n    s->ext_json = ((flags & JS_PARSE_JSON_EXT) != 0);\n    if (json_next_token(s))\n        goto fail;\n    val = json_parse_value(s);\n    if (JS_IsException(val))\n        goto fail;\n    if (s->token.val != TOK_EOF) {\n        if (js_parse_error(s, \"unexpected data at the end\"))\n            goto fail;\n    }\n    return val;\n fail:\n    JS_FreeValue(ctx, val);\n    free_token(s, &s->token);\n    return JS_EXCEPTION;\n}\n\nJSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,\n                     const char *filename)\n{\n    return JS_ParseJSON2(ctx, buf, buf_len, filename, 0); \n}\n\nstatic JSValue internalize_json_property(JSContext *ctx, JSValueConst holder,\n                                         JSAtom name, JSValueConst reviver)\n{\n    JSValue val, new_el, name_val, res;\n    JSValueConst args[2];\n    int ret, is_array;\n    uint32_t i, len = 0;\n    JSAtom prop;\n    JSPropertyEnum *atoms = NULL;\n\n    if (js_check_stack_overflow(ctx->rt, 0)) {\n        return JS_ThrowStackOverflow(ctx);\n    }\n\n    val = JS_GetProperty(ctx, holder, name);\n    if (JS_IsException(val))\n        return val;\n    if (JS_IsObject(val)) {\n        is_array = JS_IsArray(ctx, val);\n        if (is_array < 0)\n            goto fail;\n        if (is_array) {\n            if (js_get_length32(ctx, &len, val))\n                goto fail;\n        } else {\n            ret = JS_GetOwnPropertyNamesInternal(ctx, &atoms, &len, JS_VALUE_GET_OBJ(val), JS_GPN_ENUM_ONLY | JS_GPN_STRING_MASK);\n            if (ret < 0)\n                goto fail;\n        }\n        for(i = 0; i < len; i++) {\n            if (is_array) {\n                prop = JS_NewAtomUInt32(ctx, i);\n                if (prop == JS_ATOM_NULL)\n                    goto fail;\n            } else {\n                prop = JS_DupAtom(ctx, atoms[i].atom);\n            }\n            new_el = internalize_json_property(ctx, val, prop, reviver);\n            if (JS_IsException(new_el)) {\n                JS_FreeAtom(ctx, prop);\n                goto fail;\n            }\n            if (JS_IsUndefined(new_el)) {\n                ret = JS_DeleteProperty(ctx, val, prop, 0);\n            } else {\n                ret = JS_DefinePropertyValue(ctx, val, prop, new_el, JS_PROP_C_W_E);\n            }\n            JS_FreeAtom(ctx, prop);\n            if (ret < 0)\n                goto fail;\n        }\n    }\n    js_free_prop_enum(ctx, atoms, len);\n    atoms = NULL;\n    name_val = JS_AtomToValue(ctx, name);\n    if (JS_IsException(name_val))\n        goto fail;\n    args[0] = name_val;\n    args[1] = val;\n    res = JS_Call(ctx, reviver, holder, 2, args);\n    JS_FreeValue(ctx, name_val);\n    JS_FreeValue(ctx, val);\n    return res;\n fail:\n    js_free_prop_enum(ctx, atoms, len);\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_json_parse(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    JSValue obj, root;\n    JSValueConst reviver;\n    const char *str;\n    size_t len;\n\n    str = JS_ToCStringLen(ctx, &len, argv[0]);\n    if (!str)\n        return JS_EXCEPTION;\n    obj = JS_ParseJSON(ctx, str, len, \"<input>\");\n    JS_FreeCString(ctx, str);\n    if (JS_IsException(obj))\n        return obj;\n    if (argc > 1 && JS_IsFunction(ctx, argv[1])) {\n        reviver = argv[1];\n        root = JS_NewObject(ctx);\n        if (JS_IsException(root)) {\n            JS_FreeValue(ctx, obj);\n            return JS_EXCEPTION;\n        }\n        if (JS_DefinePropertyValue(ctx, root, JS_ATOM_empty_string, obj,\n                                   JS_PROP_C_W_E) < 0) {\n            JS_FreeValue(ctx, root);\n            return JS_EXCEPTION;\n        }\n        obj = internalize_json_property(ctx, root, JS_ATOM_empty_string,\n                                        reviver);\n        JS_FreeValue(ctx, root);\n    }\n    return obj;\n}\n\ntypedef struct JSONStringifyContext {\n    JSValueConst replacer_func;\n    JSValue stack;\n    JSValue property_list;\n    JSValue gap;\n    JSValue empty;\n    StringBuffer *b;\n} JSONStringifyContext;\n\nstatic JSValue JS_ToQuotedStringFree(JSContext *ctx, JSValue val) {\n    JSValue r = JS_ToQuotedString(ctx, val);\n    JS_FreeValue(ctx, val);\n    return r;\n}\n\nstatic JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc,\n                             JSValueConst holder, JSValue val, JSValueConst key)\n{\n    JSValue v;\n    JSValueConst args[2];\n\n    if (JS_IsObject(val)\n#ifdef CONFIG_BIGNUM\n    ||  JS_IsBigInt(ctx, val)   /* XXX: probably useless */\n#endif\n        ) {\n            JSValue f = JS_GetProperty(ctx, val, JS_ATOM_toJSON);\n            if (JS_IsException(f))\n                goto exception;\n            if (JS_IsFunction(ctx, f)) {\n                v = JS_CallFree(ctx, f, val, 1, &key);\n                JS_FreeValue(ctx, val);\n                val = v;\n                if (JS_IsException(val))\n                    goto exception;\n            } else {\n                JS_FreeValue(ctx, f);\n            }\n        }\n\n    if (!JS_IsUndefined(jsc->replacer_func)) {\n        args[0] = key;\n        args[1] = val;\n        v = JS_Call(ctx, jsc->replacer_func, holder, 2, args);\n        JS_FreeValue(ctx, val);\n        val = v;\n        if (JS_IsException(val))\n            goto exception;\n    }\n\n    switch (JS_VALUE_GET_NORM_TAG(val)) {\n    case JS_TAG_OBJECT:\n        if (JS_IsFunction(ctx, val))\n            break;\n    case JS_TAG_STRING:\n    case JS_TAG_INT:\n    case JS_TAG_FLOAT64:\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n#endif\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n#endif\n    case JS_TAG_EXCEPTION:\n        return val;\n    default:\n        break;\n    }\n    JS_FreeValue(ctx, val);\n    return JS_UNDEFINED;\n\nexception:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,\n                          JSValueConst holder, JSValue val,\n                          JSValueConst indent)\n{\n    JSValue indent1, sep, sep1, tab, v, prop;\n    JSObject *p;\n    int64_t i, len;\n    int cl, ret;\n    BOOL has_content;\n    \n    indent1 = JS_UNDEFINED;\n    sep = JS_UNDEFINED;\n    sep1 = JS_UNDEFINED;\n    tab = JS_UNDEFINED;\n    prop = JS_UNDEFINED;\n\n    switch (JS_VALUE_GET_NORM_TAG(val)) {\n    case JS_TAG_OBJECT:\n        p = JS_VALUE_GET_OBJ(val);\n        cl = p->class_id;\n        if (cl == JS_CLASS_STRING) {\n            val = JS_ToStringFree(ctx, val);\n            if (JS_IsException(val))\n                goto exception;\n            val = JS_ToQuotedStringFree(ctx, val);\n            if (JS_IsException(val))\n                goto exception;\n            return string_buffer_concat_value_free(jsc->b, val);\n        } else if (cl == JS_CLASS_NUMBER) {\n            val = JS_ToNumberFree(ctx, val);\n            if (JS_IsException(val))\n                goto exception;\n            return string_buffer_concat_value_free(jsc->b, val);\n        } else if (cl == JS_CLASS_BOOLEAN) {\n            ret = string_buffer_concat_value(jsc->b, p->u.object_data);\n            JS_FreeValue(ctx, val);\n            return ret;\n        }\n#ifdef CONFIG_BIGNUM\n        else if (cl == JS_CLASS_BIG_FLOAT) {\n            return string_buffer_concat_value_free(jsc->b, val);\n        } else if (cl == JS_CLASS_BIG_INT) {\n            JS_ThrowTypeError(ctx, \"bigint are forbidden in JSON.stringify\");\n            goto exception;\n        }\n#endif\n        v = js_array_includes(ctx, jsc->stack, 1, (JSValueConst *)&val);\n        if (JS_IsException(v))\n            goto exception;\n        if (JS_ToBoolFree(ctx, v)) {\n            JS_ThrowTypeError(ctx, \"circular reference\");\n            goto exception;\n        }\n        indent1 = JS_ConcatString(ctx, JS_DupValue(ctx, indent), JS_DupValue(ctx, jsc->gap));\n        if (JS_IsException(indent1))\n            goto exception;\n        if (!JS_IsEmptyString(jsc->gap)) {\n            sep = JS_ConcatString3(ctx, \"\\n\", JS_DupValue(ctx, indent1), \"\");\n            if (JS_IsException(sep))\n                goto exception;\n            sep1 = JS_NewString(ctx, \" \");\n            if (JS_IsException(sep1))\n                goto exception;\n        } else {\n            sep = JS_DupValue(ctx, jsc->empty);\n            sep1 = JS_DupValue(ctx, jsc->empty);\n        }\n        v = js_array_push(ctx, jsc->stack, 1, (JSValueConst *)&val, 0);\n        if (check_exception_free(ctx, v))\n            goto exception;\n        ret = JS_IsArray(ctx, val);\n        if (ret < 0)\n            goto exception;\n        if (ret) {\n            if (js_get_length64(ctx, &len, val))\n                goto exception;\n            string_buffer_putc8(jsc->b, '[');\n            for(i = 0; i < len; i++) {\n                if (i > 0)\n                    string_buffer_putc8(jsc->b, ',');\n                string_buffer_concat_value(jsc->b, sep);\n                v = JS_GetPropertyInt64(ctx, val, i);\n                if (JS_IsException(v))\n                    goto exception;\n                /* XXX: could do this string conversion only when needed */\n                prop = JS_ToStringFree(ctx, JS_NewInt64(ctx, i));\n                if (JS_IsException(prop))\n                    goto exception;\n                v = js_json_check(ctx, jsc, val, v, prop);\n                JS_FreeValue(ctx, prop);\n                prop = JS_UNDEFINED;\n                if (JS_IsException(v))\n                    goto exception;\n                if (JS_IsUndefined(v))\n                    v = JS_NULL;\n                if (js_json_to_str(ctx, jsc, val, v, indent1))\n                    goto exception;\n            }\n            if (len > 0 && !JS_IsEmptyString(jsc->gap)) {\n                string_buffer_putc8(jsc->b, '\\n');\n                string_buffer_concat_value(jsc->b, indent);\n            }\n            string_buffer_putc8(jsc->b, ']');\n        } else {\n            if (!JS_IsUndefined(jsc->property_list))\n                tab = JS_DupValue(ctx, jsc->property_list);\n            else\n                tab = js_object_keys(ctx, JS_UNDEFINED, 1, (JSValueConst *)&val, JS_ITERATOR_KIND_KEY);\n            if (JS_IsException(tab))\n                goto exception;\n            if (js_get_length64(ctx, &len, tab))\n                goto exception;\n            string_buffer_putc8(jsc->b, '{');\n            has_content = FALSE;\n            for(i = 0; i < len; i++) {\n                JS_FreeValue(ctx, prop);\n                prop = JS_GetPropertyInt64(ctx, tab, i);\n                if (JS_IsException(prop))\n                    goto exception;\n                v = JS_GetPropertyValue(ctx, val, JS_DupValue(ctx, prop));\n                if (JS_IsException(v))\n                    goto exception;\n                v = js_json_check(ctx, jsc, val, v, prop);\n                if (JS_IsException(v))\n                    goto exception;\n                if (!JS_IsUndefined(v)) {\n                    if (has_content)\n                        string_buffer_putc8(jsc->b, ',');\n                    prop = JS_ToQuotedStringFree(ctx, prop);\n                    if (JS_IsException(prop)) {\n                        JS_FreeValue(ctx, v);\n                        goto exception;\n                    }\n                    string_buffer_concat_value(jsc->b, sep);\n                    string_buffer_concat_value(jsc->b, prop);\n                    string_buffer_putc8(jsc->b, ':');\n                    string_buffer_concat_value(jsc->b, sep1);\n                    if (js_json_to_str(ctx, jsc, val, v, indent1))\n                        goto exception;\n                    has_content = TRUE;\n                }\n            }\n            if (has_content && JS_VALUE_GET_STRING(jsc->gap)->len != 0) {\n                string_buffer_putc8(jsc->b, '\\n');\n                string_buffer_concat_value(jsc->b, indent);\n            }\n            string_buffer_putc8(jsc->b, '}');\n        }\n        if (check_exception_free(ctx, js_array_pop(ctx, jsc->stack, 0, NULL, 0)))\n            goto exception;\n        JS_FreeValue(ctx, val);\n        JS_FreeValue(ctx, tab);\n        JS_FreeValue(ctx, sep);\n        JS_FreeValue(ctx, sep1);\n        JS_FreeValue(ctx, indent1);\n        JS_FreeValue(ctx, prop);\n        return 0;\n    case JS_TAG_STRING:\n        val = JS_ToQuotedStringFree(ctx, val);\n        if (JS_IsException(val))\n            goto exception;\n        goto concat_value;\n    case JS_TAG_FLOAT64:\n        if (!isfinite(JS_VALUE_GET_FLOAT64(val))) {\n            val = JS_NULL;\n        }\n        goto concat_value;\n    case JS_TAG_INT:\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_FLOAT:\n#endif\n    case JS_TAG_BOOL:\n    case JS_TAG_NULL:\n    concat_value:\n        return string_buffer_concat_value_free(jsc->b, val);\n#ifdef CONFIG_BIGNUM\n    case JS_TAG_BIG_INT:\n        JS_ThrowTypeError(ctx, \"bigint are forbidden in JSON.stringify\");\n        goto exception;\n#endif\n    default:\n        JS_FreeValue(ctx, val);\n        return 0;\n    }\n    \nexception:\n    JS_FreeValue(ctx, val);\n    JS_FreeValue(ctx, tab);\n    JS_FreeValue(ctx, sep);\n    JS_FreeValue(ctx, sep1);\n    JS_FreeValue(ctx, indent1);\n    JS_FreeValue(ctx, prop);\n    return -1;\n}\n\nJSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,\n                         JSValueConst replacer, JSValueConst space0)\n{\n    StringBuffer b_s;\n    JSONStringifyContext jsc_s, *jsc = &jsc_s;\n    JSValue val, v, space, ret, wrapper;\n    int res;\n    int64_t i, j, n;\n\n    jsc->replacer_func = JS_UNDEFINED;\n    jsc->stack = JS_UNDEFINED;\n    jsc->property_list = JS_UNDEFINED;\n    jsc->gap = JS_UNDEFINED;\n    jsc->b = &b_s;\n    jsc->empty = JS_AtomToString(ctx, JS_ATOM_empty_string);\n    ret = JS_UNDEFINED;\n    wrapper = JS_UNDEFINED;\n\n    string_buffer_init(ctx, jsc->b, 0);\n    jsc->stack = JS_NewArray(ctx);\n    if (JS_IsException(jsc->stack))\n        goto exception;\n    if (JS_IsFunction(ctx, replacer)) {\n        jsc->replacer_func = replacer;\n    } else {\n        res = JS_IsArray(ctx, replacer);\n        if (res < 0)\n            goto exception;\n        if (res) {\n            /* XXX: enumeration is not fully correct */\n            jsc->property_list = JS_NewArray(ctx);\n            if (JS_IsException(jsc->property_list))\n                goto exception;\n            if (js_get_length64(ctx, &n, replacer))\n                goto exception;\n            for (i = j = 0; i < n; i++) {\n                JSValue present;\n                v = JS_GetPropertyInt64(ctx, replacer, i);\n                if (JS_IsException(v))\n                    goto exception;\n                if (JS_IsObject(v)) {\n                    JSObject *p = JS_VALUE_GET_OBJ(v);\n                    if (p->class_id == JS_CLASS_STRING ||\n                        p->class_id == JS_CLASS_NUMBER) {\n                        v = JS_ToStringFree(ctx, v);\n                        if (JS_IsException(v))\n                            goto exception;\n                    } else {\n                        JS_FreeValue(ctx, v);\n                        continue;\n                    }\n                } else if (JS_IsNumber(v)) {\n                    v = JS_ToStringFree(ctx, v);\n                    if (JS_IsException(v))\n                        goto exception;\n                } else if (!JS_IsString(v)) {\n                    JS_FreeValue(ctx, v);\n                    continue;\n                }\n                present = js_array_includes(ctx, jsc->property_list,\n                                            1, (JSValueConst *)&v);\n                if (JS_IsException(present)) {\n                    JS_FreeValue(ctx, v);\n                    goto exception;\n                }\n                if (!JS_ToBoolFree(ctx, present)) {\n                    JS_SetPropertyInt64(ctx, jsc->property_list, j++, v);\n                } else {\n                    JS_FreeValue(ctx, v);\n                }\n            }\n        }\n    }\n    space = JS_DupValue(ctx, space0);\n    if (JS_IsObject(space)) {\n        JSObject *p = JS_VALUE_GET_OBJ(space);\n        if (p->class_id == JS_CLASS_NUMBER) {\n            space = JS_ToNumberFree(ctx, space);\n        } else if (p->class_id == JS_CLASS_STRING) {\n            space = JS_ToStringFree(ctx, space);\n        }\n        if (JS_IsException(space)) {\n            JS_FreeValue(ctx, space);\n            goto exception;\n        }\n    }\n    if (JS_IsNumber(space)) {\n        int n;\n        if (JS_ToInt32Clamp(ctx, &n, space, 0, 10, 0))\n            goto exception;\n        jsc->gap = JS_NewStringLen(ctx, \"          \", n);\n    } else if (JS_IsString(space)) {\n        JSString *p = JS_VALUE_GET_STRING(space);\n        jsc->gap = js_sub_string(ctx, p, 0, min_int(p->len, 10));\n    } else {\n        jsc->gap = JS_DupValue(ctx, jsc->empty);\n    }\n    JS_FreeValue(ctx, space);\n    if (JS_IsException(jsc->gap))\n        goto exception;\n    wrapper = JS_NewObject(ctx);\n    if (JS_IsException(wrapper))\n        goto exception;\n    if (JS_DefinePropertyValue(ctx, wrapper, JS_ATOM_empty_string,\n                               JS_DupValue(ctx, obj), JS_PROP_C_W_E) < 0)\n        goto exception;\n    val = JS_DupValue(ctx, obj);\n                           \n    val = js_json_check(ctx, jsc, wrapper, val, jsc->empty);\n    if (JS_IsException(val))\n        goto exception;\n    if (JS_IsUndefined(val)) {\n        ret = JS_UNDEFINED;\n        goto done1;\n    }\n    if (js_json_to_str(ctx, jsc, wrapper, val, jsc->empty))\n        goto exception;\n\n    ret = string_buffer_end(jsc->b);\n    goto done;\n\nexception:\n    ret = JS_EXCEPTION;\ndone1:\n    string_buffer_free(jsc->b);\ndone:\n    JS_FreeValue(ctx, wrapper);\n    JS_FreeValue(ctx, jsc->empty);\n    JS_FreeValue(ctx, jsc->gap);\n    JS_FreeValue(ctx, jsc->property_list);\n    JS_FreeValue(ctx, jsc->stack);\n    return ret;\n}\n\nstatic JSValue js_json_stringify(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    // stringify(val, replacer, space)\n    return JS_JSONStringify(ctx, argv[0], argv[1], argv[2]);\n}\n\nstatic const JSCFunctionListEntry js_json_funcs[] = {\n    JS_CFUNC_DEF(\"parse\", 2, js_json_parse ),\n    JS_CFUNC_DEF(\"stringify\", 3, js_json_stringify ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"JSON\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_json_obj[] = {\n    JS_OBJECT_DEF(\"JSON\", js_json_funcs, countof(js_json_funcs), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),\n};\n\nvoid JS_AddIntrinsicJSON(JSContext *ctx)\n{\n    /* add JSON as autoinit object */\n    JS_SetPropertyFunctionList(ctx, ctx->global_obj, js_json_obj, countof(js_json_obj));\n}\n\n/* Reflect */\n\nstatic JSValue js_reflect_apply(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    return js_function_apply(ctx, argv[0], max_int(0, argc - 1), argv + 1, 0);\n}\n\nstatic JSValue js_reflect_construct(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValueConst func, array_arg, new_target;\n    JSValue *tab, ret;\n    uint32_t len;\n\n    func = argv[0];\n    array_arg = argv[1];\n    if (argc > 2) {\n        new_target = argv[2];\n        if (!JS_IsConstructor(ctx, new_target))\n            return JS_ThrowTypeError(ctx, \"not a constructor\");\n    } else {\n        new_target = func;\n    }\n    tab = build_arg_list(ctx, &len, array_arg);\n    if (!tab)\n        return JS_EXCEPTION;\n    ret = JS_CallConstructor2(ctx, func, new_target, len, (JSValueConst *)tab);\n    free_arg_list(ctx, tab, len);\n    return ret;\n}\n\nstatic JSValue js_reflect_deleteProperty(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    JSValueConst obj;\n    JSAtom atom;\n    int ret;\n\n    obj = argv[0];\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    atom = JS_ValueToAtom(ctx, argv[1]);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return JS_EXCEPTION;\n    ret = JS_DeleteProperty(ctx, obj, atom, 0);\n    JS_FreeAtom(ctx, atom);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_reflect_get(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    JSValueConst obj, prop, receiver;\n    JSAtom atom;\n    JSValue ret;\n\n    obj = argv[0];\n    prop = argv[1];\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    if (argc > 2)\n        receiver = argv[2];\n    else\n        receiver = obj;\n    atom = JS_ValueToAtom(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return JS_EXCEPTION;\n    ret = JS_GetPropertyInternal(ctx, obj, atom, receiver, FALSE);\n    JS_FreeAtom(ctx, atom);\n    return ret;\n}\n\nstatic JSValue js_reflect_has(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    JSValueConst obj, prop;\n    JSAtom atom;\n    int ret;\n\n    obj = argv[0];\n    prop = argv[1];\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    atom = JS_ValueToAtom(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return JS_EXCEPTION;\n    ret = JS_HasProperty(ctx, obj, atom);\n    JS_FreeAtom(ctx, atom);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_reflect_set(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    JSValueConst obj, prop, val, receiver;\n    int ret;\n    JSAtom atom;\n\n    obj = argv[0];\n    prop = argv[1];\n    val = argv[2];\n    if (argc > 3)\n        receiver = argv[3];\n    else\n        receiver = obj;\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    atom = JS_ValueToAtom(ctx, prop);\n    if (unlikely(atom == JS_ATOM_NULL))\n        return JS_EXCEPTION;\n    ret = JS_SetPropertyGeneric(ctx, JS_VALUE_GET_OBJ(obj), atom,\n                                JS_DupValue(ctx, val), receiver, 0);\n    JS_FreeAtom(ctx, atom);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    int ret;\n    ret = JS_SetPrototypeInternal(ctx, argv[0], argv[1], FALSE);\n    if (ret < 0)\n        return JS_EXCEPTION;\n    else\n        return JS_NewBool(ctx, ret);\n}\n\nstatic JSValue js_reflect_ownKeys(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    if (JS_VALUE_GET_TAG(argv[0]) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    return JS_GetOwnPropertyNames2(ctx, argv[0],\n                                   JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK,\n                                   JS_ITERATOR_KIND_KEY);\n}\n\nstatic const JSCFunctionListEntry js_reflect_funcs[] = {\n    JS_CFUNC_DEF(\"apply\", 3, js_reflect_apply ),\n    JS_CFUNC_DEF(\"construct\", 2, js_reflect_construct ),\n    JS_CFUNC_MAGIC_DEF(\"defineProperty\", 3, js_object_defineProperty, 1 ),\n    JS_CFUNC_DEF(\"deleteProperty\", 2, js_reflect_deleteProperty ),\n    JS_CFUNC_DEF(\"get\", 2, js_reflect_get ),\n    JS_CFUNC_MAGIC_DEF(\"getOwnPropertyDescriptor\", 2, js_object_getOwnPropertyDescriptor, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"getPrototypeOf\", 1, js_object_getPrototypeOf, 1 ),\n    JS_CFUNC_DEF(\"has\", 2, js_reflect_has ),\n    JS_CFUNC_MAGIC_DEF(\"isExtensible\", 1, js_object_isExtensible, 1 ),\n    JS_CFUNC_DEF(\"ownKeys\", 1, js_reflect_ownKeys ),\n    JS_CFUNC_MAGIC_DEF(\"preventExtensions\", 1, js_object_preventExtensions, 1 ),\n    JS_CFUNC_DEF(\"set\", 3, js_reflect_set ),\n    JS_CFUNC_DEF(\"setPrototypeOf\", 2, js_reflect_setPrototypeOf ),\n};\n\nstatic const JSCFunctionListEntry js_reflect_obj[] = {\n    JS_OBJECT_DEF(\"Reflect\", js_reflect_funcs, countof(js_reflect_funcs), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),\n};\n\n/* Proxy */\n\nstatic void js_proxy_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSProxyData *s = JS_GetOpaque(val, JS_CLASS_PROXY);\n    if (s) {\n        JS_FreeValueRT(rt, s->target);\n        JS_FreeValueRT(rt, s->handler);\n        js_free_rt(rt, s);\n    }\n}\n\nstatic void js_proxy_mark(JSRuntime *rt, JSValueConst val,\n                          JS_MarkFunc *mark_func)\n{\n    JSProxyData *s = JS_GetOpaque(val, JS_CLASS_PROXY);\n    if (s) {\n        JS_MarkValue(rt, s->target, mark_func);\n        JS_MarkValue(rt, s->handler, mark_func);\n    }\n}\n\nstatic JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx)\n{\n    return JS_ThrowTypeError(ctx, \"revoked proxy\");\n}\n\nstatic JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod,\n                                     JSValueConst obj, JSAtom name)\n{\n    JSProxyData *s = JS_GetOpaque(obj, JS_CLASS_PROXY);\n    JSValue method;\n\n    /* safer to test recursion in all proxy methods */\n    if (js_check_stack_overflow(ctx->rt, 0)) {\n        JS_ThrowStackOverflow(ctx);\n        return NULL;\n    }\n    \n    /* 's' should never be NULL */\n    if (s->is_revoked) {\n        JS_ThrowTypeErrorRevokedProxy(ctx);\n        return NULL;\n    }\n    method = JS_GetProperty(ctx, s->handler, name);\n    if (JS_IsException(method))\n        return NULL;\n    if (JS_IsNull(method))\n        method = JS_UNDEFINED;\n    *pmethod = method;\n    return s;\n}\n\nstatic JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj)\n{\n    JSProxyData *s;\n    JSValue method, ret, proto1;\n    int res;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_getPrototypeOf);\n    if (!s)\n        return JS_EXCEPTION;\n    if (JS_IsUndefined(method))\n        return JS_GetPrototype(ctx, s->target);\n    ret = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target);\n    if (JS_IsException(ret))\n        return ret;\n    if (JS_VALUE_GET_TAG(ret) != JS_TAG_NULL &&\n        JS_VALUE_GET_TAG(ret) != JS_TAG_OBJECT) {\n        goto fail;\n    }\n    res = JS_IsExtensible(ctx, s->target);\n    if (res < 0) {\n        JS_FreeValue(ctx, ret);\n        return JS_EXCEPTION;\n    }\n    if (!res) {\n        /* check invariant */\n        proto1 = JS_GetPrototype(ctx, s->target);\n        if (JS_IsException(proto1)) {\n            JS_FreeValue(ctx, ret);\n            return JS_EXCEPTION;\n        }\n        if (JS_VALUE_GET_OBJ(proto1) != JS_VALUE_GET_OBJ(ret)) {\n            JS_FreeValue(ctx, proto1);\n        fail:\n            JS_FreeValue(ctx, ret);\n            return JS_ThrowTypeError(ctx, \"proxy: inconsistent prototype\");\n        }\n        JS_FreeValue(ctx, proto1);\n    }\n    return ret;\n}\n\nstatic int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,\n                                   JSValueConst proto_val, BOOL throw_flag)\n{\n    JSProxyData *s;\n    JSValue method, ret, proto1;\n    JSValueConst args[2];\n    BOOL res;\n    int res2;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_setPrototypeOf);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method))\n        return JS_SetPrototypeInternal(ctx, s->target, proto_val, throw_flag);\n    args[0] = s->target;\n    args[1] = proto_val;\n    ret = JS_CallFree(ctx, method, s->handler, 2, args);\n    if (JS_IsException(ret))\n        return -1;\n    res = JS_ToBoolFree(ctx, ret);\n    if (!res) {\n        if (throw_flag) {\n            JS_ThrowTypeError(ctx, \"proxy: bad prototype\");\n            return -1;\n        } else {\n            return FALSE;\n        }\n    }\n    res2 = JS_IsExtensible(ctx, s->target);\n    if (res2 < 0)\n        return -1;\n    if (!res2) {\n        proto1 = JS_GetPrototype(ctx, s->target);\n        if (JS_IsException(proto1))\n            return -1;\n        if (JS_VALUE_GET_OBJ(proto_val) != JS_VALUE_GET_OBJ(proto1)) {\n            JS_FreeValue(ctx, proto1);\n            JS_ThrowTypeError(ctx, \"proxy: inconsistent prototype\");\n            return -1;\n        }\n        JS_FreeValue(ctx, proto1);\n    }\n    return TRUE;\n}\n\nstatic int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj)\n{\n    JSProxyData *s;\n    JSValue method, ret;\n    BOOL res;\n    int res2;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_isExtensible);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method))\n        return JS_IsExtensible(ctx, s->target);\n    ret = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target);\n    if (JS_IsException(ret))\n        return -1;\n    res = JS_ToBoolFree(ctx, ret);\n    res2 = JS_IsExtensible(ctx, s->target);\n    if (res2 < 0)\n        return res2;\n    if (res != res2) {\n        JS_ThrowTypeError(ctx, \"proxy: inconsistent isExtensible\");\n        return -1;\n    }\n    return res;\n}\n\nstatic int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj)\n{\n    JSProxyData *s;\n    JSValue method, ret;\n    BOOL res;\n    int res2;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_preventExtensions);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method))\n        return JS_PreventExtensions(ctx, s->target);\n    ret = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target);\n    if (JS_IsException(ret))\n        return -1;\n    res = JS_ToBoolFree(ctx, ret);\n    if (res) {\n        res2 = JS_IsExtensible(ctx, s->target);\n        if (res2 < 0)\n            return res2;\n        if (res2) {\n            JS_ThrowTypeError(ctx, \"proxy: inconsistent preventExtensions\");\n            return -1;\n        }\n    }\n    return res;\n}\n\nstatic int js_proxy_has(JSContext *ctx, JSValueConst obj, JSAtom atom)\n{\n    JSProxyData *s;\n    JSValue method, ret1, atom_val;\n    int ret, res;\n    JSObject *p;\n    JSValueConst args[2];\n    BOOL res2;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_has);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method))\n        return JS_HasProperty(ctx, s->target, atom);\n    atom_val = JS_AtomToValue(ctx, atom);\n    if (JS_IsException(atom_val)) {\n        JS_FreeValue(ctx, method);\n        return -1;\n    }\n    args[0] = s->target;\n    args[1] = atom_val;\n    ret1 = JS_CallFree(ctx, method, s->handler, 2, args);\n    JS_FreeValue(ctx, atom_val);\n    if (JS_IsException(ret1))\n        return -1;\n    ret = JS_ToBoolFree(ctx, ret1);\n    if (!ret) {\n        JSPropertyDescriptor desc;\n        p = JS_VALUE_GET_OBJ(s->target);\n        res = JS_GetOwnPropertyInternal(ctx, &desc, p, atom);\n        if (res < 0)\n            return -1;\n        if (res) {\n            res2 = !(desc.flags & JS_PROP_CONFIGURABLE);\n            js_free_desc(ctx, &desc);\n            if (res2 || !p->extensible) {\n                JS_ThrowTypeError(ctx, \"proxy: inconsistent has\");\n                return -1;\n            }\n        }\n    }\n    return ret;\n}\n\nstatic JSValue js_proxy_get(JSContext *ctx, JSValueConst obj, JSAtom atom,\n                            JSValueConst receiver)\n{\n    JSProxyData *s;\n    JSValue method, ret, atom_val;\n    int res;\n    JSValueConst args[3];\n    JSPropertyDescriptor desc;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_get);\n    if (!s)\n        return JS_EXCEPTION;\n    /* Note: recursion is possible thru the prototype of s->target */\n    if (JS_IsUndefined(method))\n        return JS_GetPropertyInternal(ctx, s->target, atom, receiver, FALSE);\n    atom_val = JS_AtomToValue(ctx, atom);\n    if (JS_IsException(atom_val)) {\n        JS_FreeValue(ctx, method);\n        return JS_EXCEPTION;\n    }\n    args[0] = s->target;\n    args[1] = atom_val;\n    args[2] = receiver;\n    ret = JS_CallFree(ctx, method, s->handler, 3, args);\n    JS_FreeValue(ctx, atom_val);\n    if (JS_IsException(ret))\n        return JS_EXCEPTION;\n    res = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(s->target), atom);\n    if (res < 0)\n        return JS_EXCEPTION;\n    if (res) {\n        if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)) == 0) {\n            if (!js_same_value(ctx, desc.value, ret)) {\n                goto fail;\n            }\n        } else if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE)) == JS_PROP_GETSET) {\n            if (JS_IsUndefined(desc.getter) && !JS_IsUndefined(ret)) {\n            fail:\n                js_free_desc(ctx, &desc);\n                JS_FreeValue(ctx, ret);\n                return JS_ThrowTypeError(ctx, \"proxy: inconsistent get\");\n            }\n        }\n        js_free_desc(ctx, &desc);\n    }\n    return ret;\n}\n\nstatic int js_proxy_set(JSContext *ctx, JSValueConst obj, JSAtom atom,\n                        JSValueConst value, JSValueConst receiver, int flags)\n{\n    JSProxyData *s;\n    JSValue method, ret1, atom_val;\n    int ret, res;\n    JSValueConst args[4];\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_set);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method)) {\n        return JS_SetPropertyGeneric(ctx, JS_VALUE_GET_OBJ(s->target), atom,\n                                     JS_DupValue(ctx, value), receiver,\n                                     flags);\n    }\n    atom_val = JS_AtomToValue(ctx, atom);\n    if (JS_IsException(atom_val)) {\n        JS_FreeValue(ctx, method);\n        return -1;\n    }\n    args[0] = s->target;\n    args[1] = atom_val;\n    args[2] = value;\n    args[3] = receiver;\n    ret1 = JS_CallFree(ctx, method, s->handler, 4, args);\n    JS_FreeValue(ctx, atom_val);\n    if (JS_IsException(ret1))\n        return -1;\n    ret = JS_ToBoolFree(ctx, ret1);\n    if (ret) {\n        JSPropertyDescriptor desc;\n        res = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(s->target), atom);\n        if (res < 0)\n            return -1;\n        if (res) {\n            if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)) == 0) {\n                if (!js_same_value(ctx, desc.value, value)) {\n                    goto fail;\n                }\n            } else if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE)) == JS_PROP_GETSET && JS_IsUndefined(desc.setter)) {\n                fail:\n                    js_free_desc(ctx, &desc);\n                    JS_ThrowTypeError(ctx, \"proxy: inconsistent set\");\n                    return -1;\n            }\n            js_free_desc(ctx, &desc);\n        }\n    } else {\n        if ((flags & JS_PROP_THROW) ||\n            ((flags & JS_PROP_THROW_STRICT) && is_strict_mode(ctx))) {\n            JS_ThrowTypeError(ctx, \"proxy: cannot set property\");\n            return -1;\n        }\n    }\n    return ret;\n}\n\nstatic JSValue js_create_desc(JSContext *ctx, JSValueConst val,\n                              JSValueConst getter, JSValueConst setter,\n                              int flags)\n{\n    JSValue ret;\n    ret = JS_NewObject(ctx);\n    if (JS_IsException(ret))\n        return ret;\n    if (flags & JS_PROP_HAS_GET) {\n        JS_DefinePropertyValue(ctx, ret, JS_ATOM_get, JS_DupValue(ctx, getter),\n                               JS_PROP_C_W_E);\n    }\n    if (flags & JS_PROP_HAS_SET) {\n        JS_DefinePropertyValue(ctx, ret, JS_ATOM_set, JS_DupValue(ctx, setter),\n                               JS_PROP_C_W_E);\n    }\n    if (flags & JS_PROP_HAS_VALUE) {\n        JS_DefinePropertyValue(ctx, ret, JS_ATOM_value, JS_DupValue(ctx, val),\n                               JS_PROP_C_W_E);\n    }\n    if (flags & JS_PROP_HAS_WRITABLE) {\n        JS_DefinePropertyValue(ctx, ret, JS_ATOM_writable,\n                               JS_NewBool(ctx, (flags & JS_PROP_WRITABLE) != 0),\n                               JS_PROP_C_W_E);\n    }\n    if (flags & JS_PROP_HAS_ENUMERABLE) {\n        JS_DefinePropertyValue(ctx, ret, JS_ATOM_enumerable,\n                               JS_NewBool(ctx, (flags & JS_PROP_ENUMERABLE) != 0),\n                               JS_PROP_C_W_E);\n    }\n    if (flags & JS_PROP_HAS_CONFIGURABLE) {\n        JS_DefinePropertyValue(ctx, ret, JS_ATOM_configurable,\n                               JS_NewBool(ctx, (flags & JS_PROP_CONFIGURABLE) != 0),\n                               JS_PROP_C_W_E);\n    }\n    return ret;\n}\n\nstatic int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc,\n                                     JSValueConst obj, JSAtom prop)\n{\n    JSProxyData *s;\n    JSValue method, trap_result_obj, prop_val;\n    int res, target_desc_ret, ret;\n    JSObject *p;\n    JSValueConst args[2];\n    JSPropertyDescriptor result_desc, target_desc;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_getOwnPropertyDescriptor);\n    if (!s)\n        return -1;\n    p = JS_VALUE_GET_OBJ(s->target);\n    if (JS_IsUndefined(method)) {\n        return JS_GetOwnPropertyInternal(ctx, pdesc, p, prop);\n    }\n    prop_val = JS_AtomToValue(ctx, prop);\n    if (JS_IsException(prop_val)) {\n        JS_FreeValue(ctx, method);\n        return -1;\n    }\n    args[0] = s->target;\n    args[1] = prop_val;\n    trap_result_obj = JS_CallFree(ctx, method, s->handler, 2, args);\n    JS_FreeValue(ctx, prop_val);\n    if (JS_IsException(trap_result_obj))\n        return -1;\n    if (!JS_IsObject(trap_result_obj) && !JS_IsUndefined(trap_result_obj)) {\n        JS_FreeValue(ctx, trap_result_obj);\n        goto fail;\n    }\n    target_desc_ret = JS_GetOwnPropertyInternal(ctx, &target_desc, p, prop);\n    if (target_desc_ret < 0) {\n        JS_FreeValue(ctx, trap_result_obj);\n        return -1;\n    }\n    if (target_desc_ret)\n        js_free_desc(ctx, &target_desc);\n    if (JS_IsUndefined(trap_result_obj)) {\n        if (target_desc_ret) {\n            if (!(target_desc.flags & JS_PROP_CONFIGURABLE) || !p->extensible)\n                goto fail;\n        }\n        ret = FALSE;\n    } else {\n        int flags1, extensible_target;\n        extensible_target = JS_IsExtensible(ctx, s->target);\n        if (extensible_target < 0) {\n            JS_FreeValue(ctx, trap_result_obj);\n            return -1;\n        }\n        res = js_obj_to_desc(ctx, &result_desc, trap_result_obj);\n        JS_FreeValue(ctx, trap_result_obj);\n        if (res < 0)\n            return -1;\n        \n        if (target_desc_ret) {\n            /* convert result_desc.flags to defineProperty flags */\n            flags1 = result_desc.flags | JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_ENUMERABLE;\n            if (result_desc.flags & JS_PROP_GETSET)\n                flags1 |= JS_PROP_HAS_GET | JS_PROP_HAS_SET;\n            else\n                flags1 |= JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE;\n            /* XXX: not complete check: need to compare value &\n               getter/setter as in defineproperty */\n            if (!check_define_prop_flags(target_desc.flags, flags1))\n                goto fail1;\n        } else {\n            if (!extensible_target)\n                goto fail1;\n        }\n        if (!(result_desc.flags & JS_PROP_CONFIGURABLE)) {\n            if (!target_desc_ret || (target_desc.flags & JS_PROP_CONFIGURABLE))\n                goto fail1;\n            if ((result_desc.flags &\n                 (JS_PROP_GETSET | JS_PROP_WRITABLE)) == 0 &&\n                target_desc_ret &&\n                (target_desc.flags & JS_PROP_WRITABLE) != 0) {\n                /* proxy-missing-checks */\n            fail1:\n                js_free_desc(ctx, &result_desc);\n            fail:\n                JS_ThrowTypeError(ctx, \"proxy: inconsistent getOwnPropertyDescriptor\");\n                return -1;\n            }\n        }\n        ret = TRUE;\n        if (pdesc) {\n            *pdesc = result_desc;\n        } else {\n            js_free_desc(ctx, &result_desc);\n        }\n    }\n    return ret;\n}\n\nstatic int js_proxy_define_own_property(JSContext *ctx, JSValueConst obj,\n                                        JSAtom prop, JSValueConst val,\n                                        JSValueConst getter, JSValueConst setter,\n                                        int flags)\n{\n    JSProxyData *s;\n    JSValue method, ret1, prop_val, desc_val;\n    int res, ret;\n    JSObject *p;\n    JSValueConst args[3];\n    JSPropertyDescriptor desc;\n    BOOL setting_not_configurable;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_defineProperty);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method)) {\n        return JS_DefineProperty(ctx, s->target, prop, val, getter, setter, flags);\n    }\n    prop_val = JS_AtomToValue(ctx, prop);\n    if (JS_IsException(prop_val)) {\n        JS_FreeValue(ctx, method);\n        return -1;\n    }\n    desc_val = js_create_desc(ctx, val, getter, setter, flags);\n    if (JS_IsException(desc_val)) {\n        JS_FreeValue(ctx, prop_val);\n        JS_FreeValue(ctx, method);\n        return -1;\n    }\n    args[0] = s->target;\n    args[1] = prop_val;\n    args[2] = desc_val;\n    ret1 = JS_CallFree(ctx, method, s->handler, 3, args);\n    JS_FreeValue(ctx, prop_val);\n    JS_FreeValue(ctx, desc_val);\n    if (JS_IsException(ret1))\n        return -1;\n    ret = JS_ToBoolFree(ctx, ret1);\n    if (!ret) {\n        if (flags & JS_PROP_THROW) {\n            JS_ThrowTypeError(ctx, \"proxy: defineProperty exception\");\n            return -1;\n        } else {\n            return 0;\n        }\n    }\n    p = JS_VALUE_GET_OBJ(s->target);\n    res = JS_GetOwnPropertyInternal(ctx, &desc, p, prop);\n    if (res < 0)\n        return -1;\n    setting_not_configurable = ((flags & (JS_PROP_HAS_CONFIGURABLE |\n                                          JS_PROP_CONFIGURABLE)) ==\n                                JS_PROP_HAS_CONFIGURABLE);\n    if (!res) {\n        if (!p->extensible || setting_not_configurable)\n            goto fail;\n    } else {\n        if (!check_define_prop_flags(desc.flags, flags) ||\n            ((desc.flags & JS_PROP_CONFIGURABLE) && setting_not_configurable)) {\n            goto fail1;\n        }\n        if (flags & (JS_PROP_HAS_GET | JS_PROP_HAS_SET)) {\n            if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE)) ==\n                JS_PROP_GETSET) {\n                if ((flags & JS_PROP_HAS_GET) &&\n                    !js_same_value(ctx, getter, desc.getter)) {\n                    goto fail1;\n                }\n                if ((flags & JS_PROP_HAS_SET) &&\n                    !js_same_value(ctx, setter, desc.setter)) {\n                    goto fail1;\n                }\n            }\n        } else if (flags & JS_PROP_HAS_VALUE) {\n            if ((desc.flags & (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)) ==\n                JS_PROP_WRITABLE && !(flags & JS_PROP_WRITABLE)) {\n                /* missing-proxy-check feature */\n                goto fail1;\n            } else if ((desc.flags & (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE)) == 0 &&\n                !js_same_value(ctx, val, desc.value)) {\n                goto fail1;\n            }\n        }\n        if (flags & JS_PROP_HAS_WRITABLE) {\n            if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE |\n                               JS_PROP_WRITABLE)) == JS_PROP_WRITABLE) {\n                /* proxy-missing-checks */\n            fail1:\n                js_free_desc(ctx, &desc);\n            fail:\n                JS_ThrowTypeError(ctx, \"proxy: inconsistent defineProperty\");\n                return -1;\n            }\n        }\n        js_free_desc(ctx, &desc);\n    }\n    return 1;\n}\n\nstatic int js_proxy_delete_property(JSContext *ctx, JSValueConst obj,\n                                    JSAtom atom)\n{\n    JSProxyData *s;\n    JSValue method, ret, atom_val;\n    int res, res2, is_extensible;\n    JSValueConst args[2];\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_deleteProperty);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method)) {\n        return JS_DeleteProperty(ctx, s->target, atom, 0);\n    }\n    atom_val = JS_AtomToValue(ctx, atom);;\n    if (JS_IsException(atom_val)) {\n        JS_FreeValue(ctx, method);\n        return -1;\n    }\n    args[0] = s->target;\n    args[1] = atom_val;\n    ret = JS_CallFree(ctx, method, s->handler, 2, args);\n    JS_FreeValue(ctx, atom_val);\n    if (JS_IsException(ret))\n        return -1;\n    res = JS_ToBoolFree(ctx, ret);\n    if (res) {\n        JSPropertyDescriptor desc;\n        res2 = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(s->target), atom);\n        if (res2 < 0)\n            return -1;\n        if (res2) {\n            if (!(desc.flags & JS_PROP_CONFIGURABLE))\n                goto fail;\n            is_extensible = JS_IsExtensible(ctx, s->target);\n            if (is_extensible < 0)\n                goto fail1;\n            if (!is_extensible) {\n                /* proxy-missing-checks */\n            fail:\n                JS_ThrowTypeError(ctx, \"proxy: inconsistent deleteProperty\");\n            fail1:\n                js_free_desc(ctx, &desc);\n                return -1;\n            }\n            js_free_desc(ctx, &desc);\n        }\n    }\n    return res;\n}\n\n/* return the index of the property or -1 if not found */\nstatic int find_prop_key(const JSPropertyEnum *tab, int n, JSAtom atom)\n{\n    int i;\n    for(i = 0; i < n; i++) {\n        if (tab[i].atom == atom)\n            return i;\n    }\n    return -1;\n}\n\nstatic int js_proxy_get_own_property_names(JSContext *ctx,\n                                           JSPropertyEnum **ptab,\n                                           uint32_t *plen,\n                                           JSValueConst obj)\n{\n    JSProxyData *s;\n    JSValue method, prop_array, val;\n    uint32_t len, i, len2;\n    JSPropertyEnum *tab, *tab2;\n    JSAtom atom;\n    JSPropertyDescriptor desc;\n    int res, is_extensible, idx;\n\n    s = get_proxy_method(ctx, &method, obj, JS_ATOM_ownKeys);\n    if (!s)\n        return -1;\n    if (JS_IsUndefined(method)) {\n        return JS_GetOwnPropertyNamesInternal(ctx, ptab, plen,\n                                      JS_VALUE_GET_OBJ(s->target),\n                                      JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK);\n    }\n    prop_array = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target);\n    if (JS_IsException(prop_array))\n        return -1;\n    tab = NULL;\n    len = 0;\n    tab2 = NULL;\n    len2 = 0;\n    if (js_get_length32(ctx, &len, prop_array))\n        goto fail;\n    if (len > 0) {\n        tab = js_mallocz(ctx, sizeof(tab[0]) * len);\n        if (!tab)\n            goto fail;\n    }\n    for(i = 0; i < len; i++) {\n        val = JS_GetPropertyUint32(ctx, prop_array, i);\n        if (JS_IsException(val))\n            goto fail;\n        if (!JS_IsString(val) && !JS_IsSymbol(val)) {\n            JS_FreeValue(ctx, val);\n            JS_ThrowTypeError(ctx, \"proxy: properties must be strings or symbols\");\n            goto fail;\n        }\n        atom = JS_ValueToAtom(ctx, val);\n        JS_FreeValue(ctx, val);\n        if (atom == JS_ATOM_NULL)\n            goto fail;\n        tab[i].atom = atom;\n        tab[i].is_enumerable = FALSE; /* XXX: redundant? */\n    }\n\n    /* check duplicate properties (XXX: inefficient, could store the\n     * properties an a temporary object to use the hash) */\n    for(i = 1; i < len; i++) {\n        if (find_prop_key(tab, i, tab[i].atom) >= 0) {\n            JS_ThrowTypeError(ctx, \"proxy: duplicate property\");\n            goto fail;\n        }\n    }\n\n    is_extensible = JS_IsExtensible(ctx, s->target);\n    if (is_extensible < 0)\n        goto fail;\n\n    /* check if there are non configurable properties */\n    if (s->is_revoked) {\n        JS_ThrowTypeErrorRevokedProxy(ctx);\n        goto fail;\n    }\n    if (JS_GetOwnPropertyNamesInternal(ctx, &tab2, &len2, JS_VALUE_GET_OBJ(s->target),\n                               JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK))\n        goto fail;\n    for(i = 0; i < len2; i++) {\n        if (s->is_revoked) {\n            JS_ThrowTypeErrorRevokedProxy(ctx);\n            goto fail;\n        }\n        res = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(s->target),\n                                tab2[i].atom);\n        if (res < 0)\n            goto fail;\n        if (res) {  /* safety, property should be found */\n            js_free_desc(ctx, &desc);\n            if (!(desc.flags & JS_PROP_CONFIGURABLE) || !is_extensible) {\n                idx = find_prop_key(tab, len, tab2[i].atom);\n                if (idx < 0) {\n                    JS_ThrowTypeError(ctx, \"proxy: target property must be present in proxy ownKeys\");\n                    goto fail;\n                }\n                /* mark the property as found */\n                if (!is_extensible)\n                    tab[idx].is_enumerable = TRUE;\n            }\n        }\n    }\n    if (!is_extensible) {\n        /* check that all property in 'tab' were checked */\n        for(i = 0; i < len; i++) {\n            if (!tab[i].is_enumerable) {\n                JS_ThrowTypeError(ctx, \"proxy: property not present in target were returned by non extensible proxy\");\n                goto fail;\n            }\n        }\n    }\n\n    js_free_prop_enum(ctx, tab2, len2);\n    JS_FreeValue(ctx, prop_array);\n    *ptab = tab;\n    *plen = len;\n    return 0;\n fail:\n    js_free_prop_enum(ctx, tab2, len2);\n    js_free_prop_enum(ctx, tab, len);\n    JS_FreeValue(ctx, prop_array);\n    return -1;\n}\n\nstatic JSValue js_proxy_call_constructor(JSContext *ctx, JSValueConst func_obj,\n                                         JSValueConst new_target,\n                                         int argc, JSValueConst *argv)\n{\n    JSProxyData *s;\n    JSValue method, arg_array, ret;\n    JSValueConst args[3];\n\n    s = get_proxy_method(ctx, &method, func_obj, JS_ATOM_construct);\n    if (!s)\n        return JS_EXCEPTION;\n    if (!JS_IsConstructor(ctx, s->target))\n        return JS_ThrowTypeError(ctx, \"not a constructor\");\n    if (JS_IsUndefined(method))\n        return JS_CallConstructor2(ctx, s->target, new_target, argc, argv);\n    arg_array = js_create_array(ctx, argc, argv);\n    if (JS_IsException(arg_array)) {\n        ret = JS_EXCEPTION;\n        goto fail;\n    }\n    args[0] = s->target;\n    args[1] = arg_array;\n    args[2] = new_target;\n    ret = JS_Call(ctx, method, s->handler, 3, args);\n    if (!JS_IsException(ret) && JS_VALUE_GET_TAG(ret) != JS_TAG_OBJECT) {\n        JS_FreeValue(ctx, ret);\n        ret = JS_ThrowTypeErrorNotAnObject(ctx);\n    }\n fail:\n    JS_FreeValue(ctx, method);\n    JS_FreeValue(ctx, arg_array);\n    return ret;\n}\n\nstatic JSValue js_proxy_call(JSContext *ctx, JSValueConst func_obj,\n                             JSValueConst this_obj,\n                             int argc, JSValueConst *argv, int flags)\n{\n    JSProxyData *s;\n    JSValue method, arg_array, ret;\n    JSValueConst args[3];\n\n    if (flags & JS_CALL_FLAG_CONSTRUCTOR)\n        return js_proxy_call_constructor(ctx, func_obj, this_obj, argc, argv);\n    \n    s = get_proxy_method(ctx, &method, func_obj, JS_ATOM_apply);\n    if (!s)\n        return JS_EXCEPTION;\n    if (!s->is_func) {\n        JS_FreeValue(ctx, method);\n        return JS_ThrowTypeError(ctx, \"not a function\");\n    }\n    if (JS_IsUndefined(method))\n        return JS_Call(ctx, s->target, this_obj, argc, argv);\n    arg_array = js_create_array(ctx, argc, argv);\n    if (JS_IsException(arg_array)) {\n        ret = JS_EXCEPTION;\n        goto fail;\n    }\n    args[0] = s->target;\n    args[1] = this_obj;\n    args[2] = arg_array;\n    ret = JS_Call(ctx, method, s->handler, 3, args);\n fail:\n    JS_FreeValue(ctx, method);\n    JS_FreeValue(ctx, arg_array);\n    return ret;\n}\n\nstatic int js_proxy_isArray(JSContext *ctx, JSValueConst obj)\n{\n    JSProxyData *s = JS_GetOpaque(obj, JS_CLASS_PROXY);\n    if (!s)\n        return FALSE;\n    if (s->is_revoked) {\n        JS_ThrowTypeErrorRevokedProxy(ctx);\n        return -1;\n    }\n    return JS_IsArray(ctx, s->target);\n}\n\nstatic const JSClassExoticMethods js_proxy_exotic_methods = {\n    .get_own_property = js_proxy_get_own_property,\n    .define_own_property = js_proxy_define_own_property,\n    .delete_property = js_proxy_delete_property,\n    .get_own_property_names = js_proxy_get_own_property_names,\n    .has_property = js_proxy_has,\n    .get_property = js_proxy_get,\n    .set_property = js_proxy_set,\n};\n\nstatic JSValue js_proxy_constructor(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValueConst target, handler;\n    JSValue obj;\n    JSProxyData *s;\n\n    target = argv[0];\n    handler = argv[1];\n    if (JS_VALUE_GET_TAG(target) != JS_TAG_OBJECT ||\n        JS_VALUE_GET_TAG(handler) != JS_TAG_OBJECT)\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    obj = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_PROXY);\n    if (JS_IsException(obj))\n        return obj;\n    s = js_malloc(ctx, sizeof(JSProxyData));\n    if (!s) {\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    s->target = JS_DupValue(ctx, target);\n    s->handler = JS_DupValue(ctx, handler);\n    s->is_func = JS_IsFunction(ctx, target);\n    s->is_revoked = FALSE;\n    JS_SetOpaque(obj, s);\n    JS_SetConstructorBit(ctx, obj, JS_IsConstructor(ctx, target));\n    return obj;\n}\n\nstatic JSValue js_proxy_revoke(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv, int magic,\n                               JSValue *func_data)\n{\n    JSProxyData *s = JS_GetOpaque(func_data[0], JS_CLASS_PROXY);\n    if (s) {\n        /* We do not free the handler and target in case they are\n           referenced as constants in the C call stack */\n        s->is_revoked = TRUE;\n        JS_FreeValue(ctx, func_data[0]);\n        func_data[0] = JS_NULL;\n    }\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_proxy_revoke_constructor(JSContext *ctx,\n                                           JSValueConst proxy_obj)\n{\n    return JS_NewCFunctionData(ctx, js_proxy_revoke, 0, 0, 1, &proxy_obj);\n}\n\nstatic JSValue js_proxy_revocable(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue proxy_obj, revoke_obj = JS_UNDEFINED, obj;\n\n    proxy_obj = js_proxy_constructor(ctx, JS_UNDEFINED, argc, argv);\n    if (JS_IsException(proxy_obj))\n        goto fail;\n    revoke_obj = js_proxy_revoke_constructor(ctx, proxy_obj);\n    if (JS_IsException(revoke_obj))\n        goto fail;\n    obj = JS_NewObject(ctx);\n    if (JS_IsException(obj))\n        goto fail;\n    // XXX: exceptions?\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_proxy, proxy_obj, JS_PROP_C_W_E);\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_revoke, revoke_obj, JS_PROP_C_W_E);\n    return obj;\n fail:\n    JS_FreeValue(ctx, proxy_obj);\n    JS_FreeValue(ctx, revoke_obj);\n    return JS_EXCEPTION;\n}\n\nstatic const JSCFunctionListEntry js_proxy_funcs[] = {\n    JS_CFUNC_DEF(\"revocable\", 2, js_proxy_revocable ),\n};\n\nstatic const JSClassShortDef js_proxy_class_def[] = {\n    { JS_ATOM_Object, js_proxy_finalizer, js_proxy_mark }, /* JS_CLASS_PROXY */\n};\n\nvoid JS_AddIntrinsicProxy(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    JSValue obj1;\n\n    if (!JS_IsRegisteredClass(rt, JS_CLASS_PROXY)) {\n        init_class_range(rt, js_proxy_class_def, JS_CLASS_PROXY,\n                         countof(js_proxy_class_def));\n        rt->class_array[JS_CLASS_PROXY].exotic = &js_proxy_exotic_methods;\n        rt->class_array[JS_CLASS_PROXY].call = js_proxy_call;\n    }\n\n    obj1 = JS_NewCFunction2(ctx, js_proxy_constructor, \"Proxy\", 2,\n                            JS_CFUNC_constructor, 0);\n    JS_SetConstructorBit(ctx, obj1, TRUE);\n    JS_SetPropertyFunctionList(ctx, obj1, js_proxy_funcs,\n                               countof(js_proxy_funcs));\n    JS_DefinePropertyValueStr(ctx, ctx->global_obj, \"Proxy\",\n                              obj1, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n}\n\n/* Symbol */\n\nstatic JSValue js_symbol_constructor(JSContext *ctx, JSValueConst new_target,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue str;\n    JSString *p;\n\n    if (!JS_IsUndefined(new_target))\n        return JS_ThrowTypeError(ctx, \"not a constructor\");\n    if (argc == 0 || JS_IsUndefined(argv[0])) {\n        p = NULL;\n    } else {\n        str = JS_ToString(ctx, argv[0]);\n        if (JS_IsException(str))\n            return JS_EXCEPTION;\n        p = JS_VALUE_GET_STRING(str);\n    }\n    return JS_NewSymbol(ctx, p, JS_ATOM_TYPE_SYMBOL);\n}\n\nstatic JSValue js_thisSymbolValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_SYMBOL)\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_SYMBOL) {\n            if (JS_VALUE_GET_TAG(p->u.object_data) == JS_TAG_SYMBOL)\n                return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a symbol\");\n}\n\nstatic JSValue js_symbol_toString(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    val = js_thisSymbolValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    /* XXX: use JS_ToStringInternal() with a flags */\n    ret = js_string_constructor(ctx, JS_UNDEFINED, 1, (JSValueConst *)&val);\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic JSValue js_symbol_valueOf(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    return js_thisSymbolValue(ctx, this_val);\n}\n\nstatic JSValue js_symbol_get_description(JSContext *ctx, JSValueConst this_val)\n{\n    JSValue val, ret;\n    JSAtomStruct *p;\n\n    val = js_thisSymbolValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    p = JS_VALUE_GET_PTR(val);\n    if (p->len == 0 && p->is_wide_char != 0) {\n        ret = JS_UNDEFINED;\n    } else {\n        ret = JS_AtomToString(ctx, js_get_atom_index(ctx->rt, p));\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n}\n\nstatic const JSCFunctionListEntry js_symbol_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_symbol_toString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_symbol_valueOf ),\n    // XXX: should have writable: false\n    JS_CFUNC_DEF(\"[Symbol.toPrimitive]\", 1, js_symbol_valueOf ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Symbol\", JS_PROP_CONFIGURABLE ),\n    JS_CGETSET_DEF(\"description\", js_symbol_get_description, NULL ),\n};\n\nstatic JSValue js_symbol_for(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    JSValue str;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        return JS_EXCEPTION;\n    return JS_NewSymbol(ctx, JS_VALUE_GET_STRING(str), JS_ATOM_TYPE_GLOBAL_SYMBOL);\n}\n\nstatic JSValue js_symbol_keyFor(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSAtomStruct *p;\n\n    if (!JS_IsSymbol(argv[0]))\n        return JS_ThrowTypeError(ctx, \"not a symbol\");\n    p = JS_VALUE_GET_PTR(argv[0]);\n    if (p->atom_type != JS_ATOM_TYPE_GLOBAL_SYMBOL)\n        return JS_UNDEFINED;\n    return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p));\n}\n\nstatic const JSCFunctionListEntry js_symbol_funcs[] = {\n    JS_CFUNC_DEF(\"for\", 1, js_symbol_for ),\n    JS_CFUNC_DEF(\"keyFor\", 1, js_symbol_keyFor ),\n};\n\n/* Set/Map/WeakSet/WeakMap */\n\ntypedef struct JSMapRecord {\n    int ref_count; /* used during enumeration to avoid freeing the record */\n    BOOL empty; /* TRUE if the record is deleted */\n    struct JSMapState *map;\n    struct JSMapRecord *next_weak_ref;\n    struct list_head link;\n    struct list_head hash_link;\n    JSValue key;\n    JSValue value;\n} JSMapRecord;\n\ntypedef struct JSMapState {\n    BOOL is_weak; /* TRUE if WeakSet/WeakMap */\n    struct list_head records; /* list of JSMapRecord.link */\n    uint32_t record_count;\n    struct list_head *hash_table;\n    uint32_t hash_size; /* must be a power of two */\n    uint32_t record_count_threshold; /* count at which a hash table\n                                        resize is needed */\n} JSMapState;\n\n#define MAGIC_SET (1 << 0)\n#define MAGIC_WEAK (1 << 1)\n\nstatic JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,\n                                  int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s;\n    JSValue obj, adder = JS_UNDEFINED, iter = JS_UNDEFINED, next_method = JS_UNDEFINED;\n    JSValueConst arr;\n    BOOL is_set, is_weak;\n\n    is_set = magic & MAGIC_SET;\n    is_weak = ((magic & MAGIC_WEAK) != 0);\n    obj = js_create_from_ctor(ctx, new_target, JS_CLASS_MAP + magic);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    s = js_mallocz(ctx, sizeof(*s));\n    if (!s)\n        goto fail;\n    init_list_head(&s->records);\n    s->is_weak = is_weak;\n    JS_SetOpaque(obj, s);\n    s->hash_size = 1;\n    s->hash_table = js_malloc(ctx, sizeof(s->hash_table[0]) * s->hash_size);\n    if (!s->hash_table)\n        goto fail;\n    init_list_head(&s->hash_table[0]);\n    s->record_count_threshold = 4;\n\n    arr = JS_UNDEFINED;\n    if (argc > 0)\n        arr = argv[0];\n    if (!JS_IsUndefined(arr) && !JS_IsNull(arr)) {\n        JSValue item, ret;\n        BOOL done;\n\n        adder = JS_GetProperty(ctx, obj, is_set ? JS_ATOM_add : JS_ATOM_set);\n        if (JS_IsException(adder))\n            goto fail;\n        if (!JS_IsFunction(ctx, adder)) {\n            JS_ThrowTypeError(ctx, \"set/add is not a function\");\n            goto fail;\n        }\n\n        iter = JS_GetIterator(ctx, arr, FALSE);\n        if (JS_IsException(iter))\n            goto fail;\n        next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);\n        if (JS_IsException(next_method))\n            goto fail;\n\n        for(;;) {\n            item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);\n            if (JS_IsException(item))\n                goto fail;\n            if (done) {\n                JS_FreeValue(ctx, item);\n                break;\n            }\n            if (is_set) {\n                ret = JS_Call(ctx, adder, obj, 1, (JSValueConst *)&item);\n                if (JS_IsException(ret)) {\n                    JS_FreeValue(ctx, item);\n                    goto fail;\n                }\n            } else {\n                JSValue key, value;\n                JSValueConst args[2];\n                key = JS_UNDEFINED;\n                value = JS_UNDEFINED;\n                if (!JS_IsObject(item)) {\n                    JS_ThrowTypeErrorNotAnObject(ctx);\n                    goto fail1;\n                }\n                key = JS_GetPropertyUint32(ctx, item, 0);\n                if (JS_IsException(key))\n                    goto fail1;\n                value = JS_GetPropertyUint32(ctx, item, 1);\n                if (JS_IsException(value))\n                    goto fail1;\n                args[0] = key;\n                args[1] = value;\n                ret = JS_Call(ctx, adder, obj, 2, args);\n                if (JS_IsException(ret)) {\n                fail1:\n                    JS_FreeValue(ctx, item);\n                    JS_FreeValue(ctx, key);\n                    JS_FreeValue(ctx, value);\n                    goto fail;\n                }\n                JS_FreeValue(ctx, key);\n                JS_FreeValue(ctx, value);\n            }\n            JS_FreeValue(ctx, ret);\n            JS_FreeValue(ctx, item);\n        }\n        JS_FreeValue(ctx, next_method);\n        JS_FreeValue(ctx, iter);\n        JS_FreeValue(ctx, adder);\n    }\n    return obj;\n fail:\n    if (JS_IsObject(iter)) {\n        /* close the iterator object, preserving pending exception */\n        JS_IteratorClose(ctx, iter, TRUE);\n    }\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    JS_FreeValue(ctx, adder);\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\n/* XXX: could normalize strings to speed up comparison */\nstatic JSValueConst map_normalize_key(JSContext *ctx, JSValueConst key)\n{\n    uint32_t tag = JS_VALUE_GET_TAG(key);\n    /* convert -0.0 to +0.0 */\n    if (JS_TAG_IS_FLOAT64(tag) && JS_VALUE_GET_FLOAT64(key) == 0.0) {\n        key = JS_NewInt32(ctx, 0);\n    }\n    return key;\n}\n\n/* XXX: better hash ? */\nstatic uint32_t map_hash_key(JSContext *ctx, JSValueConst key)\n{\n    uint32_t tag = JS_VALUE_GET_NORM_TAG(key);\n    uint32_t h;\n    double d;\n    JSFloat64Union u;\n\n    switch(tag) {\n    case JS_TAG_BOOL:\n        h = JS_VALUE_GET_INT(key);\n        break;\n    case JS_TAG_STRING:\n        h = hash_string(JS_VALUE_GET_STRING(key), 0);\n        break;\n    case JS_TAG_OBJECT:\n    case JS_TAG_SYMBOL:\n        h = (uintptr_t)JS_VALUE_GET_PTR(key) * 3163;\n        break;\n    case JS_TAG_INT:\n        d = JS_VALUE_GET_INT(key) * 3163;\n        goto hash_float64;\n    case JS_TAG_FLOAT64:\n        d = JS_VALUE_GET_FLOAT64(key);\n        /* normalize the NaN */\n        if (isnan(d))\n            d = JS_FLOAT64_NAN;\n    hash_float64:\n        u.d = d;\n        h = (u.u32[0] ^ u.u32[1]) * 3163;\n        break;\n    default:\n        h = 0; /* XXX: bignum support */\n        break;\n    }\n    h ^= tag;\n    return h;\n}\n\nstatic JSMapRecord *map_find_record(JSContext *ctx, JSMapState *s,\n                                    JSValueConst key)\n{\n    struct list_head *el;\n    JSMapRecord *mr;\n    uint32_t h;\n    h = map_hash_key(ctx, key) & (s->hash_size - 1);\n    list_for_each(el, &s->hash_table[h]) {\n        mr = list_entry(el, JSMapRecord, hash_link);\n        if (js_same_value_zero(ctx, mr->key, key))\n            return mr;\n    }\n    return NULL;\n}\n\nstatic void map_hash_resize(JSContext *ctx, JSMapState *s)\n{\n    uint32_t new_hash_size, i, h;\n    size_t slack;\n    struct list_head *new_hash_table, *el;\n    JSMapRecord *mr;\n\n    /* XXX: no reporting of memory allocation failure */\n    if (s->hash_size == 1)\n        new_hash_size = 4;\n    else\n        new_hash_size = s->hash_size * 2;\n    new_hash_table = js_realloc2(ctx, s->hash_table,\n                                 sizeof(new_hash_table[0]) * new_hash_size, &slack);\n    if (!new_hash_table)\n        return;\n    new_hash_size += slack / sizeof(*new_hash_table);\n\n    for(i = 0; i < new_hash_size; i++)\n        init_list_head(&new_hash_table[i]);\n\n    list_for_each(el, &s->records) {\n        mr = list_entry(el, JSMapRecord, link);\n        if (!mr->empty) {\n            h = map_hash_key(ctx, mr->key) & (new_hash_size - 1);\n            list_add_tail(&mr->hash_link, &new_hash_table[h]);\n        }\n    }\n    s->hash_table = new_hash_table;\n    s->hash_size = new_hash_size;\n    s->record_count_threshold = new_hash_size * 2;\n}\n\nstatic JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,\n                                   JSValueConst key)\n{\n    uint32_t h;\n    JSMapRecord *mr;\n\n    mr = js_malloc(ctx, sizeof(*mr));\n    if (!mr)\n        return NULL;\n    mr->ref_count = 1;\n    mr->map = s;\n    mr->empty = FALSE;\n    if (s->is_weak) {\n        JSObject *p = JS_VALUE_GET_OBJ(key);\n        /* Add the weak reference */\n        mr->next_weak_ref = p->first_weak_ref;\n        p->first_weak_ref = mr;\n    } else {\n        JS_DupValue(ctx, key);\n    }\n    mr->key = (JSValue)key;\n    h = map_hash_key(ctx, key) & (s->hash_size - 1);\n    list_add_tail(&mr->hash_link, &s->hash_table[h]);\n    list_add_tail(&mr->link, &s->records);\n    s->record_count++;\n    if (s->record_count >= s->record_count_threshold) {\n        map_hash_resize(ctx, s);\n    }\n    return mr;\n}\n\n/* Remove the weak reference from the object weak\n   reference list. we don't use a doubly linked list to\n   save space, assuming a given object has few weak\n       references to it */\nstatic void delete_weak_ref(JSRuntime *rt, JSMapRecord *mr)\n{\n    JSMapRecord **pmr, *mr1;\n    JSObject *p;\n\n    p = JS_VALUE_GET_OBJ(mr->key);\n    pmr = &p->first_weak_ref;\n    for(;;) {\n        mr1 = *pmr;\n        assert(mr1 != NULL);\n        if (mr1 == mr)\n            break;\n        pmr = &mr1->next_weak_ref;\n    }\n    *pmr = mr1->next_weak_ref;\n}\n\nstatic void map_delete_record(JSRuntime *rt, JSMapState *s, JSMapRecord *mr)\n{\n    if (mr->empty)\n        return;\n    list_del(&mr->hash_link);\n    if (s->is_weak) {\n        delete_weak_ref(rt, mr);\n    } else {\n        JS_FreeValueRT(rt, mr->key);\n    }\n    JS_FreeValueRT(rt, mr->value);\n    if (--mr->ref_count == 0) {\n        list_del(&mr->link);\n        js_free_rt(rt, mr);\n    } else {\n        /* keep a zombie record for iterators */\n        mr->empty = TRUE;\n        mr->key = JS_UNDEFINED;\n        mr->value = JS_UNDEFINED;\n    }\n    s->record_count--;\n}\n\nstatic void map_decref_record(JSRuntime *rt, JSMapRecord *mr)\n{\n    if (--mr->ref_count == 0) {\n        /* the record can be safely removed */\n        assert(mr->empty);\n        list_del(&mr->link);\n        js_free_rt(rt, mr);\n    }\n}\n\nstatic void reset_weak_ref(JSRuntime *rt, JSObject *p)\n{\n    JSMapRecord *mr, *mr_next;\n    JSMapState *s;\n    \n    /* first pass to remove the records from the WeakMap/WeakSet\n       lists */\n    for(mr = p->first_weak_ref; mr != NULL; mr = mr->next_weak_ref) {\n        s = mr->map;\n        assert(s->is_weak);\n        assert(!mr->empty); /* no iterator on WeakMap/WeakSet */\n        list_del(&mr->hash_link);\n        list_del(&mr->link);\n    }\n    \n    /* second pass to free the values to avoid modifying the weak\n       reference list while traversing it. */\n    for(mr = p->first_weak_ref; mr != NULL; mr = mr_next) {\n        mr_next = mr->next_weak_ref;\n        JS_FreeValueRT(rt, mr->value);\n        js_free_rt(rt, mr);\n    }\n\n    p->first_weak_ref = NULL; /* fail safe */\n}\n\nstatic JSValue js_map_set(JSContext *ctx, JSValueConst this_val,\n                          int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    JSMapRecord *mr;\n    JSValueConst key, value;\n\n    if (!s)\n        return JS_EXCEPTION;\n    key = map_normalize_key(ctx, argv[0]);\n    if (s->is_weak && !JS_IsObject(key))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    if (magic & MAGIC_SET)\n        value = JS_UNDEFINED;\n    else\n        value = argv[1];\n    mr = map_find_record(ctx, s, key);\n    if (mr) {\n        JS_FreeValue(ctx, mr->value);\n    } else {\n        mr = map_add_record(ctx, s, key);\n        if (!mr)\n            return JS_EXCEPTION;\n    }\n    mr->value = JS_DupValue(ctx, value);\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic JSValue js_map_get(JSContext *ctx, JSValueConst this_val,\n                          int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    JSMapRecord *mr;\n    JSValueConst key;\n\n    if (!s)\n        return JS_EXCEPTION;\n    key = map_normalize_key(ctx, argv[0]);\n    mr = map_find_record(ctx, s, key);\n    if (!mr)\n        return JS_UNDEFINED;\n    else\n        return JS_DupValue(ctx, mr->value);\n}\n\nstatic JSValue js_map_has(JSContext *ctx, JSValueConst this_val,\n                          int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    JSMapRecord *mr;\n    JSValueConst key;\n\n    if (!s)\n        return JS_EXCEPTION;\n    key = map_normalize_key(ctx, argv[0]);\n    mr = map_find_record(ctx, s, key);\n    return JS_NewBool(ctx, (mr != NULL));\n}\n\nstatic JSValue js_map_delete(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    JSMapRecord *mr;\n    JSValueConst key;\n\n    if (!s)\n        return JS_EXCEPTION;\n    key = map_normalize_key(ctx, argv[0]);\n    mr = map_find_record(ctx, s, key);\n    if (!mr)\n        return JS_FALSE;\n    map_delete_record(ctx->rt, s, mr);\n    return JS_TRUE;\n}\n\nstatic JSValue js_map_clear(JSContext *ctx, JSValueConst this_val,\n                            int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    struct list_head *el, *el1;\n    JSMapRecord *mr;\n\n    if (!s)\n        return JS_EXCEPTION;\n    list_for_each_safe(el, el1, &s->records) {\n        mr = list_entry(el, JSMapRecord, link);\n        map_delete_record(ctx->rt, s, mr);\n    }\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_map_get_size(JSContext *ctx, JSValueConst this_val, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    if (!s)\n        return JS_EXCEPTION;\n    return JS_NewUint32(ctx, s->record_count);\n}\n\nstatic JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int magic)\n{\n    JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    JSValueConst func, this_arg;\n    JSValue ret, args[3];\n    struct list_head *el;\n    JSMapRecord *mr;\n\n    if (!s)\n        return JS_EXCEPTION;\n    func = argv[0];\n    if (argc > 1)\n        this_arg = argv[1];\n    else\n        this_arg = JS_UNDEFINED;\n    if (check_function(ctx, func))\n        return JS_EXCEPTION;\n    /* Note: the list can be modified while traversing it, but the\n       current element is locked */\n    el = s->records.next;\n    while (el != &s->records) {\n        mr = list_entry(el, JSMapRecord, link);\n        if (!mr->empty) {\n            mr->ref_count++;\n            /* must duplicate in case the record is deleted */\n            args[1] = JS_DupValue(ctx, mr->key);\n            if (magic)\n                args[0] = args[1];\n            else\n                args[0] = JS_DupValue(ctx, mr->value);\n            args[2] = (JSValue)this_val;\n            ret = JS_Call(ctx, func, this_arg, 3, (JSValueConst *)args);\n            JS_FreeValue(ctx, args[0]);\n            if (!magic)\n                JS_FreeValue(ctx, args[1]);\n            el = el->next;\n            map_decref_record(ctx->rt, mr);\n            if (JS_IsException(ret))\n                return ret;\n            JS_FreeValue(ctx, ret);\n        } else {\n            el = el->next;\n        }\n    }\n    return JS_UNDEFINED;\n}\n\nstatic void js_map_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p;\n    JSMapState *s;\n    struct list_head *el, *el1;\n    JSMapRecord *mr;\n\n    p = JS_VALUE_GET_OBJ(val);\n    s = p->u.map_state;\n    if (s) {\n        /* if the object is deleted we are sure that no iterator is\n           using it */\n        list_for_each_safe(el, el1, &s->records) {\n            mr = list_entry(el, JSMapRecord, link);\n            if (!mr->empty) {\n                if (s->is_weak)\n                    delete_weak_ref(rt, mr);\n                else\n                    JS_FreeValueRT(rt, mr->key);\n                JS_FreeValueRT(rt, mr->value);\n            }\n            js_free_rt(rt, mr);\n        }\n        js_free_rt(rt, s->hash_table);\n        js_free_rt(rt, s);\n    }\n}\n\nstatic void js_map_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSMapState *s;\n    struct list_head *el;\n    JSMapRecord *mr;\n\n    s = p->u.map_state;\n    if (s) {\n        list_for_each(el, &s->records) {\n            mr = list_entry(el, JSMapRecord, link);\n            if (!s->is_weak)\n                JS_MarkValue(rt, mr->key, mark_func);\n            JS_MarkValue(rt, mr->value, mark_func);\n        }\n    }\n}\n\n/* Map Iterator */\n\ntypedef struct JSMapIteratorData {\n    JSValue obj;\n    JSIteratorKindEnum kind;\n    JSMapRecord *cur_record;\n} JSMapIteratorData;\n\nstatic void js_map_iterator_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p;\n    JSMapIteratorData *it;\n\n    p = JS_VALUE_GET_OBJ(val);\n    it = p->u.map_iterator_data;\n    if (it) {\n        /* During the GC sweep phase the Map finalizer may be\n           called before the Map iterator finalizer */\n        if (JS_IsLiveObject(rt, it->obj) && it->cur_record) {\n            map_decref_record(rt, it->cur_record);\n        }\n        JS_FreeValueRT(rt, it->obj);\n        js_free_rt(rt, it);\n    }\n}\n\nstatic void js_map_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                 JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSMapIteratorData *it;\n    it = p->u.map_iterator_data;\n    if (it) {\n        /* the record is already marked by the object */\n        JS_MarkValue(rt, it->obj, mark_func);\n    }\n}\n\nstatic JSValue js_create_map_iterator(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv, int magic)\n{\n    JSIteratorKindEnum kind;\n    JSMapState *s;\n    JSMapIteratorData *it;\n    JSValue enum_obj;\n\n    kind = magic >> 2;\n    magic &= 3;\n    s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic);\n    if (!s)\n        return JS_EXCEPTION;\n    enum_obj = JS_NewObjectClass(ctx, JS_CLASS_MAP_ITERATOR + magic);\n    if (JS_IsException(enum_obj))\n        goto fail;\n    it = js_malloc(ctx, sizeof(*it));\n    if (!it) {\n        JS_FreeValue(ctx, enum_obj);\n        goto fail;\n    }\n    it->obj = JS_DupValue(ctx, this_val);\n    it->kind = kind;\n    it->cur_record = NULL;\n    JS_SetOpaque(enum_obj, it);\n    return enum_obj;\n fail:\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv,\n                                    BOOL *pdone, int magic)\n{\n    JSMapIteratorData *it;\n    JSMapState *s;\n    JSMapRecord *mr;\n    struct list_head *el;\n\n    it = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP_ITERATOR + magic);\n    if (!it) {\n        *pdone = FALSE;\n        return JS_EXCEPTION;\n    }\n    if (JS_IsUndefined(it->obj))\n        goto done;\n    s = JS_GetOpaque(it->obj, JS_CLASS_MAP + magic);\n    assert(s != NULL);\n    if (!it->cur_record) {\n        el = s->records.next;\n    } else {\n        mr = it->cur_record;\n        el = mr->link.next;\n        map_decref_record(ctx->rt, mr); /* the record can be freed here */\n    }\n    for(;;) {\n        if (el == &s->records) {\n            /* no more record  */\n            it->cur_record = NULL;\n            JS_FreeValue(ctx, it->obj);\n            it->obj = JS_UNDEFINED;\n        done:\n            /* end of enumeration */\n            *pdone = TRUE;\n            return JS_UNDEFINED;\n        }\n        mr = list_entry(el, JSMapRecord, link);\n        if (!mr->empty)\n            break;\n        /* get the next record */\n        el = mr->link.next;\n    }\n\n    /* lock the record so that it won't be freed */\n    mr->ref_count++;\n    it->cur_record = mr;\n    *pdone = FALSE;\n\n    if (it->kind == JS_ITERATOR_KIND_KEY) {\n        return JS_DupValue(ctx, mr->key);\n    } else {\n        JSValueConst args[2];\n        args[0] = mr->key;\n        if (magic)\n            args[1] = mr->key;\n        else\n            args[1] = mr->value;\n        if (it->kind == JS_ITERATOR_KIND_VALUE) {\n            return JS_DupValue(ctx, args[1]);\n        } else {\n            return js_create_array(ctx, 2, args);\n        }\n    }\n}\n\nstatic const JSCFunctionListEntry js_map_funcs[] = {\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL ),\n};\n\nstatic const JSCFunctionListEntry js_map_proto_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"set\", 2, js_map_set, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"get\", 1, js_map_get, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"has\", 1, js_map_has, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"delete\", 1, js_map_delete, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"clear\", 0, js_map_clear, 0 ),\n    JS_CGETSET_MAGIC_DEF(\"size\", js_map_get_size, NULL, 0),\n    JS_CFUNC_MAGIC_DEF(\"forEach\", 1, js_map_forEach, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"values\", 0, js_create_map_iterator, (JS_ITERATOR_KIND_VALUE << 2) | 0 ),\n    JS_CFUNC_MAGIC_DEF(\"keys\", 0, js_create_map_iterator, (JS_ITERATOR_KIND_KEY << 2) | 0 ),\n    JS_CFUNC_MAGIC_DEF(\"entries\", 0, js_create_map_iterator, (JS_ITERATOR_KIND_KEY_AND_VALUE << 2) | 0 ),\n    JS_ALIAS_DEF(\"[Symbol.iterator]\", \"entries\" ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Map\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_map_iterator_proto_funcs[] = {\n    JS_ITERATOR_NEXT_DEF(\"next\", 0, js_map_iterator_next, 0 ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Map Iterator\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_set_proto_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"add\", 1, js_map_set, MAGIC_SET ),\n    JS_CFUNC_MAGIC_DEF(\"has\", 1, js_map_has, MAGIC_SET ),\n    JS_CFUNC_MAGIC_DEF(\"delete\", 1, js_map_delete, MAGIC_SET ),\n    JS_CFUNC_MAGIC_DEF(\"clear\", 0, js_map_clear, MAGIC_SET ),\n    JS_CGETSET_MAGIC_DEF(\"size\", js_map_get_size, NULL, MAGIC_SET ),\n    JS_CFUNC_MAGIC_DEF(\"forEach\", 1, js_map_forEach, MAGIC_SET ),\n    JS_CFUNC_MAGIC_DEF(\"values\", 0, js_create_map_iterator, (JS_ITERATOR_KIND_KEY << 2) | MAGIC_SET ),\n    JS_ALIAS_DEF(\"keys\", \"values\" ),\n    JS_ALIAS_DEF(\"[Symbol.iterator]\", \"values\" ),\n    JS_CFUNC_MAGIC_DEF(\"entries\", 0, js_create_map_iterator, (JS_ITERATOR_KIND_KEY_AND_VALUE << 2) | MAGIC_SET ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Set\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_set_iterator_proto_funcs[] = {\n    JS_ITERATOR_NEXT_DEF(\"next\", 0, js_map_iterator_next, MAGIC_SET ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Set Iterator\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_weak_map_proto_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"set\", 2, js_map_set, MAGIC_WEAK ),\n    JS_CFUNC_MAGIC_DEF(\"get\", 1, js_map_get, MAGIC_WEAK ),\n    JS_CFUNC_MAGIC_DEF(\"has\", 1, js_map_has, MAGIC_WEAK ),\n    JS_CFUNC_MAGIC_DEF(\"delete\", 1, js_map_delete, MAGIC_WEAK ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"WeakMap\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_weak_set_proto_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"add\", 1, js_map_set, MAGIC_SET | MAGIC_WEAK ),\n    JS_CFUNC_MAGIC_DEF(\"has\", 1, js_map_has, MAGIC_SET | MAGIC_WEAK ),\n    JS_CFUNC_MAGIC_DEF(\"delete\", 1, js_map_delete, MAGIC_SET | MAGIC_WEAK ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"WeakSet\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry * const js_map_proto_funcs_ptr[6] = {\n    js_map_proto_funcs,\n    js_set_proto_funcs,\n    js_weak_map_proto_funcs,\n    js_weak_set_proto_funcs,\n    js_map_iterator_proto_funcs,\n    js_set_iterator_proto_funcs,\n};\n\nstatic const uint8_t js_map_proto_funcs_count[6] = {\n    countof(js_map_proto_funcs),\n    countof(js_set_proto_funcs),\n    countof(js_weak_map_proto_funcs),\n    countof(js_weak_set_proto_funcs),\n    countof(js_map_iterator_proto_funcs),\n    countof(js_set_iterator_proto_funcs),\n};\n\nvoid JS_AddIntrinsicMapSet(JSContext *ctx)\n{\n    int i;\n    JSValue obj1;\n    char buf[ATOM_GET_STR_BUF_SIZE];\n\n    for(i = 0; i < 4; i++) {\n        const char *name = JS_AtomGetStr(ctx, buf, sizeof(buf),\n                                         JS_ATOM_Map + i);\n        ctx->class_proto[JS_CLASS_MAP + i] = JS_NewObject(ctx);\n        JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_MAP + i],\n                                   js_map_proto_funcs_ptr[i],\n                                   js_map_proto_funcs_count[i]);\n        obj1 = JS_NewCFunctionMagic(ctx, js_map_constructor, name, 0,\n                                    JS_CFUNC_constructor_magic, i);\n        if (i < 2) {\n            JS_SetPropertyFunctionList(ctx, obj1, js_map_funcs,\n                                       countof(js_map_funcs));\n        }\n        JS_NewGlobalCConstructor2(ctx, obj1, name, ctx->class_proto[JS_CLASS_MAP + i]);\n    }\n\n    for(i = 0; i < 2; i++) {\n        ctx->class_proto[JS_CLASS_MAP_ITERATOR + i] =\n            JS_NewObjectProto(ctx, ctx->iterator_proto);\n        JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_MAP_ITERATOR + i],\n                                   js_map_proto_funcs_ptr[i + 4],\n                                   js_map_proto_funcs_count[i + 4]);\n    }\n}\n\n/* Generator */\nstatic const JSCFunctionListEntry js_generator_function_proto_funcs[] = {\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"GeneratorFunction\", JS_PROP_CONFIGURABLE),\n};\n\nstatic const JSCFunctionListEntry js_generator_proto_funcs[] = {\n    JS_ITERATOR_NEXT_DEF(\"next\", 1, js_generator_next, GEN_MAGIC_NEXT ),\n    JS_ITERATOR_NEXT_DEF(\"return\", 1, js_generator_next, GEN_MAGIC_RETURN ),\n    JS_ITERATOR_NEXT_DEF(\"throw\", 1, js_generator_next, GEN_MAGIC_THROW ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Generator\", JS_PROP_CONFIGURABLE),\n};\n\n/* Promise */\n\ntypedef enum JSPromiseStateEnum {\n    JS_PROMISE_PENDING,\n    JS_PROMISE_FULFILLED,\n    JS_PROMISE_REJECTED,\n} JSPromiseStateEnum;\n\ntypedef struct JSPromiseData {\n    JSPromiseStateEnum promise_state;\n    /* 0=fulfill, 1=reject, list of JSPromiseReactionData.link */\n    struct list_head promise_reactions[2];\n    BOOL is_handled; /* Note: only useful to debug */\n    JSValue promise_result;\n} JSPromiseData;\n\ntypedef struct JSPromiseFunctionDataResolved {\n    int ref_count;\n    BOOL already_resolved;\n} JSPromiseFunctionDataResolved;\n\ntypedef struct JSPromiseFunctionData {\n    JSValue promise;\n    JSPromiseFunctionDataResolved *presolved;\n} JSPromiseFunctionData;\n\ntypedef struct JSPromiseReactionData {\n    struct list_head link; /* not used in promise_reaction_job */\n    JSValue resolving_funcs[2];\n    JSValue handler;\n} JSPromiseReactionData;\n\nstatic int js_create_resolving_functions(JSContext *ctx, JSValue *args,\n                                         JSValueConst promise);\n\nstatic void promise_reaction_data_free(JSRuntime *rt,\n                                       JSPromiseReactionData *rd)\n{\n    JS_FreeValueRT(rt, rd->resolving_funcs[0]);\n    JS_FreeValueRT(rt, rd->resolving_funcs[1]);\n    JS_FreeValueRT(rt, rd->handler);\n    js_free_rt(rt, rd);\n}\n\nstatic JSValue promise_reaction_job(JSContext *ctx, int argc,\n                                    JSValueConst *argv)\n{\n    JSValueConst handler, arg, func;\n    JSValue res, res2;\n    BOOL is_reject;\n\n    assert(argc == 5);\n    handler = argv[2];\n    is_reject = JS_ToBool(ctx, argv[3]);\n    arg = argv[4];\n#ifdef DUMP_PROMISE\n    printf(\"promise_reaction_job: is_reject=%d\\n\", is_reject);\n#endif\n\n    if (JS_IsUndefined(handler)) {\n        if (is_reject) {\n            res = JS_Throw(ctx, JS_DupValue(ctx, arg));\n        } else {\n            res = JS_DupValue(ctx, arg);\n        }\n    } else {\n        res = JS_Call(ctx, handler, JS_UNDEFINED, 1, &arg);\n    }\n    is_reject = JS_IsException(res);\n    if (is_reject)\n        res = JS_GetException(ctx);\n    func = argv[is_reject];\n    /* as an extension, we support undefined as value to avoid\n       creating a dummy promise in the 'await' implementation of async\n       functions */\n    if (!JS_IsUndefined(func)) {\n        res2 = JS_Call(ctx, func, JS_UNDEFINED,\n                       1, (JSValueConst *)&res);\n    } else {\n        res2 = JS_UNDEFINED;\n    }\n    JS_FreeValue(ctx, res);\n\n    return res2;\n}\n\nvoid JS_SetHostPromiseRejectionTracker(JSRuntime *rt,\n                                       JSHostPromiseRejectionTracker *cb,\n                                       void *opaque)\n{\n    rt->host_promise_rejection_tracker = cb;\n    rt->host_promise_rejection_tracker_opaque = opaque;\n}\n\nstatic void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise,\n                                      JSValueConst value, BOOL is_reject)\n{\n    JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);\n    struct list_head *el, *el1;\n    JSPromiseReactionData *rd;\n    JSValueConst args[5];\n\n    if (!s || s->promise_state != JS_PROMISE_PENDING)\n        return; /* should never happen */\n    set_value(ctx, &s->promise_result, JS_DupValue(ctx, value));\n    s->promise_state = JS_PROMISE_FULFILLED + is_reject;\n#ifdef DUMP_PROMISE\n    printf(\"fulfill_or_reject_promise: is_reject=%d\\n\", is_reject);\n#endif\n    if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {\n        JSRuntime *rt = ctx->rt;\n        if (rt->host_promise_rejection_tracker) {\n            rt->host_promise_rejection_tracker(ctx, promise, value, FALSE,\n                                               rt->host_promise_rejection_tracker_opaque);\n        }\n    }\n\n    list_for_each_safe(el, el1, &s->promise_reactions[is_reject]) {\n        rd = list_entry(el, JSPromiseReactionData, link);\n        args[0] = rd->resolving_funcs[0];\n        args[1] = rd->resolving_funcs[1];\n        args[2] = rd->handler;\n        args[3] = JS_NewBool(ctx, is_reject);\n        args[4] = value;\n        JS_EnqueueJob(ctx, promise_reaction_job, 5, args);\n        list_del(&rd->link);\n        promise_reaction_data_free(ctx->rt, rd);\n    }\n\n    list_for_each_safe(el, el1, &s->promise_reactions[1 - is_reject]) {\n        rd = list_entry(el, JSPromiseReactionData, link);\n        list_del(&rd->link);\n        promise_reaction_data_free(ctx->rt, rd);\n    }\n}\n\nstatic void reject_promise(JSContext *ctx, JSValueConst promise,\n                           JSValueConst value)\n{\n    fulfill_or_reject_promise(ctx, promise, value, TRUE);\n}\n\nstatic JSValue js_promise_resolve_thenable_job(JSContext *ctx,\n                                               int argc, JSValueConst *argv)\n{\n    JSValueConst promise, thenable, then;\n    JSValue args[2], res;\n\n#ifdef DUMP_PROMISE\n    printf(\"js_promise_resolve_thenable_job\\n\");\n#endif\n    assert(argc == 3);\n    promise = argv[0];\n    thenable = argv[1];\n    then = argv[2];\n    if (js_create_resolving_functions(ctx, args, promise) < 0)\n        return JS_EXCEPTION;\n    res = JS_Call(ctx, then, thenable, 2, (JSValueConst *)args);\n    if (JS_IsException(res)) {\n        JSValue error = JS_GetException(ctx);\n        res = JS_Call(ctx, args[1], JS_UNDEFINED, 1, (JSValueConst *)&error);\n        JS_FreeValue(ctx, error);\n    }\n    JS_FreeValue(ctx, args[0]);\n    JS_FreeValue(ctx, args[1]);\n    return res;\n}\n\nstatic void js_promise_resolve_function_free_resolved(JSRuntime *rt,\n                                                      JSPromiseFunctionDataResolved *sr)\n{\n    if (--sr->ref_count == 0) {\n        js_free_rt(rt, sr);\n    }\n}\n\nstatic int js_create_resolving_functions(JSContext *ctx,\n                                         JSValue *resolving_funcs,\n                                         JSValueConst promise)\n\n{\n    JSValue obj;\n    JSPromiseFunctionData *s;\n    JSPromiseFunctionDataResolved *sr;\n    int i, ret;\n\n    sr = js_malloc(ctx, sizeof(*sr));\n    if (!sr)\n        return -1;\n    sr->ref_count = 1;\n    sr->already_resolved = FALSE; /* must be shared between the two functions */\n    ret = 0;\n    for(i = 0; i < 2; i++) {\n        obj = JS_NewObjectProtoClass(ctx, ctx->function_proto,\n                                     JS_CLASS_PROMISE_RESOLVE_FUNCTION + i);\n        if (JS_IsException(obj))\n            goto fail;\n        s = js_malloc(ctx, sizeof(*s));\n        if (!s) {\n            JS_FreeValue(ctx, obj);\n        fail:\n\n            if (i != 0)\n                JS_FreeValue(ctx, resolving_funcs[0]);\n            ret = -1;\n            break;\n        }\n        sr->ref_count++;\n        s->presolved = sr;\n        s->promise = JS_DupValue(ctx, promise);\n        JS_SetOpaque(obj, s);\n        js_function_set_properties(ctx, obj, JS_ATOM_empty_string, 1);\n        resolving_funcs[i] = obj;\n    }\n    js_promise_resolve_function_free_resolved(ctx->rt, sr);\n    return ret;\n}\n\nstatic void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSPromiseFunctionData *s = JS_VALUE_GET_OBJ(val)->u.promise_function_data;\n    if (s) {\n        js_promise_resolve_function_free_resolved(rt, s->presolved);\n        JS_FreeValueRT(rt, s->promise);\n        js_free_rt(rt, s);\n    }\n}\n\nstatic void js_promise_resolve_function_mark(JSRuntime *rt, JSValueConst val,\n                                             JS_MarkFunc *mark_func)\n{\n    JSPromiseFunctionData *s = JS_VALUE_GET_OBJ(val)->u.promise_function_data;\n    if (s) {\n        JS_MarkValue(rt, s->promise, mark_func);\n    }\n}\n\nstatic JSValue js_promise_resolve_function_call(JSContext *ctx,\n                                                JSValueConst func_obj,\n                                                JSValueConst this_val,\n                                                int argc, JSValueConst *argv,\n                                                int flags)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(func_obj);\n    JSPromiseFunctionData *s;\n    JSValueConst resolution, args[3];\n    JSValue then;\n    BOOL is_reject;\n\n    s = p->u.promise_function_data;\n    if (!s || s->presolved->already_resolved)\n        return JS_UNDEFINED;\n    s->presolved->already_resolved = TRUE;\n    is_reject = p->class_id - JS_CLASS_PROMISE_RESOLVE_FUNCTION;\n    if (argc > 0)\n        resolution = argv[0];\n    else\n        resolution = JS_UNDEFINED;\n#ifdef DUMP_PROMISE\n    printf(\"js_promise_resolving_function_call: is_reject=%d resolution=\", is_reject);\n    JS_DumpValue(ctx, resolution);\n    printf(\"\\n\");\n#endif\n    if (is_reject || !JS_IsObject(resolution)) {\n        goto done;\n    } else if (js_same_value(ctx, resolution, s->promise)) {\n        JS_ThrowTypeError(ctx, \"promise self resolution\");\n        goto fail_reject;\n    }\n    then = JS_GetProperty(ctx, resolution, JS_ATOM_then);\n    if (JS_IsException(then)) {\n        JSValue error;\n    fail_reject:\n        error = JS_GetException(ctx);\n        reject_promise(ctx, s->promise, error);\n        JS_FreeValue(ctx, error);\n    } else if (!JS_IsFunction(ctx, then)) {\n        JS_FreeValue(ctx, then);\n    done:\n        fulfill_or_reject_promise(ctx, s->promise, resolution, is_reject);\n    } else {\n        args[0] = s->promise;\n        args[1] = resolution;\n        args[2] = then;\n        JS_EnqueueJob(ctx, js_promise_resolve_thenable_job, 3, args);\n        JS_FreeValue(ctx, then);\n    }\n    return JS_UNDEFINED;\n}\n\nstatic void js_promise_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSPromiseData *s = JS_GetOpaque(val, JS_CLASS_PROMISE);\n    struct list_head *el, *el1;\n    int i;\n\n    if (!s)\n        return;\n    for(i = 0; i < 2; i++) {\n        list_for_each_safe(el, el1, &s->promise_reactions[i]) {\n            JSPromiseReactionData *rd =\n                list_entry(el, JSPromiseReactionData, link);\n            promise_reaction_data_free(rt, rd);\n        }\n    }\n    JS_FreeValueRT(rt, s->promise_result);\n    js_free_rt(rt, s);\n}\n\nstatic void js_promise_mark(JSRuntime *rt, JSValueConst val,\n                            JS_MarkFunc *mark_func)\n{\n    JSPromiseData *s = JS_GetOpaque(val, JS_CLASS_PROMISE);\n    struct list_head *el;\n    int i;\n\n    if (!s)\n        return;\n    for(i = 0; i < 2; i++) {\n        list_for_each(el, &s->promise_reactions[i]) {\n            JSPromiseReactionData *rd =\n                list_entry(el, JSPromiseReactionData, link);\n            JS_MarkValue(rt, rd->resolving_funcs[0], mark_func);\n            JS_MarkValue(rt, rd->resolving_funcs[1], mark_func);\n            JS_MarkValue(rt, rd->handler, mark_func);\n        }\n    }\n    JS_MarkValue(rt, s->promise_result, mark_func);\n}\n\nstatic JSValue js_promise_constructor(JSContext *ctx, JSValueConst new_target,\n                                      int argc, JSValueConst *argv)\n{\n    JSValueConst executor;\n    JSValue obj;\n    JSPromiseData *s;\n    JSValue args[2], ret;\n    int i;\n\n    executor = argv[0];\n    if (check_function(ctx, executor))\n        return JS_EXCEPTION;\n    obj = js_create_from_ctor(ctx, new_target, JS_CLASS_PROMISE);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    s = js_mallocz(ctx, sizeof(*s));\n    if (!s)\n        goto fail;\n    s->promise_state = JS_PROMISE_PENDING;\n    s->is_handled = FALSE;\n    for(i = 0; i < 2; i++)\n        init_list_head(&s->promise_reactions[i]);\n    s->promise_result = JS_UNDEFINED;\n    JS_SetOpaque(obj, s);\n    if (js_create_resolving_functions(ctx, args, obj))\n        goto fail;\n    ret = JS_Call(ctx, executor, JS_UNDEFINED, 2, (JSValueConst *)args);\n    if (JS_IsException(ret)) {\n        JSValue ret2, error;\n        error = JS_GetException(ctx);\n        ret2 = JS_Call(ctx, args[1], JS_UNDEFINED, 1, (JSValueConst *)&error);\n        JS_FreeValue(ctx, error);\n        if (JS_IsException(ret2))\n            goto fail1;\n        JS_FreeValue(ctx, ret2);\n    }\n    JS_FreeValue(ctx, ret);\n    JS_FreeValue(ctx, args[0]);\n    JS_FreeValue(ctx, args[1]);\n    return obj;\n fail1:\n    JS_FreeValue(ctx, args[0]);\n    JS_FreeValue(ctx, args[1]);\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_promise_executor(JSContext *ctx,\n                                   JSValueConst this_val,\n                                   int argc, JSValueConst *argv,\n                                   int magic, JSValue *func_data)\n{\n    int i;\n\n    for(i = 0; i < 2; i++) {\n        if (!JS_IsUndefined(func_data[i]))\n            return JS_ThrowTypeError(ctx, \"resolving function already set\");\n        func_data[i] = JS_DupValue(ctx, argv[i]);\n    }\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_promise_executor_new(JSContext *ctx)\n{\n    JSValueConst func_data[2];\n\n    func_data[0] = JS_UNDEFINED;\n    func_data[1] = JS_UNDEFINED;\n    return JS_NewCFunctionData(ctx, js_promise_executor, 2,\n                               0, 2, func_data);\n}\n\nstatic JSValue js_new_promise_capability(JSContext *ctx,\n                                         JSValue *resolving_funcs,\n                                         JSValueConst ctor)\n{\n    JSValue executor, result_promise;\n    JSCFunctionDataRecord *s;\n    int i;\n\n    executor = js_promise_executor_new(ctx);\n    if (JS_IsException(executor))\n        return executor;\n\n    if (JS_IsUndefined(ctor)) {\n        result_promise = js_promise_constructor(ctx, ctor, 1,\n                                                (JSValueConst *)&executor);\n    } else {\n        result_promise = JS_CallConstructor(ctx, ctor, 1,\n                                            (JSValueConst *)&executor);\n    }\n    if (JS_IsException(result_promise))\n        goto fail;\n    s = JS_GetOpaque(executor, JS_CLASS_C_FUNCTION_DATA);\n    for(i = 0; i < 2; i++) {\n        if (check_function(ctx, s->data[i]))\n            goto fail;\n    }\n    for(i = 0; i < 2; i++)\n        resolving_funcs[i] = JS_DupValue(ctx, s->data[i]);\n    JS_FreeValue(ctx, executor);\n    return result_promise;\n fail:\n    JS_FreeValue(ctx, executor);\n    JS_FreeValue(ctx, result_promise);\n    return JS_EXCEPTION;\n}\n\nJSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs)\n{\n    return js_new_promise_capability(ctx, resolving_funcs, JS_UNDEFINED);\n}\n\nstatic JSValue js_promise_resolve(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv, int magic)\n{\n    JSValue result_promise, resolving_funcs[2], ret;\n    BOOL is_reject = magic;\n\n    if (!JS_IsObject(this_val))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    if (!is_reject && JS_GetOpaque(argv[0], JS_CLASS_PROMISE)) {\n        JSValue ctor;\n        BOOL is_same;\n        ctor = JS_GetProperty(ctx, argv[0], JS_ATOM_constructor);\n        if (JS_IsException(ctor))\n            return ctor;\n        is_same = js_same_value(ctx, ctor, this_val);\n        JS_FreeValue(ctx, ctor);\n        if (is_same)\n            return JS_DupValue(ctx, argv[0]);\n    }\n    result_promise = js_new_promise_capability(ctx, resolving_funcs, this_val);\n    if (JS_IsException(result_promise))\n        return result_promise;\n    ret = JS_Call(ctx, resolving_funcs[is_reject], JS_UNDEFINED, 1, argv);\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    if (JS_IsException(ret)) {\n        JS_FreeValue(ctx, result_promise);\n        return ret;\n    }\n    JS_FreeValue(ctx, ret);\n    return result_promise;\n}\n\n#if 0\nstatic JSValue js_promise___newPromiseCapability(JSContext *ctx,\n                                                 JSValueConst this_val,\n                                                 int argc, JSValueConst *argv)\n{\n    JSValue result_promise, resolving_funcs[2], obj;\n    JSValueConst ctor;\n    ctor = argv[0];\n    if (!JS_IsObject(ctor))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    result_promise = js_new_promise_capability(ctx, resolving_funcs, ctor);\n    if (JS_IsException(result_promise))\n        return result_promise;\n    obj = JS_NewObject(ctx);\n    if (JS_IsException(obj)) {\n        JS_FreeValue(ctx, resolving_funcs[0]);\n        JS_FreeValue(ctx, resolving_funcs[1]);\n        JS_FreeValue(ctx, result_promise);\n        return JS_EXCEPTION;\n    }\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_promise, result_promise, JS_PROP_C_W_E);\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_resolve, resolving_funcs[0], JS_PROP_C_W_E);\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_reject, resolving_funcs[1], JS_PROP_C_W_E);\n    return obj;\n}\n#endif\n\nstatic __exception int remainingElementsCount_add(JSContext *ctx,\n                                                  JSValueConst resolve_element_env,\n                                                  int addend)\n{\n    JSValue val;\n    int remainingElementsCount;\n\n    val = JS_GetPropertyUint32(ctx, resolve_element_env, 0);\n    if (JS_IsException(val))\n        return -1;\n    if (JS_ToInt32Free(ctx, &remainingElementsCount, val))\n        return -1;\n    remainingElementsCount += addend;\n    if (JS_SetPropertyUint32(ctx, resolve_element_env, 0,\n                             JS_NewInt32(ctx, remainingElementsCount)) < 0)\n        return -1;\n    return (remainingElementsCount == 0);\n}\n\n#define PROMISE_MAGIC_all        0\n#define PROMISE_MAGIC_allSettled 1\n#define PROMISE_MAGIC_any        2\n\nstatic JSValue js_promise_all_resolve_element(JSContext *ctx,\n                                              JSValueConst this_val,\n                                              int argc, JSValueConst *argv,\n                                              int magic,\n                                              JSValue *func_data)\n{\n    int resolve_type = magic & 3;\n    int is_reject = magic & 4;\n    BOOL alreadyCalled = JS_ToBool(ctx, func_data[0]);\n    JSValueConst values = func_data[2];\n    JSValueConst resolve = func_data[3];\n    JSValueConst resolve_element_env = func_data[4];\n    JSValue ret, obj;\n    int is_zero, index;\n    \n    if (JS_ToInt32(ctx, &index, func_data[1]))\n        return JS_EXCEPTION;\n    if (alreadyCalled)\n        return JS_UNDEFINED;\n    func_data[0] = JS_NewBool(ctx, TRUE);\n\n    if (resolve_type == PROMISE_MAGIC_allSettled) {\n        JSValue str;\n        \n        obj = JS_NewObject(ctx);\n        if (JS_IsException(obj))\n            return JS_EXCEPTION;\n        str = JS_NewString(ctx, is_reject ? \"rejected\" : \"fulfilled\");\n        if (JS_IsException(str))\n            goto fail1;\n        if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_status,\n                                   str,\n                                   JS_PROP_C_W_E) < 0)\n            goto fail1;\n        if (JS_DefinePropertyValue(ctx, obj,\n                                   is_reject ? JS_ATOM_reason : JS_ATOM_value,\n                                   JS_DupValue(ctx, argv[0]),\n                                   JS_PROP_C_W_E) < 0) {\n        fail1:\n            JS_FreeValue(ctx, obj);\n            return JS_EXCEPTION;\n        }\n    } else {\n        obj = JS_DupValue(ctx, argv[0]);\n    }\n    if (JS_DefinePropertyValueUint32(ctx, values, index,\n                                     obj, JS_PROP_C_W_E) < 0)\n        return JS_EXCEPTION;\n    \n    is_zero = remainingElementsCount_add(ctx, resolve_element_env, -1);\n    if (is_zero < 0)\n        return JS_EXCEPTION;\n    if (is_zero) {\n        if (resolve_type == PROMISE_MAGIC_any) {\n            JSValue error;\n            error = js_aggregate_error_constructor(ctx, values);\n            if (JS_IsException(error))\n                return JS_EXCEPTION;\n            ret = JS_Call(ctx, resolve, JS_UNDEFINED, 1, (JSValueConst *)&error);\n            JS_FreeValue(ctx, error);\n        } else {\n            ret = JS_Call(ctx, resolve, JS_UNDEFINED, 1, (JSValueConst *)&values);\n        }\n        if (JS_IsException(ret))\n            return ret;\n        JS_FreeValue(ctx, ret);\n    }\n    return JS_UNDEFINED;\n}\n\n/* magic = 0: Promise.all 1: Promise.allSettled */\nstatic JSValue js_promise_all(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int magic)\n{\n    JSValue result_promise, resolving_funcs[2], item, next_promise, ret;\n    JSValue next_method = JS_UNDEFINED, values = JS_UNDEFINED;\n    JSValue resolve_element_env = JS_UNDEFINED, resolve_element, reject_element;\n    JSValue promise_resolve = JS_UNDEFINED, iter = JS_UNDEFINED;\n    JSValueConst then_args[2], resolve_element_data[5];\n    BOOL done;\n    int index, is_zero, is_promise_any = (magic == PROMISE_MAGIC_any);\n    \n    if (!JS_IsObject(this_val))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    result_promise = js_new_promise_capability(ctx, resolving_funcs, this_val);\n    if (JS_IsException(result_promise))\n        return result_promise;\n    promise_resolve = JS_GetProperty(ctx, this_val, JS_ATOM_resolve);\n    if (JS_IsException(promise_resolve) ||\n        check_function(ctx, promise_resolve))\n        goto fail_reject;\n    iter = JS_GetIterator(ctx, argv[0], FALSE);\n    if (JS_IsException(iter)) {\n        JSValue error;\n    fail_reject:\n        error = JS_GetException(ctx);\n        ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1,\n                       (JSValueConst *)&error);\n        JS_FreeValue(ctx, error);\n        if (JS_IsException(ret))\n            goto fail;\n        JS_FreeValue(ctx, ret);\n    } else {\n        next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);\n        if (JS_IsException(next_method))\n            goto fail_reject;\n        values = JS_NewArray(ctx);\n        if (JS_IsException(values))\n            goto fail_reject;\n        resolve_element_env = JS_NewArray(ctx);\n        if (JS_IsException(resolve_element_env))\n            goto fail_reject;\n        /* remainingElementsCount field */\n        if (JS_DefinePropertyValueUint32(ctx, resolve_element_env, 0,\n                                         JS_NewInt32(ctx, 1),\n                                         JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE | JS_PROP_WRITABLE) < 0)\n            goto fail_reject;\n        \n        index = 0;\n        for(;;) {\n            /* XXX: conformance: should close the iterator if error on 'done'\n               access, but not on 'value' access */\n            item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);\n            if (JS_IsException(item))\n                goto fail_reject;\n            if (done)\n                break;\n            next_promise = JS_Call(ctx, promise_resolve, \n                                   this_val, 1, (JSValueConst *)&item);\n            JS_FreeValue(ctx, item);\n            if (JS_IsException(next_promise)) {\n            fail_reject1:\n                JS_IteratorClose(ctx, iter, TRUE);\n                goto fail_reject;\n            }\n            resolve_element_data[0] = JS_NewBool(ctx, FALSE);\n            resolve_element_data[1] = (JSValueConst)JS_NewInt32(ctx, index);\n            resolve_element_data[2] = values;\n            resolve_element_data[3] = resolving_funcs[is_promise_any];\n            resolve_element_data[4] = resolve_element_env;\n            resolve_element =\n                JS_NewCFunctionData(ctx, js_promise_all_resolve_element, 1,\n                                    magic, 5, resolve_element_data);\n            if (JS_IsException(resolve_element)) {\n                JS_FreeValue(ctx, next_promise);\n                goto fail_reject1;\n            }\n            \n            if (magic == PROMISE_MAGIC_allSettled) {\n                reject_element =\n                    JS_NewCFunctionData(ctx, js_promise_all_resolve_element, 1,\n                                        magic | 4, 5, resolve_element_data);\n                if (JS_IsException(reject_element)) {\n                    JS_FreeValue(ctx, next_promise);\n                    goto fail_reject1;\n                }\n            } else if (magic == PROMISE_MAGIC_any) {\n                if (JS_DefinePropertyValueUint32(ctx, values, index,\n                                                 JS_UNDEFINED, JS_PROP_C_W_E) < 0)\n                    goto fail_reject1;\n                reject_element = resolve_element;\n                resolve_element = JS_DupValue(ctx, resolving_funcs[0]);\n            } else {\n                reject_element = JS_DupValue(ctx, resolving_funcs[1]);\n            }\n\n            if (remainingElementsCount_add(ctx, resolve_element_env, 1) < 0) {\n                JS_FreeValue(ctx, next_promise);\n                JS_FreeValue(ctx, resolve_element);\n                JS_FreeValue(ctx, reject_element);\n                goto fail_reject1;\n            }\n\n            then_args[0] = resolve_element;\n            then_args[1] = reject_element;\n            ret = JS_InvokeFree(ctx, next_promise, JS_ATOM_then, 2, then_args);\n            JS_FreeValue(ctx, resolve_element);\n            JS_FreeValue(ctx, reject_element);\n            if (check_exception_free(ctx, ret))\n                goto fail_reject1;\n            index++;\n        }\n\n        is_zero = remainingElementsCount_add(ctx, resolve_element_env, -1);\n        if (is_zero < 0)\n            goto fail_reject;\n        if (is_zero) {\n            if (magic == PROMISE_MAGIC_any) {\n                JSValue error;\n                error = js_aggregate_error_constructor(ctx, values);\n                if (JS_IsException(error))\n                    goto fail_reject;\n                JS_FreeValue(ctx, values);\n                values = error;\n            }\n            ret = JS_Call(ctx, resolving_funcs[is_promise_any], JS_UNDEFINED,\n                          1, (JSValueConst *)&values);\n            if (check_exception_free(ctx, ret))\n                goto fail_reject;\n        }\n    }\n done:\n    JS_FreeValue(ctx, promise_resolve);\n    JS_FreeValue(ctx, resolve_element_env);\n    JS_FreeValue(ctx, values);\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    return result_promise;\n fail:\n    JS_FreeValue(ctx, result_promise);\n    result_promise = JS_EXCEPTION;\n    goto done;\n}\n\nstatic JSValue js_promise_race(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    JSValue result_promise, resolving_funcs[2], item, next_promise, ret;\n    JSValue next_method = JS_UNDEFINED, iter = JS_UNDEFINED;\n    JSValue promise_resolve = JS_UNDEFINED;\n    BOOL done;\n\n    if (!JS_IsObject(this_val))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n    result_promise = js_new_promise_capability(ctx, resolving_funcs, this_val);\n    if (JS_IsException(result_promise))\n        return result_promise;\n    promise_resolve = JS_GetProperty(ctx, this_val, JS_ATOM_resolve);\n    if (JS_IsException(promise_resolve) ||\n        check_function(ctx, promise_resolve))\n        goto fail_reject;\n    iter = JS_GetIterator(ctx, argv[0], FALSE);\n    if (JS_IsException(iter)) {\n        JSValue error;\n    fail_reject:\n        error = JS_GetException(ctx);\n        ret = JS_Call(ctx, resolving_funcs[1], JS_UNDEFINED, 1,\n                       (JSValueConst *)&error);\n        JS_FreeValue(ctx, error);\n        if (JS_IsException(ret))\n            goto fail;\n        JS_FreeValue(ctx, ret);\n    } else {\n        next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);\n        if (JS_IsException(next_method))\n            goto fail_reject;\n\n        for(;;) {\n            /* XXX: conformance: should close the iterator if error on 'done'\n               access, but not on 'value' access */\n            item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);\n            if (JS_IsException(item))\n                goto fail_reject;\n            if (done)\n                break;\n            next_promise = JS_Call(ctx, promise_resolve,\n                                   this_val, 1, (JSValueConst *)&item);\n            JS_FreeValue(ctx, item);\n            if (JS_IsException(next_promise)) {\n            fail_reject1:\n                JS_IteratorClose(ctx, iter, TRUE);\n                goto fail_reject;\n            }\n            ret = JS_InvokeFree(ctx, next_promise, JS_ATOM_then, 2,\n                                (JSValueConst *)resolving_funcs);\n            if (check_exception_free(ctx, ret))\n                goto fail_reject1;\n        }\n    }\n done:\n    JS_FreeValue(ctx, promise_resolve);\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    return result_promise;\n fail:\n    //JS_FreeValue(ctx, next_method); // why not???\n    JS_FreeValue(ctx, result_promise);\n    result_promise = JS_EXCEPTION;\n    goto done;\n}\n\nstatic __exception int perform_promise_then(JSContext *ctx,\n                                            JSValueConst promise,\n                                            JSValueConst *resolve_reject,\n                                            JSValueConst *cap_resolving_funcs)\n{\n    JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);\n    JSPromiseReactionData *rd_array[2], *rd;\n    int i, j;\n\n    rd_array[0] = NULL;\n    rd_array[1] = NULL;\n    for(i = 0; i < 2; i++) {\n        JSValueConst handler;\n        rd = js_mallocz(ctx, sizeof(*rd));\n        if (!rd) {\n            if (i == 1)\n                promise_reaction_data_free(ctx->rt, rd_array[0]);\n            return -1;\n        }\n        for(j = 0; j < 2; j++)\n            rd->resolving_funcs[j] = JS_DupValue(ctx, cap_resolving_funcs[j]);\n        handler = resolve_reject[i];\n        if (!JS_IsFunction(ctx, handler))\n            handler = JS_UNDEFINED;\n        rd->handler = JS_DupValue(ctx, handler);\n        rd_array[i] = rd;\n    }\n\n    if (s->promise_state == JS_PROMISE_PENDING) {\n        for(i = 0; i < 2; i++)\n            list_add_tail(&rd_array[i]->link, &s->promise_reactions[i]);\n    } else {\n        JSValueConst args[5];\n        if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {\n            JSRuntime *rt = ctx->rt;\n            if (rt->host_promise_rejection_tracker) {\n                rt->host_promise_rejection_tracker(ctx, promise, s->promise_result,\n                                                   TRUE, rt->host_promise_rejection_tracker_opaque);\n            }\n        }\n        i = s->promise_state - JS_PROMISE_FULFILLED;\n        rd = rd_array[i];\n        args[0] = rd->resolving_funcs[0];\n        args[1] = rd->resolving_funcs[1];\n        args[2] = rd->handler;\n        args[3] = JS_NewBool(ctx, i);\n        args[4] = s->promise_result;\n        JS_EnqueueJob(ctx, promise_reaction_job, 5, args);\n        for(i = 0; i < 2; i++)\n            promise_reaction_data_free(ctx->rt, rd_array[i]);\n    }\n    s->is_handled = TRUE;\n    return 0;\n}\n\nstatic JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    JSValue ctor, result_promise, resolving_funcs[2];\n    JSPromiseData *s;\n    int i, ret;\n\n    s = JS_GetOpaque2(ctx, this_val, JS_CLASS_PROMISE);\n    if (!s)\n        return JS_EXCEPTION;\n\n    ctor = JS_SpeciesConstructor(ctx, this_val, JS_UNDEFINED);\n    if (JS_IsException(ctor))\n        return ctor;\n    result_promise = js_new_promise_capability(ctx, resolving_funcs, ctor);\n    JS_FreeValue(ctx, ctor);\n    if (JS_IsException(result_promise))\n        return result_promise;\n    ret = perform_promise_then(ctx, this_val, argv,\n                               (JSValueConst *)resolving_funcs);\n    for(i = 0; i < 2; i++)\n        JS_FreeValue(ctx, resolving_funcs[i]);\n    if (ret) {\n        JS_FreeValue(ctx, result_promise);\n        return JS_EXCEPTION;\n    }\n    return result_promise;\n}\n\nstatic JSValue js_promise_catch(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValueConst args[2];\n    args[0] = JS_UNDEFINED;\n    args[1] = argv[0];\n    return JS_Invoke(ctx, this_val, JS_ATOM_then, 2, args);\n}\n\nstatic JSValue js_promise_finally_value_thunk(JSContext *ctx, JSValueConst this_val,\n                                              int argc, JSValueConst *argv,\n                                              int magic, JSValue *func_data)\n{\n    return JS_DupValue(ctx, func_data[0]);\n}\n\nstatic JSValue js_promise_finally_thrower(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv,\n                                          int magic, JSValue *func_data)\n{\n    return JS_Throw(ctx, JS_DupValue(ctx, func_data[0]));\n}\n\nstatic JSValue js_promise_then_finally_func(JSContext *ctx, JSValueConst this_val,\n                                            int argc, JSValueConst *argv,\n                                            int magic, JSValue *func_data)\n{\n    JSValueConst ctor = func_data[0];\n    JSValueConst onFinally = func_data[1];\n    JSValue res, promise, resolving_funcs[2], ret, then_func;\n\n    res = JS_Call(ctx, onFinally, JS_UNDEFINED, 0, NULL);\n    if (JS_IsException(res))\n        return res;\n    promise = js_new_promise_capability(ctx, resolving_funcs, ctor);\n    if (JS_IsException(promise)) {\n        JS_FreeValue(ctx, res);\n        return JS_EXCEPTION;\n    }\n    ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED,\n                  1, (JSValueConst*)&res);\n    JS_FreeValue(ctx, res);\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    if (JS_IsException(ret)) {\n        JS_FreeValue(ctx, promise);\n        return ret;\n    }\n    JS_FreeValue(ctx, ret);\n    if (magic == 0) {\n        then_func = JS_NewCFunctionData(ctx, js_promise_finally_value_thunk, 0,\n                                        0, 1, argv);\n    } else {\n        then_func = JS_NewCFunctionData(ctx, js_promise_finally_thrower, 0,\n                                        0, 1, argv);\n    }\n    if (JS_IsException(then_func)) {\n        JS_FreeValue(ctx, promise);\n        return then_func;\n    }\n    ret = JS_InvokeFree(ctx, promise, JS_ATOM_then, 1, (JSValueConst *)&then_func);\n    JS_FreeValue(ctx, then_func);\n    return ret;\n}\n\nstatic JSValue js_promise_finally(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValueConst onFinally = argv[0];\n    JSValue ctor, ret;\n    JSValue then_funcs[2];\n    JSValueConst func_data[2];\n    int i;\n\n    ctor = JS_SpeciesConstructor(ctx, this_val, JS_UNDEFINED);\n    if (JS_IsException(ctor))\n        return ctor;\n    if (!JS_IsFunction(ctx, onFinally)) {\n        then_funcs[0] = JS_DupValue(ctx, onFinally);\n        then_funcs[1] = JS_DupValue(ctx, onFinally);\n    } else {\n        func_data[0] = ctor;\n        func_data[1] = onFinally;\n        for(i = 0; i < 2; i++) {\n            then_funcs[i] = JS_NewCFunctionData(ctx, js_promise_then_finally_func, 1, i, 2, func_data);\n            if (JS_IsException(then_funcs[i])) {\n                if (i == 1)\n                    JS_FreeValue(ctx, then_funcs[0]);\n                JS_FreeValue(ctx, ctor);\n                return JS_EXCEPTION;\n            }\n        }\n    }\n    JS_FreeValue(ctx, ctor);\n    ret = JS_Invoke(ctx, this_val, JS_ATOM_then, 2, (JSValueConst *)then_funcs);\n    JS_FreeValue(ctx, then_funcs[0]);\n    JS_FreeValue(ctx, then_funcs[1]);\n    return ret;\n}\n\nstatic const JSCFunctionListEntry js_promise_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"resolve\", 1, js_promise_resolve, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"reject\", 1, js_promise_resolve, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"all\", 1, js_promise_all, PROMISE_MAGIC_all ),\n    JS_CFUNC_MAGIC_DEF(\"allSettled\", 1, js_promise_all, PROMISE_MAGIC_allSettled ),\n    JS_CFUNC_MAGIC_DEF(\"any\", 1, js_promise_all, PROMISE_MAGIC_any ),\n    JS_CFUNC_DEF(\"race\", 1, js_promise_race ),\n    //JS_CFUNC_DEF(\"__newPromiseCapability\", 1, js_promise___newPromiseCapability ),\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL),\n};\n\nstatic const JSCFunctionListEntry js_promise_proto_funcs[] = {\n    JS_CFUNC_DEF(\"then\", 2, js_promise_then ),\n    JS_CFUNC_DEF(\"catch\", 1, js_promise_catch ),\n    JS_CFUNC_DEF(\"finally\", 1, js_promise_finally ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Promise\", JS_PROP_CONFIGURABLE ),\n};\n\n/* AsyncFunction */\nstatic const JSCFunctionListEntry js_async_function_proto_funcs[] = {\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"AsyncFunction\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic JSValue js_async_from_sync_iterator_unwrap(JSContext *ctx,\n                                                  JSValueConst this_val,\n                                                  int argc, JSValueConst *argv,\n                                                  int magic, JSValue *func_data)\n{\n    return js_create_iterator_result(ctx, JS_DupValue(ctx, argv[0]),\n                                     JS_ToBool(ctx, func_data[0]));\n}\n\nstatic JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx,\n                                                              BOOL done)\n{\n    JSValueConst func_data[1];\n\n    func_data[0] = (JSValueConst)JS_NewBool(ctx, done);\n    return JS_NewCFunctionData(ctx, js_async_from_sync_iterator_unwrap,\n                               1, 0, 1, func_data);\n}\n\n/* AsyncIteratorPrototype */\n\nstatic const JSCFunctionListEntry js_async_iterator_proto_funcs[] = {\n    JS_CFUNC_DEF(\"[Symbol.asyncIterator]\", 0, js_iterator_proto_iterator ),\n};\n\n/* AsyncFromSyncIteratorPrototype */\n\ntypedef struct JSAsyncFromSyncIteratorData {\n    JSValue sync_iter;\n    JSValue next_method;\n} JSAsyncFromSyncIteratorData;\n\nstatic void js_async_from_sync_iterator_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSAsyncFromSyncIteratorData *s =\n        JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR);\n    if (s) {\n        JS_FreeValueRT(rt, s->sync_iter);\n        JS_FreeValueRT(rt, s->next_method);\n        js_free_rt(rt, s);\n    }\n}\n\nstatic void js_async_from_sync_iterator_mark(JSRuntime *rt, JSValueConst val,\n                                             JS_MarkFunc *mark_func)\n{\n    JSAsyncFromSyncIteratorData *s =\n        JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR);\n    if (s) {\n        JS_MarkValue(rt, s->sync_iter, mark_func);\n        JS_MarkValue(rt, s->next_method, mark_func);\n    }\n}\n\nstatic JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx,\n                                              JSValueConst sync_iter)\n{\n    JSValue async_iter, next_method;\n    JSAsyncFromSyncIteratorData *s;\n\n    next_method = JS_GetProperty(ctx, sync_iter, JS_ATOM_next);\n    if (JS_IsException(next_method))\n        return JS_EXCEPTION;\n    async_iter = JS_NewObjectClass(ctx, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR);\n    if (JS_IsException(async_iter)) {\n        JS_FreeValue(ctx, next_method);\n        return async_iter;\n    }\n    s = js_mallocz(ctx, sizeof(*s));\n    if (!s) {\n        JS_FreeValue(ctx, async_iter);\n        JS_FreeValue(ctx, next_method);\n        return JS_EXCEPTION;\n    }\n    s->sync_iter = JS_DupValue(ctx, sync_iter);\n    s->next_method = next_method;\n    JS_SetOpaque(async_iter, s);\n    return async_iter;\n}\n\nstatic JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValueConst this_val,\n                                                int argc, JSValueConst *argv,\n                                                int magic)\n{\n    JSValue promise, resolving_funcs[2], value, err, method;\n    JSAsyncFromSyncIteratorData *s;\n    int done;\n    int is_reject;\n\n    promise = JS_NewPromiseCapability(ctx, resolving_funcs);\n    if (JS_IsException(promise))\n        return JS_EXCEPTION;\n    s = JS_GetOpaque(this_val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR);\n    if (!s) {\n        JS_ThrowTypeError(ctx, \"not an Async-from-Sync Iterator\");\n        goto reject;\n    }\n\n    if (magic == GEN_MAGIC_NEXT) {\n        method = JS_DupValue(ctx, s->next_method);\n    } else {\n        method = JS_GetProperty(ctx, s->sync_iter,\n                                magic == GEN_MAGIC_RETURN ? JS_ATOM_return :\n                                JS_ATOM_throw);\n        if (JS_IsException(method))\n            goto reject;\n        if (JS_IsUndefined(method) || JS_IsNull(method)) {\n            if (magic == GEN_MAGIC_RETURN) {\n                err = js_create_iterator_result(ctx, JS_DupValue(ctx, argv[0]), TRUE);\n                is_reject = 0;\n            } else {\n                err = JS_DupValue(ctx, argv[0]);\n                is_reject = 1;\n            }\n            goto done_resolve;\n        }\n    }\n    value = JS_IteratorNext2(ctx, s->sync_iter, method,\n                             argc >= 1 ? 1 : 0, argv, &done);\n    JS_FreeValue(ctx, method);\n    if (JS_IsException(value))\n        goto reject;\n    if (done == 2) {\n        JSValue obj = value;\n        value = JS_IteratorGetCompleteValue(ctx, obj, &done);\n        JS_FreeValue(ctx, obj);\n        if (JS_IsException(value))\n            goto reject;\n    }\n\n    if (JS_IsException(value)) {\n        JSValue res2;\n    reject:\n        err = JS_GetException(ctx);\n        is_reject = 1;\n    done_resolve:\n        res2 = JS_Call(ctx, resolving_funcs[is_reject], JS_UNDEFINED,\n                       1, (JSValueConst *)&err);\n        JS_FreeValue(ctx, err);\n        JS_FreeValue(ctx, res2);\n        JS_FreeValue(ctx, resolving_funcs[0]);\n        JS_FreeValue(ctx, resolving_funcs[1]);\n        return promise;\n    }\n    {\n        JSValue value_wrapper_promise, resolve_reject[2];\n        int res;\n\n        value_wrapper_promise = js_promise_resolve(ctx, ctx->promise_ctor,\n                                                   1, (JSValueConst *)&value, 0);\n        if (JS_IsException(value_wrapper_promise)) {\n            JS_FreeValue(ctx, value);\n            goto reject;\n        }\n\n        resolve_reject[0] =\n            js_async_from_sync_iterator_unwrap_func_create(ctx, done);\n        if (JS_IsException(resolve_reject[0])) {\n            JS_FreeValue(ctx, value_wrapper_promise);\n            goto fail;\n        }\n        JS_FreeValue(ctx, value);\n        resolve_reject[1] = JS_UNDEFINED;\n\n        res = perform_promise_then(ctx, value_wrapper_promise,\n                                   (JSValueConst *)resolve_reject,\n                                   (JSValueConst *)resolving_funcs);\n        JS_FreeValue(ctx, resolve_reject[0]);\n        JS_FreeValue(ctx, value_wrapper_promise);\n        JS_FreeValue(ctx, resolving_funcs[0]);\n        JS_FreeValue(ctx, resolving_funcs[1]);\n        if (res) {\n            JS_FreeValue(ctx, promise);\n            return JS_EXCEPTION;\n        }\n    }\n    return promise;\n fail:\n    JS_FreeValue(ctx, value);\n    JS_FreeValue(ctx, resolving_funcs[0]);\n    JS_FreeValue(ctx, resolving_funcs[1]);\n    JS_FreeValue(ctx, promise);\n    return JS_EXCEPTION;\n}\n\nstatic const JSCFunctionListEntry js_async_from_sync_iterator_proto_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"next\", 1, js_async_from_sync_iterator_next, GEN_MAGIC_NEXT ),\n    JS_CFUNC_MAGIC_DEF(\"return\", 1, js_async_from_sync_iterator_next, GEN_MAGIC_RETURN ),\n    JS_CFUNC_MAGIC_DEF(\"throw\", 1, js_async_from_sync_iterator_next, GEN_MAGIC_THROW ),\n};\n\n/* AsyncGeneratorFunction */\n\nstatic const JSCFunctionListEntry js_async_generator_function_proto_funcs[] = {\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"AsyncGeneratorFunction\", JS_PROP_CONFIGURABLE ),\n};\n\n/* AsyncGenerator prototype */\n\nstatic const JSCFunctionListEntry js_async_generator_proto_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"next\", 1, js_async_generator_next, GEN_MAGIC_NEXT ),\n    JS_CFUNC_MAGIC_DEF(\"return\", 1, js_async_generator_next, GEN_MAGIC_RETURN ),\n    JS_CFUNC_MAGIC_DEF(\"throw\", 1, js_async_generator_next, GEN_MAGIC_THROW ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"AsyncGenerator\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic JSClassShortDef const js_async_class_def[] = {\n    { JS_ATOM_Promise, js_promise_finalizer, js_promise_mark },                      /* JS_CLASS_PROMISE */\n    { JS_ATOM_PromiseResolveFunction, js_promise_resolve_function_finalizer, js_promise_resolve_function_mark }, /* JS_CLASS_PROMISE_RESOLVE_FUNCTION */\n    { JS_ATOM_PromiseRejectFunction, js_promise_resolve_function_finalizer, js_promise_resolve_function_mark }, /* JS_CLASS_PROMISE_REJECT_FUNCTION */\n    { JS_ATOM_AsyncFunction, js_bytecode_function_finalizer, js_bytecode_function_mark },  /* JS_CLASS_ASYNC_FUNCTION */\n    { JS_ATOM_AsyncFunctionResolve, js_async_function_resolve_finalizer, js_async_function_resolve_mark }, /* JS_CLASS_ASYNC_FUNCTION_RESOLVE */\n    { JS_ATOM_AsyncFunctionReject, js_async_function_resolve_finalizer, js_async_function_resolve_mark }, /* JS_CLASS_ASYNC_FUNCTION_REJECT */\n    { JS_ATOM_empty_string, js_async_from_sync_iterator_finalizer, js_async_from_sync_iterator_mark }, /* JS_CLASS_ASYNC_FROM_SYNC_ITERATOR */\n    { JS_ATOM_AsyncGeneratorFunction, js_bytecode_function_finalizer, js_bytecode_function_mark },  /* JS_CLASS_ASYNC_GENERATOR_FUNCTION */\n    { JS_ATOM_AsyncGenerator, js_async_generator_finalizer, js_async_generator_mark },  /* JS_CLASS_ASYNC_GENERATOR */\n};\n\nvoid JS_AddIntrinsicPromise(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    JSValue obj1;\n\n    if (!JS_IsRegisteredClass(rt, JS_CLASS_PROMISE)) {\n        init_class_range(rt, js_async_class_def, JS_CLASS_PROMISE,\n                         countof(js_async_class_def));\n        rt->class_array[JS_CLASS_PROMISE_RESOLVE_FUNCTION].call = js_promise_resolve_function_call;\n        rt->class_array[JS_CLASS_PROMISE_REJECT_FUNCTION].call = js_promise_resolve_function_call;\n        rt->class_array[JS_CLASS_ASYNC_FUNCTION].call = js_async_function_call;\n        rt->class_array[JS_CLASS_ASYNC_FUNCTION_RESOLVE].call = js_async_function_resolve_call;\n        rt->class_array[JS_CLASS_ASYNC_FUNCTION_REJECT].call = js_async_function_resolve_call;\n        rt->class_array[JS_CLASS_ASYNC_GENERATOR_FUNCTION].call = js_async_generator_function_call;\n    }\n\n    /* Promise */\n    ctx->class_proto[JS_CLASS_PROMISE] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_PROMISE],\n                               js_promise_proto_funcs,\n                               countof(js_promise_proto_funcs));\n    obj1 = JS_NewCFunction2(ctx, js_promise_constructor, \"Promise\", 1,\n                            JS_CFUNC_constructor, 0);\n    ctx->promise_ctor = JS_DupValue(ctx, obj1);\n    JS_SetPropertyFunctionList(ctx, obj1,\n                               js_promise_funcs,\n                               countof(js_promise_funcs));\n    JS_NewGlobalCConstructor2(ctx, obj1, \"Promise\",\n                              ctx->class_proto[JS_CLASS_PROMISE]);\n\n    /* AsyncFunction */\n    ctx->class_proto[JS_CLASS_ASYNC_FUNCTION] = JS_NewObjectProto(ctx, ctx->function_proto);\n    obj1 = JS_NewCFunction3(ctx, (JSCFunction *)js_function_constructor,\n                            \"AsyncFunction\", 1,\n                            JS_CFUNC_constructor_or_func_magic, JS_FUNC_ASYNC,\n                            ctx->function_ctor);\n    JS_SetPropertyFunctionList(ctx,\n                               ctx->class_proto[JS_CLASS_ASYNC_FUNCTION],\n                               js_async_function_proto_funcs,\n                               countof(js_async_function_proto_funcs));\n    JS_SetConstructor2(ctx, obj1, ctx->class_proto[JS_CLASS_ASYNC_FUNCTION],\n                       0, JS_PROP_CONFIGURABLE);\n    JS_FreeValue(ctx, obj1);\n\n    /* AsyncIteratorPrototype */\n    ctx->async_iterator_proto = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->async_iterator_proto,\n                               js_async_iterator_proto_funcs,\n                               countof(js_async_iterator_proto_funcs));\n\n    /* AsyncFromSyncIteratorPrototype */\n    ctx->class_proto[JS_CLASS_ASYNC_FROM_SYNC_ITERATOR] =\n        JS_NewObjectProto(ctx, ctx->async_iterator_proto);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ASYNC_FROM_SYNC_ITERATOR],\n                               js_async_from_sync_iterator_proto_funcs,\n                               countof(js_async_from_sync_iterator_proto_funcs));\n\n    /* AsyncGeneratorPrototype */\n    ctx->class_proto[JS_CLASS_ASYNC_GENERATOR] =\n        JS_NewObjectProto(ctx, ctx->async_iterator_proto);\n    JS_SetPropertyFunctionList(ctx,\n                               ctx->class_proto[JS_CLASS_ASYNC_GENERATOR],\n                               js_async_generator_proto_funcs,\n                               countof(js_async_generator_proto_funcs));\n\n    /* AsyncGeneratorFunction */\n    ctx->class_proto[JS_CLASS_ASYNC_GENERATOR_FUNCTION] =\n        JS_NewObjectProto(ctx, ctx->function_proto);\n    obj1 = JS_NewCFunction3(ctx, (JSCFunction *)js_function_constructor,\n                            \"AsyncGeneratorFunction\", 1,\n                            JS_CFUNC_constructor_or_func_magic,\n                            JS_FUNC_ASYNC_GENERATOR,\n                            ctx->function_ctor);\n    JS_SetPropertyFunctionList(ctx,\n                               ctx->class_proto[JS_CLASS_ASYNC_GENERATOR_FUNCTION],\n                               js_async_generator_function_proto_funcs,\n                               countof(js_async_generator_function_proto_funcs));\n    JS_SetConstructor2(ctx, ctx->class_proto[JS_CLASS_ASYNC_GENERATOR_FUNCTION],\n                       ctx->class_proto[JS_CLASS_ASYNC_GENERATOR],\n                       JS_PROP_CONFIGURABLE, JS_PROP_CONFIGURABLE);\n    JS_SetConstructor2(ctx, obj1, ctx->class_proto[JS_CLASS_ASYNC_GENERATOR_FUNCTION],\n                       0, JS_PROP_CONFIGURABLE);\n    JS_FreeValue(ctx, obj1);\n}\n\n/* URI handling */\n\nstatic int string_get_hex(JSString *p, int k, int n) {\n    int c = 0, h;\n    while (n-- > 0) {\n        if ((h = from_hex(string_get(p, k++))) < 0)\n            return -1;\n        c = (c << 4) | h;\n    }\n    return c;\n}\n\nstatic int isURIReserved(int c) {\n    return c < 0x100 && memchr(\";/?:@&=+$,#\", c, sizeof(\";/?:@&=+$,#\") - 1) != NULL;\n}\n\nstatic int __attribute__((format(printf, 2, 3))) js_throw_URIError(JSContext *ctx, const char *fmt, ...)\n{\n    va_list ap;\n\n    va_start(ap, fmt);\n    JS_ThrowError(ctx, JS_URI_ERROR, fmt, ap);\n    va_end(ap);\n    return -1;\n}\n\nstatic int hex_decode(JSContext *ctx, JSString *p, int k) {\n    int c;\n\n    if (k >= p->len || string_get(p, k) != '%')\n        return js_throw_URIError(ctx, \"expecting %%\");\n    if (k + 2 >= p->len || (c = string_get_hex(p, k + 1, 2)) < 0)\n        return js_throw_URIError(ctx, \"expecting hex digit\");\n\n    return c;\n}\n\nstatic JSValue js_global_decodeURI(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv, int isComponent)\n{\n    JSValue str;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p;\n    int k, c, c1, n, c_min;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        return str;\n\n    string_buffer_init(ctx, b, 0);\n\n    p = JS_VALUE_GET_STRING(str);\n    for (k = 0; k < p->len;) {\n        c = string_get(p, k);\n        if (c == '%') {\n            c = hex_decode(ctx, p, k);\n            if (c < 0)\n                goto fail;\n            k += 3;\n            if (c < 0x80) {\n                if (!isComponent && isURIReserved(c)) {\n                    c = '%';\n                    k -= 2;\n                }\n            } else {\n                /* Decode URI-encoded UTF-8 sequence */\n                if (c >= 0xc0 && c <= 0xdf) {\n                    n = 1;\n                    c_min = 0x80;\n                    c &= 0x1f;\n                } else if (c >= 0xe0 && c <= 0xef) {\n                    n = 2;\n                    c_min = 0x800;\n                    c &= 0xf;\n                } else if (c >= 0xf0 && c <= 0xf7) {\n                    n = 3;\n                    c_min = 0x10000;\n                    c &= 0x7;\n                } else {\n                    n = 0;\n                    c_min = 1;\n                    c = 0;\n                }\n                while (n-- > 0) {\n                    c1 = hex_decode(ctx, p, k);\n                    if (c1 < 0)\n                        goto fail;\n                    k += 3;\n                    if ((c1 & 0xc0) != 0x80) {\n                        c = 0;\n                        break;\n                    }\n                    c = (c << 6) | (c1 & 0x3f);\n                }\n                if (c < c_min || c > 0x10FFFF ||\n                    (c >= 0xd800 && c < 0xe000)) {\n                    js_throw_URIError(ctx, \"malformed UTF-8\");\n                    goto fail;\n                }\n            }\n        } else {\n            k++;\n        }\n        string_buffer_putc(b, c);\n    }\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n\nfail:\n    JS_FreeValue(ctx, str);\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic int isUnescaped(int c) {\n    static char const unescaped_chars[] =\n        \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n        \"abcdefghijklmnopqrstuvwxyz\"\n        \"0123456789\"\n        \"@*_+-./\";\n    return c < 0x100 &&\n        memchr(unescaped_chars, c, sizeof(unescaped_chars) - 1);\n}\n\nstatic int isURIUnescaped(int c, int isComponent) {\n    return c < 0x100 &&\n        ((c >= 0x61 && c <= 0x7a) ||\n         (c >= 0x41 && c <= 0x5a) ||\n         (c >= 0x30 && c <= 0x39) ||\n         memchr(\"-_.!~*'()\", c, sizeof(\"-_.!~*'()\") - 1) != NULL ||\n         (!isComponent && isURIReserved(c)));\n}\n\nstatic int encodeURI_hex(StringBuffer *b, int c) {\n    uint8_t buf[6];\n    int n = 0;\n    const char *hex = \"0123456789ABCDEF\";\n\n    buf[n++] = '%';\n    if (c >= 256) {\n        buf[n++] = 'u';\n        buf[n++] = hex[(c >> 12) & 15];\n        buf[n++] = hex[(c >>  8) & 15];\n    }\n    buf[n++] = hex[(c >> 4) & 15];\n    buf[n++] = hex[(c >> 0) & 15];\n    return string_buffer_write8(b, buf, n);\n}\n\nstatic JSValue js_global_encodeURI(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv,\n                                   int isComponent)\n{\n    JSValue str;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p;\n    int k, c, c1;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        return str;\n\n    p = JS_VALUE_GET_STRING(str);\n    string_buffer_init(ctx, b, p->len);\n    for (k = 0; k < p->len;) {\n        c = string_get(p, k);\n        k++;\n        if (isURIUnescaped(c, isComponent)) {\n            string_buffer_putc16(b, c);\n        } else {\n            if (c >= 0xdc00 && c <= 0xdfff) {\n                js_throw_URIError(ctx, \"invalid character\");\n                goto fail;\n            } else if (c >= 0xd800 && c <= 0xdbff) {\n                if (k >= p->len) {\n                    js_throw_URIError(ctx, \"expecting surrogate pair\");\n                    goto fail;\n                }\n                c1 = string_get(p, k);\n                k++;\n                if (c1 < 0xdc00 || c1 > 0xdfff) {\n                    js_throw_URIError(ctx, \"expecting surrogate pair\");\n                    goto fail;\n                }\n                c = (((c & 0x3ff) << 10) | (c1 & 0x3ff)) + 0x10000;\n            }\n            if (c < 0x80) {\n                encodeURI_hex(b, c);\n            } else {\n                /* XXX: use C UTF-8 conversion ? */\n                if (c < 0x800) {\n                    encodeURI_hex(b, (c >> 6) | 0xc0);\n                } else {\n                    if (c < 0x10000) {\n                        encodeURI_hex(b, (c >> 12) | 0xe0);\n                    } else {\n                        encodeURI_hex(b, (c >> 18) | 0xf0);\n                        encodeURI_hex(b, ((c >> 12) & 0x3f) | 0x80);\n                    }\n                    encodeURI_hex(b, ((c >> 6) & 0x3f) | 0x80);\n                }\n                encodeURI_hex(b, (c & 0x3f) | 0x80);\n            }\n        }\n    }\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n\nfail:\n    JS_FreeValue(ctx, str);\n    string_buffer_free(b);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_global_escape(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    JSValue str;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p;\n    int i, len, c;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        return str;\n\n    p = JS_VALUE_GET_STRING(str);\n    string_buffer_init(ctx, b, p->len);\n    for (i = 0, len = p->len; i < len; i++) {\n        c = string_get(p, i);\n        if (isUnescaped(c)) {\n            string_buffer_putc16(b, c);\n        } else {\n            encodeURI_hex(b, c);\n        }\n    }\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n}\n\nstatic JSValue js_global_unescape(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValue str;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p;\n    int i, len, c, n;\n\n    str = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(str))\n        return str;\n\n    string_buffer_init(ctx, b, 0);\n    p = JS_VALUE_GET_STRING(str);\n    for (i = 0, len = p->len; i < len; i++) {\n        c = string_get(p, i);\n        if (c == '%') {\n            if (i + 6 <= len\n            &&  string_get(p, i + 1) == 'u'\n            &&  (n = string_get_hex(p, i + 2, 4)) >= 0) {\n                c = n;\n                i += 6 - 1;\n            } else\n            if (i + 3 <= len\n            &&  (n = string_get_hex(p, i + 1, 2)) >= 0) {\n                c = n;\n                i += 3 - 1;\n            }\n        }\n        string_buffer_putc16(b, c);\n    }\n    JS_FreeValue(ctx, str);\n    return string_buffer_end(b);\n}\n\n/* global object */\n\nstatic const JSCFunctionListEntry js_global_funcs[] = {\n    JS_CFUNC_DEF(\"parseInt\", 2, js_parseInt ),\n    JS_CFUNC_DEF(\"parseFloat\", 1, js_parseFloat ),\n    JS_CFUNC_DEF(\"isNaN\", 1, js_global_isNaN ),\n    JS_CFUNC_DEF(\"isFinite\", 1, js_global_isFinite ),\n\n    JS_CFUNC_MAGIC_DEF(\"decodeURI\", 1, js_global_decodeURI, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"decodeURIComponent\", 1, js_global_decodeURI, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"encodeURI\", 1, js_global_encodeURI, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"encodeURIComponent\", 1, js_global_encodeURI, 1 ),\n    JS_CFUNC_DEF(\"escape\", 1, js_global_escape ),\n    JS_CFUNC_DEF(\"unescape\", 1, js_global_unescape ),\n    JS_PROP_DOUBLE_DEF(\"Infinity\", 1.0 / 0.0, 0 ),\n    JS_PROP_DOUBLE_DEF(\"NaN\", NAN, 0 ),\n    JS_PROP_UNDEFINED_DEF(\"undefined\", 0 ),\n\n    /* for the 'Date' implementation */\n    JS_CFUNC_DEF(\"__date_clock\", 0, js___date_clock ),\n    //JS_CFUNC_DEF(\"__date_now\", 0, js___date_now ),\n    //JS_CFUNC_DEF(\"__date_getTimezoneOffset\", 1, js___date_getTimezoneOffset ),\n    //JS_CFUNC_DEF(\"__date_create\", 3, js___date_create ),\n};\n\n/* Date */\n\nstatic int64_t math_mod(int64_t a, int64_t b) {\n    /* return positive modulo */\n    int64_t m = a % b;\n    return m + (m < 0) * b;\n}\n\nstatic int64_t floor_div(int64_t a, int64_t b) {\n    /* integer division rounding toward -Infinity */\n    int64_t m = a % b;\n    return (a - (m + (m < 0) * b)) / b;\n}\n\nstatic JSValue js_Date_parse(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv);\n\nstatic __exception int JS_ThisTimeValue(JSContext *ctx, double *valp, JSValueConst this_val)\n{\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_DATE && JS_IsNumber(p->u.object_data))\n            return JS_ToFloat64(ctx, valp, p->u.object_data);\n    }\n    JS_ThrowTypeError(ctx, \"not a Date object\");\n    return -1;\n}\n\nstatic JSValue JS_SetThisTimeValue(JSContext *ctx, JSValueConst this_val, double v)\n{\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_DATE) {\n            JS_FreeValue(ctx, p->u.object_data);\n            p->u.object_data = __JS_NewFloat64(ctx, v);\n            return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a Date object\");\n}\n\nstatic int64_t days_from_year(int64_t y) {\n    return 365 * (y - 1970) + floor_div(y - 1969, 4) -\n        floor_div(y - 1901, 100) + floor_div(y - 1601, 400);\n}\n\nstatic int64_t days_in_year(int64_t y) {\n    return 365 + !(y % 4) - !(y % 100) + !(y % 400);\n}\n\n/* return the year, update days */\nstatic int64_t year_from_days(int64_t *days) {\n    int64_t y, d1, nd, d = *days;\n    y = floor_div(d * 10000, 3652425) + 1970;\n    /* the initial approximation is very good, so only a few\n       iterations are necessary */\n    for(;;) {\n        d1 = d - days_from_year(y);\n        if (d1 < 0) {\n            y--;\n            d1 += days_in_year(y);\n        } else {\n            nd = days_in_year(y);\n            if (d1 < nd)\n                break;\n            d1 -= nd;\n            y++;\n        }\n    }\n    *days = d1;\n    return y;\n}\n\nstatic int const month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\nstatic char const month_names[] = \"JanFebMarAprMayJunJulAugSepOctNovDec\";\nstatic char const day_names[] = \"SunMonTueWedThuFriSat\";\n\nstatic __exception int get_date_fields(JSContext *ctx, JSValueConst obj,\n                                       int64_t fields[9], int is_local, int force)\n{\n    double dval;\n    int64_t d, days, wd, y, i, md, h, m, s, ms, tz = 0;\n\n    if (JS_ThisTimeValue(ctx, &dval, obj))\n        return -1;\n\n    if (isnan(dval)) {\n        if (!force)\n            return FALSE; /* NaN */\n        d = 0;        /* initialize all fields to 0 */\n    } else {\n        d = dval;\n        if (is_local) {\n            tz = -getTimezoneOffset(d);\n            d += tz * 60000;\n        }\n    }\n\n    /* result is >= 0, we can use % */\n    h = math_mod(d, 86400000);\n    days = (d - h) / 86400000;\n    ms = h % 1000;\n    h = (h - ms) / 1000;\n    s = h % 60;\n    h = (h - s) / 60;\n    m = h % 60;\n    h = (h - m) / 60;\n    wd = math_mod(days + 4, 7); /* week day */\n    y = year_from_days(&days);\n\n    for(i = 0; i < 11; i++) {\n        md = month_days[i];\n        if (i == 1)\n            md += days_in_year(y) - 365;\n        if (days < md)\n            break;\n        days -= md;\n    }\n    fields[0] = y;\n    fields[1] = i;\n    fields[2] = days + 1;\n    fields[3] = h;\n    fields[4] = m;\n    fields[5] = s;\n    fields[6] = ms;\n    fields[7] = wd;\n    fields[8] = tz;\n    return TRUE;\n}\n\nstatic double time_clip(double t) {\n    if (t >= -8.64e15 && t <= 8.64e15)\n        return trunc(t) + 0.0;  /* convert -0 to +0 */\n    else\n        return NAN;\n}\n\nstatic double set_date_fields(int64_t fields[], int is_local) {\n    int64_t days, y, m, md, h, d, i;\n\n    i = fields[1];\n    m = math_mod(i, 12);\n    y = fields[0] + (i - m) / 12;\n    days = days_from_year(y);\n\n    for(i = 0; i < m; i++) {\n        md = month_days[i];\n        if (i == 1)\n            md += days_in_year(y) - 365;\n        days += md;\n    }\n    days += fields[2] - 1;\n    h = ((fields[3] * 60 + fields[4]) * 60 + fields[5]) * 1000 + fields[6];\n    d = days * 86400000 + h;\n    if (is_local)\n        d += getTimezoneOffset(d) * 60000;\n    return time_clip(d);\n}\n\nstatic JSValue get_date_field(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int magic)\n{\n    // get_date_field(obj, n, is_local)\n    int64_t fields[9];\n    int res, n, is_local;\n\n    is_local = magic & 0x0F;\n    n = (magic >> 4) & 0x0F;\n    res = get_date_fields(ctx, this_val, fields, is_local, 0);\n    if (res < 0)\n        return JS_EXCEPTION;\n    if (!res)\n        return JS_NAN;\n\n    if (magic & 0x100) {    // getYear\n        fields[0] -= 1900;\n    }\n    return JS_NewInt64(ctx, fields[n]);\n}\n\nstatic JSValue set_date_field(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv, int magic)\n{\n    // _field(obj, first_field, end_field, args, is_local)\n    int64_t fields[9];\n    int res, first_field, end_field, is_local, i, n;\n    double d, a;\n\n    d = NAN;\n    first_field = (magic >> 8) & 0x0F;\n    end_field = (magic >> 4) & 0x0F;\n    is_local = magic & 0x0F;\n\n    res = get_date_fields(ctx, this_val, fields, is_local, first_field == 0);\n    if (res < 0)\n        return JS_EXCEPTION;\n    if (res && argc > 0) {\n        n = end_field - first_field;\n        if (argc < n)\n            n = argc;\n        for(i = 0; i < n; i++) {\n            if (JS_ToFloat64(ctx, &a, argv[i]))\n                return JS_EXCEPTION;\n            if (!isfinite(a))\n                goto done;\n            fields[first_field + i] = trunc(a);\n        }\n        d = set_date_fields(fields, is_local);\n    }\ndone:\n    return JS_SetThisTimeValue(ctx, this_val, d);\n}\n\n/* fmt:\n   0: toUTCString: \"Tue, 02 Jan 2018 23:04:46 GMT\"\n   1: toString: \"Wed Jan 03 2018 00:05:22 GMT+0100 (CET)\"\n   2: toISOString: \"2018-01-02T23:02:56.927Z\"\n   3: toLocaleString: \"1/2/2018, 11:40:40 PM\"\n   part: 1=date, 2=time 3=all\n   XXX: should use a variant of strftime().\n */\nstatic JSValue get_date_string(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv, int magic)\n{\n    // _string(obj, fmt, part)\n    char buf[64];\n    int64_t fields[9];\n    int res, fmt, part, pos;\n    int y, mon, d, h, m, s, ms, wd, tz;\n\n    fmt = (magic >> 4) & 0x0F;\n    part = magic & 0x0F;\n\n    res = get_date_fields(ctx, this_val, fields, fmt & 1, 0);\n    if (res < 0)\n        return JS_EXCEPTION;\n    if (!res) {\n        if (fmt == 2)\n            return JS_ThrowRangeError(ctx, \"Date value is NaN\");\n        else\n            return JS_NewString(ctx, \"Invalid Date\");\n    }\n\n    y = fields[0];\n    mon = fields[1];\n    d = fields[2];\n    h = fields[3];\n    m = fields[4];\n    s = fields[5];\n    ms = fields[6];\n    wd = fields[7];\n    tz = fields[8];\n\n    pos = 0;\n\n    if (part & 1) { /* date part */\n        switch(fmt) {\n        case 0:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%.3s, %02d %.3s %0*d \",\n                            day_names + wd * 3, d,\n                            month_names + mon * 3, 4 + (y < 0), y);\n            break;\n        case 1:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%.3s %.3s %02d %0*d\",\n                            day_names + wd * 3,\n                            month_names + mon * 3, d, 4 + (y < 0), y);\n            if (part == 3) {\n                buf[pos++] = ' ';\n            }\n            break;\n        case 2:\n            if (y >= 0 && y <= 9999) {\n                pos += snprintf(buf + pos, sizeof(buf) - pos,\n                                \"%04d\", y);\n            } else {\n                pos += snprintf(buf + pos, sizeof(buf) - pos,\n                                \"%+07d\", y);\n            }\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"-%02d-%02dT\", mon + 1, d);\n            break;\n        case 3:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%02d/%02d/%0*d\", mon + 1, d, 4 + (y < 0), y);\n            if (part == 3) {\n                buf[pos++] = ',';\n                buf[pos++] = ' ';\n            }\n            break;\n        }\n    }\n    if (part & 2) { /* time part */\n        switch(fmt) {\n        case 0:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%02d:%02d:%02d GMT\", h, m, s);\n            break;\n        case 1:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%02d:%02d:%02d GMT\", h, m, s);\n            if (tz < 0) {\n                buf[pos++] = '-';\n                tz = -tz;\n            } else {\n                buf[pos++] = '+';\n            }\n            /* tz is >= 0, can use % */\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%02d%02d\", tz / 60, tz % 60);\n            /* XXX: tack the time zone code? */\n            break;\n        case 2:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%02d:%02d:%02d.%03dZ\", h, m, s, ms);\n            break;\n        case 3:\n            pos += snprintf(buf + pos, sizeof(buf) - pos,\n                            \"%02d:%02d:%02d %cM\", (h + 1) % 12 - 1, m, s,\n                            (h < 12) ? 'A' : 'P');\n            break;\n        }\n    }\n    return JS_NewStringLen(ctx, buf, pos);\n}\n\n/* OS dependent: return the UTC time in ms since 1970. */\nstatic int64_t date_now(void) {\n    struct timeval tv;\n    gettimeofday(&tv, NULL);\n    return (int64_t)tv.tv_sec * 1000 + (tv.tv_usec / 1000);\n}\n\nstatic JSValue js_date_constructor(JSContext *ctx, JSValueConst new_target,\n                                   int argc, JSValueConst *argv)\n{\n    // Date(y, mon, d, h, m, s, ms)\n    JSValue rv;\n    int i, n;\n    double a, val;\n\n    if (JS_IsUndefined(new_target)) {\n        /* invoked as function */\n        argc = 0;\n    }\n    n = argc;\n    if (n == 0) {\n        val = date_now();\n    } else if (n == 1) {\n        JSValue v, dv;\n        if (JS_VALUE_GET_TAG(argv[0]) == JS_TAG_OBJECT) {\n            JSObject *p = JS_VALUE_GET_OBJ(argv[0]);\n            if (p->class_id == JS_CLASS_DATE && JS_IsNumber(p->u.object_data)) {\n                if (JS_ToFloat64(ctx, &val, p->u.object_data))\n                    return JS_EXCEPTION;\n                val = time_clip(val);\n                goto has_val;\n            }\n        }\n        v = JS_ToPrimitive(ctx, argv[0], HINT_NONE);\n        if (JS_IsString(v)) {\n            dv = js_Date_parse(ctx, JS_UNDEFINED, 1, (JSValueConst *)&v);\n            JS_FreeValue(ctx, v);\n            if (JS_IsException(dv))\n                return JS_EXCEPTION;\n            if (JS_ToFloat64Free(ctx, &val, dv))\n                return JS_EXCEPTION;\n        } else {\n            if (JS_ToFloat64Free(ctx, &val, v))\n                return JS_EXCEPTION;\n        }\n        val = time_clip(val);\n    } else {\n        int64_t fields[] = { 0, 0, 1, 0, 0, 0, 0 };\n        if (n > 7)\n            n = 7;\n        for(i = 0; i < n; i++) {\n            if (JS_ToFloat64(ctx, &a, argv[i]))\n                return JS_EXCEPTION;\n            if (!isfinite(a))\n                break;\n            fields[i] = trunc(a);\n            if (i == 0 && fields[0] >= 0 && fields[0] < 100)\n                fields[0] += 1900;\n        }\n        val = (i == n) ? set_date_fields(fields, 1) : NAN;\n    }\nhas_val:\n#if 0\n    JSValueConst args[3];\n    args[0] = new_target;\n    args[1] = ctx->class_proto[JS_CLASS_DATE];\n    args[2] = __JS_NewFloat64(ctx, val);\n    rv = js___date_create(ctx, JS_UNDEFINED, 3, args);\n#else\n    rv = js_create_from_ctor(ctx, new_target, JS_CLASS_DATE);\n    if (!JS_IsException(rv))\n        JS_SetObjectData(ctx, rv, __JS_NewFloat64(ctx, val));\n#endif\n    if (!JS_IsException(rv) && JS_IsUndefined(new_target)) {\n        /* invoked as a function, return (new Date()).toString(); */\n        JSValue s;\n        s = get_date_string(ctx, rv, 0, NULL, 0x13);\n        JS_FreeValue(ctx, rv);\n        rv = s;\n    }\n    return rv;\n}\n\nstatic JSValue js_Date_UTC(JSContext *ctx, JSValueConst this_val,\n                           int argc, JSValueConst *argv)\n{\n    // UTC(y, mon, d, h, m, s, ms)\n    int64_t fields[] = { 0, 0, 1, 0, 0, 0, 0 };\n    int i, n;\n    double a;\n\n    n = argc;\n    if (n == 0)\n        return JS_NAN;\n    if (n > 7)\n        n = 7;\n    for(i = 0; i < n; i++) {\n        if (JS_ToFloat64(ctx, &a, argv[i]))\n            return JS_EXCEPTION;\n        if (!isfinite(a))\n            return JS_NAN;\n        fields[i] = trunc(a);\n        if (i == 0 && fields[0] >= 0 && fields[0] < 100)\n            fields[0] += 1900;\n    }\n    return __JS_NewFloat64(ctx, set_date_fields(fields, 0));\n}\n\nstatic void string_skip_spaces(JSString *sp, int *pp) {\n    while (*pp < sp->len && string_get(sp, *pp) == ' ')\n        *pp += 1;\n}\n\nstatic void string_skip_non_spaces(JSString *sp, int *pp) {\n    while (*pp < sp->len && string_get(sp, *pp) != ' ')\n        *pp += 1;\n}\n\n/* parse a numeric field */\nstatic int string_get_field(JSString *sp, int *pp, int64_t *pval) {\n    int64_t v = 0;\n    int c, p = *pp;\n\n    /* skip non digits, should only skip spaces? */\n    while (p < sp->len) {\n        c = string_get(sp, p);\n        if (c >= '0' && c <= '9')\n            break;\n        p++;\n    }\n    if (p >= sp->len)\n        return -1;\n    while (p < sp->len) {\n        c = string_get(sp, p);\n        if (!(c >= '0' && c <= '9'))\n            break;\n        v = v * 10 + c - '0';\n        p++;\n    }\n    *pval = v;\n    *pp = p;\n    return 0;\n}\n\n/* parse a fixed width numeric field */\nstatic int string_get_digits(JSString *sp, int *pp, int n, int64_t *pval) {\n    int64_t v = 0;\n    int i, c, p = *pp;\n\n    for(i = 0; i < n; i++) {\n        if (p >= sp->len)\n            return -1;\n        c = string_get(sp, p);\n        if (!(c >= '0' && c <= '9'))\n            return -1;\n        v = v * 10 + c - '0';\n        p++;\n    }\n    *pval = v;\n    *pp = p;\n    return 0;\n}\n\n/* parse a signed numeric field */\nstatic int string_get_signed_field(JSString *sp, int *pp, int64_t *pval) {\n    int sgn, res;\n\n    if (*pp >= sp->len)\n        return -1;\n\n    sgn = string_get(sp, *pp);\n    if (sgn == '-' || sgn == '+')\n        *pp += 1;\n\n    res = string_get_field(sp, pp, pval);\n    if (res == 0 && sgn == '-')\n        *pval = -*pval;\n    return res;\n}\n\nstatic int find_abbrev(JSString *sp, int p, const char *list, int count) {\n    int n, i;\n\n    if (p + 3 <= sp->len) {\n        for (n = 0; n < count; n++) {\n            for (i = 0; i < 3; i++) {\n                if (string_get(sp, p + i) != month_names[n * 3 + i])\n                    goto next;\n            }\n            return n;\n        next:;\n        }\n    }\n    return -1;\n}\n\nstatic int string_get_month(JSString *sp, int *pp, int64_t *pval) {\n    int n;\n\n    string_skip_spaces(sp, pp);\n    n = find_abbrev(sp, *pp, month_names, 12);\n    if (n < 0)\n        return -1;\n\n    *pval = n;\n    *pp += 3;\n    return 0;\n}\n\nstatic JSValue js_Date_parse(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv)\n{\n    // parse(s)\n    JSValue s, rv;\n    int64_t fields[] = { 0, 1, 1, 0, 0, 0, 0 };\n    int64_t tz, hh, mm;\n    double d;\n    int p, i, c, sgn;\n    JSString *sp;\n    BOOL is_local;\n    \n    rv = JS_NAN;\n\n    s = JS_ToString(ctx, argv[0]);\n    if (JS_IsException(s))\n        return JS_EXCEPTION;\n    \n    sp = JS_VALUE_GET_STRING(s);\n    p = 0;\n    if (p < sp->len && (((c = string_get(sp, p)) >= '0' && c <= '9') || c == '+' || c == '-')) {\n        /* ISO format */\n        /* year field can be negative */\n        /* XXX: could be stricter */\n        if (string_get_signed_field(sp, &p, &fields[0]))\n            goto done;\n\n        is_local = TRUE;\n        for (i = 1; i < 6; i++) {\n            if (string_get_field(sp, &p, &fields[i]))\n                break;\n        }\n        if (i <= 3) {\n            /* no time: UTC by default */\n            is_local = FALSE;\n        } else if (i == 6 && p < sp->len && string_get(sp, p) == '.') {\n            /* parse milliseconds as a fractional part, round to nearest */\n            /* XXX: the spec does not indicate which rounding should be used */\n            int mul = 1000, ms = 0;\n            while (++p < sp->len) {\n                int c = string_get(sp, p);\n                if (!(c >= '0' && c <= '9'))\n                    break;\n                if (mul == 1 && c >= '5')\n                    ms += 1;\n                ms += (c - '0') * (mul /= 10);\n            }\n            fields[6] = ms;\n        }\n        fields[1] -= 1;\n\n        /* parse the time zone offset if present: [+-]HH:mm */\n        tz = 0;\n        if (p < sp->len) {\n            sgn = string_get(sp, p);\n            if (sgn == '+' || sgn == '-') {\n                if (string_get_field(sp, &p, &hh))\n                    goto done;\n                if (string_get_field(sp, &p, &mm))\n                    goto done;\n                tz = hh * 60 + mm;\n                if (sgn == '-')\n                    tz = -tz;\n                is_local = FALSE;\n            } else if (sgn == 'Z') {\n                is_local = FALSE;\n            }\n        }\n    } else {\n        /* toString or toUTCString format */\n        /* skip the day of the week */\n        string_skip_non_spaces(sp, &p);\n        string_skip_spaces(sp, &p);\n        if (p >= sp->len)\n            goto done;\n        c = string_get(sp, p);\n        if (c >= '0' && c <= '9') {\n            /* day of month first */\n            if (string_get_field(sp, &p, &fields[2]))\n                goto done;\n            if (string_get_month(sp, &p, &fields[1]))\n                goto done;\n        } else {\n            /* month first */\n            if (string_get_month(sp, &p, &fields[1]))\n                goto done;\n            if (string_get_field(sp, &p, &fields[2]))\n                goto done;\n        }\n        string_skip_spaces(sp, &p);\n        if (string_get_signed_field(sp, &p, &fields[0]))\n            goto done;\n\n        /* hour, min, seconds */\n        for(i = 0; i < 3; i++) {\n            if (string_get_field(sp, &p, &fields[3 + i]))\n                goto done;\n        }\n        // XXX: parse optional milliseconds?\n\n        /* parse the time zone offset if present: [+-]HHmm */\n        is_local = FALSE;\n        tz = 0;\n        for (tz = 0; p < sp->len; p++) {\n            sgn = string_get(sp, p);\n            if (sgn == '+' || sgn == '-') {\n                p++;\n                if (string_get_digits(sp, &p, 2, &hh))\n                    goto done;\n                if (string_get_digits(sp, &p, 2, &mm))\n                    goto done;\n                tz = hh * 60 + mm;\n                if (sgn == '-')\n                    tz = -tz;\n                break;\n            }\n        }\n    }\n    d = set_date_fields(fields, is_local) - tz * 60000;\n    rv = __JS_NewFloat64(ctx, d);\n\ndone:\n    JS_FreeValue(ctx, s);\n    return rv;\n}\n\nstatic JSValue js_Date_now(JSContext *ctx, JSValueConst this_val,\n                           int argc, JSValueConst *argv)\n{\n    // now()\n    return JS_NewInt64(ctx, date_now());\n}\n\nstatic JSValue js_date_Symbol_toPrimitive(JSContext *ctx, JSValueConst this_val,\n                                          int argc, JSValueConst *argv)\n{\n    // Symbol_toPrimitive(hint)\n    JSValueConst obj = this_val;\n    JSAtom hint = JS_ATOM_NULL;\n    int hint_num;\n\n    if (!JS_IsObject(obj))\n        return JS_ThrowTypeErrorNotAnObject(ctx);\n\n    if (JS_IsString(argv[0])) {\n        hint = JS_ValueToAtom(ctx, argv[0]);\n        if (hint == JS_ATOM_NULL)\n            return JS_EXCEPTION;\n        JS_FreeAtom(ctx, hint);\n    }\n    switch (hint) {\n    case JS_ATOM_number:\n#ifdef CONFIG_BIGNUM\n    case JS_ATOM_integer:\n#endif\n        hint_num = HINT_NUMBER;\n        break;\n    case JS_ATOM_string:\n    case JS_ATOM_default:\n        hint_num = HINT_STRING;\n        break;\n    default:\n        return JS_ThrowTypeError(ctx, \"invalid hint\");\n    }\n    return JS_ToPrimitive(ctx, obj, hint_num | HINT_FORCE_ORDINARY);\n}\n\nstatic JSValue js_date_getTimezoneOffset(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    // getTimezoneOffset()\n    double v;\n\n    if (JS_ThisTimeValue(ctx, &v, this_val))\n        return JS_EXCEPTION;\n    if (isnan(v))\n        return JS_NAN;\n    else\n        return JS_NewInt64(ctx, getTimezoneOffset((int64_t)trunc(v)));\n}\n\nstatic JSValue js_date_getTime(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    // getTime()\n    double v;\n\n    if (JS_ThisTimeValue(ctx, &v, this_val))\n        return JS_EXCEPTION;\n    return __JS_NewFloat64(ctx, v);\n}\n\nstatic JSValue js_date_setTime(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    // setTime(v)\n    double v;\n\n    if (JS_ThisTimeValue(ctx, &v, this_val) || JS_ToFloat64(ctx, &v, argv[0]))\n        return JS_EXCEPTION;\n    return JS_SetThisTimeValue(ctx, this_val, time_clip(v));\n}\n\nstatic JSValue js_date_setYear(JSContext *ctx, JSValueConst this_val,\n                               int argc, JSValueConst *argv)\n{\n    // setYear(y)\n    double y;\n    JSValueConst args[1];\n\n    if (JS_ThisTimeValue(ctx, &y, this_val) || JS_ToFloat64(ctx, &y, argv[0]))\n        return JS_EXCEPTION;\n    y = +y;\n    if (isfinite(y)) {\n        y = trunc(y);\n        if (y >= 0 && y < 100)\n            y += 1900;\n    }\n    args[0] = __JS_NewFloat64(ctx, y);\n    return set_date_field(ctx, this_val, 1, args, 0x011);\n}\n\nstatic JSValue js_date_toJSON(JSContext *ctx, JSValueConst this_val,\n                              int argc, JSValueConst *argv)\n{\n    // toJSON(key)\n    JSValue obj, tv, method, rv;\n    double d;\n\n    rv = JS_EXCEPTION;\n    tv = JS_UNDEFINED;\n\n    obj = JS_ToObject(ctx, this_val);\n    tv = JS_ToPrimitive(ctx, obj, HINT_NUMBER);\n    if (JS_IsException(tv))\n        goto exception;\n    if (JS_IsNumber(tv)) {\n        if (JS_ToFloat64(ctx, &d, tv) < 0)\n            goto exception;\n        if (!isfinite(d)) {\n            rv = JS_NULL;\n            goto done;\n        }\n    }\n    method = JS_GetPropertyStr(ctx, obj, \"toISOString\");\n    if (JS_IsException(method))\n        goto exception;\n    if (!JS_IsFunction(ctx, method)) {\n        JS_ThrowTypeError(ctx, \"object needs toISOString method\");\n        JS_FreeValue(ctx, method);\n        goto exception;\n    }\n    rv = JS_CallFree(ctx, method, obj, 0, NULL);\nexception:\ndone:\n    JS_FreeValue(ctx, obj);\n    JS_FreeValue(ctx, tv);\n    return rv;\n}\n\nstatic const JSCFunctionListEntry js_date_funcs[] = {\n    JS_CFUNC_DEF(\"now\", 0, js_Date_now ),\n    JS_CFUNC_DEF(\"parse\", 1, js_Date_parse ),\n    JS_CFUNC_DEF(\"UTC\", 7, js_Date_UTC ),\n};\n\nstatic const JSCFunctionListEntry js_date_proto_funcs[] = {\n    JS_CFUNC_DEF(\"valueOf\", 0, js_date_getTime ),\n    JS_CFUNC_MAGIC_DEF(\"toString\", 0, get_date_string, 0x13 ),\n    JS_CFUNC_DEF(\"[Symbol.toPrimitive]\", 1, js_date_Symbol_toPrimitive ),\n    JS_CFUNC_MAGIC_DEF(\"toUTCString\", 0, get_date_string, 0x03 ),\n    JS_ALIAS_DEF(\"toGMTString\", \"toUTCString\" ),\n    JS_CFUNC_MAGIC_DEF(\"toISOString\", 0, get_date_string, 0x23 ),\n    JS_CFUNC_MAGIC_DEF(\"toDateString\", 0, get_date_string, 0x11 ),\n    JS_CFUNC_MAGIC_DEF(\"toTimeString\", 0, get_date_string, 0x12 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleString\", 0, get_date_string, 0x33 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleDateString\", 0, get_date_string, 0x31 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleTimeString\", 0, get_date_string, 0x32 ),\n    JS_CFUNC_DEF(\"getTimezoneOffset\", 0, js_date_getTimezoneOffset ),\n    JS_CFUNC_DEF(\"getTime\", 0, js_date_getTime ),\n    JS_CFUNC_MAGIC_DEF(\"getYear\", 0, get_date_field, 0x101 ),\n    JS_CFUNC_MAGIC_DEF(\"getFullYear\", 0, get_date_field, 0x01 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCFullYear\", 0, get_date_field, 0x00 ),\n    JS_CFUNC_MAGIC_DEF(\"getMonth\", 0, get_date_field, 0x11 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCMonth\", 0, get_date_field, 0x10 ),\n    JS_CFUNC_MAGIC_DEF(\"getDate\", 0, get_date_field, 0x21 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCDate\", 0, get_date_field, 0x20 ),\n    JS_CFUNC_MAGIC_DEF(\"getHours\", 0, get_date_field, 0x31 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCHours\", 0, get_date_field, 0x30 ),\n    JS_CFUNC_MAGIC_DEF(\"getMinutes\", 0, get_date_field, 0x41 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCMinutes\", 0, get_date_field, 0x40 ),\n    JS_CFUNC_MAGIC_DEF(\"getSeconds\", 0, get_date_field, 0x51 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCSeconds\", 0, get_date_field, 0x50 ),\n    JS_CFUNC_MAGIC_DEF(\"getMilliseconds\", 0, get_date_field, 0x61 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCMilliseconds\", 0, get_date_field, 0x60 ),\n    JS_CFUNC_MAGIC_DEF(\"getDay\", 0, get_date_field, 0x71 ),\n    JS_CFUNC_MAGIC_DEF(\"getUTCDay\", 0, get_date_field, 0x70 ),\n    JS_CFUNC_DEF(\"setTime\", 1, js_date_setTime ),\n    JS_CFUNC_MAGIC_DEF(\"setMilliseconds\", 1, set_date_field, 0x671 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCMilliseconds\", 1, set_date_field, 0x670 ),\n    JS_CFUNC_MAGIC_DEF(\"setSeconds\", 2, set_date_field, 0x571 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCSeconds\", 2, set_date_field, 0x570 ),\n    JS_CFUNC_MAGIC_DEF(\"setMinutes\", 3, set_date_field, 0x471 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCMinutes\", 3, set_date_field, 0x470 ),\n    JS_CFUNC_MAGIC_DEF(\"setHours\", 4, set_date_field, 0x371 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCHours\", 4, set_date_field, 0x370 ),\n    JS_CFUNC_MAGIC_DEF(\"setDate\", 1, set_date_field, 0x231 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCDate\", 1, set_date_field, 0x230 ),\n    JS_CFUNC_MAGIC_DEF(\"setMonth\", 2, set_date_field, 0x131 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCMonth\", 2, set_date_field, 0x130 ),\n    JS_CFUNC_DEF(\"setYear\", 1, js_date_setYear ),\n    JS_CFUNC_MAGIC_DEF(\"setFullYear\", 3, set_date_field, 0x031 ),\n    JS_CFUNC_MAGIC_DEF(\"setUTCFullYear\", 3, set_date_field, 0x030 ),\n    JS_CFUNC_DEF(\"toJSON\", 1, js_date_toJSON ),\n};\n\nvoid JS_AddIntrinsicDate(JSContext *ctx)\n{\n    JSValueConst obj;\n\n    /* Date */\n    ctx->class_proto[JS_CLASS_DATE] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_DATE], js_date_proto_funcs,\n                               countof(js_date_proto_funcs));\n    obj = JS_NewGlobalCConstructor(ctx, \"Date\", js_date_constructor, 7,\n                                   ctx->class_proto[JS_CLASS_DATE]);\n    JS_SetPropertyFunctionList(ctx, obj, js_date_funcs, countof(js_date_funcs));\n}\n\n/* eval */\n\nvoid JS_AddIntrinsicEval(JSContext *ctx)\n{\n    ctx->eval_internal = __JS_EvalInternal;\n}\n\n#ifdef CONFIG_BIGNUM\n\n/* Operators */\n\nstatic void js_operator_set_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSOperatorSetData *opset = JS_GetOpaque(val, JS_CLASS_OPERATOR_SET);\n    int i, j;\n    JSBinaryOperatorDefEntry *ent;\n    \n    if (opset) {\n        for(i = 0; i < JS_OVOP_COUNT; i++) {\n            if (opset->self_ops[i])\n                JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, opset->self_ops[i]));\n        }\n        for(j = 0; j < opset->left.count; j++) {\n            ent = &opset->left.tab[j];\n            for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {\n                if (ent->ops[i])\n                    JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ent->ops[i]));\n            }\n        }\n        js_free_rt(rt, opset->left.tab);\n        for(j = 0; j < opset->right.count; j++) {\n            ent = &opset->right.tab[j];\n            for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {\n                if (ent->ops[i])\n                    JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ent->ops[i]));\n            }\n        }\n        js_free_rt(rt, opset->right.tab);\n        js_free_rt(rt, opset);\n    }\n}\n\nstatic void js_operator_set_mark(JSRuntime *rt, JSValueConst val,\n                                 JS_MarkFunc *mark_func)\n{\n    JSOperatorSetData *opset = JS_GetOpaque(val, JS_CLASS_OPERATOR_SET);\n    int i, j;\n    JSBinaryOperatorDefEntry *ent;\n    \n    if (opset) {\n        for(i = 0; i < JS_OVOP_COUNT; i++) {\n            if (opset->self_ops[i])\n                JS_MarkValue(rt, JS_MKPTR(JS_TAG_OBJECT, opset->self_ops[i]),\n                             mark_func);\n        }\n        for(j = 0; j < opset->left.count; j++) {\n            ent = &opset->left.tab[j];\n            for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {\n                if (ent->ops[i])\n                    JS_MarkValue(rt, JS_MKPTR(JS_TAG_OBJECT, ent->ops[i]),\n                                 mark_func);\n            }\n        }\n        for(j = 0; j < opset->right.count; j++) {\n            ent = &opset->right.tab[j];\n            for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {\n                if (ent->ops[i])\n                    JS_MarkValue(rt, JS_MKPTR(JS_TAG_OBJECT, ent->ops[i]),\n                                 mark_func);\n            }\n        }\n    }\n}\n\n\n/* create an OperatorSet object */\nstatic JSValue js_operators_create_internal(JSContext *ctx,\n                                            int argc, JSValueConst *argv,\n                                            BOOL is_primitive)\n{\n    JSValue opset_obj, prop, obj;\n    JSOperatorSetData *opset, *opset1;\n    JSBinaryOperatorDef *def;\n    JSValueConst arg;\n    int i, j;\n    JSBinaryOperatorDefEntry *new_tab;\n    JSBinaryOperatorDefEntry *ent;\n    uint32_t op_count;\n\n    if (ctx->rt->operator_count == UINT32_MAX) {\n        return JS_ThrowTypeError(ctx, \"too many operators\");\n    }\n    opset_obj = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_OPERATOR_SET);\n    if (JS_IsException(opset_obj))\n        goto fail;\n    opset = js_mallocz(ctx, sizeof(*opset));\n    if (!opset)\n        goto fail;\n    JS_SetOpaque(opset_obj, opset);\n    if (argc >= 1) {\n        arg = argv[0];\n        /* self operators */\n        for(i = 0; i < JS_OVOP_COUNT; i++) {\n            prop = JS_GetPropertyStr(ctx, arg, js_overloadable_operator_names[i]);\n            if (JS_IsException(prop))\n                goto fail;\n            if (!JS_IsUndefined(prop)) {\n                if (check_function(ctx, prop)) {\n                    JS_FreeValue(ctx, prop);\n                    goto fail;\n                }\n                opset->self_ops[i] = JS_VALUE_GET_OBJ(prop);\n            }\n        }\n    }\n    /* left & right operators */\n    for(j = 1; j < argc; j++) {\n        arg = argv[j];\n        prop = JS_GetPropertyStr(ctx, arg, \"left\");\n        if (JS_IsException(prop))\n            goto fail;\n        def = &opset->right;\n        if (JS_IsUndefined(prop)) {\n            prop = JS_GetPropertyStr(ctx, arg, \"right\");\n            if (JS_IsException(prop))\n                goto fail;\n            if (JS_IsUndefined(prop)) {\n                JS_ThrowTypeError(ctx, \"left or right property must be present\");\n                goto fail;\n            }\n            def = &opset->left;\n        }\n        /* get the operator set */\n        obj = JS_GetProperty(ctx, prop, JS_ATOM_prototype);\n        JS_FreeValue(ctx, prop);\n        if (JS_IsException(obj))\n            goto fail;\n        prop = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_operatorSet);\n        JS_FreeValue(ctx, obj);\n        if (JS_IsException(prop))\n            goto fail;\n        opset1 = JS_GetOpaque2(ctx, prop, JS_CLASS_OPERATOR_SET);\n        if (!opset1) {\n            JS_FreeValue(ctx, prop);\n            goto fail;\n        }\n        op_count = opset1->operator_counter;\n        JS_FreeValue(ctx, prop);\n        \n        /* we assume there are few entries */\n        new_tab = js_realloc(ctx, def->tab,\n                             (def->count + 1) * sizeof(def->tab[0]));\n        if (!new_tab)\n            goto fail;\n        def->tab = new_tab;\n        def->count++;\n        ent = def->tab + def->count - 1;\n        memset(ent, 0, sizeof(def->tab[0]));\n        ent->operator_index = op_count;\n        \n        for(i = 0; i < JS_OVOP_BINARY_COUNT; i++) {\n            prop = JS_GetPropertyStr(ctx, arg,\n                                     js_overloadable_operator_names[i]);\n            if (JS_IsException(prop))\n                goto fail;\n            if (!JS_IsUndefined(prop)) {\n                if (check_function(ctx, prop)) {\n                    JS_FreeValue(ctx, prop);\n                    goto fail;\n                }\n                ent->ops[i] = JS_VALUE_GET_OBJ(prop);\n            }\n        }\n    }\n    opset->is_primitive = is_primitive;\n    opset->operator_counter = ctx->rt->operator_count++;\n    return opset_obj;\n fail:\n    JS_FreeValue(ctx, opset_obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_operators_create(JSContext *ctx, JSValueConst this_val,\n                                int argc, JSValueConst *argv)\n{\n    return js_operators_create_internal(ctx, argc, argv, FALSE);\n}\n\nstatic JSValue js_operators_updateBigIntOperators(JSContext *ctx, JSValueConst this_val,\n                                                  int argc, JSValueConst *argv)\n{\n    JSValue opset_obj, prop;\n    JSOperatorSetData *opset;\n    const JSOverloadableOperatorEnum ops[2] = { JS_OVOP_DIV, JS_OVOP_POW };\n    JSOverloadableOperatorEnum op;\n    int i;\n    \n    opset_obj = JS_GetProperty(ctx, ctx->class_proto[JS_CLASS_BIG_INT],\n                               JS_ATOM_Symbol_operatorSet);\n    if (JS_IsException(opset_obj))\n        goto fail;\n    opset = JS_GetOpaque2(ctx, opset_obj, JS_CLASS_OPERATOR_SET);\n    if (!opset)\n        goto fail;\n    for(i = 0; i < countof(ops); i++) {\n        op = ops[i];\n        prop = JS_GetPropertyStr(ctx, argv[0],\n                                 js_overloadable_operator_names[op]);\n        if (JS_IsException(prop))\n            goto fail;\n        if (!JS_IsUndefined(prop)) {\n            if (!JS_IsNull(prop) && check_function(ctx, prop)) {\n                JS_FreeValue(ctx, prop);\n                goto fail;\n            }\n            if (opset->self_ops[op])\n                JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, opset->self_ops[op]));\n            if (JS_IsNull(prop)) {\n                opset->self_ops[op] = NULL;\n            } else {\n                opset->self_ops[op] = JS_VALUE_GET_PTR(prop);\n            }\n        }\n    }\n    JS_FreeValue(ctx, opset_obj);\n    return JS_UNDEFINED;\n fail:\n    JS_FreeValue(ctx, opset_obj);\n    return JS_EXCEPTION;\n}\n\nstatic int js_operators_set_default(JSContext *ctx, JSValueConst obj)\n{\n    JSValue opset_obj;\n\n    if (!JS_IsObject(obj)) /* in case the prototype is not defined */\n        return 0;\n    opset_obj = js_operators_create_internal(ctx, 0, NULL, TRUE);\n    if (JS_IsException(opset_obj))\n        return -1;\n    /* cannot be modified by the user */\n    JS_DefinePropertyValue(ctx, obj, JS_ATOM_Symbol_operatorSet,\n                           opset_obj, 0);\n    return 0;\n}\n\nstatic JSValue js_dummy_operators_ctor(JSContext *ctx, JSValueConst new_target,\n                                       int argc, JSValueConst *argv)\n{\n    return js_create_from_ctor(ctx, new_target, JS_CLASS_OBJECT);\n}\n\nstatic JSValue js_global_operators(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    JSValue func_obj, proto, opset_obj;\n\n    func_obj = JS_UNDEFINED;\n    proto = JS_NewObject(ctx);\n    if (JS_IsException(proto))\n        return JS_EXCEPTION;\n    opset_obj = js_operators_create_internal(ctx, argc, argv, FALSE);\n    if (JS_IsException(opset_obj))\n        goto fail;\n    JS_DefinePropertyValue(ctx, proto, JS_ATOM_Symbol_operatorSet,\n                           opset_obj, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    func_obj = JS_NewCFunction2(ctx, js_dummy_operators_ctor, \"Operators\",\n                                0, JS_CFUNC_constructor, 0);\n    if (JS_IsException(func_obj))\n        goto fail;\n    JS_SetConstructor2(ctx, func_obj, proto,\n                       0, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    JS_FreeValue(ctx, proto);\n    return func_obj;\n fail:\n    JS_FreeValue(ctx, proto);\n    JS_FreeValue(ctx, func_obj);\n    return JS_EXCEPTION;\n}\n\nstatic const JSCFunctionListEntry js_operators_funcs[] = {\n    JS_CFUNC_DEF(\"create\", 1, js_operators_create ),\n    JS_CFUNC_DEF(\"updateBigIntOperators\", 2, js_operators_updateBigIntOperators ),\n};\n\n/* must be called after all overloadable base types are initialized */\nvoid JS_AddIntrinsicOperators(JSContext *ctx)\n{\n    JSValue obj;\n\n    ctx->allow_operator_overloading = TRUE;\n    obj = JS_NewCFunction(ctx, js_global_operators, \"Operators\", 1);\n    JS_SetPropertyFunctionList(ctx, obj,\n                               js_operators_funcs,\n                               countof(js_operators_funcs));\n    JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_Operators,\n                           obj,\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    /* add default operatorSets */\n    js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BOOLEAN]);\n    js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_NUMBER]);\n    js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_STRING]);\n    js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BIG_INT]);\n    js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BIG_FLOAT]);\n    js_operators_set_default(ctx, ctx->class_proto[JS_CLASS_BIG_DECIMAL]);\n}\n\n/* BigInt */\n\nstatic JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)\n{\n    uint32_t tag;\n\n redo:\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_INT:\n    case JS_TAG_BOOL:\n        val = JS_NewBigInt64(ctx, JS_VALUE_GET_INT(val));\n        break;\n    case JS_TAG_BIG_INT:\n        break;\n    case JS_TAG_FLOAT64:\n    case JS_TAG_BIG_FLOAT:\n        {\n            bf_t *a, a_s;\n            \n            a = JS_ToBigFloat(ctx, &a_s, val);\n            if (!bf_is_finite(a)) {\n                JS_FreeValue(ctx, val);\n                val = JS_ThrowRangeError(ctx, \"cannot convert NaN or Infinity to bigint\");\n            } else {\n                JSValue val1 = JS_NewBigInt(ctx);\n                bf_t *r;\n                int ret;\n                if (JS_IsException(val1)) {\n                    JS_FreeValue(ctx, val);\n                    return JS_EXCEPTION;\n                }\n                r = JS_GetBigInt(val1);\n                ret = bf_set(r, a);\n                ret |= bf_rint(r, BF_RNDZ);\n                JS_FreeValue(ctx, val);\n                if (ret & BF_ST_MEM_ERROR) {\n                    JS_FreeValue(ctx, val1);\n                    val = JS_ThrowOutOfMemory(ctx);\n                } else if (ret & BF_ST_INEXACT) {\n                    JS_FreeValue(ctx, val1);\n                    val = JS_ThrowRangeError(ctx, \"cannot convert to bigint: not an integer\");\n                } else {\n                    val = JS_CompactBigInt(ctx, val1);\n                }\n            }\n            if (a == &a_s)\n                bf_delete(a);\n        }\n        break;\n    case JS_TAG_BIG_DECIMAL:\n        val = JS_ToStringFree(ctx, val);\n         if (JS_IsException(val))\n            break;\n        goto redo;\n    case JS_TAG_STRING:\n        val = JS_StringToBigIntErr(ctx, val);\n        break;\n    case JS_TAG_OBJECT:\n        val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);\n        if (JS_IsException(val))\n            break;\n        goto redo;\n    case JS_TAG_NULL:\n    case JS_TAG_UNDEFINED:\n    default:\n        JS_FreeValue(ctx, val);\n        return JS_ThrowTypeError(ctx, \"cannot convert to bigint\");\n    }\n    return val;\n}\n\nstatic JSValue js_bigint_constructor(JSContext *ctx,\n                                     JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    return JS_ToBigIntCtorFree(ctx, JS_DupValue(ctx, argv[0]));\n}\n\nstatic JSValue js_thisBigIntValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_IsBigInt(ctx, this_val))\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_BIG_INT) {\n            if (JS_IsBigInt(ctx, p->u.object_data))\n                return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a bigint\");\n}\n\nstatic JSValue js_bigint_toString(JSContext *ctx, JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValue val;\n    int base;\n    JSValue ret;\n\n    val = js_thisBigIntValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (argc == 0 || JS_IsUndefined(argv[0])) {\n        base = 10;\n    } else {\n        base = js_get_radix(ctx, argv[0]);\n        if (base < 0)\n            goto fail;\n    }\n    ret = js_bigint_to_string1(ctx, val, base);\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigint_valueOf(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    return js_thisBigIntValue(ctx, this_val);\n}\n\nstatic JSValue js_bigint_div(JSContext *ctx,\n                              JSValueConst this_val,\n                              int argc, JSValueConst *argv, int magic)\n{\n    bf_t a_s, b_s, *a, *b, *r, *q;\n    int status;\n    JSValue q_val, r_val;\n    \n    q_val = JS_NewBigInt(ctx);\n    if (JS_IsException(q_val))\n        return JS_EXCEPTION;\n    r_val = JS_NewBigInt(ctx);\n    if (JS_IsException(r_val))\n        goto fail;\n    b = NULL;\n    a = JS_ToBigInt(ctx, &a_s, argv[0]);\n    if (!a)\n        goto fail;\n    b = JS_ToBigInt(ctx, &b_s, argv[1]);\n    if (!b) {\n        JS_FreeBigInt(ctx, a, &a_s);\n        goto fail;\n    }\n    q = JS_GetBigInt(q_val);\n    r = JS_GetBigInt(r_val);\n    status = bf_divrem(q, r, a, b, BF_PREC_INF, BF_RNDZ, magic & 0xf);\n    JS_FreeBigInt(ctx, a, &a_s);\n    JS_FreeBigInt(ctx, b, &b_s);\n    if (unlikely(status)) {\n        throw_bf_exception(ctx, status);\n        goto fail;\n    }\n    q_val = JS_CompactBigInt(ctx, q_val);\n    if (magic & 0x10) {\n        JSValue ret;\n        ret = JS_NewArray(ctx);\n        if (JS_IsException(ret))\n            goto fail;\n        JS_SetPropertyUint32(ctx, ret, 0, q_val);\n        JS_SetPropertyUint32(ctx, ret, 1, JS_CompactBigInt(ctx, r_val));\n        return ret;\n    } else {\n        JS_FreeValue(ctx, r_val);\n        return q_val;\n    }\n fail:\n    JS_FreeValue(ctx, q_val);\n    JS_FreeValue(ctx, r_val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigint_sqrt(JSContext *ctx,\n                               JSValueConst this_val,\n                               int argc, JSValueConst *argv, int magic)\n{\n    bf_t a_s, *a, *r, *rem;\n    int status;\n    JSValue r_val, rem_val;\n    \n    r_val = JS_NewBigInt(ctx);\n    if (JS_IsException(r_val))\n        return JS_EXCEPTION;\n    rem_val = JS_NewBigInt(ctx);\n    if (JS_IsException(rem_val))\n        return JS_EXCEPTION;\n    r = JS_GetBigInt(r_val);\n    rem = JS_GetBigInt(rem_val);\n\n    a = JS_ToBigInt(ctx, &a_s, argv[0]);\n    if (!a)\n        goto fail;\n    status = bf_sqrtrem(r, rem, a);\n    JS_FreeBigInt(ctx, a, &a_s);\n    if (unlikely(status & ~BF_ST_INEXACT)) {\n        throw_bf_exception(ctx, status);\n        goto fail;\n    }\n    r_val = JS_CompactBigInt(ctx, r_val);\n    if (magic) {\n        JSValue ret;\n        ret = JS_NewArray(ctx);\n        if (JS_IsException(ret))\n            goto fail;\n        JS_SetPropertyUint32(ctx, ret, 0, r_val);\n        JS_SetPropertyUint32(ctx, ret, 1, JS_CompactBigInt(ctx, rem_val));\n        return ret;\n    } else {\n        JS_FreeValue(ctx, rem_val);\n        return r_val;\n    }\n fail:\n    JS_FreeValue(ctx, r_val);\n    JS_FreeValue(ctx, rem_val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigint_op1(JSContext *ctx,\n                              JSValueConst this_val,\n                              int argc, JSValueConst *argv,\n                              int magic)\n{\n    bf_t a_s, *a;\n    int64_t res;\n\n    a = JS_ToBigInt(ctx, &a_s, argv[0]);\n    if (!a)\n        return JS_EXCEPTION;\n    switch(magic) {\n    case 0: /* floorLog2 */\n        if (a->sign || a->expn <= 0) {\n            res = -1;\n        } else {\n            res = a->expn - 1;\n        }\n        break;\n    case 1: /* ctz */\n        if (bf_is_zero(a)) {\n            res = -1;\n        } else {\n            res = bf_get_exp_min(a);\n        }\n        break;\n    default:\n        abort();\n    }\n    JS_FreeBigInt(ctx, a, &a_s);\n    return JS_NewBigInt64(ctx, res);\n}\n\nstatic JSValue js_bigint_asUintN(JSContext *ctx,\n                                  JSValueConst this_val,\n                                  int argc, JSValueConst *argv, int asIntN)\n{\n    uint64_t bits;\n    bf_t a_s, *a = &a_s, *r, mask_s, *mask = &mask_s;\n    JSValue res;\n    \n    if (JS_ToIndex(ctx, &bits, argv[0]))\n        return JS_EXCEPTION;\n    res = JS_NewBigInt(ctx);\n    if (JS_IsException(res))\n        return JS_EXCEPTION;\n    r = JS_GetBigInt(res);\n    a = JS_ToBigInt(ctx, &a_s, argv[1]);\n    if (!a) {\n        JS_FreeValue(ctx, res);\n        return JS_EXCEPTION;\n    }\n    /* XXX: optimize */\n    r = JS_GetBigInt(res);\n    bf_init(ctx->bf_ctx, mask);\n    bf_set_ui(mask, 1);\n    bf_mul_2exp(mask, bits, BF_PREC_INF, BF_RNDZ);\n    bf_add_si(mask, mask, -1, BF_PREC_INF, BF_RNDZ);\n    bf_logic_and(r, a, mask);\n    if (asIntN && bits != 0) {\n        bf_set_ui(mask, 1);\n        bf_mul_2exp(mask, bits - 1, BF_PREC_INF, BF_RNDZ);\n        if (bf_cmpu(r, mask) >= 0) {\n            bf_set_ui(mask, 1);\n            bf_mul_2exp(mask, bits, BF_PREC_INF, BF_RNDZ);\n            bf_sub(r, r, mask, BF_PREC_INF, BF_RNDZ);\n        }\n    }\n    bf_delete(mask);\n    JS_FreeBigInt(ctx, a, &a_s);\n    return JS_CompactBigInt(ctx, res);\n}\n\nstatic const JSCFunctionListEntry js_bigint_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"asUintN\", 2, js_bigint_asUintN, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"asIntN\", 2, js_bigint_asUintN, 1 ),\n    /* QuickJS extensions */\n    JS_CFUNC_MAGIC_DEF(\"tdiv\", 2, js_bigint_div, BF_RNDZ ),\n    JS_CFUNC_MAGIC_DEF(\"fdiv\", 2, js_bigint_div, BF_RNDD ),\n    JS_CFUNC_MAGIC_DEF(\"cdiv\", 2, js_bigint_div, BF_RNDU ),\n    JS_CFUNC_MAGIC_DEF(\"ediv\", 2, js_bigint_div, BF_DIVREM_EUCLIDIAN ),\n    JS_CFUNC_MAGIC_DEF(\"tdivrem\", 2, js_bigint_div, BF_RNDZ | 0x10 ),\n    JS_CFUNC_MAGIC_DEF(\"fdivrem\", 2, js_bigint_div, BF_RNDD | 0x10 ),\n    JS_CFUNC_MAGIC_DEF(\"cdivrem\", 2, js_bigint_div, BF_RNDU | 0x10 ),\n    JS_CFUNC_MAGIC_DEF(\"edivrem\", 2, js_bigint_div, BF_DIVREM_EUCLIDIAN | 0x10 ),\n    JS_CFUNC_MAGIC_DEF(\"sqrt\", 1, js_bigint_sqrt, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"sqrtrem\", 1, js_bigint_sqrt, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"floorLog2\", 1, js_bigint_op1, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"ctz\", 1, js_bigint_op1, 1 ),\n};\n\nstatic const JSCFunctionListEntry js_bigint_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_bigint_toString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_bigint_valueOf ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"BigInt\", JS_PROP_CONFIGURABLE ),\n};\n\nvoid JS_AddIntrinsicBigInt(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    JSValue obj1;\n\n    rt->bigint_ops.to_string = js_bigint_to_string;\n    rt->bigint_ops.from_string = js_string_to_bigint;\n    rt->bigint_ops.unary_arith = js_unary_arith_bigint;\n    rt->bigint_ops.binary_arith = js_binary_arith_bigint;\n    rt->bigint_ops.compare = js_compare_bigfloat;\n    \n    ctx->class_proto[JS_CLASS_BIG_INT] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_BIG_INT],\n                               js_bigint_proto_funcs,\n                               countof(js_bigint_proto_funcs));\n    obj1 = JS_NewCFunction(ctx, js_bigint_constructor, \"BigInt\", 1);\n    JS_NewGlobalCConstructor2(ctx, obj1, \"BigInt\",\n                              ctx->class_proto[JS_CLASS_BIG_INT]);\n    JS_SetPropertyFunctionList(ctx, obj1, js_bigint_funcs,\n                               countof(js_bigint_funcs));\n}\n\n/* BigFloat */\n\nstatic JSValue js_thisBigFloatValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_IsBigFloat(this_val))\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_BIG_FLOAT) {\n            if (JS_IsBigFloat(p->u.object_data))\n                return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a bigfloat\");\n}\n\nstatic JSValue js_bigfloat_toString(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValue val;\n    int base;\n    JSValue ret;\n\n    val = js_thisBigFloatValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (argc == 0 || JS_IsUndefined(argv[0])) {\n        base = 10;\n    } else {\n        base = js_get_radix(ctx, argv[0]);\n        if (base < 0)\n            goto fail;\n    }\n    ret = js_ftoa(ctx, val, base, 0, BF_RNDN | BF_FTOA_FORMAT_FREE_MIN);\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigfloat_valueOf(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    return js_thisBigFloatValue(ctx, this_val);\n}\n\nstatic int bigfloat_get_rnd_mode(JSContext *ctx, JSValueConst val)\n{\n    int rnd_mode;\n    if (JS_ToInt32Sat(ctx, &rnd_mode, val))\n        return -1;\n    if (rnd_mode < BF_RNDN || rnd_mode > BF_RNDF) {\n        JS_ThrowRangeError(ctx, \"invalid rounding mode\");\n        return -1;\n    }\n    return rnd_mode;\n}\n\nstatic JSValue js_bigfloat_toFixed(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    int64_t f;\n    int rnd_mode, radix;\n\n    val = js_thisBigFloatValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToInt64Sat(ctx, &f, argv[0]))\n        goto fail;\n    if (f < 0 || f > BF_PREC_MAX) {\n        JS_ThrowRangeError(ctx, \"invalid number of digits\");\n        goto fail;\n    }\n    rnd_mode = BF_RNDNA;\n    radix = 10;\n    /* XXX: swap parameter order for rounding mode and radix */\n    if (argc > 1) {\n        rnd_mode = bigfloat_get_rnd_mode(ctx, argv[1]);\n        if (rnd_mode < 0)\n            goto fail;\n    }\n    if (argc > 2) {\n        radix = js_get_radix(ctx, argv[2]);\n        if (radix < 0)\n            goto fail;\n    }\n    ret = js_ftoa(ctx, val, radix, f, rnd_mode | BF_FTOA_FORMAT_FRAC);\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic BOOL js_bigfloat_is_finite(JSContext *ctx, JSValueConst val)\n{\n    BOOL res;\n    uint32_t tag;\n\n    tag = JS_VALUE_GET_NORM_TAG(val);\n    switch(tag) {\n    case JS_TAG_BIG_FLOAT:\n        {\n            JSBigFloat *p = JS_VALUE_GET_PTR(val);\n            res = bf_is_finite(&p->num);\n        }\n        break;\n    default:\n        res = FALSE;\n        break;\n    }\n    return res;\n}\n\nstatic JSValue js_bigfloat_toExponential(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    int64_t f;\n    int rnd_mode, radix;\n\n    val = js_thisBigFloatValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToInt64Sat(ctx, &f, argv[0]))\n        goto fail;\n    if (!js_bigfloat_is_finite(ctx, val)) {\n        ret = JS_ToString(ctx, val);\n    } else if (JS_IsUndefined(argv[0])) {\n        ret = js_ftoa(ctx, val, 10, 0,\n                      BF_RNDN | BF_FTOA_FORMAT_FREE_MIN | BF_FTOA_FORCE_EXP);\n    } else {\n        if (f < 0 || f > BF_PREC_MAX) {\n            JS_ThrowRangeError(ctx, \"invalid number of digits\");\n            goto fail;\n        }\n        rnd_mode = BF_RNDNA;\n        radix = 10;\n        if (argc > 1) {\n            rnd_mode = bigfloat_get_rnd_mode(ctx, argv[1]);\n            if (rnd_mode < 0)\n                goto fail;\n        }\n        if (argc > 2) {\n            radix = js_get_radix(ctx, argv[2]);\n            if (radix < 0)\n                goto fail;\n        }\n        ret = js_ftoa(ctx, val, radix, f + 1,\n                      rnd_mode | BF_FTOA_FORMAT_FIXED | BF_FTOA_FORCE_EXP);\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigfloat_toPrecision(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    int64_t p;\n    int rnd_mode, radix;\n\n    val = js_thisBigFloatValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_IsUndefined(argv[0]))\n        goto to_string;\n    if (JS_ToInt64Sat(ctx, &p, argv[0]))\n        goto fail;\n    if (!js_bigfloat_is_finite(ctx, val)) {\n    to_string:\n        ret = JS_ToString(ctx, this_val);\n    } else {\n        if (p < 1 || p > BF_PREC_MAX) {\n            JS_ThrowRangeError(ctx, \"invalid number of digits\");\n            goto fail;\n        }\n        rnd_mode = BF_RNDNA;\n        radix = 10;\n        if (argc > 1) {\n            rnd_mode = bigfloat_get_rnd_mode(ctx, argv[1]);\n            if (rnd_mode < 0)\n                goto fail;\n        }\n        if (argc > 2) {\n            radix = js_get_radix(ctx, argv[2]);\n            if (radix < 0)\n                goto fail;\n        }\n        ret = js_ftoa(ctx, val, radix, p, rnd_mode | BF_FTOA_FORMAT_FIXED);\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic const JSCFunctionListEntry js_bigfloat_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_bigfloat_toString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_bigfloat_valueOf ),\n    JS_CFUNC_DEF(\"toPrecision\", 1, js_bigfloat_toPrecision ),\n    JS_CFUNC_DEF(\"toFixed\", 1, js_bigfloat_toFixed ),\n    JS_CFUNC_DEF(\"toExponential\", 1, js_bigfloat_toExponential ),\n};\n\nstatic JSValue js_bigfloat_constructor(JSContext *ctx,\n                                       JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValue val;\n    if (argc == 0) {\n        bf_t *r;\n        val = JS_NewBigFloat(ctx);\n        if (JS_IsException(val))\n            return val;\n        r = JS_GetBigFloat(val);\n        bf_set_zero(r, 0);\n    } else {\n        val = JS_DupValue(ctx, argv[0]);\n    redo:\n        switch(JS_VALUE_GET_NORM_TAG(val)) {\n        case JS_TAG_BIG_FLOAT:\n            break;\n        case JS_TAG_FLOAT64:\n            {\n                bf_t *r;\n                double d = JS_VALUE_GET_FLOAT64(val);\n                val = JS_NewBigFloat(ctx);\n                if (JS_IsException(val))\n                    break;\n                r = JS_GetBigFloat(val);\n                if (bf_set_float64(r, d))\n                    goto fail;\n            }\n            break;\n        case JS_TAG_INT:\n            {\n                bf_t *r;\n                int32_t v = JS_VALUE_GET_INT(val);\n                val = JS_NewBigFloat(ctx);\n                if (JS_IsException(val))\n                    break;\n                r = JS_GetBigFloat(val);\n                if (bf_set_si(r, v))\n                    goto fail;\n            }\n            break;\n        case JS_TAG_BIG_INT:\n            /* We keep the full precision of the integer */\n            {\n                JSBigFloat *p = JS_VALUE_GET_PTR(val);\n                val = JS_MKPTR(JS_TAG_BIG_FLOAT, p);\n            }\n            break;\n        case JS_TAG_BIG_DECIMAL:\n            val = JS_ToStringFree(ctx, val);\n            if (JS_IsException(val))\n                break;\n            goto redo;\n        case JS_TAG_STRING:\n            {\n                const char *str, *p;\n                size_t len;\n                int err;\n\n                str = JS_ToCStringLen(ctx, &len, val);\n                JS_FreeValue(ctx, val);\n                if (!str)\n                    return JS_EXCEPTION;\n                p = str;\n                p += skip_spaces(p);\n                if ((p - str) == len) {\n                    bf_t *r;\n                    val = JS_NewBigFloat(ctx);\n                    if (JS_IsException(val))\n                        break;\n                    r = JS_GetBigFloat(val);\n                    bf_set_zero(r, 0);\n                    err = 0;\n                } else {\n                    val = js_atof(ctx, p, &p, 0, ATOD_ACCEPT_BIN_OCT |\n                                  ATOD_TYPE_BIG_FLOAT |\n                                  ATOD_ACCEPT_PREFIX_AFTER_SIGN);\n                    if (JS_IsException(val)) {\n                        JS_FreeCString(ctx, str);\n                        return JS_EXCEPTION;\n                    }\n                    p += skip_spaces(p);\n                    err = ((p - str) != len);\n                }\n                JS_FreeCString(ctx, str);\n                if (err) {\n                    JS_FreeValue(ctx, val);\n                    return JS_ThrowSyntaxError(ctx, \"invalid bigfloat literal\");\n                }\n            }\n            break;\n        case JS_TAG_OBJECT:\n            val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);\n            if (JS_IsException(val))\n                break;\n            goto redo;\n        case JS_TAG_NULL:\n        case JS_TAG_UNDEFINED:\n        default:\n            JS_FreeValue(ctx, val);\n            return JS_ThrowTypeError(ctx, \"cannot convert to bigfloat\");\n        }\n    }\n    return val;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigfloat_get_const(JSContext *ctx,\n                                     JSValueConst this_val, int magic)\n{\n    bf_t *r;\n    JSValue val;\n    val = JS_NewBigFloat(ctx);\n    if (JS_IsException(val))\n        return val;\n    r = JS_GetBigFloat(val);\n    switch(magic) {\n    case 0: /* PI */\n        bf_const_pi(r, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case 1: /* LN2 */\n        bf_const_log2(r, ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    case 2: /* MIN_VALUE */\n    case 3: /* MAX_VALUE */\n        {\n            slimb_t e_range, e;\n            e_range = (limb_t)1 << (bf_get_exp_bits(ctx->fp_env.flags) - 1);\n            bf_set_ui(r, 1);\n            if (magic == 2) {\n                e = -e_range + 2;\n                if (ctx->fp_env.flags & BF_FLAG_SUBNORMAL)\n                    e -= ctx->fp_env.prec - 1;\n                bf_mul_2exp(r, e, ctx->fp_env.prec, ctx->fp_env.flags);\n            } else {\n                bf_mul_2exp(r, ctx->fp_env.prec, ctx->fp_env.prec,\n                            ctx->fp_env.flags);\n                bf_add_si(r, r, -1, ctx->fp_env.prec, ctx->fp_env.flags);\n                bf_mul_2exp(r, e_range - ctx->fp_env.prec, ctx->fp_env.prec,\n                            ctx->fp_env.flags);\n            }\n        }\n        break;\n    case 4: /* EPSILON */\n        bf_set_ui(r, 1);\n        bf_mul_2exp(r, 1 - ctx->fp_env.prec,\n                    ctx->fp_env.prec, ctx->fp_env.flags);\n        break;\n    default:\n        abort();\n    }\n    return val;\n}\n\nstatic JSValue js_bigfloat_parseFloat(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    bf_t *a;\n    const char *str;\n    JSValue ret;\n    int radix;\n    JSFloatEnv *fe;\n\n    str = JS_ToCString(ctx, argv[0]);\n    if (!str)\n        return JS_EXCEPTION;\n    if (JS_ToInt32(ctx, &radix, argv[1])) {\n    fail:\n        JS_FreeCString(ctx, str);\n        return JS_EXCEPTION;\n    }\n    if (radix != 0 && (radix < 2 || radix > 36)) {\n        JS_ThrowRangeError(ctx, \"radix must be between 2 and 36\");\n        goto fail;\n    }\n    fe = &ctx->fp_env;\n    if (argc > 2) {\n        fe = JS_GetOpaque2(ctx, argv[2], JS_CLASS_FLOAT_ENV);\n        if (!fe)\n            goto fail;\n    }\n    ret = JS_NewBigFloat(ctx);\n    if (JS_IsException(ret))\n        goto done;\n    a = JS_GetBigFloat(ret);\n    /* XXX: use js_atof() */\n    bf_atof(a, str, NULL, radix, fe->prec, fe->flags);\n done:\n    JS_FreeCString(ctx, str);\n    return ret;\n}\n\nstatic JSValue js_bigfloat_isFinite(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValueConst val = argv[0];\n    JSBigFloat *p;\n    \n    if (JS_VALUE_GET_NORM_TAG(val) != JS_TAG_BIG_FLOAT)\n        return JS_FALSE;\n    p = JS_VALUE_GET_PTR(val);\n    return JS_NewBool(ctx, bf_is_finite(&p->num));\n}\n\nstatic JSValue js_bigfloat_isNaN(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValueConst val = argv[0];\n    JSBigFloat *p;\n    \n    if (JS_VALUE_GET_NORM_TAG(val) != JS_TAG_BIG_FLOAT)\n        return JS_FALSE;\n    p = JS_VALUE_GET_PTR(val);\n    return JS_NewBool(ctx, bf_is_nan(&p->num));\n}\n\nenum {\n    MATH_OP_ABS,\n    MATH_OP_FLOOR,\n    MATH_OP_CEIL,\n    MATH_OP_ROUND,\n    MATH_OP_TRUNC,\n    MATH_OP_SQRT,\n    MATH_OP_FPROUND,\n    MATH_OP_ACOS,\n    MATH_OP_ASIN,\n    MATH_OP_ATAN,\n    MATH_OP_ATAN2,\n    MATH_OP_COS,\n    MATH_OP_EXP,\n    MATH_OP_LOG,\n    MATH_OP_POW,\n    MATH_OP_SIN,\n    MATH_OP_TAN,\n    MATH_OP_FMOD,\n    MATH_OP_REM,\n    MATH_OP_SIGN,\n\n    MATH_OP_ADD,\n    MATH_OP_SUB,\n    MATH_OP_MUL,\n    MATH_OP_DIV,\n};\n\nstatic JSValue js_bigfloat_fop(JSContext *ctx, JSValueConst this_val,\n                           int argc, JSValueConst *argv, int magic)\n{\n    bf_t a_s, *a, *r;\n    JSFloatEnv *fe;\n    int rnd_mode;\n    JSValue op1, res;\n\n    op1 = JS_ToNumeric(ctx, argv[0]);\n    if (JS_IsException(op1))\n        return op1;\n    a = JS_ToBigFloat(ctx, &a_s, op1);\n    fe = &ctx->fp_env;\n    if (argc > 1) {\n        fe = JS_GetOpaque2(ctx, argv[1], JS_CLASS_FLOAT_ENV);\n        if (!fe)\n            goto fail;\n    }\n    res = JS_NewBigFloat(ctx);\n    if (JS_IsException(res)) {\n    fail:\n        if (a == &a_s)\n            bf_delete(a);\n        JS_FreeValue(ctx, op1);\n        return JS_EXCEPTION;\n    }\n    r = JS_GetBigFloat(res);\n    switch (magic) {\n    case MATH_OP_ABS:\n        bf_set(r, a);\n        r->sign = 0;\n        break;\n    case MATH_OP_FLOOR:\n        rnd_mode = BF_RNDD;\n        goto rint;\n    case MATH_OP_CEIL:\n        rnd_mode = BF_RNDU;\n        goto rint;\n    case MATH_OP_ROUND:\n        rnd_mode = BF_RNDNA;\n        goto rint;\n    case MATH_OP_TRUNC:\n        rnd_mode = BF_RNDZ;\n    rint:\n        bf_set(r, a);\n        fe->status |= bf_rint(r, rnd_mode);\n        break;\n    case MATH_OP_SQRT:\n        fe->status |= bf_sqrt(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_FPROUND:\n        bf_set(r, a);\n        fe->status |= bf_round(r, fe->prec, fe->flags);\n        break;\n    case MATH_OP_ACOS:\n        fe->status |= bf_acos(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_ASIN:\n        fe->status |= bf_asin(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_ATAN:\n        fe->status |= bf_atan(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_COS:\n        fe->status |= bf_cos(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_EXP:\n        fe->status |= bf_exp(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_LOG:\n        fe->status |= bf_log(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_SIN:\n        fe->status |= bf_sin(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_TAN:\n        fe->status |= bf_tan(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_SIGN:\n        if (bf_is_nan(a) || bf_is_zero(a)) {\n            bf_set(r, a);\n        } else {\n            bf_set_si(r, 1 - 2 * a->sign);\n        }\n        break;\n    default:\n        abort();\n    }\n    if (a == &a_s)\n        bf_delete(a);\n    JS_FreeValue(ctx, op1);\n    return res;\n}\n\nstatic JSValue js_bigfloat_fop2(JSContext *ctx, JSValueConst this_val,\n                            int argc, JSValueConst *argv, int magic)\n{\n    bf_t a_s, *a, b_s, *b, r_s, *r = &r_s;\n    JSFloatEnv *fe;\n    JSValue op1, op2, res;\n\n    op1 = JS_ToNumeric(ctx, argv[0]);\n    if (JS_IsException(op1))\n        return op1;\n    op2 = JS_ToNumeric(ctx, argv[1]);\n    if (JS_IsException(op2)) {\n        JS_FreeValue(ctx, op1);\n        return op2;\n    }\n    a = JS_ToBigFloat(ctx, &a_s, op1);\n    b = JS_ToBigFloat(ctx, &b_s, op2);\n    fe = &ctx->fp_env;\n    if (argc > 2) {\n        fe = JS_GetOpaque2(ctx, argv[2], JS_CLASS_FLOAT_ENV);\n        if (!fe)\n            goto fail;\n    }\n    res = JS_NewBigFloat(ctx);\n    if (JS_IsException(res)) {\n    fail:\n        if (a == &a_s)\n            bf_delete(a);\n        if (b == &b_s)\n            bf_delete(b);\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        return JS_EXCEPTION;\n    }\n    r = JS_GetBigFloat(res);\n    switch (magic) {\n    case MATH_OP_ATAN2:\n        fe->status |= bf_atan2(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_POW:\n        fe->status |= bf_pow(r, a, b, fe->prec, fe->flags | BF_POW_JS_QUIRKS);\n        break;\n    case MATH_OP_FMOD:\n        fe->status |= bf_rem(r, a, b, fe->prec, fe->flags, BF_RNDZ);\n        break;\n    case MATH_OP_REM:\n        fe->status |= bf_rem(r, a, b, fe->prec, fe->flags, BF_RNDN);\n        break;\n    case MATH_OP_ADD:\n        fe->status |= bf_add(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_SUB:\n        fe->status |= bf_sub(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_MUL:\n        fe->status |= bf_mul(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_DIV:\n        fe->status |= bf_div(r, a, b, fe->prec, fe->flags);\n        break;\n    default:\n        abort();\n    }\n    if (a == &a_s)\n        bf_delete(a);\n    if (b == &b_s)\n        bf_delete(b);\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    return res;\n}\n\nstatic const JSCFunctionListEntry js_bigfloat_funcs[] = {\n    JS_CGETSET_MAGIC_DEF(\"PI\", js_bigfloat_get_const, NULL, 0 ),\n    JS_CGETSET_MAGIC_DEF(\"LN2\", js_bigfloat_get_const, NULL, 1 ),\n    JS_CGETSET_MAGIC_DEF(\"MIN_VALUE\", js_bigfloat_get_const, NULL, 2 ),\n    JS_CGETSET_MAGIC_DEF(\"MAX_VALUE\", js_bigfloat_get_const, NULL, 3 ),\n    JS_CGETSET_MAGIC_DEF(\"EPSILON\", js_bigfloat_get_const, NULL, 4 ),\n    JS_CFUNC_DEF(\"parseFloat\", 1, js_bigfloat_parseFloat ),\n    JS_CFUNC_DEF(\"isFinite\", 1, js_bigfloat_isFinite ),\n    JS_CFUNC_DEF(\"isNaN\", 1, js_bigfloat_isNaN ),\n    JS_CFUNC_MAGIC_DEF(\"abs\", 1, js_bigfloat_fop, MATH_OP_ABS ),\n    JS_CFUNC_MAGIC_DEF(\"fpRound\", 1, js_bigfloat_fop, MATH_OP_FPROUND ),\n    JS_CFUNC_MAGIC_DEF(\"floor\", 1, js_bigfloat_fop, MATH_OP_FLOOR ),\n    JS_CFUNC_MAGIC_DEF(\"ceil\", 1, js_bigfloat_fop, MATH_OP_CEIL ),\n    JS_CFUNC_MAGIC_DEF(\"round\", 1, js_bigfloat_fop, MATH_OP_ROUND ),\n    JS_CFUNC_MAGIC_DEF(\"trunc\", 1, js_bigfloat_fop, MATH_OP_TRUNC ),\n    JS_CFUNC_MAGIC_DEF(\"sqrt\", 1, js_bigfloat_fop, MATH_OP_SQRT ),\n    JS_CFUNC_MAGIC_DEF(\"acos\", 1, js_bigfloat_fop, MATH_OP_ACOS ),\n    JS_CFUNC_MAGIC_DEF(\"asin\", 1, js_bigfloat_fop, MATH_OP_ASIN ),\n    JS_CFUNC_MAGIC_DEF(\"atan\", 1, js_bigfloat_fop, MATH_OP_ATAN ),\n    JS_CFUNC_MAGIC_DEF(\"atan2\", 2, js_bigfloat_fop2, MATH_OP_ATAN2 ),\n    JS_CFUNC_MAGIC_DEF(\"cos\", 1, js_bigfloat_fop, MATH_OP_COS ),\n    JS_CFUNC_MAGIC_DEF(\"exp\", 1, js_bigfloat_fop, MATH_OP_EXP ),\n    JS_CFUNC_MAGIC_DEF(\"log\", 1, js_bigfloat_fop, MATH_OP_LOG ),\n    JS_CFUNC_MAGIC_DEF(\"pow\", 2, js_bigfloat_fop2, MATH_OP_POW ),\n    JS_CFUNC_MAGIC_DEF(\"sin\", 1, js_bigfloat_fop, MATH_OP_SIN ),\n    JS_CFUNC_MAGIC_DEF(\"tan\", 1, js_bigfloat_fop, MATH_OP_TAN ),\n    JS_CFUNC_MAGIC_DEF(\"sign\", 1, js_bigfloat_fop, MATH_OP_SIGN ),\n    JS_CFUNC_MAGIC_DEF(\"add\", 2, js_bigfloat_fop2, MATH_OP_ADD ),\n    JS_CFUNC_MAGIC_DEF(\"sub\", 2, js_bigfloat_fop2, MATH_OP_SUB ),\n    JS_CFUNC_MAGIC_DEF(\"mul\", 2, js_bigfloat_fop2, MATH_OP_MUL ),\n    JS_CFUNC_MAGIC_DEF(\"div\", 2, js_bigfloat_fop2, MATH_OP_DIV ),\n    JS_CFUNC_MAGIC_DEF(\"fmod\", 2, js_bigfloat_fop2, MATH_OP_FMOD ),\n    JS_CFUNC_MAGIC_DEF(\"remainder\", 2, js_bigfloat_fop2, MATH_OP_REM ),\n};\n\n/* FloatEnv */\n\nstatic JSValue js_float_env_constructor(JSContext *ctx,\n                                        JSValueConst new_target,\n                                        int argc, JSValueConst *argv)\n{\n    JSValue obj;\n    JSFloatEnv *fe;\n    int64_t prec;\n    int flags, rndmode;\n\n    prec = ctx->fp_env.prec;\n    flags = ctx->fp_env.flags;\n    if (!JS_IsUndefined(argv[0])) {\n        if (JS_ToInt64Sat(ctx, &prec, argv[0]))\n            return JS_EXCEPTION;\n        if (prec < BF_PREC_MIN || prec > BF_PREC_MAX)\n            return JS_ThrowRangeError(ctx, \"invalid precision\");\n        flags = BF_RNDN; /* RNDN, max exponent size, no subnormal */\n        if (argc > 1 && !JS_IsUndefined(argv[1])) {\n            if (JS_ToInt32Sat(ctx, &rndmode, argv[1]))\n                return JS_EXCEPTION;\n            if (rndmode < BF_RNDN || rndmode > BF_RNDF)\n                return JS_ThrowRangeError(ctx, \"invalid rounding mode\");\n            flags = rndmode;\n        }\n    }\n\n    obj = JS_NewObjectClass(ctx, JS_CLASS_FLOAT_ENV);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    fe = js_malloc(ctx, sizeof(*fe));\n    if (!fe)\n        return JS_EXCEPTION;\n    fe->prec = prec;\n    fe->flags = flags;\n    fe->status = 0;\n    JS_SetOpaque(obj, fe);\n    return obj;\n}\n\nstatic void js_float_env_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSFloatEnv *fe = JS_GetOpaque(val, JS_CLASS_FLOAT_ENV);\n    js_free_rt(rt, fe);\n}\n\nstatic JSValue js_float_env_get_prec(JSContext *ctx, JSValueConst this_val)\n{\n    return JS_NewInt64(ctx, ctx->fp_env.prec);\n}\n\nstatic JSValue js_float_env_get_expBits(JSContext *ctx, JSValueConst this_val)\n{\n    return JS_NewInt32(ctx, bf_get_exp_bits(ctx->fp_env.flags));\n}\n\nstatic JSValue js_float_env_setPrec(JSContext *ctx,\n                                    JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValueConst func;\n    int exp_bits, flags, saved_flags;\n    JSValue ret;\n    limb_t saved_prec;\n    int64_t prec;\n\n    func = argv[0];\n    if (JS_ToInt64Sat(ctx, &prec, argv[1]))\n        return JS_EXCEPTION;\n    if (prec < BF_PREC_MIN || prec > BF_PREC_MAX)\n        return JS_ThrowRangeError(ctx, \"invalid precision\");\n    exp_bits = BF_EXP_BITS_MAX;\n\n    if (argc > 2 && !JS_IsUndefined(argv[2])) {\n        if (JS_ToInt32Sat(ctx, &exp_bits, argv[2]))\n            return JS_EXCEPTION;\n        if (exp_bits < BF_EXP_BITS_MIN || exp_bits > BF_EXP_BITS_MAX)\n            return JS_ThrowRangeError(ctx, \"invalid number of exponent bits\");\n    }\n\n    flags = BF_RNDN | BF_FLAG_SUBNORMAL | bf_set_exp_bits(exp_bits);\n\n    saved_prec = ctx->fp_env.prec;\n    saved_flags = ctx->fp_env.flags;\n\n    ctx->fp_env.prec = prec;\n    ctx->fp_env.flags = flags;\n\n    ret = JS_Call(ctx, func, JS_UNDEFINED, 0, NULL);\n    /* always restore the floating point precision */\n    ctx->fp_env.prec = saved_prec;\n    ctx->fp_env.flags = saved_flags;\n    return ret;\n}\n\n#define FE_PREC      (-1)\n#define FE_EXP       (-2)\n#define FE_RNDMODE   (-3)\n#define FE_SUBNORMAL (-4)\n\nstatic JSValue js_float_env_proto_get_status(JSContext *ctx, JSValueConst this_val, int magic)\n{\n    JSFloatEnv *fe;\n    fe = JS_GetOpaque2(ctx, this_val, JS_CLASS_FLOAT_ENV);\n    if (!fe)\n        return JS_EXCEPTION;\n    switch(magic) {\n    case FE_PREC:\n        return JS_NewInt64(ctx, fe->prec);\n    case FE_EXP:\n        return JS_NewInt32(ctx, bf_get_exp_bits(fe->flags));\n    case FE_RNDMODE:\n        return JS_NewInt32(ctx, fe->flags & BF_RND_MASK);\n    case FE_SUBNORMAL:\n        return JS_NewBool(ctx, (fe->flags & BF_FLAG_SUBNORMAL) != 0);\n    default:\n        return JS_NewBool(ctx, (fe->status & magic) != 0);\n    }\n}\n\nstatic JSValue js_float_env_proto_set_status(JSContext *ctx, JSValueConst this_val, JSValueConst val, int magic)\n{\n    JSFloatEnv *fe;\n    int b;\n    int64_t prec;\n\n    fe = JS_GetOpaque2(ctx, this_val, JS_CLASS_FLOAT_ENV);\n    if (!fe)\n        return JS_EXCEPTION;\n    switch(magic) {\n    case FE_PREC:\n        if (JS_ToInt64Sat(ctx, &prec, val))\n            return JS_EXCEPTION;\n        if (prec < BF_PREC_MIN || prec > BF_PREC_MAX)\n            return JS_ThrowRangeError(ctx, \"invalid precision\");\n        fe->prec = prec;\n        break;\n    case FE_EXP:\n        if (JS_ToInt32Sat(ctx, &b, val))\n            return JS_EXCEPTION;\n        if (b < BF_EXP_BITS_MIN || b > BF_EXP_BITS_MAX)\n            return JS_ThrowRangeError(ctx, \"invalid number of exponent bits\");\n        fe->flags = (fe->flags & ~(BF_EXP_BITS_MASK << BF_EXP_BITS_SHIFT)) |\n            bf_set_exp_bits(b);\n        break;\n    case FE_RNDMODE:\n        b = bigfloat_get_rnd_mode(ctx, val);\n        if (b < 0)\n            return JS_EXCEPTION;\n        fe->flags = (fe->flags & ~BF_RND_MASK) | b;\n        break;\n    case FE_SUBNORMAL:\n        b = JS_ToBool(ctx, val);\n        fe->flags = (fe->flags & ~BF_FLAG_SUBNORMAL) | (b ? BF_FLAG_SUBNORMAL: 0);\n        break;\n    default:\n        b = JS_ToBool(ctx, val);\n        fe->status = (fe->status & ~magic) & ((-b) & magic);\n        break;\n    }\n    return JS_UNDEFINED;\n}\n\nstatic JSValue js_float_env_clearStatus(JSContext *ctx,\n                                        JSValueConst this_val,\n                                        int argc, JSValueConst *argv)\n{\n    JSFloatEnv *fe = JS_GetOpaque2(ctx, this_val, JS_CLASS_FLOAT_ENV);\n    if (!fe)\n        return JS_EXCEPTION;\n    fe->status = 0;\n    return JS_UNDEFINED;\n}\n\nstatic const JSCFunctionListEntry js_float_env_funcs[] = {\n    JS_CGETSET_DEF(\"prec\", js_float_env_get_prec, NULL ),\n    JS_CGETSET_DEF(\"expBits\", js_float_env_get_expBits, NULL ),\n    JS_CFUNC_DEF(\"setPrec\", 2, js_float_env_setPrec ),\n    JS_PROP_INT32_DEF(\"RNDN\", BF_RNDN, 0 ),\n    JS_PROP_INT32_DEF(\"RNDZ\", BF_RNDZ, 0 ),\n    JS_PROP_INT32_DEF(\"RNDU\", BF_RNDU, 0 ),\n    JS_PROP_INT32_DEF(\"RNDD\", BF_RNDD, 0 ),\n    JS_PROP_INT32_DEF(\"RNDNA\", BF_RNDNA, 0 ),\n    JS_PROP_INT32_DEF(\"RNDA\", BF_RNDA, 0 ),\n    JS_PROP_INT32_DEF(\"RNDF\", BF_RNDF, 0 ),\n    JS_PROP_INT32_DEF(\"precMin\", BF_PREC_MIN, 0 ),\n    JS_PROP_INT64_DEF(\"precMax\", BF_PREC_MAX, 0 ),\n    JS_PROP_INT32_DEF(\"expBitsMin\", BF_EXP_BITS_MIN, 0 ),\n    JS_PROP_INT32_DEF(\"expBitsMax\", BF_EXP_BITS_MAX, 0 ),\n};\n\nstatic const JSCFunctionListEntry js_float_env_proto_funcs[] = {\n    JS_CGETSET_MAGIC_DEF(\"prec\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, FE_PREC ),\n    JS_CGETSET_MAGIC_DEF(\"expBits\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, FE_EXP ),\n    JS_CGETSET_MAGIC_DEF(\"rndMode\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, FE_RNDMODE ),\n    JS_CGETSET_MAGIC_DEF(\"subnormal\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, FE_SUBNORMAL ),\n    JS_CGETSET_MAGIC_DEF(\"invalidOperation\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, BF_ST_INVALID_OP ),\n    JS_CGETSET_MAGIC_DEF(\"divideByZero\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, BF_ST_DIVIDE_ZERO ),\n    JS_CGETSET_MAGIC_DEF(\"overflow\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, BF_ST_OVERFLOW ),\n    JS_CGETSET_MAGIC_DEF(\"underflow\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, BF_ST_UNDERFLOW ),\n    JS_CGETSET_MAGIC_DEF(\"inexact\", js_float_env_proto_get_status,\n                         js_float_env_proto_set_status, BF_ST_INEXACT ),\n    JS_CFUNC_DEF(\"clearStatus\", 0, js_float_env_clearStatus ),\n};\n\nvoid JS_AddIntrinsicBigFloat(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    JSValue obj1;\n    JSValueConst obj2;\n    \n    rt->bigfloat_ops.to_string = js_bigfloat_to_string;\n    rt->bigfloat_ops.from_string = js_string_to_bigfloat;\n    rt->bigfloat_ops.unary_arith = js_unary_arith_bigfloat;\n    rt->bigfloat_ops.binary_arith = js_binary_arith_bigfloat;\n    rt->bigfloat_ops.compare = js_compare_bigfloat;\n    rt->bigfloat_ops.mul_pow10_to_float64 = js_mul_pow10_to_float64;\n    rt->bigfloat_ops.mul_pow10 = js_mul_pow10;\n    \n    ctx->class_proto[JS_CLASS_BIG_FLOAT] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_BIG_FLOAT],\n                               js_bigfloat_proto_funcs,\n                               countof(js_bigfloat_proto_funcs));\n    obj1 = JS_NewCFunction(ctx, js_bigfloat_constructor, \"BigFloat\", 1);\n    JS_NewGlobalCConstructor2(ctx, obj1, \"BigFloat\",\n                              ctx->class_proto[JS_CLASS_BIG_FLOAT]);\n    JS_SetPropertyFunctionList(ctx, obj1, js_bigfloat_funcs,\n                               countof(js_bigfloat_funcs));\n\n    ctx->class_proto[JS_CLASS_FLOAT_ENV] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_FLOAT_ENV],\n                               js_float_env_proto_funcs,\n                               countof(js_float_env_proto_funcs));\n    obj2 = JS_NewGlobalCConstructorOnly(ctx, \"BigFloatEnv\",\n                                        js_float_env_constructor, 1,\n                                        ctx->class_proto[JS_CLASS_FLOAT_ENV]);\n    JS_SetPropertyFunctionList(ctx, obj2, js_float_env_funcs,\n                               countof(js_float_env_funcs));\n}\n\n/* BigDecimal */\n\nstatic JSValue JS_ToBigDecimalFree(JSContext *ctx, JSValue val,\n                                   BOOL allow_null_or_undefined)\n{\n redo:\n    switch(JS_VALUE_GET_NORM_TAG(val)) {\n    case JS_TAG_BIG_DECIMAL:\n        break;\n    case JS_TAG_NULL:\n        if (!allow_null_or_undefined)\n            goto fail;\n        /* fall thru */\n    case JS_TAG_BOOL:\n    case JS_TAG_INT:\n        {\n            bfdec_t *r;\n            int32_t v = JS_VALUE_GET_INT(val);\n\n            val = JS_NewBigDecimal(ctx);\n            if (JS_IsException(val))\n                break;\n            r = JS_GetBigDecimal(val);\n            if (bfdec_set_si(r, v)) {\n                JS_FreeValue(ctx, val);\n                val = JS_EXCEPTION;\n                break;\n            }\n        }\n        break;\n    case JS_TAG_FLOAT64:\n    case JS_TAG_BIG_INT:\n    case JS_TAG_BIG_FLOAT:\n        val = JS_ToStringFree(ctx, val);\n        if (JS_IsException(val))\n            break;\n        goto redo;\n    case JS_TAG_STRING:\n        {\n            const char *str, *p;\n            size_t len;\n            int err;\n\n            str = JS_ToCStringLen(ctx, &len, val);\n            JS_FreeValue(ctx, val);\n            if (!str)\n                return JS_EXCEPTION;\n            p = str;\n            p += skip_spaces(p);\n            if ((p - str) == len) {\n                bfdec_t *r;\n                val = JS_NewBigDecimal(ctx);\n                if (JS_IsException(val))\n                    break;\n                r = JS_GetBigDecimal(val);\n                bfdec_set_zero(r, 0);\n                err = 0;\n            } else {\n                val = js_atof(ctx, p, &p, 0, ATOD_TYPE_BIG_DECIMAL);\n                if (JS_IsException(val)) {\n                    JS_FreeCString(ctx, str);\n                    return JS_EXCEPTION;\n                }\n                p += skip_spaces(p);\n                err = ((p - str) != len);\n            }\n            JS_FreeCString(ctx, str);\n            if (err) {\n                JS_FreeValue(ctx, val);\n                return JS_ThrowSyntaxError(ctx, \"invalid bigdecimal literal\");\n            }\n        }\n        break;\n    case JS_TAG_OBJECT:\n        val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER);\n        if (JS_IsException(val))\n            break;\n        goto redo;\n    case JS_TAG_UNDEFINED:\n        {\n            bfdec_t *r;\n            if (!allow_null_or_undefined)\n                goto fail;\n            val = JS_NewBigDecimal(ctx);\n            if (JS_IsException(val))\n                break;\n            r = JS_GetBigDecimal(val);\n            bfdec_set_nan(r);\n        }\n        break;\n    default:\n    fail:\n        JS_FreeValue(ctx, val);\n        return JS_ThrowTypeError(ctx, \"cannot convert to bigdecimal\");\n    }\n    return val;\n}\n\nstatic JSValue js_bigdecimal_constructor(JSContext *ctx,\n                                         JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    JSValue val;\n    if (argc == 0) {\n        bfdec_t *r;\n        val = JS_NewBigDecimal(ctx);\n        if (JS_IsException(val))\n            return val;\n        r = JS_GetBigDecimal(val);\n        bfdec_set_zero(r, 0);\n    } else {\n        val = JS_ToBigDecimalFree(ctx, JS_DupValue(ctx, argv[0]), FALSE);\n    }\n    return val;\n}\n\nstatic JSValue js_thisBigDecimalValue(JSContext *ctx, JSValueConst this_val)\n{\n    if (JS_IsBigDecimal(this_val))\n        return JS_DupValue(ctx, this_val);\n\n    if (JS_VALUE_GET_TAG(this_val) == JS_TAG_OBJECT) {\n        JSObject *p = JS_VALUE_GET_OBJ(this_val);\n        if (p->class_id == JS_CLASS_BIG_DECIMAL) {\n            if (JS_IsBigDecimal(p->u.object_data))\n                return JS_DupValue(ctx, p->u.object_data);\n        }\n    }\n    return JS_ThrowTypeError(ctx, \"not a bigdecimal\");\n}\n\nstatic JSValue js_bigdecimal_toString(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    JSValue val;\n\n    val = js_thisBigDecimalValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    return JS_ToStringFree(ctx, val);\n}\n\nstatic JSValue js_bigdecimal_valueOf(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    return js_thisBigDecimalValue(ctx, this_val);\n}\n\nstatic int js_bigdecimal_get_rnd_mode(JSContext *ctx, JSValueConst obj)\n{\n    const char *str;\n    size_t size;\n    int rnd_mode;\n    \n    str = JS_ToCStringLen(ctx, &size, obj);\n    if (!str)\n        return -1;\n    if (strlen(str) != size)\n        goto invalid_rounding_mode;\n    if (!strcmp(str, \"floor\")) {\n        rnd_mode = BF_RNDD;\n    } else if (!strcmp(str, \"ceiling\")) {\n        rnd_mode = BF_RNDU;\n    } else if (!strcmp(str, \"down\")) {\n        rnd_mode = BF_RNDZ;\n    } else if (!strcmp(str, \"up\")) {\n        rnd_mode = BF_RNDA;\n    } else if (!strcmp(str, \"half-even\")) {\n        rnd_mode = BF_RNDN;\n    } else if (!strcmp(str, \"half-up\")) {\n        rnd_mode = BF_RNDNA;\n    } else {\n    invalid_rounding_mode:\n        JS_FreeCString(ctx, str);\n        JS_ThrowTypeError(ctx, \"invalid rounding mode\");\n        return -1;\n    }\n    JS_FreeCString(ctx, str);\n    return rnd_mode;\n}\n\ntypedef struct {\n    int64_t prec;\n    bf_flags_t flags;\n} BigDecimalEnv;\n\nstatic int js_bigdecimal_get_env(JSContext *ctx, BigDecimalEnv *fe,\n                                 JSValueConst obj)\n{\n    JSValue prop;\n    int64_t val;\n    BOOL has_prec;\n    int rnd_mode;\n    \n    if (!JS_IsObject(obj)) {\n        JS_ThrowTypeErrorNotAnObject(ctx);\n        return -1;\n    }\n    prop = JS_GetProperty(ctx, obj, JS_ATOM_roundingMode);\n    if (JS_IsException(prop))\n        return -1;\n    rnd_mode = js_bigdecimal_get_rnd_mode(ctx, prop);\n    JS_FreeValue(ctx, prop);\n    if (rnd_mode < 0)\n        return -1;\n    fe->flags = rnd_mode;\n    \n    prop = JS_GetProperty(ctx, obj, JS_ATOM_maximumSignificantDigits);\n    if (JS_IsException(prop))\n        return -1;\n    has_prec = FALSE;\n    if (!JS_IsUndefined(prop)) {\n        if (JS_ToInt64SatFree(ctx, &val, prop))\n            return -1;\n        if (val < 1 || val > BF_PREC_MAX)\n            goto invalid_precision;\n        fe->prec = val;\n        has_prec = TRUE;\n    }\n\n    prop = JS_GetProperty(ctx, obj, JS_ATOM_maximumFractionDigits);\n    if (JS_IsException(prop))\n        return -1;\n    if (!JS_IsUndefined(prop)) {\n        if (has_prec) {\n            JS_FreeValue(ctx, prop);\n            JS_ThrowTypeError(ctx, \"cannot provide both maximumSignificantDigits and maximumFractionDigits\");\n            return -1;\n        }\n        if (JS_ToInt64SatFree(ctx, &val, prop))\n            return -1;\n        if (val < 0 || val > BF_PREC_MAX) {\n        invalid_precision:\n            JS_ThrowTypeError(ctx, \"invalid precision\");\n            return -1;\n        }\n        fe->prec = val;\n        fe->flags |= BF_FLAG_RADPNT_PREC;\n        has_prec = TRUE;\n    }\n    if (!has_prec) {\n        JS_ThrowTypeError(ctx, \"precision must be present\");\n        return -1;\n    }\n    return 0;\n}\n\n\nstatic JSValue js_bigdecimal_fop(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv, int magic)\n{\n    bfdec_t *a, *b, r_s, *r = &r_s;\n    JSValue op1, op2, res;\n    BigDecimalEnv fe_s, *fe = &fe_s;\n    int op_count, ret;\n\n    if (magic == MATH_OP_SQRT ||\n        magic == MATH_OP_ROUND)\n        op_count = 1;\n    else\n        op_count = 2;\n    \n    op1 = JS_ToNumeric(ctx, argv[0]);\n    if (JS_IsException(op1))\n        return op1;\n    a = JS_ToBigDecimal(ctx, op1);\n    if (!a) {\n        JS_FreeValue(ctx, op1);\n        return JS_EXCEPTION;\n    }\n    if (op_count >= 2) {\n        op2 = JS_ToNumeric(ctx, argv[1]);\n        if (JS_IsException(op2)) {\n            JS_FreeValue(ctx, op1);\n            return op2;\n        }\n        b = JS_ToBigDecimal(ctx, op2);\n        if (!b)\n            goto fail;\n    } else {\n        op2 = JS_UNDEFINED;\n        b = NULL;\n    }\n    fe->flags = BF_RNDZ;\n    fe->prec = BF_PREC_INF;\n    if (op_count < argc) {\n        if (js_bigdecimal_get_env(ctx, fe, argv[op_count]))\n            goto fail;\n    }\n\n    res = JS_NewBigDecimal(ctx);\n    if (JS_IsException(res)) {\n    fail:\n        JS_FreeValue(ctx, op1);\n        JS_FreeValue(ctx, op2);\n        return JS_EXCEPTION;\n    }\n    r = JS_GetBigDecimal(res);\n    switch (magic) {\n    case MATH_OP_ADD:\n        ret = bfdec_add(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_SUB:\n        ret = bfdec_sub(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_MUL:\n        ret = bfdec_mul(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_DIV:\n        ret = bfdec_div(r, a, b, fe->prec, fe->flags);\n        break;\n    case MATH_OP_FMOD:\n        ret = bfdec_rem(r, a, b, fe->prec, fe->flags, BF_RNDZ);\n        break;\n    case MATH_OP_SQRT:\n        ret = bfdec_sqrt(r, a, fe->prec, fe->flags);\n        break;\n    case MATH_OP_ROUND:\n        ret = bfdec_set(r, a);\n        if (!(ret & BF_ST_MEM_ERROR))\n            ret = bfdec_round(r, fe->prec, fe->flags);\n        break;\n    default:\n        abort();\n    }\n    JS_FreeValue(ctx, op1);\n    JS_FreeValue(ctx, op2);\n    ret &= BF_ST_MEM_ERROR | BF_ST_DIVIDE_ZERO | BF_ST_INVALID_OP |\n        BF_ST_OVERFLOW;\n    if (ret != 0) {\n        JS_FreeValue(ctx, res);\n        return throw_bf_exception(ctx, ret);\n    } else {\n        return res;\n    }\n}\n\nstatic JSValue js_bigdecimal_toFixed(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    int64_t f;\n    int rnd_mode;\n\n    val = js_thisBigDecimalValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToInt64Sat(ctx, &f, argv[0]))\n        goto fail;\n    if (f < 0 || f > BF_PREC_MAX) {\n        JS_ThrowRangeError(ctx, \"invalid number of digits\");\n        goto fail;\n    }\n    rnd_mode = BF_RNDNA;\n    if (argc > 1) {\n        rnd_mode = js_bigdecimal_get_rnd_mode(ctx, argv[1]);\n        if (rnd_mode < 0)\n            goto fail;\n    }\n    ret = js_bigdecimal_to_string1(ctx, val, f, rnd_mode | BF_FTOA_FORMAT_FRAC);\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigdecimal_toExponential(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    int64_t f;\n    int rnd_mode;\n\n    val = js_thisBigDecimalValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_ToInt64Sat(ctx, &f, argv[0]))\n        goto fail;\n    if (JS_IsUndefined(argv[0])) {\n        ret = js_bigdecimal_to_string1(ctx, val, 0,\n                  BF_RNDN | BF_FTOA_FORMAT_FREE_MIN | BF_FTOA_FORCE_EXP);\n    } else {\n        if (f < 0 || f > BF_PREC_MAX) {\n            JS_ThrowRangeError(ctx, \"invalid number of digits\");\n            goto fail;\n        }\n        rnd_mode = BF_RNDNA;\n        if (argc > 1) {\n            rnd_mode = js_bigdecimal_get_rnd_mode(ctx, argv[1]);\n            if (rnd_mode < 0)\n                goto fail;\n        }\n        ret = js_bigdecimal_to_string1(ctx, val, f + 1,\n                      rnd_mode | BF_FTOA_FORMAT_FIXED | BF_FTOA_FORCE_EXP);\n    }\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_bigdecimal_toPrecision(JSContext *ctx, JSValueConst this_val,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue val, ret;\n    int64_t p;\n    int rnd_mode;\n\n    val = js_thisBigDecimalValue(ctx, this_val);\n    if (JS_IsException(val))\n        return val;\n    if (JS_IsUndefined(argv[0])) {\n        return JS_ToStringFree(ctx, val);\n    }\n    if (JS_ToInt64Sat(ctx, &p, argv[0]))\n        goto fail;\n    if (p < 1 || p > BF_PREC_MAX) {\n        JS_ThrowRangeError(ctx, \"invalid number of digits\");\n        goto fail;\n    }\n    rnd_mode = BF_RNDNA;\n    if (argc > 1) {\n        rnd_mode = js_bigdecimal_get_rnd_mode(ctx, argv[1]);\n        if (rnd_mode < 0)\n            goto fail;\n    }\n    ret = js_bigdecimal_to_string1(ctx, val, p,\n                                   rnd_mode | BF_FTOA_FORMAT_FIXED);\n    JS_FreeValue(ctx, val);\n    return ret;\n fail:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\nstatic const JSCFunctionListEntry js_bigdecimal_proto_funcs[] = {\n    JS_CFUNC_DEF(\"toString\", 0, js_bigdecimal_toString ),\n    JS_CFUNC_DEF(\"valueOf\", 0, js_bigdecimal_valueOf ),\n    JS_CFUNC_DEF(\"toPrecision\", 1, js_bigdecimal_toPrecision ),\n    JS_CFUNC_DEF(\"toFixed\", 1, js_bigdecimal_toFixed ),\n    JS_CFUNC_DEF(\"toExponential\", 1, js_bigdecimal_toExponential ),\n};\n\nstatic const JSCFunctionListEntry js_bigdecimal_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"add\", 2, js_bigdecimal_fop, MATH_OP_ADD ),\n    JS_CFUNC_MAGIC_DEF(\"sub\", 2, js_bigdecimal_fop, MATH_OP_SUB ),\n    JS_CFUNC_MAGIC_DEF(\"mul\", 2, js_bigdecimal_fop, MATH_OP_MUL ),\n    JS_CFUNC_MAGIC_DEF(\"div\", 2, js_bigdecimal_fop, MATH_OP_DIV ),\n    JS_CFUNC_MAGIC_DEF(\"mod\", 2, js_bigdecimal_fop, MATH_OP_FMOD ),\n    JS_CFUNC_MAGIC_DEF(\"round\", 1, js_bigdecimal_fop, MATH_OP_ROUND ),\n    JS_CFUNC_MAGIC_DEF(\"sqrt\", 1, js_bigdecimal_fop, MATH_OP_SQRT ),\n};\n\nvoid JS_AddIntrinsicBigDecimal(JSContext *ctx)\n{\n    JSRuntime *rt = ctx->rt;\n    JSValue obj1;\n\n    rt->bigdecimal_ops.to_string = js_bigdecimal_to_string;\n    rt->bigdecimal_ops.from_string = js_string_to_bigdecimal;\n    rt->bigdecimal_ops.unary_arith = js_unary_arith_bigdecimal;\n    rt->bigdecimal_ops.binary_arith = js_binary_arith_bigdecimal;\n    rt->bigdecimal_ops.compare = js_compare_bigdecimal;\n\n    ctx->class_proto[JS_CLASS_BIG_DECIMAL] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_BIG_DECIMAL],\n                               js_bigdecimal_proto_funcs,\n                               countof(js_bigdecimal_proto_funcs));\n    obj1 = JS_NewCFunction(ctx, js_bigdecimal_constructor, \"BigDecimal\", 1);\n    JS_NewGlobalCConstructor2(ctx, obj1, \"BigDecimal\",\n                              ctx->class_proto[JS_CLASS_BIG_DECIMAL]);\n    JS_SetPropertyFunctionList(ctx, obj1, js_bigdecimal_funcs,\n                               countof(js_bigdecimal_funcs));\n}\n\nvoid JS_EnableBignumExt(JSContext *ctx, BOOL enable)\n{\n    ctx->bignum_ext = enable;\n}\n\n#endif /* CONFIG_BIGNUM */\n\nstatic const char * const native_error_name[JS_NATIVE_ERROR_COUNT] = {\n    \"EvalError\", \"RangeError\", \"ReferenceError\",\n    \"SyntaxError\", \"TypeError\", \"URIError\",\n    \"InternalError\", \"AggregateError\",\n};\n\n/* Minimum amount of objects to be able to compile code and display\n   error messages. No JSAtom should be allocated by this function. */\nstatic void JS_AddIntrinsicBasicObjects(JSContext *ctx)\n{\n    JSValue proto;\n    int i;\n\n    ctx->class_proto[JS_CLASS_OBJECT] = JS_NewObjectProto(ctx, JS_NULL);\n    ctx->function_proto = JS_NewCFunction3(ctx, js_function_proto, \"\", 0,\n                                           JS_CFUNC_generic, 0,\n                                           ctx->class_proto[JS_CLASS_OBJECT]);\n    ctx->class_proto[JS_CLASS_BYTECODE_FUNCTION] = JS_DupValue(ctx, ctx->function_proto);\n    ctx->class_proto[JS_CLASS_ERROR] = JS_NewObject(ctx);\n#if 0\n    /* these are auto-initialized from js_error_proto_funcs,\n       but delaying might be a problem */\n    JS_DefinePropertyValue(ctx, ctx->class_proto[JS_CLASS_ERROR], JS_ATOM_name,\n                           JS_AtomToString(ctx, JS_ATOM_Error),\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n    JS_DefinePropertyValue(ctx, ctx->class_proto[JS_CLASS_ERROR], JS_ATOM_message,\n                           JS_AtomToString(ctx, JS_ATOM_empty_string),\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n#endif\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ERROR],\n                               js_error_proto_funcs,\n                               countof(js_error_proto_funcs));\n\n    for(i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {\n        proto = JS_NewObjectProto(ctx, ctx->class_proto[JS_CLASS_ERROR]);\n        JS_DefinePropertyValue(ctx, proto, JS_ATOM_name,\n                               JS_NewAtomString(ctx, native_error_name[i]),\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n        JS_DefinePropertyValue(ctx, proto, JS_ATOM_message,\n                               JS_AtomToString(ctx, JS_ATOM_empty_string),\n                               JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n        ctx->native_error_proto[i] = proto;\n    }\n\n    /* the array prototype is an array */\n    ctx->class_proto[JS_CLASS_ARRAY] =\n        JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                               JS_CLASS_ARRAY);\n\n    ctx->array_shape = js_new_shape2(ctx, get_proto_obj(ctx->class_proto[JS_CLASS_ARRAY]),\n                                     JS_PROP_INITIAL_HASH_SIZE, 1);\n    add_shape_property(ctx, &ctx->array_shape, NULL,\n                       JS_ATOM_length, JS_PROP_WRITABLE | JS_PROP_LENGTH);\n\n    /* XXX: could test it on first context creation to ensure that no\n       new atoms are created in JS_AddIntrinsicBasicObjects(). It is\n       necessary to avoid useless renumbering of atoms after\n       JS_EvalBinary() if it is done just after\n       JS_AddIntrinsicBasicObjects(). */\n    //    assert(ctx->rt->atom_count == JS_ATOM_END);\n}\n\nvoid JS_AddIntrinsicBaseObjects(JSContext *ctx)\n{\n    int i;\n    JSValueConst obj, number_obj;\n    JSValue obj1;\n\n    ctx->throw_type_error = JS_NewCFunction(ctx, js_throw_type_error, NULL, 0);\n\n    /* add caller and arguments properties to throw a TypeError */\n    obj1 = JS_NewCFunction(ctx, js_function_proto_caller, NULL, 0);\n    JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_caller, JS_UNDEFINED,\n                      obj1, ctx->throw_type_error,\n                      JS_PROP_HAS_GET | JS_PROP_HAS_SET |\n                      JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);\n    JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_arguments, JS_UNDEFINED,\n                      obj1, ctx->throw_type_error,\n                      JS_PROP_HAS_GET | JS_PROP_HAS_SET |\n                      JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE);\n    JS_FreeValue(ctx, obj1);\n    JS_FreeValue(ctx, js_object_seal(ctx, JS_UNDEFINED, 1, (JSValueConst *)&ctx->throw_type_error, 1));\n\n    ctx->global_obj = JS_NewObject(ctx);\n    ctx->global_var_obj = JS_NewObjectProto(ctx, JS_NULL);\n\n    /* Object */\n    obj = JS_NewGlobalCConstructor(ctx, \"Object\", js_object_constructor, 1,\n                                   ctx->class_proto[JS_CLASS_OBJECT]);\n    JS_SetPropertyFunctionList(ctx, obj, js_object_funcs, countof(js_object_funcs));\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                               js_object_proto_funcs, countof(js_object_proto_funcs));\n\n    /* Function */\n    JS_SetPropertyFunctionList(ctx, ctx->function_proto, js_function_proto_funcs, countof(js_function_proto_funcs));\n    ctx->function_ctor = JS_NewCFunctionMagic(ctx, js_function_constructor,\n                                              \"Function\", 1, JS_CFUNC_constructor_or_func_magic,\n                                              JS_FUNC_NORMAL);\n    JS_NewGlobalCConstructor2(ctx, JS_DupValue(ctx, ctx->function_ctor), \"Function\",\n                              ctx->function_proto);\n\n    /* Error */\n    obj1 = JS_NewCFunctionMagic(ctx, js_error_constructor,\n                                \"Error\", 1, JS_CFUNC_constructor_or_func_magic, -1);\n    JS_NewGlobalCConstructor2(ctx, obj1,\n                              \"Error\", ctx->class_proto[JS_CLASS_ERROR]);\n\n    for(i = 0; i < JS_NATIVE_ERROR_COUNT; i++) {\n        JSValue func_obj;\n        int n_args;\n        n_args = 1 + (i == JS_AGGREGATE_ERROR);\n        func_obj = JS_NewCFunction3(ctx, (JSCFunction *)js_error_constructor,\n                                    native_error_name[i], n_args,\n                                    JS_CFUNC_constructor_or_func_magic, i, obj1);\n        JS_NewGlobalCConstructor2(ctx, func_obj, native_error_name[i],\n                                  ctx->native_error_proto[i]);\n    }\n\n    /* Iterator prototype */\n    ctx->iterator_proto = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->iterator_proto,\n                               js_iterator_proto_funcs,\n                               countof(js_iterator_proto_funcs));\n\n    /* Array */\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ARRAY],\n                               js_array_proto_funcs,\n                               countof(js_array_proto_funcs));\n\n    obj = JS_NewGlobalCConstructor(ctx, \"Array\", js_array_constructor, 1,\n                                   ctx->class_proto[JS_CLASS_ARRAY]);\n    ctx->array_ctor = JS_DupValue(ctx, obj);\n    JS_SetPropertyFunctionList(ctx, obj, js_array_funcs,\n                               countof(js_array_funcs));\n\n    /* XXX: create auto_initializer */\n    {\n        /* initialize Array.prototype[Symbol.unscopables] */\n        char const unscopables[] = \"copyWithin\" \"\\0\" \"entries\" \"\\0\" \"fill\" \"\\0\" \"find\" \"\\0\"\n            \"findIndex\" \"\\0\" \"flat\" \"\\0\" \"flatMap\" \"\\0\" \"includes\" \"\\0\" \"keys\" \"\\0\" \"values\" \"\\0\";\n        const char *p = unscopables;\n        obj1 = JS_NewObjectProto(ctx, JS_NULL);\n        for(p = unscopables; *p; p += strlen(p) + 1) {\n            JS_DefinePropertyValueStr(ctx, obj1, p, JS_TRUE, JS_PROP_C_W_E);\n        }\n        JS_DefinePropertyValue(ctx, ctx->class_proto[JS_CLASS_ARRAY],\n                               JS_ATOM_Symbol_unscopables, obj1,\n                               JS_PROP_CONFIGURABLE);\n    }\n\n    /* needed to initialize arguments[Symbol.iterator] */\n    ctx->array_proto_values =\n        JS_GetProperty(ctx, ctx->class_proto[JS_CLASS_ARRAY], JS_ATOM_values);\n\n    ctx->class_proto[JS_CLASS_ARRAY_ITERATOR] = JS_NewObjectProto(ctx, ctx->iterator_proto);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ARRAY_ITERATOR],\n                               js_array_iterator_proto_funcs,\n                               countof(js_array_iterator_proto_funcs));\n\n    /* parseFloat and parseInteger must be defined before Number\n       because of the Number.parseFloat and Number.parseInteger\n       aliases */\n    JS_SetPropertyFunctionList(ctx, ctx->global_obj, js_global_funcs,\n                               countof(js_global_funcs));\n\n    /* Number */\n    ctx->class_proto[JS_CLASS_NUMBER] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                                                               JS_CLASS_NUMBER);\n    JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_NUMBER], JS_NewInt32(ctx, 0));\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_NUMBER],\n                               js_number_proto_funcs,\n                               countof(js_number_proto_funcs));\n    number_obj = JS_NewGlobalCConstructor(ctx, \"Number\", js_number_constructor, 1,\n                                          ctx->class_proto[JS_CLASS_NUMBER]);\n    JS_SetPropertyFunctionList(ctx, number_obj, js_number_funcs, countof(js_number_funcs));\n\n    /* Boolean */\n    ctx->class_proto[JS_CLASS_BOOLEAN] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                                                                JS_CLASS_BOOLEAN);\n    JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], JS_NewBool(ctx, FALSE));\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_BOOLEAN], js_boolean_proto_funcs,\n                               countof(js_boolean_proto_funcs));\n    JS_NewGlobalCConstructor(ctx, \"Boolean\", js_boolean_constructor, 1,\n                             ctx->class_proto[JS_CLASS_BOOLEAN]);\n\n    /* String */\n    ctx->class_proto[JS_CLASS_STRING] = JS_NewObjectProtoClass(ctx, ctx->class_proto[JS_CLASS_OBJECT],\n                                                               JS_CLASS_STRING);\n    JS_SetObjectData(ctx, ctx->class_proto[JS_CLASS_STRING], JS_AtomToString(ctx, JS_ATOM_empty_string));\n    obj = JS_NewGlobalCConstructor(ctx, \"String\", js_string_constructor, 1,\n                                   ctx->class_proto[JS_CLASS_STRING]);\n    JS_SetPropertyFunctionList(ctx, obj, js_string_funcs,\n                               countof(js_string_funcs));\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_STRING], js_string_proto_funcs,\n                               countof(js_string_proto_funcs));\n\n    ctx->class_proto[JS_CLASS_STRING_ITERATOR] = JS_NewObjectProto(ctx, ctx->iterator_proto);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_STRING_ITERATOR],\n                               js_string_iterator_proto_funcs,\n                               countof(js_string_iterator_proto_funcs));\n\n    /* Math: create as autoinit object */\n    js_random_init(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->global_obj, js_math_obj, countof(js_math_obj));\n\n    /* ES6 Reflect: create as autoinit object */\n    JS_SetPropertyFunctionList(ctx, ctx->global_obj, js_reflect_obj, countof(js_reflect_obj));\n\n    /* ES6 Symbol */\n    ctx->class_proto[JS_CLASS_SYMBOL] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_SYMBOL], js_symbol_proto_funcs,\n                               countof(js_symbol_proto_funcs));\n    obj = JS_NewGlobalCConstructor(ctx, \"Symbol\", js_symbol_constructor, 0,\n                                   ctx->class_proto[JS_CLASS_SYMBOL]);\n    JS_SetPropertyFunctionList(ctx, obj, js_symbol_funcs,\n                               countof(js_symbol_funcs));\n    for(i = JS_ATOM_Symbol_toPrimitive; i < JS_ATOM_END; i++) {\n        char buf[ATOM_GET_STR_BUF_SIZE];\n        const char *str, *p;\n        str = JS_AtomGetStr(ctx, buf, sizeof(buf), i);\n        /* skip \"Symbol.\" */\n        p = strchr(str, '.');\n        if (p)\n            str = p + 1;\n        JS_DefinePropertyValueStr(ctx, obj, str, JS_AtomToValue(ctx, i), 0);\n    }\n\n    /* ES6 Generator */\n    ctx->class_proto[JS_CLASS_GENERATOR] = JS_NewObjectProto(ctx, ctx->iterator_proto);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_GENERATOR],\n                               js_generator_proto_funcs,\n                               countof(js_generator_proto_funcs));\n\n    ctx->class_proto[JS_CLASS_GENERATOR_FUNCTION] = JS_NewObjectProto(ctx, ctx->function_proto);\n    obj1 = JS_NewCFunctionMagic(ctx, js_function_constructor,\n                                \"GeneratorFunction\", 1,\n                                JS_CFUNC_constructor_or_func_magic, JS_FUNC_GENERATOR);\n    JS_SetPropertyFunctionList(ctx,\n                               ctx->class_proto[JS_CLASS_GENERATOR_FUNCTION],\n                               js_generator_function_proto_funcs,\n                               countof(js_generator_function_proto_funcs));\n    JS_SetConstructor2(ctx, ctx->class_proto[JS_CLASS_GENERATOR_FUNCTION],\n                       ctx->class_proto[JS_CLASS_GENERATOR],\n                       JS_PROP_CONFIGURABLE, JS_PROP_CONFIGURABLE);\n    JS_SetConstructor2(ctx, obj1, ctx->class_proto[JS_CLASS_GENERATOR_FUNCTION],\n                       0, JS_PROP_CONFIGURABLE);\n    JS_FreeValue(ctx, obj1);\n\n    /* global properties */\n    ctx->eval_obj = JS_NewCFunction(ctx, js_global_eval, \"eval\", 1);\n    JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_eval,\n                           JS_DupValue(ctx, ctx->eval_obj),\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n\n    JS_DefinePropertyValue(ctx, ctx->global_obj, JS_ATOM_globalThis,\n                           JS_DupValue(ctx, ctx->global_obj),\n                           JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE);\n}\n\n/* Typed Arrays */\n\nstatic uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT] = {\n    0, 0, 0, 1, 1, 2, 2,\n#ifdef CONFIG_BIGNUM\n    3, 3, /* BigInt64Array, BigUint64Array */\n#endif\n    2, 3\n};\n\nstatic JSValue js_array_buffer_constructor3(JSContext *ctx,\n                                            JSValueConst new_target,\n                                            uint64_t len, JSClassID class_id,\n                                            uint8_t *buf,\n                                            JSFreeArrayBufferDataFunc *free_func,\n                                            void *opaque, BOOL alloc_flag)\n{\n    JSRuntime *rt = ctx->rt;\n    JSValue obj;\n    JSArrayBuffer *abuf = NULL;\n\n    obj = js_create_from_ctor(ctx, new_target, class_id);\n    if (JS_IsException(obj))\n        return obj;\n    /* XXX: we are currently limited to 2 GB */\n    if (len > INT32_MAX) {\n        JS_ThrowRangeError(ctx, \"invalid array buffer length\");\n        goto fail;\n    }\n    abuf = js_malloc(ctx, sizeof(*abuf));\n    if (!abuf)\n        goto fail;\n    abuf->byte_length = len;\n    if (alloc_flag) {\n        if (class_id == JS_CLASS_SHARED_ARRAY_BUFFER &&\n            rt->sab_funcs.sab_alloc) {\n            abuf->data = rt->sab_funcs.sab_alloc(rt->sab_funcs.sab_opaque,\n                                                 max_int(len, 1));\n            if (!abuf->data)\n                goto fail;\n            memset(abuf->data, 0, len);\n        } else {\n            /* the allocation must be done after the object creation */\n            abuf->data = js_mallocz(ctx, max_int(len, 1));\n            if (!abuf->data)\n                goto fail;\n        }\n    } else {\n        if (class_id == JS_CLASS_SHARED_ARRAY_BUFFER &&\n            rt->sab_funcs.sab_dup) {\n            rt->sab_funcs.sab_dup(rt->sab_funcs.sab_opaque, buf);\n        }\n        abuf->data = buf;\n    }\n    init_list_head(&abuf->array_list);\n    abuf->detached = FALSE;\n    abuf->shared = (class_id == JS_CLASS_SHARED_ARRAY_BUFFER);\n    abuf->opaque = opaque;\n    abuf->free_func = free_func;\n    if (alloc_flag && buf)\n        memcpy(abuf->data, buf, len);\n    JS_SetOpaque(obj, abuf);\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    js_free(ctx, abuf);\n    return JS_EXCEPTION;\n}\n\nstatic void js_array_buffer_free(JSRuntime *rt, void *opaque, void *ptr)\n{\n    js_free_rt(rt, ptr);\n}\n\nstatic JSValue js_array_buffer_constructor2(JSContext *ctx,\n                                            JSValueConst new_target,\n                                            uint64_t len, JSClassID class_id)\n{\n    return js_array_buffer_constructor3(ctx, new_target, len, class_id,\n                                        NULL, js_array_buffer_free, NULL,\n                                        TRUE);\n}\n\nstatic JSValue js_array_buffer_constructor1(JSContext *ctx,\n                                            JSValueConst new_target,\n                                            uint64_t len)\n{\n    return js_array_buffer_constructor2(ctx, new_target, len,\n                                        JS_CLASS_ARRAY_BUFFER);\n}\n\nJSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,\n                          JSFreeArrayBufferDataFunc *free_func, void *opaque,\n                          BOOL is_shared)\n{\n    return js_array_buffer_constructor3(ctx, JS_UNDEFINED, len,\n                                        is_shared ? JS_CLASS_SHARED_ARRAY_BUFFER : JS_CLASS_ARRAY_BUFFER,\n                                        buf, free_func, opaque, FALSE);\n}\n\n/* create a new ArrayBuffer of length 'len' and copy 'buf' to it */\nJSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len)\n{\n    return js_array_buffer_constructor3(ctx, JS_UNDEFINED, len,\n                                        JS_CLASS_ARRAY_BUFFER,\n                                        (uint8_t *)buf,\n                                        js_array_buffer_free, NULL,\n                                        TRUE);\n}\n\nstatic JSValue js_array_buffer_constructor(JSContext *ctx,\n                                           JSValueConst new_target,\n                                           int argc, JSValueConst *argv)\n{\n    uint64_t len;\n    if (JS_ToIndex(ctx, &len, argv[0]))\n        return JS_EXCEPTION;\n    return js_array_buffer_constructor1(ctx, new_target, len);\n}\n\nstatic JSValue js_shared_array_buffer_constructor(JSContext *ctx,\n                                                  JSValueConst new_target,\n                                                  int argc, JSValueConst *argv)\n{\n    uint64_t len;\n    if (JS_ToIndex(ctx, &len, argv[0]))\n        return JS_EXCEPTION;\n    return js_array_buffer_constructor2(ctx, new_target, len,\n                                        JS_CLASS_SHARED_ARRAY_BUFFER);\n}\n\n/* also used for SharedArrayBuffer */\nstatic void js_array_buffer_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSArrayBuffer *abuf = p->u.array_buffer;\n    if (abuf) {\n        /* The ArrayBuffer finalizer may be called before the typed\n           array finalizers using it, so abuf->array_list is not\n           necessarily empty. */\n        // assert(list_empty(&abuf->array_list));\n        if (abuf->shared && rt->sab_funcs.sab_free) {\n            rt->sab_funcs.sab_free(rt->sab_funcs.sab_opaque, abuf->data);\n        } else {\n            if (abuf->free_func)\n                abuf->free_func(rt, abuf->opaque, abuf->data);\n        }\n        js_free_rt(rt, abuf);\n    }\n}\n\nstatic JSValue js_array_buffer_isView(JSContext *ctx,\n                                      JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    BOOL res;\n    res = FALSE;\n    if (JS_VALUE_GET_TAG(argv[0]) == JS_TAG_OBJECT) {\n        p = JS_VALUE_GET_OBJ(argv[0]);\n        if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n            p->class_id <= JS_CLASS_DATAVIEW) {\n            res = TRUE;\n        }\n    }\n    return JS_NewBool(ctx, res);\n}\n\nstatic const JSCFunctionListEntry js_array_buffer_funcs[] = {\n    JS_CFUNC_DEF(\"isView\", 1, js_array_buffer_isView ),\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL ),\n};\n\nstatic JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx)\n{\n    return JS_ThrowTypeError(ctx, \"ArrayBuffer is detached\");\n}\n\nstatic JSValue js_array_buffer_get_byteLength(JSContext *ctx,\n                                              JSValueConst this_val,\n                                              int class_id)\n{\n    JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, class_id);\n    if (!abuf)\n        return JS_EXCEPTION;\n    if (abuf->detached)\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    return JS_NewUint32(ctx, abuf->byte_length);\n}\n\nvoid JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj)\n{\n    JSArrayBuffer *abuf = JS_GetOpaque(obj, JS_CLASS_ARRAY_BUFFER);\n    struct list_head *el;\n\n    if (!abuf || abuf->detached)\n        return;\n    if (abuf->free_func)\n        abuf->free_func(ctx->rt, abuf->opaque, abuf->data);\n    abuf->data = NULL;\n    abuf->byte_length = 0;\n    abuf->detached = TRUE;\n\n    list_for_each(el, &abuf->array_list) {\n        JSTypedArray *ta;\n        JSObject *p;\n\n        ta = list_entry(el, JSTypedArray, link);\n        p = ta->obj;\n        /* Note: the typed array length and offset fields are not modified */\n        if (p->class_id != JS_CLASS_DATAVIEW) {\n            p->u.array.count = 0;\n            p->u.array.u.ptr = NULL;\n        }\n    }\n}\n\n/* get an ArrayBuffer or SharedArrayBuffer */\nstatic JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        goto fail;\n    p = JS_VALUE_GET_OBJ(obj);\n    if (p->class_id != JS_CLASS_ARRAY_BUFFER &&\n        p->class_id != JS_CLASS_SHARED_ARRAY_BUFFER) {\n    fail:\n        JS_ThrowTypeErrorInvalidClass(ctx, JS_CLASS_ARRAY_BUFFER);\n        return NULL;\n    }\n    return p->u.array_buffer;\n}\n\n/* return NULL if exception. WARNING: any JS call can detach the\n   buffer and render the returned pointer invalid */\nuint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj)\n{\n    JSArrayBuffer *abuf = js_get_array_buffer(ctx, obj);\n    if (!abuf)\n        goto fail;\n    if (abuf->detached) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    *psize = abuf->byte_length;\n    return abuf->data;\n fail:\n    *psize = 0;\n    return NULL;\n}\n\nstatic JSValue js_array_buffer_slice(JSContext *ctx,\n                                     JSValueConst this_val,\n                                     int argc, JSValueConst *argv, int class_id)\n{\n    JSArrayBuffer *abuf, *new_abuf;\n    int64_t len, start, end, new_len;\n    JSValue ctor, new_obj;\n\n    abuf = JS_GetOpaque2(ctx, this_val, class_id);\n    if (!abuf)\n        return JS_EXCEPTION;\n    if (abuf->detached)\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    len = abuf->byte_length;\n\n    if (JS_ToInt64Clamp(ctx, &start, argv[0], 0, len, len))\n        return JS_EXCEPTION;\n\n    end = len;\n    if (!JS_IsUndefined(argv[1])) {\n        if (JS_ToInt64Clamp(ctx, &end, argv[1], 0, len, len))\n            return JS_EXCEPTION;\n    }\n    new_len = max_int64(end - start, 0);\n    ctor = JS_SpeciesConstructor(ctx, this_val, JS_UNDEFINED);\n    if (JS_IsException(ctor))\n        return ctor;\n    if (JS_IsUndefined(ctor)) {\n        new_obj = js_array_buffer_constructor2(ctx, JS_UNDEFINED, new_len,\n                                               class_id);\n    } else {\n        JSValue args[1];\n        args[0] = JS_NewInt64(ctx, new_len);\n        new_obj = JS_CallConstructor(ctx, ctor, 1, (JSValueConst *)args);\n        JS_FreeValue(ctx, ctor);\n        JS_FreeValue(ctx, args[0]);\n    }\n    if (JS_IsException(new_obj))\n        return new_obj;\n    new_abuf = JS_GetOpaque2(ctx, new_obj, class_id);\n    if (!new_abuf)\n        goto fail;\n    if (js_same_value(ctx, new_obj, this_val)) {\n        JS_ThrowTypeError(ctx, \"cannot use identical ArrayBuffer\");\n        goto fail;\n    }\n    if (new_abuf->detached) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    if (new_abuf->byte_length < new_len) {\n        JS_ThrowTypeError(ctx, \"new ArrayBuffer is too small\");\n        goto fail;\n    }\n    /* must test again because of side effects */\n    if (abuf->detached) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    memcpy(new_abuf->data, abuf->data + start, new_len);\n    return new_obj;\n fail:\n    JS_FreeValue(ctx, new_obj);\n    return JS_EXCEPTION;\n}\n\nstatic const JSCFunctionListEntry js_array_buffer_proto_funcs[] = {\n    JS_CGETSET_MAGIC_DEF(\"byteLength\", js_array_buffer_get_byteLength, NULL, JS_CLASS_ARRAY_BUFFER ),\n    JS_CFUNC_MAGIC_DEF(\"slice\", 2, js_array_buffer_slice, JS_CLASS_ARRAY_BUFFER ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"ArrayBuffer\", JS_PROP_CONFIGURABLE ),\n};\n\n/* SharedArrayBuffer */\n\nstatic const JSCFunctionListEntry js_shared_array_buffer_funcs[] = {\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL ),\n};\n\nstatic const JSCFunctionListEntry js_shared_array_buffer_proto_funcs[] = {\n    JS_CGETSET_MAGIC_DEF(\"byteLength\", js_array_buffer_get_byteLength, NULL, JS_CLASS_SHARED_ARRAY_BUFFER ),\n    JS_CFUNC_MAGIC_DEF(\"slice\", 2, js_array_buffer_slice, JS_CLASS_SHARED_ARRAY_BUFFER ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"SharedArrayBuffer\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic JSObject *get_typed_array(JSContext *ctx,\n                                 JSValueConst this_val,\n                                 int is_dataview)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)\n        goto fail;\n    p = JS_VALUE_GET_OBJ(this_val);\n    if (is_dataview) {\n        if (p->class_id != JS_CLASS_DATAVIEW)\n            goto fail;\n    } else {\n        if (!(p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n              p->class_id <= JS_CLASS_FLOAT64_ARRAY)) {\n        fail:\n            JS_ThrowTypeError(ctx, \"not a %s\", is_dataview ? \"DataView\" : \"TypedArray\");\n            return NULL;\n        }\n    }\n    return p;\n}\n\n/* WARNING: 'p' must be a typed array */\nstatic BOOL typed_array_is_detached(JSContext *ctx, JSObject *p)\n{\n    JSTypedArray *ta = p->u.typed_array;\n    JSArrayBuffer *abuf = ta->buffer->u.array_buffer;\n    /* XXX: could simplify test by ensuring that\n       p->u.array.u.ptr is NULL iff it is detached */\n    return abuf->detached;\n}\n\n/* WARNING: 'p' must be a typed array. Works even if the array buffer\n   is detached */\nstatic uint32_t typed_array_get_length(JSContext *ctx, JSObject *p)\n{\n    JSTypedArray *ta = p->u.typed_array;\n    int size_log2 = typed_array_size_log2(p->class_id);\n    return ta->length >> size_log2;\n}\n\nstatic int validate_typed_array(JSContext *ctx, JSValueConst this_val)\n{\n    JSObject *p;\n    p = get_typed_array(ctx, this_val, 0);\n    if (!p)\n        return -1;\n    if (typed_array_is_detached(ctx, p)) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        return -1;\n    }\n    return 0;\n}\n\nstatic JSValue js_typed_array_get_length(JSContext *ctx,\n                                         JSValueConst this_val)\n{\n    JSObject *p;\n    p = get_typed_array(ctx, this_val, 0);\n    if (!p)\n        return JS_EXCEPTION;\n    return JS_NewInt32(ctx, p->u.array.count);\n}\n\nstatic JSValue js_typed_array_get_buffer(JSContext *ctx,\n                                         JSValueConst this_val, int is_dataview)\n{\n    JSObject *p;\n    JSTypedArray *ta;\n    p = get_typed_array(ctx, this_val, is_dataview);\n    if (!p)\n        return JS_EXCEPTION;\n    ta = p->u.typed_array;\n    return JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, ta->buffer));\n}\n\nstatic JSValue js_typed_array_get_byteLength(JSContext *ctx,\n                                             JSValueConst this_val,\n                                             int is_dataview)\n{\n    JSObject *p;\n    JSTypedArray *ta;\n    p = get_typed_array(ctx, this_val, is_dataview);\n    if (!p)\n        return JS_EXCEPTION;\n    if (typed_array_is_detached(ctx, p)) {\n        if (is_dataview) {\n            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        } else {\n            return JS_NewInt32(ctx, 0);\n        }\n    }\n    ta = p->u.typed_array;\n    return JS_NewInt32(ctx, ta->length);\n}\n\nstatic JSValue js_typed_array_get_byteOffset(JSContext *ctx,\n                                             JSValueConst this_val,\n                                             int is_dataview)\n{\n    JSObject *p;\n    JSTypedArray *ta;\n    p = get_typed_array(ctx, this_val, is_dataview);\n    if (!p)\n        return JS_EXCEPTION;\n    if (typed_array_is_detached(ctx, p)) {\n        if (is_dataview) {\n            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        } else {\n            return JS_NewInt32(ctx, 0);\n        }\n    }\n    ta = p->u.typed_array;\n    return JS_NewInt32(ctx, ta->offset);\n}\n\n/* Return the buffer associated to the typed array or an exception if\n   it is not a typed array or if the buffer is detached. pbyte_offset,\n   pbyte_length or pbytes_per_element can be NULL. */\nJSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,\n                               size_t *pbyte_offset,\n                               size_t *pbyte_length,\n                               size_t *pbytes_per_element)\n{\n    JSObject *p;\n    JSTypedArray *ta;\n    p = get_typed_array(ctx, obj, FALSE);\n    if (!p)\n        return JS_EXCEPTION;\n    if (typed_array_is_detached(ctx, p))\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    ta = p->u.typed_array;\n    if (pbyte_offset)\n        *pbyte_offset = ta->offset;\n    if (pbyte_length)\n        *pbyte_length = ta->length;\n    if (pbytes_per_element) {\n        *pbytes_per_element = 1 << typed_array_size_log2(p->class_id);\n    }\n    return JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, ta->buffer));\n}\n                               \nstatic JSValue js_typed_array_get_toStringTag(JSContext *ctx,\n                                              JSValueConst this_val)\n{\n    JSObject *p;\n    if (JS_VALUE_GET_TAG(this_val) != JS_TAG_OBJECT)\n        return JS_UNDEFINED;\n    p = JS_VALUE_GET_OBJ(this_val);\n    if (!(p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n          p->class_id <= JS_CLASS_FLOAT64_ARRAY))\n        return JS_UNDEFINED;\n    return JS_AtomToString(ctx, ctx->rt->class_array[p->class_id].class_name);\n}\n\nstatic JSValue js_typed_array_set_internal(JSContext *ctx,\n                                           JSValueConst dst,\n                                           JSValueConst src,\n                                           JSValueConst off)\n{\n    JSObject *p;\n    JSObject *src_p;\n    uint32_t i;\n    int64_t src_len, offset;\n    JSValue val, src_obj = JS_UNDEFINED;\n\n    p = get_typed_array(ctx, dst, 0);\n    if (!p)\n        goto fail;\n    if (JS_ToInt64Sat(ctx, &offset, off))\n        goto fail;\n    if (offset < 0)\n        goto range_error;\n    if (typed_array_is_detached(ctx, p)) {\n    detached:\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    src_obj = JS_ToObject(ctx, src);\n    if (JS_IsException(src_obj))\n        goto fail;\n    src_p = JS_VALUE_GET_OBJ(src_obj);\n    if (src_p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n        src_p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n        JSTypedArray *dest_ta = p->u.typed_array;\n        JSArrayBuffer *dest_abuf = dest_ta->buffer->u.array_buffer;\n        JSTypedArray *src_ta = src_p->u.typed_array;\n        JSArrayBuffer *src_abuf = src_ta->buffer->u.array_buffer;\n        int shift = typed_array_size_log2(p->class_id);\n\n        if (src_abuf->detached)\n            goto detached;\n\n        src_len = src_p->u.array.count;\n        if (offset > (int64_t)(p->u.array.count - src_len))\n            goto range_error;\n\n        /* copying between typed objects */\n        if (src_p->class_id == p->class_id) {\n            /* same type, use memmove */\n            memmove(dest_abuf->data + dest_ta->offset + (offset << shift),\n                    src_abuf->data + src_ta->offset, src_len << shift);\n            goto done;\n        }\n        if (dest_abuf->data == src_abuf->data) {\n            /* copying between the same buffer using different types of mappings\n               would require a temporary buffer */\n        }\n        /* otherwise, default behavior is slow but correct */\n    } else {\n        if (js_get_length64(ctx, &src_len, src_obj))\n            goto fail;\n        if (offset > (int64_t)(p->u.array.count - src_len)) {\n        range_error:\n            JS_ThrowRangeError(ctx, \"invalid array length\");\n            goto fail;\n        }\n    }\n    for(i = 0; i < src_len; i++) {\n        val = JS_GetPropertyUint32(ctx, src_obj, i);\n        if (JS_IsException(val))\n            goto fail;\n        if (JS_SetPropertyUint32(ctx, dst, offset + i, val) < 0)\n            goto fail;\n    }\ndone:\n    JS_FreeValue(ctx, src_obj);\n    return JS_UNDEFINED;\nfail:\n    JS_FreeValue(ctx, src_obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_set(JSContext *ctx,\n                                  JSValueConst this_val,\n                                  int argc, JSValueConst *argv)\n{\n    JSValueConst offset = JS_UNDEFINED;\n    if (argc > 1) {\n        offset = argv[1];\n    }\n    return js_typed_array_set_internal(ctx, this_val, argv[0], offset);\n}\n\nstatic JSValue js_create_typed_array_iterator(JSContext *ctx, JSValueConst this_val,\n                                              int argc, JSValueConst *argv, int magic)\n{\n    if (validate_typed_array(ctx, this_val))\n        return JS_EXCEPTION;\n    return js_create_array_iterator(ctx, this_val, argc, argv, magic);\n}\n\n/* return < 0 if exception */\nstatic int js_typed_array_get_length_internal(JSContext *ctx,\n                                              JSValueConst obj)\n{\n    JSObject *p;\n    p = get_typed_array(ctx, obj, 0);\n    if (!p)\n        return -1;\n    if (typed_array_is_detached(ctx, p)) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        return -1;\n    }\n    return p->u.array.count;\n}\n\n#if 0\n/* validate a typed array and return its length */\nstatic JSValue js_typed_array___getLength(JSContext *ctx,\n                                          JSValueConst this_val,\n                                          int argc, JSValueConst *argv)\n{\n    BOOL ignore_detached = JS_ToBool(ctx, argv[1]);\n\n    if (ignore_detached) {\n        return js_typed_array_get_length(ctx, argv[0]);\n    } else {\n        int len;\n        len = js_typed_array_get_length_internal(ctx, argv[0]);\n        if (len < 0)\n            return JS_EXCEPTION;\n        return JS_NewInt32(ctx, len);\n    }\n}\n#endif\n\nstatic JSValue js_typed_array_create(JSContext *ctx, JSValueConst ctor,\n                                     int argc, JSValueConst *argv)\n{\n    JSValue ret;\n    int new_len;\n    int64_t len;\n\n    ret = JS_CallConstructor(ctx, ctor, argc, argv);\n    if (JS_IsException(ret))\n        return ret;\n    /* validate the typed array */\n    new_len = js_typed_array_get_length_internal(ctx, ret);\n    if (new_len < 0)\n        goto fail;\n    if (argc == 1) {\n        /* ensure that it is large enough */\n        if (JS_ToLengthFree(ctx, &len, JS_DupValue(ctx, argv[0])))\n            goto fail;\n        if (new_len < len) {\n            JS_ThrowTypeError(ctx, \"TypedArray length is too small\");\n        fail:\n            JS_FreeValue(ctx, ret);\n            return JS_EXCEPTION;\n        }\n    }\n    return ret;\n}\n\n#if 0\nstatic JSValue js_typed_array___create(JSContext *ctx,\n                                       JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    return js_typed_array_create(ctx, argv[0], max_int(argc - 1, 0), argv + 1);\n}\n#endif\n\nstatic JSValue js_typed_array___speciesCreate(JSContext *ctx,\n                                              JSValueConst this_val,\n                                              int argc, JSValueConst *argv)\n{\n    JSValueConst obj;\n    JSObject *p;\n    JSValue ctor, ret;\n    int argc1;\n\n    obj = argv[0];\n    p = get_typed_array(ctx, obj, 0);\n    if (!p)\n        return JS_EXCEPTION;\n    ctor = JS_SpeciesConstructor(ctx, obj, JS_UNDEFINED);\n    if (JS_IsException(ctor))\n        return ctor;\n    argc1 = max_int(argc - 1, 0);\n    if (JS_IsUndefined(ctor)) {\n        ret = js_typed_array_constructor(ctx, JS_UNDEFINED, argc1, argv + 1,\n                                         p->class_id);\n    } else {\n        ret = js_typed_array_create(ctx, ctor, argc1, argv + 1);\n        JS_FreeValue(ctx, ctor);\n    }\n    return ret;\n}\n\nstatic JSValue js_typed_array_from(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    // from(items, mapfn = void 0, this_arg = void 0)\n    JSValueConst items = argv[0], mapfn, this_arg;\n    JSValueConst args[2];\n    JSValue stack[2];\n    JSValue iter, arr, r, v, v2;\n    int64_t k, len;\n    int done, mapping;\n\n    mapping = FALSE;\n    mapfn = JS_UNDEFINED;\n    this_arg = JS_UNDEFINED;\n    r = JS_UNDEFINED;\n    arr = JS_UNDEFINED;\n    stack[0] = JS_UNDEFINED;\n    stack[1] = JS_UNDEFINED;\n\n    if (argc > 1) {\n        mapfn = argv[1];\n        if (!JS_IsUndefined(mapfn)) {\n            if (check_function(ctx, mapfn))\n                goto exception;\n            mapping = 1;\n            if (argc > 2)\n                this_arg = argv[2];\n        }\n    }\n    iter = JS_GetProperty(ctx, items, JS_ATOM_Symbol_iterator);\n    if (JS_IsException(iter))\n        goto exception;\n    if (!JS_IsUndefined(iter)) {\n        JS_FreeValue(ctx, iter);\n        arr = JS_NewArray(ctx);\n        if (JS_IsException(arr))\n            goto exception;\n        stack[0] = JS_DupValue(ctx, items);\n        if (js_for_of_start(ctx, &stack[1], FALSE))\n            goto exception;\n        for (k = 0;; k++) {\n            v = JS_IteratorNext(ctx, stack[0], stack[1], 0, NULL, &done);\n            if (JS_IsException(v))\n                goto exception_close;\n            if (done)\n                break;\n            if (JS_DefinePropertyValueInt64(ctx, arr, k, v, JS_PROP_C_W_E | JS_PROP_THROW) < 0)\n                goto exception_close;\n        }\n    } else {\n        arr = JS_ToObject(ctx, items);\n        if (JS_IsException(arr))\n            goto exception;\n    }\n    if (js_get_length64(ctx, &len, arr) < 0)\n        goto exception;\n    v = JS_NewInt64(ctx, len);\n    args[0] = v;\n    r = js_typed_array_create(ctx, this_val, 1, args);\n    JS_FreeValue(ctx, v);\n    if (JS_IsException(r))\n        goto exception;\n    for(k = 0; k < len; k++) {\n        v = JS_GetPropertyInt64(ctx, arr, k);\n        if (JS_IsException(v))\n            goto exception;\n        if (mapping) {\n            args[0] = v;\n            args[1] = JS_NewInt32(ctx, k);\n            v2 = JS_Call(ctx, mapfn, this_arg, 2, args);\n            JS_FreeValue(ctx, v);\n            v = v2;\n            if (JS_IsException(v))\n                goto exception;\n        }\n        if (JS_SetPropertyInt64(ctx, r, k, v) < 0)\n            goto exception;\n    }\n    goto done;\n\n exception_close:\n    if (!JS_IsUndefined(stack[0]))\n        JS_IteratorClose(ctx, stack[0], TRUE);\n exception:\n    JS_FreeValue(ctx, r);\n    r = JS_EXCEPTION;\n done:\n    JS_FreeValue(ctx, arr);\n    JS_FreeValue(ctx, stack[0]);\n    JS_FreeValue(ctx, stack[1]);\n    return r;\n}\n\nstatic JSValue js_typed_array_of(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv)\n{\n    JSValue obj;\n    JSValueConst args[1];\n    int i;\n\n    args[0] = JS_NewInt32(ctx, argc);\n    obj = js_typed_array_create(ctx, this_val, 1, args);\n    if (JS_IsException(obj))\n        return obj;\n\n    for(i = 0; i < argc; i++) {\n        if (JS_SetPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i])) < 0) {\n            JS_FreeValue(ctx, obj);\n            return JS_EXCEPTION;\n        }\n    }\n    return obj;\n}\n\nstatic JSValue js_typed_array_copyWithin(JSContext *ctx, JSValueConst this_val,\n                                         int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    int len, to, from, final, count, shift;\n\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        return JS_EXCEPTION;\n\n    if (JS_ToInt32Clamp(ctx, &to, argv[0], 0, len, len))\n        return JS_EXCEPTION;\n\n    if (JS_ToInt32Clamp(ctx, &from, argv[1], 0, len, len))\n        return JS_EXCEPTION;\n\n    final = len;\n    if (argc > 2 && !JS_IsUndefined(argv[2])) {\n        if (JS_ToInt32Clamp(ctx, &final, argv[2], 0, len, len))\n            return JS_EXCEPTION;\n    }\n\n    count = min_int(final - from, len - to);\n    if (count > 0) {\n        p = JS_VALUE_GET_OBJ(this_val);\n        if (typed_array_is_detached(ctx, p))\n            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        shift = typed_array_size_log2(p->class_id);\n        memmove(p->u.array.u.uint8_ptr + (to << shift),\n                p->u.array.u.uint8_ptr + (from << shift),\n                count << shift);\n    }\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    int len, k, final, shift;\n    uint64_t v64;\n\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        return JS_EXCEPTION;\n    p = JS_VALUE_GET_OBJ(this_val);\n\n    if (p->class_id == JS_CLASS_UINT8C_ARRAY) {\n        int32_t v;\n        if (JS_ToUint8ClampFree(ctx, &v, JS_DupValue(ctx, argv[0])))\n            return JS_EXCEPTION;\n        v64 = v;\n    } else if (p->class_id <= JS_CLASS_UINT32_ARRAY) {\n        uint32_t v;\n        if (JS_ToUint32(ctx, &v, argv[0]))\n            return JS_EXCEPTION;\n        v64 = v;\n    } else\n#ifdef CONFIG_BIGNUM\n    if (p->class_id <= JS_CLASS_BIG_UINT64_ARRAY) {\n        if (JS_ToBigInt64(ctx, (int64_t *)&v64, argv[0]))\n            return JS_EXCEPTION;\n    } else\n#endif\n    {\n        double d;\n        if (JS_ToFloat64(ctx, &d, argv[0]))\n            return JS_EXCEPTION;\n        if (p->class_id == JS_CLASS_FLOAT32_ARRAY) {\n            union {\n                float f;\n                uint32_t u32;\n            } u;\n            u.f = d;\n            v64 = u.u32;\n        } else {\n            JSFloat64Union u;\n            u.d = d;\n            v64 = u.u64;\n        }\n    }\n\n    k = 0;\n    if (argc > 1) {\n        if (JS_ToInt32Clamp(ctx, &k, argv[1], 0, len, len))\n            return JS_EXCEPTION;\n    }\n\n    final = len;\n    if (argc > 2 && !JS_IsUndefined(argv[2])) {\n        if (JS_ToInt32Clamp(ctx, &final, argv[2], 0, len, len))\n            return JS_EXCEPTION;\n    }\n\n    if (typed_array_is_detached(ctx, p))\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    \n    shift = typed_array_size_log2(p->class_id);\n    switch(shift) {\n    case 0:\n        if (k < final) {\n            memset(p->u.array.u.uint8_ptr + k, v64, final - k);\n        }\n        break;\n    case 1:\n        for(; k < final; k++) {\n            p->u.array.u.uint16_ptr[k] = v64;\n        }\n        break;\n    case 2:\n        for(; k < final; k++) {\n            p->u.array.u.uint32_ptr[k] = v64;\n        }\n        break;\n    case 3:\n        for(; k < final; k++) {\n            p->u.array.u.uint64_ptr[k] = v64;\n        }\n        break;\n    default:\n        abort();\n    }\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv, int findIndex)\n{\n    JSValueConst func, this_arg;\n    JSValueConst args[3];\n    JSValue val, index_val, res;\n    int len, k;\n\n    val = JS_UNDEFINED;\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        goto exception;\n\n    func = argv[0];\n    if (check_function(ctx, func))\n        goto exception;\n\n    this_arg = JS_UNDEFINED;\n    if (argc > 1)\n        this_arg = argv[1];\n\n    for(k = 0; k < len; k++) {\n        index_val = JS_NewInt32(ctx, k);\n        val = JS_GetPropertyValue(ctx, this_val, index_val);\n        if (JS_IsException(val))\n            goto exception;\n        args[0] = val;\n        args[1] = index_val;\n        args[2] = this_val;\n        res = JS_Call(ctx, func, this_arg, 3, args);\n        if (JS_IsException(res))\n            goto exception;\n        if (JS_ToBoolFree(ctx, res)) {\n            if (findIndex) {\n                JS_FreeValue(ctx, val);\n                return index_val;\n            } else {\n                return val;\n            }\n        }\n        JS_FreeValue(ctx, val);\n    }\n    if (findIndex)\n        return JS_NewInt32(ctx, -1);\n    else\n        return JS_UNDEFINED;\n\nexception:\n    JS_FreeValue(ctx, val);\n    return JS_EXCEPTION;\n}\n\n#define special_indexOf 0\n#define special_lastIndexOf 1\n#define special_includes -1\n\nstatic JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv, int special)\n{\n    JSObject *p;\n    int len, tag, is_int, is_bigint, k, stop, inc, res = -1;\n    int64_t v64;\n    double d;\n    float f;\n\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        goto exception;\n    if (len == 0)\n        goto done;\n\n    if (special == special_lastIndexOf) {\n        k = len - 1;\n        if (argc > 1) {\n            if (JS_ToFloat64(ctx, &d, argv[1]))\n                goto exception;\n            if (isnan(d)) {\n                k = 0;\n            } else {\n                if (d >= 0) {\n                    if (d < k) {\n                        k = d;\n                    }\n                } else {\n                    d += len;\n                    if (d < 0)\n                        goto done;\n                    k = d;\n                }\n            }\n        }\n        stop = -1;\n        inc = -1;\n    } else {\n        k = 0;\n        if (argc > 1) {\n            if (JS_ToInt32Clamp(ctx, &k, argv[1], 0, len, len))\n                goto exception;\n        }\n        stop = len;\n        inc = 1;\n    }\n\n    if (validate_typed_array(ctx, this_val))\n        goto exception;\n    p = JS_VALUE_GET_OBJ(this_val);\n\n    is_bigint = 0;\n    is_int = 0; /* avoid warning */\n    v64 = 0; /* avoid warning */\n    tag = JS_VALUE_GET_NORM_TAG(argv[0]);\n    if (tag == JS_TAG_INT) {\n        is_int = 1;\n        v64 = JS_VALUE_GET_INT(argv[0]);\n        d = v64;\n    } else\n    if (tag == JS_TAG_FLOAT64) {\n        d = JS_VALUE_GET_FLOAT64(argv[0]);\n        v64 = d;\n        is_int = (v64 == d);\n    } else\n#ifdef CONFIG_BIGNUM\n    if (tag == JS_TAG_BIG_INT) {\n        JSBigFloat *p1 = JS_VALUE_GET_PTR(argv[0]);\n        \n        if (p->class_id == JS_CLASS_BIG_INT64_ARRAY) {\n            if (bf_get_int64(&v64, &p1->num, 0) != 0)\n                goto done;\n        } else if (p->class_id == JS_CLASS_BIG_UINT64_ARRAY) {\n            if (bf_get_uint64((uint64_t *)&v64, &p1->num) != 0)\n                goto done;\n        } else {\n            goto done;\n        }\n        d = 0;\n        is_bigint = 1;\n    } else\n#endif\n    {\n        goto done;\n    }\n\n    p = JS_VALUE_GET_OBJ(this_val);\n    switch (p->class_id) {\n    case JS_CLASS_INT8_ARRAY:\n        if (is_int && (int8_t)v64 == v64)\n            goto scan8;\n        break;\n    case JS_CLASS_UINT8C_ARRAY:\n    case JS_CLASS_UINT8_ARRAY:\n        if (is_int && (uint8_t)v64 == v64) {\n            const uint8_t *pv, *pp;\n            uint16_t v;\n        scan8:\n            pv = p->u.array.u.uint8_ptr;\n            v = v64;\n            if (inc > 0) {\n                pp = memchr(pv + k, v, len - k);\n                if (pp)\n                    res = pp - pv;\n            } else {\n                for (; k != stop; k += inc) {\n                    if (pv[k] == v) {\n                        res = k;\n                        break;\n                    }\n                }\n            }\n        }\n        break;\n    case JS_CLASS_INT16_ARRAY:\n        if (is_int && (int16_t)v64 == v64)\n            goto scan16;\n        break;\n    case JS_CLASS_UINT16_ARRAY:\n        if (is_int && (uint16_t)v64 == v64) {\n            const uint16_t *pv;\n            uint16_t v;\n        scan16:\n            pv = p->u.array.u.uint16_ptr;\n            v = v64;\n            for (; k != stop; k += inc) {\n                if (pv[k] == v) {\n                    res = k;\n                    break;\n                }\n            }\n        }\n        break;\n    case JS_CLASS_INT32_ARRAY:\n        if (is_int && (int32_t)v64 == v64)\n            goto scan32;\n        break;\n    case JS_CLASS_UINT32_ARRAY:\n        if (is_int && (uint32_t)v64 == v64) {\n            const uint32_t *pv;\n            uint32_t v;\n        scan32:\n            pv = p->u.array.u.uint32_ptr;\n            v = v64;\n            for (; k != stop; k += inc) {\n                if (pv[k] == v) {\n                    res = k;\n                    break;\n                }\n            }\n        }\n        break;\n    case JS_CLASS_FLOAT32_ARRAY:\n        if (is_bigint)\n            break;\n        if (isnan(d)) {\n            const float *pv = p->u.array.u.float_ptr;\n            /* special case: indexOf returns -1, includes finds NaN */\n            if (special != special_includes)\n                goto done;\n            for (; k != stop; k += inc) {\n                if (isnan(pv[k])) {\n                    res = k;\n                    break;\n                }\n            }\n        } else if ((f = (float)d) == d) {\n            const float *pv = p->u.array.u.float_ptr;\n            for (; k != stop; k += inc) {\n                if (pv[k] == f) {\n                    res = k;\n                    break;\n                }\n            }\n        }\n        break;\n    case JS_CLASS_FLOAT64_ARRAY:\n        if (is_bigint)\n            break;\n        if (isnan(d)) {\n            const double *pv = p->u.array.u.double_ptr;\n            /* special case: indexOf returns -1, includes finds NaN */\n            if (special != special_includes)\n                goto done;\n            for (; k != stop; k += inc) {\n                if (isnan(pv[k])) {\n                    res = k;\n                    break;\n                }\n            }\n        } else {\n            const double *pv = p->u.array.u.double_ptr;\n            for (; k != stop; k += inc) {\n                if (pv[k] == d) {\n                    res = k;\n                    break;\n                }\n            }\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_CLASS_BIG_INT64_ARRAY:\n        if (is_bigint || (is_math_mode(ctx) && is_int &&\n                          v64 >= -MAX_SAFE_INTEGER &&\n                          v64 <= MAX_SAFE_INTEGER)) {\n            goto scan64;\n        }\n        break;\n    case JS_CLASS_BIG_UINT64_ARRAY:\n        if (is_bigint || (is_math_mode(ctx) && is_int &&\n                          v64 >= 0 && v64 <= MAX_SAFE_INTEGER)) {\n            const uint64_t *pv;\n            uint64_t v;\n        scan64:\n            pv = p->u.array.u.uint64_ptr;\n            v = v64;\n            for (; k != stop; k += inc) {\n                if (pv[k] == v) {\n                    res = k;\n                    break;\n                }\n            }\n        }\n        break;\n#endif\n    }\n\ndone:\n    if (special == special_includes)\n        return JS_NewBool(ctx, res >= 0);\n    else\n        return JS_NewInt32(ctx, res);\n\nexception:\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_join(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv, int toLocaleString)\n{\n    JSValue sep = JS_UNDEFINED, el;\n    StringBuffer b_s, *b = &b_s;\n    JSString *p = NULL;\n    int i, n;\n    int c;\n\n    n = js_typed_array_get_length_internal(ctx, this_val);\n    if (n < 0)\n        goto exception;\n\n    c = ',';    /* default separator */\n    if (!toLocaleString && argc > 0 && !JS_IsUndefined(argv[0])) {\n        sep = JS_ToString(ctx, argv[0]);\n        if (JS_IsException(sep))\n            goto exception;\n        p = JS_VALUE_GET_STRING(sep);\n        if (p->len == 1 && !p->is_wide_char)\n            c = p->u.str8[0];\n        else\n            c = -1;\n    }\n    string_buffer_init(ctx, b, 0);\n\n    /* XXX: optimize with direct access */\n    for(i = 0; i < n; i++) {\n        if (i > 0) {\n            if (c >= 0) {\n                if (string_buffer_putc8(b, c))\n                    goto fail;\n            } else {\n                if (string_buffer_concat(b, p, 0, p->len))\n                    goto fail;\n            }\n        }\n        el = JS_GetPropertyUint32(ctx, this_val, i);\n        if (JS_IsException(el))\n            goto fail;\n        if (toLocaleString) {\n            el = JS_ToLocaleStringFree(ctx, el);\n        }\n        if (string_buffer_concat_value_free(b, el))\n            goto fail;\n    }\n    JS_FreeValue(ctx, sep);\n    return string_buffer_end(b);\n\nfail:\n    string_buffer_free(b);\n    JS_FreeValue(ctx, sep);\nexception:\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_reverse(JSContext *ctx, JSValueConst this_val,\n                                      int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    int len;\n\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        return JS_EXCEPTION;\n    if (len > 0) {\n        p = JS_VALUE_GET_OBJ(this_val);\n        switch (typed_array_size_log2(p->class_id)) {\n        case 0:\n            {\n                uint8_t *p1 = p->u.array.u.uint8_ptr;\n                uint8_t *p2 = p1 + len - 1;\n                while (p1 < p2) {\n                    uint8_t v = *p1;\n                    *p1++ = *p2;\n                    *p2-- = v;\n                }\n            }\n            break;\n        case 1:\n            {\n                uint16_t *p1 = p->u.array.u.uint16_ptr;\n                uint16_t *p2 = p1 + len - 1;\n                while (p1 < p2) {\n                    uint16_t v = *p1;\n                    *p1++ = *p2;\n                    *p2-- = v;\n                }\n            }\n            break;\n        case 2:\n            {\n                uint32_t *p1 = p->u.array.u.uint32_ptr;\n                uint32_t *p2 = p1 + len - 1;\n                while (p1 < p2) {\n                    uint32_t v = *p1;\n                    *p1++ = *p2;\n                    *p2-- = v;\n                }\n            }\n            break;\n        case 3:\n            {\n                uint64_t *p1 = p->u.array.u.uint64_ptr;\n                uint64_t *p2 = p1 + len - 1;\n                while (p1 < p2) {\n                    uint64_t v = *p1;\n                    *p1++ = *p2;\n                    *p2-- = v;\n                }\n            }\n            break;\n        default:\n            abort();\n        }\n    }\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic JSValue js_typed_array_slice(JSContext *ctx, JSValueConst this_val,\n                                    int argc, JSValueConst *argv)\n{\n    JSValueConst args[2];\n    JSValue arr, val;\n    JSObject *p, *p1;\n    int n, len, start, final, count, shift;\n\n    arr = JS_UNDEFINED;\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        goto exception;\n\n    if (JS_ToInt32Clamp(ctx, &start, argv[0], 0, len, len))\n        goto exception;\n    final = len;\n    if (!JS_IsUndefined(argv[1])) {\n        if (JS_ToInt32Clamp(ctx, &final, argv[1], 0, len, len))\n            goto exception;\n    }\n    count = max_int(final - start, 0);\n\n    p = get_typed_array(ctx, this_val, 0);\n    if (p == NULL)\n        goto exception;\n    shift = typed_array_size_log2(p->class_id);\n\n    args[0] = this_val;\n    args[1] = JS_NewInt32(ctx, count);\n    arr = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 2, args);\n    if (JS_IsException(arr))\n        goto exception;\n\n    if (count > 0) {\n        if (validate_typed_array(ctx, this_val)\n        ||  validate_typed_array(ctx, arr))\n            goto exception;\n\n        p1 = get_typed_array(ctx, arr, 0);\n        if (p1 != NULL && p->class_id == p1->class_id &&\n            typed_array_get_length(ctx, p1) >= count &&\n            typed_array_get_length(ctx, p) >= start + count) {\n            memcpy(p1->u.array.u.uint8_ptr,\n                   p->u.array.u.uint8_ptr + (start << shift),\n                   count << shift);\n        } else {\n            for (n = 0; n < count; n++) {\n                val = JS_GetPropertyValue(ctx, this_val, JS_NewInt32(ctx, start + n));\n                if (JS_IsException(val))\n                    goto exception;\n                if (JS_SetPropertyValue(ctx, arr, JS_NewInt32(ctx, n), val,\n                                        JS_PROP_THROW) < 0)\n                    goto exception;\n            }\n        }\n    }\n    return arr;\n\n exception:\n    JS_FreeValue(ctx, arr);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val,\n                                       int argc, JSValueConst *argv)\n{\n    JSValueConst args[4];\n    JSValue arr, byteOffset, ta_buffer;\n    JSObject *p;\n    int len, start, final, count, shift, offset;\n\n    p = get_typed_array(ctx, this_val, 0);\n    if (!p)\n        goto exception;\n    len = p->u.array.count;\n    if (JS_ToInt32Clamp(ctx, &start, argv[0], 0, len, len))\n        goto exception;\n\n    final = len;\n    if (!JS_IsUndefined(argv[1])) {\n        if (JS_ToInt32Clamp(ctx, &final, argv[1], 0, len, len))\n            goto exception;\n    }\n    count = max_int(final - start, 0);\n    byteOffset = js_typed_array_get_byteOffset(ctx, this_val, 0);\n    if (JS_IsException(byteOffset))\n        goto exception;\n    shift = typed_array_size_log2(p->class_id);\n    offset = JS_VALUE_GET_INT(byteOffset) + (start << shift);\n    JS_FreeValue(ctx, byteOffset);\n    ta_buffer = js_typed_array_get_buffer(ctx, this_val, 0);\n    if (JS_IsException(ta_buffer))\n        goto exception;\n    args[0] = this_val;\n    args[1] = ta_buffer;\n    args[2] = JS_NewInt32(ctx, offset);\n    args[3] = JS_NewInt32(ctx, count);\n    arr = js_typed_array___speciesCreate(ctx, JS_UNDEFINED, 4, args);\n    JS_FreeValue(ctx, ta_buffer);\n    return arr;\n\n exception:\n    return JS_EXCEPTION;\n}\n\n/* TypedArray.prototype.sort */\n\nstatic int js_cmp_doubles(double x, double y)\n{\n    if (isnan(x))    return isnan(y) ? 0 : +1;\n    if (isnan(y))    return -1;\n    if (x < y)       return -1;\n    if (x > y)       return 1;\n    if (x != 0)      return 0;\n    if (signbit(x))  return signbit(y) ? 0 : -1;\n    else             return signbit(y) ? 1 : 0;\n}\n\nstatic int js_TA_cmp_int8(const void *a, const void *b, void *opaque) {\n    return *(const int8_t *)a - *(const int8_t *)b;\n}\n\nstatic int js_TA_cmp_uint8(const void *a, const void *b, void *opaque) {\n    return *(const uint8_t *)a - *(const uint8_t *)b;\n}\n\nstatic int js_TA_cmp_int16(const void *a, const void *b, void *opaque) {\n    return *(const int16_t *)a - *(const int16_t *)b;\n}\n\nstatic int js_TA_cmp_uint16(const void *a, const void *b, void *opaque) {\n    return *(const uint16_t *)a - *(const uint16_t *)b;\n}\n\nstatic int js_TA_cmp_int32(const void *a, const void *b, void *opaque) {\n    int32_t x = *(const int32_t *)a;\n    int32_t y = *(const int32_t *)b;\n    return (y < x) - (y > x);\n}\n\nstatic int js_TA_cmp_uint32(const void *a, const void *b, void *opaque) {\n    uint32_t x = *(const uint32_t *)a;\n    uint32_t y = *(const uint32_t *)b;\n    return (y < x) - (y > x);\n}\n\n#ifdef CONFIG_BIGNUM\nstatic int js_TA_cmp_int64(const void *a, const void *b, void *opaque) {\n    int64_t x = *(const int64_t *)a;\n    int64_t y = *(const int64_t *)b;\n    return (y < x) - (y > x);\n}\n\nstatic int js_TA_cmp_uint64(const void *a, const void *b, void *opaque) {\n    uint64_t x = *(const uint64_t *)a;\n    uint64_t y = *(const uint64_t *)b;\n    return (y < x) - (y > x);\n}\n#endif\n\nstatic int js_TA_cmp_float32(const void *a, const void *b, void *opaque) {\n    return js_cmp_doubles(*(const float *)a, *(const float *)b);\n}\n\nstatic int js_TA_cmp_float64(const void *a, const void *b, void *opaque) {\n    return js_cmp_doubles(*(const double *)a, *(const double *)b);\n}\n\nstatic JSValue js_TA_get_int8(JSContext *ctx, const void *a) {\n    return JS_NewInt32(ctx, *(const int8_t *)a);\n}\n\nstatic JSValue js_TA_get_uint8(JSContext *ctx, const void *a) {\n    return JS_NewInt32(ctx, *(const uint8_t *)a);\n}\n\nstatic JSValue js_TA_get_int16(JSContext *ctx, const void *a) {\n    return JS_NewInt32(ctx, *(const int16_t *)a);\n}\n\nstatic JSValue js_TA_get_uint16(JSContext *ctx, const void *a) {\n    return JS_NewInt32(ctx, *(const uint16_t *)a);\n}\n\nstatic JSValue js_TA_get_int32(JSContext *ctx, const void *a) {\n    return JS_NewInt32(ctx, *(const int32_t *)a);\n}\n\nstatic JSValue js_TA_get_uint32(JSContext *ctx, const void *a) {\n    return JS_NewUint32(ctx, *(const uint32_t *)a);\n}\n\n#ifdef CONFIG_BIGNUM\nstatic JSValue js_TA_get_int64(JSContext *ctx, const void *a) {\n    return JS_NewBigInt64(ctx, *(int64_t *)a);\n}\n\nstatic JSValue js_TA_get_uint64(JSContext *ctx, const void *a) {\n    return JS_NewBigUint64(ctx, *(uint64_t *)a);\n}\n#endif\n\nstatic JSValue js_TA_get_float32(JSContext *ctx, const void *a) {\n    return __JS_NewFloat64(ctx, *(const float *)a);\n}\n\nstatic JSValue js_TA_get_float64(JSContext *ctx, const void *a) {\n    return __JS_NewFloat64(ctx, *(const double *)a);\n}\n\nstruct TA_sort_context {\n    JSContext *ctx;\n    int exception;\n    JSValueConst arr;\n    JSValueConst cmp;\n    JSValue (*getfun)(JSContext *ctx, const void *a);\n    uint8_t *array_ptr; /* cannot change unless the array is detached */\n    int elt_size;\n};\n\nstatic int js_TA_cmp_generic(const void *a, const void *b, void *opaque) {\n    struct TA_sort_context *psc = opaque;\n    JSContext *ctx = psc->ctx;\n    uint32_t a_idx, b_idx;\n    JSValueConst argv[2];\n    JSValue res;\n    int cmp;\n\n    cmp = 0;\n    if (!psc->exception) {\n        a_idx = *(uint32_t *)a;\n        b_idx = *(uint32_t *)b;\n        argv[0] = psc->getfun(ctx, psc->array_ptr +\n                              a_idx * (size_t)psc->elt_size);\n        argv[1] = psc->getfun(ctx, psc->array_ptr +\n                              b_idx * (size_t)(psc->elt_size));\n        res = JS_Call(ctx, psc->cmp, JS_UNDEFINED, 2, argv);\n        if (JS_IsException(res)) {\n            psc->exception = 1;\n            goto done;\n        }\n        if (JS_VALUE_GET_TAG(res) == JS_TAG_INT) {\n            int val = JS_VALUE_GET_INT(res);\n            cmp = (val > 0) - (val < 0);\n        } else {\n            double val;\n            if (JS_ToFloat64Free(ctx, &val, res) < 0) {\n                psc->exception = 1;\n                goto done;\n            } else {\n                cmp = (val > 0) - (val < 0);\n            }\n        }\n        if (cmp == 0) {\n            /* make sort stable: compare array offsets */\n            cmp = (a_idx > b_idx) - (a_idx < b_idx);\n        }\n        if (validate_typed_array(ctx, psc->arr) < 0) {\n            psc->exception = 1;\n        }\n    done:\n        JS_FreeValue(ctx, (JSValue)argv[0]);\n        JS_FreeValue(ctx, (JSValue)argv[1]);\n    }\n    return cmp;\n}\n\nstatic JSValue js_typed_array_sort(JSContext *ctx, JSValueConst this_val,\n                                   int argc, JSValueConst *argv)\n{\n    JSObject *p;\n    int len;\n    size_t elt_size;\n    struct TA_sort_context tsc;\n    void *array_ptr;\n    int (*cmpfun)(const void *a, const void *b, void *opaque);\n\n    tsc.ctx = ctx;\n    tsc.exception = 0;\n    tsc.arr = this_val;\n    tsc.cmp = argv[0];\n\n    len = js_typed_array_get_length_internal(ctx, this_val);\n    if (len < 0)\n        return JS_EXCEPTION;\n    if (!JS_IsUndefined(tsc.cmp) && check_function(ctx, tsc.cmp))\n        return JS_EXCEPTION;\n\n    if (len > 1) {\n        p = JS_VALUE_GET_OBJ(this_val);\n        switch (p->class_id) {\n        case JS_CLASS_INT8_ARRAY:\n            tsc.getfun = js_TA_get_int8;\n            cmpfun = js_TA_cmp_int8;\n            break;\n        case JS_CLASS_UINT8C_ARRAY:\n        case JS_CLASS_UINT8_ARRAY:\n            tsc.getfun = js_TA_get_uint8;\n            cmpfun = js_TA_cmp_uint8;\n            break;\n        case JS_CLASS_INT16_ARRAY:\n            tsc.getfun = js_TA_get_int16;\n            cmpfun = js_TA_cmp_int16;\n            break;\n        case JS_CLASS_UINT16_ARRAY:\n            tsc.getfun = js_TA_get_uint16;\n            cmpfun = js_TA_cmp_uint16;\n            break;\n        case JS_CLASS_INT32_ARRAY:\n            tsc.getfun = js_TA_get_int32;\n            cmpfun = js_TA_cmp_int32;\n            break;\n        case JS_CLASS_UINT32_ARRAY:\n            tsc.getfun = js_TA_get_uint32;\n            cmpfun = js_TA_cmp_uint32;\n            break;\n#ifdef CONFIG_BIGNUM\n        case JS_CLASS_BIG_INT64_ARRAY:\n            tsc.getfun = js_TA_get_int64;\n            cmpfun = js_TA_cmp_int64;\n            break;\n        case JS_CLASS_BIG_UINT64_ARRAY:\n            tsc.getfun = js_TA_get_uint64;\n            cmpfun = js_TA_cmp_uint64;\n            break;\n#endif\n        case JS_CLASS_FLOAT32_ARRAY:\n            tsc.getfun = js_TA_get_float32;\n            cmpfun = js_TA_cmp_float32;\n            break;\n        case JS_CLASS_FLOAT64_ARRAY:\n            tsc.getfun = js_TA_get_float64;\n            cmpfun = js_TA_cmp_float64;\n            break;\n        default:\n            abort();\n        }\n        array_ptr = p->u.array.u.ptr;\n        elt_size = 1 << typed_array_size_log2(p->class_id);\n        if (!JS_IsUndefined(tsc.cmp)) {\n            uint32_t *array_idx;\n            void *array_tmp;\n            size_t i, j;\n            \n            /* XXX: a stable sort would use less memory */\n            array_idx = js_malloc(ctx, len * sizeof(array_idx[0]));\n            if (!array_idx)\n                return JS_EXCEPTION;\n            for(i = 0; i < len; i++)\n                array_idx[i] = i;\n            tsc.array_ptr = array_ptr;\n            tsc.elt_size = elt_size;\n            rqsort(array_idx, len, sizeof(array_idx[0]),\n                   js_TA_cmp_generic, &tsc);\n            if (tsc.exception)\n                goto fail;\n            array_tmp = js_malloc(ctx, len * elt_size);\n            if (!array_tmp) {\n            fail:\n                js_free(ctx, array_idx);\n                return JS_EXCEPTION;\n            }\n            memcpy(array_tmp, array_ptr, len * elt_size);\n            switch(elt_size) {\n            case 1:\n                for(i = 0; i < len; i++) {\n                    j = array_idx[i];\n                    ((uint8_t *)array_ptr)[i] = ((uint8_t *)array_tmp)[j];\n                }\n                break;\n            case 2:\n                for(i = 0; i < len; i++) {\n                    j = array_idx[i];\n                    ((uint16_t *)array_ptr)[i] = ((uint16_t *)array_tmp)[j];\n                }\n                break;\n            case 4:\n                for(i = 0; i < len; i++) {\n                    j = array_idx[i];\n                    ((uint32_t *)array_ptr)[i] = ((uint32_t *)array_tmp)[j];\n                }\n                break;\n            case 8:\n                for(i = 0; i < len; i++) {\n                    j = array_idx[i];\n                    ((uint64_t *)array_ptr)[i] = ((uint64_t *)array_tmp)[j];\n                }\n                break;\n            default:\n                abort();\n            }\n            js_free(ctx, array_tmp);\n            js_free(ctx, array_idx);\n        } else {\n            rqsort(array_ptr, len, elt_size, cmpfun, &tsc);\n            if (tsc.exception)\n                return JS_EXCEPTION;\n        }\n    }\n    return JS_DupValue(ctx, this_val);\n}\n\nstatic const JSCFunctionListEntry js_typed_array_base_funcs[] = {\n    JS_CFUNC_DEF(\"from\", 1, js_typed_array_from ),\n    JS_CFUNC_DEF(\"of\", 0, js_typed_array_of ),\n    JS_CGETSET_DEF(\"[Symbol.species]\", js_get_this, NULL ),\n    //JS_CFUNC_DEF(\"__getLength\", 2, js_typed_array___getLength ),\n    //JS_CFUNC_DEF(\"__create\", 2, js_typed_array___create ),\n    //JS_CFUNC_DEF(\"__speciesCreate\", 2, js_typed_array___speciesCreate ),\n};\n\nstatic const JSCFunctionListEntry js_typed_array_base_proto_funcs[] = {\n    JS_CGETSET_DEF(\"length\", js_typed_array_get_length, NULL ),\n    JS_CGETSET_MAGIC_DEF(\"buffer\", js_typed_array_get_buffer, NULL, 0 ),\n    JS_CGETSET_MAGIC_DEF(\"byteLength\", js_typed_array_get_byteLength, NULL, 0 ),\n    JS_CGETSET_MAGIC_DEF(\"byteOffset\", js_typed_array_get_byteOffset, NULL, 0 ),\n    JS_CFUNC_DEF(\"set\", 1, js_typed_array_set ),\n    JS_CFUNC_MAGIC_DEF(\"values\", 0, js_create_typed_array_iterator, JS_ITERATOR_KIND_VALUE ),\n    JS_ALIAS_DEF(\"[Symbol.iterator]\", \"values\" ),\n    JS_CFUNC_MAGIC_DEF(\"keys\", 0, js_create_typed_array_iterator, JS_ITERATOR_KIND_KEY ),\n    JS_CFUNC_MAGIC_DEF(\"entries\", 0, js_create_typed_array_iterator, JS_ITERATOR_KIND_KEY_AND_VALUE ),\n    JS_CGETSET_DEF(\"[Symbol.toStringTag]\", js_typed_array_get_toStringTag, NULL ),\n    JS_CFUNC_DEF(\"copyWithin\", 2, js_typed_array_copyWithin ),\n    JS_CFUNC_MAGIC_DEF(\"every\", 1, js_array_every, special_every | special_TA ),\n    JS_CFUNC_MAGIC_DEF(\"some\", 1, js_array_every, special_some | special_TA ),\n    JS_CFUNC_MAGIC_DEF(\"forEach\", 1, js_array_every, special_forEach | special_TA ),\n    JS_CFUNC_MAGIC_DEF(\"map\", 1, js_array_every, special_map | special_TA ),\n    JS_CFUNC_MAGIC_DEF(\"filter\", 1, js_array_every, special_filter | special_TA ),\n    JS_CFUNC_MAGIC_DEF(\"reduce\", 1, js_array_reduce, special_reduce | special_TA ),\n    JS_CFUNC_MAGIC_DEF(\"reduceRight\", 1, js_array_reduce, special_reduceRight | special_TA ),\n    JS_CFUNC_DEF(\"fill\", 1, js_typed_array_fill ),\n    JS_CFUNC_MAGIC_DEF(\"find\", 1, js_typed_array_find, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"findIndex\", 1, js_typed_array_find, 1 ),\n    JS_CFUNC_DEF(\"reverse\", 0, js_typed_array_reverse ),\n    JS_CFUNC_DEF(\"slice\", 2, js_typed_array_slice ),\n    JS_CFUNC_DEF(\"subarray\", 2, js_typed_array_subarray ),\n    JS_CFUNC_DEF(\"sort\", 1, js_typed_array_sort ),\n    JS_CFUNC_MAGIC_DEF(\"join\", 1, js_typed_array_join, 0 ),\n    JS_CFUNC_MAGIC_DEF(\"toLocaleString\", 0, js_typed_array_join, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"indexOf\", 1, js_typed_array_indexOf, special_indexOf ),\n    JS_CFUNC_MAGIC_DEF(\"lastIndexOf\", 1, js_typed_array_indexOf, special_lastIndexOf ),\n    JS_CFUNC_MAGIC_DEF(\"includes\", 1, js_typed_array_indexOf, special_includes ),\n    //JS_ALIAS_BASE_DEF(\"toString\", \"toString\", 2 /* Array.prototype. */), @@@\n};\n\nstatic JSValue js_typed_array_base_constructor(JSContext *ctx,\n                                               JSValueConst this_val,\n                                               int argc, JSValueConst *argv)\n{\n    return JS_ThrowTypeError(ctx, \"cannot be called\");\n}\n\n/* 'obj' must be an allocated typed array object */\nstatic int typed_array_init(JSContext *ctx, JSValueConst obj,\n                            JSValue buffer, uint64_t offset, uint64_t len)\n{\n    JSTypedArray *ta;\n    JSObject *p, *pbuffer;\n    JSArrayBuffer *abuf;\n    int size_log2;\n\n    p = JS_VALUE_GET_OBJ(obj);\n    size_log2 = typed_array_size_log2(p->class_id);\n    ta = js_malloc(ctx, sizeof(*ta));\n    if (!ta) {\n        JS_FreeValue(ctx, buffer);\n        return -1;\n    }\n    pbuffer = JS_VALUE_GET_OBJ(buffer);\n    abuf = pbuffer->u.array_buffer;\n    ta->obj = p;\n    ta->buffer = pbuffer;\n    ta->offset = offset;\n    ta->length = len << size_log2;\n    list_add_tail(&ta->link, &abuf->array_list);\n    p->u.typed_array = ta;\n    p->u.array.count = len;\n    p->u.array.u.ptr = abuf->data + offset;\n    return 0;\n}\n\n\nstatic JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,\n                                      JSValueConst obj, JSValueConst method)\n{\n    JSValue arr, iter, next_method = JS_UNDEFINED, val;\n    BOOL done;\n    uint32_t k;\n\n    *plen = 0;\n    arr = JS_NewArray(ctx);\n    if (JS_IsException(arr))\n        return arr;\n    iter = JS_GetIterator2(ctx, obj, method);\n    if (JS_IsException(iter))\n        goto fail;\n    next_method = JS_GetProperty(ctx, iter, JS_ATOM_next);\n    if (JS_IsException(next_method))\n        goto fail;\n    k = 0;\n    for(;;) {\n        val = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);\n        if (JS_IsException(val))\n            goto fail;\n        if (done) {\n            JS_FreeValue(ctx, val);\n            break;\n        }\n        if (JS_CreateDataPropertyUint32(ctx, arr, k, val, JS_PROP_THROW) < 0)\n            goto fail;\n        k++;\n    }\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    *plen = k;\n    return arr;\n fail:\n    JS_FreeValue(ctx, next_method);\n    JS_FreeValue(ctx, iter);\n    JS_FreeValue(ctx, arr);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_constructor_obj(JSContext *ctx,\n                                              JSValueConst new_target,\n                                              JSValueConst obj,\n                                              int classid)\n{\n    JSValue iter, ret, arr = JS_UNDEFINED, val, buffer;\n    uint32_t i;\n    int size_log2;\n    int64_t len;\n\n    size_log2 = typed_array_size_log2(classid);\n    ret = js_create_from_ctor(ctx, new_target, classid);\n    if (JS_IsException(ret))\n        return JS_EXCEPTION;\n\n    iter = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_iterator);\n    if (JS_IsException(iter))\n        goto fail;\n    if (!JS_IsUndefined(iter) && !JS_IsNull(iter)) {\n        uint32_t len1;\n        arr = js_array_from_iterator(ctx, &len1, obj, iter);\n        JS_FreeValue(ctx, iter);\n        if (JS_IsException(arr))\n            goto fail;\n        len = len1;\n    } else {\n        if (js_get_length64(ctx, &len, obj))\n            goto fail;\n        arr = JS_DupValue(ctx, obj);\n    }\n\n    buffer = js_array_buffer_constructor1(ctx, JS_UNDEFINED,\n                                          len << size_log2);\n    if (JS_IsException(buffer))\n        goto fail;\n    if (typed_array_init(ctx, ret, buffer, 0, len))\n        goto fail;\n\n    for(i = 0; i < len; i++) {\n        val = JS_GetPropertyUint32(ctx, arr, i);\n        if (JS_IsException(val))\n            goto fail;\n        if (JS_SetPropertyUint32(ctx, ret, i, val) < 0)\n            goto fail;\n    }\n    JS_FreeValue(ctx, arr);\n    return ret;\n fail:\n    JS_FreeValue(ctx, arr);\n    JS_FreeValue(ctx, ret);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_constructor_ta(JSContext *ctx,\n                                             JSValueConst new_target,\n                                             JSValueConst src_obj,\n                                             int classid)\n{\n    JSObject *p, *src_buffer;\n    JSTypedArray *ta;\n    JSValue ctor, obj, buffer;\n    uint32_t len, i;\n    int size_log2;\n    JSArrayBuffer *src_abuf, *abuf;\n\n    obj = js_create_from_ctor(ctx, new_target, classid);\n    if (JS_IsException(obj))\n        return obj;\n    p = JS_VALUE_GET_OBJ(src_obj);\n    if (typed_array_is_detached(ctx, p)) {\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    ta = p->u.typed_array;\n    len = p->u.array.count;\n    src_buffer = ta->buffer;\n    src_abuf = src_buffer->u.array_buffer;\n    if (!src_abuf->shared) {\n        ctor = JS_SpeciesConstructor(ctx, JS_MKPTR(JS_TAG_OBJECT, src_buffer),\n                                     JS_UNDEFINED);\n        if (JS_IsException(ctor))\n            goto fail;\n    } else {\n        /* force ArrayBuffer default constructor */\n        ctor = JS_UNDEFINED;\n    }\n    size_log2 = typed_array_size_log2(classid);\n    buffer = js_array_buffer_constructor1(ctx, ctor,\n                                          (uint64_t)len << size_log2);\n    JS_FreeValue(ctx, ctor);\n    if (JS_IsException(buffer))\n        goto fail;\n    /* necessary because it could have been detached */\n    if (typed_array_is_detached(ctx, p)) {\n        JS_FreeValue(ctx, buffer);\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    abuf = JS_GetOpaque(buffer, JS_CLASS_ARRAY_BUFFER);\n    if (typed_array_init(ctx, obj, buffer, 0, len))\n        goto fail;\n    if (p->class_id == classid) {\n        /* same type: copy the content */\n        memcpy(abuf->data, src_abuf->data + ta->offset, abuf->byte_length);\n    } else {\n        for(i = 0; i < len; i++) {\n            JSValue val;\n            val = JS_GetPropertyUint32(ctx, src_obj, i);\n            if (JS_IsException(val))\n                goto fail;\n            if (JS_SetPropertyUint32(ctx, obj, i, val) < 0)\n                goto fail;\n        }\n    }\n    return obj;\n fail:\n    JS_FreeValue(ctx, obj);\n    return JS_EXCEPTION;\n}\n\nstatic JSValue js_typed_array_constructor(JSContext *ctx,\n                                          JSValueConst new_target,\n                                          int argc, JSValueConst *argv,\n                                          int classid)\n{\n    JSValue buffer, obj;\n    JSArrayBuffer *abuf;\n    int size_log2;\n    uint64_t len, offset;\n\n    size_log2 = typed_array_size_log2(classid);\n    if (JS_VALUE_GET_TAG(argv[0]) != JS_TAG_OBJECT) {\n        if (JS_ToIndex(ctx, &len, argv[0]))\n            return JS_EXCEPTION;\n        buffer = js_array_buffer_constructor1(ctx, JS_UNDEFINED,\n                                              len << size_log2);\n        if (JS_IsException(buffer))\n            return JS_EXCEPTION;\n        offset = 0;\n    } else {\n        JSObject *p = JS_VALUE_GET_OBJ(argv[0]);\n        if (p->class_id == JS_CLASS_ARRAY_BUFFER ||\n            p->class_id == JS_CLASS_SHARED_ARRAY_BUFFER) {\n            abuf = p->u.array_buffer;\n            if (JS_ToIndex(ctx, &offset, argv[1]))\n                return JS_EXCEPTION;\n            if (abuf->detached)\n                return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n            if ((offset & ((1 << size_log2) - 1)) != 0 ||\n                offset > abuf->byte_length)\n                return JS_ThrowRangeError(ctx, \"invalid offset\");\n            if (JS_IsUndefined(argv[2])) {\n                if ((abuf->byte_length & ((1 << size_log2) - 1)) != 0)\n                    goto invalid_length;\n                len = (abuf->byte_length - offset) >> size_log2;\n            } else {\n                if (JS_ToIndex(ctx, &len, argv[2]))\n                    return JS_EXCEPTION;\n                if (abuf->detached)\n                    return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n                if ((offset + (len << size_log2)) > abuf->byte_length) {\n                invalid_length:\n                    return JS_ThrowRangeError(ctx, \"invalid length\");\n                }\n            }\n            buffer = JS_DupValue(ctx, argv[0]);\n        } else {\n            if (p->class_id >= JS_CLASS_UINT8C_ARRAY &&\n                p->class_id <= JS_CLASS_FLOAT64_ARRAY) {\n                return js_typed_array_constructor_ta(ctx, new_target, argv[0], classid);\n            } else {\n                return js_typed_array_constructor_obj(ctx, new_target, argv[0], classid);\n            }\n        }\n    }\n\n    obj = js_create_from_ctor(ctx, new_target, classid);\n    if (JS_IsException(obj)) {\n        JS_FreeValue(ctx, buffer);\n        return JS_EXCEPTION;\n    }\n    if (typed_array_init(ctx, obj, buffer, offset, len)) {\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    return obj;\n}\n\nstatic void js_typed_array_finalizer(JSRuntime *rt, JSValue val)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSTypedArray *ta = p->u.typed_array;\n    if (ta) {\n        /* during the GC the finalizers are called in an arbitrary\n           order so the ArrayBuffer finalizer may have been called */\n        if (JS_IsLiveObject(rt, JS_MKPTR(JS_TAG_OBJECT, ta->buffer))) {\n            list_del(&ta->link);\n        }\n        JS_FreeValueRT(rt, JS_MKPTR(JS_TAG_OBJECT, ta->buffer));\n        js_free_rt(rt, ta);\n    }\n}\n\nstatic void js_typed_array_mark(JSRuntime *rt, JSValueConst val,\n                                JS_MarkFunc *mark_func)\n{\n    JSObject *p = JS_VALUE_GET_OBJ(val);\n    JSTypedArray *ta = p->u.typed_array;\n    if (ta) {\n        JS_MarkValue(rt, JS_MKPTR(JS_TAG_OBJECT, ta->buffer), mark_func);\n    }\n}\n\nstatic JSValue js_dataview_constructor(JSContext *ctx,\n                                       JSValueConst new_target,\n                                       int argc, JSValueConst *argv)\n{\n    JSArrayBuffer *abuf;\n    uint64_t offset;\n    uint32_t len;\n    JSValueConst buffer;\n    JSValue obj;\n    JSTypedArray *ta;\n    JSObject *p;\n\n    buffer = argv[0];\n    abuf = js_get_array_buffer(ctx, buffer);\n    if (!abuf)\n        return JS_EXCEPTION;\n    offset = 0;\n    if (argc > 1) {\n        if (JS_ToIndex(ctx, &offset, argv[1]))\n            return JS_EXCEPTION;\n    }\n    if (abuf->detached)\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    if (offset > abuf->byte_length)\n        return JS_ThrowRangeError(ctx, \"invalid byteOffset\");\n    len = abuf->byte_length - offset;\n    if (argc > 2 && !JS_IsUndefined(argv[2])) {\n        uint64_t l;\n        if (JS_ToIndex(ctx, &l, argv[2]))\n            return JS_EXCEPTION;\n        if (l > len)\n            return JS_ThrowRangeError(ctx, \"invalid byteLength\");\n        len = l;\n    }\n\n    obj = js_create_from_ctor(ctx, new_target, JS_CLASS_DATAVIEW);\n    if (JS_IsException(obj))\n        return JS_EXCEPTION;\n    if (abuf->detached) {\n        /* could have been detached in js_create_from_ctor() */\n        JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        goto fail;\n    }\n    ta = js_malloc(ctx, sizeof(*ta));\n    if (!ta) {\n    fail:\n        JS_FreeValue(ctx, obj);\n        return JS_EXCEPTION;\n    }\n    p = JS_VALUE_GET_OBJ(obj);\n    ta->obj = p;\n    ta->buffer = JS_VALUE_GET_OBJ(JS_DupValue(ctx, buffer));\n    ta->offset = offset;\n    ta->length = len;\n    list_add_tail(&ta->link, &abuf->array_list);\n    p->u.typed_array = ta;\n    return obj;\n}\n\nstatic JSValue js_dataview_getValue(JSContext *ctx,\n                                    JSValueConst this_obj,\n                                    int argc, JSValueConst *argv, int class_id)\n{\n    JSTypedArray *ta;\n    JSArrayBuffer *abuf;\n    int is_swap, size;\n    uint8_t *ptr;\n    uint32_t v;\n    uint64_t pos;\n\n    ta = JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW);\n    if (!ta)\n        return JS_EXCEPTION;\n    size = 1 << typed_array_size_log2(class_id);\n    if (JS_ToIndex(ctx, &pos, argv[0]))\n        return JS_EXCEPTION;\n    is_swap = FALSE;\n    if (argc > 1)\n        is_swap = JS_ToBool(ctx, argv[1]);\n#ifndef WORDS_BIGENDIAN\n    is_swap ^= 1;\n#endif\n    abuf = ta->buffer->u.array_buffer;\n    if (abuf->detached)\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    if ((pos + size) > ta->length)\n        return JS_ThrowRangeError(ctx, \"out of bound\");\n    ptr = abuf->data + ta->offset + pos;\n\n    switch(class_id) {\n    case JS_CLASS_INT8_ARRAY:\n        return JS_NewInt32(ctx, *(int8_t *)ptr);\n    case JS_CLASS_UINT8_ARRAY:\n        return JS_NewInt32(ctx, *(uint8_t *)ptr);\n    case JS_CLASS_INT16_ARRAY:\n        v = get_u16(ptr);\n        if (is_swap)\n            v = bswap16(v);\n        return JS_NewInt32(ctx, (int16_t)v);\n    case JS_CLASS_UINT16_ARRAY:\n        v = get_u16(ptr);\n        if (is_swap)\n            v = bswap16(v);\n        return JS_NewInt32(ctx, v);\n    case JS_CLASS_INT32_ARRAY:\n        v = get_u32(ptr);\n        if (is_swap)\n            v = bswap32(v);\n        return JS_NewInt32(ctx, v);\n    case JS_CLASS_UINT32_ARRAY:\n        v = get_u32(ptr);\n        if (is_swap)\n            v = bswap32(v);\n        return JS_NewUint32(ctx, v);\n#ifdef CONFIG_BIGNUM\n    case JS_CLASS_BIG_INT64_ARRAY:\n        {\n            uint64_t v;\n            v = get_u64(ptr);\n            if (is_swap)\n                v = bswap64(v);\n            return JS_NewBigInt64(ctx, v);\n        }\n        break;\n    case JS_CLASS_BIG_UINT64_ARRAY:\n        {\n            uint64_t v;\n            v = get_u64(ptr);\n            if (is_swap)\n                v = bswap64(v);\n            return JS_NewBigUint64(ctx, v);\n        }\n        break;\n#endif\n    case JS_CLASS_FLOAT32_ARRAY:\n        {\n            union {\n                float f;\n                uint32_t i;\n            } u;\n            v = get_u32(ptr);\n            if (is_swap)\n                v = bswap32(v);\n            u.i = v;\n            return __JS_NewFloat64(ctx, u.f);\n        }\n    case JS_CLASS_FLOAT64_ARRAY:\n        {\n            union {\n                double f;\n                uint64_t i;\n            } u;\n            u.i = get_u64(ptr);\n            if (is_swap)\n                u.i = bswap64(u.i);\n            return __JS_NewFloat64(ctx, u.f);\n        }\n    default:\n        abort();\n    }\n}\n\nstatic JSValue js_dataview_setValue(JSContext *ctx,\n                                    JSValueConst this_obj,\n                                    int argc, JSValueConst *argv, int class_id)\n{\n    JSTypedArray *ta;\n    JSArrayBuffer *abuf;\n    int is_swap, size;\n    uint8_t *ptr;\n    uint64_t v64;\n    uint32_t v;\n    uint64_t pos;\n    JSValueConst val;\n\n    ta = JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW);\n    if (!ta)\n        return JS_EXCEPTION;\n    size = 1 << typed_array_size_log2(class_id);\n    if (JS_ToIndex(ctx, &pos, argv[0]))\n        return JS_EXCEPTION;\n    val = argv[1];\n    v = 0; /* avoid warning */\n    v64 = 0; /* avoid warning */\n    if (class_id <= JS_CLASS_UINT32_ARRAY) {\n        if (JS_ToUint32(ctx, &v, val))\n            return JS_EXCEPTION;\n    } else\n#ifdef CONFIG_BIGNUM\n    if (class_id <= JS_CLASS_BIG_UINT64_ARRAY) {\n        if (JS_ToBigInt64(ctx, (int64_t *)&v64, val))\n            return JS_EXCEPTION;\n    } else\n#endif\n    {\n        double d;\n        if (JS_ToFloat64(ctx, &d, val))\n            return JS_EXCEPTION;\n        if (class_id == JS_CLASS_FLOAT32_ARRAY) {\n            union {\n                float f;\n                uint32_t i;\n            } u;\n            u.f = d;\n            v = u.i;\n        } else {\n            JSFloat64Union u;\n            u.d = d;\n            v64 = u.u64;\n        }\n    }\n    is_swap = FALSE;\n    if (argc > 2)\n        is_swap = JS_ToBool(ctx, argv[2]);\n#ifndef WORDS_BIGENDIAN\n    is_swap ^= 1;\n#endif\n    abuf = ta->buffer->u.array_buffer;\n    if (abuf->detached)\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n    if ((pos + size) > ta->length)\n        return JS_ThrowRangeError(ctx, \"out of bound\");\n    ptr = abuf->data + ta->offset + pos;\n\n    switch(class_id) {\n    case JS_CLASS_INT8_ARRAY:\n    case JS_CLASS_UINT8_ARRAY:\n        *ptr = v;\n        break;\n    case JS_CLASS_INT16_ARRAY:\n    case JS_CLASS_UINT16_ARRAY:\n        if (is_swap)\n            v = bswap16(v);\n        put_u16(ptr, v);\n        break;\n    case JS_CLASS_INT32_ARRAY:\n    case JS_CLASS_UINT32_ARRAY:\n    case JS_CLASS_FLOAT32_ARRAY:\n        if (is_swap)\n            v = bswap32(v);\n        put_u32(ptr, v);\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_CLASS_BIG_INT64_ARRAY:\n    case JS_CLASS_BIG_UINT64_ARRAY:\n#endif\n    case JS_CLASS_FLOAT64_ARRAY:\n        if (is_swap)\n            v64 = bswap64(v64);\n        put_u64(ptr, v64);\n        break;\n    default:\n        abort();\n    }\n    return JS_UNDEFINED;\n}\n\nstatic const JSCFunctionListEntry js_dataview_proto_funcs[] = {\n    JS_CGETSET_MAGIC_DEF(\"buffer\", js_typed_array_get_buffer, NULL, 1 ),\n    JS_CGETSET_MAGIC_DEF(\"byteLength\", js_typed_array_get_byteLength, NULL, 1 ),\n    JS_CGETSET_MAGIC_DEF(\"byteOffset\", js_typed_array_get_byteOffset, NULL, 1 ),\n    JS_CFUNC_MAGIC_DEF(\"getInt8\", 1, js_dataview_getValue, JS_CLASS_INT8_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getUint8\", 1, js_dataview_getValue, JS_CLASS_UINT8_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getInt16\", 1, js_dataview_getValue, JS_CLASS_INT16_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getUint16\", 1, js_dataview_getValue, JS_CLASS_UINT16_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getInt32\", 1, js_dataview_getValue, JS_CLASS_INT32_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getUint32\", 1, js_dataview_getValue, JS_CLASS_UINT32_ARRAY ),\n#ifdef CONFIG_BIGNUM\n    JS_CFUNC_MAGIC_DEF(\"getBigInt64\", 1, js_dataview_getValue, JS_CLASS_BIG_INT64_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getBigUint64\", 1, js_dataview_getValue, JS_CLASS_BIG_UINT64_ARRAY ),\n#endif\n    JS_CFUNC_MAGIC_DEF(\"getFloat32\", 1, js_dataview_getValue, JS_CLASS_FLOAT32_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"getFloat64\", 1, js_dataview_getValue, JS_CLASS_FLOAT64_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setInt8\", 2, js_dataview_setValue, JS_CLASS_INT8_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setUint8\", 2, js_dataview_setValue, JS_CLASS_UINT8_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setInt16\", 2, js_dataview_setValue, JS_CLASS_INT16_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setUint16\", 2, js_dataview_setValue, JS_CLASS_UINT16_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setInt32\", 2, js_dataview_setValue, JS_CLASS_INT32_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setUint32\", 2, js_dataview_setValue, JS_CLASS_UINT32_ARRAY ),\n#ifdef CONFIG_BIGNUM\n    JS_CFUNC_MAGIC_DEF(\"setBigInt64\", 2, js_dataview_setValue, JS_CLASS_BIG_INT64_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setBigUint64\", 2, js_dataview_setValue, JS_CLASS_BIG_UINT64_ARRAY ),\n#endif\n    JS_CFUNC_MAGIC_DEF(\"setFloat32\", 2, js_dataview_setValue, JS_CLASS_FLOAT32_ARRAY ),\n    JS_CFUNC_MAGIC_DEF(\"setFloat64\", 2, js_dataview_setValue, JS_CLASS_FLOAT64_ARRAY ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"DataView\", JS_PROP_CONFIGURABLE ),\n};\n\n/* Atomics */\n#ifdef CONFIG_ATOMICS\n\ntypedef enum AtomicsOpEnum {\n    ATOMICS_OP_ADD,\n    ATOMICS_OP_AND,\n    ATOMICS_OP_OR,\n    ATOMICS_OP_SUB,\n    ATOMICS_OP_XOR,\n    ATOMICS_OP_EXCHANGE,\n    ATOMICS_OP_COMPARE_EXCHANGE,\n    ATOMICS_OP_LOAD,\n} AtomicsOpEnum;\n\nstatic void *js_atomics_get_ptr(JSContext *ctx,\n                                JSArrayBuffer **pabuf,\n                                int *psize_log2, JSClassID *pclass_id,\n                                JSValueConst obj, JSValueConst idx_val,\n                                int is_waitable)\n{\n    JSObject *p;\n    JSTypedArray *ta;\n    JSArrayBuffer *abuf;\n    void *ptr;\n    uint64_t idx;\n    BOOL err;\n    int size_log2;\n\n    if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)\n        goto fail;\n    p = JS_VALUE_GET_OBJ(obj);\n#ifdef CONFIG_BIGNUM\n    if (is_waitable)\n        err = (p->class_id != JS_CLASS_INT32_ARRAY &&\n               p->class_id != JS_CLASS_BIG_INT64_ARRAY);\n    else\n        err = !(p->class_id >= JS_CLASS_INT8_ARRAY &&\n                p->class_id <= JS_CLASS_BIG_UINT64_ARRAY);\n#else\n    if (is_waitable)\n        err = (p->class_id != JS_CLASS_INT32_ARRAY);\n    else\n        err = !(p->class_id >= JS_CLASS_INT8_ARRAY &&\n                p->class_id <= JS_CLASS_UINT32_ARRAY);\n#endif\n    if (err) {\n    fail:\n        JS_ThrowTypeError(ctx, \"integer TypedArray expected\");\n        return NULL;\n    }\n    ta = p->u.typed_array;\n    abuf = ta->buffer->u.array_buffer;\n    if (!abuf->shared) {\n        if (is_waitable == 2) {\n            JS_ThrowTypeError(ctx, \"not a SharedArrayBuffer TypedArray\");\n            return NULL;\n        }\n        if (abuf->detached) {\n            JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n            return NULL;\n        }\n    }\n    if (JS_ToIndex(ctx, &idx, idx_val)) {\n        return NULL;\n    }\n    /* if the array buffer is detached, p->u.array.count = 0 */\n    if (idx >= p->u.array.count) {\n        JS_ThrowRangeError(ctx, \"out-of-bound access\");\n        return NULL;\n    }\n    size_log2 = typed_array_size_log2(p->class_id);\n    ptr = p->u.array.u.uint8_ptr + ((uintptr_t)idx << size_log2);\n    if (pabuf)\n        *pabuf = abuf;\n    if (psize_log2)\n        *psize_log2 = size_log2;\n    if (pclass_id)\n        *pclass_id = p->class_id;\n    return ptr;\n}\n\nstatic JSValue js_atomics_op(JSContext *ctx,\n                             JSValueConst this_obj,\n                             int argc, JSValueConst *argv, int op)\n{\n    int size_log2;\n#ifdef CONFIG_BIGNUM\n    uint64_t v, a, rep_val;\n#else\n    uint32_t v, a, rep_val;\n#endif\n    void *ptr;\n    JSValue ret;\n    JSClassID class_id;\n    JSArrayBuffer *abuf;\n\n    ptr = js_atomics_get_ptr(ctx, &abuf, &size_log2, &class_id,\n                             argv[0], argv[1], 0);\n    if (!ptr)\n        return JS_EXCEPTION;\n    rep_val = 0;\n    if (op == ATOMICS_OP_LOAD) {\n        v = 0;\n    } else {\n#ifdef CONFIG_BIGNUM\n        if (size_log2 == 3) {\n            int64_t v64;\n            if (JS_ToBigInt64(ctx, &v64, argv[2]))\n                return JS_EXCEPTION;\n            v = v64;\n            if (op == ATOMICS_OP_COMPARE_EXCHANGE) {\n                if (JS_ToBigInt64(ctx, &v64, argv[3]))\n                    return JS_EXCEPTION;\n                rep_val = v64;\n            }\n        } else\n#endif\n        {\n                uint32_t v32;\n                if (JS_ToUint32(ctx, &v32, argv[2]))\n                    return JS_EXCEPTION;\n                v = v32;\n                if (op == ATOMICS_OP_COMPARE_EXCHANGE) {\n                    if (JS_ToUint32(ctx, &v32, argv[3]))\n                        return JS_EXCEPTION;\n                    rep_val = v32;\n                }\n        }\n        if (abuf->detached)\n            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n   }\n\n   switch(op | (size_log2 << 3)) {\n            \n#ifdef CONFIG_BIGNUM\n#define OP(op_name, func_name)                          \\\n    case ATOMICS_OP_ ## op_name | (0 << 3):             \\\n       a = func_name((_Atomic(uint8_t) *)ptr, v);       \\\n       break;                                           \\\n    case ATOMICS_OP_ ## op_name | (1 << 3):             \\\n        a = func_name((_Atomic(uint16_t) *)ptr, v);     \\\n        break;                                          \\\n    case ATOMICS_OP_ ## op_name | (2 << 3):             \\\n        a = func_name((_Atomic(uint32_t) *)ptr, v);     \\\n        break;                                          \\\n    case ATOMICS_OP_ ## op_name | (3 << 3):             \\\n        a = func_name((_Atomic(uint64_t) *)ptr, v);     \\\n        break;\n#else\n#define OP(op_name, func_name)                          \\\n    case ATOMICS_OP_ ## op_name | (0 << 3):             \\\n       a = func_name((_Atomic(uint8_t) *)ptr, v);       \\\n       break;                                           \\\n    case ATOMICS_OP_ ## op_name | (1 << 3):             \\\n        a = func_name((_Atomic(uint16_t) *)ptr, v);     \\\n        break;                                          \\\n    case ATOMICS_OP_ ## op_name | (2 << 3):             \\\n        a = func_name((_Atomic(uint32_t) *)ptr, v);     \\\n        break;\n#endif\n        OP(ADD, atomic_fetch_add)\n        OP(AND, atomic_fetch_and)\n        OP(OR, atomic_fetch_or)\n        OP(SUB, atomic_fetch_sub)\n        OP(XOR, atomic_fetch_xor)\n        OP(EXCHANGE, atomic_exchange)\n#undef OP\n\n    case ATOMICS_OP_LOAD | (0 << 3):\n        a = atomic_load((_Atomic(uint8_t) *)ptr);\n        break;\n    case ATOMICS_OP_LOAD | (1 << 3):\n        a = atomic_load((_Atomic(uint16_t) *)ptr);\n        break;\n    case ATOMICS_OP_LOAD | (2 << 3):\n        a = atomic_load((_Atomic(uint32_t) *)ptr);\n        break;\n#ifdef CONFIG_BIGNUM\n    case ATOMICS_OP_LOAD | (3 << 3):\n        a = atomic_load((_Atomic(uint64_t) *)ptr);\n        break;\n#endif\n        \n    case ATOMICS_OP_COMPARE_EXCHANGE | (0 << 3):\n        {\n            uint8_t v1 = v;\n            atomic_compare_exchange_strong((_Atomic(uint8_t) *)ptr, &v1, rep_val);\n            a = v1;\n        }\n        break;\n    case ATOMICS_OP_COMPARE_EXCHANGE | (1 << 3):\n        {\n            uint16_t v1 = v;\n            atomic_compare_exchange_strong((_Atomic(uint16_t) *)ptr, &v1, rep_val);\n            a = v1;\n        }\n        break;\n    case ATOMICS_OP_COMPARE_EXCHANGE | (2 << 3):\n        {\n            uint32_t v1 = v;\n            atomic_compare_exchange_strong((_Atomic(uint32_t) *)ptr, &v1, rep_val);\n            a = v1;\n        }\n        break;\n#ifdef CONFIG_BIGNUM\n    case ATOMICS_OP_COMPARE_EXCHANGE | (3 << 3):\n        {\n            uint64_t v1 = v;\n            atomic_compare_exchange_strong((_Atomic(uint64_t) *)ptr, &v1, rep_val);\n            a = v1;\n        }\n        break;\n#endif\n    default:\n        abort();\n    }\n\n    switch(class_id) {\n    case JS_CLASS_INT8_ARRAY:\n        a = (int8_t)a;\n        goto done;\n    case JS_CLASS_UINT8_ARRAY:\n        a = (uint8_t)a;\n        goto done;\n    case JS_CLASS_INT16_ARRAY:\n        a = (int16_t)a;\n        goto done;\n    case JS_CLASS_UINT16_ARRAY:\n        a = (uint16_t)a;\n        goto done;\n    case JS_CLASS_INT32_ARRAY:\n    done:\n        ret = JS_NewInt32(ctx, a);\n        break;\n    case JS_CLASS_UINT32_ARRAY:\n        ret = JS_NewUint32(ctx, a);\n        break;\n#ifdef CONFIG_BIGNUM\n    case JS_CLASS_BIG_INT64_ARRAY:\n        ret = JS_NewBigInt64(ctx, a);\n        break;\n    case JS_CLASS_BIG_UINT64_ARRAY:\n        ret = JS_NewBigUint64(ctx, a);\n        break;\n#endif\n    default:\n        abort();\n    }\n    return ret;\n}\n\nstatic JSValue js_atomics_store(JSContext *ctx,\n                                JSValueConst this_obj,\n                                int argc, JSValueConst *argv)\n{\n    int size_log2;\n    void *ptr;\n    JSValue ret;\n    JSArrayBuffer *abuf;\n\n    ptr = js_atomics_get_ptr(ctx, &abuf, &size_log2, NULL,\n                             argv[0], argv[1], 0);\n    if (!ptr)\n        return JS_EXCEPTION;\n#ifdef CONFIG_BIGNUM\n    if (size_log2 == 3) {\n        int64_t v64;\n        ret = JS_ToBigIntValueFree(ctx, JS_DupValue(ctx, argv[2]));\n        if (JS_IsException(ret))\n            return ret;\n        if (JS_ToBigInt64(ctx, &v64, ret)) {\n            JS_FreeValue(ctx, ret);\n            return JS_EXCEPTION;\n        }\n        if (abuf->detached)\n            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        atomic_store((_Atomic(uint64_t) *)ptr, v64);\n    } else\n#endif\n    {\n        uint32_t v;\n        /* XXX: spec, would be simpler to return the written value */\n        ret = JS_ToIntegerFree(ctx, JS_DupValue(ctx, argv[2]));\n        if (JS_IsException(ret))\n            return ret;\n        if (JS_ToUint32(ctx, &v, ret)) {\n            JS_FreeValue(ctx, ret);\n            return JS_EXCEPTION;\n        }\n        if (abuf->detached)\n            return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n        switch(size_log2) {\n        case 0:\n            atomic_store((_Atomic(uint8_t) *)ptr, v);\n            break;\n        case 1:\n            atomic_store((_Atomic(uint16_t) *)ptr, v);\n            break;\n        case 2:\n            atomic_store((_Atomic(uint32_t) *)ptr, v);\n            break;\n        default:\n            abort();\n        }\n    }\n    return ret;\n}\n\nstatic JSValue js_atomics_isLockFree(JSContext *ctx,\n                                     JSValueConst this_obj,\n                                     int argc, JSValueConst *argv)\n{\n    int v, ret;\n    if (JS_ToInt32Sat(ctx, &v, argv[0]))\n        return JS_EXCEPTION;\n    ret = (v == 1 || v == 2 || v == 4\n#ifdef CONFIG_BIGNUM\n           || v == 8\n#endif\n           );\n    return JS_NewBool(ctx, ret);\n}\n\ntypedef struct JSAtomicsWaiter {\n    struct list_head link;\n    BOOL linked;\n    pthread_cond_t cond;\n    int32_t *ptr;\n} JSAtomicsWaiter;\n\nstatic pthread_mutex_t js_atomics_mutex = PTHREAD_MUTEX_INITIALIZER;\nstatic struct list_head js_atomics_waiter_list =\n    LIST_HEAD_INIT(js_atomics_waiter_list);\n\nstatic JSValue js_atomics_wait(JSContext *ctx,\n                               JSValueConst this_obj,\n                               int argc, JSValueConst *argv)\n{\n    int64_t v;\n    int32_t v32;\n    void *ptr;\n    int64_t timeout;\n    struct timespec ts;\n    JSAtomicsWaiter waiter_s, *waiter;\n    int ret, size_log2, res;\n    double d;\n\n    ptr = js_atomics_get_ptr(ctx, NULL, &size_log2, NULL,\n                             argv[0], argv[1], 2);\n    if (!ptr)\n        return JS_EXCEPTION;\n#ifdef CONFIG_BIGNUM\n    if (size_log2 == 3) {\n        if (JS_ToBigInt64(ctx, &v, argv[2]))\n            return JS_EXCEPTION;\n    } else\n#endif\n    {        \n        if (JS_ToInt32(ctx, &v32, argv[2]))\n            return JS_EXCEPTION;\n        v = v32;\n    }\n    if (JS_ToFloat64(ctx, &d, argv[3]))\n        return JS_EXCEPTION;\n    if (isnan(d) || d > INT64_MAX)\n        timeout = INT64_MAX;\n    else if (d < 0)\n        timeout = 0;\n    else\n        timeout = (int64_t)d;\n    if (!ctx->rt->can_block)\n        return JS_ThrowTypeError(ctx, \"cannot block in this thread\");\n\n    /* XXX: inefficient if large number of waiters, should hash on\n       'ptr' value */\n    /* XXX: use Linux futexes when available ? */\n    pthread_mutex_lock(&js_atomics_mutex);\n    if (size_log2 == 3) {\n        res = *(int64_t *)ptr != v;\n    } else {\n        res = *(int32_t *)ptr != v;\n    }\n    if (res) {\n        pthread_mutex_unlock(&js_atomics_mutex);\n        return JS_AtomToString(ctx, JS_ATOM_not_equal);\n    }\n\n    waiter = &waiter_s;\n    waiter->ptr = ptr;\n    pthread_cond_init(&waiter->cond, NULL);\n    waiter->linked = TRUE;\n    list_add_tail(&waiter->link, &js_atomics_waiter_list);\n\n    if (timeout == INT64_MAX) {\n        pthread_cond_wait(&waiter->cond, &js_atomics_mutex);\n        ret = 0;\n    } else {\n        /* XXX: use clock monotonic */\n        clock_gettime(CLOCK_REALTIME, &ts);\n        ts.tv_sec += timeout / 1000;\n        ts.tv_nsec += (timeout % 1000) * 1000000;\n        if (ts.tv_nsec >= 1000000000) {\n            ts.tv_nsec -= 1000000000;\n            ts.tv_sec++;\n        }\n        ret = pthread_cond_timedwait(&waiter->cond, &js_atomics_mutex,\n                                     &ts);\n    }\n    if (waiter->linked)\n        list_del(&waiter->link);\n    pthread_mutex_unlock(&js_atomics_mutex);\n    pthread_cond_destroy(&waiter->cond);\n    if (ret == ETIMEDOUT) {\n        return JS_AtomToString(ctx, JS_ATOM_timed_out);\n    } else {\n        return JS_AtomToString(ctx, JS_ATOM_ok);\n    }\n}\n\nstatic JSValue js_atomics_notify(JSContext *ctx,\n                                 JSValueConst this_obj,\n                                 int argc, JSValueConst *argv)\n{\n    struct list_head *el, *el1, waiter_list;\n    int32_t count, n;\n    void *ptr;\n    JSAtomicsWaiter *waiter;\n    JSArrayBuffer *abuf;\n\n    ptr = js_atomics_get_ptr(ctx, &abuf, NULL, NULL, argv[0], argv[1], 1);\n    if (!ptr)\n        return JS_EXCEPTION;\n\n    if (JS_IsUndefined(argv[2])) {\n        count = INT32_MAX;\n    } else {\n        if (JS_ToInt32Clamp(ctx, &count, argv[2], 0, INT32_MAX, 0))\n            return JS_EXCEPTION;\n    }\n    if (abuf->detached)\n        return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);\n\n    n = 0;\n    if (abuf->shared && count > 0) {\n        pthread_mutex_lock(&js_atomics_mutex);\n        init_list_head(&waiter_list);\n        list_for_each_safe(el, el1, &js_atomics_waiter_list) {\n            waiter = list_entry(el, JSAtomicsWaiter, link);\n            if (waiter->ptr == ptr) {\n                list_del(&waiter->link);\n                waiter->linked = FALSE;\n                list_add_tail(&waiter->link, &waiter_list);\n                n++;\n                if (n >= count)\n                    break;\n            }\n        }\n        list_for_each(el, &waiter_list) {\n            waiter = list_entry(el, JSAtomicsWaiter, link);\n            pthread_cond_signal(&waiter->cond);\n        }\n        pthread_mutex_unlock(&js_atomics_mutex);\n    }\n    return JS_NewInt32(ctx, n);\n}\n\nstatic const JSCFunctionListEntry js_atomics_funcs[] = {\n    JS_CFUNC_MAGIC_DEF(\"add\", 3, js_atomics_op, ATOMICS_OP_ADD ),\n    JS_CFUNC_MAGIC_DEF(\"and\", 3, js_atomics_op, ATOMICS_OP_AND ),\n    JS_CFUNC_MAGIC_DEF(\"or\", 3, js_atomics_op, ATOMICS_OP_OR ),\n    JS_CFUNC_MAGIC_DEF(\"sub\", 3, js_atomics_op, ATOMICS_OP_SUB ),\n    JS_CFUNC_MAGIC_DEF(\"xor\", 3, js_atomics_op, ATOMICS_OP_XOR ),\n    JS_CFUNC_MAGIC_DEF(\"exchange\", 3, js_atomics_op, ATOMICS_OP_EXCHANGE ),\n    JS_CFUNC_MAGIC_DEF(\"compareExchange\", 4, js_atomics_op, ATOMICS_OP_COMPARE_EXCHANGE ),\n    JS_CFUNC_MAGIC_DEF(\"load\", 2, js_atomics_op, ATOMICS_OP_LOAD ),\n    JS_CFUNC_DEF(\"store\", 3, js_atomics_store ),\n    JS_CFUNC_DEF(\"isLockFree\", 1, js_atomics_isLockFree ),\n    JS_CFUNC_DEF(\"wait\", 4, js_atomics_wait ),\n    JS_CFUNC_DEF(\"notify\", 3, js_atomics_notify ),\n    JS_PROP_STRING_DEF(\"[Symbol.toStringTag]\", \"Atomics\", JS_PROP_CONFIGURABLE ),\n};\n\nstatic const JSCFunctionListEntry js_atomics_obj[] = {\n    JS_OBJECT_DEF(\"Atomics\", js_atomics_funcs, countof(js_atomics_funcs), JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),\n};\n\nvoid JS_AddIntrinsicAtomics(JSContext *ctx)\n{\n    /* add Atomics as autoinit object */\n    JS_SetPropertyFunctionList(ctx, ctx->global_obj, js_atomics_obj, countof(js_atomics_obj));\n}\n\n#endif /* CONFIG_ATOMICS */\n\nvoid JS_AddIntrinsicTypedArrays(JSContext *ctx)\n{\n    JSValue typed_array_base_proto, typed_array_base_func;\n    JSValueConst array_buffer_func, shared_array_buffer_func;\n    int i;\n\n    ctx->class_proto[JS_CLASS_ARRAY_BUFFER] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_ARRAY_BUFFER],\n                               js_array_buffer_proto_funcs,\n                               countof(js_array_buffer_proto_funcs));\n\n    array_buffer_func = JS_NewGlobalCConstructorOnly(ctx, \"ArrayBuffer\",\n                                                 js_array_buffer_constructor, 1,\n                                                 ctx->class_proto[JS_CLASS_ARRAY_BUFFER]);\n    JS_SetPropertyFunctionList(ctx, array_buffer_func,\n                               js_array_buffer_funcs,\n                               countof(js_array_buffer_funcs));\n\n    ctx->class_proto[JS_CLASS_SHARED_ARRAY_BUFFER] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_SHARED_ARRAY_BUFFER],\n                               js_shared_array_buffer_proto_funcs,\n                               countof(js_shared_array_buffer_proto_funcs));\n\n    shared_array_buffer_func = JS_NewGlobalCConstructorOnly(ctx, \"SharedArrayBuffer\",\n                                                 js_shared_array_buffer_constructor, 1,\n                                                 ctx->class_proto[JS_CLASS_SHARED_ARRAY_BUFFER]);\n    JS_SetPropertyFunctionList(ctx, shared_array_buffer_func,\n                               js_shared_array_buffer_funcs,\n                               countof(js_shared_array_buffer_funcs));\n\n    typed_array_base_proto = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, typed_array_base_proto,\n                               js_typed_array_base_proto_funcs,\n                               countof(js_typed_array_base_proto_funcs));\n\n    /* TypedArray.prototype.toString must be the same object as Array.prototype.toString */\n    JSValue obj = JS_GetProperty(ctx, ctx->class_proto[JS_CLASS_ARRAY], JS_ATOM_toString);\n    /* XXX: should use alias method in JSCFunctionListEntry */ //@@@\n    JS_DefinePropertyValue(ctx, typed_array_base_proto, JS_ATOM_toString, obj,\n                           JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE);\n\n    typed_array_base_func = JS_NewCFunction(ctx, js_typed_array_base_constructor,\n                                            \"TypedArray\", 0);\n    JS_SetPropertyFunctionList(ctx, typed_array_base_func,\n                               js_typed_array_base_funcs,\n                               countof(js_typed_array_base_funcs));\n    JS_SetConstructor(ctx, typed_array_base_func, typed_array_base_proto);\n\n    for(i = JS_CLASS_UINT8C_ARRAY; i < JS_CLASS_UINT8C_ARRAY + JS_TYPED_ARRAY_COUNT; i++) {\n        JSValue func_obj;\n        char buf[ATOM_GET_STR_BUF_SIZE];\n        const char *name;\n\n        ctx->class_proto[i] = JS_NewObjectProto(ctx, typed_array_base_proto);\n        JS_DefinePropertyValueStr(ctx, ctx->class_proto[i],\n                                  \"BYTES_PER_ELEMENT\",\n                                  JS_NewInt32(ctx, 1 << typed_array_size_log2(i)),\n                                  0);\n        name = JS_AtomGetStr(ctx, buf, sizeof(buf),\n                             JS_ATOM_Uint8ClampedArray + i - JS_CLASS_UINT8C_ARRAY);\n        func_obj = JS_NewCFunction3(ctx, (JSCFunction *)js_typed_array_constructor,\n                                    name, 3, JS_CFUNC_constructor_magic, i,\n                                    typed_array_base_func);\n        JS_NewGlobalCConstructor2(ctx, func_obj, name, ctx->class_proto[i]);\n        JS_DefinePropertyValueStr(ctx, func_obj,\n                                  \"BYTES_PER_ELEMENT\",\n                                  JS_NewInt32(ctx, 1 << typed_array_size_log2(i)),\n                                  0);\n    }\n    JS_FreeValue(ctx, typed_array_base_proto);\n    JS_FreeValue(ctx, typed_array_base_func);\n\n    /* DataView */\n    ctx->class_proto[JS_CLASS_DATAVIEW] = JS_NewObject(ctx);\n    JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_DATAVIEW],\n                               js_dataview_proto_funcs,\n                               countof(js_dataview_proto_funcs));\n    JS_NewGlobalCConstructorOnly(ctx, \"DataView\",\n                                 js_dataview_constructor, 1,\n                                 ctx->class_proto[JS_CLASS_DATAVIEW]);\n    /* Atomics */\n#ifdef CONFIG_ATOMICS\n    JS_AddIntrinsicAtomics(ctx);\n#endif\n}\n"
  },
  {
    "path": "quickjs.go",
    "content": "package quickjs\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"math/big\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"unsafe\"\n)\n\n/*\n#cgo CFLAGS: -D_GNU_SOURCE\n#cgo CFLAGS: -DCONFIG_BIGNUM\n#cgo CFLAGS: -fno-asynchronous-unwind-tables\n#cgo LDFLAGS: -lm -lpthread\n\n#include \"bridge.h\"\n*/\nimport \"C\"\n\ntype Runtime struct {\n\tref *C.JSRuntime\n}\n\nfunc NewRuntime() Runtime {\n\trt := Runtime{ref: C.JS_NewRuntime()}\n\tC.JS_SetCanBlock(rt.ref, C.int(1))\n\treturn rt\n}\n\nfunc (r Runtime) RunGC() { C.JS_RunGC(r.ref) }\n\nfunc (r Runtime) Free() { C.JS_FreeRuntime(r.ref) }\n\nfunc (r Runtime) NewContext() *Context {\n\tref := C.JS_NewContext(r.ref)\n\n\tC.JS_AddIntrinsicBigFloat(ref)\n\tC.JS_AddIntrinsicBigDecimal(ref)\n\tC.JS_AddIntrinsicOperators(ref)\n\tC.JS_EnableBignumExt(ref, C.int(1))\n\n\treturn &Context{ref: ref}\n}\n\nfunc (r Runtime) ExecutePendingJob() (Context, error) {\n\tvar ctx Context\n\n\terr := C.JS_ExecutePendingJob(r.ref, &ctx.ref)\n\tif err <= 0 {\n\t\tif err == 0 {\n\t\t\treturn ctx, io.EOF\n\t\t}\n\t\treturn ctx, ctx.Exception()\n\t}\n\n\treturn ctx, nil\n}\n\ntype Function func(ctx *Context, this Value, args []Value) Value\n\ntype funcEntry struct {\n\tctx *Context\n\tfn  Function\n}\n\nvar funcPtrLen int64\nvar funcPtrLock sync.Mutex\nvar funcPtrStore = make(map[int64]funcEntry)\nvar funcPtrClassID C.JSClassID\n\nfunc init() { C.JS_NewClassID(&funcPtrClassID) }\n\nfunc storeFuncPtr(v funcEntry) int64 {\n\tid := atomic.AddInt64(&funcPtrLen, 1) - 1\n\tfuncPtrLock.Lock()\n\tdefer funcPtrLock.Unlock()\n\tfuncPtrStore[id] = v\n\treturn id\n}\n\nfunc restoreFuncPtr(ptr int64) funcEntry {\n\tfuncPtrLock.Lock()\n\tdefer funcPtrLock.Unlock()\n\treturn funcPtrStore[ptr]\n}\n\n//func freeFuncPtr(ptr int64) {\n//\tfuncPtrLock.Lock()\n//\tdefer funcPtrLock.Unlock()\n//\tdelete(funcPtrStore, ptr)\n//}\n\n//export proxy\nfunc proxy(ctx *C.JSContext, thisVal C.JSValueConst, argc C.int, argv *C.JSValueConst) C.JSValue {\n\trefs := (*[1 << 30]C.JSValueConst)(unsafe.Pointer(argv))[:argc:argc]\n\n\tid := C.int64_t(0)\n\tC.JS_ToInt64(ctx, &id, refs[0])\n\n\tentry := restoreFuncPtr(int64(id))\n\n\targs := make([]Value, len(refs)-1)\n\tfor i := 0; i < len(args); i++ {\n\t\targs[i].ctx = entry.ctx\n\t\targs[i].ref = refs[1+i]\n\t}\n\n\tresult := entry.fn(entry.ctx, Value{ctx: entry.ctx, ref: thisVal}, args)\n\n\treturn result.ref\n}\n\ntype Context struct {\n\tref     *C.JSContext\n\tglobals *Value\n\tproxy   *Value\n}\n\nfunc (ctx *Context) Free() {\n\tif ctx.proxy != nil {\n\t\tctx.proxy.Free()\n\t}\n\tif ctx.globals != nil {\n\t\tctx.globals.Free()\n\t}\n\n\tC.JS_FreeContext(ctx.ref)\n}\n\nfunc (ctx *Context) Function(fn Function) Value {\n\tval := ctx.eval(`(proxy, id) => function() { return proxy.call(this, id, ...arguments); }`)\n\tif val.IsException() {\n\t\treturn val\n\t}\n\tdefer val.Free()\n\n\tfuncPtr := storeFuncPtr(funcEntry{ctx: ctx, fn: fn})\n\tfuncPtrVal := ctx.Int64(funcPtr)\n\n\tif ctx.proxy == nil {\n\t\tctx.proxy = &Value{\n\t\t\tctx: ctx,\n\t\t\tref: C.JS_NewCFunction(ctx.ref, (*C.JSCFunction)(unsafe.Pointer(C.InvokeProxy)), nil, C.int(0)),\n\t\t}\n\t}\n\n\targs := []C.JSValue{ctx.proxy.ref, funcPtrVal.ref}\n\n\treturn Value{ctx: ctx, ref: C.JS_Call(ctx.ref, val.ref, ctx.Null().ref, C.int(len(args)), &args[0])}\n}\n\nfunc (ctx *Context) Null() Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewNull()}\n}\n\nfunc (ctx *Context) Undefined() Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewUndefined()}\n}\n\nfunc (ctx *Context) Uninitialized() Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewUninitialized()}\n}\n\nfunc (ctx *Context) Error(err error) Value {\n\tval := Value{ctx: ctx, ref: C.JS_NewError(ctx.ref)}\n\tval.Set(\"message\", ctx.String(err.Error()))\n\treturn val\n}\n\nfunc (ctx *Context) Bool(b bool) Value {\n\tbv := 0\n\tif b {\n\t\tbv = 1\n\t}\n\treturn Value{ctx: ctx, ref: C.JS_NewBool(ctx.ref, C.int(bv))}\n}\n\nfunc (ctx *Context) Int32(v int32) Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewInt32(ctx.ref, C.int32_t(v))}\n}\n\nfunc (ctx *Context) Int64(v int64) Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewInt64(ctx.ref, C.int64_t(v))}\n}\n\nfunc (ctx *Context) Uint32(v uint32) Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewUint32(ctx.ref, C.uint32_t(v))}\n}\n\nfunc (ctx *Context) BigUint64(v uint64) Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewBigUint64(ctx.ref, C.uint64_t(v))}\n}\n\nfunc (ctx *Context) Float64(v float64) Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewFloat64(ctx.ref, C.double(v))}\n}\n\nfunc (ctx *Context) String(v string) Value {\n\tptr := C.CString(v)\n\tdefer C.free(unsafe.Pointer(ptr))\n\treturn Value{ctx: ctx, ref: C.JS_NewString(ctx.ref, ptr)}\n}\n\nfunc (ctx *Context) Atom(v string) Atom {\n\tptr := C.CString(v)\n\tdefer C.free(unsafe.Pointer(ptr))\n\treturn Atom{ctx: ctx, ref: C.JS_NewAtom(ctx.ref, ptr)}\n}\n\nfunc (ctx *Context) eval(code string) Value { return ctx.evalFile(code, \"code\") }\n\nfunc (ctx *Context) evalFile(code, filename string) Value {\n\tcodePtr := C.CString(code)\n\tdefer C.free(unsafe.Pointer(codePtr))\n\n\tfilenamePtr := C.CString(filename)\n\tdefer C.free(unsafe.Pointer(filenamePtr))\n\n\treturn Value{ctx: ctx, ref: C.JS_Eval(ctx.ref, codePtr, C.size_t(len(code)), filenamePtr, C.int(0))}\n}\n\nfunc (ctx *Context) Eval(code string) (Value, error) { return ctx.EvalFile(code, \"code\") }\n\nfunc (ctx *Context) EvalFile(code, filename string) (Value, error) {\n\tval := ctx.evalFile(code, filename)\n\tif val.IsException() {\n\t\treturn val, ctx.Exception()\n\t}\n\treturn val, nil\n}\n\nfunc (ctx *Context) Globals() Value {\n\tif ctx.globals == nil {\n\t\tctx.globals = &Value{\n\t\t\tctx: ctx,\n\t\t\tref: C.JS_GetGlobalObject(ctx.ref),\n\t\t}\n\t}\n\treturn *ctx.globals\n}\n\nfunc (ctx *Context) Throw(v Value) Value {\n\treturn Value{ctx: ctx, ref: C.JS_Throw(ctx.ref, v.ref)}\n}\n\nfunc (ctx *Context) ThrowError(err error) Value { return ctx.Throw(ctx.Error(err)) }\n\nfunc (ctx *Context) ThrowSyntaxError(format string, args ...interface{}) Value {\n\tcause := fmt.Sprintf(format, args...)\n\tcausePtr := C.CString(cause)\n\tdefer C.free(unsafe.Pointer(causePtr))\n\treturn Value{ctx: ctx, ref: C.ThrowSyntaxError(ctx.ref, causePtr)}\n}\n\nfunc (ctx *Context) ThrowTypeError(format string, args ...interface{}) Value {\n\tcause := fmt.Sprintf(format, args...)\n\tcausePtr := C.CString(cause)\n\tdefer C.free(unsafe.Pointer(causePtr))\n\treturn Value{ctx: ctx, ref: C.ThrowTypeError(ctx.ref, causePtr)}\n}\n\nfunc (ctx *Context) ThrowReferenceError(format string, args ...interface{}) Value {\n\tcause := fmt.Sprintf(format, args...)\n\tcausePtr := C.CString(cause)\n\tdefer C.free(unsafe.Pointer(causePtr))\n\treturn Value{ctx: ctx, ref: C.ThrowReferenceError(ctx.ref, causePtr)}\n}\n\nfunc (ctx *Context) ThrowRangeError(format string, args ...interface{}) Value {\n\tcause := fmt.Sprintf(format, args...)\n\tcausePtr := C.CString(cause)\n\tdefer C.free(unsafe.Pointer(causePtr))\n\treturn Value{ctx: ctx, ref: C.ThrowRangeError(ctx.ref, causePtr)}\n}\n\nfunc (ctx *Context) ThrowInternalError(format string, args ...interface{}) Value {\n\tcause := fmt.Sprintf(format, args...)\n\tcausePtr := C.CString(cause)\n\tdefer C.free(unsafe.Pointer(causePtr))\n\treturn Value{ctx: ctx, ref: C.ThrowInternalError(ctx.ref, causePtr)}\n}\n\nfunc (ctx *Context) Exception() error {\n\tval := Value{ctx: ctx, ref: C.JS_GetException(ctx.ref)}\n\tdefer val.Free()\n\treturn val.Error()\n}\n\nfunc (ctx *Context) Object() Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewObject(ctx.ref)}\n}\n\nfunc (ctx *Context) Array() Value {\n\treturn Value{ctx: ctx, ref: C.JS_NewArray(ctx.ref)}\n}\n\ntype Atom struct {\n\tctx *Context\n\tref C.JSAtom\n}\n\nfunc (a Atom) Free() { C.JS_FreeAtom(a.ctx.ref, a.ref) }\n\nfunc (a Atom) String() string {\n\tptr := C.JS_AtomToCString(a.ctx.ref, a.ref)\n\tdefer C.JS_FreeCString(a.ctx.ref, ptr)\n\treturn C.GoString(ptr)\n}\n\nfunc (a Atom) Value() Value {\n\treturn Value{ctx: a.ctx, ref: C.JS_AtomToValue(a.ctx.ref, a.ref)}\n}\n\ntype Value struct {\n\tctx *Context\n\tref C.JSValue\n}\n\nfunc (v Value) Free() { C.JS_FreeValue(v.ctx.ref, v.ref) }\n\nfunc (v Value) Context() *Context { return v.ctx }\n\nfunc (v Value) Bool() bool { return C.JS_ToBool(v.ctx.ref, v.ref) == 1 }\n\nfunc (v Value) String() string {\n\tptr := C.JS_ToCString(v.ctx.ref, v.ref)\n\tdefer C.JS_FreeCString(v.ctx.ref, ptr)\n\treturn C.GoString(ptr)\n}\n\nfunc (v Value) Int64() int64 {\n\tval := C.int64_t(0)\n\tC.JS_ToInt64(v.ctx.ref, &val, v.ref)\n\treturn int64(val)\n}\n\nfunc (v Value) Int32() int32 {\n\tval := C.int32_t(0)\n\tC.JS_ToInt32(v.ctx.ref, &val, v.ref)\n\treturn int32(val)\n}\n\nfunc (v Value) Uint32() uint32 {\n\tval := C.uint32_t(0)\n\tC.JS_ToUint32(v.ctx.ref, &val, v.ref)\n\treturn uint32(val)\n}\n\nfunc (v Value) Float64() float64 {\n\tval := C.double(0)\n\tC.JS_ToFloat64(v.ctx.ref, &val, v.ref)\n\treturn float64(val)\n}\n\nfunc (v Value) BigInt() *big.Int {\n\tif !v.IsBigInt() {\n\t\treturn nil\n\t}\n\tval, ok := new(big.Int).SetString(v.String(), 10)\n\tif !ok {\n\t\treturn nil\n\t}\n\treturn val\n}\n\nfunc (v Value) BigFloat() *big.Float {\n\tif !v.IsBigDecimal() && !v.IsBigFloat() {\n\t\treturn nil\n\t}\n\tval, ok := new(big.Float).SetString(v.String())\n\tif !ok {\n\t\treturn nil\n\t}\n\treturn val\n}\n\nfunc (v Value) Get(name string) Value {\n\tnamePtr := C.CString(name)\n\tdefer C.free(unsafe.Pointer(namePtr))\n\treturn Value{ctx: v.ctx, ref: C.JS_GetPropertyStr(v.ctx.ref, v.ref, namePtr)}\n}\n\nfunc (v Value) GetByAtom(atom Atom) Value {\n\treturn Value{ctx: v.ctx, ref: C.JS_GetProperty(v.ctx.ref, v.ref, atom.ref)}\n}\n\nfunc (v Value) GetByUint32(idx uint32) Value {\n\treturn Value{ctx: v.ctx, ref: C.JS_GetPropertyUint32(v.ctx.ref, v.ref, C.uint32_t(idx))}\n}\n\nfunc (v Value) SetByAtom(atom Atom, val Value) {\n\tC.JS_SetProperty(v.ctx.ref, v.ref, atom.ref, val.ref)\n}\n\nfunc (v Value) SetByInt64(idx int64, val Value) {\n\tC.JS_SetPropertyInt64(v.ctx.ref, v.ref, C.int64_t(idx), val.ref)\n}\n\nfunc (v Value) SetByUint32(idx uint32, val Value) {\n\tC.JS_SetPropertyUint32(v.ctx.ref, v.ref, C.uint32_t(idx), val.ref)\n}\n\nfunc (v Value) Len() int64 { return v.Get(\"length\").Int64() }\n\nfunc (v Value) Set(name string, val Value) {\n\tnamePtr := C.CString(name)\n\tdefer C.free(unsafe.Pointer(namePtr))\n\tC.JS_SetPropertyStr(v.ctx.ref, v.ref, namePtr, val.ref)\n}\n\nfunc (v Value) SetFunction(name string, fn Function) {\n\tv.Set(name, v.ctx.Function(fn))\n}\n\ntype Error struct {\n\tCause string\n\tStack string\n}\n\nfunc (err Error) Error() string { return err.Cause }\n\nfunc (v Value) Error() error {\n\tif !v.IsError() {\n\t\treturn nil\n\t}\n\tcause := v.String()\n\n\tstack := v.Get(\"stack\")\n\tdefer stack.Free()\n\n\tif stack.IsUndefined() {\n\t\treturn &Error{Cause: cause}\n\t}\n\treturn &Error{Cause: cause, Stack: stack.String()}\n}\n\nfunc (v Value) IsNumber() bool        { return C.JS_IsNumber(v.ref) == 1 }\nfunc (v Value) IsBigInt() bool        { return C.JS_IsBigInt(v.ctx.ref, v.ref) == 1 }\nfunc (v Value) IsBigFloat() bool      { return C.JS_IsBigFloat(v.ref) == 1 }\nfunc (v Value) IsBigDecimal() bool    { return C.JS_IsBigDecimal(v.ref) == 1 }\nfunc (v Value) IsBool() bool          { return C.JS_IsBool(v.ref) == 1 }\nfunc (v Value) IsNull() bool          { return C.JS_IsNull(v.ref) == 1 }\nfunc (v Value) IsUndefined() bool     { return C.JS_IsUndefined(v.ref) == 1 }\nfunc (v Value) IsException() bool     { return C.JS_IsException(v.ref) == 1 }\nfunc (v Value) IsUninitialized() bool { return C.JS_IsUninitialized(v.ref) == 1 }\nfunc (v Value) IsString() bool        { return C.JS_IsString(v.ref) == 1 }\nfunc (v Value) IsSymbol() bool        { return C.JS_IsSymbol(v.ref) == 1 }\nfunc (v Value) IsObject() bool        { return C.JS_IsObject(v.ref) == 1 }\nfunc (v Value) IsArray() bool         { return C.JS_IsArray(v.ctx.ref, v.ref) == 1 }\n\nfunc (v Value) IsError() bool       { return C.JS_IsError(v.ctx.ref, v.ref) == 1 }\nfunc (v Value) IsFunction() bool    { return C.JS_IsFunction(v.ctx.ref, v.ref) == 1 }\nfunc (v Value) IsConstructor() bool { return C.JS_IsConstructor(v.ctx.ref, v.ref) == 1 }\n\ntype PropertyEnum struct {\n\tIsEnumerable bool\n\tAtom         Atom\n}\n\nfunc (p PropertyEnum) String() string { return p.Atom.String() }\n\nfunc (v Value) PropertyNames() ([]PropertyEnum, error) {\n\tvar (\n\t\tptr  *C.JSPropertyEnum\n\t\tsize C.uint32_t\n\t)\n\n\tresult := int(C.JS_GetOwnPropertyNames(v.ctx.ref, &ptr, &size, v.ref, C.int(1<<0|1<<1|1<<2)))\n\tif result < 0 {\n\t\treturn nil, errors.New(\"value does not contain properties\")\n\t}\n\tdefer C.js_free(v.ctx.ref, unsafe.Pointer(ptr))\n\n\tentries := (*[1 << 30]C.JSPropertyEnum)(unsafe.Pointer(ptr))\n\n\tnames := make([]PropertyEnum, uint32(size))\n\n\tfor i := 0; i < len(names); i++ {\n\t\tnames[i].IsEnumerable = entries[i].is_enumerable == 1\n\n\t\tnames[i].Atom = Atom{ctx: v.ctx, ref: entries[i].atom}\n\t\tnames[i].Atom.Free()\n\t}\n\n\treturn names, nil\n}\n"
  },
  {
    "path": "quickjs.h",
    "content": "/*\n * QuickJS Javascript Engine\n *\n * Copyright (c) 2017-2020 Fabrice Bellard\n * Copyright (c) 2017-2020 Charlie Gordon\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n#ifndef QUICKJS_H\n#define QUICKJS_H\n\n#include <stdio.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#if defined(__GNUC__) || defined(__clang__)\n#define js_likely(x)          __builtin_expect(!!(x), 1)\n#define js_unlikely(x)        __builtin_expect(!!(x), 0)\n#define js_force_inline       inline __attribute__((always_inline))\n#define __js_printf_like(f, a)   __attribute__((format(printf, f, a)))\n#else\n#define js_likely(x)     (x)\n#define js_unlikely(x)   (x)\n#define js_force_inline  inline\n#define __js_printf_like(a, b)\n#endif\n\n#define JS_BOOL int\n\ntypedef struct JSRuntime JSRuntime;\ntypedef struct JSContext JSContext;\ntypedef struct JSObject JSObject;\ntypedef struct JSClass JSClass;\ntypedef uint32_t JSClassID;\ntypedef uint32_t JSAtom;\n\n#if INTPTR_MAX >= INT64_MAX\n#define JS_PTR64\n#define JS_PTR64_DEF(a) a\n#else\n#define JS_PTR64_DEF(a)\n#endif\n\n#ifndef JS_PTR64\n#define JS_NAN_BOXING\n#endif\n\nenum {\n    /* all tags with a reference count are negative */\n    JS_TAG_FIRST       = -11, /* first negative tag */\n    JS_TAG_BIG_DECIMAL = -11,\n    JS_TAG_BIG_INT     = -10,\n    JS_TAG_BIG_FLOAT   = -9,\n    JS_TAG_SYMBOL      = -8,\n    JS_TAG_STRING      = -7,\n    JS_TAG_MODULE      = -3, /* used internally */\n    JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */\n    JS_TAG_OBJECT      = -1,\n\n    JS_TAG_INT         = 0,\n    JS_TAG_BOOL        = 1,\n    JS_TAG_NULL        = 2,\n    JS_TAG_UNDEFINED   = 3,\n    JS_TAG_UNINITIALIZED = 4,\n    JS_TAG_CATCH_OFFSET = 5,\n    JS_TAG_EXCEPTION   = 6,\n    JS_TAG_FLOAT64     = 7,\n    /* any larger tag is FLOAT64 if JS_NAN_BOXING */\n};\n\ntypedef struct JSRefCountHeader {\n    int ref_count;\n} JSRefCountHeader;\n\n#define JS_FLOAT64_NAN NAN\n\n#ifdef CONFIG_CHECK_JSVALUE\n/* JSValue consistency : it is not possible to run the code in this\n   mode, but it is useful to detect simple reference counting\n   errors. It would be interesting to modify a static C analyzer to\n   handle specific annotations (clang has such annotations but only\n   for objective C) */\ntypedef struct __JSValue *JSValue;\ntypedef const struct __JSValue *JSValueConst;\n\n#define JS_VALUE_GET_TAG(v) (int)((uintptr_t)(v) & 0xf)\n/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */\n#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)\n#define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4)\n#define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v)\n#define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v)\n#define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf)\n\n#define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))\n#define JS_MKPTR(tag, p) (JSValue)((intptr_t)(p) | (tag))\n\n#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)\n\n#define JS_NAN JS_MKVAL(JS_TAG_FLOAT64, 1)\n\nstatic inline JSValue __JS_NewFloat64(JSContext *ctx, double d)\n{\n    return JS_MKVAL(JS_TAG_FLOAT64, (int)d);\n}\n\nstatic inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)\n{\n    return 0;\n}\n    \n#elif defined(JS_NAN_BOXING)\n\ntypedef uint64_t JSValue;\n\n#define JSValueConst JSValue\n\n#define JS_VALUE_GET_TAG(v) (int)((v) >> 32)\n#define JS_VALUE_GET_INT(v) (int)(v)\n#define JS_VALUE_GET_BOOL(v) (int)(v)\n#define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v)\n\n#define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))\n#define JS_MKPTR(tag, ptr) (((uint64_t)(tag) << 32) | (uintptr_t)(ptr))\n\n#define JS_FLOAT64_TAG_ADDEND (0x7ff80000 - JS_TAG_FIRST + 1) /* quiet NaN encoding */\n\nstatic inline double JS_VALUE_GET_FLOAT64(JSValue v)\n{\n    union {\n        JSValue v;\n        double d;\n    } u;\n    u.v = v;\n    u.v += (uint64_t)JS_FLOAT64_TAG_ADDEND << 32;\n    return u.d;\n}\n\n#define JS_NAN (0x7ff8000000000000 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32))\n\nstatic inline JSValue __JS_NewFloat64(JSContext *ctx, double d)\n{\n    union {\n        double d;\n        uint64_t u64;\n    } u;\n    JSValue v;\n    u.d = d;\n    /* normalize NaN */\n    if (js_unlikely((u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000))\n        v = JS_NAN;\n    else\n        v = u.u64 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32);\n    return v;\n}\n\n#define JS_TAG_IS_FLOAT64(tag) ((unsigned)((tag) - JS_TAG_FIRST) >= (JS_TAG_FLOAT64 - JS_TAG_FIRST))\n\n/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */\nstatic inline int JS_VALUE_GET_NORM_TAG(JSValue v)\n{\n    uint32_t tag;\n    tag = JS_VALUE_GET_TAG(v);\n    if (JS_TAG_IS_FLOAT64(tag))\n        return JS_TAG_FLOAT64;\n    else\n        return tag;\n}\n\nstatic inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)\n{\n    uint32_t tag;\n    tag = JS_VALUE_GET_TAG(v);\n    return tag == (JS_NAN >> 32);\n}\n    \n#else /* !JS_NAN_BOXING */\n\ntypedef union JSValueUnion {\n    int32_t int32;\n    double float64;\n    void *ptr;\n} JSValueUnion;\n\ntypedef struct JSValue {\n    JSValueUnion u;\n    int64_t tag;\n} JSValue;\n\n#define JSValueConst JSValue\n\n#define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag)\n/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */\n#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)\n#define JS_VALUE_GET_INT(v) ((v).u.int32)\n#define JS_VALUE_GET_BOOL(v) ((v).u.int32)\n#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)\n#define JS_VALUE_GET_PTR(v) ((v).u.ptr)\n\n#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }\n#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }\n\n#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)\n\n#define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }\n\nstatic inline JSValue __JS_NewFloat64(JSContext *ctx, double d)\n{\n    JSValue v;\n    v.tag = JS_TAG_FLOAT64;\n    v.u.float64 = d;\n    return v;\n}\n\nstatic inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)\n{\n    union {\n        double d;\n        uint64_t u64;\n    } u;\n    if (v.tag != JS_TAG_FLOAT64)\n        return 0;\n    u.d = v.u.float64;\n    return (u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000;\n}\n\n#endif /* !JS_NAN_BOXING */\n\n#define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)\n#define JS_VALUE_IS_BOTH_FLOAT(v1, v2) (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) && JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)))\n\n#define JS_VALUE_GET_OBJ(v) ((JSObject *)JS_VALUE_GET_PTR(v))\n#define JS_VALUE_GET_STRING(v) ((JSString *)JS_VALUE_GET_PTR(v))\n#define JS_VALUE_HAS_REF_COUNT(v) ((unsigned)JS_VALUE_GET_TAG(v) >= (unsigned)JS_TAG_FIRST)\n\n/* special values */\n#define JS_NULL      JS_MKVAL(JS_TAG_NULL, 0)\n#define JS_UNDEFINED JS_MKVAL(JS_TAG_UNDEFINED, 0)\n#define JS_FALSE     JS_MKVAL(JS_TAG_BOOL, 0)\n#define JS_TRUE      JS_MKVAL(JS_TAG_BOOL, 1)\n#define JS_EXCEPTION JS_MKVAL(JS_TAG_EXCEPTION, 0)\n#define JS_UNINITIALIZED JS_MKVAL(JS_TAG_UNINITIALIZED, 0)\n\n/* flags for object properties */\n#define JS_PROP_CONFIGURABLE  (1 << 0)\n#define JS_PROP_WRITABLE      (1 << 1)\n#define JS_PROP_ENUMERABLE    (1 << 2)\n#define JS_PROP_C_W_E         (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE | JS_PROP_ENUMERABLE)\n#define JS_PROP_LENGTH        (1 << 3) /* used internally in Arrays */\n#define JS_PROP_TMASK         (3 << 4) /* mask for NORMAL, GETSET, VARREF, AUTOINIT */\n#define JS_PROP_NORMAL         (0 << 4)\n#define JS_PROP_GETSET         (1 << 4)\n#define JS_PROP_VARREF         (2 << 4) /* used internally */\n#define JS_PROP_AUTOINIT       (3 << 4) /* used internally */\n\n/* flags for JS_DefineProperty */\n#define JS_PROP_HAS_SHIFT        8\n#define JS_PROP_HAS_CONFIGURABLE (1 << 8)\n#define JS_PROP_HAS_WRITABLE     (1 << 9)\n#define JS_PROP_HAS_ENUMERABLE   (1 << 10)\n#define JS_PROP_HAS_GET          (1 << 11)\n#define JS_PROP_HAS_SET          (1 << 12)\n#define JS_PROP_HAS_VALUE        (1 << 13)\n\n/* throw an exception if false would be returned\n   (JS_DefineProperty/JS_SetProperty) */\n#define JS_PROP_THROW            (1 << 14)\n/* throw an exception if false would be returned in strict mode\n   (JS_SetProperty) */\n#define JS_PROP_THROW_STRICT     (1 << 15)\n\n#define JS_PROP_NO_ADD           (1 << 16) /* internal use */\n#define JS_PROP_NO_EXOTIC        (1 << 17) /* internal use */\n\n#define JS_DEFAULT_STACK_SIZE (256 * 1024)\n\n/* JS_Eval() flags */\n#define JS_EVAL_TYPE_GLOBAL   (0 << 0) /* global code (default) */\n#define JS_EVAL_TYPE_MODULE   (1 << 0) /* module code */\n#define JS_EVAL_TYPE_DIRECT   (2 << 0) /* direct call (internal use) */\n#define JS_EVAL_TYPE_INDIRECT (3 << 0) /* indirect call (internal use) */\n#define JS_EVAL_TYPE_MASK     (3 << 0)\n\n#define JS_EVAL_FLAG_STRICT   (1 << 3) /* force 'strict' mode */\n#define JS_EVAL_FLAG_STRIP    (1 << 4) /* force 'strip' mode */\n/* compile but do not run. The result is an object with a\n   JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed\n   with JS_EvalFunction(). */\n#define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5)\n/* don't include the stack frames before this eval in the Error() backtraces */\n#define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6)\n\ntypedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);\ntypedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);\ntypedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data);\n\ntypedef struct JSMallocState {\n    size_t malloc_count;\n    size_t malloc_size;\n    size_t malloc_limit;\n    void *opaque; /* user opaque */\n} JSMallocState;\n\ntypedef struct JSMallocFunctions {\n    void *(*js_malloc)(JSMallocState *s, size_t size);\n    void (*js_free)(JSMallocState *s, void *ptr);\n    void *(*js_realloc)(JSMallocState *s, void *ptr, size_t size);\n    size_t (*js_malloc_usable_size)(const void *ptr);\n} JSMallocFunctions;\n\ntypedef struct JSGCObjectHeader JSGCObjectHeader;\n\nJSRuntime *JS_NewRuntime(void);\n/* info lifetime must exceed that of rt */\nvoid JS_SetRuntimeInfo(JSRuntime *rt, const char *info);\nvoid JS_SetMemoryLimit(JSRuntime *rt, size_t limit);\nvoid JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold);\nvoid JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size);\nJSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque);\nvoid JS_FreeRuntime(JSRuntime *rt);\nvoid *JS_GetRuntimeOpaque(JSRuntime *rt);\nvoid JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque);\ntypedef void JS_MarkFunc(JSRuntime *rt, JSGCObjectHeader *gp);\nvoid JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func);\nvoid JS_RunGC(JSRuntime *rt);\nJS_BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj);\n\nJSContext *JS_NewContext(JSRuntime *rt);\nvoid JS_FreeContext(JSContext *s);\nJSContext *JS_DupContext(JSContext *ctx);\nvoid *JS_GetContextOpaque(JSContext *ctx);\nvoid JS_SetContextOpaque(JSContext *ctx, void *opaque);\nJSRuntime *JS_GetRuntime(JSContext *ctx);\nvoid JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj);\nJSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id);\n\n/* the following functions are used to select the intrinsic object to\n   save memory */\nJSContext *JS_NewContextRaw(JSRuntime *rt);\nvoid JS_AddIntrinsicBaseObjects(JSContext *ctx);\nvoid JS_AddIntrinsicDate(JSContext *ctx);\nvoid JS_AddIntrinsicEval(JSContext *ctx);\nvoid JS_AddIntrinsicStringNormalize(JSContext *ctx);\nvoid JS_AddIntrinsicRegExpCompiler(JSContext *ctx);\nvoid JS_AddIntrinsicRegExp(JSContext *ctx);\nvoid JS_AddIntrinsicJSON(JSContext *ctx);\nvoid JS_AddIntrinsicProxy(JSContext *ctx);\nvoid JS_AddIntrinsicMapSet(JSContext *ctx);\nvoid JS_AddIntrinsicTypedArrays(JSContext *ctx);\nvoid JS_AddIntrinsicPromise(JSContext *ctx);\nvoid JS_AddIntrinsicBigInt(JSContext *ctx);\nvoid JS_AddIntrinsicBigFloat(JSContext *ctx);\nvoid JS_AddIntrinsicBigDecimal(JSContext *ctx);\n/* enable operator overloading */\nvoid JS_AddIntrinsicOperators(JSContext *ctx);\n/* enable \"use math\" */\nvoid JS_EnableBignumExt(JSContext *ctx, JS_BOOL enable);\n\nJSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,\n                                 int argc, JSValueConst *argv);\n\nvoid *js_malloc_rt(JSRuntime *rt, size_t size);\nvoid js_free_rt(JSRuntime *rt, void *ptr);\nvoid *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size);\nsize_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr);\nvoid *js_mallocz_rt(JSRuntime *rt, size_t size);\n\nvoid *js_malloc(JSContext *ctx, size_t size);\nvoid js_free(JSContext *ctx, void *ptr);\nvoid *js_realloc(JSContext *ctx, void *ptr, size_t size);\nsize_t js_malloc_usable_size(JSContext *ctx, const void *ptr);\nvoid *js_realloc2(JSContext *ctx, void *ptr, size_t size, size_t *pslack);\nvoid *js_mallocz(JSContext *ctx, size_t size);\nchar *js_strdup(JSContext *ctx, const char *str);\nchar *js_strndup(JSContext *ctx, const char *s, size_t n);\n\ntypedef struct JSMemoryUsage {\n    int64_t malloc_size, malloc_limit, memory_used_size;\n    int64_t malloc_count;\n    int64_t memory_used_count;\n    int64_t atom_count, atom_size;\n    int64_t str_count, str_size;\n    int64_t obj_count, obj_size;\n    int64_t prop_count, prop_size;\n    int64_t shape_count, shape_size;\n    int64_t js_func_count, js_func_size, js_func_code_size;\n    int64_t js_func_pc2line_count, js_func_pc2line_size;\n    int64_t c_func_count, array_count;\n    int64_t fast_array_count, fast_array_elements;\n    int64_t binary_object_count, binary_object_size;\n} JSMemoryUsage;\n\nvoid JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s);\nvoid JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt);\n\n/* atom support */\nJSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len);\nJSAtom JS_NewAtom(JSContext *ctx, const char *str);\nJSAtom JS_NewAtomUInt32(JSContext *ctx, uint32_t n);\nJSAtom JS_DupAtom(JSContext *ctx, JSAtom v);\nvoid JS_FreeAtom(JSContext *ctx, JSAtom v);\nvoid JS_FreeAtomRT(JSRuntime *rt, JSAtom v);\nJSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);\nJSValue JS_AtomToString(JSContext *ctx, JSAtom atom);\nconst char *JS_AtomToCString(JSContext *ctx, JSAtom atom);\nJSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);\n\n/* object class support */\n\ntypedef struct JSPropertyEnum {\n    JS_BOOL is_enumerable;\n    JSAtom atom;\n} JSPropertyEnum;\n\ntypedef struct JSPropertyDescriptor {\n    int flags;\n    JSValue value;\n    JSValue getter;\n    JSValue setter;\n} JSPropertyDescriptor;\n\ntypedef struct JSClassExoticMethods {\n    /* Return -1 if exception (can only happen in case of Proxy object),\n       FALSE if the property does not exists, TRUE if it exists. If 1 is\n       returned, the property descriptor 'desc' is filled if != NULL. */\n    int (*get_own_property)(JSContext *ctx, JSPropertyDescriptor *desc,\n                             JSValueConst obj, JSAtom prop);\n    /* '*ptab' should hold the '*plen' property keys. Return 0 if OK,\n       -1 if exception. The 'is_enumerable' field is ignored.\n    */\n    int (*get_own_property_names)(JSContext *ctx, JSPropertyEnum **ptab,\n                                  uint32_t *plen,\n                                  JSValueConst obj);\n    /* return < 0 if exception, or TRUE/FALSE */\n    int (*delete_property)(JSContext *ctx, JSValueConst obj, JSAtom prop);\n    /* return < 0 if exception or TRUE/FALSE */\n    int (*define_own_property)(JSContext *ctx, JSValueConst this_obj,\n                               JSAtom prop, JSValueConst val,\n                               JSValueConst getter, JSValueConst setter,\n                               int flags);\n    /* The following methods can be emulated with the previous ones,\n       so they are usually not needed */\n    /* return < 0 if exception or TRUE/FALSE */\n    int (*has_property)(JSContext *ctx, JSValueConst obj, JSAtom atom);\n    JSValue (*get_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,\n                            JSValueConst receiver);\n    /* return < 0 if exception or TRUE/FALSE */\n    int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,\n                        JSValueConst value, JSValueConst receiver, int flags);\n} JSClassExoticMethods;\n\ntypedef void JSClassFinalizer(JSRuntime *rt, JSValue val);\ntypedef void JSClassGCMark(JSRuntime *rt, JSValueConst val,\n                           JS_MarkFunc *mark_func);\n#define JS_CALL_FLAG_CONSTRUCTOR (1 << 0)\ntypedef JSValue JSClassCall(JSContext *ctx, JSValueConst func_obj,\n                            JSValueConst this_val, int argc, JSValueConst *argv,\n                            int flags);\n\ntypedef struct JSClassDef {\n    const char *class_name;\n    JSClassFinalizer *finalizer;\n    JSClassGCMark *gc_mark;\n    /* if call != NULL, the object is a function. If (flags &\n       JS_CALL_FLAG_CONSTRUCTOR) != 0, the function is called as a\n       constructor. In this case, 'this_val' is new.target. A\n       constructor call only happens if the object constructor bit is\n       set (see JS_SetConstructorBit()). */\n    JSClassCall *call;\n    /* XXX: suppress this indirection ? It is here only to save memory\n       because only a few classes need these methods */\n    JSClassExoticMethods *exotic;\n} JSClassDef;\n\nJSClassID JS_NewClassID(JSClassID *pclass_id);\nint JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def);\nint JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);\n\n/* value handling */\n\nstatic js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)\n{\n    return JS_MKVAL(JS_TAG_BOOL, (val != 0));\n}\n\nstatic js_force_inline JSValue JS_NewInt32(JSContext *ctx, int32_t val)\n{\n    return JS_MKVAL(JS_TAG_INT, val);\n}\n\nstatic js_force_inline JSValue JS_NewCatchOffset(JSContext *ctx, int32_t val)\n{\n    return JS_MKVAL(JS_TAG_CATCH_OFFSET, val);\n}\n\nstatic js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val)\n{\n    JSValue v;\n    if (val == (int32_t)val) {\n        v = JS_NewInt32(ctx, val);\n    } else {\n        v = __JS_NewFloat64(ctx, val);\n    }\n    return v;\n}\n\nstatic js_force_inline JSValue JS_NewUint32(JSContext *ctx, uint32_t val)\n{\n    JSValue v;\n    if (val <= 0x7fffffff) {\n        v = JS_NewInt32(ctx, val);\n    } else {\n        v = __JS_NewFloat64(ctx, val);\n    }\n    return v;\n}\n\nJSValue JS_NewBigInt64(JSContext *ctx, int64_t v);\nJSValue JS_NewBigUint64(JSContext *ctx, uint64_t v);\n\nstatic js_force_inline JSValue JS_NewFloat64(JSContext *ctx, double d)\n{\n    JSValue v;\n    int32_t val;\n    union {\n        double d;\n        uint64_t u;\n    } u, t;\n    u.d = d;\n    val = (int32_t)d;\n    t.d = val;\n    /* -0 cannot be represented as integer, so we compare the bit\n        representation */\n    if (u.u == t.u) {\n        v = JS_MKVAL(JS_TAG_INT, val);\n    } else {\n        v = __JS_NewFloat64(ctx, d);\n    }\n    return v;\n}\n\nstatic inline JS_BOOL JS_IsNumber(JSValueConst v)\n{\n    int tag = JS_VALUE_GET_TAG(v);\n    return tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag);\n}\n\nstatic inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValueConst v)\n{\n    int tag = JS_VALUE_GET_TAG(v);\n    return tag == JS_TAG_BIG_INT;\n}\n\nstatic inline JS_BOOL JS_IsBigFloat(JSValueConst v)\n{\n    int tag = JS_VALUE_GET_TAG(v);\n    return tag == JS_TAG_BIG_FLOAT;\n}\n\nstatic inline JS_BOOL JS_IsBigDecimal(JSValueConst v)\n{\n    int tag = JS_VALUE_GET_TAG(v);\n    return tag == JS_TAG_BIG_DECIMAL;\n}\n\nstatic inline JS_BOOL JS_IsBool(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_BOOL;\n}\n\nstatic inline JS_BOOL JS_IsNull(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_NULL;\n}\n\nstatic inline JS_BOOL JS_IsUndefined(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED;\n}\n\nstatic inline JS_BOOL JS_IsException(JSValueConst v)\n{\n    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);\n}\n\nstatic inline JS_BOOL JS_IsUninitialized(JSValueConst v)\n{\n    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_UNINITIALIZED);\n}\n\nstatic inline JS_BOOL JS_IsString(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_STRING;\n}\n\nstatic inline JS_BOOL JS_IsSymbol(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_SYMBOL;\n}\n\nstatic inline JS_BOOL JS_IsObject(JSValueConst v)\n{\n    return JS_VALUE_GET_TAG(v) == JS_TAG_OBJECT;\n}\n\nJSValue JS_Throw(JSContext *ctx, JSValue obj);\nJSValue JS_GetException(JSContext *ctx);\nJS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);\nvoid JS_ResetUncatchableError(JSContext *ctx);\nJSValue JS_NewError(JSContext *ctx);\nJSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);\nJSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);\nJSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...);\nJSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...);\nJSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);\nJSValue JS_ThrowOutOfMemory(JSContext *ctx);\n\nvoid __JS_FreeValue(JSContext *ctx, JSValue v);\nstatic inline void JS_FreeValue(JSContext *ctx, JSValue v)\n{\n    if (JS_VALUE_HAS_REF_COUNT(v)) {\n        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);\n        if (--p->ref_count <= 0) {\n            __JS_FreeValue(ctx, v);\n        }\n    }\n}\nvoid __JS_FreeValueRT(JSRuntime *rt, JSValue v);\nstatic inline void JS_FreeValueRT(JSRuntime *rt, JSValue v)\n{\n    if (JS_VALUE_HAS_REF_COUNT(v)) {\n        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);\n        if (--p->ref_count <= 0) {\n            __JS_FreeValueRT(rt, v);\n        }\n    }\n}\n\nstatic inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)\n{\n    if (JS_VALUE_HAS_REF_COUNT(v)) {\n        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);\n        p->ref_count++;\n    }\n    return (JSValue)v;\n}\n\nstatic inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)\n{\n    if (JS_VALUE_HAS_REF_COUNT(v)) {\n        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);\n        p->ref_count++;\n    }\n    return (JSValue)v;\n}\n\nint JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */\nint JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);\nstatic inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)\n{\n    return JS_ToInt32(ctx, (int32_t*)pres, val);\n}\nint JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val);\nint JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val);\nint JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val);\n/* return an exception if 'val' is a Number */\nint JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val);\n/* same as JS_ToInt64() but allow BigInt */\nint JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);\n\nJSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);\nJSValue JS_NewString(JSContext *ctx, const char *str);\nJSValue JS_NewAtomString(JSContext *ctx, const char *str);\nJSValue JS_ToString(JSContext *ctx, JSValueConst val);\nJSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val);\nconst char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, JS_BOOL cesu8);\nstatic inline const char *JS_ToCStringLen(JSContext *ctx, size_t *plen, JSValueConst val1)\n{\n    return JS_ToCStringLen2(ctx, plen, val1, 0);\n}\nstatic inline const char *JS_ToCString(JSContext *ctx, JSValueConst val1)\n{\n    return JS_ToCStringLen2(ctx, NULL, val1, 0);\n}\nvoid JS_FreeCString(JSContext *ctx, const char *ptr);\n\nJSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto, JSClassID class_id);\nJSValue JS_NewObjectClass(JSContext *ctx, int class_id);\nJSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto);\nJSValue JS_NewObject(JSContext *ctx);\n\nJS_BOOL JS_IsFunction(JSContext* ctx, JSValueConst val);\nJS_BOOL JS_IsConstructor(JSContext* ctx, JSValueConst val);\nJS_BOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, JS_BOOL val);\n\nJSValue JS_NewArray(JSContext *ctx);\nint JS_IsArray(JSContext *ctx, JSValueConst val);\n\nJSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,\n                               JSAtom prop, JSValueConst receiver,\n                               JS_BOOL throw_ref_error);\nstatic js_force_inline JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_obj,\n                                              JSAtom prop)\n{\n    return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0);\n}\nJSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,\n                          const char *prop);\nJSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,\n                             uint32_t idx);\n\nint JS_SetPropertyInternal(JSContext *ctx, JSValueConst this_obj,\n                           JSAtom prop, JSValue val,\n                           int flags);\nstatic inline int JS_SetProperty(JSContext *ctx, JSValueConst this_obj,\n                                 JSAtom prop, JSValue val)\n{\n    return JS_SetPropertyInternal(ctx, this_obj, prop, val, JS_PROP_THROW);\n}\nint JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,\n                         uint32_t idx, JSValue val);\nint JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,\n                        int64_t idx, JSValue val);\nint JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,\n                      const char *prop, JSValue val);\nint JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);\nint JS_IsExtensible(JSContext *ctx, JSValueConst obj);\nint JS_PreventExtensions(JSContext *ctx, JSValueConst obj);\nint JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags);\nint JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);\nJSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);\n\n#define JS_GPN_STRING_MASK  (1 << 0)\n#define JS_GPN_SYMBOL_MASK  (1 << 1)\n#define JS_GPN_PRIVATE_MASK (1 << 2)\n/* only include the enumerable properties */\n#define JS_GPN_ENUM_ONLY    (1 << 4)\n/* set theJSPropertyEnum.is_enumerable field */\n#define JS_GPN_SET_ENUM     (1 << 5)\n\nint JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,\n                           uint32_t *plen, JSValueConst obj, int flags);\nint JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,\n                      JSValueConst obj, JSAtom prop);\n\nJSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj,\n                int argc, JSValueConst *argv);\nJSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,\n                  int argc, JSValueConst *argv);\nJSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,\n                           int argc, JSValueConst *argv);\nJSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,\n                            JSValueConst new_target,\n                            int argc, JSValueConst *argv);\nJS_BOOL JS_DetectModule(const char *input, size_t input_len);\n/* 'input' must be zero terminated i.e. input[input_len] = '\\0'. */\nJSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,\n                const char *filename, int eval_flags);\nJSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj);\nJSValue JS_GetGlobalObject(JSContext *ctx);\nint JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj);\nint JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,\n                      JSAtom prop, JSValueConst val,\n                      JSValueConst getter, JSValueConst setter, int flags);\nint JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,\n                           JSAtom prop, JSValue val, int flags);\nint JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,\n                                 uint32_t idx, JSValue val, int flags);\nint JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,\n                              const char *prop, JSValue val, int flags);\nint JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,\n                            JSAtom prop, JSValue getter, JSValue setter,\n                            int flags);\nvoid JS_SetOpaque(JSValue obj, void *opaque);\nvoid *JS_GetOpaque(JSValueConst obj, JSClassID class_id);\nvoid *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);\n\n/* 'buf' must be zero terminated i.e. buf[buf_len] = '\\0'. */\nJSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,\n                     const char *filename);\n#define JS_PARSE_JSON_EXT (1 << 0) /* allow extended JSON */\nJSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,\n                      const char *filename, int flags);\nJSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,\n                         JSValueConst replacer, JSValueConst space0);\n\ntypedef void JSFreeArrayBufferDataFunc(JSRuntime *rt, void *opaque, void *ptr);\nJSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,\n                          JSFreeArrayBufferDataFunc *free_func, void *opaque,\n                          JS_BOOL is_shared);\nJSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);\nvoid JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);\nuint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);\nJSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,\n                               size_t *pbyte_offset,\n                               size_t *pbyte_length,\n                               size_t *pbytes_per_element);\ntypedef struct {\n    void *(*sab_alloc)(void *opaque, size_t size);\n    void (*sab_free)(void *opaque, void *ptr);\n    void (*sab_dup)(void *opaque, void *ptr);\n    void *sab_opaque;\n} JSSharedArrayBufferFunctions;\nvoid JS_SetSharedArrayBufferFunctions(JSRuntime *rt,\n                                      const JSSharedArrayBufferFunctions *sf);\n\nJSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);\n\n/* is_handled = TRUE means that the rejection is handled */\ntypedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValueConst promise,\n                                           JSValueConst reason,\n                                           JS_BOOL is_handled, void *opaque);\nvoid JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);\n\n/* return != 0 if the JS code needs to be interrupted */\ntypedef int JSInterruptHandler(JSRuntime *rt, void *opaque);\nvoid JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);\n/* if can_block is TRUE, Atomics.wait() can be used */\nvoid JS_SetCanBlock(JSRuntime *rt, JS_BOOL can_block);\n\ntypedef struct JSModuleDef JSModuleDef;\n\n/* return the module specifier (allocated with js_malloc()) or NULL if\n   exception */\ntypedef char *JSModuleNormalizeFunc(JSContext *ctx,\n                                    const char *module_base_name,\n                                    const char *module_name, void *opaque);\ntypedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,\n                                        const char *module_name, void *opaque);\n\n/* module_normalize = NULL is allowed and invokes the default module\n   filename normalizer */\nvoid JS_SetModuleLoaderFunc(JSRuntime *rt,\n                            JSModuleNormalizeFunc *module_normalize,\n                            JSModuleLoaderFunc *module_loader, void *opaque);\n/* return the import.meta object of a module */\nJSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);\nJSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);\n\n/* JS Job support */\n\ntypedef JSValue JSJobFunc(JSContext *ctx, int argc, JSValueConst *argv);\nint JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, int argc, JSValueConst *argv);\n\nJS_BOOL JS_IsJobPending(JSRuntime *rt);\nint JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);\n\n/* Object Writer/Reader (currently only used to handle precompiled code) */\n#define JS_WRITE_OBJ_BYTECODE  (1 << 0) /* allow function/module */\n#define JS_WRITE_OBJ_BSWAP     (1 << 1) /* byte swapped output */\n#define JS_WRITE_OBJ_SAB       (1 << 2) /* allow SharedArrayBuffer */\n#define JS_WRITE_OBJ_REFERENCE (1 << 3) /* allow object references to\n                                           encode arbitrary object\n                                           graph */\nuint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj,\n                        int flags);\nuint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,\n                         int flags, uint8_t ***psab_tab, size_t *psab_tab_len);\n\n#define JS_READ_OBJ_BYTECODE  (1 << 0) /* allow function/module */\n#define JS_READ_OBJ_ROM_DATA  (1 << 1) /* avoid duplicating 'buf' data */\n#define JS_READ_OBJ_SAB       (1 << 2) /* allow SharedArrayBuffer */\n#define JS_READ_OBJ_REFERENCE (1 << 3) /* allow object references */\nJSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,\n                      int flags);\n\n/* load the dependencies of the module 'obj'. Useful when JS_ReadObject()\n   returns a module. */\nint JS_ResolveModule(JSContext *ctx, JSValueConst obj);\n\n/* C function definition */\ntypedef enum JSCFunctionEnum {  /* XXX: should rename for namespace isolation */\n    JS_CFUNC_generic,\n    JS_CFUNC_generic_magic,\n    JS_CFUNC_constructor,\n    JS_CFUNC_constructor_magic,\n    JS_CFUNC_constructor_or_func,\n    JS_CFUNC_constructor_or_func_magic,\n    JS_CFUNC_f_f,\n    JS_CFUNC_f_f_f,\n    JS_CFUNC_getter,\n    JS_CFUNC_setter,\n    JS_CFUNC_getter_magic,\n    JS_CFUNC_setter_magic,\n    JS_CFUNC_iterator_next,\n} JSCFunctionEnum;\n\ntypedef union JSCFunctionType {\n    JSCFunction *generic;\n    JSValue (*generic_magic)(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);\n    JSCFunction *constructor;\n    JSValue (*constructor_magic)(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic);\n    JSCFunction *constructor_or_func;\n    double (*f_f)(double);\n    double (*f_f_f)(double, double);\n    JSValue (*getter)(JSContext *ctx, JSValueConst this_val);\n    JSValue (*setter)(JSContext *ctx, JSValueConst this_val, JSValueConst val);\n    JSValue (*getter_magic)(JSContext *ctx, JSValueConst this_val, int magic);\n    JSValue (*setter_magic)(JSContext *ctx, JSValueConst this_val, JSValueConst val, int magic);\n    JSValue (*iterator_next)(JSContext *ctx, JSValueConst this_val,\n                             int argc, JSValueConst *argv, int *pdone, int magic);\n} JSCFunctionType;\n\nJSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,\n                         const char *name,\n                         int length, JSCFunctionEnum cproto, int magic);\nJSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,\n                            int length, int magic, int data_len,\n                            JSValueConst *data);\n\nstatic inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name,\n                                      int length)\n{\n    return JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_generic, 0);\n}\n\nstatic inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *func,\n                                           const char *name,\n                                           int length, JSCFunctionEnum cproto, int magic)\n{\n    return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);\n}\nvoid JS_SetConstructor(JSContext *ctx, JSValueConst func_obj, \n                       JSValueConst proto);\n\n/* C property definition */\n\ntypedef struct JSCFunctionListEntry {\n    const char *name;\n    uint8_t prop_flags;\n    uint8_t def_type;\n    int16_t magic;\n    union {\n        struct {\n            uint8_t length; /* XXX: should move outside union */\n            uint8_t cproto; /* XXX: should move outside union */\n            JSCFunctionType cfunc;\n        } func;\n        struct {\n            JSCFunctionType get;\n            JSCFunctionType set;\n        } getset;\n        struct {\n            const char *name;\n            int base;\n        } alias;\n        struct {\n            const struct JSCFunctionListEntry *tab;\n            int len;\n        } prop_list;\n        const char *str;\n        int32_t i32;\n        int64_t i64;\n        double f64;\n    } u;\n} JSCFunctionListEntry;\n\n#define JS_DEF_CFUNC          0\n#define JS_DEF_CGETSET        1\n#define JS_DEF_CGETSET_MAGIC  2\n#define JS_DEF_PROP_STRING    3\n#define JS_DEF_PROP_INT32     4\n#define JS_DEF_PROP_INT64     5\n#define JS_DEF_PROP_DOUBLE    6\n#define JS_DEF_PROP_UNDEFINED 7\n#define JS_DEF_OBJECT         8\n#define JS_DEF_ALIAS          9\n\n/* Note: c++ does not like nested designators */\n#define JS_CFUNC_DEF(name, length, func1) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, 0, .u = { .func = { length, JS_CFUNC_generic, { .generic = func1 } } } }\n#define JS_CFUNC_MAGIC_DEF(name, length, func1, magic) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, magic, .u = { .func = { length, JS_CFUNC_generic_magic, { .generic_magic = func1 } } } }\n#define JS_CFUNC_SPECIAL_DEF(name, length, cproto, func1) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, 0, .u = { .func = { length, JS_CFUNC_ ## cproto, { .cproto = func1 } } } }\n#define JS_ITERATOR_NEXT_DEF(name, length, func1, magic) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, magic, .u = { .func = { length, JS_CFUNC_iterator_next, { .iterator_next = func1 } } } }\n#define JS_CGETSET_DEF(name, fgetter, fsetter) { name, JS_PROP_CONFIGURABLE, JS_DEF_CGETSET, 0, .u = { .getset = { .get = { .getter = fgetter }, .set = { .setter = fsetter } } } }\n#define JS_CGETSET_MAGIC_DEF(name, fgetter, fsetter, magic) { name, JS_PROP_CONFIGURABLE, JS_DEF_CGETSET_MAGIC, magic, .u = { .getset = { .get = { .getter_magic = fgetter }, .set = { .setter_magic = fsetter } } } }\n#define JS_PROP_STRING_DEF(name, cstr, prop_flags) { name, prop_flags, JS_DEF_PROP_STRING, 0, .u = { .str = cstr } }\n#define JS_PROP_INT32_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT32, 0, .u = { .i32 = val } }\n#define JS_PROP_INT64_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT64, 0, .u = { .i64 = val } }\n#define JS_PROP_DOUBLE_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, .u = { .f64 = val } }\n#define JS_PROP_UNDEFINED_DEF(name, prop_flags) { name, prop_flags, JS_DEF_PROP_UNDEFINED, 0, .u = { .i32 = 0 } }\n#define JS_OBJECT_DEF(name, tab, len, prop_flags) { name, prop_flags, JS_DEF_OBJECT, 0, .u = { .prop_list = { tab, len } } }\n#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }\n#define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }\n\nvoid JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,\n                                const JSCFunctionListEntry *tab,\n                                int len);\n\n/* C module definition */\n\ntypedef int JSModuleInitFunc(JSContext *ctx, JSModuleDef *m);\n\nJSModuleDef *JS_NewCModule(JSContext *ctx, const char *name_str,\n                           JSModuleInitFunc *func);\n/* can only be called before the module is instantiated */\nint JS_AddModuleExport(JSContext *ctx, JSModuleDef *m, const char *name_str);\nint JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m,\n                           const JSCFunctionListEntry *tab, int len);\n/* can only be called after the module is instantiated */\nint JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,\n                       JSValue val);\nint JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,\n                           const JSCFunctionListEntry *tab, int len);\n\n#undef js_unlikely\n#undef js_force_inline\n\n#ifdef __cplusplus\n} /* extern \"C\" { */\n#endif\n\n#endif /* QUICKJS_H */\n"
  },
  {
    "path": "quickjs_test.go",
    "content": "package quickjs\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"github.com/stretchr/testify/require\"\n\tstdruntime \"runtime\"\n\t\"sync\"\n\t\"testing\"\n)\n\nfunc TestObject(t *testing.T) {\n\truntime := NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\ttest := context.Object()\n\ttest.Set(\"A\", context.String(\"String A\"))\n\ttest.Set(\"B\", context.String(\"String B\"))\n\ttest.Set(\"C\", context.String(\"String C\"))\n\tcontext.Globals().Set(\"test\", test)\n\n\tresult, err := context.Eval(`Object.keys(test).map(key => test[key]).join(\" \")`)\n\trequire.NoError(t, err)\n\tdefer result.Free()\n\n\trequire.EqualValues(t, \"String A String B String C\", result.String())\n}\n\nfunc TestArray(t *testing.T) {\n\truntime := NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\ttest := context.Array()\n\tfor i := int64(0); i < 3; i++ {\n\t\ttest.SetByInt64(i, context.String(fmt.Sprintf(\"test %d\", i)))\n\t}\n\tfor i := int64(0); i < test.Len(); i++ {\n\t\trequire.EqualValues(t, fmt.Sprintf(\"test %d\", i), test.GetByUint32(uint32(i)).String())\n\t}\n\n\tcontext.Globals().Set(\"test\", test)\n\n\tresult, err := context.Eval(`test.map(v => v.toUpperCase())`)\n\trequire.NoError(t, err)\n\tdefer result.Free()\n\n\trequire.EqualValues(t, `TEST 0,TEST 1,TEST 2`, result.String())\n}\n\nfunc TestBadSyntax(t *testing.T) {\n\truntime := NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\t_, err := context.Eval(`\"bad syntax'`)\n\trequire.Error(t, err)\n}\n\nfunc TestFunctionThrowError(t *testing.T) {\n\texpected := errors.New(\"expected error\")\n\n\truntime := NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\tcontext.Globals().SetFunction(\"A\", func(ctx *Context, this Value, args []Value) Value {\n\t\treturn ctx.ThrowError(expected)\n\t})\n\n\t_, actual := context.Eval(\"A()\")\n\trequire.Error(t, actual)\n\trequire.EqualValues(t, \"Error: \"+expected.Error(), actual.Error())\n}\n\nfunc TestFunction(t *testing.T) {\n\truntime := NewRuntime()\n\tdefer runtime.Free()\n\n\tcontext := runtime.NewContext()\n\tdefer context.Free()\n\n\tA := make(chan struct{})\n\tB := make(chan struct{})\n\n\tcontext.Globals().SetFunction(\"A\", func(ctx *Context, this Value, args []Value) Value {\n\t\trequire.Len(t, args, 4)\n\t\trequire.True(t, args[0].IsString() && args[0].String() == \"hello world!\")\n\t\trequire.True(t, args[1].IsNumber() && args[1].Int32() == 1)\n\t\trequire.True(t, args[2].IsNumber() && args[2].Int64() == 8)\n\t\trequire.True(t, args[3].IsNull())\n\n\t\tclose(A)\n\n\t\treturn ctx.String(\"A says hello\")\n\t})\n\n\tcontext.Globals().SetFunction(\"B\", func(ctx *Context, this Value, args []Value) Value {\n\t\trequire.Len(t, args, 0)\n\n\t\tclose(B)\n\n\t\treturn ctx.Float64(256)\n\t})\n\n\tresult, err := context.Eval(`A(\"hello world!\", 1, 2 ** 3, null)`)\n\trequire.NoError(t, err)\n\tdefer result.Free()\n\n\trequire.True(t, result.IsString() && result.String() == \"A says hello\")\n\t<-A\n\n\tresult, err = context.Eval(`B()`)\n\trequire.NoError(t, err)\n\tdefer result.Free()\n\n\trequire.True(t, result.IsNumber() && result.Uint32() == 256)\n\t<-B\n}\n\nfunc TestConcurrency(t *testing.T) {\n\tn := 32\n\tm := 10000\n\n\tvar wg sync.WaitGroup\n\twg.Add(n)\n\n\treq := make(chan struct{}, n)\n\tres := make(chan int64, m)\n\n\tfor i := 0; i < n; i++ {\n\t\tgo func() {\n\t\t\tstdruntime.LockOSThread()\n\n\t\t\tdefer wg.Done()\n\n\t\t\truntime := NewRuntime()\n\t\t\tdefer runtime.Free()\n\n\t\t\tcontext := runtime.NewContext()\n\t\t\tdefer context.Free()\n\n\t\t\tfor range req {\n\t\t\t\tresult, err := context.Eval(`new Date().getTime()`)\n\t\t\t\trequire.NoError(t, err)\n\n\t\t\t\tres <- result.Int64()\n\n\t\t\t\tresult.Free()\n\t\t\t}\n\t\t}()\n\t}\n\n\tfor i := 0; i < m; i++ {\n\t\treq <- struct{}{}\n\t}\n\tclose(req)\n\n\twg.Wait()\n\n\tfor i := 0; i < m; i++ {\n\t\t<-res\n\t}\n}\n"
  },
  {
    "path": "version.h",
    "content": "#ifndef _GUARD_H_PORT_H_\n#define _GUARD_H_PORT_H_\n\n#define CONFIG_VERSION \"2020-07-05\"\n\n#endif\n"
  }
]