MCPcopy Create free account
hub / github.com/dop251/goja / functionproto_bind

Method functionproto_bind

builtin_function.go:156–208  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

154}
155
156func (r *Runtime) functionproto_bind(call FunctionCall) Value {
157 obj := r.toObject(call.This)
158
159 fcall := r.toCallable(call.This)
160 construct := obj.self.assertConstructor()
161
162 var l = _positiveZero
163 if obj.self.hasOwnPropertyStr("length") {
164 var li int64
165 switch lenProp := nilSafe(obj.self.getStr("length", nil)).(type) {
166 case valueInt:
167 li = lenProp.ToInteger()
168 case valueFloat:
169 switch lenProp {
170 case _positiveInf:
171 l = lenProp
172 goto lenNotInt
173 case _negativeInf:
174 goto lenNotInt
175 case _negativeZero:
176 // no-op, li == 0
177 default:
178 if !math.IsNaN(float64(lenProp)) {
179 li = int64(math.Abs(float64(lenProp)))
180 } // else li = 0
181 }
182 }
183 if len(call.Arguments) > 1 {
184 li -= int64(len(call.Arguments)) - 1
185 }
186 if li < 0 {
187 li = 0
188 }
189 l = intToValue(li)
190 }
191lenNotInt:
192 name := obj.self.getStr("name", nil)
193 nameStr := stringBound_
194 if s, ok := name.(String); ok {
195 nameStr = nameStr.Concat(s)
196 }
197
198 v := &Object{runtime: r}
199 ff := r.newNativeFuncAndConstruct(v, r.boundCallable(fcall, call.Arguments), r.boundConstruct(v, construct, call.Arguments), nil, nameStr.string(), l)
200 bf := &boundFuncObject{
201 nativeFuncObject: *ff,
202 wrapped: obj,
203 }
204 bf.prototype = obj.self.proto()
205 v.self = bf
206
207 return v
208}
209
210func (r *Runtime) getThrower() *Object {
211 ret := r.global.thrower

Callers

nothing calls this directly

Calls 14

toObjectMethod · 0.95
toCallableMethod · 0.95
boundCallableMethod · 0.95
boundConstructMethod · 0.95
nilSafeFunction · 0.85
intToValueFunction · 0.85
assertConstructorMethod · 0.65
hasOwnPropertyStrMethod · 0.65
getStrMethod · 0.65
ToIntegerMethod · 0.65
ConcatMethod · 0.65

Tested by

no test coverage detected