jscript: Create regexp object when evaluating regexp literal.

This commit is contained in:
Jacek Caban 2009-10-14 14:43:01 +02:00 committed by Alexandre Julliard
parent 98b5a1c6e8
commit e52115d673
5 changed files with 37 additions and 39 deletions

View File

@ -347,7 +347,7 @@ static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
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) {
case LT_UNDEFINED:
@ -364,18 +364,31 @@ static HRESULT literal_to_var(literal_t *literal, VARIANT *v)
V_VT(v) = VT_R8;
V_R8(v) = literal->u.dval;
break;
case LT_STRING:
case LT_STRING: {
BSTR str = SysAllocString(literal->u.wstr);
if(!str)
return E_OUTOFMEMORY;
V_VT(v) = VT_BSTR;
V_BSTR(v) = SysAllocString(literal->u.wstr);
V_BSTR(v) = str;
break;
}
case LT_BOOL:
V_VT(v) = VT_BOOL;
V_BOOL(v) = literal->u.bval;
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;
IDispatch_AddRef(literal->u.disp);
V_DISPATCH(v) = literal->u.disp;
V_DISPATCH(v) = (IDispatch*)_IDispatchEx_(regexp);
}
}
return S_OK;
@ -1656,7 +1669,7 @@ HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flag
TRACE("\n");
hres = literal_to_var(expr->literal, &var);
hres = literal_to_var(ctx->parser->script, expr->literal, &var);
if(FAILED(hres))
return hres;
@ -1735,7 +1748,7 @@ HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWO
return hres;
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))
break;

View File

@ -19,11 +19,6 @@
typedef struct _source_elements_t source_elements_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 {
function_expression_t *expr;
@ -61,7 +56,6 @@ typedef struct _parser_ctx_t {
jsheap_t heap;
obj_literal_t *obj_literals;
func_stack_t *func_stack;
struct _parser_ctx_t *next;
@ -131,9 +125,9 @@ typedef enum {
LT_DOUBLE,
LT_STRING,
LT_BOOL,
LT_DISPATCH,
LT_UNDEFINED,
LT_NULL
LT_NULL,
LT_REGEXP
}literal_type_t;
typedef struct {
@ -144,6 +138,11 @@ typedef struct {
const WCHAR *wstr;
VARIANT_BOOL bval;
IDispatch *disp;
struct {
const WCHAR *str;
DWORD str_len;
DWORD flags;
} regexp;
} u;
} literal_t;

View File

@ -755,20 +755,10 @@ int parser_lex(void *lval, parser_ctx_t *ctx)
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)
{
const WCHAR *re, *flags_ptr;
DWORD re_len, flags;
DispatchEx *regexp;
literal_t *ret;
HRESULT hres;
@ -798,14 +788,10 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
if(FAILED(hres))
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->type = LT_DISPATCH;
ret->u.disp = (IDispatch*)_IDispatchEx_(regexp);
ret->type = LT_REGEXP;
ret->u.regexp.str = re;
ret->u.regexp.str_len = re_len;
ret->u.regexp.flags = flags;
return ret;
}

View File

@ -1591,14 +1591,9 @@ static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
void parser_release(parser_ctx_t *ctx)
{
obj_literal_t *iter;
if(--ctx->ref)
return;
for(iter = ctx->obj_literals; iter; iter = iter->next)
jsdisp_release(iter->obj);
jsheap_free(&ctx->heap);
heap_free(ctx);
}

View File

@ -934,6 +934,11 @@ ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function
var re = /=(\?|%3F)/g;
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(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));