From 62f5ca2ef1ec59c12d87232b9f94e7a470c4e59c Mon Sep 17 00:00:00 2001 From: Michael Pishchagin Date: Sun, 13 Jul 2025 14:09:21 +1000 Subject: [PATCH] feat(javascript): make internal properties non-enumerable Changed _io, _parent, and _root properties to be non-enumerable using Object.defineProperty. This prevents these internal properties from appearing in JSON.stringify() output or for...in loops, making Kaitai objects more suitable for JSON serialization and API usage. --- .../io/kaitai/struct/languages/JavaScriptCompiler.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala index 2c7e3d81b..ab5118081 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala @@ -95,12 +95,12 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts(s"function ${type2class(name.last)}(_io, _parent, _root$endianSuffix$paramsList) {") out.inc - out.puts("this._io = _io;") - out.puts("this._parent = _parent;") + out.puts("Object.defineProperty(this, '_io', { value: _io, writable: true, enumerable: false });") + out.puts("Object.defineProperty(this, '_parent', { value: _parent, writable: true, enumerable: false });") if (name == rootClassName) { - out.puts("this._root = _root || this;") + out.puts("Object.defineProperty(this, '_root', { value: _root || this, writable: true, enumerable: false });") } else { - out.puts("this._root = _root;") + out.puts("Object.defineProperty(this, '_root', { value: _root, writable: true, enumerable: false });") } if (isHybrid)