2.4.3.2 Object.defineProperty ( O, P, Attributes )

This function is not defined for JScript 5.7. It exists only in JScript 5.8.

When the defineProperty function is called, the following steps are taken:

1. If the Type(O) is not Object, raise a TypeError exception.

2. If the O is not a host object that supports property creation using this function, raise a TypeError exception.

3. Let name be ToString(P).

4. Let attrs be ToObject(Attributes).

5. Let enumerable be undefined.

6. If the result of calling the [[HasProperty]] internal method of O with argument "enumerable" is false, go to step 9.

7. Let val be the result of calling the [[Get]] internal method of O with "enumerable".

8. Let enumerable be ToBoolean(val).

9. Let configurable be undefined.

10. If the result of calling the [[HasProperty]] internal method of O with argument "configurable" is false, go to step 13.

11. Let val be the result of calling the [[Get]] internal method of O with "configurable".

12. Let configurable be ToBoolean(val).

13. Let valuePresent be false.

14. If the result of calling the [[HasProperty]] internal method of O with argument "value" is false, go to step 17.

15. Let value be the result of calling the [[Get]] internal method of O with "value".

16. Let valuePresent be true.

17. Let writable be undefined.

18. If the result of calling the [[HasProperty]] internal method of O with argument "writable" is false, go to step 21.

19. Let val be the result of calling the [[Get]] internal method of O with "writable".

20. Let writable be ToBoolean(val).

21. Let getPresent be false.

22. If the result of calling the [[HasProperty]] internal method of O with argument "get" is false, go to step 27.

23. Let getter be the result of calling the [[Get]] internal method of O with "get".

24. Let getPresent be true.

25. If getter is undefined, go to step 27.

26. If getter is not a function, raise a TypeError exception.

27. Let setPresent be false.

28. If the result of calling the [[HasProperty]] internal method of O with argument "set" is false, go to step 33.

29. Let setter be the result of calling the [[Get]] internal method of O with "set".

30. Let setPresent be true.

31. If setter is undefined, go to step 33.

32. If setter is not a function, raise a TypeError exception.

33. If getPresent is false, let setter be undefined.

34. If setPresent is false, let setter be undefined.

35. If O does not have an own property named name, go to step 50.

36. If either getPresent or setPresent is true, go to step 44.

37. If valuePresent is false, return O.

38. If the own property named name of O is an accessor property, go to step 42.

39. If writable is false, raise a TypeError exception.

40. If configurable is false, raise a TypeError exception.

41. If enumerable is false, raise a TypeError exception.

42. Create a data property of O named name that has a value of value and with no attributes.

43. Return O.

44. If configurable is false, raise a TypeError exception.

45. If enumerable is true, raise a TypeError exception.

46. If writable is not undefined, raise a TypeError exception.

47. If valuePresent is true, raise a TypeError exception.

48. Create an accessor property of O named name that has a set function of setter, a get function of getter, and that has the DontEnum attribute.

49. Return O.

50. If the own property named name of O is an accessor property, go to step 65.

51. If either getPresent or setPresent is true, go to step 59.

52. If valuePresent is false, return O.

53. Call the [[Put]] method of desc, passing "value" and value as arguments.

54. If configurable is false, raise a TypeError exception.

55. If writable is false, raise a TypeError exception.

56. If enumerable is false, raise a TypeError exception.

57. Set the value of the data property of O named name to value.

58. Return O.

59. If configurable is false, raise a TypeError exception.

60. If enumerable is true, raise a TypeError exception.

61. If writable is not undefined, raise a TypeError exception.

62. If valuePresent is true, raise a TypeError exception.

63. Convert the own property of O named name into an accessor property that has a set function of setter, a get function of getter, and that has the DontEnum attribute.

64. Return O.

65. If valuePresent is true, go to step 73.

66. If neither getPresent nor setPresent is true, return O.

67. If configurable is false, raise a TypeError exception.

68. If enumerable is true, raise a TypeError exception.

69. If writable is not undefined, raise a TypeError exception.

70. If setPresent is true, set the set function of the accessor property of O named name to setter.

71. If getPresent is true, set the get function of the accessor property of O named name to getter.

72. Return O.

73. If either getPresent or setPresent is true, go to step 79.

74. If configurable is false, raise a TypeError exception.

75. If writable is false, raise a TypeError exception.

76. If enumerable is false, raise a TypeError exception.

77. Call the [[Put]] method of O passing name and value as arguments.

78. Return O.

79. If configurable is false, raise a TypeError exception.

80. If enumerable is true, raise a TypeError exception.

81. If writable is not undefined, raise a TypeError exception.

82. Raise a TypeError exception.