diff options
Diffstat (limited to 'extension/background/emscriptif.js')
-rw-r--r-- | extension/background/emscriptif.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index e9e118ed3..c12c41416 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -268,6 +268,19 @@ class PackedArenaObject extends ArenaObject { emsc.hash(this.nativePtr, this.size(), x.nativePtr); return x; } + hexdump() { + let bytes = []; + for (let i = 0; i < this.size(); i++) { + let b = Module.getValue(this.getNative() + i, "i8"); + b = (b + 256) % 256; + bytes.push("0".concat(b.toString(16)).slice(-2)); + } + let lines = []; + for (let i = 0; i < bytes.length; i += 8) { + lines.push(bytes.slice(i, i + 8).join(",")); + } + return lines.join("\n"); + } } class AmountNbo extends PackedArenaObject { size() { @@ -496,7 +509,7 @@ class AbsoluteTimeNbo extends PackedArenaObject { if (m.length != 2) { throw Error(); } - let n = parseInt(m[1]); + let n = parseInt(m[1]) * 1000000; // XXX: This only works up to 54 bit numbers. set64(x.getNative(), n); return x; @@ -508,14 +521,15 @@ class AbsoluteTimeNbo extends PackedArenaObject { // XXX: This only works up to 54 bit numbers. function set64(p, n) { for (let i = 0; i < 8; ++i) { - Module.setValue(p + (8 - i), n & 0xFF, "i8"); - n >>>= 8; + Module.setValue(p + (7 - i), n & 0xFF, "i8"); + n = Math.floor(n / 256); } } class UInt64 extends PackedArenaObject { static fromNumber(n) { let x = new UInt64(); x.alloc(); + console.log("Creating UINT64 with", n); set64(x.getNative(), n); return x; } |