[JSCRIPT] Sync with Wine Staging 1.9.23. Dedicated to Ged. CORE-12409

7af3f65 jscript: Add more jsdisp_t to Instance helpers.
55f6e3c jscript: Use the existing helpers to get from a jsdisp_t to an Instance.
0f21353 jscript: Use wine_rb_tree to store local variables in compiler_ctx_t.
fc1ae4f jscript: Use CONTAINING_RECORD() to get from a field to a struct.
57291c4 jscript: Simplify create_utc_string and add basic tests.
20d5bba jscript: Simplify date_to_string and add basic tests.
4d67ffd jscript: Allocate string of correct size in Date toLocaleDateString method.
79f18d0 jscript: Properly handle \0 characters in Array join method.
fd07a15 jscript: Allocate string of correct size in Date toTimeString method.
1c3e0dd jscript: Properly handle \0 characters in String indexOf method.
54e6736 jscript: Properly handle \0 characters in String to{Lower,Upper}Case methods.
1842082 jscript: Do not include terminating \0 in result returned by Date_toLocale{Date,Time}String.
69437af jscript: Change prototype of jsstr_alloc_buf and fix some error handling issues.
d36ae56 jscript: Fix definition of JSSTR_MAX_LENGTH.
7369836 jscript: Simplify jsstr_release implementation.

svn path=/trunk/; revision=73354
This commit is contained in:
Amine Khaldi 2016-11-23 10:06:56 +00:00
parent e98102ef8a
commit a7a057e3a2
15 changed files with 205 additions and 240 deletions

View file

@ -93,7 +93,7 @@ static HRESULT get_length(script_ctx_t *ctx, vdisp_t *vdisp, jsdisp_t **jsthis,
static HRESULT set_length(jsdisp_t *obj, DWORD length)
{
if(is_class(obj, JSCLASS_ARRAY)) {
((ArrayInstance*)obj)->length = length;
array_from_jsdisp(obj)->length = length;
return S_OK;
}
@ -181,7 +181,7 @@ static HRESULT concat_obj(jsdisp_t *array, IDispatch *obj, DWORD *len)
jsobj = iface_to_jsdisp(obj);
if(jsobj) {
if(is_class(jsobj, JSCLASS_ARRAY)) {
hres = concat_array(array, (ArrayInstance*)jsobj, len);
hres = concat_array(array, array_from_jsdisp(jsobj), len);
jsdisp_release(jsobj);
return hres;
}
@ -228,9 +228,10 @@ static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
return S_OK;
}
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,
unsigned seplen, jsval_t *r)
{
jsstr_t **str_tab, *ret;
jsstr_t **str_tab, *ret = NULL;
jsval_t val;
DWORD i;
HRESULT hres = E_FAIL;
@ -262,9 +263,7 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
}
if(SUCCEEDED(hres)) {
DWORD seplen = 0, len = 0;
seplen = strlenW(sep);
DWORD len = 0;
if(str_tab[0])
len = jsstr_length(str_tab[0]);
@ -281,8 +280,8 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
if(SUCCEEDED(hres)) {
WCHAR *ptr = NULL;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr) {
ret = jsstr_alloc_buf(len, &ptr);
if(ret) {
if(str_tab[0])
ptr += jsstr_flush(str_tab[0], ptr);
@ -340,11 +339,11 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
hres = array_join(ctx, jsthis, length, sep, r);
hres = array_join(ctx, jsthis, length, sep, jsstr_length(sep_str), r);
jsstr_release(sep_str);
}else {
hres = array_join(ctx, jsthis, length, default_separatorW, r);
hres = array_join(ctx, jsthis, length, default_separatorW, strlenW(default_separatorW), r);
}
return hres;
@ -928,7 +927,8 @@ static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(!array)
return throw_type_error(ctx, JS_E_ARRAY_EXPECTED, NULL);
return array_join(ctx, &array->dispex, array->length, default_separatorW, r);
return array_join(ctx, &array->dispex, array->length, default_separatorW,
strlenW(default_separatorW), r);
}
static HRESULT Array_toLocaleString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv,
@ -1004,7 +1004,8 @@ static HRESULT Array_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
TRACE("\n");
return array_join(ctx, &array->dispex, array->length, default_separatorW, r);
return array_join(ctx, &array->dispex, array->length, default_separatorW,
strlenW(default_separatorW), r);
}
static void Array_destructor(jsdisp_t *dispex)
@ -1014,7 +1015,7 @@ static void Array_destructor(jsdisp_t *dispex)
static void Array_on_put(jsdisp_t *dispex, const WCHAR *name)
{
ArrayInstance *array = (ArrayInstance*)dispex;
ArrayInstance *array = array_from_jsdisp(dispex);
const WCHAR *ptr = name;
DWORD id = 0;

View file

@ -28,15 +28,25 @@ typedef struct {
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
static inline BoolInstance *bool_from_jsdisp(jsdisp_t *jsdisp)
{
return CONTAINING_RECORD(jsdisp, BoolInstance, dispex);
}
static inline BoolInstance *bool_from_vdisp(vdisp_t *vdisp)
{
return bool_from_jsdisp(vdisp->u.jsdisp);
}
static inline BoolInstance *bool_this(vdisp_t *jsthis)
{
return is_vclass(jsthis, JSCLASS_BOOLEAN) ? (BoolInstance*)jsthis->u.jsdisp : NULL;
return is_vclass(jsthis, JSCLASS_BOOLEAN) ? bool_from_vdisp(jsthis) : NULL;
}
BOOL bool_obj_value(jsdisp_t *obj)
{
assert(is_class(obj, JSCLASS_BOOLEAN));
return ((BoolInstance*)obj)->val;
return bool_from_jsdisp(obj)->val;
}
/* ECMA-262 3rd Edition 15.6.4.2 */

View file

@ -18,6 +18,8 @@
#include "jscript.h"
#include <wine/rbtree.h>
WINE_DECLARE_DEBUG_CHANNEL(jscript_disas);
typedef struct _statement_ctx_t {
@ -33,6 +35,12 @@ typedef struct _statement_ctx_t {
struct _statement_ctx_t *next;
} statement_ctx_t;
typedef struct {
struct wine_rb_entry entry;
BSTR name;
int ref;
} function_local_t;
typedef struct {
parser_ctx_t *parser;
bytecode_t *code;
@ -46,8 +54,7 @@ typedef struct {
unsigned labels_size;
unsigned labels_cnt;
local_ref_t *locals_buf;
unsigned locals_buf_size;
struct wine_rb_tree locals;
unsigned locals_cnt;
statement_ctx_t *stat_ctx;
@ -55,6 +62,8 @@ typedef struct {
function_expression_t *func_head;
function_expression_t *func_tail;
heap_pool_t heap;
} compiler_ctx_t;
static const struct {
@ -1804,42 +1813,29 @@ static HRESULT compile_statement(compiler_ctx_t *ctx, statement_ctx_t *stat_ctx,
return hres;
}
static int local_cmp(const void *key, const void *ref)
static int function_local_cmp(const void *key, const struct wine_rb_entry *entry)
{
return strcmpW((const WCHAR*)key, ((const local_ref_t*)ref)->name);
function_local_t *local = WINE_RB_ENTRY_VALUE(entry, function_local_t, entry);
return strcmpW(key, local->name);
}
static inline local_ref_t *find_local(compiler_ctx_t *ctx, const WCHAR *name)
static inline function_local_t *find_local(compiler_ctx_t *ctx, const WCHAR *name)
{
return bsearch(name, ctx->locals_buf, ctx->locals_cnt, sizeof(*ctx->locals_buf), local_cmp);
struct wine_rb_entry *entry = wine_rb_get(&ctx->locals, name);
return entry ? WINE_RB_ENTRY_VALUE(entry, function_local_t, entry) : NULL;
}
static BOOL alloc_local(compiler_ctx_t *ctx, BSTR name, int ref)
{
unsigned i;
function_local_t *local;
if(!ctx->locals_buf_size) {
ctx->locals_buf = heap_alloc(4 * sizeof(*ctx->locals_buf));
if(!ctx->locals_buf)
return FALSE;
ctx->locals_buf_size = 4;
}else if(ctx->locals_buf_size == ctx->locals_cnt) {
local_ref_t *new_buf = heap_realloc(ctx->locals_buf, ctx->locals_buf_size * 2 * sizeof(*ctx->locals_buf));
if(!new_buf)
return FALSE;
ctx->locals_buf = new_buf;
ctx->locals_buf_size *= 2;
}
local = heap_pool_alloc(&ctx->heap, sizeof(*local));
if(!local)
return FALSE;
for(i = 0; i < ctx->locals_cnt; i++) {
if(strcmpW(ctx->locals_buf[i].name, name) > 0) {
memmove(ctx->locals_buf + i+1, ctx->locals_buf + i, (ctx->locals_cnt - i) * sizeof(*ctx->locals_buf));
break;
}
}
ctx->locals_buf[i].name = name;
ctx->locals_buf[i].ref = ref;
local->name = name;
local->ref = ref;
wine_rb_put(&ctx->locals, name, &local->entry);
ctx->locals_cnt++;
return TRUE;
}
@ -2256,7 +2252,8 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
BOOL from_eval, function_code_t *func)
{
function_expression_t *iter;
unsigned off, i, j;
function_local_t *local;
unsigned off, i;
HRESULT hres;
TRACE("\n");
@ -2265,6 +2262,7 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
ctx->from_eval = from_eval;
ctx->func = func;
ctx->locals_cnt = 0;
wine_rb_init(&ctx->locals, function_local_cmp);
if(func_expr) {
parameter_t *param_iter;
@ -2311,21 +2309,22 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
if(!func->locals)
return E_OUTOFMEMORY;
func->locals_cnt = ctx->locals_cnt;
memcpy(func->locals, ctx->locals_buf, func->locals_cnt * sizeof(*func->locals));
func->variables = compiler_alloc(ctx->code, func->var_cnt * sizeof(*func->variables));
if(!func->variables)
return E_OUTOFMEMORY;
for(i = 0, j = 0; i < func->locals_cnt; i++) {
if(func->locals[i].ref < 0)
continue; /* skip arguments */
func->variables[func->locals[i].ref].name = func->locals[i].name;
func->variables[func->locals[i].ref].func_id = -1;
j++;
i = 0;
WINE_RB_FOR_EACH_ENTRY(local, &ctx->locals, function_local_t, entry) {
func->locals[i].name = local->name;
func->locals[i].ref = local->ref;
if(local->ref >= 0) {
func->variables[local->ref].name = local->name;
func->variables[local->ref].func_id = -1;
}
i++;
}
assert(j == func->var_cnt);
assert(i == ctx->locals_cnt);
func->funcs = compiler_alloc(ctx->code, func->func_cnt * sizeof(*func->funcs));
if(!func->funcs)
@ -2468,9 +2467,10 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *args,
return hres;
}
heap_pool_init(&compiler.heap);
hres = compile_function(&compiler, compiler.parser->source, NULL, from_eval, &compiler.code->global_code);
heap_pool_free(&compiler.heap);
parser_release(compiler.parser);
heap_free(compiler.locals_buf);
if(FAILED(hres)) {
release_bytecode(compiler.code);
return hres;

View file

@ -483,8 +483,9 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
BOOL formatAD = TRUE;
WCHAR week[64], month[64];
WCHAR buf[192];
jsstr_t *date_jsstr;
int len, size, year, day;
int year, day;
DWORD lcid_en;
WCHAR sign = '-';
@ -495,66 +496,45 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
}
if(r) {
WCHAR *date_str;
len = 21;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
size = GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, sizeof(week)/sizeof(*week));
assert(size);
len += size-1;
week[0] = 0;
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, sizeof(week)/sizeof(*week));
size = GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, sizeof(month)/sizeof(*month));
len += size-1;
year = year_from_time(time);
if(year<0)
year = -year+1;
do {
year /= 10;
len++;
} while(year);
month[0] = 0;
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, sizeof(month)/sizeof(*month));
year = year_from_time(time);
if(year<0) {
formatAD = FALSE;
year = -year+1;
len += 5;
}
day = date_from_time(time);
do {
day /= 10;
len++;
} while(day);
day = date_from_time(time);
if(!show_offset) len -= 9;
else if(offset == 0) len -= 5;
else if(offset < 0) {
if(offset < 0) {
sign = '+';
offset = -offset;
}
date_str = jsstr_alloc_buf(len, &date_jsstr);
if(!date_str)
return E_OUTOFMEMORY;
if(!show_offset)
sprintfW(date_str, formatNoOffsetW, week, month, day,
sprintfW(buf, formatNoOffsetW, week, month, day,
(int)hour_from_time(time), (int)min_from_time(time),
(int)sec_from_time(time), year, formatAD?ADW:BCW);
else if(offset)
sprintfW(date_str, formatW, week, month, day,
sprintfW(buf, formatW, week, month, day,
(int)hour_from_time(time), (int)min_from_time(time),
(int)sec_from_time(time), sign, offset/60, offset%60,
year, formatAD?ADW:BCW);
else
sprintfW(date_str, formatUTCW, week, month, day,
sprintfW(buf, formatUTCW, week, month, day,
(int)hour_from_time(time), (int)min_from_time(time),
(int)sec_from_time(time), year, formatAD?ADW:BCW);
date_jsstr = jsstr_alloc(buf);
if(!date_jsstr)
return E_OUTOFMEMORY;
*r = jsval_string(date_jsstr);
}
return S_OK;
@ -616,7 +596,7 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(date_len+time_len-1, &date_str);
date_str = jsstr_alloc_buf(date_len+time_len-1, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
@ -663,9 +643,10 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
BOOL formatAD = TRUE;
WCHAR week[64], month[64];
WCHAR buf[192];
DateInstance *date;
jsstr_t *date_str;
int len, size, year, day;
int year, day;
DWORD lcid_en;
if(!(date = date_this(jsthis)))
@ -678,48 +659,30 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
}
if(r) {
WCHAR *ptr;
len = 17;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
size = GetLocaleInfoW(lcid_en, week_ids[(int)week_day(date->time)], week, sizeof(week)/sizeof(*week));
len += size-1;
week[0] = 0;
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(date->time)], week, sizeof(week)/sizeof(*week));
size = GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(date->time)], month, sizeof(month)/sizeof(*month));
len += size-1;
year = year_from_time(date->time);
if(year<0)
year = -year+1;
do {
year /= 10;
len++;
} while(year);
month[0] = 0;
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(date->time)], month, sizeof(month)/sizeof(*month));
year = year_from_time(date->time);
if(year<0) {
formatAD = FALSE;
year = -year+1;
len += 5;
}
day = date_from_time(date->time);
do {
day /= 10;
len++;
} while(day);
day = date_from_time(date->time);
ptr = jsstr_alloc_buf(len, &date_str);
if(!date_str)
return E_OUTOFMEMORY;
sprintfW(ptr, formatAD?formatADW:formatBCW, week, day, month, year,
sprintfW(buf, formatAD ? formatADW : formatBCW, week, day, month, year,
(int)hour_from_time(date->time), (int)min_from_time(date->time),
(int)sec_from_time(date->time));
date_str = jsstr_alloc(buf);
if(!date_str)
return E_OUTOFMEMORY;
*r = jsval_string(date_str);
}
return S_OK;
@ -758,9 +721,10 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
BOOL formatAD = TRUE;
WCHAR week[64], month[64];
WCHAR buf[192];
jsstr_t *date_str;
DOUBLE time;
int len, size, year, day;
int year, day;
DWORD lcid_en;
if(isnan(date->time)) {
@ -772,46 +736,27 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
time = local_time(date->time, date);
if(r) {
WCHAR *ptr;
len = 5;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
size = GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, sizeof(week)/sizeof(*week));
assert(size);
len += size-1;
week[0] = 0;
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, sizeof(week)/sizeof(*week));
size = GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, sizeof(month)/sizeof(*month));
assert(size);
len += size-1;
year = year_from_time(time);
if(year<0)
year = -year+1;
do {
year /= 10;
len++;
} while(year);
month[0] = 0;
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, sizeof(month)/sizeof(*month));
year = year_from_time(time);
if(year<0) {
formatAD = FALSE;
year = -year+1;
len += 5;
}
day = date_from_time(time);
do {
day /= 10;
len++;
} while(day);
day = date_from_time(time);
ptr = jsstr_alloc_buf(len, &date_str);
if(!ptr)
sprintfW(buf, formatAD ? formatADW : formatBCW, week, month, day, year);
date_str = jsstr_alloc(buf);
if(!date_str)
return E_OUTOFMEMORY;
sprintfW(ptr, formatAD?formatADW:formatBCW, week, month, day, year);
*r = jsval_string(date_str);
}
@ -839,6 +784,7 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
':','%','0','2','d',' ','U','T','C',0 };
DateInstance *date;
jsstr_t *date_str;
WCHAR buf[32];
DOUBLE time;
WCHAR sign;
int offset;
@ -857,12 +803,6 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
time = local_time(date->time, date);
if(r) {
WCHAR *ptr;
ptr = jsstr_alloc_buf(17, &date_str);
if(!date_str)
return E_OUTOFMEMORY;
offset = date->bias +
daylight_saving_ta(time, date);
@ -873,13 +813,17 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
else sign = '-';
if(offset)
sprintfW(ptr, formatW, (int)hour_from_time(time),
sprintfW(buf, formatW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time),
sign, offset/60, offset%60);
else
sprintfW(ptr, formatUTCW, (int)hour_from_time(time),
sprintfW(buf, formatUTCW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time));
date_str = jsstr_alloc(buf);
if(!date_str)
return E_OUTOFMEMORY;
*r = jsval_string(date_str);
}
return S_OK;
@ -914,8 +858,8 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
WCHAR *ptr;
len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(len, &date_str);
if(!ptr)
date_str = jsstr_alloc_buf(len-1, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, len);
@ -953,8 +897,8 @@ static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
WCHAR *ptr;
len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(len, &date_str);
if(!ptr)
date_str = jsstr_alloc_buf(len-1, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr, len);
@ -2469,7 +2413,7 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(FAILED(hres))
return hres;
di = (DateInstance*)date;
di = date_from_jsdisp(date);
di->time = utc(di->time, di);
}
}

