]> git.kaiwu.me - quickjs.git/commitdiff
fixed RegExp.escape
authorFabrice Bellard <fabrice@bellard.org>
Sat, 21 Mar 2026 14:53:25 +0000 (15:53 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 21 Mar 2026 14:53:25 +0000 (15:53 +0100)
TODO
quickjs.c
test262_errors.txt

diff --git a/TODO b/TODO
index 986a966bfea35511c79ec580ef912296ff899816..e0f6d60b35eb63ce0eef313d9caeb3bac5e726e8 100644 (file)
--- a/TODO
+++ b/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
index 5fae94bef617bb0d26b62a63a93e6c869882abef..d8ef72c4d42f0be18bfb13c6a32d83b62da55b75 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -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);
index a9c3174c8ef342d7d95e648975274a42f0577656..309e927e5ef5345a8c9a4b2ab05477c0096e9619 100644 (file)
@@ -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