ErrorConstructor.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Jint.Native.Function;
  2. using Jint.Native.Object;
  3. using Jint.Runtime;
  4. namespace Jint.Native.Error
  5. {
  6. public class ErrorConstructor : FunctionInstance, IConstructor
  7. {
  8. public ErrorConstructor(Engine engine) : base(engine, null, null, false)
  9. {
  10. }
  11. public static ErrorConstructor CreateErrorConstructor(Engine engine, string name)
  12. {
  13. var obj = new ErrorConstructor(engine);
  14. obj.Extensible = true;
  15. // The value of the [[Prototype]] internal property of the Error constructor is the Function prototype object (15.11.3)
  16. obj.Prototype = engine.Function.PrototypeObject;
  17. obj.PrototypeObject = ErrorPrototype.CreatePrototypeObject(engine, obj, name);
  18. obj.FastAddProperty("length", 1, false, false, false);
  19. // The initial value of Error.prototype is the Error prototype object
  20. obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
  21. return obj;
  22. }
  23. public void Configure()
  24. {
  25. }
  26. public override object Call(object thisObject, object[] arguments)
  27. {
  28. return Construct(arguments);
  29. }
  30. public ObjectInstance Construct(object[] arguments)
  31. {
  32. var instance = new ErrorInstance(Engine, null);
  33. instance.Prototype = PrototypeObject;
  34. instance.Extensible = true;
  35. if (arguments.At(0) != Undefined.Instance)
  36. {
  37. instance.Put("message", TypeConverter.ToString(arguments.At(0)), false);
  38. }
  39. return instance;
  40. }
  41. public ErrorPrototype PrototypeObject { get; private set; }
  42. }
  43. }