Skip to content

Printing the result of hxToBytes will hang the runtime #171

@kevinresol

Description

@kevinresol
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 (<anonymous>)
    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_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;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions