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

Method arrayproto_unshift

builtin_array.go:532–572  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

530}
531
532func (r *Runtime) arrayproto_unshift(call FunctionCall) Value {
533 o := call.This.ToObject(r)
534 length := toLength(o.self.getStr("length", nil))
535 argCount := int64(len(call.Arguments))
536 newLen := intToValue(length + argCount)
537 if argCount > 0 {
538 newSize := length + argCount
539 if newSize >= maxInt {
540 panic(r.NewTypeError("Invalid array length"))
541 }
542 if arr := r.checkStdArrayObjWithProto(o); arr != nil && newSize < math.MaxUint32 {
543 if int64(cap(arr.values)) >= newSize {
544 arr.values = arr.values[:newSize]
545 copy(arr.values[argCount:], arr.values[:length])
546 } else {
547 values := make([]Value, newSize)
548 copy(values[argCount:], arr.values)
549 arr.values = values
550 }
551 copy(arr.values, call.Arguments)
552 arr.objCount = int(arr.length)
553 } else {
554 for k := length - 1; k >= 0; k-- {
555 from := valueInt(k)
556 to := valueInt(k + argCount)
557 if o.self.hasPropertyIdx(from) {
558 o.self.setOwnIdx(to, nilSafe(o.self.getIdx(from, nil)), true)
559 } else {
560 o.self.deleteIdx(to, true)
561 }
562 }
563
564 for k, arg := range call.Arguments {
565 o.self.setOwnIdx(valueInt(int64(k)), arg, true)
566 }
567 }
568 }
569
570 o.self.setOwnStr("length", newLen, true)
571 return newLen
572}
573
574func (r *Runtime) arrayproto_at(call FunctionCall) Value {
575 o := call.This.ToObject(r)

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected