Skip to content

Commit

Permalink
Fix #138
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed May 9, 2018
1 parent 674d90a commit 9498e6b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
24 changes: 24 additions & 0 deletions IntegrationTests/Expressions/EqualTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS.BaseLibrary;
using NiL.JS.Core;

namespace IntegrationTests.Expressions
{
[TestClass]
public class EqualTests
{
[TestMethod]
public void ComparisonWithNotExistsShouldWorkProperly()
{
Action f = () => { };
var context = new Context();
context.DefineVariable("test").Assign(f);

var result = context.Eval("test() == 'hi there'");

Assert.IsFalse((bool)result);
}
}
}
1 change: 1 addition & 0 deletions NiL.JS/BaseLibrary/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public static JSValue toString(JSValue self, Arguments radix)
break;
}
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
case JSValueType.Undefined:
{
r = 10;
Expand Down
4 changes: 0 additions & 4 deletions NiL.JS/Core/JSValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ public virtual object Value
return (_oValue as JSObject).Value;
return _oValue;
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
default:
return null;
}
Expand Down Expand Up @@ -271,8 +269,6 @@ protected set
_oValue = value;
break;
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
default:
throw new InvalidOperationException();
}
Expand Down
3 changes: 3 additions & 0 deletions NiL.JS/Expressions/Addition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ internal static void Impl(JSValue resultContainer, JSValue first, JSValue second
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
{
tstr = new RopeString(tstr, "undefined");
break;
Expand Down Expand Up @@ -237,6 +238,7 @@ internal static void Impl(JSValue resultContainer, JSValue first, JSValue second
return;
}
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
case JSValueType.Undefined:
{
if (second._valueType >= JSValueType.Object)
Expand All @@ -259,6 +261,7 @@ internal static void Impl(JSValue resultContainer, JSValue first, JSValue second
}
case JSValueType.Object: // undefined+null
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
case JSValueType.Undefined:
{
resultContainer._valueType = JSValueType.Double;
Expand Down
1 change: 1 addition & 0 deletions NiL.JS/Expressions/Decrement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public override JSValue Evaluate(Context context)
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
{
val._valueType = JSValueType.Double;
val._dValue = double.NaN;
Expand Down
1 change: 1 addition & 0 deletions NiL.JS/Expressions/Equal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public override JSValue Evaluate(Context context)
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
{
temp = _right.Evaluate(context);
switch (temp._valueType)
Expand Down
1 change: 1 addition & 0 deletions NiL.JS/Expressions/Increment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public override JSValue Evaluate(Context context)
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
{
val._valueType = JSValueType.Double;
val._dValue = double.NaN;
Expand Down
1 change: 1 addition & 0 deletions NiL.JS/Expressions/More.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ internal static bool Check(JSValue first, JSValue second, bool lessOrEqual)
}
case JSValueType.Undefined:
case JSValueType.NotExistsInObject:
case JSValueType.NotExists:
{
return lessOrEqual;
}
Expand Down

0 comments on commit 9498e6b

Please sign in to comment.