@@ -492,25 +492,26 @@ void SdlGameController::enableGyroscope(const Napi::CallbackInfo &info) {
492492
493493 SDL_bool enable = SDL_TRUE;
494494 int playerNumber = 0 ; // enable for all players
495+ auto warning = Napi::Object::New (env);
495496
496497 // Check if enable is set.
497498 if (info.Length () > 0 ) {
498- // Check the argument types
499- if (!info[0 ].IsBoolean ()) {
500- throw Napi::Error::New (env, " Wrong arguments" );
501- return ;
499+ if (info[0 ].IsBoolean ()) {
500+ enable = info[0 ].ToBoolean () ? SDL_TRUE : SDL_FALSE;
501+ } else {
502+ warning.Set (" message" , " wrong argument type: enable" );
503+ emit ({Napi::String::New (env, " warning" ), warning});
502504 }
503- enable = info[0 ].ToBoolean () ? SDL_TRUE : SDL_FALSE;
504505 }
505506
506507 // Check if player number is set
507508 if (info.Length () > 1 ) {
508- // Check the argument types
509- if (!info[0 ].IsNumber ()) {
510- throw Napi::Error::New (env, " Wrong arguments" );
511- return ;
509+ if (info[0 ].IsNumber ()) {
510+ playerNumber = info[1 ].ToNumber ();
511+ } else {
512+ warning.Set (" message" , " wrong argument type: player" );
513+ emit ({Napi::String::New (env, " warning" ), warning});
512514 }
513- playerNumber = info[1 ].ToNumber ();
514515 }
515516
516517 for (auto &controller : gamecontrollers) {
@@ -555,24 +556,25 @@ void SdlGameController::enableAccelerometer(const Napi::CallbackInfo &info) {
555556
556557 int playerNumber = 0 ; // enable for all players
557558 SDL_bool enable = SDL_TRUE;
559+ auto warning = Napi::Object::New (env);
558560
559561 // Check the number of arguments passed.
560562 if (info.Length () > 0 ) {
561- // Check the argument types
562- if (!info[0 ].IsBoolean ()) {
563- throw Napi::Error::New (env, " Wrong arguments" );
564- return ;
563+ if (info[0 ].IsBoolean ()) {
564+ enable = info[0 ].ToBoolean () ? SDL_TRUE : SDL_FALSE;
565+ } else {
566+ warning.Set (" message" , " wrong argument type: enable" );
567+ emit ({Napi::String::New (env, " warning" ), warning});
565568 }
566- enable = info[0 ].ToBoolean () ? SDL_TRUE : SDL_FALSE;
567569 }
568570
569571 if (info.Length () > 1 ) {
570- // Check the argument types
571- if (!info[1 ].IsNumber ()) {
572- throw Napi::Error::New (env, " Wrong arguments" );
573- return ;
572+ if (info[1 ].IsNumber ()) {
573+ playerNumber = info[1 ].ToNumber ();
574+ } else {
575+ warning.Set (" message" , " wrong argument type: player" );
576+ emit ({Napi::String::New (env, " warning" ), warning});
574577 }
575- playerNumber = info[1 ].ToNumber ();
576578 }
577579
578580 for (auto &controller : gamecontrollers) {
@@ -620,45 +622,46 @@ void SdlGameController::rumble(const Napi::CallbackInfo &info) {
620622 Uint16 low_frequency_rumble = 0xFFFC ;
621623 Uint16 high_frequency_rumble = 0xFFFC ;
622624 Uint32 duration_ms = 250 ;
625+ auto warning = Napi::Object::New (env);
623626
624627 // Check for low frequency
625628 if (info.Length () > 0 ) {
626- // Check the argument type
627- if (!info[0 ].IsNumber ()) {
628- throw Napi::Error::New (env, " Wrong arguments" );
629- return ;
629+ if (info[0 ].IsNumber ()) {
630+ low_frequency_rumble = static_cast <uint32_t >(info[0 ].ToNumber ());
631+ } else {
632+ warning.Set (" message" , " wrong argument type: low_frequency_rumble" );
633+ emit ({Napi::String::New (env, " warning" ), warning});
630634 }
631- low_frequency_rumble = static_cast <uint32_t >(info[0 ].ToNumber ());
632635 }
633636
634637 // Check for high frequency
635638 if (info.Length () > 1 ) {
636- // Check the argument type
637- if (!info[1 ].IsNumber ()) {
638- throw Napi::Error::New (env, " Wrong arguments" );
639- return ;
639+ if (info[1 ].IsNumber ()) {
640+ high_frequency_rumble = static_cast <uint32_t >(info[1 ].ToNumber ());
641+ } else {
642+ warning.Set (" message" , " wrong argument type: high_frequency_rumble" );
643+ emit ({Napi::String::New (env, " warning" ), warning});
640644 }
641- high_frequency_rumble = static_cast <uint32_t >(info[1 ].ToNumber ());
642645 }
643646
644647 // Check for high frequency
645648 if (info.Length () > 2 ) {
646- // Check the argument type
647- if (!info[2 ].IsNumber ()) {
648- throw Napi::Error::New (env, " Wrong arguments" );
649- return ;
649+ if (info[2 ].IsNumber ()) {
650+ duration_ms = static_cast <uint32_t >(info[2 ].ToNumber ());
651+ } else {
652+ warning.Set (" message" , " wrong argument type: duration_ms" );
653+ emit ({Napi::String::New (env, " warning" ), warning});
650654 }
651- duration_ms = static_cast <uint32_t >(info[2 ].ToNumber ());
652655 }
653656
654657 // Check for player number
655658 if (info.Length () > 3 ) {
656- // Check the argument types
657- if (!info[3 ].IsNumber ()) {
658- throw Napi::Error::New (env, " Wrong arguments" );
659- return ;
659+ if (info[3 ].IsNumber ()) {
660+ playerNumber = info[3 ].ToNumber ();
661+ } else {
662+ warning.Set (" message" , " wrong argument type: player" );
663+ emit ({Napi::String::New (env, " warning" ), warning});
660664 }
661- playerNumber = info[3 ].ToNumber ();
662665 }
663666
664667 for (auto &controller : gamecontrollers) {
@@ -705,45 +708,47 @@ void SdlGameController::rumbleTriggers(const Napi::CallbackInfo &info) {
705708 Uint16 left_rumble = 0xFFFC ;
706709 Uint16 right_rumble = 0xFFFC ;
707710 Uint32 duration_ms = 250 ;
711+ auto warning = Napi::Object::New (env);
708712
709713 // Check for left
710714 if (info.Length () > 0 ) {
711- // Check the argument type
712- if (!info[0 ].IsNumber ()) {
713- throw Napi::Error::New (env, " Wrong arguments" );
714- return ;
715+ if (info[0 ].IsNumber ()) {
716+ left_rumble = static_cast <uint32_t >(info[0 ].ToNumber ());
717+ } else {
718+ warning.Set (" message" , " wrong argument type: left_rumble" );
719+ emit ({Napi::String::New (env, " warning" ), warning});
715720 }
716- left_rumble = static_cast <uint32_t >(info[0 ].ToNumber ());
717721 }
718722
719723 // Check for right
720724 if (info.Length () > 1 ) {
721- // Check the argument type
722- if (!info[1 ].IsNumber ()) {
723- throw Napi::Error::New (env, " Wrong arguments" );
724- return ;
725+ if (info[1 ].IsNumber ()) {
726+ right_rumble = static_cast <uint32_t >(info[1 ].ToNumber ());
727+ } else {
728+ warning.Set (" message" , " wrong argument type: right_rumble" );
729+ emit ({Napi::String::New (env, " warning" ), warning});
725730 }
726- right_rumble = static_cast <uint32_t >(info[1 ].ToNumber ());
727731 }
728732
729733 // Check for duration
730734 if (info.Length () > 2 ) {
731- // Check the argument type
732- if (!info[2 ].IsNumber ()) {
733- throw Napi::Error::New (env, " Wrong arguments" );
734- return ;
735+ if (info[2 ].IsNumber ()) {
736+ duration_ms = static_cast <uint32_t >(info[2 ].ToNumber ());
737+ } else {
738+ warning.Set (" message" , " wrong argument type: duration_ms" );
739+ emit ({Napi::String::New (env, " warning" ), warning});
735740 }
736- duration_ms = static_cast <uint32_t >(info[2 ].ToNumber ());
737741 }
738742
739743 // Check for player number
740744 if (info.Length () > 3 ) {
741745 // Check the argument types
742- if (!info[3 ].IsNumber ()) {
743- throw Napi::Error::New (env, " Wrong arguments" );
744- return ;
746+ if (info[3 ].IsNumber ()) {
747+ playerNumber = info[3 ].ToNumber ();
748+ } else {
749+ warning.Set (" message" , " wrong argument type: player" );
750+ emit ({Napi::String::New (env, " warning" ), warning});
745751 }
746- playerNumber = info[3 ].ToNumber ();
747752 }
748753
749754 for (auto &controller : gamecontrollers) {
@@ -790,45 +795,46 @@ void SdlGameController::setLeds(const Napi::CallbackInfo &info) {
790795 Uint8 red = 0x00 ;
791796 Uint8 green = 0x00 ;
792797 Uint8 blue = 0xff ;
798+ auto warning = Napi::Object::New (env);
793799
794800 // Check for red
795801 if (info.Length () > 0 ) {
796- // Check the argument type
797- if (!info[0 ].IsNumber ()) {
798- throw Napi::Error::New (env, " Wrong arguments" );
799- return ;
802+ if (info[0 ].IsNumber ()) {
803+ red = static_cast <uint32_t >(info[0 ].ToNumber ());
804+ } else {
805+ warning.Set (" message" , " wrong argument type: red" );
806+ emit ({Napi::String::New (env, " warning" ), warning});
800807 }
801- red = static_cast <uint32_t >(info[0 ].ToNumber ());
802808 }
803809
804810 // Check for green
805811 if (info.Length () > 1 ) {
806- // Check the argument type
807- if (!info[1 ].IsNumber ()) {
808- throw Napi::Error::New (env, " Wrong arguments" );
809- return ;
812+ if (info[1 ].IsNumber ()) {
813+ green = static_cast <uint32_t >(info[1 ].ToNumber ());
814+ } else {
815+ warning.Set (" message" , " wrong argument type: green" );
816+ emit ({Napi::String::New (env, " warning" ), warning});
810817 }
811- green = static_cast <uint32_t >(info[1 ].ToNumber ());
812818 }
813819
814820 // Check for blue
815821 if (info.Length () > 2 ) {
816- // Check the argument type
817- if (!info[2 ].IsNumber ()) {
818- throw Napi::Error::New (env, " Wrong arguments" );
819- return ;
822+ if (info[2 ].IsNumber ()) {
823+ blue = static_cast <uint32_t >(info[2 ].ToNumber ());
824+ } else {
825+ warning.Set (" message" , " wrong argument type: blue" );
826+ emit ({Napi::String::New (env, " warning" ), warning});
820827 }
821- blue = static_cast <uint32_t >(info[2 ].ToNumber ());
822828 }
823829
824830 // Check for player number
825831 if (info.Length () > 3 ) {
826- // Check the argument types
827- if (!info[3 ].IsNumber ()) {
828- throw Napi::Error::New (env, " Wrong arguments" );
829- return ;
832+ if (info[3 ].IsNumber ()) {
833+ playerNumber = info[3 ].ToNumber ();
834+ } else {
835+ warning.Set (" message" , " wrong argument type: player" );
836+ emit ({Napi::String::New (env, " warning" ), warning});
830837 }
831- playerNumber = info[3 ].ToNumber ();
832838 }
833839
834840 for (auto &controller : gamecontrollers) {
0 commit comments