Commit e52115d6 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Create regexp object when evaluating regexp literal.

parent 98b5a1c6
...@@ -347,7 +347,7 @@ static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret) ...@@ -347,7 +347,7 @@ static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
return S_OK; return S_OK;
} }
static HRESULT literal_to_var(literal_t *literal, VARIANT *v) static HRESULT literal_to_var(script_ctx_t *ctx, literal_t *literal, VARIANT *v)
{ {
switch(literal->type) { switch(literal->type) {
case LT_UNDEFINED: case LT_UNDEFINED:
...@@ -364,18 +364,31 @@ static HRESULT literal_to_var(literal_t *literal, VARIANT *v) ...@@ -364,18 +364,31 @@ static HRESULT literal_to_var(literal_t *literal, VARIANT *v)
V_VT(v) = VT_R8; V_VT(v) = VT_R8;
V_R8(v) = literal->u.dval; V_R8(v) = literal->u.dval;
break; break;
case LT_STRING: case LT_STRING: {
BSTR str = SysAllocString(literal->u.wstr);
if(!str)
return E_OUTOFMEMORY;
V_VT(v) = VT_BSTR; V_VT(v) = VT_BSTR;
V_BSTR(v) = SysAllocString(literal->u.wstr); V_BSTR(v) = str;
break; break;
}
case LT_BOOL: case LT_BOOL:
V_VT(v) = VT_BOOL; V_VT(v) = VT_BOOL;
V_BOOL(v) = literal->u.bval; V_BOOL(v) = literal->u.bval;
break; break;
case LT_DISPATCH: case LT_REGEXP: {
DispatchEx *regexp;
HRESULT hres;
hres = create_regexp(ctx, literal->u.regexp.str, literal->u.regexp.str_len,
literal->u.regexp.flags, &regexp);
if(FAILED(hres))
return hres;
V_VT(v) = VT_DISPATCH; V_VT(v) = VT_DISPATCH;
IDispatch_AddRef(literal->u.disp); V_DISPATCH(v) = (IDispatch*)_IDispatchEx_(regexp);
V_DISPATCH(v) = literal->u.disp; }
} }
return S_OK; return S_OK;
...@@ -1656,7 +1669,7 @@ HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flag ...@@ -1656,7 +1669,7 @@ HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flag
TRACE("\n"); TRACE("\n");
hres = literal_to_var(expr->literal, &var); hres = literal_to_var(ctx->parser->script, expr->literal, &var);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -1735,7 +1748,7 @@ HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWO ...@@ -1735,7 +1748,7 @@ HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWO
return hres; return hres;
for(iter = expr->property_list; iter; iter = iter->next) { for(iter = expr->property_list; iter; iter = iter->next) {
hres = literal_to_var(iter->name, &tmp); hres = literal_to_var(ctx->parser->script, iter->name, &tmp);
if(FAILED(hres)) if(FAILED(hres))
break; break;
......
...@@ -19,11 +19,6 @@ ...@@ -19,11 +19,6 @@
typedef struct _source_elements_t source_elements_t; typedef struct _source_elements_t source_elements_t;
typedef struct _function_expression_t function_expression_t; typedef struct _function_expression_t function_expression_t;
typedef struct _obj_literal_t {
DispatchEx *obj;
struct _obj_literal_t *next;
} obj_literal_t;
typedef struct _function_declaration_t { typedef struct _function_declaration_t {
function_expression_t *expr; function_expression_t *expr;
...@@ -61,7 +56,6 @@ typedef struct _parser_ctx_t { ...@@ -61,7 +56,6 @@ typedef struct _parser_ctx_t {
jsheap_t heap; jsheap_t heap;
obj_literal_t *obj_literals;
func_stack_t *func_stack; func_stack_t *func_stack;
struct _parser_ctx_t *next; struct _parser_ctx_t *next;
...@@ -131,9 +125,9 @@ typedef enum { ...@@ -131,9 +125,9 @@ typedef enum {
LT_DOUBLE, LT_DOUBLE,
LT_STRING, LT_STRING,
LT_BOOL, LT_BOOL,
LT_DISPATCH,
LT_UNDEFINED, LT_UNDEFINED,
LT_NULL LT_NULL,
LT_REGEXP
}literal_type_t; }literal_type_t;
typedef struct { typedef struct {
...@@ -144,6 +138,11 @@ typedef struct { ...@@ -144,6 +138,11 @@ typedef struct {
const WCHAR *wstr; const WCHAR *wstr;
VARIANT_BOOL bval; VARIANT_BOOL bval;
IDispatch *disp; IDispatch *disp;
struct {
const WCHAR *str;
DWORD str_len;
DWORD flags;
} regexp;
} u; } u;
} literal_t; } literal_t;
......
...@@ -755,20 +755,10 @@ int parser_lex(void *lval, parser_ctx_t *ctx) ...@@ -755,20 +755,10 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
return 0; return 0;
} }
static void add_object_literal(parser_ctx_t *ctx, DispatchEx *obj)
{
obj_literal_t *literal = parser_alloc(ctx, sizeof(obj_literal_t));
literal->obj = obj;
literal->next = ctx->obj_literals;
ctx->obj_literals = literal;
}
literal_t *parse_regexp(parser_ctx_t *ctx) literal_t *parse_regexp(parser_ctx_t *ctx)
{ {
const WCHAR *re, *flags_ptr; const WCHAR *re, *flags_ptr;
DWORD re_len, flags; DWORD re_len, flags;
DispatchEx *regexp;
literal_t *ret; literal_t *ret;
HRESULT hres; HRESULT hres;
...@@ -798,14 +788,10 @@ literal_t *parse_regexp(parser_ctx_t *ctx) ...@@ -798,14 +788,10 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
if(FAILED(hres)) if(FAILED(hres))
return NULL; return NULL;
hres = create_regexp(ctx->script, re, re_len, flags, &regexp);
if(FAILED(hres))
return NULL;
add_object_literal(ctx, regexp);
ret = parser_alloc(ctx, sizeof(literal_t)); ret = parser_alloc(ctx, sizeof(literal_t));
ret->type = LT_DISPATCH; ret->type = LT_REGEXP;
ret->u.disp = (IDispatch*)_IDispatchEx_(regexp); ret->u.regexp.str = re;
ret->u.regexp.str_len = re_len;
ret->u.regexp.flags = flags;
return ret; return ret;
} }
...@@ -1591,14 +1591,9 @@ static void program_parsed(parser_ctx_t *ctx, source_elements_t *source) ...@@ -1591,14 +1591,9 @@ static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
void parser_release(parser_ctx_t *ctx) void parser_release(parser_ctx_t *ctx)
{ {
obj_literal_t *iter;
if(--ctx->ref) if(--ctx->ref)
return; return;
for(iter = ctx->obj_literals; iter; iter = iter->next)
jsdisp_release(iter->obj);
jsheap_free(&ctx->heap); jsheap_free(&ctx->heap);
heap_free(ctx); heap_free(ctx);
} }
......
...@@ -934,6 +934,11 @@ ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function ...@@ -934,6 +934,11 @@ ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function
var re = /=(\?|%3F)/g; var re = /=(\?|%3F)/g;
ok(re.source === "=(\\?|%3F)", "re.source = " + re.source); ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
tmp = new Array();
for(var i=0; i<2; i++)
tmp[i] = /b/;
ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
ok(createNullBSTR() === '', "createNullBSTR() !== ''"); ok(createNullBSTR() === '', "createNullBSTR() !== ''");
ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp)); ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment