jscript: Added Function.toString implementation for builtin functions.

This commit is contained in:
Jacek Caban 2009-09-17 01:04:44 +02:00 committed by Alexandre Julliard
parent 522d0bf973
commit d918a1890b
12 changed files with 63 additions and 18 deletions

View File

@ -1101,11 +1101,13 @@ HRESULT create_array_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Dis
ArrayInstance *array;
HRESULT hres;
static const WCHAR ArrayW[] = {'A','r','r','a','y',0};
hres = alloc_array(ctx, object_prototype, &array);
if(FAILED(hres))
return hres;
hres = create_builtin_function(ctx, ArrayConstr_value, NULL, PROPF_CONSTR, &array->dispex, ret);
hres = create_builtin_function(ctx, ArrayConstr_value, ArrayW, NULL, PROPF_CONSTR, &array->dispex, ret);
jsdisp_release(&array->dispex);
return hres;

View File

@ -179,11 +179,13 @@ HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Disp
BoolInstance *bool;
HRESULT hres;
static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
hres = alloc_bool(ctx, object_prototype, &bool);
if(FAILED(hres))
return hres;
hres = create_builtin_function(ctx, BoolConstr_value, NULL, PROPF_CONSTR, &bool->dispex, ret);
hres = create_builtin_function(ctx, BoolConstr_value, BooleanW, NULL, PROPF_CONSTR, &bool->dispex, ret);
jsdisp_release(&bool->dispex);
return hres;

View File

@ -2603,11 +2603,13 @@ HRESULT create_date_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Disp
DispatchEx *date;
HRESULT hres;
static const WCHAR DateW[] = {'D','a','t','e',0};
hres = create_date(ctx, object_prototype, 0.0, &date);
if(FAILED(hres))
return hres;
hres = create_builtin_function(ctx, DateConstr_value, &DateConstr_info, PROPF_CONSTR, date, ret);
hres = create_builtin_function(ctx, DateConstr_value, DateW, &DateConstr_info, PROPF_CONSTR, date, ret);
jsdisp_release(date);
return hres;

View File

