Skip to content

Commit 1b017f2

Browse files
committed
Merge pull request #17 from UnTraDe/overloading
Fixed choosing incorrect method overload
2 parents 5fc2387 + 2c55e85 commit 1b017f2

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Source/Noesis.Javascript/JavascriptInterop.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ JavascriptInterop::Invoker(const v8::FunctionCallbackInfo<Value>& iArgs)
579579
cli::array<System::Object^>^ arguments;
580580

581581
// Match arguments & parameters counts. We will add nulls where
582-
// we have imsufficient parameters. Note that this checking does
582+
// we have insufficient parameters. Note that this checking does
583583
// not detect where nulls have been supplied (or insufficient parameters
584-
// have been spplied), but the corresponding parameter cannot accept
584+
// have been supplied), but the corresponding parameter cannot accept
585585
// a null. This will trigger an exception during invocation.
586586
if (iArgs.Length() <= parametersInfo->Length)
587587
{
@@ -626,10 +626,32 @@ JavascriptInterop::Invoker(const v8::FunctionCallbackInfo<Value>& iArgs)
626626
bestMethodArguments = arguments;
627627
bestMethodMatchedArgs = match;
628628
}
629-
629+
else if (match == bestMethodMatchedArgs)
630+
{
631+
if (suppliedArguments->Length == parametersInfo->Length) // Prefer method with the most matches and the same length of arguments
632+
{
633+
bestMethod = method;
634+
bestMethodArguments = arguments;
635+
bestMethodMatchedArgs = match;
636+
}
637+
}
638+
639+
/*
640+
THE CODE BELOW MAY CHOOSE A METHOD PREMATURLY
641+
for example:
642+
643+
public void test(string a, int b, bool c) { ... }
644+
public void test(string a, int b, bool c, float d) { ... }
645+
646+
and then invoke it this way in JavaScript:
647+
648+
test("some text", 1234, true, 3.14);
649+
650+
it'll invoke the first one instead of the second because it found 3 matches and there are 3 arguments.
651+
*/
630652
// skip lookup if all args matched
631-
if (match == arguments->Length)
632-
break;
653+
//if (match == arguments->Length)
654+
//break;
633655
}
634656
}
635657
}

0 commit comments

Comments
 (0)