ErrorConstructor.cs 1.8 KB

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