Description
Prerequisites
- Can you reproduce the problem in a MWE?
- Are you running the latest version of AngleSharp?
- Did you check the FAQs to see if that helps you?
- Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g.,
AngleSharp.Css
for CSS support) - Did you perform a search in the issues?
Description
Being a getter only property is not a problem in AngleSharp itself, but when it is exposed to JS DOM, via DomNameAttribute, then it doesn't conform to the spec.
I decided to report here and not in AngleSharp.JS, as the code in current repo requires fix.
Tested on master versions of AngleSharp, AngleSharp.Js and Jint
Steps to Reproduce
var config = Configuration.Default.WithJs();
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(req => req.Content("")).ConfigureAwait(false);
Console.WriteLine(document.ExecuteScript("document.createElement('div').hasChildNodes()"));
Expected Behavior
Console should output: False
Actual Behavior
Exception is thrown:
Jint.Runtime.JavaScriptException: 'Property 'hasChildNodes' of object is not a function'
Possible Solution / Known Workarounds
Workaround: using document.createElement('div').hasChildNodes
(without parentheses)
Proposed solutions:
-
Change HasChildNodes to method.
Pros: JS signature is the same as the one in C#
Cons: breaking change -
Introduce ExposeAsMethod property in DomNameAttribute and set it to true for that property.
Pros: no breaking change in C#; there's still breaking change in JS if anyone used mentioned workaround, but impact would be much lower
Cons: different C#/JS signatures