Skip to content

Commit eb43a36

Browse files
committed
Take care of exceptions when accessing out-of-range elements
1 parent e795421 commit eb43a36

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

AngleSharp.Scripting.JavaScript/DomNodeInstance.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ public override PropertyDescriptor GetOwnProperty(String propertyName)
4141
if (_numericIndexer != null && Int32.TryParse(propertyName, out numericIndex))
4242
{
4343
var args = new Object[] { numericIndex };
44-
var orig = _numericIndexer.GetMethod.Invoke(_value, args);
45-
var prop = orig != null ? orig.ToJsValue(_engine) : JsValue.Undefined;
46-
return new PropertyDescriptor(prop, false, false, false);
44+
45+
try
46+
{
47+
var orig = _numericIndexer.GetMethod.Invoke(_value, args);
48+
return new PropertyDescriptor(orig.ToJsValue(_engine), false, false, false);
49+
}
50+
catch
51+
{
52+
return new PropertyDescriptor(JsValue.Undefined, false, false, false);
53+
}
4754
}
4855

4956
// Else a string property

AngleSharp.Scripting.JavaScript/EngineInstance.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88

99
sealed class EngineInstance
1010
{
11+
#region Fields
12+
1113
readonly Dictionary<Object, DomNodeInstance> _objects;
1214
readonly Engine _engine;
1315
readonly LexicalEnvironment _lexicals;
1416
readonly LexicalEnvironment _variables;
1517
readonly DomNodeInstance _window;
1618
readonly DomConstructors _constructors;
1719

20+
#endregion
21+
22+
#region ctor
23+
1824
public EngineInstance(IWindow window, IDictionary<String, Object> assignments)
1925
{
2026
_objects = new Dictionary<Object, DomNodeInstance>();
@@ -37,6 +43,10 @@ public EngineInstance(IWindow window, IDictionary<String, Object> assignments)
3743
this.AddInstances(_window, this.GetType());
3844
}
3945

46+
#endregion
47+
48+
#region Properties
49+
4050
public DomNodeInstance Window
4151
{
4252
get { return _window; }
@@ -62,6 +72,10 @@ public Engine Jint
6272
get { return _engine; }
6373
}
6474

75+
#endregion
76+
77+
#region Methods
78+
6579
public DomNodeInstance GetDomNode(Object obj)
6680
{
6781
var domNodeInstance = default(DomNodeInstance);
@@ -80,5 +94,7 @@ public void RunScript(String source)
8094
_engine.Execute(source);
8195
_engine.LeaveExecutionContext();
8296
}
97+
98+
#endregion
8399
}
84100
}

0 commit comments

Comments
 (0)