FunctionConstructor.cs 1.1 KB

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