From 99b14a882ac0e5356fdd149392afe43378b70e6f Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Mon, 22 Jul 2019 14:16:44 -0400 Subject: [PATCH 01/14] [Implement] Buffer#concat (todo: fix tlsf problem) --- assembly/buffer/index.ts | 42 +++++++++++++++++++++++++++++++++++++++- assembly/node.d.ts | 2 ++ tests/buffer.spec.ts | 33 +++++++++++++++++++++++++++---- tests/node.js | 39 ++----------------------------------- 4 files changed, 74 insertions(+), 42 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 769dd8a..a0796a6 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -2,6 +2,8 @@ import { BLOCK_MAXSIZE } from "rt/common"; import { E_INVALIDLENGTH, E_INDEXOUTOFRANGE } from "util/error"; import { Uint8Array } from "typedarray"; +const BUFFER_INSPECT_HEADER_START: string = "(this.dataStart + offset, value); return offset + 1; } - + readInt8(offset: i32 = 0): i8 { if(offset >= this.dataLength) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + usize(offset)); } + + public INSPECT_MAX_BYTES: i32 = 50; + + inspect(): string { + let length = this.byteLength; + let dataStart = this.dataStart; + let maxBytes = this.INSPECT_MAX_BYTES; + + // formula for calculating end string length (length * 2) + length - 1 + 9 + // Example: Buffer.from([1, 2, 3, 4, 5]).inspect() == '' + let totalBytes = (min(length, maxBytes) * 3 + 8) << 1; // two bytes * formula + let buffer = __alloc(totalBytes, idof()); + + let source = "(source), 16); // copy the 16 "(i << 1) * 3; + let byte = load(dataStart + i); + let top = (byte >>> 4) & 0xF; + byte &= 0xF; + + store(writeOffset, top < 10 ? top + 48 : top + 87); + store(writeOffset, byte < 10 ? byte + 48 : byte + 87, 2); + + if (i < (maxBytes - 1)) { + store(writeOffset, (i == (length - 1) ? 62 : 32), 4); // " " | ">" + } else { + // TODO: Optimize this into a single u64 store + store(writeOffset, 46, 4); // "." + store(writeOffset, 46, 6); // "." + store(writeOffset, 46, 8); // "." + store(writeOffset, 62, 10); // ">" + break; + } + } + + return changetype(buffer); + } } diff --git a/assembly/node.d.ts b/assembly/node.d.ts index 895ea93..4ac5268 100644 --- a/assembly/node.d.ts +++ b/assembly/node.d.ts @@ -11,4 +11,6 @@ declare class Buffer extends Uint8Array { writeInt8(value:i8, offset?:i32): i32; /** Reads a signed integer at the designated offset. */ readInt8(offset?: i32): i8; + /** Inspect a buffer. */ + inspect(): string; } diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index 9ba33fe..2994623 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -53,10 +53,10 @@ describe("buffer", () => { // Testing offset expect(buff.readUInt8(9)).toBe(47); // TODO: - // expectFn(() => { + // expectFn(() => { // let newBuff = new Buffer(1); // newBuff.readUInt8(5); - // }).toThrow(); + // }).toThrow(); }); test("#writeUInt8", () => { @@ -65,7 +65,7 @@ describe("buffer", () => { expect(buff.writeUInt8(252,4)).toBe(5); expect(buff[0]).toBe(4); expect(buff[4]).toBe(252); - }); + }); test("#writeInt8", () => { let buff = new Buffer(5); @@ -84,9 +84,34 @@ describe("buffer", () => { // Testing offset, and casting between u8 and i8. expect(buff.readInt8(9)).toBe(-1); // TODO: - // expectFn(() => { + // expectFn(() => { // let newBuff = new Buffer(1); // newBuff.readInt8(5); // }).toThrow(); }); + + test("#inspect", () => { + let buff = new Buffer(16); + buff[0] = 0; + buff[1] = 1; + buff[2] = 2; + buff[3] = 3; + buff[4] = 4; + buff[5] = 5; + buff[6] = 6; + buff[7] = 7; + buff[8] = 8; + buff[9] = 9; + buff[10] = 10; + buff[11] = 11; + buff[12] = 12; + buff[13] = 13; + buff[14] = 14; + buff[15] = 15; + let result = buff.inspect(); + expect(result).toBe(""); + buff.INSPECT_MAX_BYTES = 5; + result = buff.inspect(); + expect(result).toBe(""); + }); }); diff --git a/tests/node.js b/tests/node.js index 5cb4a58..a0d5797 100644 --- a/tests/node.js +++ b/tests/node.js @@ -1,4 +1,4 @@ -const { TestContext, EmptyReporter } = require("@as-pect/core"); +const { TestContext, VerboseReporter } = require("@as-pect/core"); const { instantiateBuffer } = require("assemblyscript/lib/loader"); const glob = require("glob"); const { main } = require("assemblyscript/cli/asc"); @@ -7,7 +7,6 @@ const path = require("path"); const fs = require("fs"); const Wasi = require("wasi"); const wasi = new Wasi({}); -const diff = require("diff"); const options = parse(process.argv.slice(2), { "help": { @@ -27,41 +26,7 @@ if (options.unknown.length > 1) { process.exit(1); } -class Reporter extends EmptyReporter { - onGroupFinish(group) { - if (group.name) { - if (group.pass) process.stdout.write("Group : " + group.name + " -> ✔ PASS"); - else process.stdout.write("Group : " + group.name + " -> ❌ FAIL"); - process.stdout.write("\n"); - } - } - - onTestFinish(group, test) { - if (test.pass) process.stdout.write("Test : " + group.name + " -> " + test.name + " ✔ PASS\n"); - else process.stdout.write("Test : " + group.name + " -> " + test.name + " ❌ FAIL\n"); - - if (!test.pass) { - process.stdout.write("Actual : " + test.actual.message + "\n"); - process.stdout.write("Expected : " + test.expected.message + "\n"); - } - - if (test.logs.length > 0) { - test.logs.forEach((e, i) => { - if (i > 0) process.stdout.write("\n"); - process.stdout.write("Log : " + e.value); - }); - process.stdout.write("\n"); - } - } - onFinish(context) { - const passed = context.testGroups.filter(e => !e.pass).length === 0; - if (passed) process.stdout.write("Suite : ✔ PASS"); - else process.stdout.write("Suite : ❌ FAIL"); - process.stdout.write("\n"); - } -} - -const reporter = new Reporter(); +const reporter = new VerboseReporter(); function relativeFromCwd(location) { return path.relative(process.cwd(), location); From 881217202a452e6a19b576f613ae92e5cb20be0b Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 23 Jul 2019 09:44:48 -0400 Subject: [PATCH 02/14] [Fix] Clean up inspect implementation --- assembly/buffer/index.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index a0796a6..40a66a2 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -50,19 +50,21 @@ export class Buffer extends Uint8Array { public INSPECT_MAX_BYTES: i32 = 50; inspect(): string { - let length = this.byteLength; + let byteLength = this.byteLength; let dataStart = this.dataStart; - let maxBytes = this.INSPECT_MAX_BYTES; - - // formula for calculating end string length (length * 2) + length - 1 + 9 + let INSPECT_MAX_BYTES = this.INSPECT_MAX_BYTES; + let elipsisEnd = byteLength > INSPECT_MAX_BYTES; + let maxBytes = elipsisEnd ? INSPECT_MAX_BYTES : byteLength; + // formula for calculating end string length (3 * bytes) + 8 // Example: Buffer.from([1, 2, 3, 4, 5]).inspect() == '' - let totalBytes = (min(length, maxBytes) * 3 + 8) << 1; // two bytes * formula - let buffer = __alloc(totalBytes, idof()); + let stringLength = 3 * maxBytes + 8; + if (elipsisEnd) stringLength += 3; // add 3 characters for elipsis + let buffer = __alloc(stringLength << 1, idof()); let source = "(source), 16); // copy the 16 "(i << 1) * 3; + let writeOffset = buffer + 16; + for (let i = 0; i < maxBytes; i++, writeOffset += 6) { let byte = load(dataStart + i); let top = (byte >>> 4) & 0xF; byte &= 0xF; @@ -70,15 +72,15 @@ export class Buffer extends Uint8Array { store(writeOffset, top < 10 ? top + 48 : top + 87); store(writeOffset, byte < 10 ? byte + 48 : byte + 87, 2); - if (i < (maxBytes - 1)) { - store(writeOffset, (i == (length - 1) ? 62 : 32), 4); // " " | ">" + if (i == (maxBytes - 1)) { + if (elipsisEnd) { + // make this a single 64 bit store + store(writeOffset, 17451646127570990, 4); // "...>" + } else { + store(writeOffset, 62, 4); // ">" + } } else { - // TODO: Optimize this into a single u64 store - store(writeOffset, 46, 4); // "." - store(writeOffset, 46, 6); // "." - store(writeOffset, 46, 8); // "." - store(writeOffset, 62, 10); // ">" - break; + store(writeOffset, 32, 4); // " " } } From 01d079b1cfa786c5b60e972ae8c03fdf8aae7872 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 23 Jul 2019 09:59:25 -0400 Subject: [PATCH 03/14] [Fix] Edge case when length = 0, todo: more optimization --- assembly/buffer/index.ts | 21 ++++++++++++++++----- tests/buffer.spec.ts | 21 +++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 40a66a2..b2f443a 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -51,19 +51,30 @@ export class Buffer extends Uint8Array { inspect(): string { let byteLength = this.byteLength; - let dataStart = this.dataStart; let INSPECT_MAX_BYTES = this.INSPECT_MAX_BYTES; + if (INSPECT_MAX_BYTES == 0 || byteLength == 0) return ""; + + // Calculate if an elipsis will be in the string let elipsisEnd = byteLength > INSPECT_MAX_BYTES; let maxBytes = elipsisEnd ? INSPECT_MAX_BYTES : byteLength; + + // find the start of the buffer + let dataStart = this.dataStart; + // formula for calculating end string length (3 * bytes) + 8 // Example: Buffer.from([1, 2, 3, 4, 5]).inspect() == '' let stringLength = 3 * maxBytes + 8; if (elipsisEnd) stringLength += 3; // add 3 characters for elipsis - let buffer = __alloc(stringLength << 1, idof()); + // create the result + let result = __alloc(stringLength << 1, idof()); + + // copy the 16 "(source), 16); // copy the 16 "(source), 16); + + // Start writing at index 8 + let writeOffset: usize = result + 16; for (let i = 0; i < maxBytes; i++, writeOffset += 6) { let byte = load(dataStart + i); let top = (byte >>> 4) & 0xF; @@ -84,6 +95,6 @@ export class Buffer extends Uint8Array { } } - return changetype(buffer); + return changetype(result); } } diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index 2994623..167ee67 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -92,26 +92,15 @@ describe("buffer", () => { test("#inspect", () => { let buff = new Buffer(16); - buff[0] = 0; - buff[1] = 1; - buff[2] = 2; - buff[3] = 3; - buff[4] = 4; - buff[5] = 5; - buff[6] = 6; - buff[7] = 7; - buff[8] = 8; - buff[9] = 9; - buff[10] = 10; - buff[11] = 11; - buff[12] = 12; - buff[13] = 13; - buff[14] = 14; - buff[15] = 15; + for (let i = 0; i < 16; i++) buff[i] = i; let result = buff.inspect(); expect(result).toBe(""); buff.INSPECT_MAX_BYTES = 5; result = buff.inspect(); expect(result).toBe(""); + + buff = new Buffer(0); + result = buff.inspect() + expect(result).toBe(""); }); }); From 10a5c54945865baa7886c8027cf856c8d2aece72 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 23 Jul 2019 14:31:14 -0400 Subject: [PATCH 04/14] [Chore] switch to global --- assembly/buffer/index.ts | 5 ++--- assembly/node.d.ts | 16 ++++++++++++++++ tests/buffer.spec.ts | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index b2f443a..de9580f 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -4,6 +4,8 @@ import { Uint8Array } from "typedarray"; const BUFFER_INSPECT_HEADER_START: string = "(this.dataStart + usize(offset)); } - public INSPECT_MAX_BYTES: i32 = 50; - inspect(): string { let byteLength = this.byteLength; - let INSPECT_MAX_BYTES = this.INSPECT_MAX_BYTES; if (INSPECT_MAX_BYTES == 0 || byteLength == 0) return ""; // Calculate if an elipsis will be in the string diff --git a/assembly/node.d.ts b/assembly/node.d.ts index 4ac5268..10625c3 100644 --- a/assembly/node.d.ts +++ b/assembly/node.d.ts @@ -14,3 +14,19 @@ declare class Buffer extends Uint8Array { /** Inspect a buffer. */ inspect(): string; } + +declare module "buffer" { + /** + * The maximum number of bytes to inspect on a buffer. + * + * @example + * import { INSPECT_MAX_BYTES } from "buffer"; + * // @ts-ignore: This is treated like a global + * INSPECT_MAX_BYTES = 10; + */ + export var INSPECT_MAX_BYTES: i32; + + // To export the buffer, we must obtain the `typeof Buffer` + const BuffType: typeof Buffer; + export { BuffType as Buffer }; +} diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index 167ee67..fdf1d8e 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -10,6 +10,7 @@ * }); */ import { BLOCK_MAXSIZE } from "rt/common"; +import { INSPECT_MAX_BYTES } from "buffer"; describe("buffer", () => { test("#constructor", () => { @@ -95,7 +96,7 @@ describe("buffer", () => { for (let i = 0; i < 16; i++) buff[i] = i; let result = buff.inspect(); expect(result).toBe(""); - buff.INSPECT_MAX_BYTES = 5; + INSPECT_MAX_BYTES = 5; result = buff.inspect(); expect(result).toBe(""); From f418fd039eea0e51a0d679eb46c3f31405973274 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 23 Jul 2019 15:16:37 -0400 Subject: [PATCH 05/14] [Optimize] memory.copy parameters with global strings --- assembly/buffer/index.ts | 10 ++++++---- tests/node.js | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 6b63478..b8e53cc 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -1,7 +1,6 @@ -import { BLOCK_MAXSIZE } from "rt/common"; +import { BLOCK_MAXSIZE, BLOCK, BLOCK_OVERHEAD } from "rt/common"; import { E_INVALIDLENGTH, E_INDEXOUTOFRANGE } from "util/error"; import { Uint8Array } from "typedarray"; - const BUFFER_INSPECT_HEADER_START: string = "()); // copy the 16 "(source), 16); + memory.copy( + result, + changetype(BUFFER_INSPECT_HEADER_START), + changetype(changetype(BUFFER_INSPECT_HEADER_START) - BLOCK_OVERHEAD).rtSize, + ); // Start writing at index 8 let writeOffset: usize = result + 16; diff --git a/tests/node.js b/tests/node.js index c652c1e..0b5a3d4 100644 --- a/tests/node.js +++ b/tests/node.js @@ -109,9 +109,7 @@ function runTest(file, type, binary, wat) { + "." + type + ".wat"; // should not block testing - fs.writeFile(watPath, wat, (err) => { - if (err) console.warn(err); - }); + fs.writeFileSync(watPath, wat); const context = new TestContext({ fileName: file, From 628562ca10599c80aa75d06b1c8abfc2a051c04e Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 10:56:03 -0400 Subject: [PATCH 06/14] [Fix] switch to hex --- assembly/buffer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 7a11708..0117bfd 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -276,7 +276,7 @@ export class Buffer extends Uint8Array { if (i == (maxBytes - 1)) { if (elipsisEnd) { // make this a single 64 bit store - store(writeOffset, 17451646127570990, 4); // "...>" + store(writeOffset, 0x003e_002e_002e_002e, 4); // "...>" } else { store(writeOffset, 62, 4); // ">" } From b956d5e063c8b5e1610591dce448b81b1e113fb2 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 11:00:53 -0400 Subject: [PATCH 07/14] [Fix] types merge problem --- assembly/node.d.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/assembly/node.d.ts b/assembly/node.d.ts index d41c617..c2df1f7 100644 --- a/assembly/node.d.ts +++ b/assembly/node.d.ts @@ -13,24 +13,6 @@ declare class Buffer extends Uint8Array { writeInt8(value:i8, offset?:i32): i32; /** Reads a signed integer at the designated offset. */ readInt8(offset?: i32): i8; - /** Inspect a buffer. */ - inspect(): string; -} - -declare module "buffer" { - /** - * The maximum number of bytes to inspect on a buffer. - * - * @example - * import { INSPECT_MAX_BYTES } from "buffer"; - * // @ts-ignore: This is treated like a global - * INSPECT_MAX_BYTES = 10; - */ - export var INSPECT_MAX_BYTES: i32; - - // To export the buffer, we must obtain the `typeof Buffer` - const BuffType: typeof Buffer; - export { BuffType as Buffer }; /** Writes an inputted u8 value to the buffer, at the desired offset. */ writeUInt8(value:u8, offset?:i32): i32; /** Reads a signed 16-bit integer, stored in Little Endian format at the designated offset. */ @@ -97,6 +79,24 @@ declare module "buffer" { writeDoubleLE(value: f64, offset?: i32): i32; /** Writes an inputted 64-bit double at the designated offset, stored in Big Endian format */ writeDoubleBE(value: f64, offset?: i32): i32; + /** Inspect a buffer. */ + inspect(): string; +} + +declare module "buffer" { + /** + * The maximum number of bytes to inspect on a buffer. + * + * @example + * import { INSPECT_MAX_BYTES } from "buffer"; + * // @ts-ignore: This is treated like a global + * INSPECT_MAX_BYTES = 10; + */ + export var INSPECT_MAX_BYTES: i32; + + // To export the buffer, we must obtain the `typeof Buffer` + const BuffType: typeof Buffer; + export { BuffType as Buffer }; } declare namespace Buffer { From e8afe8507aad68355f56608716a2adc2474f7bc8 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 11:20:52 -0400 Subject: [PATCH 08/14] [fix] example --- assembly/buffer/index.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 0117bfd..bec0402 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -241,6 +241,13 @@ export class Buffer extends Uint8Array { return offset + 8; } + /** + * Calculate an inspectable string to print to the console. + * + * @example + * let result = Buffer.from([1, 2, 3, 4, 5]).inspect(); + * // '' + */ inspect(): string { let byteLength = this.byteLength; if (INSPECT_MAX_BYTES == 0 || byteLength == 0) return ""; @@ -252,10 +259,22 @@ export class Buffer extends Uint8Array { // find the start of the buffer let dataStart = this.dataStart; - // formula for calculating end string length (3 * bytes) + 8 - // Example: Buffer.from([1, 2, 3, 4, 5]).inspect() == '' - let stringLength = 3 * maxBytes + 8; - if (elipsisEnd) stringLength += 3; // add 3 characters for elipsis + /** + * Formula for stringLength is calculated by adding the constant character count + * to the number of visible bytes multiplied by 3, and adding 3 more for an ellipsis + * if the total number of visible bytes is less than the actual byteLength. + * + * @example + * let stringLength = (3 * maxBytes) + len("") + (elipsisEnd ? 3 : 0); + * + * // This can be reduced to... + * let stringLength = (3 * maxBytes) + 8 + (elipsisEnd ? 3 : 0); + * + * // finally, `a * 3 + 3` is the same thing as `(a + 1) * 3` + * // we can cast `elipsisEnd` to an integer `1 | 0` + * let stringLength = 3 * (maxBytes + i32(elipsisEnd)) + 8; + */ + let stringLength = 3 * (maxBytes + i32(elipsisEnd)) + 8; // add 3 characters for elipsis // create the result let result = __alloc(stringLength << 1, idof()); From b9ed343dbac0cadc428519e5dfd8d208a3ca36ff Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 11:45:24 -0400 Subject: [PATCH 09/14] [chore] remove unecessary comment --- assembly/buffer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index bec0402..abd9ff0 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -274,7 +274,7 @@ export class Buffer extends Uint8Array { * // we can cast `elipsisEnd` to an integer `1 | 0` * let stringLength = 3 * (maxBytes + i32(elipsisEnd)) + 8; */ - let stringLength = 3 * (maxBytes + i32(elipsisEnd)) + 8; // add 3 characters for elipsis + let stringLength = 3 * (maxBytes + i32(elipsisEnd)) + 8; // create the result let result = __alloc(stringLength << 1, idof()); From a5579cba6abb76aef75ae8be4511eb8cce2c1033 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 11:54:11 -0400 Subject: [PATCH 10/14] [fix] nit remove parenthesis --- assembly/buffer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index abd9ff0..c1861a1 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -292,7 +292,7 @@ export class Buffer extends Uint8Array { let byte = load(dataStart + i); store(writeOffset, Buffer.HEX.charsFromByte(byte)); - if (i == (maxBytes - 1)) { + if (i == maxBytes - 1) { if (elipsisEnd) { // make this a single 64 bit store store(writeOffset, 0x003e_002e_002e_002e, 4); // "...>" From 11cc4d32662e03e734b46071c390de183a87ddb5 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 11:56:18 -0400 Subject: [PATCH 11/14] [fix] remove type annotation --- assembly/buffer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index c1861a1..e98035b 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -287,7 +287,7 @@ export class Buffer extends Uint8Array { ); // Start writing at index 8 - let writeOffset: usize = result + 16; + let writeOffset = result + 16; for (let i = 0; i < maxBytes; i++, writeOffset += 6) { let byte = load(dataStart + i); From a00145cf30933841d0536a4ef76b7bfab501916c Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 12:02:23 -0400 Subject: [PATCH 12/14] [test] use create convenience method instead --- tests/buffer.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index 148591a..217d420 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -143,8 +143,7 @@ describe("buffer", () => { test("#inspect", () => { - let buff = new Buffer(16); - for (let i = 0; i < 16; i++) buff[i] = i; + let buff = create([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]); let result = buff.inspect(); expect(result).toBe(""); INSPECT_MAX_BYTES = 5; From ef7e34e1963110387c4424d0f598704688234da4 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 12:17:41 -0400 Subject: [PATCH 13/14] [fix] switch to known constant --- assembly/buffer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index e98035b..e2a856e 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -283,7 +283,7 @@ export class Buffer extends Uint8Array { memory.copy( result, changetype(BUFFER_INSPECT_HEADER_START), - changetype(changetype(BUFFER_INSPECT_HEADER_START) - BLOCK_OVERHEAD).rtSize, + 16, ); // Start writing at index 8 From 5fe8a7f704022917a290c54a10925c2e9a30c767 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Tue, 6 Aug 2019 12:21:57 -0400 Subject: [PATCH 14/14] [fix] add BUFFER_INSPECT_HEADER_BYTE_LEN constant --- assembly/buffer/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index e2a856e..6201e2d 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -1,7 +1,8 @@ import { BLOCK_MAXSIZE, BLOCK, BLOCK_OVERHEAD } from "rt/common"; import { E_INVALIDLENGTH, E_INDEXOUTOFRANGE } from "util/error"; import { Uint8Array } from "typedarray"; -const BUFFER_INSPECT_HEADER_START: string = "(BUFFER_INSPECT_HEADER_START), - 16, + BUFFER_INSPECT_HEADER_BYTE_LEN, ); // Start writing at index 8 - let writeOffset = result + 16; + let writeOffset = result + BUFFER_INSPECT_HEADER_BYTE_LEN; for (let i = 0; i < maxBytes; i++, writeOffset += 6) { let byte = load(dataStart + i);