Skip to content

Commit 619b9cd

Browse files
committed
Placed in AngleSharp.Extensions namespace
1 parent 9db90c4 commit 619b9cd

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

src/AngleSharp.Scripting.JavaScript.Tests/InteractionTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace AngleSharp.Scripting.JavaScript.Tests
22
{
33
using AngleSharp.Scripting.JavaScript.Services;
4+
using AngleSharp.Extensions;
45
using Jint.Runtime;
56
using NUnit.Framework;
67
using System;
@@ -79,6 +80,16 @@ public async Task RunScriptSnippetDirectlyGetComplexObjectFromProperty()
7980
Assert.AreEqual(document.DefaultView, result);
8081
}
8182

83+
[Test]
84+
public async Task RunScriptSnippetDirectlyGetsWindow()
85+
{
86+
var html = "<!doctype html><span id=test>Test</span>";
87+
var config = Configuration.Default.WithJavaScript();
88+
var document = await BrowsingContext.New(config).OpenAsync(m => m.Content(html));
89+
var result = document.ExecuteScript("window");
90+
Assert.AreEqual(document.DefaultView, result);
91+
}
92+
8293
[Test]
8394
public async Task RunScriptSnippetDirectlyGetComplexObjectFromQuerySelector()
8495
{

src/AngleSharp.Scripting.JavaScript/AngleSharp.Scripting.JavaScript.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<Reference Include="System.Xml" />
5151
</ItemGroup>
5252
<ItemGroup>
53-
<Compile Include="ApiExtensions.cs" />
53+
<Compile Include="JsApiExtensions.cs" />
5454
<Compile Include="Attributes\DomInstanceAttribute.cs" />
5555
<Compile Include="JsConfigurationExtensions.cs" />
5656
<Compile Include="ConsoleInstance.cs" />

src/AngleSharp.Scripting.JavaScript/EngineInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public DomNodeInstance GetDomNode(Object obj)
101101
return domNodeInstance;
102102
}
103103

104-
public Object RunScript(String source, JsValue context)
104+
public JsValue RunScript(String source, JsValue context)
105105
{
106106
_engine.EnterExecutionContext(Lexicals, Variables, context);
107107
_engine.Execute(source);
108108
_engine.LeaveExecutionContext();
109-
return _engine.GetCompletionValue().FromJsValue();
109+
return _engine.GetCompletionValue();
110110
}
111111

112112
#endregion

src/AngleSharp.Scripting.JavaScript/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ public static void AddInstance(this EngineInstance engine, ObjectInstance obj, T
261261
}
262262
}
263263

264-
public static Object RunScript(this EngineInstance engine, String source)
264+
public static JsValue RunScript(this EngineInstance engine, String source)
265265
{
266266
return engine.RunScript(source, engine.Window);
267267
}
268268

269-
public static Object RunScript(this EngineInstance engine, String source, INode context)
269+
public static JsValue RunScript(this EngineInstance engine, String source, INode context)
270270
{
271271
return engine.RunScript(source, context.ToJsValue(engine));
272272
}

src/AngleSharp.Scripting.JavaScript/JavaScriptEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public Object EvaluateScript(IDocument document, String source)
9595
if (document == null)
9696
throw new ArgumentNullException(nameof(document));
9797

98-
return GetOrCreateInstance(document).RunScript(source);
98+
return GetOrCreateInstance(document).RunScript(source).FromJsValue();
9999
}
100100

101101
#endregion

src/AngleSharp.Scripting.JavaScript/ApiExtensions.cs renamed to src/AngleSharp.Scripting.JavaScript/JsApiExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Scripting.JavaScript
1+
namespace AngleSharp.Extensions
22
{
33
using AngleSharp.Dom;
44
using AngleSharp.Scripting.JavaScript.Services;
@@ -8,7 +8,7 @@
88
/// <summary>
99
/// Useful extensions for the DOM.
1010
/// </summary>
11-
public static class ApiExtensions
11+
public static class JsApiExtensions
1212
{
1313
/// <summary>
1414
/// Executes the given script code in the context of the document.

0 commit comments

Comments
 (0)