forked from dop251/goja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_args.go
150 lines (126 loc) · 3.25 KB
/
object_args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package goja
type argumentsObject struct {
baseObject
length int
}
type mappedProperty struct {
valueProperty
v *Value
}
func (a *argumentsObject) getPropStr(name string) Value {
if prop, ok := a.values[name].(*mappedProperty); ok {
return *prop.v
}
return a.baseObject.getPropStr(name)
}
func (a *argumentsObject) getProp(n Value) Value {
return a.getPropStr(n.String())
}
func (a *argumentsObject) init() {
a.baseObject.init()
a._putProp("length", intToValue(int64(a.length)), true, false, true)
}
func (a *argumentsObject) put(n Value, val Value, throw bool) {
a.putStr(n.String(), val, throw)
}
func (a *argumentsObject) putStr(name string, val Value, throw bool) {
if prop, ok := a.values[name].(*mappedProperty); ok {
if !prop.writable {
a.val.runtime.typeErrorResult(throw, "Property is not writable: %s", name)
return
}
*prop.v = val
return
}
a.baseObject.putStr(name, val, throw)
}
func (a *argumentsObject) deleteStr(name string, throw bool) bool {
if prop, ok := a.values[name].(*mappedProperty); ok {
if !a.checkDeleteProp(name, &prop.valueProperty, throw) {
return false
}
a._delete(name)
return true
}
return a.baseObject.deleteStr(name, throw)
}
func (a *argumentsObject) delete(n Value, throw bool) bool {
return a.deleteStr(n.String(), throw)
}
type argumentsPropIter1 struct {
a *argumentsObject
idx int
recursive bool
}
type argumentsPropIter struct {
wrapped iterNextFunc
}
func (i *argumentsPropIter) next() (propIterItem, iterNextFunc) {
var item propIterItem
item, i.wrapped = i.wrapped()
if i.wrapped == nil {
return propIterItem{}, nil
}
if prop, ok := item.value.(*mappedProperty); ok {
item.value = *prop.v
}
return item, i.next
}
func (a *argumentsObject) _enumerate(recursive bool) iterNextFunc {
return (&argumentsPropIter{
wrapped: a.baseObject._enumerate(recursive),
}).next
}
func (a *argumentsObject) enumerate(all, recursive bool) iterNextFunc {
return (&argumentsPropIter{
wrapped: a.baseObject.enumerate(all, recursive),
}).next
}
func (a *argumentsObject) defineOwnProperty(n Value, descr propertyDescr, throw bool) bool {
name := n.String()
if mapped, ok := a.values[name].(*mappedProperty); ok {
existing := &valueProperty{
configurable: mapped.configurable,
writable: true,
enumerable: mapped.enumerable,
value: mapped.get(a.val),
}
val, ok := a.baseObject._defineOwnProperty(n, existing, descr, throw)
if !ok {
return false
}
if prop, ok := val.(*valueProperty); ok {
if !prop.accessor {
*mapped.v = prop.value
}
if prop.accessor || !prop.writable {
a._put(name, prop)
return true
}
mapped.configurable = prop.configurable
mapped.enumerable = prop.enumerable
} else {
*mapped.v = val
mapped.configurable = true
mapped.enumerable = true
}
return true
}
return a.baseObject.defineOwnProperty(n, descr, throw)
}
func (a *argumentsObject) getOwnProp(name string) Value {
if mapped, ok := a.values[name].(*mappedProperty); ok {
return *mapped.v
}
return a.baseObject.getOwnProp(name)
}
func (a *argumentsObject) export() interface{} {
arr := make([]interface{}, a.length)
for i, _ := range arr {
v := a.get(intToValue(int64(i)))
if v != nil {
arr[i] = v.Export()
}
}
return arr
}