Jacek Caban : jscript: Added Error. toString implementation for invoke version >= 2.
Alexandre Julliard
julliard at winehq.org
Tue Oct 20 10:33:35 CDT 2009
Module: wine
Branch: master
Commit: 86e7beae82e4234dd5537f580f51820d65d76775
URL: http://source.winehq.org/git/wine.git/?a=commit;h=86e7beae82e4234dd5537f580f51820d65d76775
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Oct 19 20:41:02 2009 +0200
jscript: Added Error.toString implementation for invoke version >= 2.
---
dlls/jscript/error.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c
index 2b193ef..6c89d70 100644
--- a/dlls/jscript/error.c
+++ b/dlls/jscript/error.c
@@ -36,6 +36,7 @@ typedef struct {
static const WCHAR descriptionW[] = {'d','e','s','c','r','i','p','t','i','o','n',0};
static const WCHAR messageW[] = {'m','e','s','s','a','g','e',0};
+static const WCHAR nameW[] = {'n','a','m','e',0};
static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
@@ -44,6 +45,11 @@ static inline ErrorInstance *error_from_vdisp(vdisp_t *vdisp)
return (ErrorInstance*)vdisp->u.jsdisp;
}
+static inline ErrorInstance *error_this(vdisp_t *jsthis)
+{
+ return is_vclass(jsthis, JSCLASS_ERROR) ? error_from_vdisp(jsthis) : NULL;
+}
+
static HRESULT Error_number(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
@@ -101,17 +107,77 @@ static HRESULT Error_message(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
/* ECMA-262 3rd Edition 15.11.4.4 */
static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
- DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
+ DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
+ ErrorInstance *error;
+ BSTR name, msg = NULL, ret = NULL;
+ VARIANT v;
+ HRESULT hres;
+
static const WCHAR str[] = {'[','o','b','j','e','c','t',' ','E','r','r','o','r',']',0};
TRACE("\n");
+ error = error_this(jsthis);
+ if(ctx->version < 2 || !error) {
+ if(retv) {
+ V_VT(retv) = VT_BSTR;
+ V_BSTR(retv) = SysAllocString(str);
+ if(!V_BSTR(retv))
+ return E_OUTOFMEMORY;
+ }
+ return S_OK;
+ }
+
+ hres = jsdisp_propget_name(&error->dispex, nameW, &v, ei, caller);
+ if(FAILED(hres))
+ return hres;
+
+ hres = to_string(ctx, &v, ei, &name);
+ VariantClear(&v);
+ if(FAILED(hres))
+ return hres;
+
+ if(V_VT(&error->message) != VT_EMPTY) {
+ hres = to_string(ctx, &error->message, ei, &msg);
+ if(SUCCEEDED(hres) && !*msg) {
+ SysFreeString(msg);
+ msg = NULL;
+ }
+ }
+
+ if(SUCCEEDED(hres)) {
+ if(msg) {
+ DWORD name_len, msg_len;
+
+ name_len = SysStringLen(name);
+ msg_len = SysStringLen(msg);
+
+ ret = SysAllocStringLen(NULL, name_len + msg_len + 2);
+ if(ret) {
+ memcpy(ret, name, name_len*sizeof(WCHAR));
+ ret[name_len] = ':';
+ ret[name_len+1] = ' ';
+ memcpy(ret+name_len+2, msg, msg_len*sizeof(WCHAR));
+ }
+ }else {
+ ret = name;
+ name = NULL;
+ }
+ }
+
+ SysFreeString(msg);
+ SysFreeString(name);
+ if(FAILED(hres))
+ return hres;
+ if(!ret)
+ return E_OUTOFMEMORY;
+
if(retv) {
V_VT(retv) = VT_BSTR;
- V_BSTR(retv) = SysAllocString(str);
- if(!V_BSTR(retv))
- return E_OUTOFMEMORY;
+ V_BSTR(retv) = ret;
+ }else {
+ SysFreeString(ret);
}
return S_OK;
@@ -341,7 +407,6 @@ static HRESULT URIErrorConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD fla
HRESULT init_error_constr(script_ctx_t *ctx, DispatchEx *object_prototype)
{
- static const WCHAR nameW[] = {'n','a','m','e',0};
static const WCHAR ErrorW[] = {'E','r','r','o','r',0};
static const WCHAR EvalErrorW[] = {'E','v','a','l','E','r','r','o','r',0};
static const WCHAR RangeErrorW[] = {'R','a','n','g','e','E','r','r','o','r',0};
More information about the wine-cvs
mailing list