Skip to content

Commit e07cdd4

Browse files
committed
Replace TypedArrayPrototypeSubarray StringFromCharCode in the byte-by-byte fallback path
Signed-off-by: Ali Hassan <ali-hassan27@outlook.com>
1 parent 825b3e3 commit e07cdd4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/internal/test_runner/runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
SafePromiseAllSettledReturnVoid,
2626
SafeSet,
2727
String,
28+
StringFromCharCode,
2829
StringPrototypeIndexOf,
2930
StringPrototypeSlice,
3031
StringPrototypeStartsWith,
@@ -391,7 +392,7 @@ class FileTest extends Test {
391392
data: {
392393
__proto__: null,
393394
file: this.name,
394-
message: TypedArrayPrototypeSubarray(bufferHead, 0, 1).toString('utf-8'),
395+
message: StringFromCharCode(bufferHead[0]),
395396
},
396397
});
397398

test/parallel/test-runner-v8-deserializer.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const headerLength = defaultSerializer.releaseBuffer().length;
2525
const headerOnly = Buffer.from([0xff, 0x0f]);
2626
const oversizedLengthHeader = Buffer.from([0xff, 0x0f, 0x7f, 0xff, 0xff, 0xff]);
2727
const truncatedLengthHeader = Buffer.from([0xff, 0x0f, 0x00, 0x01, 0x00, 0x00]);
28+
// Expected stdout for oversizedLengthHeader: first byte is emitted via
29+
// String.fromCharCode (byte-by-byte fallback in #drainRawBuffer), remaining
30+
// bytes go through the nonSerialized UTF-8 decode path in #processRawBuffer.
31+
const oversizedLengthStdout = String.fromCharCode(oversizedLengthHeader[0]) +
32+
Buffer.from(oversizedLengthHeader.subarray(1)).toString('utf-8');
2833

2934
function collectStdout(reported) {
3035
return reported
@@ -98,7 +103,7 @@ describe('v8 deserializer', common.mustCall(() => {
98103
reported,
99104
Array.from({ length: reported.length }, () => ({ type: 'test:stdout' })),
100105
);
101-
assert.strictEqual(collectStdout(reported), oversizedLengthHeader.toString('utf8'));
106+
assert.strictEqual(collectStdout(reported), oversizedLengthStdout);
102107
});
103108

104109
it('should flush incomplete v8 frame as stdout and keep prior valid data', async () => {
@@ -108,14 +113,14 @@ describe('v8 deserializer', common.mustCall(() => {
108113
Buffer.from('hello'),
109114
truncatedLengthHeader,
110115
]);
111-
assert.strictEqual(collectStdout(reported), `hello${truncatedLengthHeader.toString('utf8')}`);
116+
assert.strictEqual(collectStdout(reported), `hello${truncatedLengthHeader.toString('latin1')}`);
112117
});
113118

114119
it('should flush v8Header-only bytes as stdout when stream ends', async () => {
115120
// Just the two-byte v8 header with no size field at all.
116121
const reported = await collectReported([headerOnly]);
117122
assert(reported.every((event) => event.type === 'test:stdout'));
118-
assert.strictEqual(collectStdout(reported), headerOnly.toString('utf8'));
123+
assert.strictEqual(collectStdout(reported), headerOnly.toString('latin1'));
119124
});
120125

121126
it('should resync and parse valid messages after false v8 header', async () => {
@@ -128,7 +133,7 @@ describe('v8 deserializer', common.mustCall(() => {
128133
]);
129134
assert.deepStrictEqual(reported.at(-1), diagnosticEvent);
130135
assert.strictEqual(reported.filter((event) => event.type === 'test:diagnostic').length, 1);
131-
assert.strictEqual(collectStdout(reported), oversizedLengthHeader.toString('utf8'));
136+
assert.strictEqual(collectStdout(reported), oversizedLengthStdout);
132137
});
133138

134139
it('should preserve a false v8 header split across chunks', async () => {
@@ -137,7 +142,7 @@ describe('v8 deserializer', common.mustCall(() => {
137142
oversizedLengthHeader.subarray(1),
138143
]);
139144
assert(reported.every((event) => event.type === 'test:stdout'));
140-
assert.strictEqual(collectStdout(reported), oversizedLengthHeader.toString('utf8'));
145+
assert.strictEqual(collectStdout(reported), oversizedLengthStdout);
141146
});
142147

143148
const headerPosition = headerLength * 2 + 4;

0 commit comments

Comments
 (0)