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
28 changes: 28 additions & 0 deletions src/AngleSharp.Js.Tests/DomTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,33 @@ public async Task ConsoleKeepsPropertiesAssignedToIt()
var result = await "(function () { window.console.marker = 'kept'; return window.console.marker; })()".EvalScriptAsync();
Assert.AreEqual("kept", result);
}

[Test]
public async Task InheritedMemberIsNotAnOwnPropertyOfTheNode()
{
var result = await "document.createElement('div').hasOwnProperty('firstChild')".EvalScriptAsync();
Assert.AreEqual("False", result);
}

[Test]
public async Task InheritedMemberIsStillVisibleOnTheNode()
{
var result = await "('firstChild' in document.documentElement) + ',' + (typeof document.documentElement.appendChild)".EvalScriptAsync();
Assert.AreEqual("true,function", result);
}

[Test]
public async Task InheritedAccessorStillReadsAndWrites()
{
var result = await "(function () { var d = document.createElement('div'); d.id = 'jint'; return d.id; })()".EvalScriptAsync();
Assert.AreEqual("jint", result);
}

[Test]
public async Task AssignedPropertyIsReportedConsistently()
{
var result = await "(function () { var d = document.createElement('div'); d.custom = 1; return d.hasOwnProperty('custom') + ',' + Object.getOwnPropertyNames(d).join(); })()".EvalScriptAsync();
Assert.AreEqual("true,custom", result);
}
}
}
18 changes: 7 additions & 11 deletions src/AngleSharp.Js/Proxies/DomNodeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ public DomEventInstance.Registration RemoveEventHandler(DomEventInstance ev)

public override PropertyDescriptor GetOwnProperty(JsValue property)
{
if (Prototype is DomPrototypeInstance prototype)
// An indexer is the only thing that can turn into an own property of the node
// itself. The members of the DOM interface live on the prototype, so finding
// them is the engine's job - answering them here would make the node claim
// every inherited member as its own.
if (Prototype is DomPrototypeInstance prototype &&
prototype.TryGetFromIndex(_value, property.ToString(), out var descriptor))
{
if (prototype.TryGetFromIndex(_value, property.ToString(), out var descriptor))
{
return descriptor;
}

var prototypeProperty = prototype.GetOwnProperty(property);
if (prototypeProperty != PropertyDescriptor.Undefined)
{
return prototypeProperty;
}
return descriptor;
}

return base.GetOwnProperty(property);
Expand Down
Loading