@@ -436,13 +436,25 @@ void ConverterObject::Create(const FunctionCallbackInfo<Value>& args) {
436
436
void ConverterObject::Decode (const FunctionCallbackInfo<Value>& args) {
437
437
Environment* env = Environment::GetCurrent (args);
438
438
439
- CHECK_GE (args.Length (), 3 ); // Converter, Buffer, Flags
439
+ CHECK_GE (args.Length (), 4 ); // Converter, Buffer, Flags, Encoding
440
440
441
441
ConverterObject* converter;
442
442
ASSIGN_OR_RETURN_UNWRAP (&converter, args[0 ].As <Object>());
443
+
444
+ if (!(args[1 ]->IsArrayBuffer () || args[1 ]->IsSharedArrayBuffer () ||
445
+ args[1 ]->IsArrayBufferView ())) {
446
+ return node::THROW_ERR_INVALID_ARG_TYPE (
447
+ env->isolate (),
448
+ " The \" input\" argument must be an instance of SharedArrayBuffer, "
449
+ " ArrayBuffer or ArrayBufferView." );
450
+ }
451
+
443
452
ArrayBufferViewContents<char > input (args[1 ]);
444
453
int flags = args[2 ]->Uint32Value (env->context ()).ToChecked ();
445
454
455
+ CHECK (args[3 ]->IsString ());
456
+ Local<String> from_encoding = args[3 ].As <String>();
457
+
446
458
UErrorCode status = U_ZERO_ERROR;
447
459
MaybeStackBuffer<UChar> result;
448
460
@@ -524,14 +536,14 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) {
524
536
Local<Value> ret;
525
537
if (encoded.ToLocal (&ret)) {
526
538
args.GetReturnValue ().Set (ret);
527
- } else {
528
- args.GetReturnValue ().Set (error);
539
+ return ;
529
540
}
530
-
531
- return ;
532
541
}
533
542
534
- args.GetReturnValue ().Set (status);
543
+ node::THROW_ERR_ENCODING_INVALID_ENCODED_DATA (
544
+ env->isolate (),
545
+ " The encoded data was not valid for encoding %s" ,
546
+ *node::Utf8Value (env->isolate (), from_encoding));
535
547
}
536
548
537
549
ConverterObject::ConverterObject (
0 commit comments