mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
v8: add a js class for Serializer/Dserializer
Calling Serializer/Deserializer without new crashes node. Adding a js class which just inherits cpp bindings. Added regression tests. Fixes: https://github.com/nodejs/node/issues/13326 PR-URL: https://github.com/nodejs/node/pull/13541 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
e2617a0388
commit
12fd63d6bb
12
lib/v8.js
12
lib/v8.js
@ -15,11 +15,21 @@
|
||||
'use strict';
|
||||
|
||||
const { Buffer } = require('buffer');
|
||||
const { Serializer, Deserializer } = process.binding('serdes');
|
||||
const {
|
||||
Serializer: _Serializer,
|
||||
Deserializer: _Deserializer
|
||||
} = process.binding('serdes');
|
||||
const { copy } = process.binding('buffer');
|
||||
const { objectToString } = require('internal/util');
|
||||
const { FastBuffer } = require('internal/buffer');
|
||||
|
||||
// Calling exposed c++ functions directly throws exception as it expected to be
|
||||
// called with new operator and caused an assert to fire.
|
||||
// Creating JS wrapper so that it gets caught at JS layer.
|
||||
class Serializer extends _Serializer { }
|
||||
|
||||
class Deserializer extends _Deserializer { }
|
||||
|
||||
const {
|
||||
cachedDataVersionTag,
|
||||
setFlagsFromString,
|
||||
|
@ -131,3 +131,15 @@ const objects = [
|
||||
|
||||
assert.deepStrictEqual(v8.deserialize(buf), expectedResult);
|
||||
}
|
||||
|
||||
{
|
||||
assert.throws(
|
||||
() => { v8.Serializer(); },
|
||||
/^TypeError: Class constructor Serializer cannot be invoked without 'new'$/
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => { v8.Deserializer(); },
|
||||
/^TypeError: Class constructor Deserializer cannot be invoked without 'new'$/
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user