View file

@ -76,8 +76,8 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(name_len && msg_len) {
WCHAR *ptr;
ptr = jsstr_alloc_buf(name_len + msg_len + 2, &ret);
if(ptr) {
ret = jsstr_alloc_buf(name_len + msg_len + 2, &ptr);
if(ret) {
jsstr_flush(name, ptr);
ptr[name_len] = ':';
ptr[name_len+1] = ' ';

View file

@ -74,7 +74,7 @@ static HRESULT Arguments_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
static void Arguments_destructor(jsdisp_t *jsdisp)
{
ArgumentsInstance *arguments = (ArgumentsInstance*)jsdisp;
ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
TRACE("(%p)\n", arguments);
@ -91,7 +91,7 @@ static void Arguments_destructor(jsdisp_t *jsdisp)
static unsigned Arguments_idx_length(jsdisp_t *jsdisp)
{
ArgumentsInstance *arguments = (ArgumentsInstance*)jsdisp;
ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
return arguments->argc;
}
@ -106,7 +106,7 @@ static jsval_t *get_argument_ref(ArgumentsInstance *arguments, unsigned idx)
static HRESULT Arguments_idx_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
{
ArgumentsInstance *arguments = (ArgumentsInstance*)jsdisp;
ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
jsval_t *ref;
TRACE("%p[%u]\n", arguments, idx);
@ -120,7 +120,7 @@ static HRESULT Arguments_idx_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
static HRESULT Arguments_idx_put(jsdisp_t *jsdisp, unsigned idx, jsval_t val)
{
ArgumentsInstance *arguments = (ArgumentsInstance*)jsdisp;
ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
jsval_t *ref;
HRESULT hres;
@ -295,8 +295,8 @@ static HRESULT function_to_string(FunctionInstance *function, jsstr_t **ret)
WCHAR *ptr;
name_len = strlenW(function->name);
ptr = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &str);
if(!ptr)
str = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &ptr);
if(!str)
return E_OUTOFMEMORY;
memcpy(ptr, native_prefixW, sizeof(native_prefixW));
@ -320,7 +320,7 @@ HRESULT Function_invoke(jsdisp_t *func_this, IDispatch *jsthis, WORD flags, unsi
TRACE("func %p this %p\n", func_this, jsthis);
assert(is_class(func_this, JSCLASS_FUNCTION));
function = (FunctionInstance*)func_this;
function = function_from_jsdisp(func_this);
flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
if(function->value_proc)
@ -523,7 +523,7 @@ HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned
return E_FAIL;
}
function = (FunctionInstance*)jsthis->u.jsdisp;
function = function_from_jsdisp(jsthis->u.jsdisp);
assert(function->value_proc != NULL);
return invoke_value_proc(ctx, function, NULL, flags, argc, argv, r);
@ -570,7 +570,7 @@ static HRESULT Function_get_arguments(script_ctx_t *ctx, jsdisp_t *jsthis, jsval
static void Function_destructor(jsdisp_t *dispex)
{
FunctionInstance *This = (FunctionInstance*)dispex;
FunctionInstance *This = function_from_jsdisp(dispex);
if(This->code)
release_bytecode(This->code);

View file

@ -140,8 +140,8 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
len += 3;
}
ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
@ -500,8 +500,8 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
len++;
}
ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
@ -639,8 +639,8 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
}
}
rptr = jsstr_alloc_buf(len, &ret);
if(!rptr) {
ret = jsstr_alloc_buf(len, &rptr);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
@ -718,8 +718,8 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
}
}
ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
@ -789,8 +789,8 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
}
}
ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
@ -889,7 +889,7 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
}
}
out_ptr = jsstr_alloc_buf(len, &ret);
ret = jsstr_alloc_buf(len, &out_ptr);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;

