|
83 | 83 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringEndsWithNodeGen; |
84 | 84 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringIncludesNodeGen; |
85 | 85 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringIndexOfNodeGen; |
| 86 | +import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringIsWellFormedNodeGen; |
86 | 87 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringLastIndexOfNodeGen; |
87 | 88 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringLocaleCompareIntlNodeGen; |
88 | 89 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringLocaleCompareNodeGen; |
|
106 | 107 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringToLowerCaseNodeGen; |
107 | 108 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringToStringNodeGen; |
108 | 109 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringToUpperCaseNodeGen; |
| 110 | +import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringToWellFormedNodeGen; |
109 | 111 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringTrimLeftNodeGen; |
110 | 112 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringTrimNodeGen; |
111 | 113 | import com.oracle.truffle.js.builtins.StringPrototypeBuiltinsFactory.JSStringTrimRightNodeGen; |
@@ -235,7 +237,11 @@ public enum StringPrototype implements BuiltinEnum<StringPrototype> { |
235 | 237 | replaceAll(2), |
236 | 238 |
|
237 | 239 | // ES2022 |
238 | | - at(1); |
| 240 | + at(1), |
| 241 | + |
| 242 | + // ES2024 |
| 243 | + isWellFormed(0), |
| 244 | + toWellFormed(0); |
239 | 245 |
|
240 | 246 | private final int length; |
241 | 247 |
|
@@ -265,6 +271,8 @@ public int getECMAScriptVersion() { |
265 | 271 | return JSConfig.ECMAScript2021; |
266 | 272 | } else if (at == this) { |
267 | 273 | return JSConfig.ECMAScript2022; |
| 274 | + } else if (EnumSet.of(isWellFormed, toWellFormed).contains(this)) { |
| 275 | + return JSConfig.ECMAScript2024; |
268 | 276 | } |
269 | 277 | return BuiltinEnum.super.getECMAScriptVersion(); |
270 | 278 | } |
@@ -396,6 +404,11 @@ protected Object createNode(JSContext context, JSBuiltin builtin, boolean constr |
396 | 404 |
|
397 | 405 | case at: |
398 | 406 | return JSStringAtNodeGen.create(context, builtin, args().withThis().fixedArgs(1).createArgumentNodes(context)); |
| 407 | + |
| 408 | + case isWellFormed: |
| 409 | + return JSStringIsWellFormedNodeGen.create(context, builtin, args().withThis().createArgumentNodes(context)); |
| 410 | + case toWellFormed: |
| 411 | + return JSStringToWellFormedNodeGen.create(context, builtin, args().withThis().createArgumentNodes(context)); |
399 | 412 | } |
400 | 413 | return null; |
401 | 414 | } |
@@ -2971,6 +2984,46 @@ protected Object pad(Object thisObj, Object[] args, |
2971 | 2984 |
|
2972 | 2985 | } |
2973 | 2986 |
|
| 2987 | + public abstract static class JSStringIsWellFormedNode extends JSStringOperation { |
| 2988 | + |
| 2989 | + public JSStringIsWellFormedNode(JSContext context, JSBuiltin builtin) { |
| 2990 | + super(context, builtin); |
| 2991 | + } |
| 2992 | + |
| 2993 | + @Specialization |
| 2994 | + protected static Object doString(TruffleString thisStr, |
| 2995 | + @Shared @Cached TruffleString.IsValidNode isValidNode) { |
| 2996 | + return isValidNode.execute(thisStr, TruffleString.Encoding.UTF_16); |
| 2997 | + } |
| 2998 | + |
| 2999 | + @Specialization(guards = "!isString(thisObj)") |
| 3000 | + protected final Object doOther(Object thisObj, |
| 3001 | + @Shared @Cached TruffleString.IsValidNode isValidNode) { |
| 3002 | + requireObjectCoercible(thisObj); |
| 3003 | + return doString(toString(thisObj), isValidNode); |
| 3004 | + } |
| 3005 | + } |
| 3006 | + |
| 3007 | + public abstract static class JSStringToWellFormedNode extends JSStringOperation { |
| 3008 | + |
| 3009 | + public JSStringToWellFormedNode(JSContext context, JSBuiltin builtin) { |
| 3010 | + super(context, builtin); |
| 3011 | + } |
| 3012 | + |
| 3013 | + @Specialization |
| 3014 | + protected static TruffleString doString(TruffleString thisStr, |
| 3015 | + @Shared @Cached TruffleString.ToValidStringNode toValidNode) { |
| 3016 | + return toValidNode.execute(thisStr, TruffleString.Encoding.UTF_16); |
| 3017 | + } |
| 3018 | + |
| 3019 | + @Specialization(guards = "!isString(thisObj)") |
| 3020 | + protected final TruffleString doOther(Object thisObj, |
| 3021 | + @Shared @Cached TruffleString.ToValidStringNode toValidNode) { |
| 3022 | + requireObjectCoercible(thisObj); |
| 3023 | + return doString(toString(thisObj), toValidNode); |
| 3024 | + } |
| 3025 | + } |
| 3026 | + |
2974 | 3027 | /** |
2975 | 3028 | * Implementation of the CreateRegExpStringIterator abstract operation as specified by the |
2976 | 3029 | * String.prototype.matchAll draft proposal. |
|
0 commit comments