Commit 4ece40f8 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Return buffer pointer separately from jsstr_t from jsstr_alloc_len.

parent 79632a22
...@@ -234,7 +234,7 @@ static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi ...@@ -234,7 +234,7 @@ static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, jsval_t *r) static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, jsval_t *r)
{ {
jsstr_t **str_tab, *ret = NULL; jsstr_t **str_tab, *ret;
jsval_t val; jsval_t val;
DWORD i; DWORD i;
HRESULT hres = E_FAIL; HRESULT hres = E_FAIL;
...@@ -267,7 +267,6 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons ...@@ -267,7 +267,6 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
DWORD seplen = 0, len = 0; DWORD seplen = 0, len = 0;
WCHAR *ptr;
seplen = strlenW(sep); seplen = strlenW(sep);
...@@ -283,11 +282,11 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons ...@@ -283,11 +282,11 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
} }
} }
if(SUCCEEDED(hres)) if(SUCCEEDED(hres)) {
ret = jsstr_alloc_buf(len); WCHAR *ptr = NULL;
if(ret) {
ptr = ret->str;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr) {
if(str_tab[0]) if(str_tab[0])
ptr += jsstr_flush(str_tab[0], ptr); ptr += jsstr_flush(str_tab[0], ptr);
...@@ -304,6 +303,7 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons ...@@ -304,6 +303,7 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
hres = E_OUTOFMEMORY; hres = E_OUTOFMEMORY;
} }
} }
}
for(i=0; i < length; i++) { for(i=0; i < length; i++) {
if(str_tab[i]) if(str_tab[i])
......
...@@ -492,7 +492,7 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, ...@@ -492,7 +492,7 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
BOOL formatAD = TRUE; BOOL formatAD = TRUE;
WCHAR week[64], month[64]; WCHAR week[64], month[64];
jsstr_t *date_str; jsstr_t *date_jsstr;
int len, size, year, day; int len, size, year, day;
DWORD lcid_en; DWORD lcid_en;
WCHAR sign = '-'; WCHAR sign = '-';
...@@ -504,6 +504,8 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, ...@@ -504,6 +504,8 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
} }
if(r) { if(r) {
WCHAR *date_str;
len = 21; len = 21;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT); lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
...@@ -544,25 +546,25 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, ...@@ -544,25 +546,25 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
offset = -offset; offset = -offset;
} }
date_str = jsstr_alloc_buf(len); date_str = jsstr_alloc_buf(len, &date_jsstr);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(!show_offset) if(!show_offset)
sprintfW(date_str->str, formatNoOffsetW, week, month, day, sprintfW(date_str, formatNoOffsetW, week, month, day,
(int)hour_from_time(time), (int)min_from_time(time), (int)hour_from_time(time), (int)min_from_time(time),
(int)sec_from_time(time), year, formatAD?ADW:BCW); (int)sec_from_time(time), year, formatAD?ADW:BCW);
else if(offset) else if(offset)
sprintfW(date_str->str, formatW, week, month, day, sprintfW(date_str, formatW, week, month, day,
(int)hour_from_time(time), (int)min_from_time(time), (int)hour_from_time(time), (int)min_from_time(time),
(int)sec_from_time(time), sign, offset/60, offset%60, (int)sec_from_time(time), sign, offset/60, offset%60,
year, formatAD?ADW:BCW); year, formatAD?ADW:BCW);
else else
sprintfW(date_str->str, formatUTCW, week, month, day, sprintfW(date_str, formatUTCW, week, month, day,
(int)hour_from_time(time), (int)min_from_time(time), (int)hour_from_time(time), (int)min_from_time(time),
(int)sec_from_time(time), year, formatAD?ADW:BCW); (int)sec_from_time(time), year, formatAD?ADW:BCW);
*r = jsval_string(date_str); *r = jsval_string(date_jsstr);
} }
return S_OK; return S_OK;
} }
...@@ -618,14 +620,18 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag ...@@ -618,14 +620,18 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
return dateobj_to_string(date, r); return dateobj_to_string(date, r);
if(r) { if(r) {
WCHAR *ptr;
date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0); date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0); time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
date_str = jsstr_alloc_buf(date_len+time_len-1);
ptr = jsstr_alloc_buf(date_len+time_len-1, &date_str);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, date_str->str, date_len);
GetTimeFormatW(ctx->lcid, 0, &st, NULL, date_str->str+date_len, time_len); GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, date_len);
date_str->str[date_len-1] = ' '; GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr+date_len, time_len);
ptr[date_len-1] = ' ';
*r = jsval_string(date_str); *r = jsval_string(date_str);
} }
...@@ -681,6 +687,8 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva ...@@ -681,6 +687,8 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
} }
if(r) { if(r) {
WCHAR *ptr;
len = 17; len = 17;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT); lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
...@@ -713,11 +721,11 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva ...@@ -713,11 +721,11 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
} while(day); } while(day);
day = date_from_time(date->time); day = date_from_time(date->time);
date_str = jsstr_alloc_buf(len); ptr = jsstr_alloc_buf(len, &date_str);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
sprintfW(date_str->str, formatAD?formatADW:formatBCW, week, day, month, year, sprintfW(ptr, formatAD?formatADW:formatBCW, week, day, month, year,
(int)hour_from_time(date->time), (int)min_from_time(date->time), (int)hour_from_time(date->time), (int)min_from_time(date->time),
(int)sec_from_time(date->time)); (int)sec_from_time(date->time));
...@@ -773,6 +781,8 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r) ...@@ -773,6 +781,8 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
time = local_time(date->time, date); time = local_time(date->time, date);
if(r) { if(r) {
WCHAR *ptr;
len = 5; len = 5;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT); lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
...@@ -807,10 +817,10 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r) ...@@ -807,10 +817,10 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
} while(day); } while(day);
day = date_from_time(time); day = date_from_time(time);
date_str = jsstr_alloc_buf(len); ptr = jsstr_alloc_buf(len, &date_str);
if(!date_str) if(!ptr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
sprintfW(date_str->str, formatAD?formatADW:formatBCW, week, month, day, year); sprintfW(ptr, formatAD?formatADW:formatBCW, week, month, day, year);
*r = jsval_string(date_str); *r = jsval_string(date_str);
} }
...@@ -856,7 +866,9 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -856,7 +866,9 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
time = local_time(date->time, date); time = local_time(date->time, date);
if(r) { if(r) {
date_str = jsstr_alloc_buf(17); WCHAR *ptr;
ptr = jsstr_alloc_buf(17, &date_str);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
...@@ -870,11 +882,11 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -870,11 +882,11 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
else sign = '-'; else sign = '-';
if(offset) if(offset)
sprintfW(date_str->str, formatW, (int)hour_from_time(time), sprintfW(ptr, formatW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time), (int)min_from_time(time), (int)sec_from_time(time),
sign, offset/60, offset%60); sign, offset/60, offset%60);
else else
sprintfW(date_str->str, formatUTCW, (int)hour_from_time(time), sprintfW(ptr, formatUTCW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time)); (int)min_from_time(time), (int)sec_from_time(time));
*r = jsval_string(date_str); *r = jsval_string(date_str);
...@@ -908,11 +920,13 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD ...@@ -908,11 +920,13 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
return dateobj_to_date_string(date, r); return dateobj_to_date_string(date, r);
if(r) { if(r) {
WCHAR *ptr;
len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0); len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
date_str = jsstr_alloc_buf(len); ptr = jsstr_alloc_buf(len, &date_str);
if(!date_str) if(!ptr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, date_str->str, len); GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, len);
*r = jsval_string(date_str); *r = jsval_string(date_str);
} }
...@@ -945,11 +959,13 @@ static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD ...@@ -945,11 +959,13 @@ static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
return Date_toTimeString(ctx, jsthis, flags, argc, argv, r); return Date_toTimeString(ctx, jsthis, flags, argc, argv, r);
if(r) { if(r) {
WCHAR *ptr;
len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0); len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
date_str = jsstr_alloc_buf(len); ptr = jsstr_alloc_buf(len, &date_str);
if(!date_str) if(!ptr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
GetTimeFormatW(ctx->lcid, 0, &st, NULL, date_str->str, len); GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr, len);
*r = jsval_string(date_str); *r = jsval_string(date_str);
} }
......
...@@ -2001,11 +2001,11 @@ static HRESULT interp_eq2(exec_ctx_t *ctx) ...@@ -2001,11 +2001,11 @@ static HRESULT interp_eq2(exec_ctx_t *ctx)
BOOL b; BOOL b;
HRESULT hres; HRESULT hres;
TRACE("\n");
r = stack_pop(ctx); r = stack_pop(ctx);
l = stack_pop(ctx); l = stack_pop(ctx);
TRACE("%s === %s\n", debugstr_jsval(l), debugstr_jsval(r));
hres = equal2_values(r, l, &b); hres = equal2_values(r, l, &b);
jsval_release(l); jsval_release(l);
jsval_release(r); jsval_release(r);
......
...@@ -83,12 +83,16 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, ...@@ -83,12 +83,16 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
unsigned msg_len = msg ? jsstr_length(msg) : 0; unsigned msg_len = msg ? jsstr_length(msg) : 0;
if(name_len && msg_len) { if(name_len && msg_len) {
ret = jsstr_alloc_buf(name_len + msg_len + 2); WCHAR *ptr;
if(ret) {
jsstr_flush(name, ret->str); ptr = jsstr_alloc_buf(name_len + msg_len + 2, &ret);
ret->str[name_len] = ':'; if(ptr) {
ret->str[name_len+1] = ' '; jsstr_flush(name, ptr);
jsstr_flush(msg, ret->str+name_len+2); ptr[name_len] = ':';
ptr[name_len+1] = ' ';
jsstr_flush(msg, ptr+name_len+2);
}else {
hres = E_OUTOFMEMORY;
} }
}else if(name_len) { }else if(name_len) {
ret = name; ret = name;
......
...@@ -318,15 +318,16 @@ static HRESULT function_to_string(FunctionInstance *function, jsstr_t **ret) ...@@ -318,15 +318,16 @@ static HRESULT function_to_string(FunctionInstance *function, jsstr_t **ret)
if(function->value_proc) { if(function->value_proc) {
DWORD name_len; DWORD name_len;
WCHAR *ptr;
name_len = strlenW(function->name); name_len = strlenW(function->name);
str = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len); ptr = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &str);
if(!str) if(!ptr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
memcpy(str->str, native_prefixW, sizeof(native_prefixW)); memcpy(ptr, native_prefixW, sizeof(native_prefixW));
memcpy(str->str + sizeof(native_prefixW)/sizeof(WCHAR), function->name, name_len*sizeof(WCHAR)); memcpy(ptr += sizeof(native_prefixW)/sizeof(WCHAR), function->name, name_len*sizeof(WCHAR));
memcpy(str->str + sizeof(native_prefixW)/sizeof(WCHAR) + name_len, native_suffixW, sizeof(native_suffixW)); memcpy(ptr + name_len, native_suffixW, sizeof(native_suffixW));
}else { }else {
str = jsstr_alloc_len(function->func_code->source, function->func_code->source_len); str = jsstr_alloc_len(function->func_code->source, function->func_code->source_len);
if(!str) if(!str)
......
...@@ -304,14 +304,13 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u ...@@ -304,14 +304,13 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
len += 3; len += 3;
} }
ret_str = jsstr_alloc_buf(len); ret = jsstr_alloc_buf(len, &ret_str);
if(!ret_str) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
len = 0; len = 0;
ret = ret_str->str;
for(ptr = str->str; *ptr; ptr++) { for(ptr = str->str; *ptr; ptr++) {
if(*ptr > 0xff) { if(*ptr > 0xff) {
ret[len++] = '%'; ret[len++] = '%';
...@@ -655,13 +654,12 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -655,13 +654,12 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
len++; len++;
} }
ret_str = jsstr_alloc_buf(len); ret = jsstr_alloc_buf(len, &ret_str);
if(!ret_str) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
ret = ret_str->str;
len = 0; len = 0;
for(ptr = str->str; *ptr; ptr++) { for(ptr = str->str; *ptr; ptr++) {
if(*ptr == '%') { if(*ptr == '%') {
...@@ -793,12 +791,11 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -793,12 +791,11 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
} }
} }
ret = jsstr_alloc_buf(len); rptr = jsstr_alloc_buf(len, &ret);
if(!ret) { if(!rptr) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
rptr = ret->str;
for(ptr = str->str; *ptr; ptr++) { for(ptr = str->str; *ptr; ptr++) {
if(is_uri_unescaped(*ptr) || is_uri_reserved(*ptr) || *ptr == '#') { if(is_uri_unescaped(*ptr) || is_uri_reserved(*ptr) || *ptr == '#') {
...@@ -826,9 +823,10 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -826,9 +823,10 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r) jsval_t *r)
{ {
jsstr_t *str, *ret; jsstr_t *str, *ret_str;
WCHAR *ptr; unsigned len = 0;
int i, len = 0, val, res; WCHAR *ptr, *ret;
int i, val, res;
char buf[4]; char buf[4];
WCHAR out; WCHAR out;
HRESULT hres; HRESULT hres;
...@@ -871,17 +869,15 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -871,17 +869,15 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
} }
} }
ret = jsstr_alloc_buf(len); ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
len = 0;
for(ptr = str->str; *ptr; ptr++) { for(ptr = str->str; *ptr; ptr++) {
if(*ptr != '%') { if(*ptr != '%') {
ret->str[len] = *ptr; *ret++ = *ptr;
len++;
}else { }else {
for(i=0; i<4; i++) { for(i=0; i<4; i++) {
if(ptr[i*3]!='%' || hex_to_int(ptr[i*3+1])==-1 || (val=hex_to_int(ptr[i*3+2]))==-1) if(ptr[i*3]!='%' || hex_to_int(ptr[i*3+1])==-1 || (val=hex_to_int(ptr[i*3+2]))==-1)
...@@ -889,33 +885,34 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -889,33 +885,34 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
val += hex_to_int(ptr[i*3+1])<<4; val += hex_to_int(ptr[i*3+1])<<4;
buf[i] = val; buf[i] = val;
res = MultiByteToWideChar(CP_UTF8, 0, buf, i+1, ret->str+len, 1); res = MultiByteToWideChar(CP_UTF8, 0, buf, i+1, ret, 1);
if(res) if(res)
break; break;
} }
ptr += i*3+2; ptr += i*3+2;
len++; ret++;
} }
} }
TRACE("%s -> %s\n", debugstr_jsstr(str), debugstr_jsstr(ret)); TRACE("%s -> %s\n", debugstr_jsstr(str), debugstr_jsstr(ret_str));
jsstr_release(str); jsstr_release(str);
if(r) if(r)
*r = jsval_string(ret); *r = jsval_string(ret_str);
else else
jsstr_release(ret); jsstr_release(ret_str);
return S_OK; return S_OK;
} }
static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r) jsval_t *r)
{ {
jsstr_t *str, *ret; jsstr_t *str, *ret_str;
char buf[4]; char buf[4];
const WCHAR *ptr; const WCHAR *ptr;
DWORD len = 0, size, i; DWORD len = 0, size, i;
WCHAR *ret;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
...@@ -943,22 +940,21 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W ...@@ -943,22 +940,21 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
} }
} }
ret = jsstr_alloc_buf(len); ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
len = 0;
for(ptr = str->str; *ptr; ptr++) { for(ptr = str->str; *ptr; ptr++) {
if(is_uri_unescaped(*ptr)) { if(is_uri_unescaped(*ptr)) {
ret->str[len++] = *ptr; *ret++ = *ptr;
}else { }else {
size = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, buf, sizeof(buf), NULL, NULL); size = WideCharToMultiByte(CP_UTF8, 0, ptr, 1, buf, sizeof(buf), NULL, NULL);
for(i=0; i<size; i++) { for(i=0; i<size; i++) {
ret->str[len++] = '%'; *ret++ = '%';
ret->str[len++] = int_to_char((BYTE)buf[i] >> 4); *ret++ = int_to_char((BYTE)buf[i] >> 4);
ret->str[len++] = int_to_char(buf[i] & 0x0f); *ret++ = int_to_char(buf[i] & 0x0f);
} }
} }
} }
...@@ -966,9 +962,9 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W ...@@ -966,9 +962,9 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
jsstr_release(str); jsstr_release(str);
if(r) if(r)
*r = jsval_string(ret); *r = jsval_string(ret_str);
else else
jsstr_release(ret); jsstr_release(ret_str);
return S_OK; return S_OK;
} }
...@@ -1044,12 +1040,11 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W ...@@ -1044,12 +1040,11 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
} }
} }
ret = jsstr_alloc_buf(len); out_ptr = jsstr_alloc_buf(len, &ret);
if(!ret) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
out_ptr = ret->str;
ptr = str->str; ptr = str->str;
while(*ptr) { while(*ptr) {
......
...@@ -25,7 +25,7 @@ const char *debugstr_jsstr(jsstr_t *str) ...@@ -25,7 +25,7 @@ const char *debugstr_jsstr(jsstr_t *str)
return debugstr_wn(str->str, jsstr_length(str)); return debugstr_wn(str->str, jsstr_length(str));
} }
jsstr_t *jsstr_alloc_buf(unsigned len) WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r)
{ {
jsstr_t *ret; jsstr_t *ret;
...@@ -39,16 +39,18 @@ jsstr_t *jsstr_alloc_buf(unsigned len) ...@@ -39,16 +39,18 @@ jsstr_t *jsstr_alloc_buf(unsigned len)
ret->length_flags = len << JSSTR_LENGTH_SHIFT; ret->length_flags = len << JSSTR_LENGTH_SHIFT;
ret->ref = 1; ret->ref = 1;
ret->str[len] = 0; ret->str[len] = 0;
return ret; *r = ret;
return ret->str;
} }
jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len) jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
{ {
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr;
ret = jsstr_alloc_buf(len); ptr = jsstr_alloc_buf(len, &ret);
if(ret) if(ptr)
memcpy(ret->str, buf, len*sizeof(WCHAR)); memcpy(ptr, buf, len*sizeof(WCHAR));
return ret; return ret;
} }
...@@ -70,6 +72,7 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2) ...@@ -70,6 +72,7 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2)
{ {
unsigned len1, len2; unsigned len1, len2;
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr;
len1 = jsstr_length(str1); len1 = jsstr_length(str1);
if(!len1) if(!len1)
...@@ -79,12 +82,12 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2) ...@@ -79,12 +82,12 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2)
if(!len2) if(!len2)
return jsstr_addref(str1); return jsstr_addref(str1);
ret = jsstr_alloc_buf(len1+len2); ptr = jsstr_alloc_buf(len1+len2, &ret);
if(!ret) if(!ret)
return NULL; return NULL;
jsstr_flush(str1, ret->str); jsstr_flush(str1, ptr);
jsstr_flush(str2, ret->str+len1); jsstr_flush(str2, ptr+len1);
return ret; return ret;
} }
...@@ -110,7 +113,7 @@ BOOL init_strings(void) ...@@ -110,7 +113,7 @@ BOOL init_strings(void)
static const WCHAR NaNW[] = { 'N','a','N',0 }; static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
if(!(empty_str = jsstr_alloc_buf(0))) if(!jsstr_alloc_buf(0, &empty_str))
return FALSE; return FALSE;
if(!(nan_str = jsstr_alloc(NaNW))) if(!(nan_str = jsstr_alloc(NaNW)))
return FALSE; return FALSE;
......
...@@ -34,7 +34,7 @@ static inline unsigned jsstr_length(jsstr_t *str) ...@@ -34,7 +34,7 @@ static inline unsigned jsstr_length(jsstr_t *str)
} }
jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN; jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN;
jsstr_t *jsstr_alloc_buf(unsigned) DECLSPEC_HIDDEN; WCHAR *jsstr_alloc_buf(unsigned,jsstr_t**) DECLSPEC_HIDDEN;
static inline jsstr_t *jsstr_alloc(const WCHAR *str) static inline jsstr_t *jsstr_alloc(const WCHAR *str)
{ {
......
...@@ -125,11 +125,10 @@ static inline jsstr_t *number_to_fixed(double val, int prec) ...@@ -125,11 +125,10 @@ static inline jsstr_t *number_to_fixed(double val, int prec)
if(prec) if(prec)
size += prec+1; size += prec+1;
ret = jsstr_alloc_buf(size); str = jsstr_alloc_buf(size, &ret);
if(!ret) if(!ret)
return NULL; return NULL;
str = ret->str;
size = buf_pos = 0; size = buf_pos = 0;
if(neg) if(neg)
str[size++] = '-'; str[size++] = '-';
...@@ -193,11 +192,10 @@ static inline jsstr_t *number_to_exponential(double val, int prec) ...@@ -193,11 +192,10 @@ static inline jsstr_t *number_to_exponential(double val, int prec)
if(neg) if(neg)
size++; size++;
ret = jsstr_alloc_buf(size); str = jsstr_alloc_buf(size, &ret);
if(!ret) if(!ret)
return NULL; return NULL;
str = ret->str;
size = 0; size = 0;
pbuf = buf; pbuf = buf;
if(neg) if(neg)
......
...@@ -71,12 +71,13 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u ...@@ -71,12 +71,13 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(r) { if(r) {
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr;
ret = jsstr_alloc_buf(9+strlenW(str)); ptr = jsstr_alloc_buf(9+strlenW(str), &ret);
if(!ret) if(!ptr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
sprintfW(ret->str, formatW, str); sprintfW(ptr, formatW, str);
*r = jsval_string(ret); *r = jsval_string(ret);
} }
......
...@@ -160,13 +160,12 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j ...@@ -160,13 +160,12 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j
tagname_len = strlenW(tagname); tagname_len = strlenW(tagname);
ret = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5); ptr = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5, &ret);
if(!ret) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
ptr = ret->str;
*ptr++ = '<'; *ptr++ = '<';
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR)); memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
ptr += tagname_len; ptr += tagname_len;
...@@ -209,11 +208,10 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig ...@@ -209,11 +208,10 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
unsigned attrname_len = strlenW(attrname); unsigned attrname_len = strlenW(attrname);
unsigned tagname_len = strlenW(tagname); unsigned tagname_len = strlenW(tagname);
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr;
ret = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9); ptr = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ret);
if(ret) { if(ptr) {
WCHAR *ptr = ret->str;
*ptr++ = '<'; *ptr++ = '<';
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR)); memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
ptr += tagname_len; ptr += tagname_len;
...@@ -390,9 +388,8 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns ...@@ -390,9 +388,8 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
} }
} }
ret = jsstr_alloc_buf(len); ptr = jsstr_alloc_buf(len, &ret);
if(ret) { if(ptr) {
ptr = ret->str;
for(i=0; i < str_cnt; i++) for(i=0; i < str_cnt; i++)
ptr += jsstr_flush(strs[i], ptr); ptr += jsstr_flush(strs[i], ptr);
}else { }else {
...@@ -1337,15 +1334,16 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -1337,15 +1334,16 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(r) { if(r) {
jsstr_t *ret; jsstr_t *ret;
WCHAR *buf;
ret = jsstr_alloc_buf(jsstr_length(str)); buf = jsstr_alloc_buf(jsstr_length(str), &ret);
if(!ret) { if(!buf) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
jsstr_flush(str, ret->str); jsstr_flush(str, buf);
strlwrW(ret->str); strlwrW(buf);
*r = jsval_string(ret); *r = jsval_string(ret);
} }
jsstr_release(str); jsstr_release(str);
...@@ -1366,15 +1364,16 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags ...@@ -1366,15 +1364,16 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
if(r) { if(r) {
jsstr_t *ret; jsstr_t *ret;
WCHAR *buf;
ret = jsstr_alloc_buf(jsstr_length(str)); buf = jsstr_alloc_buf(jsstr_length(str), &ret);
if(!ret) { if(!buf) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
jsstr_flush(str, ret->str); jsstr_flush(str, buf);
struprW(ret->str); struprW(buf);
*r = jsval_string(ret); *r = jsval_string(ret);
} }
jsstr_release(str); jsstr_release(str);
...@@ -1525,14 +1524,15 @@ static const builtin_info_t StringInst_info = { ...@@ -1525,14 +1524,15 @@ static const builtin_info_t StringInst_info = {
static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, jsval_t *argv, jsval_t *r) unsigned argc, jsval_t *argv, jsval_t *r)
{ {
WCHAR *ret_str;
DWORD i, code; DWORD i, code;
jsstr_t *ret; jsstr_t *ret;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
ret = jsstr_alloc_buf(argc); ret_str = jsstr_alloc_buf(argc, &ret);
if(!ret) if(!ret_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
for(i=0; i<argc; i++) { for(i=0; i<argc; i++) {
...@@ -1542,7 +1542,7 @@ static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WOR ...@@ -1542,7 +1542,7 @@ static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WOR
return hres; return hres;
} }
ret->str[i] = code; ret_str[i] = code;
} }
if(r) if(r)
......
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