-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from tomvanenckevort/image-constructor-support
Added Image constructor support
- Loading branch information
Showing
8 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/AngleSharp.Js/Attributes/DomConstructorFunctionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace AngleSharp.Js.Attributes | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// This attribute is used to mark a method to be uses as a | ||
/// constructor function from scripts. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public sealed class DomConstructorFunctionAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Creates a new DomConstructorFunctionAttribute. | ||
/// </summary> | ||
/// <param name="officialName"> | ||
/// The official name of the decorated method. | ||
/// </param> | ||
public DomConstructorFunctionAttribute(String officialName) | ||
{ | ||
OfficialName = officialName; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the official name of the given class. | ||
/// </summary> | ||
public String OfficialName { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/AngleSharp.Js/Proxies/DomConstructorFunctionInstance.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace AngleSharp.Js.Proxies | ||
{ | ||
using Jint.Native; | ||
using Jint.Native.Object; | ||
using Jint.Runtime; | ||
using System.Reflection; | ||
|
||
sealed class DomConstructorFunctionInstance : Constructor | ||
{ | ||
private readonly EngineInstance _instance; | ||
private readonly MethodInfo _constructorFunction; | ||
|
||
public DomConstructorFunctionInstance(EngineInstance instance, MethodInfo constructorFunction, string name) : base(instance.Jint, name) | ||
{ | ||
_instance = instance; | ||
_constructorFunction = constructorFunction; | ||
} | ||
|
||
public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) | ||
{ | ||
try | ||
{ | ||
return _instance.Call(_constructorFunction, _instance.Window, arguments) as ObjectInstance; | ||
} | ||
catch | ||
{ | ||
throw new JavaScriptException(_instance.Jint.Intrinsics.Error); | ||
} | ||
} | ||
} | ||
} |