mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 13:48:11 +08:00
Retrieve RegExp 'g' flag in spec conformant way (original patch by bnoordhuis)
This commit is contained in:
parent
c4cdd61a3e
commit
4949d75daf
35
quickjs.c
35
quickjs.c
@ -42551,7 +42551,7 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,
|
|||||||
{
|
{
|
||||||
// [Symbol.match](str)
|
// [Symbol.match](str)
|
||||||
JSValueConst rx = this_val;
|
JSValueConst rx = this_val;
|
||||||
JSValue A, S, result, matchStr;
|
JSValue A, S, flags, result, matchStr;
|
||||||
int global, n, fullUnicode, isEmpty;
|
int global, n, fullUnicode, isEmpty;
|
||||||
JSString *p;
|
JSString *p;
|
||||||
|
|
||||||
@ -42559,16 +42559,23 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,
|
|||||||
return JS_ThrowTypeErrorNotAnObject(ctx);
|
return JS_ThrowTypeErrorNotAnObject(ctx);
|
||||||
|
|
||||||
A = JS_UNDEFINED;
|
A = JS_UNDEFINED;
|
||||||
|
flags = JS_UNDEFINED;
|
||||||
result = JS_UNDEFINED;
|
result = JS_UNDEFINED;
|
||||||
matchStr = JS_UNDEFINED;
|
matchStr = JS_UNDEFINED;
|
||||||
S = JS_ToString(ctx, argv[0]);
|
S = JS_ToString(ctx, argv[0]);
|
||||||
if (JS_IsException(S))
|
if (JS_IsException(S))
|
||||||
goto exception;
|
goto exception;
|
||||||
|
|
||||||
global = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_global));
|
flags = JS_GetProperty(ctx, rx, JS_ATOM_flags);
|
||||||
if (global < 0)
|
if (JS_IsException(flags))
|
||||||
goto exception;
|
goto exception;
|
||||||
|
flags = JS_ToStringFree(ctx, flags);
|
||||||
|
if (JS_IsException(flags))
|
||||||
|
goto exception;
|
||||||
|
p = JS_VALUE_GET_STRING(flags);
|
||||||
|
|
||||||
|
// TODO(bnoordhuis) query 'u' flag the same way?
|
||||||
|
global = (-1 != string_indexof_char(p, 'g', 0));
|
||||||
if (!global) {
|
if (!global) {
|
||||||
A = JS_RegExpExec(ctx, rx, S);
|
A = JS_RegExpExec(ctx, rx, S);
|
||||||
} else {
|
} else {
|
||||||
@ -42612,12 +42619,14 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
JS_FreeValue(ctx, result);
|
JS_FreeValue(ctx, result);
|
||||||
|
JS_FreeValue(ctx, flags);
|
||||||
JS_FreeValue(ctx, S);
|
JS_FreeValue(ctx, S);
|
||||||
return A;
|
return A;
|
||||||
|
|
||||||
exception:
|
exception:
|
||||||
JS_FreeValue(ctx, A);
|
JS_FreeValue(ctx, A);
|
||||||
JS_FreeValue(ctx, result);
|
JS_FreeValue(ctx, result);
|
||||||
|
JS_FreeValue(ctx, flags);
|
||||||
JS_FreeValue(ctx, S);
|
JS_FreeValue(ctx, S);
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
@ -42860,8 +42869,8 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val,
|
|||||||
// [Symbol.replace](str, rep)
|
// [Symbol.replace](str, rep)
|
||||||
JSValueConst rx = this_val, rep = argv[1];
|
JSValueConst rx = this_val, rep = argv[1];
|
||||||
JSValueConst args[6];
|
JSValueConst args[6];
|
||||||
JSValue str, rep_val, matched, tab, rep_str, namedCaptures, res;
|
JSValue flags, str, rep_val, matched, tab, rep_str, namedCaptures, res;
|
||||||
JSString *sp, *rp;
|
JSString *p, *sp, *rp;
|
||||||
StringBuffer b_s, *b = &b_s;
|
StringBuffer b_s, *b = &b_s;
|
||||||
ValueBuffer v_b, *results = &v_b;
|
ValueBuffer v_b, *results = &v_b;
|
||||||
int nextSourcePosition, n, j, functionalReplace, is_global, fullUnicode;
|
int nextSourcePosition, n, j, functionalReplace, is_global, fullUnicode;
|
||||||
@ -42877,6 +42886,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val,
|
|||||||
rep_val = JS_UNDEFINED;
|
rep_val = JS_UNDEFINED;
|
||||||
matched = JS_UNDEFINED;
|
matched = JS_UNDEFINED;
|
||||||
tab = JS_UNDEFINED;
|
tab = JS_UNDEFINED;
|
||||||
|
flags = JS_UNDEFINED;
|
||||||
rep_str = JS_UNDEFINED;
|
rep_str = JS_UNDEFINED;
|
||||||
namedCaptures = JS_UNDEFINED;
|
namedCaptures = JS_UNDEFINED;
|
||||||
|
|
||||||
@ -42893,10 +42903,18 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val,
|
|||||||
goto exception;
|
goto exception;
|
||||||
rp = JS_VALUE_GET_STRING(rep_val);
|
rp = JS_VALUE_GET_STRING(rep_val);
|
||||||
}
|
}
|
||||||
fullUnicode = 0;
|
|
||||||
is_global = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_global));
|
flags = JS_GetProperty(ctx, rx, JS_ATOM_flags);
|
||||||
if (is_global < 0)
|
if (JS_IsException(flags))
|
||||||
goto exception;
|
goto exception;
|
||||||
|
flags = JS_ToStringFree(ctx, flags);
|
||||||
|
if (JS_IsException(flags))
|
||||||
|
goto exception;
|
||||||
|
p = JS_VALUE_GET_STRING(flags);
|
||||||
|
|
||||||
|
// TODO(bnoordhuis) query 'u' flag the same way?
|
||||||
|
fullUnicode = 0;
|
||||||
|
is_global = (-1 != string_indexof_char(p, 'g', 0));
|
||||||
if (is_global) {
|
if (is_global) {
|
||||||
fullUnicode = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_unicode));
|
fullUnicode = JS_ToBoolFree(ctx, JS_GetProperty(ctx, rx, JS_ATOM_unicode));
|
||||||
if (fullUnicode < 0)
|
if (fullUnicode < 0)
|
||||||
@ -43030,6 +43048,7 @@ done1:
|
|||||||
value_buffer_free(results);
|
value_buffer_free(results);
|
||||||
JS_FreeValue(ctx, rep_val);
|
JS_FreeValue(ctx, rep_val);
|
||||||
JS_FreeValue(ctx, matched);
|
JS_FreeValue(ctx, matched);
|
||||||
|
JS_FreeValue(ctx, flags);
|
||||||
JS_FreeValue(ctx, tab);
|
JS_FreeValue(ctx, tab);
|
||||||
JS_FreeValue(ctx, rep_str);
|
JS_FreeValue(ctx, rep_str);
|
||||||
JS_FreeValue(ctx, namedCaptures);
|
JS_FreeValue(ctx, namedCaptures);
|
||||||
|
@ -11,18 +11,6 @@ test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: Test262Er
|
|||||||
test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: strict mode: Test262Error: Expected [a, abc] and [a, undefined] to have the same contents. ? quantifier
|
test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: strict mode: Test262Error: Expected [a, abc] and [a, undefined] to have the same contents. ? quantifier
|
||||||
test262/test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js:46: SyntaxError: invalid group name
|
test262/test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js:46: SyntaxError: invalid group name
|
||||||
test262/test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js:46: strict mode: SyntaxError: invalid group name
|
test262/test/built-ins/RegExp/named-groups/non-unicode-property-names-valid.js:46: strict mode: SyntaxError: invalid group name
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js:22: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js:22: strict mode: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js:23: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js:23: strict mode: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js:22: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js:22: strict mode: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.replace/flags-tostring-error.js:26: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.replace/flags-tostring-error.js:26: strict mode: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.replace/get-flags-err.js:27: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.replace/get-flags-err.js:27: strict mode: Test262Error: Expected a CustomError but got a Test262Error
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js:26: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all
|
|
||||||
test262/test/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js:26: strict mode: Test262Error: Expected a Test262Error to be thrown but no exception was thrown at all
|
|
||||||
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: Test262Error: \u0390 does not match \u1fd3
|
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: Test262Error: \u0390 does not match \u1fd3
|
||||||
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: strict mode: Test262Error: \u0390 does not match \u1fd3
|
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: strict mode: Test262Error: \u0390 does not match \u1fd3
|
||||||
test262/test/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js:62: Test262Error: String.prototype.localeCompare considers ö (\u006f\u0308) ≠ ö (\u00f6).
|
test262/test/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js:62: Test262Error: String.prototype.localeCompare considers ö (\u006f\u0308) ≠ ö (\u00f6).
|
||||||
|
Loading…
Reference in New Issue
Block a user