(call FunctionCall)
| 813 | } |
| 814 | |
| 815 | func (r *Runtime) stringproto_split(call FunctionCall) Value { |
| 816 | r.checkObjectCoercible(call.This) |
| 817 | separatorValue := call.Argument(0) |
| 818 | limitValue := call.Argument(1) |
| 819 | if _, ok := separatorValue.(*Object); ok { |
| 820 | if splitter := toMethod(r.getV(separatorValue, SymSplit)); splitter != nil { |
| 821 | return splitter(FunctionCall{ |
| 822 | This: separatorValue, |
| 823 | Arguments: []Value{call.This, limitValue}, |
| 824 | }) |
| 825 | } |
| 826 | } |
| 827 | s := call.This.toString() |
| 828 | |
| 829 | limit := -1 |
| 830 | if limitValue != _undefined { |
| 831 | limit = int(toUint32(limitValue)) |
| 832 | } |
| 833 | |
| 834 | separatorValue = separatorValue.ToString() |
| 835 | |
| 836 | if limit == 0 { |
| 837 | return r.newArrayValues(nil) |
| 838 | } |
| 839 | |
| 840 | if separatorValue == _undefined { |
| 841 | return r.newArrayValues([]Value{s}) |
| 842 | } |
| 843 | |
| 844 | separator := separatorValue.String() |
| 845 | |
| 846 | str := s.String() |
| 847 | splitLimit := limit |
| 848 | if limit > 0 { |
| 849 | splitLimit = limit + 1 |
| 850 | } |
| 851 | |
| 852 | // TODO handle invalid UTF-16 |
| 853 | split := strings.SplitN(str, separator, splitLimit) |
| 854 | |
| 855 | if limit > 0 && len(split) > limit { |
| 856 | split = split[:limit] |
| 857 | } |
| 858 | |
| 859 | valueArray := make([]Value, len(split)) |
| 860 | for index, value := range split { |
| 861 | valueArray[index] = newStringValue(value) |
| 862 | } |
| 863 | |
| 864 | return r.newArrayValues(valueArray) |
| 865 | } |
| 866 | |
| 867 | func (r *Runtime) stringproto_startsWith(call FunctionCall) Value { |
| 868 | r.checkObjectCoercible(call.This) |
nothing calls this directly
no test coverage detected