Commit 7828df17 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Introduce jsstr_to_bstr helper.

parent 31c57484
......@@ -299,9 +299,18 @@ jsstr_t *jsstr_null_bstr(void)
return jsstr_addref(null_bstr_str);
}
BOOL is_null_bstr(jsstr_t *str)
HRESULT jsstr_to_bstr(jsstr_t *str, BSTR *r)
{
return str == null_bstr_str;
if(str == null_bstr_str) {
*r = NULL;
return S_OK;
}
if(!(*r = SysAllocStringLen(NULL, jsstr_length(str))))
return E_OUTOFMEMORY;
jsstr_flush(str, *r);
return S_OK;
}
BOOL init_strings(void)
......
......@@ -182,7 +182,7 @@ jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN;
jsstr_t *jsstr_undefined(void) DECLSPEC_HIDDEN;
jsstr_t *jsstr_null_bstr(void) DECLSPEC_HIDDEN;
BOOL is_null_bstr(jsstr_t*) DECLSPEC_HIDDEN;
HRESULT jsstr_to_bstr(jsstr_t *str, BSTR *r) DECLSPEC_HIDDEN;
BOOL init_strings(void) DECLSPEC_HIDDEN;
void free_strings(void) DECLSPEC_HIDDEN;
......
......@@ -355,21 +355,9 @@ HRESULT jsval_to_variant(jsval_t val, VARIANT *retv)
IDispatch_AddRef(get_object(val));
V_DISPATCH(retv) = get_object(val);
return S_OK;
case JSV_STRING: {
jsstr_t *str = get_string(val);
case JSV_STRING:
V_VT(retv) = VT_BSTR;
if(is_null_bstr(str)) {
V_BSTR(retv) = NULL;
}else {
V_BSTR(retv) = SysAllocStringLen(NULL, jsstr_length(str));
if(V_BSTR(retv))
jsstr_flush(str, V_BSTR(retv));
else
return E_OUTOFMEMORY;
}
return S_OK;
}
return jsstr_to_bstr(get_string(val), &V_BSTR(retv));
case JSV_NUMBER: {
double n = get_number(val);
......@@ -945,16 +933,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
if(FAILED(hres))
break;
if(is_null_bstr(str)) {
V_BSTR(dst) = NULL;
break;
}
V_BSTR(dst) = SysAllocStringLen(NULL, jsstr_length(str));
if(V_BSTR(dst))
jsstr_flush(str, V_BSTR(dst));
else
hres = E_OUTOFMEMORY;
hres = jsstr_to_bstr(str, &V_BSTR(dst));
break;
}
case VT_EMPTY:
......
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