@@ -34,8 +34,8 @@ When the GetLastArrayItem method is called, the following steps are taken:
34
34
If len is zero, then
35
35
Return undefined.
36
36
Else len > 0,
37
- Let newLen be len-1.
38
- Let index be ! ToString(newLen ).
37
+ Set len to len-1.
38
+ Let index be ! ToString(len ).
39
39
Let element be ? Get(O, index).
40
40
Return element.
41
41
@@ -48,7 +48,7 @@ When the SetLastArrayItem method is called, the following steps are taken:
48
48
Let O be ? ToObject(this value).
49
49
Let len be ? ToLength(? Get(O, "length")).
50
50
If len > 0, then
51
- Set len to len-1
51
+ Set len to len-1.
52
52
Let index be ! ToString(len).
53
53
Return ? Set(O, index, value).
54
54
@@ -61,29 +61,30 @@ The SetLastArrayItem function is intentionally generic; it does not require that
61
61
62
62
63
63
``` js
64
+ import { ToString , ToObject , ToLength } from ' es-abstract'
64
65
// This polyfill tries to stick as close to the spec as possible. There are polyfills which could use less code.
65
66
Object .defineProperty (Array .prototype , ' end' , {
66
67
enumerable: false ,
67
68
configurable: false ,
68
69
get () {
69
- let O = Object (this )
70
- let len = Math . min ( Math . max ( 0 , Math . floor ( Math . abs ( O .length ))), Number . MAX_SAFE_INTEGER )
70
+ let O = ToObject (this )
71
+ let len = ToLength ( O .length )
71
72
if (len === 0 ) {
72
73
return undefined
73
74
} else if (len > 0 ) {
74
- let newLen = len - 1
75
- let index = String (newLen )
75
+ len = len - 1
76
+ let index = ToString (len )
76
77
let element = O [index]
77
78
return element
78
79
}
79
80
},
80
81
set (value ) {
81
- let O = Object (this )
82
- let len = Math . min ( Math . max ( 0 , Math . floor ( Math . abs ( O .length ))), Number . MAX_SAFE_INTEGER )
82
+ let O = ToObject (this )
83
+ let len = ToLength ( O .length )
83
84
if (len > 0 ) {
84
85
len = len - 1
85
86
}
86
- let index = String (newLen )
87
+ let index = ToString (len )
87
88
return O [index] = value
88
89
},
89
90
})
0 commit comments