Skip to content
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

Fix some Object static methods returning wrong value #1318

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 24 additions & 8 deletions Jint.Tests/Runtime/InteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ public void ShouldGetIteratorForListAndDictionary()
_engine.SetValue("collection", new List<string> { "a", "b", "c" });
Assert.Equal("abc", _engine.Evaluate(Script));

_engine.SetValue("collection", new Dictionary<string, object> { {"a", 1 }, { "b", 2 }, { "c", 3 } });
_engine.SetValue("collection", new Dictionary<string, object> { { "a", 1 }, { "b", 2 }, { "c", 3 } });
Assert.Equal("a,1b,2c,3", _engine.Evaluate(Script));
}

Expand Down Expand Up @@ -2985,7 +2985,7 @@ function Eval(param0, param1)

// checking throwing exception in override operator
string errorMsg = string.Empty;
errorMsg = Assert.Throws<JavaScriptException>(() => engine.Invoke("Eval", new object[] {new Dimensional("kg", 30), new Dimensional("piece", 70)})).Message;
errorMsg = Assert.Throws<JavaScriptException>(() => engine.Invoke("Eval", new object[] { new Dimensional("kg", 30), new Dimensional("piece", 70) })).Message;
Assert.Equal("Dimensionals with different measure types are non-summable", errorMsg);
}

Expand All @@ -2997,7 +2997,7 @@ private class Profile
[Fact]
public void GenericParameterResolutionShouldWorkWithNulls()
{
var result =new Engine()
var result = new Engine()
.SetValue("JintCommon", new JintCommon())
.Evaluate("JintCommon.sum(1, null)")
.AsNumber();
Expand Down Expand Up @@ -3094,7 +3094,7 @@ public void CanUseClrFunction()
engine.SetValue("fn", new ClrFunctionInstance(engine, "fn", (_, args) => (JsValue) (args[0].AsInteger() + 1)));

var result = engine.Evaluate("fn(1)");

Assert.Equal(2, result);
}

Expand All @@ -3109,7 +3109,7 @@ public void ShouldAllowClrExceptionsThrough()
}
wrap();
";

Assert.Throws<InvalidOperationException>(() => engine.Execute(Source));
}

Expand All @@ -3124,11 +3124,11 @@ public void ShouldConvertClrExceptionsToErrors()
}
wrap();
";

var exc = Assert.Throws<JavaScriptException>(() => engine.Execute(Source));
Assert.Equal(exc.Message, "This is a C# error");
}

[Fact]
public void ShouldAllowCatchingConvertedClrExceptions()
{
Expand All @@ -3141,7 +3141,7 @@ public void ShouldAllowCatchingConvertedClrExceptions()
throw new Error('Caught: ' + e.message);
}
";

var exc = Assert.Throws<JavaScriptException>(() => engine.Execute(Source));
Assert.Equal(exc.Message, "Caught: This is a C# error");
}
Expand Down Expand Up @@ -3208,5 +3208,21 @@ public void ShouldCallEnumeratorDisposeOnException()
engine.Execute(Source);
Assert.Equal(1, baz.DisposeCalls);
}

public class PropertyTestClass
{
public object Value;
}

[Fact]
public void PropertiesOfJsObjectPassedToClrShouldBeReadable()
{
_engine.SetValue("MyClass", typeof(PropertyTestClass));
RunTest(@"
var obj = new MyClass();
obj.Value = { foo: 'bar' };
equal('bar', obj.Value.foo);
");
}
}
}
6 changes: 3 additions & 3 deletions Jint/Native/Object/ObjectConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ private static JsValue IsSealed(JsValue thisObject, JsValue[] arguments)
{
if (arguments.At(0) is not ObjectInstance o)
{
return arguments.At(0);
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could return JsBoolen.True and JsBoolean.False

}

return TestIntegrityLevel(o, IntegrityLevel.Sealed);
Expand All @@ -509,7 +509,7 @@ private static JsValue IsFrozen(JsValue thisObject, JsValue[] arguments)
{
if (arguments.At(0) is not ObjectInstance o)
{
return arguments.At(0);
return true;
}

return TestIntegrityLevel(o, IntegrityLevel.Frozen);
Expand Down Expand Up @@ -555,7 +555,7 @@ private static JsValue IsExtensible(JsValue thisObject, JsValue[] arguments)
{
if (arguments.At(0) is not ObjectInstance o)
{
return arguments.At(0);
return false;
}

return o.Extensible;
Expand Down