diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index eb15be43ace..52cdc88f80c 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -1698,13 +1698,11 @@ static HRESULT interp_typeofid(exec_ctx_t *ctx) DISPID id; HRESULT hres; - static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; - TRACE("\n"); obj = stack_pop_objid(ctx, &id); if(!obj) - return stack_push_string(ctx, undefinedW); + return stack_push(ctx, jsval_string(jsstr_undefined())); hres = disp_propget(ctx->script, obj, id, &v); IDispatch_Release(obj); @@ -1735,7 +1733,7 @@ static HRESULT interp_typeofident(exec_ctx_t *ctx) return hres; if(exprval.type == EXPRVAL_INVALID) { - hres = stack_push_string(ctx, undefinedW); + hres = stack_push(ctx, jsval_string(jsstr_undefined())); exprval_release(&exprval); return hres; } diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 0668e860d5b..739a8319f4d 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -286,14 +286,8 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u TRACE("\n"); if(!argc) { - if(r) { - ret_str = jsstr_alloc(undefinedW); - if(!ret_str) - return E_OUTOFMEMORY; - - *r = jsval_string(ret_str); - } - + if(r) + *r = jsval_string(jsstr_undefined()); return S_OK; } @@ -640,13 +634,8 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, TRACE("\n"); if(!argc) { - if(r) { - ret_str = jsstr_alloc(undefinedW); - if(!ret_str) - return E_OUTOFMEMORY; - *r = jsval_string(ret_str); - } - + if(r) + *r = jsval_string(jsstr_undefined()); return S_OK; } @@ -781,14 +770,8 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags TRACE("\n"); if(!argc) { - if(r) { - ret = jsstr_alloc(undefinedW); - if(!ret) - return E_OUTOFMEMORY; - - *r = jsval_string(ret); - } - + if(r) + *r = jsval_string(jsstr_undefined()); return S_OK; } @@ -853,14 +836,8 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags TRACE("\n"); if(!argc) { - if(r) { - ret = jsstr_alloc(undefinedW); - if(!ret) - return E_OUTOFMEMORY; - - *r = jsval_string(ret); - } - + if(r) + *r = jsval_string(jsstr_undefined()); return S_OK; } @@ -944,14 +921,8 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W TRACE("\n"); if(!argc) { - if(r) { - ret = jsstr_alloc(undefinedW); - if(!ret) - return E_OUTOFMEMORY; - - *r = jsval_string(ret); - } - + if(r) + *r = jsval_string(jsstr_undefined()); return S_OK; } @@ -1014,14 +985,8 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W TRACE("\n"); if(!argc) { - if(r) { - ret = jsstr_alloc(undefinedW); - if(!ret) - return E_OUTOFMEMORY; - - *r = jsval_string(ret); - } - + if(r) + *r = jsval_string(jsstr_undefined()); return S_OK; } diff --git a/dlls/jscript/jsregexp.c b/dlls/jscript/jsregexp.c index 43df35a1ca0..61e9a95a239 100644 --- a/dlls/jscript/jsregexp.c +++ b/dlls/jscript/jsregexp.c @@ -58,7 +58,6 @@ static const WCHAR idx7W[] = {'$','7',0}; static const WCHAR idx8W[] = {'$','8',0}; static const WCHAR idx9W[] = {'$','9',0}; -static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; static const WCHAR emptyW[] = {0}; static inline RegExpInstance *regexp_from_vdisp(vdisp_t *vdisp) @@ -487,21 +486,15 @@ static HRESULT RegExp_test(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig jsval_t *r) { match_state_t *match; - heap_pool_t *mark; jsstr_t *undef_str; + heap_pool_t *mark; BOOL b; HRESULT hres; TRACE("\n"); - if(!argc) { - undef_str = jsstr_alloc(undefinedW); - if(!undef_str) - return E_OUTOFMEMORY; - } - mark = heap_pool_mark(&ctx->tmp_heap); - hres = run_exec(ctx, jsthis, argc ? argv[0] : jsval_string(undef_str), NULL, &match, &b); + hres = run_exec(ctx, jsthis, argc ? argv[0] : jsval_string(undef_str = jsstr_undefined()), NULL, &match, &b); heap_pool_clear(mark); if(!argc) jsstr_release(undef_str); diff --git a/dlls/jscript/jsstr.c b/dlls/jscript/jsstr.c index 59dfe9824c9..3fb50b4779f 100644 --- a/dlls/jscript/jsstr.c +++ b/dlls/jscript/jsstr.c @@ -88,7 +88,7 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2) return ret; } -static jsstr_t *empty_str, *nan_str; +static jsstr_t *empty_str, *nan_str, *undefined_str; jsstr_t *jsstr_nan(void) { @@ -100,14 +100,22 @@ jsstr_t *jsstr_empty(void) return jsstr_addref(empty_str); } +jsstr_t *jsstr_undefined(void) +{ + return jsstr_addref(undefined_str); +} + BOOL init_strings(void) { static const WCHAR NaNW[] = { 'N','a','N',0 }; + static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; if(!(empty_str = jsstr_alloc_buf(0))) return FALSE; if(!(nan_str = jsstr_alloc(NaNW))) return FALSE; + if(!(undefined_str = jsstr_alloc(undefinedW))) + return FALSE; return TRUE; } @@ -115,4 +123,5 @@ void free_strings(void) { jsstr_release(empty_str); jsstr_release(nan_str); + jsstr_release(undefined_str); } diff --git a/dlls/jscript/jsstr.h b/dlls/jscript/jsstr.h index cbe68ef3437..c71cbea4293 100644 --- a/dlls/jscript/jsstr.h +++ b/dlls/jscript/jsstr.h @@ -76,6 +76,7 @@ jsstr_t *jsstr_concat(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN; jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN; jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN; +jsstr_t *jsstr_undefined(void) DECLSPEC_HIDDEN; BOOL init_strings(void) DECLSPEC_HIDDEN; void free_strings(void) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 5900d81d685..60260bba49a 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -738,15 +738,14 @@ HRESULT double_to_string(double n, jsstr_t **str) /* ECMA-262 3rd Edition 9.8 */ HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str) { - const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; const WCHAR nullW[] = {'n','u','l','l',0}; const WCHAR trueW[] = {'t','r','u','e',0}; const WCHAR falseW[] = {'f','a','l','s','e',0}; switch(jsval_type(val)) { case JSV_UNDEFINED: - *str = jsstr_alloc(undefinedW); - break; + *str = jsstr_undefined(); + return S_OK; case JSV_NULL: *str = jsstr_alloc(nullW); break; diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c index 8823a30b364..54c8fcf98ce 100644 --- a/dlls/jscript/lex.c +++ b/dlls/jscript/lex.c @@ -59,7 +59,6 @@ static const WCHAR throwW[] = {'t','h','r','o','w',0}; static const WCHAR trueW[] = {'t','r','u','e',0}; static const WCHAR tryW[] = {'t','r','y',0}; static const WCHAR typeofW[] = {'t','y','p','e','o','f',0}; -static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; static const WCHAR varW[] = {'v','a','r',0}; static const WCHAR voidW[] = {'v','o','i','d',0}; static const WCHAR whileW[] = {'w','h','i','l','e',0}; diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 8f38621e6a1..2aa9e585c57 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -188,10 +188,7 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsigned argc, jsval_t *argv, jsval_t *r, const WCHAR *tagname, const WCHAR *attrname) { - static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; - jsstr_t *str, *attr_value = NULL; - unsigned attr_len; HRESULT hres; hres = get_string_val(ctx, jsthis, &str); @@ -204,9 +201,8 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig jsstr_release(str); return hres; } - attr_len = jsstr_length(attr_value); }else { - attr_len = sizeof(undefinedW)/sizeof(WCHAR)-1; + attr_value = jsstr_undefined(); } if(r) { @@ -214,7 +210,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig unsigned tagname_len = strlenW(tagname); jsstr_t *ret; - ret = jsstr_alloc_buf(2*tagname_len + attrname_len + attr_len + jsstr_length(str) + 9); + ret = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9); if(ret) { WCHAR *ptr = ret->str; @@ -226,13 +222,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig ptr += attrname_len; *ptr++ = '='; *ptr++ = '"'; - - if(attr_value) - jsstr_flush(attr_value, ptr); - else - memcpy(ptr, undefinedW, attr_len*sizeof(WCHAR)); - ptr += attr_len; - + ptr += jsstr_flush(attr_value, ptr); *ptr++ = '"'; *ptr++ = '>'; ptr += jsstr_flush(str, ptr); @@ -249,8 +239,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig } } - if(attr_value) - jsstr_release(attr_value); + jsstr_release(attr_value); jsstr_release(str); return hres; }