File tree 2 files changed +19
-3
lines changed
Tests/Noesis.Javascript.Tests
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -719,7 +719,8 @@ JavascriptInterop::Invoker(const v8::FunctionCallbackInfo<Value>& iArgs)
719
719
arguments = gcnew cli::array<System::Object^>(parametersInfo->Length ); // trailing parameters will be null
720
720
for (int p = 0 ; p < suppliedArguments->Length ; p++)
721
721
{
722
- System::Type^ paramType = parametersInfo[p]->ParameterType ;
722
+ System::Reflection::ParameterInfo^ parameter = parametersInfo[p];
723
+ System::Type^ paramType = parameter->ParameterType ;
723
724
724
725
if (suppliedArguments[p] != nullptr )
725
726
{
@@ -740,9 +741,15 @@ JavascriptInterop::Invoker(const v8::FunctionCallbackInfo<Value>& iArgs)
740
741
}
741
742
}
742
743
}
744
+ else if (parameter->IsOptional && parameter->HasDefaultValue && iArgs[p]->IsUndefined ())
745
+ {
746
+ // pass default value if parameter is optional and undefined was supplied as an argument
747
+ arguments[p] = parameter->DefaultValue ;
748
+ }
743
749
}
744
- for (int p = suppliedArguments->Length ; p < arguments->Length ; p++) // set default values if there are optional parameters
750
+ for (int p = suppliedArguments->Length ; p < arguments->Length ; p++)
745
751
{
752
+ // pass default values if there are optional parameters
746
753
System::Reflection::ParameterInfo^ parameter = parametersInfo[p];
747
754
if (parameter->IsOptional && parameter->HasDefaultValue )
748
755
arguments[p] = parameter->DefaultValue ;
Original file line number Diff line number Diff line change @@ -272,7 +272,16 @@ public void MethodCallWithRequiredAndDefaultParameters_PassingAllActualParameter
272
272
}
273
273
274
274
[ TestMethod ]
275
- [ Ignore ]
275
+ public void MethodCallWithRequiredAndDefaultParameters_PassingUndefinedForAllOptionalActualParameter ( )
276
+ {
277
+ var obj = new TypedPropertiesClass ( ) ;
278
+ _context . SetParameter ( "obj" , obj ) ;
279
+ var result = _context . Run ( "obj.methodWithRequiredAndDefaultParameters(1, undefined, undefined)" ) ;
280
+
281
+ result . Should ( ) . Be ( "i: 1, s: abc, b: True" ) ;
282
+ }
283
+
284
+ [ TestMethod ]
276
285
public void MethodCallWithRequiredAndDefaultParameters_PassingOnlyOneOptionalActualParameterLeavingTheMiddleOneUndefined ( )
277
286
{
278
287
var obj = new TypedPropertiesClass ( ) ;
You can’t perform that action at this time.
0 commit comments