Skip to content

Commit 5d08351

Browse files
committed
Handling of new accessor: Method
1 parent e5f859a commit 5d08351

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/AngleSharp.Js/Extensions/Extensibility.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public static IDictionary<String, ExtensionEntry> GetExtensions(this IEnumerable
4949
case Accessors.Adder:
5050
entry.Adder = method;
5151
break;
52+
case Accessors.Method:
53+
entry.Other = method;
54+
break;
5255
}
5356
}
5457
else

src/AngleSharp.Js/Proxies/DomPrototypeInstance.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,32 @@ private void SetNormalProperties(IEnumerable<PropertyInfo> properties)
148148
foreach (var property in properties)
149149
{
150150
var indexParameters = property.GetIndexParameters();
151-
var index = property.GetCustomAttribute<DomAccessorAttribute>();
151+
var accessor = property.GetCustomAttribute<DomAccessorAttribute>()?.Type;
152152
var putsForward = property.GetCustomAttribute<DomPutForwardsAttribute>();
153153
var names = property
154154
.GetCustomAttributes<DomNameAttribute>()
155155
.Select(m => m.OfficialName)
156156
.ToArray();
157157

158-
if (index != null || Array.Exists(names, m => m.Is("item")))
158+
if (accessor == Accessors.Method)
159+
{
160+
// property decorated with Method accessor, so we need to treat it as a method, not a property
161+
162+
if (property.GetMethod == null)
163+
{
164+
throw new InvalidOperationException("Getter not found.");
165+
}
166+
167+
foreach (var name in names)
168+
{
169+
SetMethod(name, property.GetMethod);
170+
}
171+
172+
// methods were set, so finish processing
173+
return;
174+
}
175+
176+
if (accessor == Accessors.Getter || accessor == Accessors.Setter || Array.Exists(names, m => m.Is("item")))
159177
{
160178
SetIndexer(property, indexParameters);
161179
}

0 commit comments

Comments
 (0)