View file

@ -118,7 +118,7 @@ static HRESULT do_regexp_match_next(script_ctx_t *ctx, RegExpInstance *regexp,
HRESULT regexp_match_next(script_ctx_t *ctx, jsdisp_t *dispex,
DWORD rem_flags, jsstr_t *jsstr, match_state_t **ret)
{
RegExpInstance *regexp = (RegExpInstance*)dispex;
RegExpInstance *regexp = regexp_from_jsdisp(dispex);
match_state_t *match;
heap_pool_t *mark;
const WCHAR *str;
@ -175,7 +175,7 @@ HRESULT regexp_match_next(script_ctx_t *ctx, jsdisp_t *dispex,
static HRESULT regexp_match(script_ctx_t *ctx, jsdisp_t *dispex, jsstr_t *jsstr, BOOL gflag,
match_result_t **match_result, DWORD *result_cnt)
{
RegExpInstance *This = (RegExpInstance*)dispex;
RegExpInstance *This = regexp_from_jsdisp(dispex);
match_result_t *ret = NULL;
match_state_t *result;
DWORD i=0, ret_size = 0;
@ -367,8 +367,8 @@ static HRESULT RegExp_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(f & REG_MULTILINE)
len++;
ptr = jsstr_alloc_buf(len, &ret);
if(!ptr)
ret = jsstr_alloc_buf(len, &ptr);
if(!ret)
return E_OUTOFMEMORY;
*ptr++ = '/';
@ -589,7 +589,7 @@ static HRESULT RegExp_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
static void RegExp_destructor(jsdisp_t *dispex)
{
RegExpInstance *This = (RegExpInstance*)dispex;
RegExpInstance *This = regexp_from_jsdisp(dispex);
if(This->jsregexp)
regexp_destroy(This->jsregexp);
@ -701,7 +701,7 @@ HRESULT create_regexp_var(script_ctx_t *ctx, jsval_t src_arg, jsval_t *flags_arg
obj = iface_to_jsdisp(get_object(src_arg));
if(obj) {
if(is_class(obj, JSCLASS_REGEXP)) {
RegExpInstance *regexp = (RegExpInstance*)obj;
RegExpInstance *regexp = regexp_from_jsdisp(obj);
hres = create_regexp(ctx, regexp->str, regexp->jsregexp->flags, ret);
jsdisp_release(obj);
@ -747,7 +747,7 @@ HRESULT regexp_string_match(script_ctx_t *ctx, jsdisp_t *re, jsstr_t *jsstr, jsv
static const WCHAR inputW[] = {'i','n','p','u','t',0};
static const WCHAR lastIndexW[] = {'l','a','s','t','I','n','d','e','x',0};
RegExpInstance *regexp = (RegExpInstance*)re;
RegExpInstance *regexp = regexp_from_jsdisp(re);
match_result_t *match_result;
unsigned match_cnt, i;
const WCHAR *str;

View file

@ -62,7 +62,7 @@ static inline void jsstr_init(jsstr_t *str, unsigned len, jsstr_tag_t tag)
str->ref = 1;
}
WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r)
jsstr_t *jsstr_alloc_buf(unsigned len, WCHAR **buf)
{
jsstr_inline_t *ret;
@ -75,8 +75,8 @@ WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r)
jsstr_init(&ret->str, len, JSSTR_INLINE);
ret->buf[len] = 0;
*r = &ret->str;
return ret->buf;
*buf = ret->buf;
return &ret->str;
}
jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
@ -84,8 +84,8 @@ jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr)
ret = jsstr_alloc_buf(len, &ptr);
if(ret)
memcpy(ptr, buf, len*sizeof(WCHAR));
return ret;
@ -243,7 +243,7 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2)
}
}
ptr = jsstr_alloc_buf(len1+len2, &ret);
ret = jsstr_alloc_buf(len1+len2, &ptr);
if(!ret)
return NULL;
@ -305,14 +305,15 @@ 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};
WCHAR *ptr;
if(!jsstr_alloc_buf(0, &empty_str))
if(!(empty_str = jsstr_alloc_buf(0, &ptr)))
return FALSE;
if(!(nan_str = jsstr_alloc(NaNW)))
return FALSE;
if(!(undefined_str = jsstr_alloc(undefinedW)))
return FALSE;
if(!jsstr_alloc_buf(0, &null_bstr_str))
if(!(null_bstr_str = jsstr_alloc_buf(0, &ptr)))
return FALSE;
return TRUE;
}

