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

Method arrayproto_shift

builtin_array.go:998–1035  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

996}
997
998func (r *Runtime) arrayproto_shift(call FunctionCall) Value {
999 o := call.This.ToObject(r)
1000 if a := r.checkStdArrayObjWithProto(o); a != nil {
1001 if len(a.values) == 0 {
1002 if !a.lengthProp.writable {
1003 a.setLength(0, true) // will throw
1004 }
1005 return _undefined
1006 }
1007 first := a.values[0]
1008 copy(a.values, a.values[1:])
1009 a.values[len(a.values)-1] = nil
1010 a.values = a.values[:len(a.values)-1]
1011 a.length--
1012 return first
1013 }
1014 length := toLength(o.self.getStr("length", nil))
1015 if length == 0 {
1016 o.self.setOwnStr("length", intToValue(0), true)
1017 return _undefined
1018 }
1019 first := o.self.getIdx(valueInt(0), nil)
1020 for i := int64(1); i < length; i++ {
1021 idxFrom := valueInt(i)
1022 idxTo := valueInt(i - 1)
1023 if o.self.hasPropertyIdx(idxFrom) {
1024 o.self.setOwnIdx(idxTo, nilSafe(o.self.getIdx(idxFrom, nil)), true)
1025 } else {
1026 o.self.deleteIdx(idxTo, true)
1027 }
1028 }
1029
1030 lv := valueInt(length - 1)
1031 o.self.deleteIdx(lv, true)
1032 o.self.setOwnStr("length", lv, true)
1033
1034 return first
1035}
1036
1037func (r *Runtime) arrayproto_values(call FunctionCall) Value {
1038 return r.createArrayIterator(call.This.ToObject(r), iterationKindValue)

Callers

nothing calls this directly

Calls 13

toLengthFunction · 0.85
intToValueFunction · 0.85
valueIntTypeAlias · 0.85
nilSafeFunction · 0.85
ToObjectMethod · 0.65
getStrMethod · 0.65
setOwnStrMethod · 0.65
getIdxMethod · 0.65
hasPropertyIdxMethod · 0.65
setOwnIdxMethod · 0.65
deleteIdxMethod · 0.65

Tested by

no test coverage detected