2
0

FunctionConstructor.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Jint.Native;
  4. using Jint.Native.Function;
  5. using Jint.Native.Object;
  6. using Jint.Parser.Ast;
  7. using Jint.Runtime.Descriptors;
  8. using Jint.Runtime.Environments;
  9. namespace Jint.Runtime
  10. {
  11. /// <summary>
  12. ///
  13. /// </summary>
  14. public class FunctionConstructor : FunctionInstance
  15. {
  16. private readonly IEnumerable<Identifier> _parameters;
  17. public FunctionConstructor(ObjectInstance prototype)
  18. : base(prototype, null, null)
  19. {
  20. // http://www.ecma-international.org/ecma-262/5.1/#sec-13.2
  21. Extensible = true;
  22. }
  23. public override dynamic Call(Engine engine, object thisObject, dynamic[] arguments)
  24. {
  25. return Construct(arguments);
  26. }
  27. public virtual ObjectInstance Construct(dynamic[] arguments)
  28. {
  29. var instance = new FunctionShim(Prototype, null, null);
  30. instance.DefineOwnProperty("constructor", new DataDescriptor(Prototype) { Writable = true, Enumerable = false, Configurable = false }, false);
  31. return instance;
  32. }
  33. }
  34. }