View file

@ -42,7 +42,7 @@ struct _jsstr_t {
};
#define JSSTR_LENGTH_SHIFT 4
#define JSSTR_MAX_LENGTH (1 << (32-JSSTR_LENGTH_SHIFT))
#define JSSTR_MAX_LENGTH ((1 << (32-JSSTR_LENGTH_SHIFT))-1)
#define JSSTR_FLAGS_MASK ((1 << JSSTR_LENGTH_SHIFT)-1)
#define JSSTR_FLAG_LBIT 1
@ -98,7 +98,7 @@ typedef struct {
} jsstr_rope_t;
jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN;
WCHAR *jsstr_alloc_buf(unsigned,jsstr_t**) DECLSPEC_HIDDEN;
jsstr_t *jsstr_alloc_buf(unsigned,WCHAR**) DECLSPEC_HIDDEN;
static inline jsstr_t *jsstr_alloc(const WCHAR *str)
{
@ -109,12 +109,8 @@ void jsstr_free(jsstr_t*) DECLSPEC_HIDDEN;
static inline void jsstr_release(jsstr_t *str)
{
if(!--str->ref) {
if(jsstr_is_inline(str))
heap_free(str);
else
jsstr_free(str);
}
if(!--str->ref)
jsstr_free(str);
}
static inline jsstr_t *jsstr_addref(jsstr_t *str)
@ -169,8 +165,8 @@ static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr)
ret = jsstr_alloc_buf(len, &ptr);
if(ret)
jsstr_extract(str, off, len, ptr);
return ret;
}

