| 144 | |
| 145 | global.Go = class { |
| 146 | constructor() { |
| 147 | this.argv = ["js"]; |
| 148 | this.env = {}; |
| 149 | this.exit = (code) => { |
| 150 | if (code !== 0) { |
| 151 | console.warn("exit code:", code); |
| 152 | } |
| 153 | }; |
| 154 | this._exitPromise = new Promise((resolve) => { |
| 155 | this._resolveExitPromise = resolve; |
| 156 | }); |
| 157 | this._pendingEvent = null; |
| 158 | this._scheduledTimeouts = new Map(); |
| 159 | this._nextCallbackTimeoutID = 1; |
| 160 | |
| 161 | const setInt64 = (addr, v) => { |
| 162 | this.mem.setUint32(addr + 0, v, true); |
| 163 | this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true); |
| 164 | } |
| 165 | |
| 166 | const getInt64 = (addr) => { |
| 167 | const low = this.mem.getUint32(addr + 0, true); |
| 168 | const high = this.mem.getInt32(addr + 4, true); |
| 169 | return low + high * 4294967296; |
| 170 | } |
| 171 | |
| 172 | const loadValue = (addr) => { |
| 173 | const f = this.mem.getFloat64(addr, true); |
| 174 | if (f === 0) { |
| 175 | return undefined; |
| 176 | } |
| 177 | if (!isNaN(f)) { |
| 178 | return f; |
| 179 | } |
| 180 | |
| 181 | const id = this.mem.getUint32(addr, true); |
| 182 | return this._values[id]; |
| 183 | } |
| 184 | |
| 185 | const storeValue = (addr, v) => { |
| 186 | const nanHead = 0x7FF80000; |
| 187 | |
| 188 | if (typeof v === "number" && v !== 0) { |
| 189 | if (isNaN(v)) { |
| 190 | this.mem.setUint32(addr + 4, nanHead, true); |
| 191 | this.mem.setUint32(addr, 0, true); |
| 192 | return; |
| 193 | } |
| 194 | this.mem.setFloat64(addr, v, true); |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | if (v === undefined) { |
| 199 | this.mem.setFloat64(addr, 0, true); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | let id = this._ids.get(v); |