BooleanPrototype.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using Jint.Native.Object;
  3. using Jint.Runtime;
  4. using Jint.Runtime.Interop;
  5. namespace Jint.Native.Boolean
  6. {
  7. /// <summary>
  8. /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.6.4
  9. /// </summary>
  10. public sealed class BooleanPrototype : BooleanInstance
  11. {
  12. private BooleanPrototype(Engine engine) : base(engine)
  13. {
  14. }
  15. public static BooleanPrototype CreatePrototypeObject(Engine engine, BooleanConstructor booleanConstructor)
  16. {
  17. var obj = new BooleanPrototype(engine);
  18. obj.Prototype = engine.Object.PrototypeObject;
  19. obj.PrimitiveValue = false;
  20. obj.Extensible = true;
  21. obj.FastAddProperty("constructor", booleanConstructor, false, false, false);
  22. return obj;
  23. }
  24. public void Configure()
  25. {
  26. FastAddProperty("toString", new ClrFunctionInstance<object, bool>(Engine, ToBooleanString), true, false, true);
  27. FastAddProperty("valueOf", new ClrFunctionInstance<object, object>(Engine, ValueOf), true, false, true);
  28. }
  29. private object ValueOf(object thisObj, object[] arguments)
  30. {
  31. var B = thisObj;
  32. object b;
  33. if (TypeConverter.GetType(B) == TypeCode.Boolean)
  34. {
  35. b = B;
  36. }
  37. else
  38. {
  39. var o = B as BooleanInstance;
  40. if (o != null)
  41. {
  42. return o.PrimitiveValue;
  43. }
  44. else
  45. {
  46. throw new JavaScriptException(Engine.TypeError);
  47. }
  48. }
  49. return b;
  50. }
  51. private bool ToBooleanString(object thisObj, object[] arguments)
  52. {
  53. throw new NotImplementedException();
  54. }
  55. }
  56. }