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

Method stringproto_replace

builtin_string.go:682–705  ·  view source on GitHub ↗
(call FunctionCall)

Source from the content-addressed store, hash-verified

680}
681
682func (r *Runtime) stringproto_replace(call FunctionCall) Value {
683 r.checkObjectCoercible(call.This)
684 searchValue := call.Argument(0)
685 replaceValue := call.Argument(1)
686 if _, ok := searchValue.(*Object); ok {
687 if replacer := toMethod(r.getV(searchValue, SymReplace)); replacer != nil {
688 return replacer(FunctionCall{
689 This: searchValue,
690 Arguments: []Value{call.This, replaceValue},
691 })
692 }
693 }
694
695 s := call.This.toString()
696 var found []regexpResult
697 searchStr := searchValue.toString()
698 pos := s.index(searchStr, 0)
699 if pos != -1 {
700 found = append(found, regexpResult{indexes: []int{pos, pos + searchStr.Length()}})
701 }
702
703 str, rcall := getReplaceValue(replaceValue)
704 return r.stringReplace(s, found, str, rcall)
705}
706
707func (r *Runtime) stringproto_replaceAll(call FunctionCall) Value {
708 r.checkObjectCoercible(call.This)

Callers

nothing calls this directly

Calls 9

checkObjectCoercibleMethod · 0.95
getVMethod · 0.95
stringReplaceMethod · 0.95
toMethodFunction · 0.85
getReplaceValueFunction · 0.85
toStringMethod · 0.65
indexMethod · 0.65
LengthMethod · 0.65
ArgumentMethod · 0.45

Tested by

no test coverage detected