Commit d918a189 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added Function.toString implementation for builtin functions.

parent 522d0bf9
...@@ -1101,11 +1101,13 @@ HRESULT create_array_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Dis ...@@ -1101,11 +1101,13 @@ HRESULT create_array_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Dis
ArrayInstance *array; ArrayInstance *array;
HRESULT hres; HRESULT hres;
static const WCHAR ArrayW[] = {'A','r','r','a','y',0};
hres = alloc_array(ctx, object_prototype, &array); hres = alloc_array(ctx, object_prototype, &array);
if(FAILED(hres)) if(FAILED(hres))
return 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); jsdisp_release(&array->dispex);
return hres; return hres;
......
...@@ -179,11 +179,13 @@ HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Disp ...@@ -179,11 +179,13 @@ HRESULT create_bool_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Disp
BoolInstance *bool; BoolInstance *bool;
HRESULT hres; HRESULT hres;
static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
hres = alloc_bool(ctx, object_prototype, &bool); hres = alloc_bool(ctx, object_prototype, &bool);
if(FAILED(hres)) if(FAILED(hres))
return 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); jsdisp_release(&bool->dispex);
return hres; return hres;
......
...@@ -2603,11 +2603,13 @@ HRESULT create_date_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Disp ...@@ -2603,11 +2603,13 @@ HRESULT create_date_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Disp
DispatchEx *date; DispatchEx *date;
HRESULT hres; HRESULT hres;
static const WCHAR DateW[] = {'D','a','t','e',0};
hres = create_date(ctx, object_prototype, 0.0, &date); hres = create_date(ctx, object_prototype, 0.0, &date);
if(FAILED(hres)) if(FAILED(hres))
return 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); jsdisp_release(date);
return hres; return hres;
......
...@@ -293,7 +293,8 @@ static HRESULT prop_get(DispatchEx *This, dispex_prop_t *prop, LCID lcid, DISPPA ...@@ -293,7 +293,8 @@ static HRESULT prop_get(DispatchEx *This, dispex_prop_t *prop, LCID lcid, DISPPA
case PROP_BUILTIN: case PROP_BUILTIN:
if(prop->u.p->flags & PROPF_METHOD) { if(prop->u.p->flags & PROPF_METHOD) {
DispatchEx *obj; 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)) if(FAILED(hres))
break; break;
......
...@@ -374,7 +374,7 @@ HRESULT init_error_constr(script_ctx_t *ctx, DispatchEx *object_prototype) ...@@ -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*/); hres = jsdisp_propput_name(&err->dispex, nameW, ctx->lcid, &v, NULL/*FIXME*/, NULL/*FIXME*/);
if(SUCCEEDED(hres)) 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]); PROPF_CONSTR, &err->dispex, constr_addr[i]);
jsdisp_release(&err->dispex); jsdisp_release(&err->dispex);
......
...@@ -26,6 +26,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(jscript); ...@@ -26,6 +26,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(jscript);
typedef struct { typedef struct {
DispatchEx dispex; DispatchEx dispex;
builtin_invoke_t value_proc; builtin_invoke_t value_proc;
const WCHAR *name;
DWORD flags; DWORD flags;
source_elements_t *source; source_elements_t *source;
parameter_t *parameters; parameter_t *parameters;
...@@ -285,14 +286,26 @@ static HRESULT function_to_string(FunctionInstance *function, BSTR *ret) ...@@ -285,14 +286,26 @@ static HRESULT function_to_string(FunctionInstance *function, BSTR *ret)
{ {
BSTR str; BSTR str;
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'};
if(function->value_proc) { if(function->value_proc) {
FIXME("Builtin functions not implemented\n"); DWORD name_len;
return E_NOTIMPL;
}
str = SysAllocStringLen(function->src_str, function->src_len); name_len = strlenW(function->name);
if(!str) str = SysAllocStringLen(NULL, sizeof(native_prefixW) + name_len*sizeof(WCHAR) + sizeof(native_suffixW));
return E_OUTOFMEMORY; 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; *ret = str;
return S_OK; return S_OK;
...@@ -598,7 +611,7 @@ static HRESULT set_prototype(script_ctx_t *ctx, DispatchEx *dispex, DispatchEx * ...@@ -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*/); 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) const builtin_info_t *builtin_info, DWORD flags, DispatchEx *prototype, DispatchEx **ret)
{ {
FunctionInstance *function; FunctionInstance *function;
...@@ -615,6 +628,7 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, ...@@ -615,6 +628,7 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
} }
function->value_proc = value_proc; function->value_proc = value_proc;
function->name = name;
*ret = &function->dispex; *ret = &function->dispex;
return S_OK; return S_OK;
...@@ -670,15 +684,19 @@ HRESULT init_function_constr(script_ctx_t *ctx, DispatchEx *object_prototype) ...@@ -670,15 +684,19 @@ HRESULT init_function_constr(script_ctx_t *ctx, DispatchEx *object_prototype)
FunctionInstance *prot, *constr; FunctionInstance *prot, *constr;
HRESULT hres; 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); hres = create_function(ctx, NULL, PROPF_CONSTR, TRUE, object_prototype, &prot);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
prot->value_proc = FunctionProt_value; prot->value_proc = FunctionProt_value;
prot->name = prototypeW;
hres = create_function(ctx, NULL, PROPF_CONSTR, TRUE, &prot->dispex, &constr); hres = create_function(ctx, NULL, PROPF_CONSTR, TRUE, &prot->dispex, &constr);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
constr->value_proc = FunctionConstr_value; constr->value_proc = FunctionConstr_value;
constr->name = FunctionW;
hres = set_prototype(ctx, &constr->dispex, &prot->dispex); hres = set_prototype(ctx, &constr->dispex, &prot->dispex);
if(FAILED(hres)) if(FAILED(hres))
jsdisp_release(&constr->dispex); jsdisp_release(&constr->dispex);
......
...@@ -144,7 +144,7 @@ HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceP ...@@ -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_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
HRESULT jsdisp_delete_idx(DispatchEx*,DWORD); 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**); DispatchEx*,DispatchEx**);
HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*); HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
......
...@@ -330,12 +330,14 @@ HRESULT create_number_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di ...@@ -330,12 +330,14 @@ HRESULT create_number_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
NumberInstance *number; NumberInstance *number;
HRESULT hres; HRESULT hres;
static const WCHAR NumberW[] = {'N','u','m','b','e','r',0};
hres = alloc_number(ctx, object_prototype, &number); hres = alloc_number(ctx, object_prototype, &number);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
V_VT(&number->num) = VT_I4; 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); jsdisp_release(&number->dispex);
return hres; return hres;
......
...@@ -192,7 +192,9 @@ static HRESULT ObjectConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DIS ...@@ -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) 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); object_prototype, ret);
} }
......
...@@ -3845,11 +3845,13 @@ HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di ...@@ -3845,11 +3845,13 @@ HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
RegExpInstance *regexp; RegExpInstance *regexp;
HRESULT hres; HRESULT hres;
static const WCHAR RegExpW[] = {'R','e','g','E','x','p',0};
hres = alloc_regexp(ctx, object_prototype, &regexp); hres = alloc_regexp(ctx, object_prototype, &regexp);
if(FAILED(hres)) if(FAILED(hres))
return 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); jsdisp_release(&regexp->dispex);
return hres; return hres;
......
...@@ -1869,11 +1869,14 @@ HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di ...@@ -1869,11 +1869,14 @@ HRESULT create_string_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
StringInstance *string; StringInstance *string;
HRESULT hres; HRESULT hres;
static const WCHAR StringW[] = {'S','t','r','i','n','g',0};
hres = string_alloc(ctx, object_prototype, &string); hres = string_alloc(ctx, object_prototype, &string);
if(FAILED(hres)) if(FAILED(hres))
return 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); jsdisp_release(&string->dispex);
return hres; return hres;
......
...@@ -1467,6 +1467,17 @@ ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2); ...@@ -1467,6 +1467,17 @@ ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
Math.SQRT1_2 = "test"; Math.SQRT1_2 = "test";
ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2); 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(); var bool = new Boolean();
ok(bool.toString() === "false", "bool.toString() = " + bool.toString()); ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
var bool = new Boolean("false"); var bool = new Boolean("false");
......
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