-
-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow host to handle unknown references #410
Conversation
…d with unknown references.
Jint/Runtime/ExpressionIntepreter.cs
Outdated
@@ -851,7 +852,17 @@ public JsValue EvaluateCallExpression(CallExpression callExpression) | |||
|
|||
if (!func.IsObject()) | |||
{ | |||
throw new JavaScriptException(_engine.TypeError, r == null ? "" : string.Format("Property '{0}' of object is not a function", (callee as Reference).GetReferencedName())); | |||
var reference = (Reference) callee; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails some tests with System.InvalidCastException: Unable to cast object of type 'Jint.Native.JsValue' to type 'Jint.Runtime.References.Reference'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might have been hidden in the previous code because it was already throwing an exception. I assume the correct behavior is to throw a TypeError if it's not a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I assumed that this is correct because it would NRE otherwise. Will fix in a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, there was no NRE, there is a check for r == null
there.
FYI in ES6 this kind of pluggable behavior is part of the language, so you can dynamically change it. |
The dev branch is available on myget here https://www.myget.org/feed/Packages/jint |
Thanks |
|
||
namespace Jint.Tests.Runtime | ||
{ | ||
public class NullPropogation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this typo be fixed to NullPropagation ?
{ | ||
public class NullPropogation | ||
{ | ||
public class NullPropgationReferenceResolver : IReferenceResolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one to NullPropagationReferenceResolver
See #409
This handle null reference errors as well as methods calls.