|
72 | 72 | import com.oracle.truffle.api.strings.TruffleString; |
73 | 73 | import com.oracle.truffle.api.strings.TruffleString.CodeRange; |
74 | 74 | import com.oracle.truffle.api.strings.TruffleStringBuilder; |
75 | | -import com.oracle.truffle.api.strings.TruffleStringIterator; |
76 | 75 | import com.oracle.truffle.js.builtins.RegExpPrototypeBuiltins.JSRegExpExecES5Node; |
77 | 76 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.CreateHTMLNodeGen; |
78 | 77 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.CreateStringIteratorNodeGen; |
@@ -3013,39 +3012,15 @@ public JSStringToWellFormedNode(JSContext context, JSBuiltin builtin) { |
3013 | 3012 |
|
3014 | 3013 | @Specialization |
3015 | 3014 | protected static TruffleString doString(TruffleString thisStr, |
3016 | | - @Shared @Cached TruffleString.IsValidNode isValidNode, |
3017 | | - @Shared @Cached TruffleString.CreateCodePointIteratorNode codePointIteratorNode, |
3018 | | - @Shared @Cached TruffleStringIterator.NextNode nextNode, |
3019 | | - @Shared @Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode, |
3020 | | - @Shared @Cached TruffleStringBuilder.ToStringNode toStringNode) { |
3021 | | - if (isValidNode.execute(thisStr, TruffleString.Encoding.UTF_16)) { |
3022 | | - return thisStr; |
3023 | | - } else { |
3024 | | - TruffleStringIterator it = codePointIteratorNode.execute(thisStr, TruffleString.Encoding.UTF_16); |
3025 | | - TruffleStringBuilder sb = Strings.builderCreate(Strings.length(thisStr)); |
3026 | | - while (it.hasNext()) { |
3027 | | - int cp = nextNode.execute(it); |
3028 | | - if (cp >= Character.MIN_SURROGATE && cp <= Character.MAX_SURROGATE) { |
3029 | | - appendCodePointNode.execute(sb, 0xfffd); |
3030 | | - } else { |
3031 | | - appendCodePointNode.execute(sb, cp); |
3032 | | - } |
3033 | | - } |
3034 | | - TruffleString result = toStringNode.execute(sb); |
3035 | | - assert result.isValidUncached(TruffleString.Encoding.UTF_16) : result; |
3036 | | - return result; |
3037 | | - } |
| 3015 | + @Shared @Cached TruffleString.ToValidStringNode toValidNode) { |
| 3016 | + return toValidNode.execute(thisStr, TruffleString.Encoding.UTF_16); |
3038 | 3017 | } |
3039 | 3018 |
|
3040 | 3019 | @Specialization(guards = "!isString(thisObj)") |
3041 | 3020 | protected final TruffleString doOther(Object thisObj, |
3042 | | - @Shared @Cached TruffleString.IsValidNode isValidNode, |
3043 | | - @Shared @Cached TruffleString.CreateCodePointIteratorNode codePointIteratorNode, |
3044 | | - @Shared @Cached TruffleStringIterator.NextNode nextNode, |
3045 | | - @Shared @Cached TruffleStringBuilder.AppendCodePointNode appendCodePointNode, |
3046 | | - @Shared @Cached TruffleStringBuilder.ToStringNode toStringNode) { |
| 3021 | + @Shared @Cached TruffleString.ToValidStringNode toValidNode) { |
3047 | 3022 | requireObjectCoercible(thisObj); |
3048 | | - return doString(toString(thisObj), isValidNode, codePointIteratorNode, nextNode, appendCodePointNode, toStringNode); |
| 3023 | + return doString(toString(thisObj), toValidNode); |
3049 | 3024 | } |
3050 | 3025 | } |
3051 | 3026 |
|
|
0 commit comments