From abf1c7064f7a0aaece72ba274ca3692770d9f38d Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Mon, 2 Mar 2020 16:34:23 -0500 Subject: [PATCH 1/7] update to latest as-pect, fix ArrayBufferView errors --- assembly/buffer/index.ts | 136 ++++++++++++++++--------------- package-lock.json | 172 +++++++++++---------------------------- package.json | 9 +- tests/node.js | 27 ++++-- 4 files changed, 141 insertions(+), 203 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 363ab5e..805de87 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -12,15 +12,18 @@ export class Buffer extends Uint8Array { } @unsafe static allocUnsafe(size: i32): Buffer { - // Node throws an error if size is less than 0 - if (size > BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH); + // range must be valid + if (i32(size > BLOCK_MAXSIZE) | i32(size < 0)) throw new RangeError(E_INVALIDLENGTH); let buffer = __alloc(size, idof()); - // This retains the pointer to the result Buffer. - let result = changetype(__alloc(offsetof(), idof())); - result.data = changetype(buffer); - result.dataStart = buffer; - result.dataLength = size; - return result; + let result = __alloc(offsetof(), idof()); + + // set the properties + store(result, __retain(buffer), offsetof("buffer")); + store(result, buffer, offsetof("dataStart")); + store(result, size, offsetof("byteLength")); + + // return and retain + return changetype(result); } static isBuffer(value: T): bool { @@ -29,222 +32,225 @@ export class Buffer extends Uint8Array { // Adapted from https://github.com/AssemblyScript/assemblyscript/blob/master/std/assembly/typedarray.ts subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Buffer { - var len = this.dataLength; + var len = this.byteLength; begin = begin < 0 ? max(len + begin, 0) : min(begin, len); end = end < 0 ? max(len + end, 0) : min(end, len); end = max(end, begin); - var out = changetype(__alloc(offsetof(), idof())); // retains - out.data = this.data; // retains - out.dataStart = this.dataStart + begin; - out.dataLength = end - begin; - return out; + + var out = __alloc(offsetof(), idof()); // retains + store(out, __retain(changetype(this.buffer)), offsetof("buffer")); + store(out, this.dataStart + begin, offsetof("dataStart")); + store(out, end - begin, offsetof("byteLength")); + + // retains + return changetype(out); } readInt8(offset: i32 = 0): i8 { - if (i32(offset < 0) | i32(offset >= this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset >= this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readUInt8(offset: i32 = 0): u8 { - if (i32(offset < 0) | i32(offset >= this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset >= this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } writeInt8(value: i8, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset >= this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset >= this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 1; } writeUInt8(value: u8, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset >= this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset >= this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 1; } readInt16LE(offset: i32 = 0): i16 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readInt16BE(offset: i32 = 0): i16 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return bswap(load(this.dataStart + offset)); } readUInt16LE(offset: i32 = 0): u16 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readUInt16BE(offset: i32 = 0): u16 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return bswap(load(this.dataStart + offset)); } writeInt16LE(value: i16, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 2; } writeInt16BE(value: i16, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(value)); return offset + 2; } writeUInt16LE(value: u16, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 2; } writeUInt16BE(value: u16, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 2 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 2 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(value)); return offset + 2; } readInt32LE(offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readInt32BE(offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return bswap(load(this.dataStart + offset)); } readUInt32LE(offset: i32 = 0): u32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readUInt32BE(offset: i32 = 0): u32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return bswap(load(this.dataStart + offset)); } writeInt32LE(value: i32, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 4; } writeInt32BE(value: i32, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(value)); return offset + 4; } writeUInt32LE(value: u32, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 4; } writeUInt32BE(value: u32, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(value)); return offset + 4; } readFloatLE(offset: i32 = 0): f32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readFloatBE(offset: i32 = 0): f32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return reinterpret(bswap(load(this.dataStart + offset))); } writeFloatLE(value: f32, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 4; } writeFloatBE(value: f32, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 4 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 4 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(reinterpret(value))); return offset + 4; } readBigInt64LE(offset: i32 = 0): i64 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readBigInt64BE(offset: i32 = 0): i64 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return bswap(load(this.dataStart + offset)); } readBigUInt64LE(offset: i32 = 0): u64 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readBigUInt64BE(offset: i32 = 0): u64 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return bswap(load(this.dataStart + offset)); } writeBigInt64LE(value: i64, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 8; } writeBigInt64BE(value: i64, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(value)); return offset + 8; } writeBigUInt64LE(value: u64, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 8; } writeBigUInt64BE(value: u64, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(value)); return offset + 8; } readDoubleLE(offset: i32 = 0): f64 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return load(this.dataStart + offset); } readDoubleBE(offset: i32 = 0): f64 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); return reinterpret(bswap(load(this.dataStart + offset))); } writeDoubleLE(value: f64, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, value); return offset + 8; } writeDoubleBE(value: f64, offset: i32 = 0): i32 { - if (i32(offset < 0) | i32(offset + 8 > this.dataLength)) throw new RangeError(E_INDEXOUTOFRANGE); + if (i32(offset < 0) | i32(offset + 8 > this.byteLength)) throw new RangeError(E_INDEXOUTOFRANGE); store(this.dataStart + offset, bswap(reinterpret(value))); return offset + 8; } swap16(): Buffer { - let dataLength = this.dataLength; - // Make sure dataLength is even - if (dataLength & 1) throw new RangeError(E_INVALIDLENGTH); + let byteLength = this.byteLength; + // Make sure byteLength is even + if (byteLength & 1) throw new RangeError(E_INVALIDLENGTH); let dataStart = this.dataStart; - dataLength += dataStart; - while (dataStart < dataLength) { + byteLength += dataStart; + while (dataStart < byteLength) { store(dataStart, bswap(load(dataStart))); dataStart += 2; } @@ -252,12 +258,12 @@ export class Buffer extends Uint8Array { } swap32(): Buffer { - let dataLength = this.dataLength; - // Make sure dataLength is divisible by 4 - if (dataLength & 3) throw new RangeError(E_INVALIDLENGTH); + let byteLength = this.byteLength; + // Make sure byteLength is divisible by 4 + if (byteLength & 3) throw new RangeError(E_INVALIDLENGTH); let dataStart = this.dataStart; - dataLength += dataStart; - while (dataStart < dataLength) { + byteLength += dataStart; + while (dataStart < byteLength) { store(dataStart, bswap(load(dataStart))); dataStart += 4; } @@ -265,12 +271,12 @@ export class Buffer extends Uint8Array { } swap64(): Buffer { - let dataLength = this.dataLength; - // Make sure dataLength is divisible by 8 - if (dataLength & 7) throw new RangeError(E_INVALIDLENGTH); + let byteLength = this.byteLength; + // Make sure byteLength is divisible by 8 + if (byteLength & 7) throw new RangeError(E_INVALIDLENGTH); let dataStart = this.dataStart; - dataLength += dataStart; - while (dataStart < dataLength) { + byteLength += dataStart; + while (dataStart < byteLength) { store(dataStart, bswap(load(dataStart))); dataStart += 8; } diff --git a/package-lock.json b/package-lock.json index 05a35d2..1c42566 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,49 +5,46 @@ "requires": true, "dependencies": { "@as-pect/assembly": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-2.3.1.tgz", - "integrity": "sha512-KYBhyTEnaVcJjN/1EpzLhpbUHKT3pJjCPxm+Mdc7obnZ9EdVz6vN/lw+BQjeL4cUi1YLsnvgl8ftXcup5jVbQA==", + "version": "3.1.0-alpha.0", + "resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-3.1.0-alpha.0.tgz", + "integrity": "sha512-/WA1SZnfKvXqQEYgVxub4kHi1YDccnrCFWE3mBHz3BECNGrealVWv2RYqANl26ZACdz1PxG95DGyEl6OvyNu3g==", "dev": true }, "@as-pect/core": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/@as-pect/core/-/core-2.3.1.tgz", - "integrity": "sha512-iwd4MkGuO1wZqo9/sPlT567XYK0PkMLzBvwfkXOM2zq1wwuc5GZQrKoofgYorA40KI0edJW39djtOmPwIhx2vA==", + "version": "3.1.0-alpha.0", + "resolved": "https://registry.npmjs.org/@as-pect/core/-/core-3.1.0-alpha.0.tgz", + "integrity": "sha512-5XfvlZHGD5f47Ppc41eVxF5j/L/iFUZLpDz37slunEPipI3JIHUNraUj+hJEIsCbkX6zdlsluMxtr7IYVg1jmQ==", "dev": true, "requires": { - "@as-pect/assembly": "^2.3.1", - "chalk": "^2.4.2", - "csv-stringify": "^5.3.0", + "@as-pect/assembly": "^3.1.0-alpha.0", + "chalk": "^3.0.0", "long": "^4.0.0" } }, - "@protobufjs/utf8": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", - "integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=", + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "dev": true, "requires": { - "color-convert": "^1.9.0" + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" } }, "assemblyscript": { - "version": "github:assemblyscript/assemblyscript#227c626921175ab19701752397fa513171750d38", - "from": "github:assemblyscript/assemblyscript", + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.9.2.tgz", + "integrity": "sha512-eqPbxS323ivXdUclGJjvihxEEMBaXcNYHLb17j3j3UaYvkqVPNSrNuJ/H1r7G/UwmQnFQ8NDrQ9BncOFCGmahg==", "dev": true, "requires": { - "@protobufjs/utf8": "^1.1.0", - "binaryen": "87.0.0-nightly.20190716", - "glob": "^7.1.4", - "long": "^4.0.0", - "opencollective-postinstall": "^2.0.0", - "source-map-support": "^0.5.12" + "binaryen": "90.0.0-nightly.20200214", + "long": "^4.0.0" } }, "balanced-match": { @@ -57,20 +54,11 @@ "dev": true }, "binaryen": { - "version": "87.0.0-nightly.20190716", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-87.0.0-nightly.20190716.tgz", - "integrity": "sha512-qRGfV8cLV4HVVo1oUCtTaDmOhbwctaW7vyW0G6HKftywWOJI9t9IsCrUEFKya50RqyEnanuS2w3nfOg4bxTGqg==", + "version": "90.0.0-nightly.20200214", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-90.0.0-nightly.20200214.tgz", + "integrity": "sha512-ZHajaPd2aP6kDrM9q77afnA402Ufsuw9yLUxtAfgmIglP1JMB2XSRmaXc5pgCELaX53PWJIdcH07LL8uNfTBRw==", "dev": true }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "dev": true, - "requires": { - "file-uri-to-path": "1.0.0" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -81,36 +69,29 @@ "concat-map": "0.0.1" } }, - "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", - "dev": true - }, "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", "dev": true, "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" } }, "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "requires": { - "color-name": "1.1.3" + "color-name": "~1.1.4" } }, "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, "concat-map": { @@ -119,28 +100,6 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, - "csv-stringify": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/csv-stringify/-/csv-stringify-5.3.0.tgz", - "integrity": "sha512-VMYPbE8zWz475smwqb9VbX9cj0y4J0PBl59UdcqzLkzXHZZ8dh4Rmbb0ZywsWEtUml4A96Hn7Q5MW9ppVghYzg==", - "dev": true, - "optional": true, - "requires": { - "lodash.get": "~4.4.2" - } - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "dev": true - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -148,9 +107,9 @@ "dev": true }, "glob": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", - "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -162,9 +121,9 @@ } }, "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, "inflight": { @@ -183,13 +142,6 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, - "lodash.get": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", - "dev": true, - "optional": true - }, "long": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", @@ -214,49 +166,19 @@ "wrappy": "1" } }, - "opencollective-postinstall": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz", - "integrity": "sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==", - "dev": true - }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - }, - "source-map-support": { - "version": "0.5.12", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", - "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, - "wasi": { - "version": "github:devsnek/node-wasi#12a0985a46589587facd8d8e161911650ef15f3b", - "from": "github:devsnek/node-wasi", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", "dev": true, "requires": { - "bindings": "^1.5.0" + "has-flag": "^4.0.0" } }, "wrappy": { diff --git a/package.json b/package.json index ff4bc6b..de83423 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,12 @@ "url": "https://github.com/AssemblyScript/node/issues" }, "devDependencies": { - "@as-pect/core": "^2.3.1", - "assemblyscript": "github:assemblyscript/assemblyscript", - "glob": "^7.1.4", - "wasi": "github:devsnek/node-wasi" + "@as-pect/core": "^3.1.0-alpha.0", + "assemblyscript": "^0.9.2", + "glob": "^7.1.4" }, "scripts": { - "test": "node tests/node" + "test": "node --experimental-wasi-unstable-preview1 tests/node" }, "dependencies": {} } diff --git a/tests/node.js b/tests/node.js index c652c1e..11fbd25 100644 --- a/tests/node.js +++ b/tests/node.js @@ -5,8 +5,14 @@ const { main } = require("assemblyscript/cli/asc"); const { parse } = require("assemblyscript/cli/util/options"); const path = require("path"); const fs = require("fs"); -const Wasi = require("wasi"); -const wasi = new Wasi({}); +const { WASI } = require("wasi"); +const wasi = new WASI({ + args: [], + env: {}, + preopens: { + // '/sandbox': '/some/real/path/that/wasm/can/access' + } +}); let pass = true; const options = parse(process.argv.slice(2), { @@ -28,6 +34,8 @@ if (options.unknown.length > 1) { } const reporter = new VerboseReporter(); +reporter.stderr = process.stderr; +reporter.stdout = process.stdout; function relativeFromCwd(location) { return path.relative(process.cwd(), location); @@ -38,9 +46,9 @@ const ascOptions = [ "--use", "ASC_RTRACE=1", "--explicitStart", "--validate", - "--debug", "--measure", "--lib", "assembly", + "--transform", require.resolve("@as-pect/core/lib/transform/index.js"), ]; const files = glob.sync("tests/**/*.spec.ts") @@ -74,10 +82,15 @@ for (const file of files) { const ext = path.extname(file); const wasmFileName = path.join(path.dirname(file), path.basename(file, ext)) + ".wasm"; const watFileName = path.join(path.dirname(file), path.basename(file, ext)) + ".wat"; - const cliOptions = ascOptions.concat([file, "--binaryFile", wasmFileName, "--textFile", watFileName]); + + const cliOptions = ascOptions.concat([ + file, + "--binaryFile", wasmFileName, + "--textFile", watFileName, + ]); process.stdout.write("Test File : " + file + " (untouched)\n"); - main(cliOptions, untouchedAscOptions, (err) => { + main(cliOptions.concat(["--debug"]), untouchedAscOptions, (err) => { if (err) { console.error(err); errors.push(err); @@ -116,11 +129,9 @@ function runTest(file, type, binary, wat) { const context = new TestContext({ fileName: file, reporter, - stderr: process.stderr, - stdout: process.stdout, }); const imports = context.createImports({ - wasi_unstable: wasi.exports, + wasi_snapshot_preview1: wasi.wasiImport, }); const wasm = instantiateBuffer(binary, imports); wasi.setMemory(wasm.memory); From 43f239c4d3b602ef897c8c6269845917fc471369 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Mon, 2 Mar 2020 16:40:34 -0500 Subject: [PATCH 2/7] add compiler errors detection for code exit --- tests/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/node.js b/tests/node.js index 11fbd25..62f1d19 100644 --- a/tests/node.js +++ b/tests/node.js @@ -141,4 +141,4 @@ function runTest(file, type, binary, wat) { if (!context.pass) pass = false; } -process.exit(pass ? 0 : 1); +process.exit(pass && errors.length === 0 ? 0 : 1); From 98a9b3eccb2e62484b0153a7520044df149672f5 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Mon, 2 Mar 2020 17:30:19 -0500 Subject: [PATCH 3/7] remove excess type info --- package-lock.json | 6 +- package.json | 2 +- tests/buffer.spec.ts | 591 ++++++++++++++++++++----------------------- tests/node.js | 10 +- 4 files changed, 288 insertions(+), 321 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1c42566..8d9dda5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,9 +38,9 @@ } }, "assemblyscript": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.9.2.tgz", - "integrity": "sha512-eqPbxS323ivXdUclGJjvihxEEMBaXcNYHLb17j3j3UaYvkqVPNSrNuJ/H1r7G/UwmQnFQ8NDrQ9BncOFCGmahg==", + "version": "0.9.2-nightly.20200228", + "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.9.2-nightly.20200228.tgz", + "integrity": "sha512-leL/jjCuEwwMah4zJS11nVRN2mCm6xOjJ8XYWgpy8f3M6URkBnXHmr32ReQaSixDhzyfTWDs4JjqT5tYN1nYVA==", "dev": true, "requires": { "binaryen": "90.0.0-nightly.20200214", diff --git a/package.json b/package.json index de83423..bc20c51 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@as-pect/core": "^3.1.0-alpha.0", - "assemblyscript": "^0.9.2", + "assemblyscript": "0.9.2-nightly.20200228", "glob": "^7.1.4" }, "scripts": { diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index c508a08..49fcd08 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -22,34 +22,34 @@ function create(values: valueof[]): T { describe("buffer", () => { test("#constructor", () => { - expect(new Buffer(0)).toBeTruthy(); - expect(new Buffer(10)).toHaveLength(10); + expect(new Buffer(0)).toBeTruthy(); + expect(new Buffer(10)).toHaveLength(10); let myBuffer = new Buffer(10); - expect(myBuffer.buffer).toBeTruthy(); - expect(myBuffer.buffer).toHaveLength(10); - // TODO: expectFn(() => { new Buffer(-1); }).toThrow(); - // TODO: expectFn(() => { new Buffer(BLOCK_MAXSIZE + 1); }).toThrow(); + expect(myBuffer.buffer).toBeTruthy(); + expect(myBuffer.buffer).toHaveLength(10); + expect(() => { new Buffer(-1); }).toThrow(); + expect(() => { new Buffer(BLOCK_MAXSIZE + 1); }).toThrow(); }); test("#alloc", () => { - expect(Buffer.alloc(10)).toBeTruthy(); - expect(Buffer.alloc(10)).toHaveLength(10); + expect(Buffer.alloc(10)).toBeTruthy(); + expect(Buffer.alloc(10)).toHaveLength(10); let buff = Buffer.alloc(100); for (let i = 0; i < buff.length; i++) expect(buff[i]).toBe(0); - expect(buff.buffer).not.toBeNull(); - expect(buff.byteLength).toBe(100); - // TODO: expectFn(() => { Buffer.alloc(-1); }).toThrow(); - // TODO: expectFn(() => { Buffer.alloc(BLOCK_MAXSIZE + 1); }).toThrow(); + expect(buff.buffer).not.toBeNull(); + expect(buff.byteLength).toBe(100); + expect(() => { Buffer.alloc(-1); }).toThrow(); + expect(() => { Buffer.alloc(BLOCK_MAXSIZE + 1); }).toThrow(); }); test("#allocUnsafe", () => { - expect(Buffer.allocUnsafe(10)).toBeTruthy(); - expect(Buffer.allocUnsafe(10)).toHaveLength(10); + expect(Buffer.allocUnsafe(10)).toBeTruthy(); + expect(Buffer.allocUnsafe(10)).toHaveLength(10); let buff = Buffer.allocUnsafe(100); - expect(buff.buffer).not.toBeNull(); - expect(buff.byteLength).toBe(100); - // TODO: expectFn(() => { Buffer.allocUnsafe(-1); }).toThrow(); - // TODO: expectFn(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow(); + expect(buff.buffer).not.toBeNull(); + expect(buff.byteLength).toBe(100); + expect(() => { Buffer.allocUnsafe(-1); }).toThrow(); + expect(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow(); }); test("#isBuffer", () => { @@ -58,33 +58,33 @@ describe("buffer", () => { let c = 0; let d = 1.1; let e = new Buffer(0); - expect(Buffer.isBuffer(a)).toBeFalsy(); - expect(Buffer.isBuffer(b)).toBeFalsy(); - expect(Buffer.isBuffer(c)).toBeFalsy(); - expect(Buffer.isBuffer(d)).toBeFalsy(); - expect(Buffer.isBuffer(e)).toBeTruthy(); - // null checks are done by the compiler explicitly at runtime - expect(Buffer.isBuffer(null)).toBeFalsy(); + let f: Buffer | null = null; + + expect(Buffer.isBuffer(a)).toBeFalsy(); + expect(Buffer.isBuffer(b)).toBeFalsy(); + expect(Buffer.isBuffer(c)).toBeFalsy(); + expect(Buffer.isBuffer(d)).toBeFalsy(); + expect(Buffer.isBuffer(e)).toBeTruthy(); + expect(Buffer.isBuffer(f)).toBeFalsy(); }); test("#readInt8", () => { let buff = create([0x5,0x0,0x0,0x0,0xFF]); - expect(buff.readInt8()).toBe(5); + expect(buff.readInt8()).toBe(5); // Testing offset, and casting between u8 and i8. - expect(buff.readInt8(4)).toBe(-1); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readInt8(5); - // }).toThrow(); + expect(buff.readInt8(4)).toBe(-1); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readInt8(5); + }).toThrow(); }); test("#readUInt8", () => { let buff = create([0xFE,0x0,0x0,0x0,0x2F]); // Testing casting between u8 and i8. - expect(buff.readUInt8()).toBe(254); + expect(buff.readUInt8()).toBe(254); // Testing offset - expect(buff.readUInt8(4)).toBe(47); + expect(buff.readUInt8(4)).toBe(47); // TODO: // expectFn(() => { // let newBuff = new Buffer(1); @@ -94,106 +94,99 @@ describe("buffer", () => { test("#writeInt8", () => { let buff = new Buffer(5); - expect(buff.writeInt8(9)).toBe(1); - expect(buff.writeInt8(-3,4)).toBe(5); + expect(buff.writeInt8(9)).toBe(1); + expect(buff.writeInt8(-3,4)).toBe(5); let result = create([0x09, 0x0, 0x0, 0x0, 0xFD]); - expect(buff).toStrictEqual(result); + expect(buff).toStrictEqual(result); // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeInt8(5,10); - // }).toThrow(); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeInt8(5,10); + }).toThrow(); }); test("#writeUInt8", () => { let buff = new Buffer(5); - expect(buff.writeUInt8(4)).toBe(1); - expect(buff.writeUInt8(252,4)).toBe(5); + expect(buff.writeUInt8(4)).toBe(1); + expect(buff.writeUInt8(252,4)).toBe(5); let result = create([0x04, 0x0, 0x0, 0x0, 0xFC]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeUInt8(5,10); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeUInt8(5,10); + }).toThrow(); }); test("#readInt16LE", () => { let buff = create([0x0,0x05,0x0]); - expect(buff.readInt16LE()).toBe(1280); - expect(buff.readInt16LE(1)).toBe(5); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readInt16LE(0); - // }).toThrow(); + expect(buff.readInt16LE()).toBe(1280); + expect(buff.readInt16LE(1)).toBe(5); + expectFn(() => { + let newBuff = new Buffer(1); + newBuff.readInt16LE(0); + }).toThrow(); }); test("#readInt16BE", () => { let buff = create([0x0,0x05,0x0]); - expect(buff.readInt16BE()).toBe(5); - expect(buff.readInt16BE(1)).toBe(1280); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readInt16BE(0); - // }).toThrow(); + expect(buff.readInt16BE()).toBe(5); + expect(buff.readInt16BE(1)).toBe(1280); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readInt16BE(0); + }).toThrow(); }); test("#readUInt16LE", () => { let buff = create([0x0,0x05,0x0]); - expect(buff.readUInt16LE()).toBe(1280); - expect(buff.readUInt16LE(1)).toBe(5); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readUInt16LE(0); - // }).toThrow(); + expect(buff.readUInt16LE()).toBe(1280); + expect(buff.readUInt16LE(1)).toBe(5); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readUInt16LE(0); + }).toThrow(); }); test("#readUInt16BE", () => { let buff = create([0x0,0x05,0x0]); - expect(buff.readUInt16BE()).toBe(5); - expect(buff.readUInt16BE(1)).toBe(1280); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readUInt16BE(0); - // }).toThrow(); + expect(buff.readUInt16BE()).toBe(5); + expect(buff.readUInt16BE(1)).toBe(1280); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readUInt16BE(0); + }).toThrow(); }); test("#writeInt16LE", () => { let buff = new Buffer(4); - expect(buff.writeInt16LE(5)).toBe(2); - expect(buff.writeInt16LE(1280,2)).toBe(4); + expect(buff.writeInt16LE(5)).toBe(2); + expect(buff.writeInt16LE(1280,2)).toBe(4); let result = create([0x05, 0x0, 0x0, 0x5]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeInt16LE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeInt16LE(0); + }).toThrow(); }); test("#writeInt16BE", () => { let buff = new Buffer(4); - expect(buff.writeInt16BE(1280)).toBe(2); - expect(buff.writeInt16BE(5,2)).toBe(4); + expect(buff.writeInt16BE(1280)).toBe(2); + expect(buff.writeInt16BE(5,2)).toBe(4); let result = create([0x05, 0x0, 0x0, 0x5]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeInt16BE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeInt16BE(0); + }).toThrow(); }); test("#writeUInt16LE", () => { let buff = new Buffer(4); - expect(buff.writeUInt16LE(5)).toBe(2); - expect(buff.writeUInt16LE(1280,2)).toBe(4); + expect(buff.writeUInt16LE(5)).toBe(2); + expect(buff.writeUInt16LE(1280,2)).toBe(4); let result = create([0x05, 0x0, 0x0, 0x5]); - expect(buff).toStrictEqual(result); + expect(buff).toStrictEqual(result); // TODO: // expectFn(() => { // let newBuff = new Buffer(1); @@ -203,303 +196,278 @@ describe("buffer", () => { test("#writeUInt16BE", () => { let buff = new Buffer(4); - expect(buff.writeUInt16BE(1280)).toBe(2); - expect(buff.writeUInt16BE(5,2)).toBe(4); + expect(buff.writeUInt16BE(1280)).toBe(2); + expect(buff.writeUInt16BE(5,2)).toBe(4); let result = create([0x05, 0x0, 0x0, 0x5]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeUInt16BE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeUInt16BE(0); + }).toThrow(); }); test("#readInt32LE", () => { let buff = create([0xEF,0xBE,0xAD,0xDE,0x0d,0xc0,0xde,0x10]); - expect(buff.readInt32LE()).toBe(-559038737); - expect(buff.readInt32LE(4)).toBe(283033613); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readInt32LE(0); - // }).toThrow(); + expect(buff.readInt32LE()).toBe(-559038737); + expect(buff.readInt32LE(4)).toBe(283033613); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readInt32LE(0); + }).toThrow(); }); test("#readInt32BE", () => { let buff = create([0xDE,0xAD,0xBE,0xEF,0x10,0xde,0xc0,0x0d]); - expect(buff.readInt32BE()).toBe(-559038737); - expect(buff.readInt32BE(4)).toBe(283033613); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readInt32BE(0); - // }).toThrow(); + expect(buff.readInt32BE()).toBe(-559038737); + expect(buff.readInt32BE(4)).toBe(283033613); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readInt32BE(0); + }).toThrow(); }); test("#readUInt32LE", () => { let buff = create([0xEF,0xBE,0xAD,0xDE,0x0d,0xc0,0xde,0x10]); - expect(buff.readUInt32LE()).toBe(3735928559); - expect(buff.readUInt32LE(4)).toBe(283033613); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readUInt32LE(0); - // }).toThrow(); + expect(buff.readUInt32LE()).toBe(3735928559); + expect(buff.readUInt32LE(4)).toBe(283033613); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readUInt32LE(0); + }).toThrow(); }); test("#readUInt32BE", () => { let buff = create([0xDE,0xAD,0xBE,0xEF,0x10,0xde,0xc0,0x0d]); - expect(buff.readUInt32BE()).toBe(3735928559); - expect(buff.readUInt32BE(4)).toBe(283033613); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readUInt32BE(0); - // }).toThrow(); + expect(buff.readUInt32BE()).toBe(3735928559); + expect(buff.readUInt32BE(4)).toBe(283033613); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readUInt32BE(0); + }).toThrow(); }); test("#writeInt32LE", () => { let buff = new Buffer(8); - expect(buff.writeInt32LE(-559038737)).toBe(4); - expect(buff.writeInt32LE(283033613,4)).toBe(8); + expect(buff.writeInt32LE(-559038737)).toBe(4); + expect(buff.writeInt32LE(283033613,4)).toBe(8); let result = create([0xEF,0xBE,0xAD,0xDE,0x0d,0xc0,0xde,0x10]); expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeInt32LE(0); - // }).toThrow(); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeInt32LE(0); + }).toThrow(); }); test("#writeInt32BE", () => { let buff = new Buffer(8); - expect(buff.writeInt32BE(-559038737)).toBe(4); - expect(buff.writeInt32BE(283033613,4)).toBe(8); + expect(buff.writeInt32BE(-559038737)).toBe(4); + expect(buff.writeInt32BE(283033613,4)).toBe(8); let result = create([0xDE,0xAD,0xBE,0xEF,0x10,0xde,0xc0,0x0d]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeInt32BE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeInt32BE(0); + }).toThrow(); }); test("#writeUInt32LE", () => { let buff = new Buffer(8); - expect(buff.writeUInt32LE(3735928559)).toBe(4); - expect(buff.writeUInt32LE(283033613,4)).toBe(8); + expect(buff.writeUInt32LE(3735928559)).toBe(4); + expect(buff.writeUInt32LE(283033613,4)).toBe(8); let result = create([0xEF,0xBE,0xAD,0xDE,0x0d,0xc0,0xde,0x10]);; - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeUInt32LE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeUInt32LE(0); + }).toThrow(); }); test("#writeUInt32BE", () => { let buff = new Buffer(8); - expect(buff.writeUInt32BE(3735928559)).toBe(4); - expect(buff.writeUInt32BE(283033613,4)).toBe(8); + expect(buff.writeUInt32BE(3735928559)).toBe(4); + expect(buff.writeUInt32BE(283033613,4)).toBe(8); let result = create([0xDE,0xAD,0xBE,0xEF,0x10,0xde,0xc0,0x0d]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeUInt32BE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeUInt32BE(0); + }).toThrow(); }); test("#readFloatLE", () => { let buff = create([0xbb,0xfe,0x4a,0x4f,0x01,0x02,0x03,0x04]); - expect(buff.readFloatLE()).toBe(0xcafebabe); - expect(buff.readFloatLE(4)).toBe(1.539989614439558e-36); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readFloatLE(0); - // }).toThrow(); + expect(buff.readFloatLE()).toBe(0xcafebabe); + expect(buff.readFloatLE(4)).toBe(1.539989614439558e-36); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readFloatLE(0); + }).toThrow(); }); test("#readFloatBE", () => { let buff = create([0x4f,0x4a,0xfe,0xbb,0x01,0x02,0x03,0x04]); - expect(buff.readFloatBE()).toBe(0xcafebabe); - expect(buff.readFloatBE(4)).toBe(2.387939260590663e-38); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readFloatBE(0); - // }).toThrow(); + expect(buff.readFloatBE()).toBe(0xcafebabe); + expect(buff.readFloatBE(4)).toBe(2.387939260590663e-38); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readFloatBE(0); + }).toThrow(); }); test("#writeFloatLE", () => { let buff = new Buffer(8); - expect(buff.writeFloatLE(0xcafebabe)).toBe(4); - expect(buff.writeFloatLE(1.539989614439558e-36,4)).toBe(8); + expect(buff.writeFloatLE(0xcafebabe)).toBe(4); + expect(buff.writeFloatLE(1.539989614439558e-36,4)).toBe(8); let result = create([0xbb,0xfe,0x4a,0x4f,0x01,0x02,0x03,0x04]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeFloatLE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeFloatLE(0); + }).toThrow(); }); test("#writeFloatBE", () => { let buff = new Buffer(8); - expect(buff.writeFloatBE(0xcafebabe)).toBe(4); - expect(buff.writeFloatBE(2.387939260590663e-38,4)).toBe(8); + expect(buff.writeFloatBE(0xcafebabe)).toBe(4); + expect(buff.writeFloatBE(2.387939260590663e-38,4)).toBe(8); let result = create([0x4f,0x4a,0xfe,0xbb,0x01,0x02,0x03,0x04]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeFloatBE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeFloatBE(0); + }).toThrow(); }); test("#readBigInt64LE", () => { let buff = create([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00]); - expect(buff.readBigInt64LE()).toBe(-4294967296); - expect(buff.readBigInt64LE(8)).toBe(4294967295); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readBigInt64LE(0); - // }).toThrow(); + expect(buff.readBigInt64LE()).toBe(-4294967296); + expect(buff.readBigInt64LE(8)).toBe(4294967295); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readBigInt64LE(0); + }).toThrow(); }); test("#readBigInt64BE", () => { let buff = create([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00]); - expect(buff.readBigInt64BE()).toBe(4294967295); - expect(buff.readBigInt64BE(8)).toBe(-4294967296); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readBigInt64BE(0); - // }).toThrow(); + expect(buff.readBigInt64BE()).toBe(4294967295); + expect(buff.readBigInt64BE(8)).toBe(-4294967296); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readBigInt64BE(0); + }).toThrow(); }); test("#readBigUInt64LE", () => { let buff = create([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00]); - expect(buff.readBigUInt64LE()).toBe(18446744069414584320); - expect(buff.readBigUInt64LE(8)).toBe(4294967295); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readBigUInt64LE(0); - // }).toThrow(); + expect(buff.readBigUInt64LE()).toBe(18446744069414584320); + expect(buff.readBigUInt64LE(8)).toBe(4294967295); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readBigUInt64LE(0); + }).toThrow(); }); test("#readBigUInt64BE", () => { let buff = create([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00]); - expect(buff.readBigUInt64BE()).toBe(4294967295); - expect(buff.readBigUInt64BE(8)).toBe(18446744069414584320); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readBigUInt64BE(0); - // }).toThrow(); + expect(buff.readBigUInt64BE()).toBe(4294967295); + expect(buff.readBigUInt64BE(8)).toBe(18446744069414584320); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readBigUInt64BE(0); + }).toThrow(); }); test("#writeBigInt64LE", () => { let buff = new Buffer(16); - expect(buff.writeBigInt64LE(-559038737)).toBe(8); - expect(buff.writeBigInt64LE(283033613,8)).toBe(16); + expect(buff.writeBigInt64LE(-559038737)).toBe(8); + expect(buff.writeBigInt64LE(283033613,8)).toBe(16); let result = create([0xEF,0xBE,0xAD,0xDE,0xFF,0xFF,0xFF,0xFF,0x0d,0xc0,0xde,0x10,0x00,0x00,0x00,0x00]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeBigInt64LE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeBigInt64LE(0); + }).toThrow(); }); test("#writeBigInt64BE", () => { let buff = new Buffer(16); - expect(buff.writeBigInt64BE(-559038737)).toBe(8); - expect(buff.writeBigInt64BE(283033613,8)).toBe(16); + expect(buff.writeBigInt64BE(-559038737)).toBe(8); + expect(buff.writeBigInt64BE(283033613,8)).toBe(16); let result = create([0xFF,0xFF,0xFF,0xFF,0xDE,0xAD,0xBE,0xEF,0x00,0x00,0x00,0x00,0x10,0xde,0xc0,0x0d]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeBigInt64BE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeBigInt64BE(0); + }).toThrow(); }); test("#writeBigUInt64LE", () => { let buff = new Buffer(16); - expect(buff.writeBigUInt64LE(3735928559)).toBe(8); - expect(buff.writeBigUInt64LE(283033613,8)).toBe(16); + expect(buff.writeBigUInt64LE(3735928559)).toBe(8); + expect(buff.writeBigUInt64LE(283033613,8)).toBe(16); let result = create([0xEF,0xBE,0xAD,0xDE,0x00,0x00,0x00,0x00,0x0d,0xc0,0xde,0x10,0x00,0x00,0x00,0x00]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeBigUInt64LE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeBigUInt64LE(0); + }).toThrow(); }); test("#writeBigUInt64BE", () => { let buff = new Buffer(16); - expect(buff.writeBigUInt64BE(3735928559)).toBe(8); - expect(buff.writeBigUInt64BE(283033613,8)).toBe(16); + expect(buff.writeBigUInt64BE(3735928559)).toBe(8); + expect(buff.writeBigUInt64BE(283033613,8)).toBe(16); let result = create([0x00,0x00,0x00,0x00,0xDE,0xAD,0xBE,0xEF,0x00,0x00,0x00,0x00,0x10,0xde,0xc0,0x0d]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeBigUInt64BE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeBigUInt64BE(0); + }).toThrow(); }); test("#readDoubleLE", () => { let buff = create([0x77, 0xbe, 0x9f, 0x1a, 0x2f, 0xdd, 0x5e, 0x40, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]); - expect(buff.readDoubleLE()).toBe(123.456); - expect(buff.readDoubleLE(8)).toBe(5.447603722011605e-270); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readDoubleLE(0); - // }).toThrow(); + expect(buff.readDoubleLE()).toBe(123.456); + expect(buff.readDoubleLE(8)).toBe(5.447603722011605e-270); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readDoubleLE(0); + }).toThrow(); }); test("#readDoubleBE", () => { let buff = create([0x40, 0x5e, 0xdd, 0x2f, 0x1a, 0x9f, 0xbe, 0x77, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]); - expect(buff.readDoubleBE()).toBe(123.456); - expect(buff.readDoubleBE(8)).toBe(8.20788039913184e-304); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readDoubleBE(0); - // }).toThrow(); + expect(buff.readDoubleBE()).toBe(123.456); + expect(buff.readDoubleBE(8)).toBe(8.20788039913184e-304); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readDoubleBE(0); + }).toThrow(); }); test("#writeDoubleLE", () => { let buff = new Buffer(16); - expect(buff.writeDoubleLE(123.456)).toBe(8); - expect(buff.writeDoubleLE(5.447603722011605e-270,8)).toBe(16); + expect(buff.writeDoubleLE(123.456)).toBe(8); + expect(buff.writeDoubleLE(5.447603722011605e-270,8)).toBe(16); let result = create([0x77, 0xbe, 0x9f, 0x1a, 0x2f, 0xdd, 0x5e, 0x40, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeDoubleLE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeDoubleLE(0); + }).toThrow(); }); test("#writeDoubleBE", () => { let buff = new Buffer(16); - expect(buff.writeDoubleBE(123.456)).toBe(8); - expect(buff.writeDoubleBE(8.20788039913184e-304,8)).toBe(16); + expect(buff.writeDoubleBE(123.456)).toBe(8); + expect(buff.writeDoubleBE(8.20788039913184e-304,8)).toBe(16); let result = create([0x40, 0x5e, 0xdd, 0x2f, 0x1a, 0x9f, 0xbe, 0x77, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]); - expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeDoubleBE(0); - // }).toThrow(); + expect(buff).toStrictEqual(result); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeDoubleBE(0); + }).toThrow(); }); test("#subarray", () => { @@ -507,81 +475,78 @@ describe("buffer", () => { // no parameters means copy the Buffer let actual = example.subarray(); - expect(actual).toStrictEqual(example); - expect(actual.buffer).toBe(example.buffer); // should use the same buffer + expect(actual).toStrictEqual(example); + expect(actual.buffer).toBe(example.buffer); // should use the same buffer // start at offset 5 actual = example.subarray(5); let expected = create([6, 7, 8]); // trace("length", 1, expected.length); - expect(actual).toStrictEqual(expected); + expect(actual).toStrictEqual(expected); // negative start indicies, start at (8 - 5) actual = example.subarray(-5); expected = create([4, 5, 6, 7, 8]); - expect(actual).toStrictEqual(expected); + expect(actual).toStrictEqual(expected); // two parameters actual = example.subarray(2, 6); expected = create([3, 4, 5, 6]); - expect(actual).toStrictEqual(expected); + expect(actual).toStrictEqual(expected); // negative end index actual = example.subarray(4, -1); expected = create([5, 6, 7]); - expect(actual).toStrictEqual(expected); + expect(actual).toStrictEqual(expected); }); test("#swap16", () => { let actual = create([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); let expected = create([0x2, 0x1, 0x4, 0x3, 0x6, 0x5, 0x8, 0x7]); let swapped = actual.swap16(); - expect(actual).toStrictEqual(expected); - expect(swapped).toBe(actual); - // TODO: - // expectFn(() => { - // let newBuff = create([0x1, 0x2, 0x3]); - // newBuff.swap16(); - // }).toThrow(); + expect(actual).toStrictEqual(expected); + expect(swapped).toBe(actual); + expect(() => { + let newBuff = create([0x1, 0x2, 0x3]); + newBuff.swap16(); + }).toThrow(); }); test("#swap32", () => { let actual = create([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); let expected = create([0x4, 0x3, 0x2, 0x1, 0x8, 0x7, 0x6, 0x5]); let swapped = actual.swap32(); - expect(actual).toStrictEqual(expected); - expect(swapped).toBe(actual); - // TODO: - // expectFn(() => { - // let newBuff = create([0x1, 0x2, 0x3]); - // newBuff.swap64(); - // }).toThrow(); + expect(actual).toStrictEqual(expected); + expect(swapped).toBe(actual); + expect(() => { + let newBuff = create([0x1, 0x2, 0x3]); + newBuff.swap64(); + }).toThrow(); }); test("#swap64", () => { let actual = create([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf]); let expected = create([0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0, 0xf, 0xe, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8]); let swapped = actual.swap64(); - expect(actual).toStrictEqual(expected); - expect(swapped).toBe(actual); - // TODO: - // expectFn(() => { - // let newBuff = create([0x1, 0x2, 0x3]); - // newBuff.swap64(); - // }).toThrow(); + expect(actual).toStrictEqual(expected); + expect(swapped).toBe(actual); + expect(() => { + let newBuff = create([0x1, 0x2, 0x3]); + newBuff.swap64(); + }).toThrow(); }); - + test("#Hex.encode", () => { let actual = "000102030405060708090a0b0c0d0e0f102030405060708090a0b0c0d0e0f0"; let exampleBuffer = create([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0]); let encoded = Buffer.HEX.encode(actual); - expect(encoded).toStrictEqual(exampleBuffer.buffer); + expect(encoded).toStrictEqual(exampleBuffer.buffer); }); test("#Hex.decode", () => { let expected = "000102030405060708090a0b0c0d0e0f102030405060708090a0b0c0d0e0f0"; let exampleBuffer = create([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0]); let decoded = Buffer.HEX.decode(exampleBuffer.buffer); - expect(decoded).toStrictEqual(expected); + expect(decoded).toStrictEqual(expected); }); }); diff --git a/tests/node.js b/tests/node.js index 62f1d19..05a8051 100644 --- a/tests/node.js +++ b/tests/node.js @@ -117,8 +117,8 @@ for (const file of files) { process.stdout.write("\n"); } -function runTest(file, type, binary, wat) { - const watPath = path.join(path.dirname(file), path.basename(file, ".ts")) +function runTest(fileName, type, binary, wat) { + const watPath = path.join(path.dirname(fileName), path.basename(fileName, ".ts")) + "." + type + ".wat"; // should not block testing @@ -127,9 +127,11 @@ function runTest(file, type, binary, wat) { }); const context = new TestContext({ - fileName: file, - reporter, + fileName, // set the fileName + reporter, // use verbose reporter + binary, // pass the binary to get function names }); + const imports = context.createImports({ wasi_snapshot_preview1: wasi.wasiImport, }); From d2e0fb45b9ed69a423042bc4b2595b9c45b5a812 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Mon, 2 Mar 2020 17:57:21 -0500 Subject: [PATCH 4/7] fix up wasi --- assembly/buffer/index.ts | 24 ++++++++++++++++++++++++ tests/buffer.spec.ts | 20 +++++++++----------- tests/node.js | 33 +++++++++++++++++---------------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 805de87..34da9a1 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -3,6 +3,30 @@ import { E_INVALIDLENGTH, E_INDEXOUTOFRANGE } from "util/error"; import { Uint8Array } from "typedarray"; export class Buffer extends Uint8Array { + [key: number]: u8; + + @operator("[]") + private __get(index: i32): u8 { + if (index >= this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE); + return load(this.dataStart + index); + } + + @unsafe @operator("{}") + private __uget(index: i32): u8 { + return load(this.dataStart + index); + } + + @operator("[]=") + private __set(index: i32, value: native): void { + if (index >= this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE); + store(this.dataStart + index, value); + } + + @unsafe @operator("{}=") + private __uset(index: i32, value: native): void { + store(this.dataStart + index, value); + } + constructor(size: i32) { super(size); } diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index 49fcd08..f57e612 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -85,11 +85,10 @@ describe("buffer", () => { expect(buff.readUInt8()).toBe(254); // Testing offset expect(buff.readUInt8(4)).toBe(47); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.readUInt8(5); - // }).toThrow(); + expect(() => { + let newBuff = new Buffer(1); + newBuff.readUInt8(5); + }).toThrow(); }); test("#writeInt8", () => { @@ -121,7 +120,7 @@ describe("buffer", () => { let buff = create([0x0,0x05,0x0]); expect(buff.readInt16LE()).toBe(1280); expect(buff.readInt16LE(1)).toBe(5); - expectFn(() => { + expect(() => { let newBuff = new Buffer(1); newBuff.readInt16LE(0); }).toThrow(); @@ -187,11 +186,10 @@ describe("buffer", () => { expect(buff.writeUInt16LE(1280,2)).toBe(4); let result = create([0x05, 0x0, 0x0, 0x5]); expect(buff).toStrictEqual(result); - // TODO: - // expectFn(() => { - // let newBuff = new Buffer(1); - // newBuff.writeUInt16LE(0); - // }).toThrow(); + expect(() => { + let newBuff = new Buffer(1); + newBuff.writeUInt16LE(0); + }).toThrow(); }); test("#writeUInt16BE", () => { diff --git a/tests/node.js b/tests/node.js index 05a8051..fd8ce2b 100644 --- a/tests/node.js +++ b/tests/node.js @@ -1,18 +1,11 @@ const { TestContext, VerboseReporter } = require("@as-pect/core"); -const { instantiateBuffer } = require("assemblyscript/lib/loader"); const glob = require("glob"); +const { instantiateSync } = require("assemblyscript/lib/loader"); const { main } = require("assemblyscript/cli/asc"); const { parse } = require("assemblyscript/cli/util/options"); const path = require("path"); const fs = require("fs"); const { WASI } = require("wasi"); -const wasi = new WASI({ - args: [], - env: {}, - preopens: { - // '/sandbox': '/some/real/path/that/wasm/can/access' - } -}); let pass = true; const options = parse(process.argv.slice(2), { @@ -118,8 +111,11 @@ for (const file of files) { } function runTest(fileName, type, binary, wat) { - const watPath = path.join(path.dirname(fileName), path.basename(fileName, ".ts")) - + "." + type + ".wat"; + const dirname = path.dirname(fileName); + const basename = path.basename(fileName, ".ts"); + const fullName = path.join(dirname, basename) + const watPath = `${fullName}.${type}.wat`; + const fileNamePath = `${fullName}.${type}.ts`; // should not block testing fs.writeFile(watPath, wat, (err) => { @@ -127,18 +123,23 @@ function runTest(fileName, type, binary, wat) { }); const context = new TestContext({ - fileName, // set the fileName + fileName: fileNamePath, // set the fileName reporter, // use verbose reporter binary, // pass the binary to get function names }); - + const wasi = new WASI({ + args: [], + env: {}, + preopens: { + // '/sandbox': '/some/real/path/that/wasm/can/access' + } + }); const imports = context.createImports({ wasi_snapshot_preview1: wasi.wasiImport, }); - const wasm = instantiateBuffer(binary, imports); - wasi.setMemory(wasm.memory); - wasi.view = new DataView(wasm.memory.buffer); - context.run(wasm); + const instance = instantiateSync(binary, imports); + // TODO: wasi.start(instance); + context.run(instance); if (!context.pass) pass = false; } From 1f375b6e669874abb3d190c486b47871defc1693 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Mon, 2 Mar 2020 18:04:54 -0500 Subject: [PATCH 5/7] general cleanups --- tests/node.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/node.js b/tests/node.js index fd8ce2b..ee06d4e 100644 --- a/tests/node.js +++ b/tests/node.js @@ -137,8 +137,10 @@ function runTest(fileName, type, binary, wat) { const imports = context.createImports({ wasi_snapshot_preview1: wasi.wasiImport, }); + const instance = instantiateSync(binary, imports); // TODO: wasi.start(instance); + process.stdout.write("\n"); context.run(instance); if (!context.pass) pass = false; From cafd80adb81f93f86d7a9b33c889edd08438686d Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Wed, 11 Mar 2020 16:23:07 -0400 Subject: [PATCH 6/7] update to latest aspect and assemblyscript, remove index signatures, add in some unreachable tests --- assembly/buffer/index.ts | 40 ++++----------- package-lock.json | 104 +++++++++++++++++++++++++++++++++------ package.json | 6 +-- tests/buffer.spec.ts | 9 ++-- 4 files changed, 108 insertions(+), 51 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index 34da9a1..b0eba22 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -5,28 +5,6 @@ import { Uint8Array } from "typedarray"; export class Buffer extends Uint8Array { [key: number]: u8; - @operator("[]") - private __get(index: i32): u8 { - if (index >= this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE); - return load(this.dataStart + index); - } - - @unsafe @operator("{}") - private __uget(index: i32): u8 { - return load(this.dataStart + index); - } - - @operator("[]=") - private __set(index: i32, value: native): void { - if (index >= this.byteLength) throw new RangeError(E_INDEXOUTOFRANGE); - store(this.dataStart + index, value); - } - - @unsafe @operator("{}=") - private __uset(index: i32, value: native): void { - store(this.dataStart + index, value); - } - constructor(size: i32) { super(size); } @@ -269,12 +247,12 @@ export class Buffer extends Uint8Array { } swap16(): Buffer { - let byteLength = this.byteLength; + let byteLength = this.byteLength; // Make sure byteLength is even if (byteLength & 1) throw new RangeError(E_INVALIDLENGTH); let dataStart = this.dataStart; byteLength += dataStart; - while (dataStart < byteLength) { + while (dataStart < byteLength) { store(dataStart, bswap(load(dataStart))); dataStart += 2; } @@ -282,12 +260,12 @@ export class Buffer extends Uint8Array { } swap32(): Buffer { - let byteLength = this.byteLength; + let byteLength = this.byteLength; // Make sure byteLength is divisible by 4 if (byteLength & 3) throw new RangeError(E_INVALIDLENGTH); let dataStart = this.dataStart; byteLength += dataStart; - while (dataStart < byteLength) { + while (dataStart < byteLength) { store(dataStart, bswap(load(dataStart))); dataStart += 4; } @@ -295,7 +273,7 @@ export class Buffer extends Uint8Array { } swap64(): Buffer { - let byteLength = this.byteLength; + let byteLength = this.byteLength; // Make sure byteLength is divisible by 8 if (byteLength & 7) throw new RangeError(E_INVALIDLENGTH); let dataStart = this.dataStart; @@ -313,8 +291,8 @@ export namespace Buffer { /** Calculates the byte length of the specified string when encoded as HEX. */ export function byteLength(str: string): i32 { let ptr = changetype(str); - let byteCount = changetype(changetype(str) - BLOCK_OVERHEAD).rtSize; - let length = byteCount >> 2; + let byteCount = changetype(changetype(str) - BLOCK_OVERHEAD).rtSize; + let length = byteCount >>> 2; // The string length must be even because the bytes come in pairs of characters two wide if (byteCount & 3) return 0; // encoding fails and returns an empty ArrayBuffer @@ -330,7 +308,7 @@ export namespace Buffer { return 0; } } - return length; + return length; } /** Creates an ArrayBuffer from a given string that is encoded in the HEX format. */ @@ -341,7 +319,7 @@ export namespace Buffer { // long path: loop over each enociding pair and perform the conversion let ptr = changetype(str); - let byteEnd = changetype(changetype(str) - BLOCK_OVERHEAD).rtSize + ptr; + let byteEnd = ptr + changetype(changetype(str) - BLOCK_OVERHEAD).rtSize; let result = __alloc(bufferLength, idof()); let b: u32 = 0; let outChar = 0; diff --git a/package-lock.json b/package-lock.json index 8d9dda5..411d808 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,22 +5,33 @@ "requires": true, "dependencies": { "@as-pect/assembly": { - "version": "3.1.0-alpha.0", - "resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-3.1.0-alpha.0.tgz", - "integrity": "sha512-/WA1SZnfKvXqQEYgVxub4kHi1YDccnrCFWE3mBHz3BECNGrealVWv2RYqANl26ZACdz1PxG95DGyEl6OvyNu3g==", + "version": "3.1.0-beta.3", + "resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-3.1.0-beta.3.tgz", + "integrity": "sha512-NYMzh8c4mloGJHQEyEz7Gw4DFKDjepyuSkojca0agSOVsjJcaTy6DtM42Lq7DTLwNoM4xt+YI7nQNTWcrhhHGw==", "dev": true }, "@as-pect/core": { - "version": "3.1.0-alpha.0", - "resolved": "https://registry.npmjs.org/@as-pect/core/-/core-3.1.0-alpha.0.tgz", - "integrity": "sha512-5XfvlZHGD5f47Ppc41eVxF5j/L/iFUZLpDz37slunEPipI3JIHUNraUj+hJEIsCbkX6zdlsluMxtr7IYVg1jmQ==", + "version": "3.1.0-beta.3", + "resolved": "https://registry.npmjs.org/@as-pect/core/-/core-3.1.0-beta.3.tgz", + "integrity": "sha512-/i3wzOYEvvzECRKLPWm7FGKnPgtD6RdaPFWAT6nA4OHtsHdHz2BvvGdCecheLRG3GoRk00LfCSRB8/L3IJnS/A==", "dev": true, "requires": { - "@as-pect/assembly": "^3.1.0-alpha.0", + "@as-pect/assembly": "^3.1.0-beta.3", + "@as-pect/snapshots": "^3.1.0-beta.3", "chalk": "^3.0.0", "long": "^4.0.0" } }, + "@as-pect/snapshots": { + "version": "3.1.0-beta.3", + "resolved": "https://registry.npmjs.org/@as-pect/snapshots/-/snapshots-3.1.0-beta.3.tgz", + "integrity": "sha512-hL+a3/ByQQAhLLVsY9Qtd0eAb9UTZbMeJyh4mKQQS4X9KXhpVHADjoK31PbOlM+E3TUbR/KbZFFPu2Z79T3How==", + "dev": true, + "requires": { + "diff": "^4.0.2", + "nearley": "^2.19.1" + } + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", @@ -38,12 +49,12 @@ } }, "assemblyscript": { - "version": "0.9.2-nightly.20200228", - "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.9.2-nightly.20200228.tgz", - "integrity": "sha512-leL/jjCuEwwMah4zJS11nVRN2mCm6xOjJ8XYWgpy8f3M6URkBnXHmr32ReQaSixDhzyfTWDs4JjqT5tYN1nYVA==", + "version": "0.9.3", + "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.9.3.tgz", + "integrity": "sha512-5Mm15oLOi4Uj/N9h2uGuy4U2zFpaOQuP3kcRuFYiTchuvKIpyqqihMm+e7P6VaTLzPnN+oIRwn1KjTyo4aSw1A==", "dev": true, "requires": { - "binaryen": "90.0.0-nightly.20200214", + "binaryen": "91.0.0-nightly.20200310", "long": "^4.0.0" } }, @@ -54,9 +65,9 @@ "dev": true }, "binaryen": { - "version": "90.0.0-nightly.20200214", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-90.0.0-nightly.20200214.tgz", - "integrity": "sha512-ZHajaPd2aP6kDrM9q77afnA402Ufsuw9yLUxtAfgmIglP1JMB2XSRmaXc5pgCELaX53PWJIdcH07LL8uNfTBRw==", + "version": "91.0.0-nightly.20200310", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-91.0.0-nightly.20200310.tgz", + "integrity": "sha512-MmDzq267aa61HdEQeYiz+7guJlsYk2/6NxWC8I4w1jijqDwoqyZZxi7UYnTH7QvfLrNdMjweEgfT7FHjkvkPmQ==", "dev": true }, "brace-expansion": { @@ -94,12 +105,30 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, + "discontinuous-range": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", + "integrity": "sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=", + "dev": true + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -157,6 +186,25 @@ "brace-expansion": "^1.1.7" } }, + "moo": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.1.tgz", + "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==", + "dev": true + }, + "nearley": { + "version": "2.19.1", + "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.19.1.tgz", + "integrity": "sha512-xq47GIUGXxU9vQg7g/y1o1xuKnkO7ev4nRWqftmQrLkfnE/FjRqDaGOUakM8XHPn/6pW3bGjU2wgoJyId90rqg==", + "dev": true, + "requires": { + "commander": "^2.19.0", + "moo": "^0.5.0", + "railroad-diagrams": "^1.0.0", + "randexp": "0.4.6", + "semver": "^5.4.1" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -172,6 +220,34 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "railroad-diagrams": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", + "integrity": "sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=", + "dev": true + }, + "randexp": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", + "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", + "dev": true, + "requires": { + "discontinuous-range": "1.0.0", + "ret": "~0.1.10" + } + }, + "ret": { + "version": "0.1.15", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", + "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", + "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, "supports-color": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", diff --git a/package.json b/package.json index bc20c51..0b5ba7b 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "url": "https://github.com/AssemblyScript/node/issues" }, "devDependencies": { - "@as-pect/core": "^3.1.0-alpha.0", - "assemblyscript": "0.9.2-nightly.20200228", - "glob": "^7.1.4" + "@as-pect/core": "^3.1.0-beta.3", + "assemblyscript": "0.9.3", + "glob": "^7.1.6" }, "scripts": { "test": "node --experimental-wasi-unstable-preview1 tests/node" diff --git a/tests/buffer.spec.ts b/tests/buffer.spec.ts index f57e612..b7681a4 100644 --- a/tests/buffer.spec.ts +++ b/tests/buffer.spec.ts @@ -28,7 +28,8 @@ describe("buffer", () => { expect(myBuffer.buffer).toBeTruthy(); expect(myBuffer.buffer).toHaveLength(10); expect(() => { new Buffer(-1); }).toThrow(); - expect(() => { new Buffer(BLOCK_MAXSIZE + 1); }).toThrow(); + // TODO: figure out how to test block maxsize + // expect(() => { new Buffer(1 + BLOCK_MAXSIZE); }).toThrow(); }); test("#alloc", () => { @@ -39,7 +40,8 @@ describe("buffer", () => { expect(buff.buffer).not.toBeNull(); expect(buff.byteLength).toBe(100); expect(() => { Buffer.alloc(-1); }).toThrow(); - expect(() => { Buffer.alloc(BLOCK_MAXSIZE + 1); }).toThrow(); + // TODO: figure out how to test block maxsize + // expect(() => { Buffer.alloc(1 + BLOCK_MAXSIZE); }).toThrow(); }); test("#allocUnsafe", () => { @@ -49,7 +51,8 @@ describe("buffer", () => { expect(buff.buffer).not.toBeNull(); expect(buff.byteLength).toBe(100); expect(() => { Buffer.allocUnsafe(-1); }).toThrow(); - expect(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow(); + // TODO: figure out how to test block maxsize + // expect(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow(); }); test("#isBuffer", () => { From 25485053ccea46a423d0826c7ac735481455eb8a Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Thu, 12 Mar 2020 10:40:37 -0400 Subject: [PATCH 7/7] use promises to write files, optimize allocUnsafe --- assembly/buffer/index.ts | 2 +- tests/node.js | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/assembly/buffer/index.ts b/assembly/buffer/index.ts index b0eba22..1c5a832 100644 --- a/assembly/buffer/index.ts +++ b/assembly/buffer/index.ts @@ -15,7 +15,7 @@ export class Buffer extends Uint8Array { @unsafe static allocUnsafe(size: i32): Buffer { // range must be valid - if (i32(size > BLOCK_MAXSIZE) | i32(size < 0)) throw new RangeError(E_INVALIDLENGTH); + if (size > BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH); let buffer = __alloc(size, idof()); let result = __alloc(offsetof(), idof()); diff --git a/tests/node.js b/tests/node.js index ee06d4e..6c9e25f 100644 --- a/tests/node.js +++ b/tests/node.js @@ -4,8 +4,10 @@ const { instantiateSync } = require("assemblyscript/lib/loader"); const { main } = require("assemblyscript/cli/asc"); const { parse } = require("assemblyscript/cli/util/options"); const path = require("path"); -const fs = require("fs"); +const fs = require("fs").promises; const { WASI } = require("wasi"); + +const promises = []; let pass = true; const options = parse(process.argv.slice(2), { @@ -118,9 +120,7 @@ function runTest(fileName, type, binary, wat) { const fileNamePath = `${fullName}.${type}.ts`; // should not block testing - fs.writeFile(watPath, wat, (err) => { - if (err) console.warn(err); - }); + promises.push(fs.writeFile(watPath, wat)); const context = new TestContext({ fileName: fileNamePath, // set the fileName @@ -146,4 +146,15 @@ function runTest(fileName, type, binary, wat) { if (!context.pass) pass = false; } -process.exit(pass && errors.length === 0 ? 0 : 1); +// await for all the file writes to occur for the wat files +Promise.all(promises) + .then(() => { + // if the file writes were successful, inspect errors and pass + process.exit(pass && errors.length === 0 ? 0 : 1); + }) + .catch((error) => { + // report the file write error and exit 1 + console.error(error); + process.exit(1); + }); +