Skip to content

Commit 088a9b3

Browse files
committed
Refactored
1 parent 9712d2e commit 088a9b3

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/AngleSharp.Scripting.JavaScript/Extensions.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ public static JsValue ToJsValue(this Object obj, EngineInstance engine)
5555
return JsValue.Null;
5656
}
5757

58-
public static Object RunScript(this EngineInstance engine, String source)
59-
{
60-
return engine.RunScript(source, engine.Window);
61-
}
62-
63-
public static Object RunScript(this EngineInstance engine, String source, INode context)
64-
{
65-
return engine.RunScript(source, context.ToJsValue(engine));
66-
}
67-
6858
public static ClrFunctionInstance AsValue(this Engine engine, Func<JsValue, JsValue[], JsValue> func)
6959
{
7060
return new ClrFunctionInstance(engine, func);
@@ -98,13 +88,7 @@ public static Object FromJsValue(this JsValue val)
9888
case Types.Object:
9989
var obj = val.AsObject();
10090
var node = obj as DomNodeInstance;
101-
102-
if (node != null)
103-
{
104-
return node.Value;
105-
}
106-
107-
return obj;
91+
return node != null ? node.Value : obj;
10892
case Types.Undefined:
10993
return "undefined";
11094
case Types.Null:
@@ -137,9 +121,7 @@ public static Object As(this Object value, Type targetType, EngineInstance engin
137121
var method = sourceType.PrepareConvert(targetType);
138122

139123
if (method == null)
140-
{
141124
throw new JavaScriptException("[Internal] Could not find corresponding cast target.");
142-
}
143125

144126
return method.Invoke(value, null);
145127
}
@@ -279,6 +261,16 @@ public static void AddInstance(this EngineInstance engine, ObjectInstance obj, T
279261
}
280262
}
281263

264+
public static Object RunScript(this EngineInstance engine, String source)
265+
{
266+
return engine.RunScript(source, engine.Window);
267+
}
268+
269+
public static Object RunScript(this EngineInstance engine, String source, INode context)
270+
{
271+
return engine.RunScript(source, context.ToJsValue(engine));
272+
}
273+
282274
public static String GetOfficialName(this MemberInfo member)
283275
{
284276
var names = member.GetCustomAttributes<DomNameAttribute>();

0 commit comments

Comments
 (0)