HaxeFoundation / HaxeFoundation/hxnodejs

Printing the result of hxToBytes will hang the runtime

Open
#171 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
177
Forks
58
PR merge metrics
No merged PRs in 30d

Description

```haxe
class Main {
static function main() {
var buf = js.node.Buffer.from('foo');
var bytes = buf.hxToBytes();
trace(bytes);
}
}
```

Run the above code with node 12+, it will hang forever.
node 10 or below is fine though.

However, when run with a debugger (vscode), it will crash with the following error.

```
Waiting for the debugger to disconnect...
internal/util/inspect.js:1249
throw err;
^

SyntaxError: Invalid regular expression: /(.{2})/: Stack overflow
at String.replace ()
at Buffer.inspect (buffer.js:814:41)
at formatValue (internal/util/inspect.js:693:31)
at formatProperty (internal/util/inspect.js:1558:11)
at formatRaw (internal/util/inspect.js:933:9)
at formatValue (internal/util/inspect.js:721:10)
at inspect (internal/util/inspect.js:264:10)
at Buffer.inspect (buffer.js:831:14)
at formatValue (internal/util/inspect.js:693:31)
at formatProperty (internal/util/inspect.js:1558:11)
Process exited with code 1
```

It could be fixed by commentting out a line in the gennerated js:

```js
js_node_buffer__$Buffer_Helper.bytesOfBuffer = function(b) {
var o = Object.create(haxe_io_Bytes.prototype);
o.length = b.byteLength;
// o.b = b; <-- commentting this line will fix the hang
b.bufferValue = b;
b.hxBytes = o;
b.bytes = b;
return o;
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.