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

Method arrayproto_includes

builtin_array.go:632–671  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

630}
631
632func (r *Runtime) arrayproto_includes(call FunctionCall) Value {
633 o := call.This.ToObject(r)
634 length := toLength(o.self.getStr("length", nil))
635 if length == 0 {
636 return valueFalse
637 }
638
639 n := call.Argument(1).ToInteger()
640 if n >= length {
641 return valueFalse
642 }
643
644 if n < 0 {
645 n = max(length+n, 0)
646 }
647
648 searchElement := call.Argument(0)
649 if searchElement == _negativeZero {
650 searchElement = _positiveZero
651 }
652
653 if arr := r.checkStdArrayObj(o); arr != nil {
654 for _, val := range arr.values[n:] {
655 if searchElement.SameAs(val) {
656 return valueTrue
657 }
658 }
659 return valueFalse
660 }
661
662 for ; n < length; n++ {
663 idx := valueInt(n)
664 val := nilSafe(o.self.getIdx(idx, nil))
665 if searchElement.SameAs(val) {
666 return valueTrue
667 }
668 }
669
670 return valueFalse
671}
672
673func (r *Runtime) arrayproto_lastIndexOf(call FunctionCall) Value {
674 o := call.This.ToObject(r)

Callers

nothing calls this directly

Calls 10

checkStdArrayObjMethod · 0.95
toLengthFunction · 0.85
valueIntTypeAlias · 0.85
nilSafeFunction · 0.85
ToObjectMethod · 0.65
getStrMethod · 0.65
ToIntegerMethod · 0.65
SameAsMethod · 0.65
getIdxMethod · 0.65
ArgumentMethod · 0.45

Tested by

no test coverage detected