Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/AngleSharp.Js.Tests/OperatorsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace AngleSharp.Js.Tests
{
using NUnit.Framework;
using System.Threading.Tasks;

[TestFixture]
public class OperatorsTests
{
[Test]
public async Task InOperatorExistingAttribute()
{

var result = await "'action' in document.createElement('form')".EvalScriptAsync();
Assert.AreEqual("True", result);
}

[Test]
public async Task InOperatorNonExistingAttribute()
{

var result = await "'action' in document.createElement('div')".EvalScriptAsync();
Assert.AreEqual("False", result);
}

[Test]
public async Task InOperatorInputWithinForm()
{
var result = await "'input1' in new DOMParser().parseFromString(`<form><input name='input1'/></form>`, 'text/html').body.firstChild".EvalScriptAsync();
Assert.AreEqual("True", result);
}

[Test]
public async Task InOperatorInputWithinDiv()
{
var result = await "'input1' in new DOMParser().parseFromString(`<div><input name='input1'/></div>`, 'text/html').body.firstChild".EvalScriptAsync();
Assert.AreEqual("False", result);
}

[Test]
public async Task InOperator_Issue104()
{
var result = await "'somethingThatDoesntExist' in document.createElement('form')".EvalScriptAsync();
Assert.AreEqual("False", result);
}

}
}
10 changes: 9 additions & 1 deletion src/AngleSharp.Js/Proxies/DomPrototypeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ public Boolean TryGetFromIndex(Object value, String index, out PropertyDescripto
if (_stringIndexer != null && !HasProperty(index))
{
var args = new Object[] { index };
var prop = _stringIndexer.GetMethod.Invoke(value, args).ToJsValue(_instance);
var valueAtIndex = _stringIndexer.GetMethod.Invoke(value, args);

if (valueAtIndex == null)
{
result = PropertyDescriptor.Undefined;
return false;
}

var prop = valueAtIndex.ToJsValue(_instance);
result = new PropertyDescriptor(prop, false, false, false);
return true;
}
Expand Down
Loading