Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3170636

Browse filesBrowse files
ExE-Bossdanielleadams
authored andcommitted
v8: fix native serdes constructors
Fixes: #13326 Refs: #13541 PR-URL: #36549 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent c844d22 commit 3170636
Copy full SHA for 3170636

File tree

Expand file treeCollapse file tree

3 files changed

+23
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-16
lines changed
Open diff view settings
Collapse file

‎lib/v8.js‎

Copy file name to clipboardExpand all lines: lib/v8.js
+2-9Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const {
3535
const { Buffer } = require('buffer');
3636
const { validateString } = require('internal/validators');
3737
const {
38-
Serializer: _Serializer,
39-
Deserializer: _Deserializer
38+
Serializer,
39+
Deserializer
4040
} = internalBinding('serdes');
4141

4242
let profiler = {};
@@ -70,13 +70,6 @@ function getHeapSnapshot() {
7070
return new HeapSnapshotStream(handle);
7171
}
7272

73-
// Calling exposed c++ functions directly throws exception as it expected to be
74-
// called with new operator and caused an assert to fire.
75-
// Creating JS wrapper so that it gets caught at JS layer.
76-
class Serializer extends _Serializer { }
77-
78-
class Deserializer extends _Deserializer { }
79-
8073
const {
8174
cachedDataVersionTag,
8275
setFlagsFromString: _setFlagsFromString,
Collapse file

‎src/node_serdes.cc‎

Copy file name to clipboardExpand all lines: src/node_serdes.cc
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ Maybe<bool> SerializerContext::WriteHostObject(Isolate* isolate,
169169

170170
void SerializerContext::New(const FunctionCallbackInfo<Value>& args) {
171171
Environment* env = Environment::GetCurrent(args);
172+
if (!args.IsConstructCall()) {
173+
return THROW_ERR_CONSTRUCT_CALL_REQUIRED(
174+
env, "Class constructor Serializer cannot be invoked without 'new'");
175+
}
172176

173177
new SerializerContext(env, args.This());
174178
}
@@ -319,6 +323,10 @@ MaybeLocal<Object> DeserializerContext::ReadHostObject(Isolate* isolate) {
319323

320324
void DeserializerContext::New(const FunctionCallbackInfo<Value>& args) {
321325
Environment* env = Environment::GetCurrent(args);
326+
if (!args.IsConstructCall()) {
327+
return THROW_ERR_CONSTRUCT_CALL_REQUIRED(
328+
env, "Class constructor Deserializer cannot be invoked without 'new'");
329+
}
322330

323331
if (!args[0]->IsArrayBufferView()) {
324332
return node::THROW_ERR_INVALID_ARG_TYPE(
@@ -470,6 +478,7 @@ void Initialize(Local<Object> target,
470478
Local<String> serializerString =
471479
FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer");
472480
ser->SetClassName(serializerString);
481+
ser->ReadOnlyPrototype();
473482
target->Set(env->context(),
474483
serializerString,
475484
ser->GetFunction(env->context()).ToLocalChecked()).Check();
@@ -496,6 +505,8 @@ void Initialize(Local<Object> target,
496505

497506
Local<String> deserializerString =
498507
FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer");
508+
des->SetLength(1);
509+
des->ReadOnlyPrototype();
499510
des->SetClassName(deserializerString);
500511
target->Set(env->context(),
501512
deserializerString,
Collapse file

‎test/parallel/test-v8-serdes.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-v8-serdes.js
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ const objects = [
2525

2626
const hostObject = new (internalBinding('js_stream').JSStream)();
2727

28-
const serializerTypeError =
29-
/^TypeError: Class constructor Serializer cannot be invoked without 'new'$/;
30-
const deserializerTypeError =
31-
/^TypeError: Class constructor Deserializer cannot be invoked without 'new'$/;
32-
3328
{
3429
const ser = new v8.DefaultSerializer();
3530
ser.writeHeader();
@@ -186,8 +181,16 @@ const deserializerTypeError =
186181
}
187182

188183
{
189-
assert.throws(v8.Serializer, serializerTypeError);
190-
assert.throws(v8.Deserializer, deserializerTypeError);
184+
assert.throws(() => v8.Serializer(), {
185+
constructor: TypeError,
186+
message: "Class constructor Serializer cannot be invoked without 'new'",
187+
code: 'ERR_CONSTRUCT_CALL_REQUIRED'
188+
});
189+
assert.throws(() => v8.Deserializer(), {
190+
constructor: TypeError,
191+
message: "Class constructor Deserializer cannot be invoked without 'new'",
192+
code: 'ERR_CONSTRUCT_CALL_REQUIRED'
193+
});
191194
}
192195

193196

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.