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

Method arrayproto_slice

builtin_array.go:338–375  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

336}
337
338func (r *Runtime) arrayproto_slice(call FunctionCall) Value {
339 o := call.This.ToObject(r)
340 length := toLength(o.self.getStr("length", nil))
341 start := relToIdx(call.Argument(0).ToInteger(), length)
342 var end int64
343 if endArg := call.Argument(1); endArg != _undefined {
344 end = endArg.ToInteger()
345 } else {
346 end = length
347 }
348 end = relToIdx(end, length)
349
350 count := end - start
351 if count < 0 {
352 count = 0
353 }
354
355 a := arraySpeciesCreate(o, count)
356 if src := r.checkStdArrayObj(o); src != nil {
357 if dst := r.checkStdArrayObjWithProto(a); dst != nil {
358 values := make([]Value, count)
359 copy(values, src.values[start:])
360 setArrayValues(dst, values)
361 return a
362 }
363 }
364
365 n := int64(0)
366 for start < end {
367 p := o.self.getIdx(valueInt(start), nil)
368 if p != nil {
369 createDataPropertyOrThrow(a, valueInt(n), p)
370 }
371 start++
372 n++
373 }
374 return a
375}
376
377func (r *Runtime) arrayproto_sort(call FunctionCall) Value {
378 o := call.This.ToObject(r)

Callers

nothing calls this directly

Calls 13

checkStdArrayObjMethod · 0.95
toLengthFunction · 0.85
relToIdxFunction · 0.85
arraySpeciesCreateFunction · 0.85
setArrayValuesFunction · 0.85
valueIntTypeAlias · 0.85
ToObjectMethod · 0.65
getStrMethod · 0.65
ToIntegerMethod · 0.65
getIdxMethod · 0.65

Tested by

no test coverage detected