Skip to content

Commit 70670b0

Browse files
addaleaxdanbev
authored andcommitted
test: make test-v8-serdes work without stdin
If `stdin` was closed or referred to a file, this didn't work, because it was accessed via file descriptor. Instead, use another generic native object. cherry-picked from ayojs/ayo#63 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 57a716f commit 70670b0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/parallel/test-v8-serdes.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const objects = [
2020
circular
2121
];
2222

23+
const hostObject = new (process.binding('js_stream').JSStream)();
24+
2325
const serializerTypeError =
2426
/^TypeError: Class constructor Serializer cannot be invoked without 'new'$/;
2527
const deserializerTypeError =
@@ -63,8 +65,8 @@ const deserializerTypeError =
6365
{
6466
const ser = new v8.DefaultSerializer();
6567
ser._writeHostObject = common.mustCall((object) => {
66-
assert.strictEqual(object, process.stdin._handle);
67-
const buf = Buffer.from('stdin');
68+
assert.strictEqual(object, hostObject);
69+
const buf = Buffer.from('hostObjectTag');
6870

6971
ser.writeUint32(buf.length);
7072
ser.writeRawBytes(buf);
@@ -74,23 +76,23 @@ const deserializerTypeError =
7476
});
7577

7678
ser.writeHeader();
77-
ser.writeValue({ val: process.stdin._handle });
79+
ser.writeValue({ val: hostObject });
7880

7981
const des = new v8.DefaultDeserializer(ser.releaseBuffer());
8082
des._readHostObject = common.mustCall(() => {
8183
const length = des.readUint32();
8284
const buf = des.readRawBytes(length);
8385

84-
assert.strictEqual(buf.toString(), 'stdin');
86+
assert.strictEqual(buf.toString(), 'hostObjectTag');
8587

8688
assert.deepStrictEqual(des.readUint64(), [1, 2]);
8789
assert.strictEqual(des.readDouble(), -0.25);
88-
return process.stdin._handle;
90+
return hostObject;
8991
});
9092

9193
des.readHeader();
9294

93-
assert.strictEqual(des.readValue().val, process.stdin._handle);
95+
assert.strictEqual(des.readValue().val, hostObject);
9496
}
9597

9698
{
@@ -101,12 +103,12 @@ const deserializerTypeError =
101103

102104
ser.writeHeader();
103105
assert.throws(() => {
104-
ser.writeValue({ val: process.stdin._handle });
106+
ser.writeValue({ val: hostObject });
105107
}, /foobar/);
106108
}
107109

108110
{
109-
assert.throws(() => v8.serialize(process.stdin._handle),
111+
assert.throws(() => v8.serialize(hostObject),
110112
/^Error: Unknown host object type: \[object .*\]$/);
111113
}
112114

0 commit comments

Comments
 (0)