From 7e906941a018a86dba568e53ac997202dead345f Mon Sep 17 00:00:00 2001 From: erichiggins0 Date: Thu, 21 Dec 2023 07:29:39 -0800 Subject: [PATCH 1/3] Extend Object prototype for message instances --- packages/runtime/src/message-type.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/message-type.ts b/packages/runtime/src/message-type.ts index 2c4d58f5..a52013ca 100644 --- a/packages/runtime/src/message-type.ts +++ b/packages/runtime/src/message-type.ts @@ -67,7 +67,14 @@ export class MessageType implements IMessageType { this.typeName = name; this.fields = fields.map(normalizeFieldInfo); this.options = options ?? {}; - this.messagePrototype = Object.defineProperty({}, MESSAGE_TYPE, { value: this }); + this.messagePrototype = this.messagePrototype = Object.defineProperty( + Object.create( + null, + Object.getOwnPropertyDescriptors(Object.getPrototypeOf({})) + ), + MESSAGE_TYPE, + { value: this }, + ); this.refTypeCheck = new ReflectionTypeCheck(this); this.refJsonReader = new ReflectionJsonReader(this); this.refJsonWriter = new ReflectionJsonWriter(this); From 0c012ba75f50c5a8c9336d40c19e89b3eff2a289 Mon Sep 17 00:00:00 2001 From: erichiggins0 Date: Fri, 8 Mar 2024 13:51:31 -0800 Subject: [PATCH 2/3] address comment --- packages/runtime/src/message-type.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/runtime/src/message-type.ts b/packages/runtime/src/message-type.ts index a52013ca..30345d16 100644 --- a/packages/runtime/src/message-type.ts +++ b/packages/runtime/src/message-type.ts @@ -19,6 +19,8 @@ import type {UnknownMessage} from "./unknown-types"; import {binaryWriteOptions} from "./binary-writer"; import {binaryReadOptions} from "./binary-reader"; +const baseDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf({})); + /** * This standard message type provides reflection-based * operations to work with a message. @@ -67,14 +69,7 @@ export class MessageType implements IMessageType { this.typeName = name; this.fields = fields.map(normalizeFieldInfo); this.options = options ?? {}; - this.messagePrototype = this.messagePrototype = Object.defineProperty( - Object.create( - null, - Object.getOwnPropertyDescriptors(Object.getPrototypeOf({})) - ), - MESSAGE_TYPE, - { value: this }, - ); + this.messagePrototype = Object.create(null, { ...baseDescriptors, [MESSAGE_TYPE]: { value: this } });; this.refTypeCheck = new ReflectionTypeCheck(this); this.refJsonReader = new ReflectionJsonReader(this); this.refJsonWriter = new ReflectionJsonWriter(this); From a9ac176c0557a2252c462ee48b9e8af2f26c922c Mon Sep 17 00:00:00 2001 From: erichiggins0 Date: Fri, 8 Mar 2024 13:51:49 -0800 Subject: [PATCH 3/3] remove double semicolon --- packages/runtime/src/message-type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/message-type.ts b/packages/runtime/src/message-type.ts index 30345d16..b16a6888 100644 --- a/packages/runtime/src/message-type.ts +++ b/packages/runtime/src/message-type.ts @@ -69,7 +69,7 @@ export class MessageType implements IMessageType { this.typeName = name; this.fields = fields.map(normalizeFieldInfo); this.options = options ?? {}; - this.messagePrototype = Object.create(null, { ...baseDescriptors, [MESSAGE_TYPE]: { value: this } });; + this.messagePrototype = Object.create(null, { ...baseDescriptors, [MESSAGE_TYPE]: { value: this } }); this.refTypeCheck = new ReflectionTypeCheck(this); this.refJsonReader = new ReflectionJsonReader(this); this.refJsonWriter = new ReflectionJsonWriter(this);