Skip to content

Commit c8e4bdb

Browse files
committed
fix: Add missing encoding level to stream message handling, Remove redundant JSON.stringify
1 parent a709af0 commit c8e4bdb

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/rpc.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,10 @@ class RpcSessionImpl implements Importer, Exporter {
629629
msgLength = msgText.length;
630630
} else {
631631
encoded = msg;
632-
// For non-stringify levels, estimate size for flow control.
633-
// This may fail if msg contains non-JSON types (Uint8Array, BigInt, etc.)
634-
// In that case, use a rough estimate.
635-
try {
636-
msgLength = JSON.stringify(msg).length;
637-
} catch {
638-
// Rough estimate: 100 bytes per top-level message element
639-
msgLength = Array.isArray(msg) ? msg.length * 100 : 100;
640-
}
632+
// For non-stringify levels, use a rough estimate for flow control.
633+
// Avoid JSON.stringify since it would fail on non-JSON types (Uint8Array, BigInt, etc.)
634+
// and defeats the purpose of not stringifying.
635+
msgLength = Array.isArray(msg) ? msg.length * 100 : 100;
641636
}
642637
} catch (err) {
643638
// If JSON stringification failed, there's something wrong with the devaluator, as it should
@@ -835,7 +830,7 @@ class RpcSessionImpl implements Importer, Exporter {
835830
// - The export is automatically considered "pulled".
836831
// - Once the "resolve" is sent, the export is implicitly released.
837832
if (msg.length > 1) {
838-
let payload = new Evaluator(this).evaluate(msg[1]);
833+
let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
839834
let hook = new PayloadStubHook(payload);
840835
hook.ignoreUnhandledRejections();
841836

0 commit comments

Comments
 (0)