@ -293,7 +293,8 @@ static HRESULT prop_get(DispatchEx *This, dispex_prop_t *prop, LCID lcid, DISPPA
case PROP_BUILTIN:
if(prop->u.p->flags & PROPF_METHOD) {
DispatchEx *obj;
hres = create_builtin_function(This->ctx, prop->u.p->invoke, NULL, prop->u.p->flags, NULL, &obj);
hres = create_builtin_function(This->ctx, prop->u.p->invoke, prop->u.p->name, NULL,
prop->u.p->flags, NULL, &obj);
if(FAILED(hres))
break;

View File

@ -374,7 +374,7 @@ HRESULT init_error_constr(script_ctx_t *ctx, DispatchEx *object_prototype)
hres = jsdisp_propput_name(&err->dispex, nameW, ctx->lcid, &v, NULL/*FIXME*/, NULL/*FIXME*/);
if(SUCCEEDED(hres))
hres = create_builtin_function(ctx, constr_val[i], NULL,
hres = create_builtin_function(ctx, constr_val[i], names[i], NULL,
PROPF_CONSTR, &err->dispex, constr_addr[i]);
jsdisp_release(&err->dispex);

View File

@ -26,6 +26,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(jscript);
typedef struct {
DispatchEx dispex;
builtin_invoke_t value_proc;
const WCHAR *name;
DWORD flags;
source_elements_t *source;
parameter_t *parameters;
@ -285,14 +286,26 @@ static HRESULT function_to_string(FunctionInstance *function, BSTR *ret)
{
BSTR str;
if(function->value_proc) {
FIXME("Builtin functions not implemented\n");
return E_NOTIMPL;
}
static const WCHAR native_prefixW[] = {'\n','f','u','n','c','t','i','o','n',' '};
static const WCHAR native_suffixW[] =
{'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
str = SysAllocStringLen(function->src_str, function->src_len);
if(!str)
return E_OUTOFMEMORY;
if(function->value_proc) {
DWORD name_len;
name_len = strlenW(function->name);
str = SysAllocStringLen(NULL, sizeof(native_prefixW) + name_len*sizeof(WCHAR) + sizeof(native_suffixW));
if(!str)
return E_OUTOFMEMORY;
memcpy(str, native_prefixW, sizeof(native_prefixW));
memcpy(str + sizeof(native_prefixW)/sizeof(WCHAR), function->name, name_len*sizeof(WCHAR));
memcpy(str + sizeof(native_prefixW)/sizeof(WCHAR) + name_len, native_suffixW, sizeof(native_suffixW));
}else {
str = SysAllocStringLen(function->src_str, function->src_len);
if(!str)
return E_OUTOFMEMORY;
}
*ret = str;
return S_OK;
@ -598,7 +611,7 @@ static HRESULT set_prototype(script_ctx_t *ctx, DispatchEx *dispex, DispatchEx *
return jsdisp_propput_name(dispex, prototypeW, ctx->lcid, &var, &jsexcept, NULL/*FIXME*/);
}
HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name,
const builtin_info_t *builtin_info, DWORD flags, DispatchEx *prototype, DispatchEx **ret)
{
FunctionInstance *function;
@ -615,6 +628,7 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
}
function->value_proc = value_proc;
function->name = name;
*ret = &function->dispex;
return S_OK;
@ -670,15 +684,19 @@ HRESULT init_function_constr(script_ctx_t *ctx, DispatchEx *object_prototype)
FunctionInstance *prot, *constr;
HRESULT hres;
static const WCHAR FunctionW[] = {'F','u','n','c','t','i','o','n',0};
hres = create_function(ctx, NULL, PROPF_CONSTR, TRUE, object_prototype, &prot);
if(FAILED(hres))
return hres;
prot->value_proc = FunctionProt_value;
prot->name = prototypeW;
hres = create_function(ctx, NULL, PROPF_CONSTR, TRUE, &prot->dispex, &constr);
if(SUCCEEDED(hres)) {
constr->value_proc = FunctionConstr_value;
constr->name = FunctionW;
hres = set_prototype(ctx, &constr->dispex, &prot->dispex);
if(FAILED(hres))
jsdisp_release(&constr->dispex);

View File

@ -144,7 +144,7 @@ HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceP
HRESULT jsdisp_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
HRESULT jsdisp_delete_idx(DispatchEx*,DWORD);
HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_info_t*,DWORD,
HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,const builtin_info_t*,DWORD,
DispatchEx*,DispatchEx**);
HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);

View File

@ -330,12 +330,14 @@ HRESULT create_number_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
NumberInstance *number;
HRESULT hres;
static const WCHAR NumberW[] = {'N','u','m','b','e','r',0};
hres = alloc_number(ctx, object_prototype, &number);
if(FAILED(hres))
return hres;
V_VT(&number->num) = VT_I4;
hres = create_builtin_function(ctx, NumberConstr_value, NULL, PROPF_CONSTR, &number->dispex, ret);
hres = create_builtin_function(ctx, NumberConstr_value, NumberW, NULL, PROPF_CONSTR, &number->dispex, ret);
jsdisp_release(&number->dispex);
return hres;

View File

@ -192,7 +192,9 @@ static HRESULT ObjectConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DIS
HRESULT create_object_constr(script_ctx_t *ctx, DispatchEx *object_prototype, DispatchEx **ret)
{
return create_builtin_function(ctx, ObjectConstr_value, NULL, PROPF_CONSTR,
static const WCHAR ObjectW[] = {'O','b','j','e','c','t',0};
return create_builtin_function(ctx, ObjectConstr_value, ObjectW, NULL, PROPF_CONSTR,
object_prototype, ret);
}

View File

@ -3845,11 +3845,13 @@ HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
RegExpInstance *regexp;
HRESULT hres;
static const WCHAR RegExpW[] = {'R','e','g','E','x','p',0};
hres = alloc_regexp(ctx, object_prototype, &regexp);
if(FAILED(hres))
return hres;
hres = create_builtin_function(ctx, RegExpConstr_value, NULL, PROPF_CONSTR, &regexp->dispex, ret);
hres = create_builtin_function(ctx, RegExpConstr_value, RegExpW, NULL, PROPF_CONSTR, &regexp->dispex, ret);
jsdisp_release(&regexp->dispex);
return hres;

View File

@ -1869,11 +1869,14 @@ HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
StringInstance *string;
HRESULT hres;
static const WCHAR StringW[] = {'S','t','r','i','n','g',0};
hres = string_alloc(ctx, object_prototype, &string);
if(FAILED(hres))
return hres;
hres = create_builtin_function(ctx, StringConstr_value, &StringConstr_info, PROPF_CONSTR, &string->dispex, ret);
hres = create_builtin_function(ctx, StringConstr_value, StringW, &StringConstr_info,
PROPF_CONSTR, &string->dispex, ret);
jsdisp_release(&string->dispex);
return hres;

View File

@ -1467,6 +1467,17 @@ ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
Math.SQRT1_2 = "test";
ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);
ok(isNaN.toString() === "\nfunction isNaN() {\n [native code]\n}\n",
"isNaN.toString = '" + isNaN.toString() + "'");
ok(Array.toString() === "\nfunction Array() {\n [native code]\n}\n",
"isNaN.toString = '" + Array.toString() + "'");
ok(Function.toString() === "\nfunction Function() {\n [native code]\n}\n",
"isNaN.toString = '" + Function.toString() + "'");
ok(Function.prototype.toString() === "\nfunction prototype() {\n [native code]\n}\n",
"isNaN.toString = '" + Function.prototype.toString() + "'");
ok("".substr.toString() === "\nfunction substr() {\n [native code]\n}\n",
"''.substr.toString = '" + "".substr.toString() + "'");
var bool = new Boolean();
ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
var bool = new Boolean("false");