(call FunctionCall)
| 705 | } |
| 706 | |
| 707 | func (r *Runtime) stringproto_replaceAll(call FunctionCall) Value { |
| 708 | r.checkObjectCoercible(call.This) |
| 709 | searchValue := call.Argument(0) |
| 710 | replaceValue := call.Argument(1) |
| 711 | if o, ok := searchValue.(*Object); ok { |
| 712 | if isRegexp(searchValue) { |
| 713 | flags := nilSafe(o.self.getStr("flags", nil)) |
| 714 | r.checkObjectCoercible(flags) |
| 715 | if !strings.Contains(flags.toString().String(), "g") { |
| 716 | panic(r.NewTypeError("String.prototype.replaceAll called with a non-global RegExp argument")) |
| 717 | } |
| 718 | } |
| 719 | if replacer := toMethod(r.getV(searchValue, SymReplace)); replacer != nil { |
| 720 | return replacer(FunctionCall{ |
| 721 | This: searchValue, |
| 722 | Arguments: []Value{call.This, replaceValue}, |
| 723 | }) |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | s := call.This.toString() |
| 728 | var found []regexpResult |
| 729 | searchStr := searchValue.toString() |
| 730 | searchLength := searchStr.Length() |
| 731 | advanceBy := toIntStrict(max(1, int64(searchLength))) |
| 732 | |
| 733 | pos := s.index(searchStr, 0) |
| 734 | for pos != -1 { |
| 735 | found = append(found, regexpResult{indexes: []int{pos, pos + searchLength}}) |
| 736 | pos = s.index(searchStr, pos+advanceBy) |
| 737 | } |
| 738 | |
| 739 | str, rcall := getReplaceValue(replaceValue) |
| 740 | return r.stringReplace(s, found, str, rcall) |
| 741 | } |
| 742 | |
| 743 | func (r *Runtime) stringproto_search(call FunctionCall) Value { |
| 744 | r.checkObjectCoercible(call.This) |
nothing calls this directly
no test coverage detected