ErrorConstructor.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Jint.Native.Function;
  2. using Jint.Native.Object;
  3. using Jint.Runtime;
  4. namespace Jint.Native.Error
  5. {
  6. public sealed 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
  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 Date.prototype is the Boolean prototype object
  20. obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
  21. return obj;
  22. }
  23. public override object Call(object thisObject, object[] arguments)
  24. {
  25. return Construct(arguments);
  26. }
  27. public ObjectInstance Construct(object[] arguments)
  28. {
  29. var instance = new ErrorInstance(Engine, null);
  30. instance.Prototype = PrototypeObject;
  31. instance.Extensible = true;
  32. if (arguments.Length > 0 && arguments[0] != Undefined.Instance)
  33. {
  34. instance.Message = TypeConverter.ToString(arguments[0]);
  35. }
  36. return instance;
  37. }
  38. public ObjectInstance PrototypeObject { get; private set; }
  39. }
  40. }