@@ -436,13 +436,25 @@ void ConverterObject::Create(const FunctionCallbackInfo<Value>& args) {
436436void  ConverterObject::Decode (const  FunctionCallbackInfo<Value>& args) {
437437  Environment* env = Environment::GetCurrent (args);
438438
439-   CHECK_GE (args.Length (), 3 );  //  Converter, Buffer, Flags
439+   CHECK_GE (args.Length (), 4 );  //  Converter, Buffer, Flags, Encoding 
440440
441441  ConverterObject* converter;
442442  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+ 
443452  ArrayBufferViewContents<char > input (args[1 ]);
444453  int  flags = args[2 ]->Uint32Value (env->context ()).ToChecked ();
445454
455+   CHECK (args[3 ]->IsString ());
456+   Local<String> from_encoding = args[3 ].As <String>();
457+ 
446458  UErrorCode status = U_ZERO_ERROR;
447459  MaybeStackBuffer<UChar> result;
448460
@@ -524,14 +536,14 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) {
524536    Local<Value> ret;
525537    if  (encoded.ToLocal (&ret)) {
526538      args.GetReturnValue ().Set (ret);
527-     } else  {
528-       args.GetReturnValue ().Set (error);
539+       return ;
529540    }
530- 
531-     return ;
532541  }
533542
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));
535547}
536548
537549ConverterObject::ConverterObject (
0 commit comments