From 3805eef49a323e5022329822cfd87dd32e7ce7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= Date: Tue, 22 Nov 2022 18:53:20 +0200 Subject: [PATCH] jscript: Initialize source and lastIndex for RegExp.prototype. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Ivăncescu --- dlls/jscript/jsregexp.c | 14 ++++++++------ dlls/jscript/tests/api.js | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dlls/jscript/jsregexp.c b/dlls/jscript/jsregexp.c index fa4759b972d..1cbc828ce09 100644 --- a/dlls/jscript/jsregexp.c +++ b/dlls/jscript/jsregexp.c @@ -585,7 +585,7 @@ static const builtin_info_t RegExpInst_info = { NULL }; -static HRESULT alloc_regexp(script_ctx_t *ctx, jsdisp_t *object_prototype, RegExpInstance **ret) +static HRESULT alloc_regexp(script_ctx_t *ctx, jsstr_t *str, jsdisp_t *object_prototype, RegExpInstance **ret) { RegExpInstance *regexp; HRESULT hres; @@ -604,6 +604,9 @@ static HRESULT alloc_regexp(script_ctx_t *ctx, jsdisp_t *object_prototype, RegEx return hres; } + regexp->str = jsstr_addref(str); + regexp->last_index_val = jsval_number(0); + *ret = regexp; return S_OK; } @@ -620,13 +623,10 @@ HRESULT create_regexp(script_ctx_t *ctx, jsstr_t *src, DWORD flags, jsdisp_t **r TRACE("%s %lx\n", debugstr_wn(str, jsstr_length(src)), flags); - hres = alloc_regexp(ctx, NULL, ®exp); + hres = alloc_regexp(ctx, src, NULL, ®exp); if(FAILED(hres)) return hres; - regexp->str = jsstr_addref(src); - regexp->last_index_val = jsval_number(0); - regexp->jsregexp = regexp_new(ctx, &ctx->tmp_heap, str, jsstr_length(regexp->str), flags, FALSE); if(!regexp->jsregexp) { WARN("regexp_new failed\n"); @@ -959,10 +959,12 @@ static const builtin_info_t RegExpConstr_info = { HRESULT create_regexp_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret) { + jsstr_t *str = jsstr_empty(); RegExpInstance *regexp; HRESULT hres; - hres = alloc_regexp(ctx, object_prototype, ®exp); + hres = alloc_regexp(ctx, str, object_prototype, ®exp); + jsstr_release(str); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index c33791f1fb1..a3b2bbcbba5 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -335,6 +335,8 @@ ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false"); ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true"); ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true"); ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false"); +ok(RegExp.prototype.source === "", "RegExp.prototype.source = " + RegExp.prototype.source); +ok(RegExp.prototype.lastIndex === 0, "RegExp.prototype.lastIndex = " + RegExp.prototype.lastIndex); String(); new String();