From 955a1bbb9ded4621b618ab201c45a2c7bc89d866 Mon Sep 17 00:00:00 2001 From: Rajaram Gaunker Date: Fri, 9 Jun 2017 10:38:55 -0700 Subject: [PATCH] v8: add a js class for Serializer/Deserializer 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 --- lib/v8.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index 9c1cdccb80839e..7cdf4598c4fdcd 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -15,14 +15,20 @@ 'use strict'; const { Buffer } = require('buffer'); -const serdesBindings = 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'); -class Serializer extends serdesBindings.Serializer {} +// 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 serdesBindings.Deserializer {} +class Deserializer extends _Deserializer { } const { cachedDataVersionTag,