@onflow/cadence-parser 0.26.0 → 1.0.0-preview.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cadence-parser.wasm +0 -0
- package/dist/cjs/go.js +1 -1
- package/dist/cjs/go.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.mjs +689 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/types/go.d.ts +1 -1
- package/package.json +5 -4
- package/dist/esm/go.js +0 -495
- package/dist/esm/go.js.map +0 -1
- package/dist/esm/index.js +0 -100
- package/dist/esm/index.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../node_modules/global/window.js", "../../node_modules/get-random-values/index.js", "../../src/go.js", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["var win;\n\nif (typeof window !== \"undefined\") {\n win = window;\n} else if (typeof global !== \"undefined\") {\n win = global;\n} else if (typeof self !== \"undefined\"){\n win = self;\n} else {\n win = {};\n}\n\nmodule.exports = win;\n", "/* eslint-disable no-var, operator-linebreak */\n\nvar window = require('global/window');\nvar nodeCrypto = require('crypto');\n\n/**\n * @template {ArrayBufferView | null} T\n * @param {T} buf\n * @returns {T}\n */\nfunction getRandomValues(buf) {\n if (window.crypto && window.crypto.getRandomValues) {\n return window.crypto.getRandomValues(buf);\n }\n if (typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') {\n return window.msCrypto.getRandomValues(buf);\n }\n if (nodeCrypto.randomBytes) {\n if (!(buf instanceof Uint8Array)) {\n throw new TypeError('expected Uint8Array');\n }\n if (buf.length > 65536) {\n var e = new Error();\n // @ts-expect-error\n e.code = 22;\n e.message = 'Failed to execute \\'getRandomValues\\' on \\'Crypto\\': The ' +\n 'ArrayBufferView\\'s byte length (' + buf.length + ') exceeds the ' +\n 'number of bytes of entropy available via this API (65536).';\n e.name = 'QuotaExceededError';\n throw e;\n }\n var bytes = nodeCrypto.randomBytes(buf.length);\n buf.set(bytes);\n return buf;\n }\n else {\n throw new Error('No secure random number generator available.');\n }\n}\n\nmodule.exports = getRandomValues;\n", "// Copyright 2018 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\nimport getRandomValues from 'get-random-values';\n\nconst encoder = new TextEncoder(\"utf-8\");\nconst decoder = new TextDecoder(\"utf-8\");\n\nconst enosys = () => {\n const err = new Error(\"not implemented\");\n err.code = \"ENOSYS\";\n return err;\n};\n\n// NOTE: required and used by the WASM binary\nlet outputBuf = \"\";\nglobal.fs = {\n\tconstants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused\n\twriteSync(fd, buf) {\n\t\toutputBuf += decoder.decode(buf);\n\t\tconst nl = outputBuf.lastIndexOf(\"\\n\");\n\t\tif (nl != -1) {\n\t\t\tconsole.log(outputBuf.substr(0, nl));\n\t\t\toutputBuf = outputBuf.substr(nl + 1);\n\t\t}\n\t\treturn buf.length;\n\t},\n\twrite(fd, buf, offset, length, position, callback) {\n\t\tif (offset !== 0 || length !== buf.length || position !== null) {\n\t\t\tcallback(enosys());\n\t\t\treturn;\n\t\t}\n\t\tconst n = this.writeSync(fd, buf);\n\t\tcallback(null, n);\n\t},\n\tchmod(path, mode, callback) { callback(enosys()); },\n\tchown(path, uid, gid, callback) { callback(enosys()); },\n\tclose(fd, callback) { callback(enosys()); },\n\tfchmod(fd, mode, callback) { callback(enosys()); },\n\tfchown(fd, uid, gid, callback) { callback(enosys()); },\n\tfstat(fd, callback) { callback(enosys()); },\n\tfsync(fd, callback) { callback(null); },\n\tftruncate(fd, length, callback) { callback(enosys()); },\n\tlchown(path, uid, gid, callback) { callback(enosys()); },\n\tlink(path, link, callback) { callback(enosys()); },\n\tlstat(path, callback) { callback(enosys()); },\n\tmkdir(path, perm, callback) { callback(enosys()); },\n\topen(path, flags, mode, callback) { callback(enosys()); },\n\tread(fd, buffer, offset, length, position, callback) { callback(enosys()); },\n\treaddir(path, callback) { callback(enosys()); },\n\treadlink(path, callback) { callback(enosys()); },\n\trename(from, to, callback) { callback(enosys()); },\n\trmdir(path, callback) { callback(enosys()); },\n\tstat(path, callback) { callback(enosys()); },\n\tsymlink(path, link, callback) { callback(enosys()); },\n\ttruncate(path, length, callback) { callback(enosys()); },\n\tunlink(path, callback) { callback(enosys()); },\n\tutimes(path, atime, mtime, callback) { callback(enosys()); },\n};\n\n// NOTE: required and used by the WASM binary\nif (!global.process) {\n global.process = {\n getuid() { return -1; },\n getgid() { return -1; },\n geteuid() { return -1; },\n getegid() { return -1; },\n getgroups() { throw enosys(); },\n pid: -1,\n ppid: -1,\n umask() { throw enosys(); },\n cwd() { throw enosys(); },\n chdir() { throw enosys(); },\n }\n}\n\nclass Go {\n\n\tconstructor() {\n\t\tthis.argv = [\"js\"];\n\t\tthis.env = {};\n\t\tthis.exit = (code) => {\n\t\t\tif (code !== 0) {\n\t\t\t\tconsole.warn(\"exit code:\", code);\n\t\t\t}\n\t\t};\n\t\tthis._exitPromise = new Promise((resolve) => {\n\t\t\tthis._resolveExitPromise = resolve;\n\t\t});\n\t\tthis._pendingEvent = null;\n\t\tthis._scheduledTimeouts = new Map();\n\t\tthis._nextCallbackTimeoutID = 1;\n\n\t\tconst setInt64 = (addr, v) => {\n\t\t\tthis.mem.setUint32(addr + 0, v, true);\n\t\t\tthis.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);\n\t\t}\n\n\t\tconst getInt64 = (addr) => {\n\t\t\tconst low = this.mem.getUint32(addr + 0, true);\n\t\t\tconst high = this.mem.getInt32(addr + 4, true);\n\t\t\treturn low + high * 4294967296;\n\t\t}\n\n\t\tconst loadValue = (addr) => {\n\t\t\tconst f = this.mem.getFloat64(addr, true);\n\t\t\tif (f === 0) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (!isNaN(f)) {\n\t\t\t\treturn f;\n\t\t\t}\n\n\t\t\tconst id = this.mem.getUint32(addr, true);\n\t\t\treturn this._values[id];\n\t\t}\n\n\t\tconst storeValue = (addr, v) => {\n\t\t\tconst nanHead = 0x7FF80000;\n\n\t\t\tif (typeof v === \"number\" && v !== 0) {\n\t\t\t\tif (isNaN(v)) {\n\t\t\t\t\tthis.mem.setUint32(addr + 4, nanHead, true);\n\t\t\t\t\tthis.mem.setUint32(addr, 0, true);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.mem.setFloat64(addr, v, true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (v === undefined) {\n\t\t\t\tthis.mem.setFloat64(addr, 0, true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet id = this._ids.get(v);\n\t\t\tif (id === undefined) {\n\t\t\t\tid = this._idPool.pop();\n\t\t\t\tif (id === undefined) {\n\t\t\t\t\tid = this._values.length;\n\t\t\t\t}\n\t\t\t\tthis._values[id] = v;\n\t\t\t\tthis._goRefCounts[id] = 0;\n\t\t\t\tthis._ids.set(v, id);\n\t\t\t}\n\t\t\tthis._goRefCounts[id]++;\n\t\t\tlet typeFlag = 0;\n\t\t\tswitch (typeof v) {\n\t\t\t\tcase \"object\":\n\t\t\t\t\tif (v !== null) {\n\t\t\t\t\t\ttypeFlag = 1;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"string\":\n\t\t\t\t\ttypeFlag = 2;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"symbol\":\n\t\t\t\t\ttypeFlag = 3;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"function\":\n\t\t\t\t\ttypeFlag = 4;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.mem.setUint32(addr + 4, nanHead | typeFlag, true);\n\t\t\tthis.mem.setUint32(addr, id, true);\n\t\t}\n\n\t\tconst loadSlice = (addr) => {\n\t\t\tconst array = getInt64(addr + 0);\n\t\t\tconst len = getInt64(addr + 8);\n\t\t\treturn new Uint8Array(this._inst.exports.mem.buffer, array, len);\n\t\t}\n\n\t\tconst loadSliceOfValues = (addr) => {\n\t\t\tconst array = getInt64(addr + 0);\n\t\t\tconst len = getInt64(addr + 8);\n\t\t\tconst a = new Array(len);\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\ta[i] = loadValue(array + i * 8);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tconst loadString = (addr) => {\n\t\t\tconst saddr = getInt64(addr + 0);\n\t\t\tconst len = getInt64(addr + 8);\n\t\t\treturn decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));\n\t\t}\n\n\t\tconst timeOrigin = Date.now() - performance.now();\n\t\tthis.importObject = {\n\t\t\tgojs: {\n\t\t\t\t// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)\n\t\t\t\t// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported\n\t\t\t\t// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).\n\t\t\t\t// This changes the SP, thus we have to update the SP used by the imported function.\n\n\t\t\t\t// func wasmExit(code int32)\n\t\t\t\t\"runtime.wasmExit\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst code = this.mem.getInt32(sp + 8, true);\n\t\t\t\t\tthis.exited = true;\n\t\t\t\t\tdelete this._inst;\n\t\t\t\t\tdelete this._values;\n\t\t\t\t\tdelete this._goRefCounts;\n\t\t\t\t\tdelete this._ids;\n\t\t\t\t\tdelete this._idPool;\n\t\t\t\t\tthis.exit(code);\n\t\t\t\t},\n\n\t\t\t\t// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)\n\t\t\t\t\"runtime.wasmWrite\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst fd = getInt64(sp + 8);\n\t\t\t\t\tconst p = getInt64(sp + 16);\n\t\t\t\t\tconst n = this.mem.getInt32(sp + 24, true);\n\t\t\t\t\tfs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));\n\t\t\t\t},\n\n\t\t\t\t// func resetMemoryDataView()\n\t\t\t\t\"runtime.resetMemoryDataView\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);\n\t\t\t\t},\n\n\t\t\t\t// func nanotime1() int64\n\t\t\t\t\"runtime.nanotime1\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tsetInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);\n\t\t\t\t},\n\n\t\t\t\t// func walltime() (sec int64, nsec int32)\n\t\t\t\t\"runtime.walltime\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst msec = (new Date).getTime();\n\t\t\t\t\tsetInt64(sp + 8, msec / 1000);\n\t\t\t\t\tthis.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);\n\t\t\t\t},\n\n\t\t\t\t// func scheduleTimeoutEvent(delay int64) int32\n\t\t\t\t\"runtime.scheduleTimeoutEvent\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst id = this._nextCallbackTimeoutID;\n\t\t\t\t\tthis._nextCallbackTimeoutID++;\n\t\t\t\t\tthis._scheduledTimeouts.set(id, setTimeout(\n\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\tthis._resume();\n\t\t\t\t\t\t\twhile (this._scheduledTimeouts.has(id)) {\n\t\t\t\t\t\t\t\t// for some reason Go failed to register the timeout event, log and try again\n\t\t\t\t\t\t\t\t// (temporary workaround for https://github.com/golang/go/issues/28975)\n\t\t\t\t\t\t\t\tconsole.warn(\"scheduleTimeoutEvent: missed timeout event\");\n\t\t\t\t\t\t\t\tthis._resume();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early\n\t\t\t\t\t));\n\t\t\t\t\tthis.mem.setInt32(sp + 16, id, true);\n\t\t\t\t},\n\n\t\t\t\t// func clearTimeoutEvent(id int32)\n\t\t\t\t\"runtime.clearTimeoutEvent\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst id = this.mem.getInt32(sp + 8, true);\n\t\t\t\t\tclearTimeout(this._scheduledTimeouts.get(id));\n\t\t\t\t\tthis._scheduledTimeouts.delete(id);\n\t\t\t\t},\n\n\t\t\t\t// func getRandomData(r []byte)\n\t\t\t\t\"runtime.getRandomData\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tgetRandomValues(loadSlice(sp + 8));\n\t\t\t\t},\n\n\t\t\t\t// func finalizeRef(v ref)\n\t\t\t\t\"syscall/js.finalizeRef\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst id = this.mem.getUint32(sp + 8, true);\n\t\t\t\t\tthis._goRefCounts[id]--;\n\t\t\t\t\tif (this._goRefCounts[id] === 0) {\n\t\t\t\t\t\tconst v = this._values[id];\n\t\t\t\t\t\tthis._values[id] = null;\n\t\t\t\t\t\tthis._ids.delete(v);\n\t\t\t\t\t\tthis._idPool.push(id);\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\t// func stringVal(value string) ref\n\t\t\t\t\"syscall/js.stringVal\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tstoreValue(sp + 24, loadString(sp + 8));\n\t\t\t\t},\n\n\t\t\t\t// func valueGet(v ref, p string) ref\n\t\t\t\t\"syscall/js.valueGet\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));\n\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\tstoreValue(sp + 32, result);\n\t\t\t\t},\n\n\t\t\t\t// func valueSet(v ref, p string, x ref)\n\t\t\t\t\"syscall/js.valueSet\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tReflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));\n\t\t\t\t},\n\n\t\t\t\t// func valueDelete(v ref, p string)\n\t\t\t\t\"syscall/js.valueDelete\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tReflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));\n\t\t\t\t},\n\n\t\t\t\t// func valueIndex(v ref, i int) ref\n\t\t\t\t\"syscall/js.valueIndex\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tstoreValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));\n\t\t\t\t},\n\n\t\t\t\t// valueSetIndex(v ref, i int, x ref)\n\t\t\t\t\"syscall/js.valueSetIndex\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tReflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));\n\t\t\t\t},\n\n\t\t\t\t// func valueCall(v ref, m string, args []ref) (ref, bool)\n\t\t\t\t\"syscall/js.valueCall\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\tconst m = Reflect.get(v, loadString(sp + 16));\n\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 32);\n\t\t\t\t\t\tconst result = Reflect.apply(m, v, args);\n\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\t\tstoreValue(sp + 56, result);\n\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 1);\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\t\tstoreValue(sp + 56, err);\n\t\t\t\t\t\tthis.mem.setUint8(sp + 64, 0);\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\t// func valueInvoke(v ref, args []ref) (ref, bool)\n\t\t\t\t\"syscall/js.valueInvoke\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);\n\t\t\t\t\t\tconst result = Reflect.apply(v, undefined, args);\n\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\t\tstoreValue(sp + 40, result);\n\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\t\tstoreValue(sp + 40, err);\n\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\t// func valueNew(v ref, args []ref) (ref, bool)\n\t\t\t\t\"syscall/js.valueNew\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst v = loadValue(sp + 8);\n\t\t\t\t\t\tconst args = loadSliceOfValues(sp + 16);\n\t\t\t\t\t\tconst result = Reflect.construct(v, args);\n\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\t\tstoreValue(sp + 40, result);\n\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tsp = this._inst.exports.getsp() >>> 0; // see comment above\n\t\t\t\t\t\tstoreValue(sp + 40, err);\n\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\t// func valueLength(v ref) int\n\t\t\t\t\"syscall/js.valueLength\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tsetInt64(sp + 16, parseInt(loadValue(sp + 8).length));\n\t\t\t\t},\n\n\t\t\t\t// valuePrepareString(v ref) (ref, int)\n\t\t\t\t\"syscall/js.valuePrepareString\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst str = encoder.encode(String(loadValue(sp + 8)));\n\t\t\t\t\tstoreValue(sp + 16, str);\n\t\t\t\t\tsetInt64(sp + 24, str.length);\n\t\t\t\t},\n\n\t\t\t\t// valueLoadString(v ref, b []byte)\n\t\t\t\t\"syscall/js.valueLoadString\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst str = loadValue(sp + 8);\n\t\t\t\t\tloadSlice(sp + 16).set(str);\n\t\t\t\t},\n\n\t\t\t\t// func valueInstanceOf(v ref, t ref) bool\n\t\t\t\t\"syscall/js.valueInstanceOf\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tthis.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);\n\t\t\t\t},\n\n\t\t\t\t// func copyBytesToGo(dst []byte, src ref) (int, bool)\n\t\t\t\t\"syscall/js.copyBytesToGo\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst dst = loadSlice(sp + 8);\n\t\t\t\t\tconst src = loadValue(sp + 32);\n\t\t\t\t\tif (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {\n\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);\n\t\t\t\t\tdst.set(toCopy);\n\t\t\t\t\tsetInt64(sp + 40, toCopy.length);\n\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t},\n\n\t\t\t\t// func copyBytesToJS(dst ref, src []byte) (int, bool)\n\t\t\t\t\"syscall/js.copyBytesToJS\": (sp) => {\n\t\t\t\t\tsp >>>= 0;\n\t\t\t\t\tconst dst = loadValue(sp + 8);\n\t\t\t\t\tconst src = loadSlice(sp + 16);\n\t\t\t\t\tif (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {\n\t\t\t\t\t\tthis.mem.setUint8(sp + 48, 0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst toCopy = src.subarray(0, dst.length);\n\t\t\t\t\tdst.set(toCopy);\n\t\t\t\t\tsetInt64(sp + 40, toCopy.length);\n\t\t\t\t\tthis.mem.setUint8(sp + 48, 1);\n\t\t\t\t},\n\n\t\t\t\t\"debug\": (value) => {\n\t\t\t\t\tconsole.log(value);\n\t\t\t\t},\n\t\t\t}\n\t\t};\n\t}\n\n\tasync run(instance) {\n\t\tif (!(instance instanceof WebAssembly.Instance)) {\n\t\t\tthrow new Error(\"Go.run: WebAssembly.Instance expected\");\n\t\t}\n\t\tthis._inst = instance;\n\t\tthis.mem = new DataView(this._inst.exports.mem.buffer);\n\t\tthis._values = [ // JS values that Go currently has references to, indexed by reference id\n\t\t\tNaN,\n\t\t\t0,\n\t\t\tnull,\n\t\t\ttrue,\n\t\t\tfalse,\n\t\t\tglobal,\n\t\t\tthis,\n\t\t];\n\t\tthis._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id\n\t\tthis._ids = new Map([ // mapping from JS values to reference ids\n\t\t\t[0, 1],\n\t\t\t[null, 2],\n\t\t\t[true, 3],\n\t\t\t[false, 4],\n\t\t\t[global, 5],\n\t\t\t[this, 6],\n\t\t]);\n\t\tthis._idPool = []; // unused ids that have been garbage collected\n\t\tthis.exited = false; // whether the Go program has exited\n\n\t\t// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.\n\t\tlet offset = 4096;\n\n\t\tconst strPtr = (str) => {\n\t\t\tconst ptr = offset;\n\t\t\tconst bytes = encoder.encode(str + \"\\0\");\n\t\t\tnew Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);\n\t\t\toffset += bytes.length;\n\t\t\tif (offset % 8 !== 0) {\n\t\t\t\toffset += 8 - (offset % 8);\n\t\t\t}\n\t\t\treturn ptr;\n\t\t};\n\n\t\tconst argc = this.argv.length;\n\n\t\tconst argvPtrs = [];\n\t\tthis.argv.forEach((arg) => {\n\t\t\targvPtrs.push(strPtr(arg));\n\t\t});\n\t\targvPtrs.push(0);\n\n\t\tconst keys = Object.keys(this.env).sort();\n\t\tkeys.forEach((key) => {\n\t\t\targvPtrs.push(strPtr(`${key}=${this.env[key]}`));\n\t\t});\n\t\targvPtrs.push(0);\n\n\t\tconst argv = offset;\n\t\targvPtrs.forEach((ptr) => {\n\t\t\tthis.mem.setUint32(offset, ptr, true);\n\t\t\tthis.mem.setUint32(offset + 4, 0, true);\n\t\t\toffset += 8;\n\t\t});\n\n\t\t// The linker guarantees global data starts from at least wasmMinDataAddr.\n\t\t// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.\n\t\tconst wasmMinDataAddr = 4096 + 8192;\n\t\tif (offset >= wasmMinDataAddr) {\n\t\t\tthrow new Error(\"total length of command line and environment variables exceeds limit\");\n\t\t}\n\n\t\tthis._inst.exports.run(argc, argv);\n\t\tif (this.exited) {\n\t\t\tthis._resolveExitPromise();\n\t\t}\n\t\tawait this._exitPromise;\n\t}\n\n\t_resume() {\n\t\tif (this.exited) {\n\t\t\tthrow new Error(\"Go program has already exited\");\n\t\t}\n\t\tthis._inst.exports.resume();\n\t\tif (this.exited) {\n\t\t\tthis._resolveExitPromise();\n\t\t}\n\t}\n\n\t_makeFuncWrapper(id) {\n\t\tconst go = this;\n\t\treturn function () {\n\t\t\tconst event = { id: id, this: this, args: arguments };\n\t\t\tgo._pendingEvent = event;\n\t\t\tgo._resume();\n\t\t\treturn event.result;\n\t\t};\n\t}\n}\n\nexport const go = new Go()\n", "/*\n * Cadence - The resource-oriented smart contract programming language\n *\n * Copyright Flow Foundation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { go } from './go'\nimport WebAssemblyInstantiatedSource = WebAssembly.WebAssemblyInstantiatedSource\n\ndeclare global {\n namespace NodeJS {\n interface Global {\n [key: string]: any\n }\n }\n}\n\nexport class CadenceParser {\n\n private static functionNamePrefix = \"CADENCE_PARSER\"\n private static loaded = false\n\n private static functionName(name: string): string {\n return `__${CadenceParser.functionNamePrefix}_${name}__`\n }\n\n public static async create(binaryLocation: string | BufferSource): Promise<CadenceParser> {\n await this.ensureLoaded(binaryLocation)\n return new CadenceParser()\n }\n\n private static async ensureLoaded(urlOrBinary: string | BufferSource) {\n if (this.loaded) {\n return\n }\n\n this.setWriteSync()\n\n await this.load(urlOrBinary)\n this.loaded = true\n }\n\n private static async load(urlOrBinary: string | BufferSource): Promise<void> {\n let instantiatedSource: WebAssemblyInstantiatedSource\n if (typeof urlOrBinary === 'string') {\n const binaryRequest = fetch(urlOrBinary)\n instantiatedSource = (await WebAssembly.instantiateStreaming(binaryRequest, go.importObject))\n } else {\n instantiatedSource = await WebAssembly.instantiate(urlOrBinary, go.importObject);\n }\n\n // NOTE: don't await the promise, just ignore it, as it is only resolved when the program exists\n go.run(instantiatedSource.instance).then(() => {})\n }\n\n private constructor() {}\n\n public parse(code: string): any {\n const result = global[CadenceParser.functionName('parse')](code)\n return JSON.parse(result)\n }\n\n // setWriteSync installs the writeSync filesystem handler that the Go WebAssembly binary calls\n private static setWriteSync() {\n // For each file descriptor, buffer the written content until reaching a newline\n\n const outputBuffers = new Map<number, string>()\n const decoder = new TextDecoder(\"utf-8\")\n\n // Implementing `writeSync` is mainly just for debugging purposes:\n // When the language server writes to a file, e.g. standard output or standard error,\n // then log the output in the console\n\n global.fs.writeSync = function (fileDescriptor: number, buf: Uint8Array): number {\n // Get the currently buffered output for the given file descriptor,\n // or initialize it, if there is no buffered output yet.\n\n let outputBuffer = outputBuffers.get(fileDescriptor)\n if (!outputBuffer) {\n outputBuffer = \"\"\n }\n\n // Decode the written data as UTF-8\n outputBuffer += decoder.decode(buf)\n\n // If the buffered output contains a newline,\n // log the contents up to the newline to the console\n\n const nl = outputBuffer.lastIndexOf(\"\\n\")\n if (nl != -1) {\n const lines = outputBuffer.substr(0, nl + 1)\n console.debug(`(FD ${fileDescriptor}):`, lines)\n // keep the remainder\n outputBuffer = outputBuffer.substr(nl + 1)\n }\n outputBuffers.set(fileDescriptor, outputBuffer)\n\n return buf.length\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,QAAI;AAEJ,QAAI,OAAO,WAAW,aAAa;AAC/B,YAAM;AAAA,IACV,WAAW,OAAO,WAAW,aAAa;AACtC,YAAM;AAAA,IACV,WAAW,OAAO,SAAS,aAAY;AACnC,YAAM;AAAA,IACV,OAAO;AACH,YAAM,CAAC;AAAA,IACX;AAEA,WAAO,UAAU;AAAA;AAAA;;;;;;;;;ACZjB;AAAA;AAEA,QAAIA,UAAS;AACb,QAAI,aAAa;AAOjB,aAASC,iBAAgB,KAAK;AAC5B,UAAID,QAAO,UAAUA,QAAO,OAAO,iBAAiB;AAClD,eAAOA,QAAO,OAAO,gBAAgB,GAAG;AAAA,MAC1C;AACA,UAAI,OAAOA,QAAO,aAAa,YAAY,OAAOA,QAAO,SAAS,oBAAoB,YAAY;AAChG,eAAOA,QAAO,SAAS,gBAAgB,GAAG;AAAA,MAC5C;AACA,UAAI,WAAW,aAAa;AAC1B,YAAI,EAAE,eAAe,aAAa;AAChC,gBAAM,IAAI,UAAU,qBAAqB;AAAA,QAC3C;AACA,YAAI,IAAI,SAAS,OAAO;AACtB,cAAI,IAAI,IAAI,MAAM;AAElB,YAAE,OAAO;AACT,YAAE,UAAU,yFAC2B,IAAI,SAAS;AAEpD,YAAE,OAAO;AACT,gBAAM;AAAA,QACR;AACA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AM;AAAA,IAAC,CAAC;AAAA,EACnD;AAAA,EAEQ,cAAc;AAAA,EAAC;AAAA,EAEhB,MAAM,MAAmB;AAC9B,UAAM,SAAS,OAAO,eAAc,aAAa,OAAO,CAAC,EAAE,IAAI;AAC/D,WAAO,KAAK,MAAM,MAAM;AAAA,EAC1B;AAAA;AAAA,EAGA,OAAe,eAAe;AAG5B,UAAM,gBAAgB,oBAAI,IAAoB;AAC9C,UAAMC,WAAU,IAAI,YAAY,OAAO;AAMvC,WAAO,GAAG,YAAY,SAAU,gBAAwB,KAAyB;AAI/E,UAAI,eAAe,cAAc,IAAI,cAAc;AACnD,UAAI,CAAC,cAAc;AACjB,uBAAe;AAAA,MACjB;AAGA,sBAAgBA,SAAQ,OAAO,GAAG;AAKlC,YAAM,KAAK,aAAa,YAAY,IAAI;AACxC,UAAI,MAAM,IAAI;AACZ,cAAM,QAAQ,aAAa,OAAO,GAAG,KAAK,CAAC;AAC3C,gBAAQ,MAAM,OAAO,cAAc,MAAM,KAAK;AAE9C,uBAAe,aAAa,OAAO,KAAK,CAAC;AAAA,MAC3C;AACA,oBAAc,IAAI,gBAAgB,YAAY;AAE9C,aAAO,IAAI;AAAA,IACb;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["window", "getRandomValues", "getRandomValues", "go", "decoder"]
|
|
7
|
+
}
|
package/dist/types/go.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare class Go {
|
|
|
9
9
|
_scheduledTimeouts: Map<any, any>;
|
|
10
10
|
_nextCallbackTimeoutID: number;
|
|
11
11
|
importObject: {
|
|
12
|
-
|
|
12
|
+
gojs: {
|
|
13
13
|
"runtime.wasmExit": (sp: any) => void;
|
|
14
14
|
"runtime.wasmWrite": (sp: any) => void;
|
|
15
15
|
"runtime.resetMemoryDataView": (sp: any) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onflow/cadence-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-preview.50",
|
|
4
4
|
"description": "The Cadence parser",
|
|
5
5
|
"homepage": "https://github.com/onflow/cadence",
|
|
6
6
|
"repository": {
|
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"url": "https://github.com/onflow/cadence.git"
|
|
9
9
|
},
|
|
10
10
|
"main": "./dist/cjs/index.js",
|
|
11
|
-
"module": "./dist/esm/index.
|
|
11
|
+
"module": "./dist/esm/index.mjs",
|
|
12
12
|
"types": "./dist/types/index.d.ts",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"require": "./dist/cjs/index.js",
|
|
16
|
-
"import": "./dist/esm/index.
|
|
16
|
+
"import": "./dist/esm/index.mjs",
|
|
17
17
|
"types": "./dist/types/index.d.ts"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "npm run build:types && npm run build:esm && npm run build:cjs && GOARCH=wasm GOOS=js go build -o ./dist/cadence-parser.wasm ../../runtime/cmd/parse",
|
|
22
22
|
"build:types": "tsc --emitDeclarationOnly --module system --outDir dist/types",
|
|
23
|
-
"build:esm": "
|
|
23
|
+
"build:esm": "esbuild src/index.ts --bundle --sourcemap --format=esm --outfile=dist/esm/index.mjs",
|
|
24
24
|
"build:cjs": "tsc --module commonjs --target es6 --outDir dist/cjs --declaration false",
|
|
25
25
|
"test": "jest"
|
|
26
26
|
},
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^28.1.4",
|
|
30
30
|
"@types/node": "^18.0.3",
|
|
31
|
+
"esbuild": "0.19.4",
|
|
31
32
|
"jest": "^28.1.2",
|
|
32
33
|
"node-fetch": "^2.6.1",
|
|
33
34
|
"ts-jest": "^28.0.5",
|
package/dist/esm/go.js
DELETED
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
// Copyright 2018 The Go Authors. All rights reserved.
|
|
2
|
-
// Use of this source code is governed by a BSD-style
|
|
3
|
-
// license that can be found in the LICENSE file.
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
import getRandomValues from 'get-random-values';
|
|
14
|
-
const encoder = new TextEncoder("utf-8");
|
|
15
|
-
const decoder = new TextDecoder("utf-8");
|
|
16
|
-
const enosys = () => {
|
|
17
|
-
const err = new Error("not implemented");
|
|
18
|
-
err.code = "ENOSYS";
|
|
19
|
-
return err;
|
|
20
|
-
};
|
|
21
|
-
// NOTE: required and used by the WASM binary
|
|
22
|
-
let outputBuf = "";
|
|
23
|
-
global.fs = {
|
|
24
|
-
constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 },
|
|
25
|
-
writeSync(fd, buf) {
|
|
26
|
-
outputBuf += decoder.decode(buf);
|
|
27
|
-
const nl = outputBuf.lastIndexOf("\n");
|
|
28
|
-
if (nl != -1) {
|
|
29
|
-
console.log(outputBuf.substr(0, nl));
|
|
30
|
-
outputBuf = outputBuf.substr(nl + 1);
|
|
31
|
-
}
|
|
32
|
-
return buf.length;
|
|
33
|
-
},
|
|
34
|
-
write(fd, buf, offset, length, position, callback) {
|
|
35
|
-
if (offset !== 0 || length !== buf.length || position !== null) {
|
|
36
|
-
callback(enosys());
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const n = this.writeSync(fd, buf);
|
|
40
|
-
callback(null, n);
|
|
41
|
-
},
|
|
42
|
-
chmod(path, mode, callback) { callback(enosys()); },
|
|
43
|
-
chown(path, uid, gid, callback) { callback(enosys()); },
|
|
44
|
-
close(fd, callback) { callback(enosys()); },
|
|
45
|
-
fchmod(fd, mode, callback) { callback(enosys()); },
|
|
46
|
-
fchown(fd, uid, gid, callback) { callback(enosys()); },
|
|
47
|
-
fstat(fd, callback) { callback(enosys()); },
|
|
48
|
-
fsync(fd, callback) { callback(null); },
|
|
49
|
-
ftruncate(fd, length, callback) { callback(enosys()); },
|
|
50
|
-
lchown(path, uid, gid, callback) { callback(enosys()); },
|
|
51
|
-
link(path, link, callback) { callback(enosys()); },
|
|
52
|
-
lstat(path, callback) { callback(enosys()); },
|
|
53
|
-
mkdir(path, perm, callback) { callback(enosys()); },
|
|
54
|
-
open(path, flags, mode, callback) { callback(enosys()); },
|
|
55
|
-
read(fd, buffer, offset, length, position, callback) { callback(enosys()); },
|
|
56
|
-
readdir(path, callback) { callback(enosys()); },
|
|
57
|
-
readlink(path, callback) { callback(enosys()); },
|
|
58
|
-
rename(from, to, callback) { callback(enosys()); },
|
|
59
|
-
rmdir(path, callback) { callback(enosys()); },
|
|
60
|
-
stat(path, callback) { callback(enosys()); },
|
|
61
|
-
symlink(path, link, callback) { callback(enosys()); },
|
|
62
|
-
truncate(path, length, callback) { callback(enosys()); },
|
|
63
|
-
unlink(path, callback) { callback(enosys()); },
|
|
64
|
-
utimes(path, atime, mtime, callback) { callback(enosys()); },
|
|
65
|
-
};
|
|
66
|
-
// NOTE: required and used by the WASM binary
|
|
67
|
-
if (!global.process) {
|
|
68
|
-
global.process = {
|
|
69
|
-
getuid() { return -1; },
|
|
70
|
-
getgid() { return -1; },
|
|
71
|
-
geteuid() { return -1; },
|
|
72
|
-
getegid() { return -1; },
|
|
73
|
-
getgroups() { throw enosys(); },
|
|
74
|
-
pid: -1,
|
|
75
|
-
ppid: -1,
|
|
76
|
-
umask() { throw enosys(); },
|
|
77
|
-
cwd() { throw enosys(); },
|
|
78
|
-
chdir() { throw enosys(); },
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
class Go {
|
|
82
|
-
constructor() {
|
|
83
|
-
this.argv = ["js"];
|
|
84
|
-
this.env = {};
|
|
85
|
-
this.exit = (code) => {
|
|
86
|
-
if (code !== 0) {
|
|
87
|
-
console.warn("exit code:", code);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
this._exitPromise = new Promise((resolve) => {
|
|
91
|
-
this._resolveExitPromise = resolve;
|
|
92
|
-
});
|
|
93
|
-
this._pendingEvent = null;
|
|
94
|
-
this._scheduledTimeouts = new Map();
|
|
95
|
-
this._nextCallbackTimeoutID = 1;
|
|
96
|
-
const setInt64 = (addr, v) => {
|
|
97
|
-
this.mem.setUint32(addr + 0, v, true);
|
|
98
|
-
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
99
|
-
};
|
|
100
|
-
const getInt64 = (addr) => {
|
|
101
|
-
const low = this.mem.getUint32(addr + 0, true);
|
|
102
|
-
const high = this.mem.getInt32(addr + 4, true);
|
|
103
|
-
return low + high * 4294967296;
|
|
104
|
-
};
|
|
105
|
-
const loadValue = (addr) => {
|
|
106
|
-
const f = this.mem.getFloat64(addr, true);
|
|
107
|
-
if (f === 0) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
if (!isNaN(f)) {
|
|
111
|
-
return f;
|
|
112
|
-
}
|
|
113
|
-
const id = this.mem.getUint32(addr, true);
|
|
114
|
-
return this._values[id];
|
|
115
|
-
};
|
|
116
|
-
const storeValue = (addr, v) => {
|
|
117
|
-
const nanHead = 0x7FF80000;
|
|
118
|
-
if (typeof v === "number" && v !== 0) {
|
|
119
|
-
if (isNaN(v)) {
|
|
120
|
-
this.mem.setUint32(addr + 4, nanHead, true);
|
|
121
|
-
this.mem.setUint32(addr, 0, true);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.mem.setFloat64(addr, v, true);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (v === undefined) {
|
|
128
|
-
this.mem.setFloat64(addr, 0, true);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
let id = this._ids.get(v);
|
|
132
|
-
if (id === undefined) {
|
|
133
|
-
id = this._idPool.pop();
|
|
134
|
-
if (id === undefined) {
|
|
135
|
-
id = this._values.length;
|
|
136
|
-
}
|
|
137
|
-
this._values[id] = v;
|
|
138
|
-
this._goRefCounts[id] = 0;
|
|
139
|
-
this._ids.set(v, id);
|
|
140
|
-
}
|
|
141
|
-
this._goRefCounts[id]++;
|
|
142
|
-
let typeFlag = 0;
|
|
143
|
-
switch (typeof v) {
|
|
144
|
-
case "object":
|
|
145
|
-
if (v !== null) {
|
|
146
|
-
typeFlag = 1;
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
case "string":
|
|
150
|
-
typeFlag = 2;
|
|
151
|
-
break;
|
|
152
|
-
case "symbol":
|
|
153
|
-
typeFlag = 3;
|
|
154
|
-
break;
|
|
155
|
-
case "function":
|
|
156
|
-
typeFlag = 4;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
160
|
-
this.mem.setUint32(addr, id, true);
|
|
161
|
-
};
|
|
162
|
-
const loadSlice = (addr) => {
|
|
163
|
-
const array = getInt64(addr + 0);
|
|
164
|
-
const len = getInt64(addr + 8);
|
|
165
|
-
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
166
|
-
};
|
|
167
|
-
const loadSliceOfValues = (addr) => {
|
|
168
|
-
const array = getInt64(addr + 0);
|
|
169
|
-
const len = getInt64(addr + 8);
|
|
170
|
-
const a = new Array(len);
|
|
171
|
-
for (let i = 0; i < len; i++) {
|
|
172
|
-
a[i] = loadValue(array + i * 8);
|
|
173
|
-
}
|
|
174
|
-
return a;
|
|
175
|
-
};
|
|
176
|
-
const loadString = (addr) => {
|
|
177
|
-
const saddr = getInt64(addr + 0);
|
|
178
|
-
const len = getInt64(addr + 8);
|
|
179
|
-
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
180
|
-
};
|
|
181
|
-
const timeOrigin = Date.now() - performance.now();
|
|
182
|
-
this.importObject = {
|
|
183
|
-
go: {
|
|
184
|
-
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
185
|
-
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
186
|
-
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
187
|
-
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
188
|
-
// func wasmExit(code int32)
|
|
189
|
-
"runtime.wasmExit": (sp) => {
|
|
190
|
-
sp >>>= 0;
|
|
191
|
-
const code = this.mem.getInt32(sp + 8, true);
|
|
192
|
-
this.exited = true;
|
|
193
|
-
delete this._inst;
|
|
194
|
-
delete this._values;
|
|
195
|
-
delete this._goRefCounts;
|
|
196
|
-
delete this._ids;
|
|
197
|
-
delete this._idPool;
|
|
198
|
-
this.exit(code);
|
|
199
|
-
},
|
|
200
|
-
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
201
|
-
"runtime.wasmWrite": (sp) => {
|
|
202
|
-
sp >>>= 0;
|
|
203
|
-
const fd = getInt64(sp + 8);
|
|
204
|
-
const p = getInt64(sp + 16);
|
|
205
|
-
const n = this.mem.getInt32(sp + 24, true);
|
|
206
|
-
fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
207
|
-
},
|
|
208
|
-
// func resetMemoryDataView()
|
|
209
|
-
"runtime.resetMemoryDataView": (sp) => {
|
|
210
|
-
sp >>>= 0;
|
|
211
|
-
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
212
|
-
},
|
|
213
|
-
// func nanotime1() int64
|
|
214
|
-
"runtime.nanotime1": (sp) => {
|
|
215
|
-
sp >>>= 0;
|
|
216
|
-
setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
|
|
217
|
-
},
|
|
218
|
-
// func walltime() (sec int64, nsec int32)
|
|
219
|
-
"runtime.walltime": (sp) => {
|
|
220
|
-
sp >>>= 0;
|
|
221
|
-
const msec = (new Date).getTime();
|
|
222
|
-
setInt64(sp + 8, msec / 1000);
|
|
223
|
-
this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
|
|
224
|
-
},
|
|
225
|
-
// func scheduleTimeoutEvent(delay int64) int32
|
|
226
|
-
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
227
|
-
sp >>>= 0;
|
|
228
|
-
const id = this._nextCallbackTimeoutID;
|
|
229
|
-
this._nextCallbackTimeoutID++;
|
|
230
|
-
this._scheduledTimeouts.set(id, setTimeout(() => {
|
|
231
|
-
this._resume();
|
|
232
|
-
while (this._scheduledTimeouts.has(id)) {
|
|
233
|
-
// for some reason Go failed to register the timeout event, log and try again
|
|
234
|
-
// (temporary workaround for https://github.com/golang/go/issues/28975)
|
|
235
|
-
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
236
|
-
this._resume();
|
|
237
|
-
}
|
|
238
|
-
}, getInt64(sp + 8) + 1));
|
|
239
|
-
this.mem.setInt32(sp + 16, id, true);
|
|
240
|
-
},
|
|
241
|
-
// func clearTimeoutEvent(id int32)
|
|
242
|
-
"runtime.clearTimeoutEvent": (sp) => {
|
|
243
|
-
sp >>>= 0;
|
|
244
|
-
const id = this.mem.getInt32(sp + 8, true);
|
|
245
|
-
clearTimeout(this._scheduledTimeouts.get(id));
|
|
246
|
-
this._scheduledTimeouts.delete(id);
|
|
247
|
-
},
|
|
248
|
-
// func getRandomData(r []byte)
|
|
249
|
-
"runtime.getRandomData": (sp) => {
|
|
250
|
-
sp >>>= 0;
|
|
251
|
-
getRandomValues(loadSlice(sp + 8));
|
|
252
|
-
},
|
|
253
|
-
// func finalizeRef(v ref)
|
|
254
|
-
"syscall/js.finalizeRef": (sp) => {
|
|
255
|
-
sp >>>= 0;
|
|
256
|
-
const id = this.mem.getUint32(sp + 8, true);
|
|
257
|
-
this._goRefCounts[id]--;
|
|
258
|
-
if (this._goRefCounts[id] === 0) {
|
|
259
|
-
const v = this._values[id];
|
|
260
|
-
this._values[id] = null;
|
|
261
|
-
this._ids.delete(v);
|
|
262
|
-
this._idPool.push(id);
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
// func stringVal(value string) ref
|
|
266
|
-
"syscall/js.stringVal": (sp) => {
|
|
267
|
-
sp >>>= 0;
|
|
268
|
-
storeValue(sp + 24, loadString(sp + 8));
|
|
269
|
-
},
|
|
270
|
-
// func valueGet(v ref, p string) ref
|
|
271
|
-
"syscall/js.valueGet": (sp) => {
|
|
272
|
-
sp >>>= 0;
|
|
273
|
-
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
274
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
275
|
-
storeValue(sp + 32, result);
|
|
276
|
-
},
|
|
277
|
-
// func valueSet(v ref, p string, x ref)
|
|
278
|
-
"syscall/js.valueSet": (sp) => {
|
|
279
|
-
sp >>>= 0;
|
|
280
|
-
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
281
|
-
},
|
|
282
|
-
// func valueDelete(v ref, p string)
|
|
283
|
-
"syscall/js.valueDelete": (sp) => {
|
|
284
|
-
sp >>>= 0;
|
|
285
|
-
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
286
|
-
},
|
|
287
|
-
// func valueIndex(v ref, i int) ref
|
|
288
|
-
"syscall/js.valueIndex": (sp) => {
|
|
289
|
-
sp >>>= 0;
|
|
290
|
-
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
291
|
-
},
|
|
292
|
-
// valueSetIndex(v ref, i int, x ref)
|
|
293
|
-
"syscall/js.valueSetIndex": (sp) => {
|
|
294
|
-
sp >>>= 0;
|
|
295
|
-
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
296
|
-
},
|
|
297
|
-
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
298
|
-
"syscall/js.valueCall": (sp) => {
|
|
299
|
-
sp >>>= 0;
|
|
300
|
-
try {
|
|
301
|
-
const v = loadValue(sp + 8);
|
|
302
|
-
const m = Reflect.get(v, loadString(sp + 16));
|
|
303
|
-
const args = loadSliceOfValues(sp + 32);
|
|
304
|
-
const result = Reflect.apply(m, v, args);
|
|
305
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
306
|
-
storeValue(sp + 56, result);
|
|
307
|
-
this.mem.setUint8(sp + 64, 1);
|
|
308
|
-
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
311
|
-
storeValue(sp + 56, err);
|
|
312
|
-
this.mem.setUint8(sp + 64, 0);
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
316
|
-
"syscall/js.valueInvoke": (sp) => {
|
|
317
|
-
sp >>>= 0;
|
|
318
|
-
try {
|
|
319
|
-
const v = loadValue(sp + 8);
|
|
320
|
-
const args = loadSliceOfValues(sp + 16);
|
|
321
|
-
const result = Reflect.apply(v, undefined, args);
|
|
322
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
323
|
-
storeValue(sp + 40, result);
|
|
324
|
-
this.mem.setUint8(sp + 48, 1);
|
|
325
|
-
}
|
|
326
|
-
catch (err) {
|
|
327
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
328
|
-
storeValue(sp + 40, err);
|
|
329
|
-
this.mem.setUint8(sp + 48, 0);
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
// func valueNew(v ref, args []ref) (ref, bool)
|
|
333
|
-
"syscall/js.valueNew": (sp) => {
|
|
334
|
-
sp >>>= 0;
|
|
335
|
-
try {
|
|
336
|
-
const v = loadValue(sp + 8);
|
|
337
|
-
const args = loadSliceOfValues(sp + 16);
|
|
338
|
-
const result = Reflect.construct(v, args);
|
|
339
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
340
|
-
storeValue(sp + 40, result);
|
|
341
|
-
this.mem.setUint8(sp + 48, 1);
|
|
342
|
-
}
|
|
343
|
-
catch (err) {
|
|
344
|
-
sp = this._inst.exports.getsp() >>> 0; // see comment above
|
|
345
|
-
storeValue(sp + 40, err);
|
|
346
|
-
this.mem.setUint8(sp + 48, 0);
|
|
347
|
-
}
|
|
348
|
-
},
|
|
349
|
-
// func valueLength(v ref) int
|
|
350
|
-
"syscall/js.valueLength": (sp) => {
|
|
351
|
-
sp >>>= 0;
|
|
352
|
-
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
353
|
-
},
|
|
354
|
-
// valuePrepareString(v ref) (ref, int)
|
|
355
|
-
"syscall/js.valuePrepareString": (sp) => {
|
|
356
|
-
sp >>>= 0;
|
|
357
|
-
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
358
|
-
storeValue(sp + 16, str);
|
|
359
|
-
setInt64(sp + 24, str.length);
|
|
360
|
-
},
|
|
361
|
-
// valueLoadString(v ref, b []byte)
|
|
362
|
-
"syscall/js.valueLoadString": (sp) => {
|
|
363
|
-
sp >>>= 0;
|
|
364
|
-
const str = loadValue(sp + 8);
|
|
365
|
-
loadSlice(sp + 16).set(str);
|
|
366
|
-
},
|
|
367
|
-
// func valueInstanceOf(v ref, t ref) bool
|
|
368
|
-
"syscall/js.valueInstanceOf": (sp) => {
|
|
369
|
-
sp >>>= 0;
|
|
370
|
-
this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
|
|
371
|
-
},
|
|
372
|
-
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
373
|
-
"syscall/js.copyBytesToGo": (sp) => {
|
|
374
|
-
sp >>>= 0;
|
|
375
|
-
const dst = loadSlice(sp + 8);
|
|
376
|
-
const src = loadValue(sp + 32);
|
|
377
|
-
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
378
|
-
this.mem.setUint8(sp + 48, 0);
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
const toCopy = src.subarray(0, dst.length);
|
|
382
|
-
dst.set(toCopy);
|
|
383
|
-
setInt64(sp + 40, toCopy.length);
|
|
384
|
-
this.mem.setUint8(sp + 48, 1);
|
|
385
|
-
},
|
|
386
|
-
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
387
|
-
"syscall/js.copyBytesToJS": (sp) => {
|
|
388
|
-
sp >>>= 0;
|
|
389
|
-
const dst = loadValue(sp + 8);
|
|
390
|
-
const src = loadSlice(sp + 16);
|
|
391
|
-
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
392
|
-
this.mem.setUint8(sp + 48, 0);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const toCopy = src.subarray(0, dst.length);
|
|
396
|
-
dst.set(toCopy);
|
|
397
|
-
setInt64(sp + 40, toCopy.length);
|
|
398
|
-
this.mem.setUint8(sp + 48, 1);
|
|
399
|
-
},
|
|
400
|
-
"debug": (value) => {
|
|
401
|
-
console.log(value);
|
|
402
|
-
},
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
run(instance) {
|
|
407
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
-
if (!(instance instanceof WebAssembly.Instance)) {
|
|
409
|
-
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
410
|
-
}
|
|
411
|
-
this._inst = instance;
|
|
412
|
-
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
413
|
-
this._values = [
|
|
414
|
-
NaN,
|
|
415
|
-
0,
|
|
416
|
-
null,
|
|
417
|
-
true,
|
|
418
|
-
false,
|
|
419
|
-
global,
|
|
420
|
-
this,
|
|
421
|
-
];
|
|
422
|
-
this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
|
|
423
|
-
this._ids = new Map([
|
|
424
|
-
[0, 1],
|
|
425
|
-
[null, 2],
|
|
426
|
-
[true, 3],
|
|
427
|
-
[false, 4],
|
|
428
|
-
[global, 5],
|
|
429
|
-
[this, 6],
|
|
430
|
-
]);
|
|
431
|
-
this._idPool = []; // unused ids that have been garbage collected
|
|
432
|
-
this.exited = false; // whether the Go program has exited
|
|
433
|
-
// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
|
|
434
|
-
let offset = 4096;
|
|
435
|
-
const strPtr = (str) => {
|
|
436
|
-
const ptr = offset;
|
|
437
|
-
const bytes = encoder.encode(str + "\0");
|
|
438
|
-
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
439
|
-
offset += bytes.length;
|
|
440
|
-
if (offset % 8 !== 0) {
|
|
441
|
-
offset += 8 - (offset % 8);
|
|
442
|
-
}
|
|
443
|
-
return ptr;
|
|
444
|
-
};
|
|
445
|
-
const argc = this.argv.length;
|
|
446
|
-
const argvPtrs = [];
|
|
447
|
-
this.argv.forEach((arg) => {
|
|
448
|
-
argvPtrs.push(strPtr(arg));
|
|
449
|
-
});
|
|
450
|
-
argvPtrs.push(0);
|
|
451
|
-
const keys = Object.keys(this.env).sort();
|
|
452
|
-
keys.forEach((key) => {
|
|
453
|
-
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
454
|
-
});
|
|
455
|
-
argvPtrs.push(0);
|
|
456
|
-
const argv = offset;
|
|
457
|
-
argvPtrs.forEach((ptr) => {
|
|
458
|
-
this.mem.setUint32(offset, ptr, true);
|
|
459
|
-
this.mem.setUint32(offset + 4, 0, true);
|
|
460
|
-
offset += 8;
|
|
461
|
-
});
|
|
462
|
-
// The linker guarantees global data starts from at least wasmMinDataAddr.
|
|
463
|
-
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
|
|
464
|
-
const wasmMinDataAddr = 4096 + 8192;
|
|
465
|
-
if (offset >= wasmMinDataAddr) {
|
|
466
|
-
throw new Error("total length of command line and environment variables exceeds limit");
|
|
467
|
-
}
|
|
468
|
-
this._inst.exports.run(argc, argv);
|
|
469
|
-
if (this.exited) {
|
|
470
|
-
this._resolveExitPromise();
|
|
471
|
-
}
|
|
472
|
-
yield this._exitPromise;
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
_resume() {
|
|
476
|
-
if (this.exited) {
|
|
477
|
-
throw new Error("Go program has already exited");
|
|
478
|
-
}
|
|
479
|
-
this._inst.exports.resume();
|
|
480
|
-
if (this.exited) {
|
|
481
|
-
this._resolveExitPromise();
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
_makeFuncWrapper(id) {
|
|
485
|
-
const go = this;
|
|
486
|
-
return function () {
|
|
487
|
-
const event = { id: id, this: this, args: arguments };
|
|
488
|
-
go._pendingEvent = event;
|
|
489
|
-
go._resume();
|
|
490
|
-
return event.result;
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
export const go = new Go();
|
|
495
|
-
//# sourceMappingURL=go.js.map
|