| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,8 +35,8 @@ const { | |||
| 35 | 35 | const { Buffer } = require('buffer'); | |
| 36 | 36 | const { validateString } = require('internal/validators'); | |
| 37 | 37 | const { | |
| 38 | - Serializer: _Serializer, | ||
| 39 | - Deserializer: _Deserializer | ||
| 38 | + Serializer, | ||
| 39 | + Deserializer | ||
| 40 | 40 | } = internalBinding('serdes'); | |
| 41 | 41 | ||
| 42 | 42 | let profiler = {}; | |
@@ -70,13 +70,6 @@ function getHeapSnapshot() { | |||
| 70 | 70 | return new HeapSnapshotStream(handle); | |
| 71 | 71 | } | |
| 72 | 72 | ||
| 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 | - | ||
| 80 | 73 | const { | |
| 81 | 74 | cachedDataVersionTag, | |
| 82 | 75 | setFlagsFromString: _setFlagsFromString, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,6 +169,10 @@ Maybe<bool> SerializerContext::WriteHostObject(Isolate* isolate, | |||
| 169 | 169 | ||
| 170 | 170 | void SerializerContext::New(const FunctionCallbackInfo<Value>& args) { | |
| 171 | 171 | 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 | + } | ||
| 172 | 176 | ||
| 173 | 177 | new SerializerContext(env, args.This()); | |
| 174 | 178 | } | |
@@ -319,6 +323,10 @@ MaybeLocal<Object> DeserializerContext::ReadHostObject(Isolate* isolate) { | |||
| 319 | 323 | ||
| 320 | 324 | void DeserializerContext::New(const FunctionCallbackInfo<Value>& args) { | |
| 321 | 325 | 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 | + } | ||
| 322 | 330 | ||
| 323 | 331 | if (!args[0]->IsArrayBufferView()) { | |
| 324 | 332 | return node::THROW_ERR_INVALID_ARG_TYPE( | |
@@ -470,6 +478,7 @@ void Initialize(Local<Object> target, | |||
| 470 | 478 | Local<String> serializerString = | |
| 471 | 479 | FIXED_ONE_BYTE_STRING(env->isolate(), "Serializer"); | |
| 472 | 480 | ser->SetClassName(serializerString); | |
| 481 | + ser->ReadOnlyPrototype(); | ||
| 473 | 482 | target->Set(env->context(), | |
| 474 | 483 | serializerString, | |
| 475 | 484 | ser->GetFunction(env->context()).ToLocalChecked()).Check(); | |
@@ -496,6 +505,8 @@ void Initialize(Local<Object> target, | |||
| 496 | 505 | ||
| 497 | 506 | Local<String> deserializerString = | |
| 498 | 507 | FIXED_ONE_BYTE_STRING(env->isolate(), "Deserializer"); | |
| 508 | + des->SetLength(1); | ||
| 509 | + des->ReadOnlyPrototype(); | ||
| 499 | 510 | des->SetClassName(deserializerString); | |
| 500 | 511 | target->Set(env->context(), | |
| 501 | 512 | deserializerString, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,11 +25,6 @@ const objects = [ | |||
| 25 | 25 | ||
| 26 | 26 | const hostObject = new (internalBinding('js_stream').JSStream)(); | |
| 27 | 27 | ||
| 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 | - | ||
| 33 | 28 | { | |
| 34 | 29 | const ser = new v8.DefaultSerializer(); | |
| 35 | 30 | ser.writeHeader(); | |
@@ -186,8 +181,16 @@ const deserializerTypeError = | |||
| 186 | 181 | } | |
| 187 | 182 | ||
| 188 | 183 | { | |
| 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 | + }); | ||
| 191 | 194 | } | |
| 192 | 195 | ||
| 193 | 196 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments