diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-09-18 04:48:06 +0300 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-10-25 22:33:45 +0300 |
commit | d66c9276a976b4177e56634a5707d43d0e56603e (patch) | |
tree | a9db6a76dc6f2c20cd89a402a98ffa97cf0a5545 /test | |
parent | 9f87d6ad4d71643f9b1bafcf4d6e4047ab4f61a9 (diff) |
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 https://github.com/ayojs/ayo/pull/63
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-v8-serdes.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 981e1961578..ad8666ee3ba 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -20,6 +20,8 @@ const objects = [ circular ]; +const hostObject = new (process.binding('js_stream').JSStream)(); + const serializerTypeError = /^TypeError: Class constructor Serializer cannot be invoked without 'new'$/; const deserializerTypeError = @@ -63,8 +65,8 @@ const deserializerTypeError = { const ser = new v8.DefaultSerializer(); ser._writeHostObject = common.mustCall((object) => { - assert.strictEqual(object, process.stdin._handle); - const buf = Buffer.from('stdin'); + assert.strictEqual(object, hostObject); + const buf = Buffer.from('hostObjectTag'); ser.writeUint32(buf.length); ser.writeRawBytes(buf); @@ -74,23 +76,23 @@ const deserializerTypeError = }); ser.writeHeader(); - ser.writeValue({ val: process.stdin._handle }); + ser.writeValue({ val: hostObject }); const des = new v8.DefaultDeserializer(ser.releaseBuffer()); des._readHostObject = common.mustCall(() => { const length = des.readUint32(); const buf = des.readRawBytes(length); - assert.strictEqual(buf.toString(), 'stdin'); + assert.strictEqual(buf.toString(), 'hostObjectTag'); assert.deepStrictEqual(des.readUint64(), [1, 2]); assert.strictEqual(des.readDouble(), -0.25); - return process.stdin._handle; + return hostObject; }); des.readHeader(); - assert.strictEqual(des.readValue().val, process.stdin._handle); + assert.strictEqual(des.readValue().val, hostObject); } { @@ -101,12 +103,12 @@ const deserializerTypeError = ser.writeHeader(); assert.throws(() => { - ser.writeValue({ val: process.stdin._handle }); + ser.writeValue({ val: hostObject }); }, /foobar/); } { - assert.throws(() => v8.serialize(process.stdin._handle), + assert.throws(() => v8.serialize(hostObject), /^Error: Unknown host object type: \[object .*\]$/); } |