From 4ac5c89c570b1b68f294c392b7a33feae90662c4 Mon Sep 17 00:00:00 2001 From: Yotam Date: Fri, 14 Apr 2023 14:20:17 +0300 Subject: [PATCH] class-factory: Add toString() method to types and field (#278) --- lib/class-factory.js | 16 ++++++++++++++++ lib/types.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/class-factory.js b/lib/class-factory.js index f3b76f6..1d71bec 100644 --- a/lib/class-factory.js +++ b/lib/class-factory.js @@ -1978,6 +1978,22 @@ Object.defineProperties(Field.prototype, { get () { return this._p[2]; } + }, + toString: { + enumerable: true, + value () { + const inlineString = `Java.Field{holder: ${this.holder}, fieldType: ${this.fieldType}, fieldReturnType: ${this.fieldReturnType}, value: ${this.value}}`; + if (inlineString.length < 200) { + return inlineString; + } + const multilineString = `Java.Field{ +\tholder: ${this.holder}, +\tfieldType: ${this.fieldType}, +\tfieldReturnType: ${this.fieldReturnType}, +\tvalue: ${this.value}, +}`; + return multilineString.split('\n').map(l => l.length > 200 ? l.slice(0, l.indexOf(' ') + 1) + '...,' : l).join('\n'); + }, } }); diff --git a/lib/types.js b/lib/types.js index 565b146..6a0f977 100644 --- a/lib/types.js +++ b/lib/types.js @@ -51,6 +51,9 @@ const primitiveTypes = { }, write (address, value) { address.writeU8(value); + }, + toString () { + return this.name; } }, byte: { @@ -69,6 +72,9 @@ const primitiveTypes = { }, write (address, value) { address.writeS8(value); + }, + toString () { + return this.name; } }, char: { @@ -96,6 +102,9 @@ const primitiveTypes = { }, write (address, value) { address.writeU16(value); + }, + toString () { + return this.name; } }, short: { @@ -114,6 +123,9 @@ const primitiveTypes = { }, write (address, value) { address.writeS16(value); + }, + toString () { + return this.name; } }, int: { @@ -132,6 +144,9 @@ const primitiveTypes = { }, write (address, value) { address.writeS32(value); + }, + toString () { + return this.name; } }, long: { @@ -150,6 +165,9 @@ const primitiveTypes = { }, write (address, value) { address.writeS64(value); + }, + toString () { + return this.name; } }, float: { @@ -168,6 +186,9 @@ const primitiveTypes = { }, write (address, value) { address.writeFloat(value); + }, + toString () { + return this.name; } }, double: { @@ -186,6 +207,9 @@ const primitiveTypes = { }, write (address, value) { address.writeDouble(value); + }, + toString () { + return this.name; } }, void: { @@ -202,6 +226,9 @@ const primitiveTypes = { }, toJni () { return NULL; + }, + toString () { + return this.name; } } }; @@ -345,6 +372,9 @@ function getAnyObjectType (typeName, unbox, factory) { } return o.$h; + }, + toString () { + return this.name; } }; }