fixed RegExp.escape

This commit is contained in:
Fabrice Bellard 2026-03-21 15:53:25 +01:00
parent 46bd985b33
commit 4d16546cdf
3 changed files with 9 additions and 9 deletions

2
TODO

@ -63,4 +63,4 @@ Test262o: 0/11262 errors, 463 excluded
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
Test262:
Result: 62/83394 errors, 3348 excluded, 6090 skipped
Result: 60/83394 errors, 3348 excluded, 6090 skipped

@ -47318,9 +47318,10 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val,
JSValue str;
StringBuffer b_s, *b = &b_s;
JSString *p;
uint32_t c, i;
uint32_t c;
char s[16];
int i, i0;
if (!JS_IsString(argv[0]))
return JS_ThrowTypeError(ctx, "not a string");
str = JS_ToString(ctx, argv[0]); /* must call it to linearlize ropes */
@ -47328,8 +47329,9 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val,
return JS_EXCEPTION;
p = JS_VALUE_GET_STRING(str);
string_buffer_init2(ctx, b, 0, p->is_wide_char);
for (i = 0; i < p->len; i++) {
c = string_get(p, i);
for (i = 0; i < p->len; ) {
i0 = i;
c = string_getc(p, &i);
if (c < 33) {
if (c >= 9 && c <= 13) {
string_buffer_putc8(b, '\\');
@ -47341,7 +47343,7 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val,
if ((c >= '0' && c <= '9')
|| (c >= 'A' && c <= 'Z')
|| (c >= 'a' && c <= 'z')) {
if (i == 0)
if (i0 == 0)
goto hex2;
} else if (strchr(",-=<>#&!%:;@~'`\"", c)) {
goto hex2;
@ -47357,7 +47359,7 @@ static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val,
snprintf(s, sizeof(s), "\\u%04x", c);
string_buffer_puts8(b, s);
} else {
string_buffer_putc16(b, c);
string_buffer_putc(b, c);
}
}
JS_FreeValue(ctx, str);

@ -23,8 +23,6 @@ test262/test/language/module-code/ambiguous-export-bindings/import-and-export-pr
test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-export-star-as-from-and-import-star-as-and-export.js:74: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-import-star-as-and-export.js' is ambiguous
test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-export-star-as-from.js:75: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-export-star-as-from.js' is ambiguous
test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-import-star-as-and-export.js:74: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/namespace-unambiguous-if-import-star-as-and-export.js' is ambiguous
test262/test/staging/built-ins/RegExp/escape/surrogate-pair.js:9: Test262Error: Unescaped surrogate pair Expected SameValue(«"\\ud800\\udc00"», «"𐀀"») to be true
test262/test/staging/built-ins/RegExp/escape/surrogate-pair.js:9: strict mode: Test262Error: Unescaped surrogate pair Expected SameValue(«"\\ud800\\udc00"», «"𐀀"») to be true
test262/test/staging/sm/Function/arguments-parameter-shadowing.js:14: Test262Error: Expected SameValue(«true», «false») to be true
test262/test/staging/sm/Function/constructor-binding.js:11: Test262Error: Expected SameValue(«"function"», «"undefined"») to be true
test262/test/staging/sm/Function/constructor-binding.js:11: strict mode: Test262Error: Expected SameValue(«"function"», «"undefined"») to be true