View file

@ -120,7 +120,7 @@ static inline jsstr_t *number_to_fixed(double val, int prec)
if(prec)
size += prec+1;
str = jsstr_alloc_buf(size, &ret);
ret = jsstr_alloc_buf(size, &str);
if(!ret)
return NULL;
@ -187,7 +187,7 @@ static inline jsstr_t *number_to_exponential(double val, int prec)
if(neg)
size++;
str = jsstr_alloc_buf(size, &ret);
ret = jsstr_alloc_buf(size, &str);
if(!ret)
return NULL;

View file

@ -67,8 +67,8 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(9+strlenW(str), &ret);
if(!ptr)
ret = jsstr_alloc_buf(9+strlenW(str), &ptr);
if(!ret)
return E_OUTOFMEMORY;
sprintfW(ptr, formatW, str);

View file

@ -103,7 +103,7 @@ static HRESULT get_string_flat_val(script_ctx_t *ctx, vdisp_t *jsthis, jsstr_t *
static HRESULT String_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
{
StringInstance *string = (StringInstance*)jsthis;
StringInstance *string = string_from_jsdisp(jsthis);
TRACE("%p\n", jsthis);
@ -167,7 +167,7 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j
tagname_len = strlenW(tagname);
ptr = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5, &ret);
ret = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5, &ptr);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;
@ -217,8 +217,8 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ret);
if(ptr) {
ret = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ptr);
if(ret) {
*ptr++ = '<';
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
ptr += tagname_len;
@ -368,7 +368,7 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
jsstr_t *ret, *str;
jsstr_t *ret = NULL, *str;
HRESULT hres;
TRACE("\n");
@ -425,8 +425,8 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
if(SUCCEEDED(hres)) {
ptr = jsstr_alloc_buf(len, &ret);
if(ptr) {
ret = jsstr_alloc_buf(len, &ptr);
if(ret) {
for(i=0; i < str_cnt; i++)
ptr += jsstr_flush(strs[i], ptr);
}else {
@ -478,9 +478,9 @@ static HRESULT String_fontsize(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
unsigned pos = 0, search_len, length;
jsstr_t *search_jsstr, *jsstr;
const WCHAR *search_str, *str;
int length, pos = 0;
INT ret = -1;
HRESULT hres;
@ -490,7 +490,6 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
if(FAILED(hres))
return hres;
length = jsstr_length(jsstr);
if(!argc) {
if(r)
*r = jsval_number(-1);
@ -504,6 +503,9 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
return hres;
}
search_len = jsstr_length(search_jsstr);
length = jsstr_length(jsstr);
if(argc >= 2) {
double d;
@ -512,14 +514,16 @@ static HRESULT String_indexOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un
pos = is_int32(d) ? min(length, d) : length;
}
if(SUCCEEDED(hres)) {
if(SUCCEEDED(hres) && length >= search_len) {
const WCHAR *end = str+length-search_len;
const WCHAR *ptr;
ptr = strstrW(str+pos, search_str);
if(ptr)
ret = ptr - str;
else
ret = -1;
for(ptr = str+pos; ptr <= end; ptr++) {
if(!memcmp(ptr, search_str, search_len*sizeof(WCHAR))) {
ret = ptr-str;
break;
}
}
}
jsstr_release(search_jsstr);
@ -1394,17 +1398,19 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return hres;
if(r) {
unsigned len = jsstr_length(str);
jsstr_t *ret;
WCHAR *buf;
buf = jsstr_alloc_buf(jsstr_length(str), &ret);
if(!buf) {
ret = jsstr_alloc_buf(len, &buf);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
jsstr_flush(str, buf);
strlwrW(buf);
for (; len--; buf++) *buf = tolowerW(*buf);
*r = jsval_string(ret);
}
jsstr_release(str);
@ -1424,17 +1430,19 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
return hres;
if(r) {
unsigned len = jsstr_length(str);
jsstr_t *ret;
WCHAR *buf;
buf = jsstr_alloc_buf(jsstr_length(str), &ret);
if(!buf) {
ret = jsstr_alloc_buf(len, &buf);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
jsstr_flush(str, buf);
struprW(buf);
for (; len--; buf++) *buf = toupperW(*buf);
*r = jsval_string(ret);
}
jsstr_release(str);
@ -1464,7 +1472,7 @@ static HRESULT String_localeCompare(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
static HRESULT String_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
{
StringInstance *This = (StringInstance*)jsthis;
StringInstance *This = string_from_jsdisp(jsthis);
TRACE("\n");
@ -1474,7 +1482,7 @@ static HRESULT String_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
static void String_destructor(jsdisp_t *dispex)
{
StringInstance *This = (StringInstance*)dispex;
StringInstance *This = string_from_jsdisp(dispex);
jsstr_release(This->str);
heap_free(This);
@ -1482,7 +1490,7 @@ static void String_destructor(jsdisp_t *dispex)
static unsigned String_idx_length(jsdisp_t *jsdisp)
{
StringInstance *string = (StringInstance*)jsdisp;
StringInstance *string = string_from_jsdisp(jsdisp);
/*
* NOTE: For invoke version < 2, indexed array is not implemented at all.
@ -1496,7 +1504,7 @@ static unsigned String_idx_length(jsdisp_t *jsdisp)
static HRESULT String_idx_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
{
StringInstance *string = (StringInstance*)jsdisp;
StringInstance *string = string_from_jsdisp(jsdisp);
jsstr_t *ret;
ret = jsstr_substr(string->str, idx, 1);
@ -1580,8 +1588,8 @@ static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WOR
TRACE("\n");
ret_str = jsstr_alloc_buf(argc, &ret);
if(!ret_str)
ret = jsstr_alloc_buf(argc, &ret_str);
if(!ret)
return E_OUTOFMEMORY;
for(i=0; i<argc; i++) {

View file

@ -30,9 +30,14 @@ static const WCHAR lboundW[] = {'l','b','o','u','n','d',0};
static const WCHAR toArrayW[] = {'t','o','A','r','r','a','y',0};
static const WCHAR uboundW[] = {'u','b','o','u','n','d',0};
static inline VBArrayInstance *vbarray_from_jsdisp(jsdisp_t *jsdisp)
{
return CONTAINING_RECORD(jsdisp, VBArrayInstance, dispex);
}
static inline VBArrayInstance *vbarray_from_vdisp(vdisp_t *vdisp)
{
return (VBArrayInstance*)vdisp->u.jsdisp;
return vbarray_from_jsdisp(vdisp->u.jsdisp);
}
static inline VBArrayInstance *vbarray_this(vdisp_t *jsthis)
@ -232,7 +237,7 @@ static HRESULT VBArray_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
static void VBArray_destructor(jsdisp_t *dispex)
{
VBArrayInstance *vbarray = (VBArrayInstance*)dispex;
VBArrayInstance *vbarray = vbarray_from_jsdisp(dispex);
SafeArrayDestroy(vbarray->safearray);
heap_free(vbarray);

View file

@ -85,7 +85,7 @@ reactos/dll/win32/inseng # Synced to WineStaging-1.9.23
reactos/dll/win32/iphlpapi # Out of sync
reactos/dll/win32/itircl # Synced to WineStaging-1.9.11
reactos/dll/win32/itss # Synced to WineStaging-1.9.11
reactos/dll/win32/jscript # Synced to WineStaging-1.9.16
reactos/dll/win32/jscript # Synced to WineStaging-1.9.23
reactos/dll/win32/jsproxy # Synced to WineStaging-1.9.11
reactos/dll/win32/loadperf # Synced to WineStaging-1.9.11
reactos/dll/win32/lz32 # Synced to WineStaging-1.9.11