| 167 | // the relative read/write methods expect the offset to be a unsigned 32-bit |
| 168 | // integer |
| 169 | export class Memory { |
| 170 | constructor(main, worker, obj, addr_addr, fake_addr) { |
| 171 | this._main = main; |
| 172 | this._worker = worker; |
| 173 | this._obj = obj; |
| 174 | this._addr_low = addr_addr.lo; |
| 175 | this._addr_high = addr_addr.hi; |
| 176 | this._fake_low = fake_addr.lo; |
| 177 | this._fake_high = fake_addr.hi; |
| 178 | |
| 179 | main[view_m_length / 4] = 0xffffffff; |
| 180 | |
| 181 | init_module(this); |
| 182 | |
| 183 | const off_mvec = view_m_vector; |
| 184 | // use this to create WastefulTypedArrays to avoid a GC crash |
| 185 | const buf = new ArrayBuffer(0); |
| 186 | |
| 187 | const src = new Uint8Array(buf); |
| 188 | const sset = new Uint32Array(buf); |
| 189 | const sset_p = this.addrof(sset); |
| 190 | sset_p.write64(off_mvec, this.addrof(src).add(off_mvec)); |
| 191 | sset_p.write32(view_m_length, 3); |
| 192 | this._cpysrc = src; |
| 193 | this._src_setter = sset; |
| 194 | |
| 195 | const dst = new Uint8Array(buf); |
| 196 | const dset = new Uint32Array(buf); |
| 197 | const dset_p = this.addrof(dset); |
| 198 | dset_p.write64(off_mvec, this.addrof(dst).add(off_mvec)); |
| 199 | dset_p.write32(view_m_length, 3); |
| 200 | dset[2] = 0xffffffff; |
| 201 | this._cpydst = dst; |
| 202 | this._dst_setter = dset; |
| 203 | } |
| 204 | |
| 205 | // dst and src may overlap |
| 206 | cpy(dst, src, len) { |
| 207 | if (!(isInteger(len) && 0 <= len && len <= 0xffffffff)) { |
| 208 | throw TypeError("len not a unsigned 32-bit integer"); |
| 209 | } |
| 210 | |
| 211 | const dvals = lohi_from_one(dst); |
| 212 | const svals = lohi_from_one(src); |
| 213 | const dset = this._dst_setter; |
| 214 | const sset = this._src_setter; |
| 215 | |
| 216 | dset[0] = dvals[0]; |
| 217 | dset[1] = dvals[1]; |
| 218 | sset[0] = svals[0]; |
| 219 | sset[1] = svals[1]; |
| 220 | sset[2] = len; |
| 221 | |
| 222 | this._cpydst.set(this._cpysrc); |
| 223 | } |
| 224 | |
| 225 | // allocate Garbage Collector managed memory. returns [address_of_memory, |
| 226 | // backer]. backer is the JSCell that is keeping the returned memory alive, |
nothing calls this directly
no outgoing calls
no test coverage detected