From d2b1db32397d9e753575fa53230e4dd51969e8fe Mon Sep 17 00:00:00 2001 From: Eric Higgins <87031925+erichiggins0@users.noreply.github.com> Date: Wed, 13 Mar 2024 05:21:24 -0700 Subject: [PATCH] Extend Object prototype for message instances (#618) --- packages/runtime/src/message-type.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/message-type.ts b/packages/runtime/src/message-type.ts index 2c4d58f5..b16a6888 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,7 +69,7 @@ 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 = Object.create(null, { ...baseDescriptors, [MESSAGE_TYPE]: { value: this } }); this.refTypeCheck = new ReflectionTypeCheck(this); this.refJsonReader = new ReflectionJsonReader(this); this.refJsonWriter = new ReflectionJsonWriter(this);