jscript: Initialize source and lastIndex for RegExp.prototype.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
This commit is contained in:
Gabriel Ivăncescu 2022-11-22 18:53:20 +02:00 committed by Alexandre Julliard
parent f8a0d96567
commit 3805eef49a
2 changed files with 10 additions and 6 deletions

View file

@ -585,7 +585,7 @@ static const builtin_info_t RegExpInst_info = {
NULL 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; RegExpInstance *regexp;
HRESULT hres; HRESULT hres;
@ -604,6 +604,9 @@ static HRESULT alloc_regexp(script_ctx_t *ctx, jsdisp_t *object_prototype, RegEx
return hres; return hres;
} }
regexp->str = jsstr_addref(str);
regexp->last_index_val = jsval_number(0);
*ret = regexp; *ret = regexp;
return S_OK; 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); TRACE("%s %lx\n", debugstr_wn(str, jsstr_length(src)), flags);
hres = alloc_regexp(ctx, NULL, &regexp); hres = alloc_regexp(ctx, src, NULL, &regexp);
if(FAILED(hres)) if(FAILED(hres))
return 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); regexp->jsregexp = regexp_new(ctx, &ctx->tmp_heap, str, jsstr_length(regexp->str), flags, FALSE);
if(!regexp->jsregexp) { if(!regexp->jsregexp) {
WARN("regexp_new failed\n"); 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) HRESULT create_regexp_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
{ {
jsstr_t *str = jsstr_empty();
RegExpInstance *regexp; RegExpInstance *regexp;
HRESULT hres; HRESULT hres;
hres = alloc_regexp(ctx, object_prototype, &regexp); hres = alloc_regexp(ctx, str, object_prototype, &regexp);
jsstr_release(str);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;

View file

@ -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('exec'), "RegExp.hasOwnProperty('exec') is true");
ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') 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.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(); String();
new String(); new String();